#include <FolderView.h>
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. |
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::WTreeView.
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 int result = WMessageBox::show 00047 ("Drop event", 00048 "Move " 00049 + boost::lexical_cast<std::string>(selection->selectedIndexes().size()) 00050 + " files to folder '" 00051 + boost::any_cast<WString>(target.data(DisplayRole)).toUTF8() 00052 + "' ?", 00053 Yes | No); 00054 00055 if (result == Yes) { 00056 /* 00057 * You can access the source model from the selection and 00058 * manipulate it. 00059 */ 00060 WAbstractItemModel *sourceModel = selection->model(); 00061 00062 WModelIndexSet toChange = selection->selectedIndexes(); 00063 00064 for (WModelIndexSet::const_reverse_iterator i = toChange.rbegin(); 00065 i != toChange.rend(); ++i) { 00066 WModelIndex index = *i; 00067 00068 /* 00069 * Copy target folder to file. Since we are using a 00070 * dynamic WSortFilterProxyModel that filters on folder, this 00071 * will also result in the removal of the file from the 00072 * current view. 00073 */ 00074 std::map<int, boost::any> data = model()->itemData(target); 00075 data[DecorationRole] = index.data(DecorationRole); 00076 sourceModel->setItemData(index, data); 00077 } 00078 } 00079 } 00080 }
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.