* Fixed CID 461 as well - same thing, only for adding a menu to the save panel.

* The menus are now only created when the menu bar is found.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38466 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-08-30 21:18:20 +00:00
parent 56f837e265
commit 252999c4e2
2 changed files with 47 additions and 45 deletions
+27 -26
View File
@@ -92,36 +92,39 @@ StyledEditApp::StyledEditApp()
fOpenPanel = new BFilePanel(); fOpenPanel = new BFilePanel();
fOpenAsEncoding = 0; fOpenAsEncoding = 0;
fOpenPanelEncodingMenu = new BMenu(B_TRANSLATE("Encoding"));
fOpenPanelEncodingMenu->SetRadioMode(true);
BMenuBar* menuBar BMenuBar* menuBar
= dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar")); = dynamic_cast<BMenuBar*>(fOpenPanel->Window()->FindView("MenuBar"));
if (menuBar != NULL) if (menuBar != NULL) {
fOpenPanelEncodingMenu = new BMenu(B_TRANSLATE("Encoding"));
fOpenPanelEncodingMenu->SetRadioMode(true);
menuBar->AddItem(fOpenPanelEncodingMenu); 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) {
BString name; BString name;
if (charset.GetFontID() == B_UNICODE_UTF8) if (charset.GetFontID() == B_UNICODE_UTF8)
name = B_TRANSLATE("Default"); name = B_TRANSLATE("Default");
else else
name = charset.GetPrintName(); name = charset.GetPrintName();
const char* mime = charset.GetMIMEName(); const char* mime = charset.GetMIMEName();
if (mime) { if (mime != NULL) {
name.Append(" ("); name.Append(" (");
name.Append(mime); name.Append(mime);
name.Append(")"); name.Append(")");
}
BMenuItem* item =
new BMenuItem(name.String(), new BMessage(OPEN_AS_ENCODING));
item->SetTarget(this);
fOpenPanelEncodingMenu->AddItem(item);
if (charset.GetFontID() == fOpenAsEncoding)
item->SetMarked(true);
} }
BMenuItem* item = } else
new BMenuItem(name.String(), new BMessage(OPEN_AS_ENCODING)); fOpenPanelEncodingMenu = NULL;
item->SetTarget(this);
fOpenPanelEncodingMenu->AddItem(item);
if (charset.GetFontID() == fOpenAsEncoding)
item->SetMarked(true);
}
fWindowCount = 0; fWindowCount = 0;
fNextUntitledWindow = 1; fNextUntitledWindow = 1;
@@ -132,8 +135,6 @@ StyledEditApp::StyledEditApp()
StyledEditApp::~StyledEditApp() StyledEditApp::~StyledEditApp()
{ {
delete fOpenPanel; delete fOpenPanel;
if (fOpenPanelEncodingMenu->Supermenu() == NULL)
delete fOpenPanelEncodingMenu;
} }
@@ -153,7 +154,7 @@ StyledEditApp::MessageReceived(BMessage* message)
case OPEN_AS_ENCODING: case OPEN_AS_ENCODING:
void* ptr; void* ptr;
if (message->FindPointer("source", &ptr) == B_OK if (message->FindPointer("source", &ptr) == B_OK
&& fOpenPanelEncodingMenu != 0) { && fOpenPanelEncodingMenu != NULL) {
fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf( fOpenAsEncoding = (uint32)fOpenPanelEncodingMenu->IndexOf(
(BMenuItem*)ptr); (BMenuItem*)ptr);
} }
+20 -19
View File
@@ -1001,27 +1001,28 @@ StyledEditWindow::SaveAs(BMessage* message)
BMenuBar* menuBar = dynamic_cast<BMenuBar*>( BMenuBar* menuBar = dynamic_cast<BMenuBar*>(
fSavePanel->Window()->FindView("MenuBar")); fSavePanel->Window()->FindView("MenuBar"));
if (menuBar != NULL) {
fSavePanelEncodingMenu = new BMenu(B_TRANSLATE("Encoding"));
fSavePanelEncodingMenu->SetRadioMode(true);
menuBar->AddItem(fSavePanelEncodingMenu);
fSavePanelEncodingMenu= new BMenu(B_TRANSLATE("Encoding")); BCharacterSetRoster roster;
menuBar->AddItem(fSavePanelEncodingMenu); BCharacterSet charset;
fSavePanelEncodingMenu->SetRadioMode(true); while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) {
BString name(charset.GetPrintName());
BCharacterSetRoster roster; const char* mime = charset.GetMIMEName();
BCharacterSet charset; if (mime) {
while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { name.Append(" (");
BString name(charset.GetPrintName()); name.Append(mime);
const char* mime = charset.GetMIMEName(); name.Append(")");
if (mime) { }
name.Append(" ("); BMenuItem * item = new BMenuItem(name.String(),
name.Append(mime); new BMessage(SAVE_AS_ENCODING));
name.Append(")"); item->SetTarget(this);
fSavePanelEncodingMenu->AddItem(item);
if (charset.GetFontID() == fTextView->GetEncoding())
item->SetMarked(true);
} }
BMenuItem * item = new BMenuItem(name.String(),
new BMessage(SAVE_AS_ENCODING));
item->SetTarget(this);
fSavePanelEncodingMenu->AddItem(item);
if (charset.GetFontID() == fTextView->GetEncoding())
item->SetMarked(true);
} }
} }