Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions src/editor/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ EditorWindow::EditorWindow(bool stagger)

fToolbar->AddAction(MAINMENU_SEARCH_BOOKMARKS,
B_TRANSLATE("Bookmarks"), "bookmarks");
BButton* bookmarkButton = fToolbar->FindButton(MAINMENU_SEARCH_BOOKMARKS);
if(bookmarkButton != nullptr) {
bookmarkButton->SetBehavior(BButton::B_POP_UP_BEHAVIOR);
bookmarkButton->SetPopUpMessage(new BMessage(TOOLBAR_OPEN_BOOKMARK));
}
fToolbar->AddAction(MAINMENU_SEARCH_PREVBOOKMARK,
B_TRANSLATE("Previous bookmark"), "bookmark prev");
fToolbar->AddAction(MAINMENU_SEARCH_NEXTBOOKMARK,
Expand Down Expand Up @@ -671,20 +676,41 @@ EditorWindow::MessageReceived(BMessage* message)
case MAINMENU_LANGUAGE: {
_SetLanguage(message->GetString("lang", "text"));
} break;
case TOOLBAR_OPEN_BOOKMARK: {
BButton* button = fToolbar->FindButton(MAINMENU_SEARCH_BOOKMARKS);
if(button == nullptr) {
return;
}
BPopUpMenu* menu = new BPopUpMenu("BookmarksPopUp", false, false);
BMessage bookmarks = fEditor->BookmarksWithText();
type_code type;
int32 count;
if(bookmarks.GetInfo("line", &type, &count) == B_OK) {
for(int32 i = 0; i < count; i++) {
int64 line = bookmarks.GetInt64("line", i, -1);
if(line != -1) {
line += 1;
BString bookmarkText(bookmarks.GetString("text", i, ""));
BString itemLabel;
itemLabel << line << " - " << bookmarkText.Trim();
// truncate to make sure our menu isn't too wide
itemLabel.Truncate(50);
BMessage* itemMessage = new BMessage(GTLW_GO);
itemMessage->AddInt32("line", line);
menu->AddItem(new BMenuItem(itemLabel.String(), itemMessage));
}
}
}
_ShowToolbarPopUp(menu, button);
} break;
case TOOLBAR_OPEN_RECENT: {
BButton* button = fToolbar->FindButton(MAINMENU_FILE_OPEN);
if(button == nullptr) {
return;
}
BPopUpMenu* menu = new BPopUpMenu("RecentsPopUp", false, false);
_PopulateOpenRecentMenu(menu);
menu->SetTargetForItems(this);
BPoint menuPoint(ConvertToScreen(fToolbar->ConvertToParent(button->Frame().LeftBottom())));
menuPoint.x += 2;
menuPoint.y += 1;
button->SetValue(1);
menu->Go(menuPoint, true);
button->SetValue(0);
_ShowToolbarPopUp(menu, button);
} break;
case TOOLBAR_SPECIAL_SYMBOLS: {
bool pressed = fPreferences->fWhiteSpaceVisible && fPreferences->fEOLVisible;
Expand Down Expand Up @@ -1269,6 +1295,20 @@ EditorWindow::_SyncEditMenus()
}


void
EditorWindow::_ShowToolbarPopUp(BPopUpMenu* menu, BButton* button)
{
menu->SetTargetForItems(this);
BPoint menuPoint(ConvertToScreen(fToolbar->ConvertToParent(button->Frame().LeftBottom())));
menuPoint.x += 2;
menuPoint.y += 1;
button->SetValue(1);
UpdateIfNeeded();
menu->Go(menuPoint, true);
button->SetValue(0);
}


int32
EditorWindow::_ShowModifiedAlert()
{
Expand Down
2 changes: 2 additions & 0 deletions src/editor/EditorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum {
MAINMENU_LANGUAGE = 'ml00',
MAINMENU_OPEN_RECENT = 'mr00',

TOOLBAR_OPEN_BOOKMARK = 'tlob',
TOOLBAR_OPEN_RECENT = 'tlor',
TOOLBAR_SPECIAL_SYMBOLS = 'tlss',

Expand Down Expand Up @@ -173,6 +174,7 @@ class EditorWindow : public BWindow {
void _SyncWithPreferences();
void _SyncEditMenus();
int32 _ShowModifiedAlert();
void _ShowToolbarPopUp(BPopUpMenu* menu, BButton* button);
void _ReloadAlert(const char* title, const char* message);
void _Save();
void _OpenTerminal(const char* path);
Expand Down