Skip to content

Commit 715c134

Browse files
committed
EditorWindow: use an application menu in the main menubar
Fixes #153
1 parent 47b309a commit 715c134

File tree

7 files changed

+418
-6
lines changed

7 files changed

+418
-6
lines changed

locales/en.catkeys

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1 English x-vnd.KapiX-Koder 3292494141
1+
1 English x-vnd.KapiX-Koder 2982779499
22
Something wrong has happened while opening the configuration file. Your personal settings will not be %s%. Preferences Something wrong has happened while opening the configuration file. Your personal settings will not be %s%.
33
Access denied EditorWindow Access denied
44
Line endings EditorWindow Line endings
@@ -24,6 +24,7 @@ Special symbols EditorWindow Special symbols
2424
Show line endings EditorWindow Show line endings
2525
Undo EditorWindow Undo
2626
Comment line EditorWindow Comment line
27+
Open project website EditorWindow Open project website
2728
Show full path in title AppPreferencesWindow Show full path in title
2829
Close EditorWindow Close
2930
Spaces per tab: AppPreferencesWindow Spaces per tab:
@@ -76,6 +77,7 @@ save Preferences to _ the configuration save
7677
Up to the next non-empty line AppPreferencesWindow Up to the next non-empty line
7778
Replace all FindWindow Replace all
7879
Koder System name Koder
80+
View or submit bug reports EditorWindow View or submit bug reports
7981
Extra large AppPreferencesWindow Toolbar icon size Extra large
8082
Stack new windows AppPreferencesWindow Stack new windows
8183
Find selection EditorWindow Find selection
@@ -116,6 +118,7 @@ Quit EditorWindow Quit
116118
Redo EditorWindow Redo
117119
Go to line: GoToLineWindow Go to line:
118120
Editor settings Preferences Editor settings
121+
Windows EditorWindow Windows
119122
You don't have sufficient permissions to edit this file. EditorWindow You don't have sufficient permissions to edit this file.
120123
Convert tabs to spaces AppPreferencesWindow Convert tabs to spaces
121124
Search EditorWindow Search
@@ -134,6 +137,7 @@ Untitled EditorWindow Untitled
134137
Unknown error. Preferences Unknown error.
135138
Find FindWindow Find
136139
Delete BookmarksListView Delete
140+
Preferences… EditorWindow Preferences…
137141
Reload EditorWindow Reload
138142
Go to line GoToLineWindow Go to line
139143
There are unsaved changes.\nSelect the files to save. QuitAlert There are unsaved changes.\nSelect the files to save.

src/App.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ App::MessageReceived(BMessage* message)
266266
case SUPPRESS_INITIAL_WINDOW: {
267267
fSuppressInitialWindow = true;
268268
} break;
269+
case ACTIVATE_WINDOW: {
270+
BWindow* window = nullptr;
271+
if(message->FindPointer("window", (void**) &window) == B_OK && window != nullptr) {
272+
window->Activate();
273+
}
274+
} break;
269275
case ACTIVE_WINDOW_CHANGED: {
270276
if(message->FindPointer("window", (void**) &fLastActiveWindow) != B_OK) {
271277
fLastActiveWindow = nullptr;

src/App.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class Styler;
2525

2626
enum {
2727
SUPPRESS_INITIAL_WINDOW = 'Siwn',
28-
WINDOW_NEW_WITH_QUIT_REPLY = 'NWwn'
28+
WINDOW_NEW_WITH_QUIT_REPLY = 'NWwn',
29+
ACTIVATE_WINDOW = 'actw'
2930
};
3031

3132

src/editor/EditorWindow.cpp

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <String.h>
2727
#include <StringFormat.h>
2828
#include <ToolBar.h>
29+
#include <Url.h>
2930
#include <kernel/fs_attr.h>
3031

3132
#include "App.h"
@@ -37,6 +38,7 @@
3738
#include "FindReplaceHandler.h"
3839
#include "FindWindow.h"
3940
#include "GoToLineWindow.h"
41+
#include "IconMenuItem.h"
4042
#include "Languages.h"
4143
#include "Preferences.h"
4244
#include "ScintillaUtils.h"
@@ -85,8 +87,20 @@ EditorWindow::EditorWindow(bool stagger)
8587
fOpenPanel->SetMessage(&openMessage);
8688
fSavePanel = new BFilePanel(B_SAVE_PANEL, windowMessenger, nullptr, 0, false);
8789

90+
BMenu* appMenu = new BMenu("");
91+
fWindowsMenu = new BMenu(B_TRANSLATE("Windows"));
92+
BLayoutBuilder::Menu<>(appMenu)
93+
.AddItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), B_ABOUT_REQUESTED)
94+
.AddSeparator()
95+
.AddMenu(fWindowsMenu)
96+
.End()
97+
.AddItem(B_TRANSLATE("Preferences" B_UTF8_ELLIPSIS), MAINMENU_EDIT_APP_PREFERENCES)
98+
.AddSeparator()
99+
.AddItem(B_TRANSLATE("Quit"), MAINMENU_FILE_QUIT, 'Q');
100+
88101
fMainMenu = new BMenuBar("MainMenu");
89102
BLayoutBuilder::Menu<>(fMainMenu)
103+
.AddItem(new IconMenuItem(appMenu, nullptr, gAppMime, B_MINI_ICON))
90104
.AddMenu(B_TRANSLATE("File"))
91105
.AddItem(B_TRANSLATE("New"), MAINMENU_FILE_NEW, 'N')
92106
.AddSeparator()
@@ -101,7 +115,6 @@ EditorWindow::EditorWindow(bool stagger)
101115
.AddItem(B_TRANSLATE("Open partner file"), MAINMENU_FILE_OPEN_CORRESPONDING, 'O', B_OPTION_KEY)
102116
.AddSeparator()
103117
.AddItem(B_TRANSLATE("Close"), B_QUIT_REQUESTED, 'W')
104-
.AddItem(B_TRANSLATE("Quit"), MAINMENU_FILE_QUIT, 'Q')
105118
.End()
106119
.AddMenu(B_TRANSLATE("Edit"))
107120
.AddItem(B_TRANSLATE("Undo"), B_UNDO, 'Z')
@@ -123,9 +136,8 @@ EditorWindow::EditorWindow(bool stagger)
123136
.AddItem(B_TRANSLATE("Windows format"), MAINMENU_EDIT_CONVERTEOLS_WINDOWS)
124137
.AddItem(B_TRANSLATE("Old Mac format"), MAINMENU_EDIT_CONVERTEOLS_MAC)
125138
.End()
126-
.AddSeparator()
139+
//.AddSeparator()
127140
//.AddItem(B_TRANSLATE("File preferences" B_UTF8_ELLIPSIS), MAINMENU_EDIT_FILE_PREFERENCES)
128-
.AddItem(B_TRANSLATE("Koder preferences" B_UTF8_ELLIPSIS), MAINMENU_EDIT_APP_PREFERENCES)
129141
.End()
130142
.AddMenu(B_TRANSLATE("View"))
131143
.AddMenu(B_TRANSLATE("Special symbols"))
@@ -153,7 +165,8 @@ EditorWindow::EditorWindow(bool stagger)
153165
.AddItem("Dummy", MAINMENU_LANGUAGE)
154166
.End()
155167
.AddMenu(B_TRANSLATE("Help"))
156-
.AddItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), B_ABOUT_REQUESTED)
168+
.AddItem(B_TRANSLATE("Open project website"), MAINMENU_HELP_PROJECT)
169+
.AddItem(B_TRANSLATE("View or submit bug reports"), MAINMENU_HELP_ISSUES)
157170
.End();
158171

159172
// When changing this shortcut remember to update one in StatusView as well
@@ -673,6 +686,12 @@ EditorWindow::MessageReceived(BMessage* message)
673686
fEditor->SendMessage(SCI_SETWRAPMODE, fPreferences->fWrapLines ?
674687
SC_WRAP_WORD : SC_WRAP_NONE, 0);
675688
} break;
689+
case MAINMENU_HELP_PROJECT: {
690+
BUrl("https://github.com/KapiX/Koder", true).OpenWithPreferredApplication();
691+
} break;
692+
case MAINMENU_HELP_ISSUES: {
693+
BUrl("https://github.com/KapiX/Koder/issues", true).OpenWithPreferredApplication();
694+
} break;
676695
case MAINMENU_LANGUAGE: {
677696
_SetLanguage(message->GetString("lang", "text"));
678697
} break;
@@ -932,6 +951,34 @@ EditorWindow::Show()
932951
}
933952

934953

954+
void
955+
EditorWindow::MenusBeginning()
956+
{
957+
if(fWindowsMenu == nullptr) {
958+
return;
959+
}
960+
for(int32 x = fWindowsMenu->CountItems() - 1; x >= 0; x--) {
961+
delete fWindowsMenu->ItemAt(x);
962+
}
963+
for(int32 x = 0; x < be_app->CountWindows(); x++) {
964+
// use a dynamic_cast to filter out other window types (find, save, bookmarks, ...)
965+
EditorWindow* window = dynamic_cast<EditorWindow*>(be_app->WindowAt(x));
966+
if(window == nullptr)
967+
continue;
968+
969+
BMessage* message = new BMessage(ACTIVATE_WINDOW);
970+
message->AddPointer("window", window);
971+
BMenuItem* menuItem = new BMenuItem(window->Title(), message);
972+
if(window == this) {
973+
menuItem->SetEnabled(false);
974+
menuItem->SetMarked(true);
975+
}
976+
fWindowsMenu->AddItem(menuItem);
977+
}
978+
fWindowsMenu->SetTargetForItems(be_app);
979+
}
980+
981+
935982
const char*
936983
EditorWindow::OpenedFilePath()
937984
{

src/editor/EditorWindow.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ enum {
8080
MAINMENU_SEARCH_PREVBOOKMARK = 'mpbk',
8181
MAINMENU_SEARCH_GOTOLINE = 'msgl',
8282

83+
MAINMENU_HELP_PROJECT = 'hlpp',
84+
MAINMENU_HELP_ISSUES = 'hlpi',
85+
8386
MAINMENU_LANGUAGE = 'ml00',
8487
MAINMENU_OPEN_RECENT = 'mr00',
8588

@@ -114,6 +117,7 @@ class EditorWindow : public BWindow {
114117
void WindowActivated(bool active);
115118
void FrameMoved(BPoint origin);
116119
void Show();
120+
void MenusBeginning();
117121

118122
bool IsModified() { return fModified; }
119123
const char* OpenedFilePath();
@@ -148,6 +152,7 @@ class EditorWindow : public BWindow {
148152
BFilePanel* fSavePanel;
149153
BMenu* fOpenRecentMenu;
150154
BMenu* fLanguageMenu;
155+
BMenu* fWindowsMenu;
151156
std::string fCurrentLanguage;
152157
ToolBar* fToolbar;
153158
StatusView* fStatusView;

0 commit comments

Comments
 (0)