diff --git a/src/apps/icon-o-matic/gui/StyleListView.cpp b/src/apps/icon-o-matic/gui/StyleListView.cpp index ec30208b39..7cd7808c61 100644 --- a/src/apps/icon-o-matic/gui/StyleListView.cpp +++ b/src/apps/icon-o-matic/gui/StyleListView.cpp @@ -428,9 +428,12 @@ StyleListView::MakeDragMessage(BMessage* message) const for (int32 i = 0; i < count; i++) { StyleListItem* item = dynamic_cast( ItemAt(CurrentSelection(i))); - if (item != NULL) + if (item != NULL) { message->AddPointer("style", (void*)item->style); - else + BMessage archive; + if (item->style->Archive(&archive, true) == B_OK) + message->AddMessage("style archive", &archive); + } else break; } } @@ -450,6 +453,56 @@ StyleListView::SetDropTargetRect(const BMessage* message, BPoint where) } +bool +StyleListView::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 || fStyleContainer == 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 styles; + while (true) { + BMessage archive; + if (message->FindMessage("style archive", index, &archive) != B_OK) + break; + Style* style = new(std::nothrow) Style(&archive); + if (style == NULL) + break; + + if (!styles.AddItem(style)) { + delete style; + break; + } + + index++; + } + + int32 count = styles.CountItems(); + if (count == 0) + return false; + + AddStylesCommand* command = new(std::nothrow) AddStylesCommand( + fStyleContainer, (Style**)styles.Items(), count, dropIndex); + + if (command == NULL) { + for (int32 i = 0; i < count; i++) + delete (Style*)styles.ItemAtFast(i); + return false; + } + + fCommandStack->Perform(command); + + return true; +} + + void StyleListView::MoveItems(BList& items, int32 toIndex) { diff --git a/src/apps/icon-o-matic/gui/StyleListView.h b/src/apps/icon-o-matic/gui/StyleListView.h index 5029dce926..9945b8d965 100644 --- a/src/apps/icon-o-matic/gui/StyleListView.h +++ b/src/apps/icon-o-matic/gui/StyleListView.h @@ -48,6 +48,8 @@ public: 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);