Author: axeld Date: 2010-08-30 23:04:06 +0200 (Mon, 30 Aug 2010) New Revision: 38463 Changeset: http://dev.haiku-os.org/changeset/38463 Modified: haiku/trunk/src/apps/stylededit/StyledEditApp.cpp haiku/trunk/src/apps/stylededit/StyledEditApp.h haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp Log: * Fixed potential NULL menuBar. This fixes CID 462. * Got rid of the global styled_edit_app variable. * Minor cleanup. Modified: haiku/trunk/src/apps/stylededit/StyledEditApp.cpp =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditApp.cpp 2010-08-30 20:47:22 UTC (rev 38462) +++ haiku/trunk/src/apps/stylededit/StyledEditApp.cpp 2010-08-30 21:04:06 UTC (rev 38463) @@ -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. * * Authors: @@ -32,7 +32,6 @@ using namespace BPrivate; -StyledEditApp * styled_edit_app; BRect gWindowRect(7-15, 26-15, 507, 426); @@ -80,22 +79,27 @@ // #pragma mark - + #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "Open_and_SaveAsPanel" + StyledEditApp::StyledEditApp() - : BApplication(APP_SIGNATURE), + : + BApplication(APP_SIGNATURE), fOpenPanel(NULL) { fOpenPanel = new BFilePanel(); - BMenuBar* menuBar = - dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar")); fOpenAsEncoding = 0; - fOpenPanelEncodingMenu= new BMenu(B_TRANSLATE("Encoding")); - menuBar->AddItem(fOpenPanelEncodingMenu); + fOpenPanelEncodingMenu = new BMenu(B_TRANSLATE("Encoding")); fOpenPanelEncodingMenu->SetRadioMode(true); + BMenuBar* menuBar + = dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar")); + if (menuBar != NULL) + menuBar->AddItem(fOpenPanelEncodingMenu); + BCharacterSetRoster roster; BCharacterSet charset; while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { @@ -122,14 +126,14 @@ fWindowCount = 0; fNextUntitledWindow = 1; fBadArguments = false; - - styled_edit_app = this; } StyledEditApp::~StyledEditApp() { delete fOpenPanel; + if (fOpenPanelEncodingMenu->Supermenu() == NULL) + delete fOpenPanelEncodingMenu; } @@ -150,7 +154,8 @@ void* ptr; if (message->FindPointer("source", &ptr) == B_OK && fOpenPanelEncodingMenu != 0) { - fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf((BMenuItem*)ptr); + fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf( + (BMenuItem*)ptr); } break; Modified: haiku/trunk/src/apps/stylededit/StyledEditApp.h =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditApp.h 2010-08-30 20:47:22 UTC (rev 38462) +++ haiku/trunk/src/apps/stylededit/StyledEditApp.h 2010-08-30 21:04:06 UTC (rev 38463) @@ -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. * * Authors: @@ -25,33 +25,32 @@ class StyledEditApp : public BApplication { - public: - StyledEditApp(); - virtual ~StyledEditApp(); +public: + StyledEditApp(); + virtual ~StyledEditApp(); - virtual void MessageReceived(BMessage *message); - virtual void ArgvReceived(int32 argc, char** argv); - virtual void RefsReceived(BMessage *message); - virtual void ReadyToRun(); + virtual void MessageReceived(BMessage* message); + virtual void ArgvReceived(int32 argc, char** argv); + virtual void RefsReceived(BMessage* message); + virtual void ReadyToRun(); - int32 NumberOfWindows(); - void OpenDocument(); - status_t OpenDocument(entry_ref *ref); - void CloseDocument(); + int32 NumberOfWindows(); + void OpenDocument(); + status_t OpenDocument(entry_ref* ref); + void CloseDocument(); - private: - void ArgvReceivedEx(int32 argc, const char *argv[], const char * cwd); +private: + void ArgvReceivedEx(int32 argc, const char* argv[], + const char* cwd); - private: - BFilePanel *fOpenPanel; - BMenu *fOpenPanelEncodingMenu; - uint32 fOpenAsEncoding; - int32 fWindowCount; - int32 fNextUntitledWindow; - bool fBadArguments; +private: + BFilePanel* fOpenPanel; + BMenu* fOpenPanelEncodingMenu; + uint32 fOpenAsEncoding; + int32 fWindowCount; + int32 fNextUntitledWindow; + bool fBadArguments; }; -extern StyledEditApp* styled_edit_app; #endif // STYLED_EDIT_APP - Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2010-08-30 20:47:22 UTC (rev 38462) +++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2010-08-30 21:04:06 UTC (rev 38463) @@ -861,7 +861,8 @@ StyledEditWindow::Quit() { SaveAttrs(); - styled_edit_app->CloseDocument(); + if (StyledEditApp* app = dynamic_cast<StyledEditApp*>(be_app)) + app->CloseDocument(); BWindow::Quit(); }