@ -14,6 +14,58 @@ Window::Window() : notebook(), plugin_api(¬ebook), box(Gtk::ORIENTATION_VERTI
add ( box ) ;
add ( box ) ;
//TODO: see TODO Window::on_directory_navigation
//TODO: see TODO Window::on_directory_navigation
directories . m_TreeView . signal_row_activated ( ) . connect ( sigc : : mem_fun ( * this , & Window : : on_directory_navigation ) ) ;
directories . m_TreeView . signal_row_activated ( ) . connect ( sigc : : mem_fun ( * this , & Window : : on_directory_navigation ) ) ;
add_menu ( ) ;
box . pack_start ( entry_box , Gtk : : PACK_SHRINK ) ;
directory_and_notebook_panes . pack1 ( directories . widget ( ) , true , true ) ; //TODO: should be pack1(directories, ...) Clean up directories.*
directory_and_notebook_panes . pack2 ( notebook ) ;
directory_and_notebook_panes . set_position ( 120 ) ;
vpaned . set_position ( 300 ) ;
vpaned . pack1 ( directory_and_notebook_panes , true , false ) ;
vpaned . pack2 ( Singleton : : terminal ( ) - > view , true , true ) ;
box . pack_end ( vpaned ) ;
show_all_children ( ) ;
entry_box . signal_show ( ) . connect ( [ this ] ( ) {
std : : vector < Gtk : : Widget * > focus_chain ;
focus_chain . emplace_back ( & entry_box ) ;
box . set_focus_chain ( focus_chain ) ;
} ) ;
entry_box . signal_hide ( ) . connect ( [ this ] ( ) {
box . unset_focus_chain ( ) ;
} ) ;
entry_box . signal_hide ( ) . connect ( [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
notebook . get_current_view ( ) - > grab_focus ( ) ;
}
} ) ;
notebook . signal_switch_page ( ) . connect ( [ this ] ( Gtk : : Widget * page , guint page_num ) {
if ( search_entry_shown & & entry_box . labels . size ( ) > 0 & & notebook . get_current_page ( ) ! = - 1 ) {
notebook . get_current_view ( ) - > update_search_occurrences = [ this ] ( int number ) {
entry_box . labels . begin ( ) - > update ( 0 , std : : to_string ( number ) ) ;
} ;
notebook . get_current_view ( ) - > search_highlight ( last_search , case_sensitive_search , regex_search ) ;
}
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceGotoDeclaration " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > get_declaration_location ) ;
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceGotoMethod " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > goto_method ) ;
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceRename " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > rename_similar_tokens ) ;
}
} ) ;
INFO ( " Window created " ) ;
} // Window constructor
void Window : : add_menu ( ) {
auto menu = Singleton : : menu ( ) ;
auto menu = Singleton : : menu ( ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " FileQuit " , " Quit juCi++ " ) , Gtk : : AccelKey ( menu - > key_map [ " quit " ] ) , [ this ] ( ) {
menu - > action_group - > add ( Gtk : : Action : : create ( " FileQuit " , " Quit juCi++ " ) , Gtk : : AccelKey ( menu - > key_map [ " quit " ] ) , [ this ] ( ) {
hide ( ) ;
hide ( ) ;
@ -46,65 +98,64 @@ Window::Window() : notebook(), plugin_api(¬ebook), box(Gtk::ORIENTATION_VERTI
auto widget = get_focus ( ) ;
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > cut_clipboard ( ) ;
entry - > cut_clipboard ( ) ;
else {
else if ( notebook . get_current_page ( ) ! = - 1 )
if ( notebook . size ( ) ! = 0 )
notebook . get_current_view ( ) - > get_buffer ( ) - > cut_clipboard ( Gtk : : Clipboard : : get ( ) ) ;
notebook . get_current_view ( ) - > get_buffer ( ) - > cut_clipboard ( Gtk : : Clipboard : : get ( ) ) ;
}
} ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " EditPaste " , " Paste " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_paste " ] ) , [ this ] ( ) {
menu - > action_group - > add ( Gtk : : Action : : create ( " EditPaste " , " Paste " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_paste " ] ) , [ this ] ( ) {
auto widget = get_focus ( ) ;
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > paste_clipboard ( ) ;
entry - > paste_clipboard ( ) ;
else {
else if ( notebook . get_current_page ( ) ! = - 1 )
if ( notebook . size ( ) ! = 0 )
notebook . get_current_view ( ) - > get_buffer ( ) - > paste_clipboard ( Gtk : : Clipboard : : get ( ) ) ;
notebook . get_current_view ( ) - > get_buffer ( ) - > paste_clipboard ( Gtk : : Clipboard : : get ( ) ) ;
}
} ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " EditFind " , " Find " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_find " ] ) , [ this ] ( ) {
menu - > action_group - > add ( Gtk : : Action : : create ( " EditFind " , " Find " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_find " ] ) , [ this ] ( ) {
search_and_replace_entry ( ) ;
search_and_replace_entry ( ) ;
} ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " EditUndo " , " Undo " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_undo " ] ) , [ this ] ( ) {
INFO ( " On undo " ) ;
if ( notebook . get_current_page ( ) ! = - 1 ) {
auto undo_manager = notebook . get_current_view ( ) - > get_source_buffer ( ) - > get_undo_manager ( ) ;
if ( undo_manager - > can_undo ( ) ) {
undo_manager - > undo ( ) ;
}
}
INFO ( " Done undo " ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " EditRedo " , " Redo " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_redo " ] ) , [ this ] ( ) {
INFO ( " On Redo " ) ;
if ( notebook . get_current_page ( ) ! = - 1 ) {
auto undo_manager = notebook . get_current_view ( ) - > get_source_buffer ( ) - > get_undo_manager ( ) ;
if ( undo_manager - > can_redo ( ) ) {
undo_manager - > redo ( ) ;
}
}
INFO ( " Done Redo " ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " SourceRename " , " Rename function/variable " ) , Gtk : : AccelKey ( menu - > key_map [ " source_rename " ] ) , [ this ] ( ) {
menu - > action_group - > add ( Gtk : : Action : : create ( " SourceGotoDeclaration " , " Go to declaration " ) , Gtk : : AccelKey ( menu - > key_map [ " source_goto_declaration " ] ) , [ this ] ( ) {
entry_box . clear ( ) ;
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > get_token & & notebook . get_current_view ( ) - > get_token_name ) {
if ( notebook . get_current_view ( ) - > get_declaration_location ) {
auto token = std : : make_shared < std : : string > ( notebook . get_current_view ( ) - > get_token ( ) ) ;
auto location = notebook . get_current_view ( ) - > get_declaration_location ( ) ;
if ( token - > size ( ) > 0 & & notebook . get_current_view ( ) - > get_token_name ) {
if ( location . first . size ( ) > 0 ) {
auto token_name = std : : make_shared < std : : string > ( notebook . get_current_view ( ) - > get_token_name ( ) ) ;
notebook . open ( location . first ) ;
for ( int c = 0 ; c < notebook . size ( ) ; c + + ) {
notebook . get_current_view ( ) - > get_buffer ( ) - > place_cursor ( notebook . get_current_view ( ) - > get_buffer ( ) - > get_iter_at_offset ( location . second ) ) ;
if ( notebook . get_view ( c ) - > tag_similar_tokens ) {
while ( gtk_events_pending ( ) )
notebook . get_view ( c ) - > tag_similar_tokens ( * token ) ;
gtk_main_iteration ( ) ;
}
notebook . get_current_view ( ) - > scroll_to ( notebook . get_current_view ( ) - > get_buffer ( ) - > get_insert ( ) , 0.0 , 1.0 , 0.5 ) ;
}
entry_box . labels . emplace_back ( ) ;
auto label_it = entry_box . labels . begin ( ) ;
label_it - > update = [ label_it ] ( int state , const std : : string & message ) {
label_it - > set_text ( " Warning: only opened and parsed tabs will have its content renamed, and modified files will be saved. " ) ;
} ;
label_it - > update ( 0 , " " ) ;
entry_box . entries . emplace_back ( * token_name , [ this , token_name , token ] ( const std : : string & content ) {
if ( notebook . get_current_page ( ) ! = - 1 & & content ! = * token_name ) {
for ( int c = 0 ; c < notebook . size ( ) ; c + + ) {
if ( notebook . get_view ( c ) - > rename_similar_tokens ) {
auto number = notebook . get_view ( c ) - > rename_similar_tokens ( * token , content ) ;
if ( number > 0 ) {
Singleton : : terminal ( ) - > print ( " Replaced " + std : : to_string ( number ) + " occurrences in file " + notebook . get_view ( c ) - > file_path + " \n " ) ;
notebook . save ( c ) ;
}
}
}
entry_box . hide ( ) ;
}
} ) ;
auto entry_it = entry_box . entries . begin ( ) ;
entry_box . buttons . emplace_back ( " Rename " , [ this , entry_it ] ( ) {
entry_it - > activate ( ) ;
} ) ;
entry_box . show ( ) ;
}
}
}
}
}
}
} ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " SourceGotoMethod " , " Go to method " ) , Gtk : : AccelKey ( menu - > key_map [ " source_goto_method " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > goto_method ) {
notebook . get_current_view ( ) - > goto_method ( ) ;
}
}
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " SourceRename " , " Rename " ) , Gtk : : AccelKey ( menu - > key_map [ " source_rename " ] ) , [ this ] ( ) {
rename_token_entry ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " ProjectCompileAndRun " , " Compile And Run " ) , Gtk : : AccelKey ( menu - > key_map [ " compile_and_run " ] ) , [ this ] ( ) {
menu - > action_group - > add ( Gtk : : Action : : create ( " ProjectCompileAndRun " , " Compile And Run " ) , Gtk : : AccelKey ( menu - > key_map [ " compile_and_run " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) = = - 1 )
if ( notebook . get_current_page ( ) = = - 1 )
@ -126,7 +177,6 @@ Window::Window() : notebook(), plugin_api(¬ebook), box(Gtk::ORIENTATION_VERTI
execute . detach ( ) ;
execute . detach ( ) ;
}
}
} ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " ProjectCompile " , " Compile " ) , Gtk : : AccelKey ( menu - > key_map [ " compile " ] ) , [ this ] ( ) {
menu - > action_group - > add ( Gtk : : Action : : create ( " ProjectCompile " , " Compile " ) , Gtk : : AccelKey ( menu - > key_map [ " compile " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) = = - 1 )
if ( notebook . get_current_page ( ) = = - 1 )
return ;
return ;
@ -146,56 +196,14 @@ Window::Window() : notebook(), plugin_api(¬ebook), box(Gtk::ORIENTATION_VERTI
}
}
} ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " WindowCloseTab " , " Close tab " ) , Gtk : : AccelKey ( menu - > key_map [ " close_tab " ] ) , [ this ] ( ) {
notebook . close_current_page ( ) ;
} ) ;
add_accel_group ( menu - > ui_manager - > get_accel_group ( ) ) ;
add_accel_group ( menu - > ui_manager - > get_accel_group ( ) ) ;
menu - > build ( ) ;
menu - > build ( ) ;
box . pack_start ( menu - > get_widget ( ) , Gtk : : PACK_SHRINK ) ;
box . pack_start ( menu - > get_widget ( ) , Gtk : : PACK_SHRINK ) ;
box . pack_start ( entry_box , Gtk : : PACK_SHRINK ) ;
}
directory_and_notebook_panes . pack1 ( directories . widget ( ) , true , true ) ; //TODO: should be pack1(directories, ...) Clean up directories.*
directory_and_notebook_panes . pack2 ( notebook ) ;
directory_and_notebook_panes . set_position ( 120 ) ;
vpaned . set_position ( 300 ) ;
vpaned . pack1 ( directory_and_notebook_panes , true , false ) ;
vpaned . pack2 ( Singleton : : terminal ( ) - > view , true , true ) ;
box . pack_end ( vpaned ) ;
show_all_children ( ) ;
entry_box . signal_show ( ) . connect ( [ this ] ( ) {
std : : vector < Gtk : : Widget * > focus_chain ;
focus_chain . emplace_back ( & entry_box ) ;
box . set_focus_chain ( focus_chain ) ;
} ) ;
entry_box . signal_hide ( ) . connect ( [ this ] ( ) {
box . unset_focus_chain ( ) ;
} ) ;
entry_box . signal_hide ( ) . connect ( [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
notebook . get_current_view ( ) - > grab_focus ( ) ;
}
} ) ;
notebook . signal_switch_page ( ) . connect ( [ this ] ( Gtk : : Widget * page , guint page_num ) {
if ( search_entry_shown & & entry_box . labels . size ( ) > 0 & & notebook . get_current_page ( ) ! = - 1 ) {
notebook . get_current_view ( ) - > update_search_occurrences = [ this ] ( int number ) {
entry_box . labels . begin ( ) - > update ( 0 , std : : to_string ( number ) ) ;
} ;
notebook . get_current_view ( ) - > search_highlight ( last_search , case_sensitive_search , regex_search ) ;
}
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceGotoDeclaration " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > get_declaration_location ) ;
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceGotoMethod " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > goto_method ) ;
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceRename " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > rename_similar_tokens ) ;
}
} ) ;
INFO ( " Window created " ) ;
} // Window constructor
bool Window : : on_key_press_event ( GdkEventKey * event ) {
bool Window : : on_key_press_event ( GdkEventKey * event ) {
if ( event - > keyval = = GDK_KEY_Escape )
if ( event - > keyval = = GDK_KEY_Escape )
@ -485,3 +493,45 @@ void Window::search_and_replace_entry() {
search_entry_shown = true ;
search_entry_shown = true ;
entry_box . show ( ) ;
entry_box . show ( ) ;
}
}
void Window : : rename_token_entry ( ) {
entry_box . clear ( ) ;
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > get_token & & notebook . get_current_view ( ) - > get_token_name ) {
auto token = std : : make_shared < std : : string > ( notebook . get_current_view ( ) - > get_token ( ) ) ;
if ( token - > size ( ) > 0 & & notebook . get_current_view ( ) - > get_token_name ) {
auto token_name = std : : make_shared < std : : string > ( notebook . get_current_view ( ) - > get_token_name ( ) ) ;
for ( int c = 0 ; c < notebook . size ( ) ; c + + ) {
if ( notebook . get_view ( c ) - > tag_similar_tokens ) {
notebook . get_view ( c ) - > tag_similar_tokens ( * token ) ;
}
}
entry_box . labels . emplace_back ( ) ;
auto label_it = entry_box . labels . begin ( ) ;
label_it - > update = [ label_it ] ( int state , const std : : string & message ) {
label_it - > set_text ( " Warning: only opened and parsed tabs will have its content renamed, and modified files will be saved. " ) ;
} ;
label_it - > update ( 0 , " " ) ;
entry_box . entries . emplace_back ( * token_name , [ this , token_name , token ] ( const std : : string & content ) {
if ( notebook . get_current_page ( ) ! = - 1 & & content ! = * token_name ) {
for ( int c = 0 ; c < notebook . size ( ) ; c + + ) {
if ( notebook . get_view ( c ) - > rename_similar_tokens ) {
auto number = notebook . get_view ( c ) - > rename_similar_tokens ( * token , content ) ;
if ( number > 0 ) {
Singleton : : terminal ( ) - > print ( " Replaced " + std : : to_string ( number ) + " occurrences in file " + notebook . get_view ( c ) - > file_path + " \n " ) ;
notebook . save ( c ) ;
}
}
}
entry_box . hide ( ) ;
}
} ) ;
auto entry_it = entry_box . entries . begin ( ) ;
entry_box . buttons . emplace_back ( " Rename " , [ this , entry_it ] ( ) {
entry_it - > activate ( ) ;
} ) ;
entry_box . show ( ) ;
}
}
}
}