| 857 | } |
| 858 | |
| 859 | void GlobalSearchController::initGlobalSearchTree( UITreeViewGlobalSearch* searchTree ) { |
| 860 | searchTree->addClass( "search_tree" ); |
| 861 | searchTree->setParent( mGlobalSearchLayout ); |
| 862 | searchTree->setVisible( false ); |
| 863 | searchTree->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::Fixed ); |
| 864 | searchTree->setExpanderIconSize( PixelDensity::dpToPx( 20 ) ); |
| 865 | searchTree->setHeadersVisible( false ); |
| 866 | searchTree->setColumnsHidden( |
| 867 | { ProjectSearch::ResultModel::Line, ProjectSearch::ResultModel::ColumnStart }, true ); |
| 868 | searchTree->on( Event::OnModelEvent, [this]( const Event* event ) { |
| 869 | const ModelEvent* modelEvent = static_cast<const ModelEvent*>( event ); |
| 870 | if ( modelEvent->getModelEventType() == ModelEventType::Open ) { |
| 871 | const Model* model = modelEvent->getModel(); |
| 872 | if ( !model ) |
| 873 | return; |
| 874 | if ( mGlobalSearchTreeReplace == mGlobalSearchTree ) { |
| 875 | if ( modelEvent->getTriggerEvent()->getType() == Event::KeyDown ) { |
| 876 | const KeyEvent* keyEvent = |
| 877 | static_cast<const KeyEvent*>( modelEvent->getTriggerEvent() ); |
| 878 | if ( keyEvent->getKeyCode() == KEY_SPACE && |
| 879 | keyEvent->getNode()->isType( UI_TYPE_TREEVIEW_CELL ) ) { |
| 880 | auto* cell = |
| 881 | static_cast<UITreeViewCellGlobalSearch*>( keyEvent->getNode() ); |
| 882 | cell->toggleSelected(); |
| 883 | return; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | Variant vPath( model->data( model->index( modelEvent->getModelIndex().internalId(), |
| 889 | ProjectSearch::ResultModel::FileOrPosition ), |
| 890 | ModelRole::Custom ) ); |
| 891 | if ( vPath.isValid() && vPath.isString() ) { |
| 892 | std::string path( vPath.toString() ); |
| 893 | UITab* tab = mSplitter->isDocumentOpen( path ); |
| 894 | Variant lineNum( |
| 895 | model->data( model->index( modelEvent->getModelIndex().row(), |
| 896 | ProjectSearch::ResultModel::FileOrPosition, |
| 897 | modelEvent->getModelIndex().parent() ), |
| 898 | ModelRole::Custom ) ); |
| 899 | Variant colNum( model->data( model->index( modelEvent->getModelIndex().row(), |
| 900 | ProjectSearch::ResultModel::ColumnStart, |
| 901 | modelEvent->getModelIndex().parent() ), |
| 902 | ModelRole::Custom ) ); |
| 903 | if ( !tab ) { |
| 904 | FileInfo fileInfo( path ); |
| 905 | if ( fileInfo.exists() && fileInfo.isRegularFile() ) |
| 906 | mApp->loadFileFromPath( |
| 907 | path, true, nullptr, |
| 908 | [this, lineNum, colNum]( UICodeEditor*, const std::string& ) { |
| 909 | onLoadDone( lineNum, colNum ); |
| 910 | } ); |
| 911 | } else { |
| 912 | tab->getTabWidget()->setTabSelected( tab ); |
| 913 | onLoadDone( lineNum, colNum ); |
| 914 | } |
| 915 | } |
| 916 | } |
nothing calls this directly
no test coverage detected