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:
@@ -508,9 +508,12 @@ PathListView::MakeDragMessage(BMessage* message) const
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
PathListItem* item = dynamic_cast<PathListItem*>(
|
PathListItem* item = dynamic_cast<PathListItem*>(
|
||||||
ItemAt(CurrentSelection(i)));
|
ItemAt(CurrentSelection(i)));
|
||||||
if (item != NULL)
|
if (item != NULL) {
|
||||||
message->AddPointer("path", (void*)item->path);
|
message->AddPointer("path", (void*)item->path);
|
||||||
else
|
BMessage archive;
|
||||||
|
if (item->path->Archive(&archive, true) == B_OK)
|
||||||
|
message->AddMessage("path archive", &archive);
|
||||||
|
} else
|
||||||
break;
|
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
|
void
|
||||||
PathListView::MoveItems(BList& items, int32 toIndex)
|
PathListView::MoveItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ class PathListView : public SimpleListView,
|
|||||||
virtual bool AcceptDragMessage(const BMessage* message) const;
|
virtual bool AcceptDragMessage(const BMessage* message) const;
|
||||||
virtual void SetDropTargetRect(const BMessage* message,
|
virtual void SetDropTargetRect(const BMessage* message,
|
||||||
BPoint where);
|
BPoint where);
|
||||||
|
virtual bool HandleDropMessage(const BMessage* message,
|
||||||
|
int32 dropIndex);
|
||||||
|
|
||||||
virtual void MoveItems(BList& items, int32 toIndex);
|
virtual void MoveItems(BList& items, int32 toIndex);
|
||||||
virtual void CopyItems(BList& items, int32 toIndex);
|
virtual void CopyItems(BList& items, int32 toIndex);
|
||||||
|
|||||||
Reference in New Issue
Block a user