From 0c935a7f50ca50a2d154a64226049b69901b2125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 15 Jul 2022 01:35:51 -0300 Subject: [PATCH] ecode: Improved project view menu and some global keybindings. --- projects/linux/ee.creator.user | 5 +- src/eepp/ui/uitreeview.cpp | 2 - src/tools/ecode/docsearchcontroller.cpp | 11 +- src/tools/ecode/docsearchcontroller.hpp | 2 +- src/tools/ecode/ecode.cpp | 168 ++++++++++++++++----- src/tools/ecode/ecode.hpp | 14 ++ src/tools/ecode/globalsearchcontroller.cpp | 2 + 7 files changed, 154 insertions(+), 50 deletions(-) diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 85340edf5..8e592c3ed 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -109,7 +109,7 @@ {388e5431-b31b-42b3-b9ad-9002d279d75d} 10 0 - 19 + 20 ../../make/linux @@ -1203,6 +1203,7 @@ ecode-debug ProjectExplorer.CustomExecutableRunConfiguration + /home/programming/nume/nume-api/ true false false diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index 83393ed29..2ab473aad 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -372,8 +372,6 @@ void UITreeView::setAllExpanded( const ModelIndex& index, bool expanded ) { if ( model.rowCount( curIndex ) > 0 ) setAllExpanded( curIndex, expanded ); } - - createOrUpdateColumns(); } void UITreeView::expandAll( const ModelIndex& index ) { diff --git a/src/tools/ecode/docsearchcontroller.cpp b/src/tools/ecode/docsearchcontroller.cpp index 23e628619..b44592798 100644 --- a/src/tools/ecode/docsearchcontroller.cpp +++ b/src/tools/ecode/docsearchcontroller.cpp @@ -26,10 +26,10 @@ void DocSearchController::initSearchBar( }; auto& kbind = mSearchBarLayout->getKeyBindings(); - kbind.addKeybindsString( { - { mApp->getKeybind( "repeat-find" ), "repeat-find" }, - { mApp->getKeybind( "find-prev" ), "find-prev" } - } ); + kbind.addKeybindsString( + { { mApp->getKeybind( "repeat-find" ), "repeat-find" }, + { mApp->getKeybind( "find-prev" ), "find-prev" }, + { mApp->getKeybind( "open-global-search" ), "open-global-search" } } ); kbind.addKeybindsStringUnordered( keybindings ); UITextInput* findInput = mSearchBarLayout->find( "search_find" ); @@ -139,6 +139,7 @@ void DocSearchController::initSearchBar( mSearchBarLayout->addCommand( "toggle-lua-pattern", [&, luaPatternChk] { luaPatternChk->setChecked( !luaPatternChk->isChecked() ); } ); + mSearchBarLayout->addCommand( "open-global-search", [&] { mApp->showGlobalSearch(); } ); addReturnListener( findInput, "repeat-find" ); addReturnListener( replaceInput, "find-and-replace" ); @@ -371,4 +372,4 @@ SearchBarConfig DocSearchController::getSearchBarConfig() const { return searchBarConfig; } -} +} // namespace ecode diff --git a/src/tools/ecode/docsearchcontroller.hpp b/src/tools/ecode/docsearchcontroller.hpp index 43d53e1c1..e20eadc01 100644 --- a/src/tools/ecode/docsearchcontroller.hpp +++ b/src/tools/ecode/docsearchcontroller.hpp @@ -28,7 +28,7 @@ class DocSearchController { public: static std::unordered_map getDefaultKeybindings() { return { { "mod+g", "repeat-find" }, { "escape", "close-searchbar" }, - { "mod+r", "replace-selection" }, { "mod+shift+f", "find-and-replace" }, + { "mod+r", "replace-selection" }, { "mod+shift+n", "find-and-replace" }, { "mod+shift+r", "replace-all" }, { "mod+s", "change-case" }, { "mod+w", "change-whole-word" }, { "mod+l", "toggle-lua-pattern" }, { "mod+e", "change-escape-sequence" } }; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 4e93c5149..a11070a2e 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2159,6 +2159,10 @@ void App::loadTerminalColorSchemes() { mTerminalCurrentColorScheme = mTerminalColorSchemes.begin()->first; } +void App::showGlobalSearch() { + mGlobalSearchController->showGlobalSearch(); +} + UITerminal* App::createNewTerminal( const std::string& title, UITabWidget* inTabWidget, const std::string& workingDir ) { #if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN @@ -2332,7 +2336,7 @@ UITerminal* App::createNewTerminal( const std::string& title, UITabWidget* inTab mSplitter->forEachEditor( [lock]( UICodeEditor* editor ) { editor->setLocked( lock ); } ); } ); term->setCommand( "menu-toggle", [&] { toggleSettingsMenu(); } ); - term->setCommand( "open-global-search", [&] { mGlobalSearchController->showGlobalSearch(); } ); + term->setCommand( "open-global-search", [&] { showGlobalSearch(); } ); term->setCommand( "open-locatebar", [&] { mFileLocator->showLocateBar(); } ); term->setCommand( "download-file-web", [&] { downloadFileWebDialog(); } ); @@ -2381,6 +2385,10 @@ void App::setTerminalColorScheme( const std::string& name ) { } } +void App::showFindView() { + mDocSearchController->showFindView(); +} + void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { const CodeEditorConfig& config = mConfig.editor; const DocumentConfig& docc = !mCurrentProject.empty() && !mProjectDocConfig.useGlobalSettings @@ -2423,8 +2431,8 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { saveFileDialog( mSplitter->getCurEditor() ); } ); doc.setCommand( "save-all", [&] { saveAll(); } ); - doc.setCommand( "find-replace", [&] { mDocSearchController->showFindView(); } ); - doc.setCommand( "open-global-search", [&] { mGlobalSearchController->showGlobalSearch(); } ); + doc.setCommand( "find-replace", [&] { showFindView(); } ); + doc.setCommand( "open-global-search", [&] { showGlobalSearch(); } ); doc.setCommand( "open-locatebar", [&] { mFileLocator->showLocateBar(); } ); doc.setCommand( "repeat-find", [&] { mDocSearchController->findNextText( mDocSearchController->getSearchState() ); @@ -3023,6 +3031,105 @@ void App::renameFile( const FileInfo& file ) { } ); } +void App::showProjectTreeMenu() { + Vector2f pos( mWindow->getInput()->getMousePosf() ); + mProjectTreeMenu->nodeToWorldTranslation( pos ); + UIMenu::findBestMenuPos( pos, mProjectTreeMenu ); + mProjectTreeMenu->setPixelsPosition( pos ); + mProjectTreeMenu->show(); +} + +void App::createProjectTreeMenu() { + if ( mProjectTreeMenu && mProjectTreeMenu->isVisible() ) + mProjectTreeMenu->close(); + + mProjectTreeMenu = UIPopUpMenu::New(); + + if ( !mCurrentProject.empty() ) { + mProjectTreeMenu->add( i18n( "new_file", "New File..." ), findIcon( "file-add" ) ) + ->setId( "new_file" ); + mProjectTreeMenu->add( i18n( "new_folder", "New Folder..." ), findIcon( "folder-add" ) ) + ->setId( "new_folder" ); + mProjectTreeMenu->add( i18n( "open_folder", "Open Folder..." ), findIcon( "folder-open" ) ) + ->setId( "open_folder" ); + mProjectTreeMenu + ->add( i18n( "execute_dir_in_terminal", "Open directory in terminal" ), + findIcon( "filetype-bash" ) ) + ->setId( "execute_dir_in_terminal" ); + mProjectTreeMenu->addSeparator(); + } + + mProjectTreeMenu->add( i18n( "collapse_all", "Collapse All" ) )->setId( "collapse-all" ); + mProjectTreeMenu->add( i18n( "expand_all", "Expand All" ) )->setId( "expand-all" ); + mProjectTreeMenu->addSeparator(); + mProjectTreeMenu + ->addCheckBox( i18n( "show_hidden_files", "Show hidden files" ), + !mFileSystemModel->getDisplayConfig().ignoreHidden ) + ->setId( "show_hidden_files" ); + + mProjectTreeMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) + return; + UIMenuItem* item = event->getNode()->asType(); + std::string id( item->getId() ); + if ( "new_file" == id || "new_file_in_place" == id ) { + newFile( FileInfo( mCurrentProject ) ); + } else if ( "new_folder" == id ) { + newFolder( FileInfo( mCurrentProject ) ); + } else if ( "open_folder" == id ) { + Engine::instance()->openURI( mCurrentProject ); + } else if ( "execute_dir_in_terminal" == id ) { + createNewTerminal( "", nullptr, mCurrentProject ); + } else if ( "show_hidden_files" == id ) { + toggleHiddenFiles(); + } else if ( "collapse-all" == id ) { + mProjectTreeView->collapseAll(); + } else if ( "expand-all" == id ) { + mProjectTreeView->expandAll(); + } + } ); + + showProjectTreeMenu(); +} + +void App::toggleHiddenFiles() { + mFileSystemModel = FileSystemModel::New( + mFileSystemModel->getRootPath(), FileSystemModel::Mode::FilesAndDirectories, + { true, true, !mFileSystemModel->getDisplayConfig().ignoreHidden } ); + mProjectTreeView->setModel( mFileSystemModel ); +} + +void App::newFile( const FileInfo& file ) { + UIMessageBox* msgBox = newInputMsgBox( i18n( "create_new_file", "Create new file" ), + i18n( "enter_new_file_name", "Enter new file name:" ) ); + msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, file, msgBox]( const Event* ) { + auto newFilePath( getNewFilePath( file, msgBox ) ); + if ( !FileSystem::fileExists( newFilePath ) ) { + if ( !FileSystem::fileWrite( newFilePath, nullptr, 0 ) ) + errorMsgBox( i18n( "couldnt_create_file", "Couldn't create file." ) ); + msgBox->closeWindow(); + } else { + fileAlreadyExistsMsgBox(); + } + } ); +} + +void App::newFolder( const FileInfo& file ) { + UIMessageBox* msgBox = + newInputMsgBox( i18n( "create_new_folder", "Create new folder" ), + i18n( "enter_new_folder_name", "Enter new folder name:" ) ); + msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, file, msgBox]( const Event* ) { + auto newFolderPath( getNewFilePath( file, msgBox ) ); + if ( !FileSystem::fileExists( newFolderPath ) ) { + if ( !FileSystem::makeDir( newFolderPath ) ) + errorMsgBox( i18n( "couldnt_create_directory", "Couldn't create directory." ) ); + msgBox->closeWindow(); + } else { + fileAlreadyExistsMsgBox(); + } + } ); +} + void App::createProjectTreeMenu( const FileInfo& file ) { if ( mProjectTreeMenu && mProjectTreeMenu->isVisible() ) mProjectTreeMenu->close(); @@ -3035,7 +3142,7 @@ void App::createProjectTreeMenu( const FileInfo& file ) { mProjectTreeMenu->add( i18n( "open_folder", "Open Folder..." ), findIcon( "folder-open" ) ) ->setId( "open_folder" ); } else { - mProjectTreeMenu->add( i18n( "open_fole", "Open File" ), findIcon( "document-open" ) ) + mProjectTreeMenu->add( i18n( "open_folder", "Open File" ), findIcon( "document-open" ) ) ->setId( "open_file" ); mProjectTreeMenu ->add( i18n( "open_containin_folder", "Open Containing Folder..." ), @@ -3076,6 +3183,10 @@ void App::createProjectTreeMenu( const FileInfo& file ) { !mFileSystemModel->getDisplayConfig().ignoreHidden ) ->setId( "show_hidden_files" ); + mProjectTreeMenu->addSeparator(); + mProjectTreeMenu->add( i18n( "collapse_all", "Collapse All" ) )->setId( "collapse-all" ); + mProjectTreeMenu->add( i18n( "expand_all", "Expand All" ) )->setId( "expand-all" ); + mProjectTreeMenu->addEventListener( Event::OnItemClicked, [&, file]( const Event* event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; @@ -3083,34 +3194,9 @@ void App::createProjectTreeMenu( const FileInfo& file ) { std::string id( item->getId() ); if ( "new_file" == id || "new_file_in_place" == id ) { - UIMessageBox* msgBox = - newInputMsgBox( i18n( "create_new_file", "Create new file" ), - i18n( "enter_new_file_name", "Enter new file name:" ) ); - msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, file, msgBox]( const Event* ) { - auto newFilePath( getNewFilePath( file, msgBox ) ); - if ( !FileSystem::fileExists( newFilePath ) ) { - if ( !FileSystem::fileWrite( newFilePath, nullptr, 0 ) ) - errorMsgBox( i18n( "couldnt_create_file", "Couldn't create file." ) ); - msgBox->closeWindow(); - } else { - fileAlreadyExistsMsgBox(); - } - } ); + newFile( file ); } else if ( "new_folder" == id ) { - UIMessageBox* msgBox = - newInputMsgBox( i18n( "create_new_folder", "Create new folder" ), - i18n( "enter_new_folder_name", "Enter new folder name:" ) ); - msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, file, msgBox]( const Event* ) { - auto newFolderPath( getNewFilePath( file, msgBox ) ); - if ( !FileSystem::fileExists( newFolderPath ) ) { - if ( !FileSystem::makeDir( newFolderPath ) ) - errorMsgBox( - i18n( "couldnt_create_directory", "Couldn't create directory." ) ); - msgBox->closeWindow(); - } else { - fileAlreadyExistsMsgBox(); - } - } ); + newFolder( file ); } else if ( "open_file" == id ) { loadFileFromPath( file.getFilepath() ); } else if ( "remove" == id ) { @@ -3163,10 +3249,7 @@ void App::createProjectTreeMenu( const FileInfo& file ) { } else if ( "open_folder" == id ) { Engine::instance()->openURI( file.getFilepath() ); } else if ( "show_hidden_files" == id ) { - mFileSystemModel = FileSystemModel::New( - mFileSystemModel->getRootPath(), FileSystemModel::Mode::FilesAndDirectories, - { true, true, !mFileSystemModel->getDisplayConfig().ignoreHidden } ); - mProjectTreeView->setModel( mFileSystemModel ); + toggleHiddenFiles(); } else if ( "execute_in_terminal" == id ) { UITerminal* term = createNewTerminal( "", nullptr, file.getDirectoryPath() ); if ( !term ) @@ -3174,14 +3257,14 @@ void App::createProjectTreeMenu( const FileInfo& file ) { term->executeFile( file.getFilepath() ); } else if ( "execute_dir_in_terminal" == id ) { createNewTerminal( "", nullptr, file.getDirectoryPath() ); + } else if ( "collapse-all" == id ) { + mProjectTreeView->collapseAll(); + } else if ( "expand-all" == id ) { + mProjectTreeView->expandAll(); } } ); - Vector2f pos( mWindow->getInput()->getMousePosf() ); - mProjectTreeMenu->nodeToWorldTranslation( pos ); - UIMenu::findBestMenuPos( pos, mProjectTreeMenu ); - mProjectTreeMenu->setPixelsPosition( pos ); - mProjectTreeMenu->show(); + showProjectTreeMenu(); } void App::initProjectTreeView( const std::string& path ) { @@ -3225,6 +3308,11 @@ void App::initProjectTreeView( const std::string& path ) { } } } ); + mProjectTreeView->addEventListener( Event::MouseClick, [&]( const Event* event ) { + const MouseEvent* mouseEvent = static_cast( event ); + if ( mouseEvent->getFlags() & EE_BUTTON_RMASK ) + createProjectTreeMenu(); + } ); mProjectTreeView->addEventListener( Event::KeyDown, [&]( const Event* event ) { const KeyEvent* keyEvent = static_cast( event ); if ( keyEvent->getKeyCode() == KEY_F2 ) { diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index a2c800f80..e49685e78 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -94,6 +94,18 @@ class App : public UICodeEditorSplitter::Client { void downloadFileWebDialog(); + void showGlobalSearch(); + + void showFindView(); + + void showProjectTreeMenu(); + + void toggleHiddenFiles(); + + void newFile( const FileInfo& file ); + + void newFolder( const FileInfo& file ); + protected: EE::Window::Window* mWindow{ nullptr }; UISceneNode* mUISceneNode{ nullptr }; @@ -295,6 +307,8 @@ class App : public UICodeEditorSplitter::Client { void createProjectTreeMenu( const FileInfo& file ); + void createProjectTreeMenu(); + void setUIColorScheme( const ColorSchemePreference& colorScheme ); UIMessageBox* errorMsgBox( const String& msg ); diff --git a/src/tools/ecode/globalsearchcontroller.cpp b/src/tools/ecode/globalsearchcontroller.cpp index 0787f496a..76a7742c8 100644 --- a/src/tools/ecode/globalsearchcontroller.cpp +++ b/src/tools/ecode/globalsearchcontroller.cpp @@ -64,6 +64,7 @@ void GlobalSearchController::initGlobalSearchBar( } ); }; auto& kbind = mGlobalSearchBarLayout->getKeyBindings(); + kbind.addKeybindsString( { { mApp->getKeybind( "find-replace" ), "find-replace" } } ); kbind.addKeybindsStringUnordered( keybindings ); UIPushButton* searchButton = mGlobalSearchBarLayout->find( "global_search" ); @@ -159,6 +160,7 @@ void GlobalSearchController::initGlobalSearchBar( mGlobalSearchBarLayout->addCommand( "change-escape-sequence", [&, escapeSequenceChk] { escapeSequenceChk->setChecked( !escapeSequenceChk->isChecked() ); } ); + mGlobalSearchBarLayout->addCommand( "find-replace", [&] { mApp->showFindView(); } ); mGlobalSearchInput->addEventListener( Event::OnPressEnter, [&]( const Event* ) { if ( mGlobalSearchInput->hasFocus() ) { mGlobalSearchBarLayout->execute( "search-in-files" );