* Fixed potential NULL menuBar. This fixes CID 462.

* Got rid of the global styled_edit_app variable.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38463 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-08-30 21:04:06 +00:00
parent 4cdd7099dc
commit 6387dbc3f2
3 changed files with 39 additions and 34 deletions
+15 -10
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved. * Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -32,7 +32,6 @@
using namespace BPrivate; using namespace BPrivate;
StyledEditApp * styled_edit_app;
BRect gWindowRect(7-15, 26-15, 507, 426); BRect gWindowRect(7-15, 26-15, 507, 426);
@@ -80,22 +79,27 @@ namespace
// #pragma mark - // #pragma mark -
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Open_and_SaveAsPanel" #define B_TRANSLATE_CONTEXT "Open_and_SaveAsPanel"
StyledEditApp::StyledEditApp() StyledEditApp::StyledEditApp()
: BApplication(APP_SIGNATURE), :
BApplication(APP_SIGNATURE),
fOpenPanel(NULL) fOpenPanel(NULL)
{ {
fOpenPanel = new BFilePanel(); fOpenPanel = new BFilePanel();
BMenuBar* menuBar =
dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
fOpenAsEncoding = 0; fOpenAsEncoding = 0;
fOpenPanelEncodingMenu= new BMenu(B_TRANSLATE("Encoding")); fOpenPanelEncodingMenu = new BMenu(B_TRANSLATE("Encoding"));
menuBar->AddItem(fOpenPanelEncodingMenu);
fOpenPanelEncodingMenu->SetRadioMode(true); fOpenPanelEncodingMenu->SetRadioMode(true);
BMenuBar* menuBar
= dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
if (menuBar != NULL)
menuBar->AddItem(fOpenPanelEncodingMenu);
BCharacterSetRoster roster; BCharacterSetRoster roster;
BCharacterSet charset; BCharacterSet charset;
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
@@ -122,14 +126,14 @@ StyledEditApp::StyledEditApp()
fWindowCount = 0; fWindowCount = 0;
fNextUntitledWindow = 1; fNextUntitledWindow = 1;
fBadArguments = false; fBadArguments = false;
styled_edit_app = this;
} }
StyledEditApp::~StyledEditApp() StyledEditApp::~StyledEditApp()
{ {
delete fOpenPanel; delete fOpenPanel;
if (fOpenPanelEncodingMenu->Supermenu() == NULL)
delete fOpenPanelEncodingMenu;
} }
@@ -150,7 +154,8 @@ StyledEditApp::MessageReceived(BMessage* message)
void* ptr; void* ptr;
if (message->FindPointer("source", &ptr) == B_OK if (message->FindPointer("source", &ptr) == B_OK
&& fOpenPanelEncodingMenu != 0) { && fOpenPanelEncodingMenu != 0) {
fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr); fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf(
(BMenuItem*)ptr);
} }
break; break;
+22 -23
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved. * Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -25,33 +25,32 @@ class StyledEditWindow;
class StyledEditApp : public BApplication { class StyledEditApp : public BApplication {
public: public:
StyledEditApp(); StyledEditApp();
virtual ~StyledEditApp(); virtual ~StyledEditApp();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
virtual void ArgvReceived(int32 argc, char** argv); virtual void ArgvReceived(int32 argc, char** argv);
virtual void RefsReceived(BMessage *message); virtual void RefsReceived(BMessage* message);
virtual void ReadyToRun(); virtual void ReadyToRun();
int32 NumberOfWindows(); int32 NumberOfWindows();
void OpenDocument(); void OpenDocument();
status_t OpenDocument(entry_ref *ref); status_t OpenDocument(entry_ref* ref);
void CloseDocument(); void CloseDocument();
private: private:
void ArgvReceivedEx(int32 argc, const char *argv[], const char * cwd); void ArgvReceivedEx(int32 argc, const char* argv[],
const char* cwd);
private: private:
BFilePanel *fOpenPanel; BFilePanel* fOpenPanel;
BMenu *fOpenPanelEncodingMenu; BMenu* fOpenPanelEncodingMenu;
uint32 fOpenAsEncoding; uint32 fOpenAsEncoding;
int32 fWindowCount; int32 fWindowCount;
int32 fNextUntitledWindow; int32 fNextUntitledWindow;
bool fBadArguments; bool fBadArguments;
}; };
extern StyledEditApp* styled_edit_app;
#endif // STYLED_EDIT_APP #endif // STYLED_EDIT_APP
+2 -1
View File
@@ -861,7 +861,8 @@ void
StyledEditWindow::Quit() StyledEditWindow::Quit()
{ {
SaveAttrs(); SaveAttrs();
styled_edit_app->CloseDocument(); if (StyledEditApp* app = dynamic_cast<StyledEditApp*>(be_app))
app->CloseDocument();
BWindow::Quit(); BWindow::Quit();
} }