| 110 | static constexpr auto LOCATEBAR_MAX_RESULTS = 100; |
| 111 | |
| 112 | UniversalLocator::UniversalLocator( UICodeEditorSplitter* editorSplitter, UISceneNode* sceneNode, |
| 113 | App* app ) : |
| 114 | mSplitter( editorSplitter ), |
| 115 | mUISceneNode( sceneNode ), |
| 116 | mApp( app ), |
| 117 | mCommandPalette( mApp->getThreadPool() ) { |
| 118 | |
| 119 | mLocatorProviders.push_back( |
| 120 | { ">", mUISceneNode->i18n( "search_in_command_palette", "Search in Command Palette" ), |
| 121 | [this]( auto ) { |
| 122 | showCommandPalette(); |
| 123 | return true; |
| 124 | }, |
| 125 | [this]( const Variant&, const ModelEvent* modelEvent ) { |
| 126 | ModelIndex idx( |
| 127 | modelEvent->getModel()->index( modelEvent->getModelIndex().row(), 2 ) ); |
| 128 | if ( idx.isValid() ) { |
| 129 | String cmd = modelEvent->getModel()->data( idx, ModelRole::Display ).toString(); |
| 130 | mApp->runCommand( cmd ); |
| 131 | if ( mSplitter->getCurWidget()->isType( UI_TYPE_CODEEDITOR ) && |
| 132 | mSplitter->curEditorIsNotNull() && |
| 133 | mSplitter->getCurEditor()->getDocument().hasCommand( cmd ) && |
| 134 | !mUISceneNode->getRoot()->getLastChild()->isType( UI_TYPE_WINDOW ) ) |
| 135 | mSplitter->getCurEditor()->setFocus(); |
| 136 | if ( cmd != "open-locatebar" && cmd != "open-workspace-symbol-search" && |
| 137 | cmd != "open-document-symbol-search" && cmd != "go-to-line" && |
| 138 | cmd != "show-open-documents" && cmd != "open-locatebar-glob-search" ) { |
| 139 | hideLocateBar(); |
| 140 | } else { |
| 141 | mLocateInput->setFocus(); |
| 142 | } |
| 143 | } |
| 144 | }, |
| 145 | nullptr, false } ); |
| 146 | |
| 147 | mLocatorProviders.push_back( |
| 148 | { ":", mUISceneNode->i18n( "search_for_workspace_symbols", "Search for Workspace Symbols" ), |
| 149 | [this]( auto ) { |
| 150 | showWorkspaceSymbol(); |
| 151 | return true; |
| 152 | }, |
| 153 | nullptr } ); |
| 154 | |
| 155 | mLocatorProviders.push_back( |
| 156 | { ".", |
| 157 | mUISceneNode->i18n( "search_for_symbols_in_current_document", |
| 158 | "Search for Symbols in Current Document" ), |
| 159 | [this]( auto ) { |
| 160 | showDocumentSymbol(); |
| 161 | return true; |
| 162 | }, |
| 163 | [this]( const Variant&, const ModelEvent* modelEvent ) { |
| 164 | Variant rangeStr( modelEvent->getModel()->data( |
| 165 | modelEvent->getModel()->index( modelEvent->getModelIndex().row(), 1 ), |
| 166 | ModelRole::Custom ) ); |
| 167 | auto range = rangeStr.isValid() ? TextRange::fromString( rangeStr.asStdString() ) |
| 168 | : TextRange(); |
| 169 | if ( !range.isValid() ) |
nothing calls this directly
no test coverage detected