Made it possible to drag paths from one I-O-M window to another.

* Put archived versions of the selected paths into the drag message.
 * If the base class version HandleDropMessage() failed, it means the
   drag message came from another window. Reconstruct the paths and
   add them via the AddPathsCommand.
This commit is contained in:
Stephan Aßmus 2012-05-05 17:14:42 +02:00
parent 34c3ca13b4
commit 5959960b03
2 changed files with 57 additions and 2 deletions

View File

@ -508,9 +508,12 @@ PathListView::MakeDragMessage(BMessage* message) const
for (int32 i = 0; i < count; i++) {
PathListItem* item = dynamic_cast<PathListItem*>(
ItemAt(CurrentSelection(i)));
if (item != NULL)
if (item != NULL) {
message->AddPointer("path", (void*)item->path);
else
BMessage archive;
if (item->path->Archive(&archive, true) == B_OK)
message->AddMessage("path archive", &archive);
} else
break;
}
}
@ -530,6 +533,56 @@ PathListView::SetDropTargetRect(const BMessage* message, BPoint where)
}
bool
PathListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
{
// Let SimpleListView handle drag-sorting (when drag came from ourself)
if (SimpleListView::HandleDropMessage(message, dropIndex))
return true;
if (fCommandStack == NULL || fPathContainer == NULL)
return false;
// Drag may have come from another instance, like in another window.
// Reconstruct the Styles from the archive and add them at the drop
// index.
int index = 0;
BList paths;
while (true) {
BMessage archive;
if (message->FindMessage("path archive", index, &archive) != B_OK)
break;
VectorPath* path = new(std::nothrow) VectorPath(&archive);
if (path == NULL)
break;
if (!paths.AddItem(path)) {
delete path;
break;
}
index++;
}
int32 count = paths.CountItems();
if (count == 0)
return false;
AddPathsCommand* command = new(nothrow) AddPathsCommand(fPathContainer,
(VectorPath**)paths.Items(), count, true, dropIndex);
if (command == NULL) {
for (int32 i = 0; i < count; i++)
delete (VectorPath*)paths.ItemAtFast(i);
return false;
}
fCommandStack->Perform(command);
return true;
}
void
PathListView::MoveItems(BList& items, int32 toIndex)
{

View File

@ -51,6 +51,8 @@ class PathListView : public SimpleListView,
virtual bool AcceptDragMessage(const BMessage* message) const;
virtual void SetDropTargetRect(const BMessage* message,
BPoint where);
virtual bool HandleDropMessage(const BMessage* message,
int32 dropIndex);
virtual void MoveItems(BList& items, int32 toIndex);
virtual void CopyItems(BList& items, int32 toIndex);