@@ -88,6 +88,7 @@ pub fn connect_row_selections(app: &MainWindow) {
8888 selection:: select_items_with_shift ( app) ; // SHIFT + LMB
8989 opener:: open_selected_item ( app) ;
9090 opener:: open_parent_of_selected_item ( app) ;
91+ opener:: open_provided_item ( app) ;
9192}
9293
9394mod opener {
@@ -98,31 +99,36 @@ mod opener {
9899 use crate :: connect_row_selection:: get_write_selection_lock;
99100 use crate :: { Callabler , GuiState , MainWindow } ;
100101
102+ fn open_item ( app : & MainWindow , items_path_str : & [ usize ] , id : usize ) {
103+ let active_tab = app. global :: < GuiState > ( ) . get_active_tab ( ) ;
104+ let model = get_tool_model ( app, active_tab) ;
105+ let model_data = model
106+ . row_data ( id)
107+ . unwrap_or_else ( || panic ! ( "Failed to get row data with id {id}, with model {} items" , model. row_count( ) ) ) ;
108+
109+ let path_to_open = if items_path_str. len ( ) == 1 {
110+ format ! ( "{}" , model_data. val_str. iter( ) . nth( items_path_str[ 0 ] ) . expect( "Cannot find path" ) )
111+ } else {
112+ format ! (
113+ "{}/{}" ,
114+ model_data. val_str. iter( ) . nth( items_path_str[ 0 ] ) . expect( "Cannot find path" ) ,
115+ model_data. val_str. iter( ) . nth( items_path_str[ 1 ] ) . expect( "Cannot find name" )
116+ )
117+ } ;
118+
119+ if let Err ( e) = open:: that ( & path_to_open) {
120+ error ! ( "Failed to open file: {e}" ) ;
121+ } ;
122+ }
123+
101124 fn open_selected_items ( app : & MainWindow , items_path_str : & [ usize ] ) {
102125 let active_tab = app. global :: < GuiState > ( ) . get_active_tab ( ) ;
103126 let mut lock = get_write_selection_lock ( ) ;
104127 let selection = lock. get_mut ( & active_tab) . expect ( "Failed to get selection data" ) ;
105- let model = get_tool_model ( app, active_tab) ;
106128
107129 if selection. selected_rows . len ( ) == 1 {
108130 let id = selection. selected_rows [ 0 ] ;
109- let model_data = model
110- . row_data ( id)
111- . unwrap_or_else ( || panic ! ( "Failed to get row data with id {id}, with model {} items" , model. row_count( ) ) ) ;
112-
113- let path_to_open = if items_path_str. len ( ) == 1 {
114- format ! ( "{}" , model_data. val_str. iter( ) . nth( items_path_str[ 0 ] ) . expect( "Cannot find path" ) )
115- } else {
116- format ! (
117- "{}/{}" ,
118- model_data. val_str. iter( ) . nth( items_path_str[ 0 ] ) . expect( "Cannot find path" ) ,
119- model_data. val_str. iter( ) . nth( items_path_str[ 1 ] ) . expect( "Cannot find name" )
120- )
121- } ;
122-
123- if let Err ( e) = open:: that ( & path_to_open) {
124- error ! ( "Failed to open file: {e}" ) ;
125- } ;
131+ open_item ( app, items_path_str, id) ;
126132 } else {
127133 if selection. selected_rows . is_empty ( ) {
128134 error ! ( "Failed to open selected item, because there is no selected item" ) ;
@@ -149,6 +155,16 @@ mod opener {
149155 open_selected_items ( & app, & [ get_str_path_idx ( active_tab) ] ) ;
150156 } ) ;
151157 }
158+
159+ pub ( crate ) fn open_provided_item ( app : & MainWindow ) {
160+ let a = app. as_weak ( ) ;
161+ app. global :: < Callabler > ( ) . on_row_open_item_with_index ( move |idx| {
162+ let app = a. upgrade ( ) . expect ( "Failed to upgrade app :(" ) ;
163+ let active_tab = app. global :: < GuiState > ( ) . get_active_tab ( ) ;
164+
165+ open_item ( & app, & [ get_str_path_idx ( active_tab) , get_str_name_idx ( active_tab) ] , idx as usize ) ;
166+ } ) ;
167+ }
152168}
153169mod selection {
154170 use slint:: { ComponentHandle , Model } ;
@@ -306,7 +322,7 @@ fn rows_select_all_by_mode(selection: &mut SelectionData, model: &ModelRc<MainLi
306322 if model. row_count ( ) > SELECTED_ROWS_LIMIT || selection. exceeded_limit {
307323 selection. exceeded_limit = true ;
308324 selection. selected_rows . clear ( ) ;
309- selection. number_of_selected_rows = model. iter ( ) . filter ( |e| e. selected_row ) . count ( )
325+ selection. number_of_selected_rows = model. iter ( ) . filter ( |e| e. selected_row ) . count ( ) ;
310326 } else {
311327 selection. selected_rows = model
312328 . iter ( )
@@ -436,7 +452,7 @@ fn row_select_items_with_shift(selection: &mut SelectionData, model: &ModelRc<Ma
436452 selection. exceeded_limit = false ;
437453 selection. selected_rows = new_model
438454 . as_ref ( )
439- . unwrap_or ( & model)
455+ . unwrap_or ( model)
440456 . iter ( )
441457 . enumerate ( )
442458 . filter_map ( |( idx, row) | if row. selected_row { Some ( idx) } else { None } )
@@ -446,7 +462,7 @@ fn row_select_items_with_shift(selection: &mut SelectionData, model: &ModelRc<Ma
446462 new_model
447463}
448464
449- fn rows_reverse_checked_selection ( selection : & mut SelectionData , model : & ModelRc < MainListModel > ) -> Option < ModelRc < MainListModel > > {
465+ fn rows_reverse_checked_selection ( selection : & SelectionData , model : & ModelRc < MainListModel > ) -> Option < ModelRc < MainListModel > > {
450466 if selection. exceeded_limit {
451467 let new_model = model
452468 . iter ( )
@@ -476,9 +492,10 @@ fn rows_reverse_checked_selection(selection: &mut SelectionData, model: &ModelRc
476492
477493#[ cfg( test) ]
478494mod tests {
479- use super :: * ;
480495 use slint:: VecModel ;
481496
497+ use super :: * ;
498+
482499 fn get_main_list_model ( ) -> MainListModel {
483500 MainListModel {
484501 selected_row : false ,
@@ -492,8 +509,8 @@ mod tests {
492509 fn get_model_vec ( items : usize ) -> Vec < MainListModel > {
493510 ( 0 ..items) . map ( |_| get_main_list_model ( ) ) . collect :: < Vec < _ > > ( )
494511 }
495- fn create_model_from_model_vec ( model_vec : & Vec < MainListModel > ) -> ModelRc < MainListModel > {
496- ModelRc :: new ( VecModel :: from ( model_vec. clone ( ) ) )
512+ fn create_model_from_model_vec ( model_vec : & [ MainListModel ] ) -> ModelRc < MainListModel > {
513+ ModelRc :: new ( VecModel :: from ( model_vec. to_owned ( ) ) )
497514 }
498515
499516 #[ test]
@@ -739,13 +756,13 @@ mod tests {
739756 model[ 1 ] . selected_row = true ;
740757 let model = create_model_from_model_vec ( & model) ;
741758
742- let mut selection = SelectionData {
759+ let selection = SelectionData {
743760 number_of_selected_rows : 2 ,
744761 selected_rows : vec ! [ 0 , 1 ] ,
745762 exceeded_limit : false ,
746763 } ;
747764
748- let new_model = rows_reverse_checked_selection ( & mut selection, & model) ;
765+ let new_model = rows_reverse_checked_selection ( & selection, & model) ;
749766
750767 assert ! ( new_model. is_none( ) ) ;
751768 assert ! ( model. row_data( 0 ) . unwrap( ) . checked) ;
@@ -760,13 +777,13 @@ mod tests {
760777 model[ 1 ] . selected_row = true ;
761778 let model = create_model_from_model_vec ( & model) ;
762779
763- let mut selection = SelectionData {
780+ let selection = SelectionData {
764781 number_of_selected_rows : 2 ,
765782 selected_rows : vec ! [ ] ,
766783 exceeded_limit : true ,
767784 } ;
768785
769- let new_model = rows_reverse_checked_selection ( & mut selection, & model) ;
786+ let new_model = rows_reverse_checked_selection ( & selection, & model) ;
770787
771788 assert ! ( new_model. is_some( ) ) ;
772789 let new_model = new_model. unwrap ( ) ;
0 commit comments