E-mail: Fixed view deletion order.

* The FiltersConfigView now ensures that its current filter is deleted
  before itself, as the filter's add-in would already be unloaded at
  that point.
* This fixes crashing when leaving the filter config view.
This commit is contained in:
Axel Dörfler
2016-01-14 20:51:43 +01:00
parent 94834e20a8
commit ecd3b5d5f1
2 changed files with 22 additions and 16 deletions
+19 -13
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2015, Haiku, Inc. All rights reserved. * Copyright 2007-2016, Haiku, Inc. All rights reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <[email protected]> * Copyright 2011, Clemens Zeidler <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -211,7 +211,7 @@ private:
FiltersConfigView::FiltersConfigView(BMailAccountSettings& account) FiltersConfigView::FiltersConfigView(BMailAccountSettings& account)
: :
BBox("filters"), BGroupView(B_VERTICAL),
fAccount(account), fAccount(account),
fDirection(kIncoming), fDirection(kIncoming),
fInboundFilters(kIncoming), fInboundFilters(kIncoming),
@@ -219,8 +219,11 @@ FiltersConfigView::FiltersConfigView(BMailAccountSettings& account)
fFilterView(NULL), fFilterView(NULL),
fCurrentIndex(-1) fCurrentIndex(-1)
{ {
BBox* box = new BBox("filters");
AddChild(box);
BView* contents = new BView(NULL, 0); BView* contents = new BView(NULL, 0);
AddChild(contents); box->AddChild(contents);
BMessage* msg = new BMessage(kMsgChainSelected); BMessage* msg = new BMessage(kMsgChainSelected);
msg->AddInt32("direction", kIncoming); msg->AddInt32("direction", kIncoming);
@@ -236,7 +239,7 @@ FiltersConfigView::FiltersConfigView(BMailAccountSettings& account)
fChainsField = new BMenuField(NULL, NULL, menu); fChainsField = new BMenuField(NULL, NULL, menu);
fChainsField->ResizeToPreferred(); fChainsField->ResizeToPreferred();
SetLabel(fChainsField); box->SetLabel(fChainsField);
fListView = new DragListView(NULL, B_SINGLE_SELECTION_LIST, fListView = new DragListView(NULL, B_SINGLE_SELECTION_LIST,
new BMessage(kMsgFilterMoved)); new BMessage(kMsgFilterMoved));
@@ -264,18 +267,23 @@ FiltersConfigView::FiltersConfigView(BMailAccountSettings& account)
FiltersConfigView::~FiltersConfigView() FiltersConfigView::~FiltersConfigView()
{ {
// We need to remove the filter manually, as their add-on
// is not available anymore in the parent destructor.
if (fFilterView != NULL) {
RemoveChild(fFilterView);
delete fFilterView;
}
} }
void void
FiltersConfigView::_SelectFilter(int32 index) FiltersConfigView::_SelectFilter(int32 index)
{ {
if (Parent()) Hide();
Parent()->Hide();
// remove old config view // remove old config view
if (fFilterView) { if (fFilterView != NULL) {
Parent()->RemoveChild(fFilterView); RemoveChild(fFilterView);
_SaveConfig(fCurrentIndex); _SaveConfig(fCurrentIndex);
delete fFilterView; delete fFilterView;
fFilterView = NULL; fFilterView = NULL;
@@ -293,15 +301,13 @@ FiltersConfigView::_SelectFilter(int32 index)
fFilterView = new FilterSettingsView( fFilterView = new FilterSettingsView(
filters->DescriptiveName(filterSettings->AddOnRef(), filters->DescriptiveName(filterSettings->AddOnRef(),
fAccount, NULL), view); fAccount, NULL), view);
Parent()->AddChild(fFilterView); AddChild(fFilterView);
} }
} }
} }
fCurrentIndex = index; fCurrentIndex = index;
Show();
if (Parent())
Parent()->Show();
} }
@@ -433,7 +439,7 @@ FiltersConfigView::MessageReceived(BMessage *msg)
if (!_MailSettings()->MoveFilterSettings(from, to)) { if (!_MailSettings()->MoveFilterSettings(from, to)) {
BAlert* alert = new BAlert("E-mail", BAlert* alert = new BAlert("E-mail",
B_TRANSLATE("The filter could not be moved. Deleting " B_TRANSLATE("The filter could not be moved. Deleting "
"filter."), B_TRANSLATE("OK")); "filter."), B_TRANSLATE("OK"));
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(); alert->Go();
fListView->RemoveItem(to); fListView->RemoveItem(to);
+3 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2007-2016, Haiku, Inc. All rights reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <[email protected]> * Copyright 2011, Clemens Zeidler <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -10,8 +10,8 @@
#include <vector> #include <vector>
#include <Box.h>
#include <Button.h> #include <Button.h>
#include <GroupView.h>
#include <ListView.h> #include <ListView.h>
#include <MailSettings.h> #include <MailSettings.h>
#include <Message.h> #include <Message.h>
@@ -23,7 +23,7 @@
class FilterSettingsView; class FilterSettingsView;
class FiltersConfigView : public BBox { class FiltersConfigView : public BGroupView {
public: public:
FiltersConfigView( FiltersConfigView(
BMailAccountSettings& account); BMailAccountSettings& account);