diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index e2740c942..b31cfe148 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -175,6 +175,8 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, doc.tabStops = ini.getValueB( "document", "tab_stops", true ); doc.lineEndings = TextFormat::stringToLineEnding( ini.getValue( "document", "line_endings", "LF" ) ); + editor.newTabPosition = + NewTabPosition::fromString( ini.getValue( "editor", "new_tab_position", "last" ) ); // Migrate old data if ( ini.keyValueExists( "document", "windows_line_endings" ) && !ini.keyValueExists( "document", "line_endings" ) && @@ -388,6 +390,7 @@ void AppConfig::save( const std::vector& recentFiles, ini.setValueB( "editor", "tab_switcher", editor.tabSwitcher ); ini.setValue( "editor", "tab_jump_mode", UITabWidget::tabJumpModeToString( editor.tabJumpMode ) ); + ini.setValue( "editor", "new_tab_position", NewTabPosition::toString( editor.newTabPosition ) ); ini.setValueB( "editor", "single_click_tree_navigation", editor.singleClickNavigation ); ini.setValueB( "editor", "sync_project_tree_with_editor", editor.syncProjectTreeWithEditor ); ini.setValueB( "editor", "auto_close_xml_tags", editor.autoCloseXMLTags ); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index 0b6176810..af1f7889b 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -30,6 +30,35 @@ class PluginManager; enum class PanelPosition { Left, Right }; +class NewTabPosition { + public: + enum Position { AfterActive, Last, First, LeftOfActive }; + + static NewTabPosition::Position fromString( const std::string& position ) { + if ( "after_active" == position ) + return Position::AfterActive; + if ( "first" == position ) + return Position::First; + if ( "left_of_active" == position ) + return Position::LeftOfActive; + return Position::Last; + } + + static std::string toString( const Position& position ) { + switch ( position ) { + case Position::AfterActive: + return "after_active"; + case Position::First: + return "first"; + case Position::LeftOfActive: + return "left_of_active"; + case Position::Last: + default: + return "last"; + } + } +}; + struct UIConfig { StyleSheetLength fontSize{ 11, StyleSheetLength::Dp }; StyleSheetLength panelFontSize{ 11, StyleSheetLength::Dp }; @@ -90,6 +119,7 @@ struct CodeEditorConfig { bool tabSwitcher{ false }; bool openDocumentsInMainSplit{ false }; UITabWidget::TabJumpMode tabJumpMode{ UITabWidget::TabJumpMode::Linear }; + NewTabPosition::Position newTabPosition{ NewTabPosition::Last }; bool singleClickNavigation{ false }; bool syncProjectTreeWithEditor{ true }; @@ -297,8 +327,8 @@ class AppConfig { bool sessionSnapshot, PluginManager* ); void loadProject( std::string projectFolder, UICodeEditorSplitter* editorSplitter, - const std::string& configPath, ProjectConfig& docConfig, - ecode::App* app, bool sessionSnapshot, PluginManager* pluginManager ); + const std::string& configPath, ProjectConfig& docConfig, ecode::App* app, + bool sessionSnapshot, PluginManager* pluginManager ); void addTabWidgetType( const std::string& type, TabWidgetCbs tabWidget ) { Lock l( tabWidgetTypesMutex ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 0a615bc38..091ef28d6 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -103,7 +103,7 @@ class App : public UICodeEditorSplitter::Client, public PluginContextProvider { std::vector getUnlockedCommands(); - void saveAll( bool includeBuffers = true); + void saveAll( bool includeBuffers = true ); ProjectDirectoryTree* getDirTree() const; @@ -384,6 +384,45 @@ class App : public UICodeEditorSplitter::Client, public PluginContextProvider { mSplitter->registerSplitterCommands( t ); // Overwrite it + t.setCommand( "create-new", [this] { + UITabWidget* tabWidget = getSplitter()->getPreferredTabWidget(); + Uint32 selectedIdx = + tabWidget && tabWidget->getTabCount() > 0 ? tabWidget->getTabSelectedIndex() : 0; + auto d = getSplitter()->createCodeEditorInTabWidget( tabWidget ); + if ( d.first == nullptr || d.second == nullptr ) { + if ( !getSplitter()->getTabWidgets().empty() ) { + tabWidget = getSplitter()->getTabWidgets()[0]; + selectedIdx = tabWidget && tabWidget->getTabCount() > 0 + ? tabWidget->getTabSelectedIndex() + : 0; + d = getSplitter()->createCodeEditorInTabWidget( tabWidget ); + } + } + if ( d.first == nullptr || d.second == nullptr ) { + Log::error( "Couldn't createCodeEditorInTabWidget in create-new command" ); + return; + } + tabWidget = d.first->getTabWidget(); + switch ( mConfig.editor.newTabPosition ) { + case NewTabPosition::AfterActive: { + Uint32 newIdx = eemin( selectedIdx + 1, tabWidget->getTabCount() - 1 ); + tabWidget->moveTab( d.first, newIdx ); + break; + } + case NewTabPosition::First: + tabWidget->moveTab( d.first, 0 ); + break; + case NewTabPosition::LeftOfActive: + tabWidget->moveTab( + d.first, eemin( selectedIdx, tabWidget->getTabCount() - 1 ) ); + break; + case NewTabPosition::Last: + default: + break; + } + tabWidget->setTabSelected( d.first ); + } ); + t.setCommand( "next-tab", [this] { UITabWidget* tabWidget = getSplitter()->tabWidgetFromWidget( getSplitter()->getCurWidget() ); diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index e310c6fc4..1e9a1df14 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -782,6 +782,42 @@ UIMenu* SettingsMenu::createDocumentMenu() { mGlobalMenu->addSeparator(); + UIPopUpMenu* newTabPositionMenu = UIPopUpMenu::New(); + mGlobalMenu + ->addSubMenu( i18n( "new_tab_position", "New Tab Position" ), nullptr, newTabPositionMenu ) + ->setId( "new_tab_position" ); + + newTabPositionMenu->on( Event::OnMenuShow, [this, newTabPositionMenu]( const Event* ) { + if ( newTabPositionMenu->getCount() == 0 ) { + newTabPositionMenu + ->addRadioButton( i18n( "new_tab_position_after_active", "After Active Tab" ) ) + ->setId( "after_active" ); + newTabPositionMenu->addRadioButton( i18n( "new_tab_position_last", "Last" ) ) + ->setId( "last" ); + newTabPositionMenu->addRadioButton( i18n( "new_tab_position_first", "First" ) ) + ->setId( "first" ); + newTabPositionMenu + ->addRadioButton( i18n( "new_tab_position_left_of_active", "Left of Active Tab" ) ) + ->setId( "left_of_active" ); + } + + newTabPositionMenu->getItemId( "after_active" ) + ->asType() + ->setActive( mApp->getConfig().editor.newTabPosition == NewTabPosition::AfterActive ); + newTabPositionMenu->getItemId( "last" )->asType()->setActive( + mApp->getConfig().editor.newTabPosition == NewTabPosition::Last ); + newTabPositionMenu->getItemId( "first" )->asType()->setActive( + mApp->getConfig().editor.newTabPosition == NewTabPosition::First ); + newTabPositionMenu->getItemId( "left_of_active" ) + ->asType() + ->setActive( mApp->getConfig().editor.newTabPosition == NewTabPosition::LeftOfActive ); + } ); + + newTabPositionMenu->on( Event::OnItemClicked, [this]( const Event* event ) { + const std::string& id( event->getNode()->getId() ); + mApp->getConfig().editor.newTabPosition = NewTabPosition::fromString( id ); + } ); + mGlobalMenu->add( i18n( "line_breaking_column", "Line Breaking Column" ) ) ->setId( "line_breaking_column" );