Accept dropping Styles from another I-O-M window.
* Add archived versions of the selected Styles to the drag message. * If the base class didn't handle the drop message, try to unarchive Styles and add them via AddStylesCommand.
This commit is contained in:
@@ -428,9 +428,12 @@ StyleListView::MakeDragMessage(BMessage* message) const
|
|||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
StyleListItem* item = dynamic_cast<StyleListItem*>(
|
StyleListItem* item = dynamic_cast<StyleListItem*>(
|
||||||
ItemAt(CurrentSelection(i)));
|
ItemAt(CurrentSelection(i)));
|
||||||
if (item != NULL)
|
if (item != NULL) {
|
||||||
message->AddPointer("style", (void*)item->style);
|
message->AddPointer("style", (void*)item->style);
|
||||||
else
|
BMessage archive;
|
||||||
|
if (item->style->Archive(&archive, true) == B_OK)
|
||||||
|
message->AddMessage("style archive", &archive);
|
||||||
|
} else
|
||||||
break;
|
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
|
void
|
||||||
StyleListView::MoveItems(BList& items, int32 toIndex)
|
StyleListView::MoveItems(BList& items, int32 toIndex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public:
|
|||||||
const BMessage* message) const;
|
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