A specialized treeview that supports a custom drop event. More...
#include <FolderView.h>
Inherits Wt::WTreeView.
Public Member Functions | |
FolderView (Wt::WContainerWidget *parent=0) | |
Constructor. | |
Static Public Attributes | |
static const char * | FileSelectionMimeType = "application/x-computers-selection" |
Constant that indicates the mime type for a selection of files. | |
Protected Member Functions | |
virtual void | dropEvent (const Wt::WDropEvent &event, const Wt::WModelIndex &target) |
Drop event. |
A specialized treeview that supports a custom drop event.
Definition at line 19 of file FolderView.h.
FolderView::FolderView | ( | Wt::WContainerWidget * | parent = 0 |
) |
Constructor.
Definition at line 19 of file FolderView.C.
00020 : WTreeView(parent) 00021 { 00022 /* 00023 * Accept drops for the custom mime type. 00024 */ 00025 acceptDrops(FileSelectionMimeType); 00026 }
void FolderView::dropEvent | ( | const Wt::WDropEvent & | event, | |
const Wt::WModelIndex & | target | |||
) | [protected, virtual] |
Drop event.
Reimplemented from Wt::WAbstractItemView.
Definition at line 28 of file FolderView.C.
00030 { 00031 /* 00032 * We reimplement the drop event to handle the dropping of a 00033 * selection of computers. 00034 * 00035 * The test below would always be true in this case, since we only 00036 * indicated support for that particular mime type. 00037 */ 00038 if (event.mimeType() == FileSelectionMimeType) { 00039 /* 00040 * The source object for a drag of a selection from a WTreeView is 00041 * a WItemSelectionModel. 00042 */ 00043 WItemSelectionModel *selection 00044 = dynamic_cast<WItemSelectionModel *>(event.source()); 00045 00046 #ifdef WT_THREADED 00047 int result = WMessageBox::show 00048 ("Drop event", 00049 "Move " 00050 + boost::lexical_cast<std::string>(selection->selectedIndexes().size()) 00051 + " files to folder '" 00052 + boost::any_cast<WString>(target.data(DisplayRole)).toUTF8() 00053 + "' ?", 00054 Yes | No); 00055 #else 00056 int result = Yes; 00057 #endif 00058 00059 if (result == Yes) { 00060 /* 00061 * You can access the source model from the selection and 00062 * manipulate it. 00063 */ 00064 WAbstractItemModel *sourceModel = selection->model(); 00065 00066 WModelIndexSet toChange = selection->selectedIndexes(); 00067 00068 for (WModelIndexSet::const_reverse_iterator i = toChange.rbegin(); 00069 i != toChange.rend(); ++i) { 00070 WModelIndex index = *i; 00071 00072 /* 00073 * Copy target folder to file. Since we are using a 00074 * dynamic WSortFilterProxyModel that filters on folder, this 00075 * will also result in the removal of the file from the 00076 * current view. 00077 */ 00078 std::map<int, boost::any> data = model()->itemData(target); 00079 data[DecorationRole] = index.data(DecorationRole); 00080 sourceModel->setItemData(index, data); 00081 } 00082 } 00083 } 00084 }
const char * FolderView::FileSelectionMimeType = "application/x-computers-selection" [static] |
Constant that indicates the mime type for a selection of files.
Every kind of dragged data should be identified using a unique mime type.
Definition at line 26 of file FolderView.h.