From 51c908221e78fee5b2f96b4c99b3e4632f9c857e Mon Sep 17 00:00:00 2001 From: Freaxed Date: Sun, 24 Nov 2024 18:04:02 +0100 Subject: [PATCH 1/2] Command run as a toolbar --- src/ui/GenioWindow.cpp | 99 +++++++++++++++++++++++++++++------------- src/ui/GenioWindow.h | 7 ++- 2 files changed, 74 insertions(+), 32 deletions(-) diff --git a/src/ui/GenioWindow.cpp b/src/ui/GenioWindow.cpp index ded56905..76591116 100644 --- a/src/ui/GenioWindow.cpp +++ b/src/ui/GenioWindow.cpp @@ -161,9 +161,9 @@ GenioWindow::GenioWindow(BRect frame) , fFindCaseSensitiveCheck(nullptr) , fFindWholeWordCheck(nullptr) , fFindWrapCheck(nullptr) - , fRunConsoleProgramGroup(nullptr) + , fRunGroup(nullptr) , fRunConsoleProgramText(nullptr) - , fRunConsoleProgramButton(nullptr) + , fRunMenuField(nullptr) , fConsoleStdinLine("") , fOpenPanel(nullptr) , fSavePanel(nullptr) @@ -355,7 +355,8 @@ GenioWindow::MessageReceived(BMessage* message) _ReplaceGroupShow(false); fFindTextControl->MakeFocus(true); } else if (CurrentFocus() == fRunConsoleProgramText->TextView()) { - fRunConsoleProgramGroup->SetVisible(false); + _ShowView(fRunGroup, false); +// fRunConsoleProgramGroup->SetVisible(false); fRunConsoleProgramText->MakeFocus(false); ActionManager::SetPressed(MSG_RUN_CONSOLE_PROGRAM_SHOW, false); } @@ -1036,22 +1037,25 @@ GenioWindow::MessageReceived(BMessage* message) break; case MSG_RUN_CONSOLE_PROGRAM_SHOW: { - if (fRunConsoleProgramGroup->IsVisible()) { + _ShowView(fRunGroup, fRunGroup->IsHidden()); + fRunConsoleProgramText->MakeFocus(!fRunGroup->IsHidden()); + /*if (fRunConsoleProgramGroup->IsVisible()) { fRunConsoleProgramGroup->SetVisible(false); fRunConsoleProgramText->MakeFocus(false); } else { fRunConsoleProgramGroup->SetVisible(true); fRunConsoleProgramText->MakeFocus(true); - } - ActionManager::SetPressed(MSG_RUN_CONSOLE_PROGRAM_SHOW, fRunConsoleProgramGroup->IsVisible()); + }*/ + ActionManager::SetPressed(MSG_RUN_CONSOLE_PROGRAM_SHOW, !fRunGroup->IsHidden()); break; } case MSG_RUN_CONSOLE_PROGRAM: { - const BString& command(fRunConsoleProgramText->Text()); + BString command = message->GetString("command", fRunConsoleProgramText->Text()); if (!command.IsEmpty()) _RunInConsole(command); - fRunConsoleProgramText->SetText(""); + if (!message->HasString("command")) + fRunConsoleProgramText->SetText(""); break; } case MSG_RUN_TARGET: @@ -2561,6 +2565,41 @@ GenioWindow::_HandleNodeMonitorMsg(BMessage* msg) } } +void +GenioWindow::_InitCommandRunToolbar() +{ + fRunGroup = new ToolBar(this); + if (gCFG["use_small_icons"]) { + fRunGroup->ChangeIconSize(be_control_look->ComposeIconSize(kDefaultIconSizeSmall).Width()); + } else { + fRunGroup->ChangeIconSize(be_control_look->ComposeIconSize(kDefaultIconSize).Width()); + } + + fRunMenuField = new BMenuField("RecentMenuField", NULL, new BMenu(B_TRANSLATE("Recents"))); + fRunMenuField->SetExplicitMaxSize(BSize(kFindReplaceOPSize, B_SIZE_UNSET)); + fRunMenuField->SetExplicitMinSize(BSize(kFindReplaceOPSize, B_SIZE_UNSET)); + + fRunConsoleProgramText = new BTextControl("RunTextControl", "" , "", new BMessage(MSG_RUN_CONSOLE_PROGRAM)); + fRunConsoleProgramText->TextView()->SetMaxBytes(kFindReplaceMaxBytes*2); + float charWidth = fRunConsoleProgramText->StringWidth("0", 1); + fRunConsoleProgramText->SetExplicitMinSize( + BSize(charWidth * kFindReplaceMinBytes + 10.0f, + B_SIZE_UNSET)); + BSize doubleSize = fRunConsoleProgramText->MinSize(); + doubleSize.width *= 2; + fRunConsoleProgramText->SetExplicitMaxSize(doubleSize); + + fRunGroup->AddView(BLayoutBuilder::Group<>(B_HORIZONTAL, B_USE_HALF_ITEM_SPACING) + .Add(fRunMenuField) + .Add(fRunConsoleProgramText).View()); + + fRunGroup->AddAction(MSG_RUN_CONSOLE_PROGRAM, "", "kIconRun", false); + fRunGroup->FindButton(MSG_RUN_CONSOLE_PROGRAM)->SetLabel(B_TRANSLATE("Run")); + fRunGroup->AddGlue(); + fRunGroup->Hide(); + +} + void GenioWindow::_InitCentralSplit() @@ -2641,25 +2680,7 @@ GenioWindow::_InitCentralSplit() fReplaceGroup->AddGlue(); fReplaceGroup->Hide(); - // Run group - fRunConsoleProgramText = new BTextControl("ReplaceTextControl", "", "", - new BMessage(MSG_RUN_CONSOLE_PROGRAM)); - fRunConsoleProgramButton = new BButton("RunConsoleProgramButton", - B_TRANSLATE("Run"), new BMessage(MSG_RUN_CONSOLE_PROGRAM)); - - BString tooltip("cwd: "); - tooltip << (const char*)gCFG["projects_directory"]; - fRunConsoleProgramText->SetToolTip(tooltip); - - fRunConsoleProgramGroup = BLayoutBuilder::Group<>(B_VERTICAL, 0.0f) - .Add(BLayoutBuilder::Group<>(B_HORIZONTAL, B_USE_DEFAULT_SPACING) - .Add(fRunConsoleProgramText) - .Add(fRunConsoleProgramButton) - .AddGlue() - ) - .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) - ; - fRunConsoleProgramGroup->SetVisible(false); + _InitCommandRunToolbar(); // Editor tab & view @@ -2671,7 +2692,7 @@ GenioWindow::_InitCentralSplit() dirtyFrameHack = fTabManager->TabGroup()->Frame(); fEditorTabsGroup = BLayoutBuilder::Group<>(B_VERTICAL, 0.0f) - .Add(fRunConsoleProgramGroup) + .Add(fRunGroup) .Add(fFindGroup) .Add(fReplaceGroup) .Add(fTabManager->TabGroup()) @@ -3562,9 +3583,9 @@ GenioWindow::_ProjectFolderActivate(ProjectFolder *project) } // Update run command working directory tooltip too - BString tooltip; + /*BString tooltip; tooltip << "cwd: " << fActiveProject->Path(); - fRunConsoleProgramText->SetToolTip(tooltip); + fRunConsoleProgramText->SetToolTip(tooltip);*/ } @@ -4086,6 +4107,8 @@ GenioWindow::_RunInConsole(const BString& command) _ShowLog(kOutputLog); + _UpdateRecentCommands(command); + BMessage message; message.AddString("cmd", command); message.AddString("cmd_type", command); @@ -4182,6 +4205,22 @@ GenioWindow::_UpdateFindMenuItems(const BString& text) fFindMenuField->Menu()->RemoveItem(count); } +void +GenioWindow::_UpdateRecentCommands(const BString& text) +{ + int32 count = fRunMenuField->Menu()->CountItems(); + // Add item if not already present + if (fRunMenuField->Menu()->FindItem(text) == nullptr) { + BMessage* command = new BMessage(MSG_RUN_CONSOLE_PROGRAM); + command->AddString("command", text); + BMenuItem* item = new BMenuItem(text, command); + fRunMenuField->Menu()->AddItem(item, 0); + } + //remove last one. + if (count == kFindReplaceMenuItems) + fRunMenuField->Menu()->RemoveItem(count); +} + status_t GenioWindow::_UpdateLabel(int32 index, bool isModified) diff --git a/src/ui/GenioWindow.h b/src/ui/GenioWindow.h index ec028f20..dc843b57 100644 --- a/src/ui/GenioWindow.h +++ b/src/ui/GenioWindow.h @@ -113,6 +113,7 @@ class GenioWindow : public BWindow { void _HandleNodeMonitorMsg(BMessage* msg); void _CheckEntryRemoved(BMessage* msg); void _InitCentralSplit(); + void _InitCommandRunToolbar(); void _InitMenu(); void _InitOutputSplit(); void _InitLeftSplit(); @@ -151,6 +152,7 @@ class GenioWindow : public BWindow { void _ShowLog(int32 index); void _UpdateFindMenuItems(const BString& text); + void _UpdateRecentCommands(const BString& text); status_t _UpdateLabel(int32 index, bool isModified); void _UpdateProjectActivation(bool active); void _UpdateReplaceMenuItems(const BString& text); @@ -235,9 +237,9 @@ class GenioWindow : public BWindow { BCheckBox* fFindCaseSensitiveCheck; BCheckBox* fFindWholeWordCheck; BCheckBox* fFindWrapCheck; - BGroupLayout* fRunConsoleProgramGroup; + ToolBar* fRunGroup; BTextControl* fRunConsoleProgramText; - BButton* fRunConsoleProgramButton; + BMenuField* fRunMenuField; BString fConsoleStdinLine; BFilePanel* fOpenPanel; @@ -262,6 +264,7 @@ class GenioWindow : public BWindow { #ifdef GDEBUG BString fTitlePrefix; #endif + }; extern GenioWindow *gMainWindow; From 6f61f6be1dbd9a7ae75c75c2289561c6176687bf Mon Sep 17 00:00:00 2001 From: Freaxed Date: Sun, 24 Nov 2024 18:16:24 +0100 Subject: [PATCH 2/2] fixed invoking run command with enter --- src/ui/GenioWindow.cpp | 8 +++++--- src/ui/GenioWindowMessages.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ui/GenioWindow.cpp b/src/ui/GenioWindow.cpp index 76591116..da2ca6c8 100644 --- a/src/ui/GenioWindow.cpp +++ b/src/ui/GenioWindow.cpp @@ -207,7 +207,7 @@ GenioWindow::GenioWindow(BRect frame) AddCommonFilter(new KeyDownMessageFilter(MSG_FILE_NEXT_SELECTED, B_RIGHT_ARROW, B_CONTROL_KEY)); AddCommonFilter(new KeyDownMessageFilter(MSG_ESCAPE_KEY, B_ESCAPE, 0, B_DISPATCH_MESSAGE)); - AddCommonFilter(new KeyDownMessageFilter(MSG_FIND_INVOKED, B_ENTER, 0, B_DISPATCH_MESSAGE)); + AddCommonFilter(new KeyDownMessageFilter(MSG_TOOLBAR_INVOKED, B_ENTER, 0, B_DISPATCH_MESSAGE)); AddCommonFilter(new EditorKeyDownMessageFilter()); AddCommonFilter(new EditorMouseWheelMessageFilter()); @@ -762,7 +762,7 @@ GenioWindow::MessageReceived(BMessage* message) } break; } - case MSG_FIND_INVOKED: + case MSG_TOOLBAR_INVOKED: { if (CurrentFocus() == fFindTextControl->TextView()) { const BString& text(fFindTextControl->Text()); @@ -772,6 +772,8 @@ GenioWindow::MessageReceived(BMessage* message) PostMessage(MSG_FIND_IN_FILES); fFindTextControl->MakeFocus(true); + } else if (CurrentFocus() == fRunConsoleProgramText->TextView()) { + PostMessage(MSG_RUN_CONSOLE_PROGRAM); } break; } @@ -2579,7 +2581,7 @@ GenioWindow::_InitCommandRunToolbar() fRunMenuField->SetExplicitMaxSize(BSize(kFindReplaceOPSize, B_SIZE_UNSET)); fRunMenuField->SetExplicitMinSize(BSize(kFindReplaceOPSize, B_SIZE_UNSET)); - fRunConsoleProgramText = new BTextControl("RunTextControl", "" , "", new BMessage(MSG_RUN_CONSOLE_PROGRAM)); + fRunConsoleProgramText = new BTextControl("RunTextControl", "" , "", nullptr); fRunConsoleProgramText->TextView()->SetMaxBytes(kFindReplaceMaxBytes*2); float charWidth = fRunConsoleProgramText->StringWidth("0", 1); fRunConsoleProgramText->SetExplicitMinSize( diff --git a/src/ui/GenioWindowMessages.h b/src/ui/GenioWindowMessages.h index 8cbb473e..aa29250a 100644 --- a/src/ui/GenioWindowMessages.h +++ b/src/ui/GenioWindowMessages.h @@ -69,7 +69,7 @@ enum { MSG_FIND_PREVIOUS = 'fipr', MSG_FIND_MARK_ALL = 'fmal', MSG_FIND_NEXT = 'fite', - MSG_FIND_INVOKED = 'finv', + MSG_TOOLBAR_INVOKED = 'tinv', MSG_REPLACE_GROUP_SHOW = 'regs', MSG_REPLACE_MENU_SELECTED = 'rmse', MSG_REPLACE_ONE = 'reon',