/usr/lib/Wt/examples/treeview-dragdrop/FolderView.C is in witty-examples 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | /*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <iostream>
#include <Wt/WAbstractItemModel>
#include <Wt/WItemSelectionModel>
#include <Wt/WMessageBox>
#include "FolderView.h"
using namespace Wt;
const char *FolderView::FileSelectionMimeType
= "application/x-computers-selection";
FolderView::FolderView(Wt::WContainerWidget *parent)
: WTreeView(parent)
{
/*
* Accept drops for the custom mime type.
*/
acceptDrops(FileSelectionMimeType);
}
void FolderView::dropEvent(const Wt::WDropEvent& event,
const Wt::WModelIndex& target)
{
/*
* We reimplement the drop event to handle the dropping of a
* selection of computers.
*
* The test below would always be true in this case, since we only
* indicated support for that particular mime type.
*/
if (event.mimeType() == FileSelectionMimeType) {
/*
* The source object for a drag of a selection from a WTreeView is
* a WItemSelectionModel.
*/
WItemSelectionModel *selection
= dynamic_cast<WItemSelectionModel *>(event.source());
#ifdef WT_THREADED
int result = WMessageBox::show
("Drop event",
"Move "
+ boost::lexical_cast<std::string>(selection->selectedIndexes().size())
+ " files to folder '"
+ boost::any_cast<WString>(target.data(DisplayRole)).toUTF8()
+ "' ?",
Yes | No);
#else
int result = Yes;
#endif
if (result == Yes) {
/*
* You can access the source model from the selection and
* manipulate it.
*/
WAbstractItemModel *sourceModel = selection->model();
WModelIndexSet toChange = selection->selectedIndexes();
for (WModelIndexSet::reverse_iterator i = toChange.rbegin();
i != toChange.rend(); ++i) {
WModelIndex index = *i;
/*
* Copy target folder to file. Since we are using a
* dynamic WSortFilterProxyModel that filters on folder, this
* will also result in the removal of the file from the
* current view.
*/
std::map<int, boost::any> data = model()->itemData(target);
data[DecorationRole] = index.data(DecorationRole);
sourceModel->setItemData(index, data);
}
}
}
}
|