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:
parent
34c3ca13b4
commit
5959960b03
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user