mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-30 01:56:31 +03:00
File locator now displays the relative path to the open folder instead of the full path of a file.
Improve universal locator options when no folder is open (fixes SpartanJ/ecode#303).
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "universallocator.hpp"
|
||||
#include "ecode.hpp"
|
||||
#include "pathhelper.hpp"
|
||||
#include "settingsmenu.hpp"
|
||||
#include "universallocator.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -118,33 +118,33 @@ UniversalLocator::UniversalLocator( UICodeEditorSplitter* editorSplitter, UIScen
|
||||
mApp( app ),
|
||||
mCommandPalette( mApp->getThreadPool() ) {
|
||||
|
||||
mLocatorProviders.push_back( {
|
||||
">",
|
||||
mUISceneNode->i18n( "search_in_command_palette", "Search in Command Palette" ),
|
||||
[this]( auto ) {
|
||||
showCommandPalette();
|
||||
return true;
|
||||
},
|
||||
[this]( const Variant&, const ModelEvent* modelEvent ) {
|
||||
ModelIndex idx( modelEvent->getModel()->index( modelEvent->getModelIndex().row(), 2 ) );
|
||||
if ( idx.isValid() ) {
|
||||
String cmd = modelEvent->getModel()->data( idx, ModelRole::Display ).toString();
|
||||
mApp->runCommand( cmd );
|
||||
if ( !mSplitter->getCurWidget()->isType( UI_TYPE_TERMINAL ) ) {
|
||||
if ( mSplitter->curEditorIsNotNull() &&
|
||||
mSplitter->getCurEditor()->getDocument().hasCommand( cmd ) )
|
||||
mSplitter->getCurEditor()->setFocus();
|
||||
}
|
||||
if ( cmd != "open-locatebar" && cmd != "open-workspace-symbol-search" &&
|
||||
cmd != "open-document-symbol-search" && cmd != "go-to-line" &&
|
||||
cmd != "show-open-documents" ) {
|
||||
hideLocateBar();
|
||||
} else {
|
||||
mLocateInput->setFocus();
|
||||
}
|
||||
}
|
||||
},
|
||||
} );
|
||||
mLocatorProviders.push_back(
|
||||
{ ">", mUISceneNode->i18n( "search_in_command_palette", "Search in Command Palette" ),
|
||||
[this]( auto ) {
|
||||
showCommandPalette();
|
||||
return true;
|
||||
},
|
||||
[this]( const Variant&, const ModelEvent* modelEvent ) {
|
||||
ModelIndex idx(
|
||||
modelEvent->getModel()->index( modelEvent->getModelIndex().row(), 2 ) );
|
||||
if ( idx.isValid() ) {
|
||||
String cmd = modelEvent->getModel()->data( idx, ModelRole::Display ).toString();
|
||||
mApp->runCommand( cmd );
|
||||
if ( !mSplitter->getCurWidget()->isType( UI_TYPE_TERMINAL ) ) {
|
||||
if ( mSplitter->curEditorIsNotNull() &&
|
||||
mSplitter->getCurEditor()->getDocument().hasCommand( cmd ) )
|
||||
mSplitter->getCurEditor()->setFocus();
|
||||
}
|
||||
if ( cmd != "open-locatebar" && cmd != "open-workspace-symbol-search" &&
|
||||
cmd != "open-document-symbol-search" && cmd != "go-to-line" &&
|
||||
cmd != "show-open-documents" ) {
|
||||
hideLocateBar();
|
||||
} else {
|
||||
mLocateInput->setFocus();
|
||||
}
|
||||
}
|
||||
},
|
||||
nullptr, false } );
|
||||
|
||||
mLocatorProviders.push_back(
|
||||
{ ":", mUISceneNode->i18n( "search_for_workspace_symbols", "Search for Workspace Symbols" ),
|
||||
@@ -217,14 +217,15 @@ UniversalLocator::UniversalLocator( UICodeEditorSplitter* editorSplitter, UIScen
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} } );
|
||||
},
|
||||
false } );
|
||||
|
||||
mLocatorProviders.push_back( { "o", mUISceneNode->i18n( "open_documents", "Open Documents" ),
|
||||
[this]( auto ) {
|
||||
showOpenDocuments();
|
||||
return true;
|
||||
},
|
||||
nullptr } );
|
||||
nullptr, nullptr, false } );
|
||||
|
||||
// clang-format off
|
||||
mLocatorProviders.push_back( { "sb", mUISceneNode->i18n( "switch_build", "Switch Build" ),
|
||||
@@ -339,27 +340,31 @@ void UniversalLocator::updateFilesTable() {
|
||||
}
|
||||
|
||||
if ( !mApp->isDirTreeReady() ) {
|
||||
mLocateTable->setModel( ProjectDirectoryTree::emptyModel( getLocatorCommands() ) );
|
||||
mLocateTable->setModel(
|
||||
ProjectDirectoryTree::emptyModel( getLocatorCommands(), mApp->getCurrentProject() ) );
|
||||
mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) );
|
||||
} else if ( !mLocateInput->getText().empty() ) {
|
||||
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ )
|
||||
mApp->getDirTree()->asyncFuzzyMatchTree(
|
||||
text, LOCATEBAR_MAX_RESULTS, [this, text]( auto res ) {
|
||||
text, LOCATEBAR_MAX_RESULTS,
|
||||
[this, text]( auto res ) {
|
||||
mUISceneNode->runOnMainThread( [this, res] {
|
||||
mLocateTable->setModel( res );
|
||||
mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) );
|
||||
mLocateTable->scrollToTop();
|
||||
updateLocateBarSync();
|
||||
} );
|
||||
} );
|
||||
},
|
||||
mApp->getCurrentProject() );
|
||||
#else
|
||||
mLocateTable->setModel( mApp->getDirTree()->fuzzyMatchTree( text, LOCATEBAR_MAX_RESULTS ) );
|
||||
mLocateTable->setModel( mApp->getDirTree()->fuzzyMatchTree( text, LOCATEBAR_MAX_RESULTS,
|
||||
mApp->getCurrentProject() ) );
|
||||
mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) );
|
||||
mLocateTable->scrollToTop();
|
||||
#endif
|
||||
} else {
|
||||
mLocateTable->setModel(
|
||||
mApp->getDirTree()->asModel( LOCATEBAR_MAX_RESULTS, getLocatorCommands() ) );
|
||||
mLocateTable->setModel( mApp->getDirTree()->asModel(
|
||||
LOCATEBAR_MAX_RESULTS, getLocatorCommands(), mApp->getCurrentProject() ) );
|
||||
mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) );
|
||||
}
|
||||
}
|
||||
@@ -554,6 +559,10 @@ void UniversalLocator::initLocateBar( UILocateBar* locateBar, UITextInput* locat
|
||||
auto pathAndPos = getPathAndPosition( mLocateInput->getText() );
|
||||
range = { pathAndPos.second, pathAndPos.second };
|
||||
}
|
||||
|
||||
if ( FileSystem::isRelativePath( path ) )
|
||||
path = mApp->getCurrentProject() + path;
|
||||
|
||||
focusOrLoadFile( path, range );
|
||||
mLocateBarLayout->execute( "close-locatebar" );
|
||||
}
|
||||
@@ -618,11 +627,12 @@ void UniversalLocator::showLocateBar() {
|
||||
mLocateInput->setText( "" );
|
||||
|
||||
if ( mApp->getDirTree() && !mLocateTable->getModel() ) {
|
||||
mLocateTable->setModel(
|
||||
mApp->getDirTree()->asModel( LOCATEBAR_MAX_RESULTS, getLocatorCommands() ) );
|
||||
mLocateTable->setModel( mApp->getDirTree()->asModel(
|
||||
LOCATEBAR_MAX_RESULTS, getLocatorCommands(), mApp->getCurrentProject() ) );
|
||||
mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) );
|
||||
} else if ( !mLocateTable->getModel() ) {
|
||||
mLocateTable->setModel( ProjectDirectoryTree::emptyModel( getLocatorCommands() ) );
|
||||
mLocateTable->setModel(
|
||||
ProjectDirectoryTree::emptyModel( getLocatorCommands(), mApp->getCurrentProject() ) );
|
||||
mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) );
|
||||
}
|
||||
|
||||
@@ -1130,8 +1140,12 @@ void UniversalLocator::asyncFuzzyMatchTextDocumentSymbol(
|
||||
std::vector<ProjectDirectoryTree::CommandInfo> UniversalLocator::getLocatorCommands() const {
|
||||
std::vector<ProjectDirectoryTree::CommandInfo> vec;
|
||||
UIIcon* icon = mUISceneNode->findIcon( "chevron-right" );
|
||||
for ( const auto& locator : mLocatorProviders )
|
||||
bool isOpenFolder = mApp->getCurrentProject().empty();
|
||||
for ( const auto& locator : mLocatorProviders ) {
|
||||
if ( !isOpenFolder && locator.projectNeeded )
|
||||
continue;
|
||||
vec.push_back( { locator.symbolTrigger, locator.description, icon } );
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user