Deleting replicants now works

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18066 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-07-07 19:16:50 +00:00
parent 05fd381837
commit 931aebe962
3 changed files with 35 additions and 33 deletions
+1 -1
View File
@@ -18,7 +18,7 @@
#include <Rect.h> #include <Rect.h>
#include <Region.h> #include <Region.h>
const static uint32 kDeleteDragger = 'JAHA'; const static uint32 kDeleteReplicant = 'JAHA';
struct shape_data { struct shape_data {
uint32* opList; uint32* opList;
+6 -10
View File
@@ -264,7 +264,7 @@ BDragger::MessageReceived(BMessage *msg)
{ {
if (msg->what == B_TRASH_TARGET) { if (msg->what == B_TRASH_TARGET) {
if (fShelf) if (fShelf)
Window()->PostMessage(kDeleteDragger, fTarget, NULL); Window()->PostMessage(kDeleteReplicant, fTarget, NULL);
else else
(new BAlert("??", (new BAlert("??",
"Can't delete this replicant from its original application. Life goes on.", "Can't delete this replicant from its original application. Life goes on.",
@@ -385,12 +385,12 @@ BDragger::AllDetached()
status_t status_t
BDragger::SetPopUp(BPopUpMenu *context_menu) BDragger::SetPopUp(BPopUpMenu *menu)
{ {
if (fPopUp && fPopUp != context_menu) if (fPopUp != NULL && fPopUp != menu)
delete fPopUp; delete fPopUp;
fPopUp = context_menu; fPopUp = menu;
return B_OK; return B_OK;
} }
@@ -547,12 +547,8 @@ BDragger::BuildDefaultPopUp()
snprintf(about, B_OS_NAME_LENGTH, "About %s", name); snprintf(about, B_OS_NAME_LENGTH, "About %s", name);
fPopUp->AddItem(new BMenuItem(about, msg)); fPopUp->AddItem(new BMenuItem(about, msg));
fPopUp->AddSeparatorItem();
// Separator fPopUp->AddItem(new BMenuItem("Delete", new BMessage(kDeleteReplicant)));
fPopUp->AddItem(new BSeparatorItem());
// Delete
fPopUp->AddItem(new BMenuItem("Delete", new BMessage(kDeleteDragger)));
} }
+28 -22
View File
@@ -25,6 +25,7 @@
#include <Shelf.h> #include <Shelf.h>
#include <View.h> #include <View.h>
#include <ViewPrivate.h>
#include <ZombieReplicantView.h> #include <ZombieReplicantView.h>
#include <stdio.h> #include <stdio.h>
@@ -295,10 +296,10 @@ _rep_data_::index_of(BList const *list, unsigned long id)
_TContainerViewFilter_::_TContainerViewFilter_(BShelf *shelf, BView *view) _TContainerViewFilter_::_TContainerViewFilter_(BShelf *shelf, BView *view)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE) : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
fShelf(shelf),
fView(view)
{ {
fShelf = shelf;
fView = view;
} }
@@ -323,12 +324,9 @@ _TContainerViewFilter_::Filter(BMessage *msg, BHandler **handler)
filter_result filter_result
_TContainerViewFilter_::ObjectDropFilter(BMessage *msg, BHandler **_handler) _TContainerViewFilter_::ObjectDropFilter(BMessage *msg, BHandler **_handler)
{ {
BView *mouseView; BView *mouseView = NULL;
if (*_handler) if (*_handler)
mouseView = dynamic_cast<BView*>(*_handler); mouseView = dynamic_cast<BView*>(*_handler);
else
mouseView = NULL;
if (msg->WasDropped()) { if (msg->WasDropped()) {
if (!fShelf->fAllowDragging) { if (!fShelf->fAllowDragging) {
@@ -343,20 +341,16 @@ _TContainerViewFilter_::ObjectDropFilter(BMessage *msg, BHandler **_handler)
if (msg->WasDropped()) { if (msg->WasDropped()) {
point = msg->DropPoint(&offset); point = msg->DropPoint(&offset);
point = mouseView->ConvertFromScreen(point - offset); point = mouseView->ConvertFromScreen(point - offset);
} }
BLooper *looper; BLooper *looper = NULL;
BHandler *handler = msg->ReturnAddress().Target(&looper); BHandler *handler = msg->ReturnAddress().Target(&looper);
BDragger *dragger;
if (Looper() == looper) { if (Looper() == looper) {
BDragger *dragger = NULL;
if (handler) if (handler)
dragger = dynamic_cast<BDragger*>(handler); dragger = dynamic_cast<BDragger*>(handler);
else
dragger = NULL;
BRect rect; BRect rect;
if (dragger->fRelation == BDragger::TARGET_IS_CHILD) if (dragger->fRelation == BDragger::TARGET_IS_CHILD)
@@ -389,22 +383,27 @@ _TContainerViewFilter_::ObjectDropFilter(BMessage *msg, BHandler **_handler)
class _TReplicantViewFilter_ : public BMessageFilter { class _TReplicantViewFilter_ : public BMessageFilter {
public: public:
_TReplicantViewFilter_(BShelf *shelf, BView *view) _TReplicantViewFilter_(BShelf *shelf, BView *view)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE) : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
{ fShelf(shelf),
fShelf = shelf; fView(view)
fView = view; {
} }
virtual ~_TReplicantViewFilter_() virtual ~_TReplicantViewFilter_()
{ {
} }
filter_result Filter(BMessage *, BHandler **) filter_result Filter(BMessage *message, BHandler **handler)
{ {
if (message->what == kDeleteReplicant) {
if (handler != NULL)
*handler = fShelf;
message->AddPointer("_target", fView);
}
return B_DISPATCH_MESSAGE; return B_DISPATCH_MESSAGE;
} }
protected: private:
BShelf *fShelf; BShelf *fShelf;
BView *fView; BView *fView;
}; };
@@ -470,6 +469,14 @@ BShelf::Instantiate(BMessage *data)
void void
BShelf::MessageReceived(BMessage *msg) BShelf::MessageReceived(BMessage *msg)
{ {
if (msg->what == kDeleteReplicant) {
BView *replicant = NULL;
if (msg->FindPointer("_target", (void **)&replicant) == B_OK && replicant != NULL)
DeleteReplicant(replicant);
return;
}
BMessage replyMsg(B_REPLY); BMessage replyMsg(B_REPLY);
status_t err = B_BAD_SCRIPT_SYNTAX; status_t err = B_BAD_SCRIPT_SYNTAX;
@@ -1192,7 +1199,7 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
if (relation == BDragger::TARGET_IS_SIBLING || relation == BDragger::TARGET_IS_CHILD) if (relation == BDragger::TARGET_IS_SIBLING || relation == BDragger::TARGET_IS_CHILD)
fContainerView->AddChild(dragger); fContainerView->AddChild(dragger);
AddFilter(new _TReplicantViewFilter_(this, replicant)); replicant->AddFilter(new _TReplicantViewFilter_(this, replicant));
} else if (fDisplayZombies && fAllowZombies) { } else if (fDisplayZombies && fAllowZombies) {
// TODO: the zombies must be adjusted and moved as well! // TODO: the zombies must be adjusted and moved as well!
@@ -1217,8 +1224,7 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
zombie->AddChild(dragger); zombie->AddChild(dragger);
zombie->SetArchive(data); zombie->SetArchive(data);
zombie->AddFilter(new _TReplicantViewFilter_(this, zombie));
AddFilter(new _TReplicantViewFilter_(this, zombie));
fContainerView->AddChild(zombie); fContainerView->AddChild(zombie);
} }