From 5959960b03df3ff092215d04d8d8c2adc0d6e9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 5 May 2012 17:14:42 +0200 Subject: [PATCH] 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. --- src/apps/icon-o-matic/gui/PathListView.cpp | 57 +++++++++++++++++++++- src/apps/icon-o-matic/gui/PathListView.h | 2 + 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/apps/icon-o-matic/gui/PathListView.cpp b/src/apps/icon-o-matic/gui/PathListView.cpp index 8fa1150d7e..411ce1cc29 100644 --- a/src/apps/icon-o-matic/gui/PathListView.cpp +++ b/src/apps/icon-o-matic/gui/PathListView.cpp @@ -508,9 +508,12 @@ PathListView::MakeDragMessage(BMessage* message) const for (int32 i = 0; i < count; i++) { PathListItem* item = dynamic_cast( 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) { diff --git a/src/apps/icon-o-matic/gui/PathListView.h b/src/apps/icon-o-matic/gui/PathListView.h index 892f1ee6db..7c93448526 100644 --- a/src/apps/icon-o-matic/gui/PathListView.h +++ b/src/apps/icon-o-matic/gui/PathListView.h @@ -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);