@ -22,31 +22,18 @@ namespace sigc {
# endif
}
void Window : : generate_keybindings ( ) {
for ( auto & i : Singleton : : Config : : window ( ) - > keybindings ) {
auto key = i . second . get_value < std : : string > ( ) ;
menu . key_map [ i . first ] = key ;
}
}
Window : : Window ( ) : box ( Gtk : : ORIENTATION_VERTICAL ) , compiling ( false ) {
Window : : Window ( ) : compiling ( false ) {
JDEBUG ( " start " ) ;
set_title ( " juCi++ " ) ;
set_events ( Gdk : : POINTER_MOTION_MASK | Gdk : : FOCUS_CHANGE_MASK | Gdk : : SCROLL_MASK ) ;
set_menu_actions ( ) ;
configure ( ) ;
set_default_size ( Singleton : : Config : : window ( ) - > default_size . first , Singleton : : Config : : window ( ) - > default_size . second ) ;
//PluginApi(&this->notebook, &this->menu);
add ( box ) ;
//TODO: Do not use deprecated ui_manager? And make menu shortcuts update when config.json is saved (in configure())
generate_keybindings ( ) ;
create_menu ( ) ;
menu . build ( ) ;
add_accel_group ( menu . ui_manager - > get_accel_group ( ) ) ;
box . pack_start ( menu . get_widget ( ) , Gtk : : PACK_SHRINK ) ;
add ( vpaned ) ;
directory_and_notebook_panes . pack1 ( * Singleton : : directories ( ) , Gtk : : SHRINK ) ;
notebook_vbox . pack_start ( notebook ) ;
notebook_vbox . pack_end ( entry_box , Gtk : : PACK_SHRINK ) ;
@ -63,7 +50,6 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), compiling(false) {
terminal_vbox . pack_end ( info_and_status_hbox , Gtk : : PACK_SHRINK ) ;
vpaned . pack2 ( terminal_vbox , true , true ) ;
box . pack_end ( vpaned ) ;
show_all_children ( ) ;
Singleton : : directories ( ) - > on_row_activated = [ this ] ( const std : : string & file ) {
@ -78,13 +64,11 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), compiling(false) {
} ) ;
entry_box . signal_show ( ) . connect ( [ this ] ( ) {
box . set_focus_chain ( { & vpaned } ) ;
vpaned . set_focus_chain ( { & directory_and_notebook_panes } ) ;
directory_and_notebook_panes . set_focus_chain ( { & notebook_vbox } ) ;
notebook_vbox . set_focus_chain ( { & entry_box } ) ;
} ) ;
entry_box . signal_hide ( ) . connect ( [ this ] ( ) {
box . unset_focus_chain ( ) ;
vpaned . unset_focus_chain ( ) ;
directory_and_notebook_panes . unset_focus_chain ( ) ;
notebook_vbox . unset_focus_chain ( ) ;
@ -104,24 +88,8 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), compiling(false) {
notebook . get_current_view ( ) - > search_highlight ( last_search , case_sensitive_search , regex_search ) ;
}
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( 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 * > ( 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 * > ( menu . ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceRename " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > rename_similar_tokens ) ;
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( menu . ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceGotoNextDiagnostic " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > goto_next_diagnostic ) ;
activate_menu_items ( ) ;
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( menu . ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceApplyFixIts " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > apply_fix_its ) ;
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( menu . ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceFindDocumentation " ) ) )
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > get_token_data ) ;
Singleton : : directories ( ) - > select ( notebook . get_current_view ( ) - > file_path ) ;
if ( auto source_view = dynamic_cast < Source : : ClangView * > ( notebook . get_current_view ( ) ) ) {
@ -158,54 +126,65 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), compiling(false) {
} // Window constructor
void Window : : configure ( ) {
Singleton : : Config : : main ( ) - > read ( ) ;
auto style_context = Gtk : : StyleContext : : create ( ) ;
auto screen = Gdk : : Screen : : get_default ( ) ;
auto css_provider = Gtk : : CssProvider : : get_named ( Singleton : : Config : : window ( ) - > theme_name , Singleton : : Config : : window ( ) - > theme_variant ) ;
//TODO: add check if theme exists, or else write error to Singleton::terminal()
style_context - > add_provider_for_screen ( screen , css_provider , GTK_STYLE_PROVIDER_PRIORITY_SETTINGS ) ;
Singleton : : menu ( ) - > set_keys ( ) ;
}
void Window : : create_menu ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileQuit " , " Quit juCi++ " ) , Gtk : : AccelKey ( menu . key_map [ " quit " ] ) , [ this ] ( ) {
void Window : : set_menu_actions ( ) {
auto menu = Singleton : : menu ( ) ;
menu - > add_action ( " about " , [ this ] ( ) {
about . show ( ) ;
about . present ( ) ;
} ) ;
menu - > add_action ( " preferences " , [ this ] ( ) {
notebook . open ( Singleton : : Config : : main ( ) - > juci_home_path ( ) / " config " / " config.json " ) ;
} ) ;
menu - > add_action ( " quit " , [ this ] ( ) {
hide ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewFile " , " New File " ) , Gtk : : AccelKey ( menu . key_map [ " new_file " ] ) , [ this ] ( ) {
boost : : filesystem : : path path = Dialog : : new_file ( ) ;
if ( path ! = " " ) {
if ( boost : : filesystem : : exists ( path ) ) {
Singleton : : terminal ( ) - > print ( " Error: " + path . string ( ) + " already exists. \n " ) ;
}
else {
if ( filesystem : : write ( path ) ) {
if ( Singleton : : directories ( ) - > current_path ! = " " )
Singleton : : directories ( ) - > update ( ) ;
notebook . open ( path . string ( ) ) ;
Singleton : : terminal ( ) - > print ( " New file " + path . string ( ) + " created. \n " ) ;
}
else
Singleton : : terminal ( ) - > print ( " Error: could not create new file " + path . string ( ) + " . \n " ) ;
}
menu - > add_action ( " new_file " , [ this ] ( ) {
boost : : filesystem : : path path = Dialog : : new_file ( ) ;
if ( path ! = " " ) {
if ( boost : : filesystem : : exists ( path ) ) {
Singleton : : terminal ( ) - > print ( " Error: " + path . string ( ) + " already exists. \n " ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewFolder " , " New Folder " ) , Gtk : : AccelKey ( menu . key_map [ " new_folder " ] ) , [ this ] ( ) {
auto time_now = std : : chrono : : system_clock : : to_time_t ( std : : chrono : : system_clock : : now ( ) ) ;
boost : : filesystem : : path path = Dialog : : new_folder ( ) ;
if ( path ! = " " & & boost : : filesystem : : exists ( path ) ) {
if ( boost : : filesystem : : last_write_time ( path ) > = time_now ) {
else {
if ( filesystem : : write ( path ) ) {
if ( Singleton : : directories ( ) - > current_path ! = " " )
Singleton : : directories ( ) - > update ( ) ;
Singleton : : terminal ( ) - > print ( " New folder " + path . string ( ) + " created. \n " ) ;
notebook . open ( path . string ( ) ) ;
Singleton : : terminal ( ) - > print ( " New file " + path . string ( ) + " created. \n " ) ;
}
else
Singleton : : terminal ( ) - > print ( " Error: " + path . string ( ) + " already exists. \n " ) ;
Singleton : : terminal ( ) - > print ( " Error: could not create new file " + path . string ( ) + " . \n " ) ;
}
}
} ) ;
menu - > add_action ( " new_folder " , [ this ] ( ) {
auto time_now = std : : chrono : : system_clock : : to_time_t ( std : : chrono : : system_clock : : now ( ) ) ;
boost : : filesystem : : path path = Dialog : : new_folder ( ) ;
if ( path ! = " " & & boost : : filesystem : : exists ( path ) ) {
if ( boost : : filesystem : : last_write_time ( path ) > = time_now ) {
if ( Singleton : : directories ( ) - > current_path ! = " " )
Singleton : : directories ( ) - > update ( ) ;
Singleton : : terminal ( ) - > print ( " New folder " + path . string ( ) + " created. \n " ) ;
}
else
Singleton : : terminal ( ) - > print ( " Error: " + path . string ( ) + " already exists. \n " ) ;
Singleton : : directories ( ) - > select ( path ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewProject " , " New Project " ) ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewProjectCpp " , " C++ " ) , [ this ] ( ) {
boost : : filesystem : : path project_path = Dialog : : new_folder ( ) ;
if ( project_path = = " " )
return ;
menu - > add_action ( " new_project_cpp " , [ this ] ( ) {
boost : : filesystem : : path project_path = Dialog : : new_folder ( ) ;
if ( project_path ! = " " ) {
auto project_name = project_path . filename ( ) . string ( ) ;
for ( size_t c = 0 ; c < project_name . size ( ) ; c + + ) {
if ( project_name [ c ] = = ' ' )
@ -232,74 +211,55 @@ void Window::create_menu() {
}
else
Singleton : : terminal ( ) - > print ( " Error: Could not create project " + project_path . string ( ) + " \n " ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFile " , " Open File " ) , Gtk : : AccelKey ( menu . key_map [ " open_file " ] ) , [ this ] ( ) {
notebook . open ( Dialog : : select_file ( ) ) ;
menu - > add_action ( " open_file " , [ this ] ( ) {
auto path = Dialog : : select_file ( ) ;
if ( path ! = " " )
notebook . open ( path ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFolder " , " Open Folder " ) , Gtk : : AccelKey ( menu . key_map [ " open_folder " ] ) , [ this ] ( ) {
menu - > add_action ( " open_folder " , [ this ] ( ) {
auto path = Dialog : : select_folder ( ) ;
if ( path ! = " " & & boost : : filesystem : : exists ( path ) )
Singleton : : directories ( ) - > open ( path ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileSaveAs " , " Save As " ) , Gtk : : AccelKey ( menu . key_map [ " save_as " ] ) , [ this ] ( ) {
auto path = Dialog : : save_file ( ) ;
if ( path ! = " " ) {
std : : ofstream file ( path ) ;
if ( file ) {
file < < notebook . get_current_view ( ) - > get_buffer ( ) - > get_text ( ) ;
file . close ( ) ;
if ( Singleton : : directories ( ) - > current_path ! = " " )
Singleton : : directories ( ) - > update ( ) ;
notebook . open ( path ) ;
Singleton : : terminal ( ) - > print ( " File saved to: " + notebook . get_current_view ( ) - > file_path . string ( ) + " \n " ) ;
menu - > add_action ( " save " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . save_current ( ) ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > file_path = = Singleton : : Config : : main ( ) - > juci_home_path ( ) / " config " / " config.json " ) {
configure ( ) ;
for ( int c = 0 ; c < notebook . size ( ) ; c + + ) {
notebook . get_view ( c ) - > configure ( ) ;
notebook . configure ( c ) ;
}
}
}
}
else
Singleton : : terminal ( ) - > print ( " Error saving file \n " ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " Preferences " , " Preferences... " ) , Gtk : : AccelKey ( menu . key_map [ " preferences " ] ) , [ this ] ( ) {
notebook . open ( Singleton : : Config : : main ( ) - > juci_home_path ( ) / " config " / " config.json " ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileSave " , " Save " ) , Gtk : : AccelKey ( menu . key_map [ " save " ] ) , [ this ] ( ) {
if ( notebook . save_current ( ) ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > file_path = = Singleton : : Config : : main ( ) - > juci_home_path ( ) / " config " / " config.json " ) {
configure ( ) ;
for ( int c = 0 ; c < notebook . size ( ) ; c + + ) {
notebook . get_view ( c ) - > configure ( ) ;
notebook . configure ( c ) ;
}
menu - > add_action ( " save_as " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
auto path = Dialog : : save_file ( ) ;
if ( path ! = " " ) {
std : : ofstream file ( path ) ;
if ( file ) {
file < < notebook . get_current_view ( ) - > get_buffer ( ) - > get_text ( ) ;
file . close ( ) ;
if ( Singleton : : directories ( ) - > current_path ! = " " )
Singleton : : directories ( ) - > update ( ) ;
notebook . open ( path ) ;
Singleton : : terminal ( ) - > print ( " File saved to: " + notebook . get_current_view ( ) - > file_path . string ( ) + " \n " ) ;
}
else
Singleton : : terminal ( ) - > print ( " Error saving file \n " ) ;
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " EditCopy " , " Copy " ) , Gtk : : AccelKey ( menu . key_map [ " edit_copy " ] ) , [ this ] ( ) {
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > copy_clipboard ( ) ;
else if ( auto text_view = dynamic_cast < Gtk : : TextView * > ( widget ) )
text_view - > get_buffer ( ) - > copy_clipboard ( Gtk : : Clipboard : : get ( ) ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " EditCut " , " Cut " ) , Gtk : : AccelKey ( menu . key_map [ " edit_cut " ] ) , [ this ] ( ) {
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > cut_clipboard ( ) ;
else if ( notebook . get_current_page ( ) ! = - 1 )
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 ] ( ) {
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > paste_clipboard ( ) ;
else if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > paste ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " EditFind " , " Find " ) , Gtk : : AccelKey ( menu . key_map [ " edit_find " ] ) , [ this ] ( ) {
search_and_replace_entry ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " EditUndo " , " Undo " ) , Gtk : : AccelKey ( menu . key_map [ " edit_undo " ] ) , [ this ] ( ) {
menu - > add_action ( " edit_undo " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
auto undo_manager = notebook . get_current_view ( ) - > get_source_buffer ( ) - > get_undo_manager ( ) ;
if ( undo_manager - > can_undo ( ) ) {
@ -308,7 +268,7 @@ void Window::create_menu() {
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " EditRedo " , " Redo " ) , Gtk : : AccelKey ( menu . key_map [ " edit_redo " ] ) , [ this ] ( ) {
menu - > add_action ( " edit_redo " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
auto undo_manager = notebook . get_current_view ( ) - > get_source_buffer ( ) - > get_undo_manager ( ) ;
if ( undo_manager - > can_redo ( ) ) {
@ -317,31 +277,58 @@ void Window::create_menu() {
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceSpellCheck " , " Spell Check " ) ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceSpellCheckBuffer " , " Spell Check Buffer " ) , Gtk : : AccelKey ( menu . key_map [ " source_spellcheck " ] ) , [ this ] ( ) {
menu - > add_action ( " edit_cut " , [ this ] ( ) {
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > cut_clipboard ( ) ;
else if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > get_buffer ( ) - > cut_clipboard ( Gtk : : Clipboard : : get ( ) ) ;
} ) ;
menu - > add_action ( " edit_copy " , [ this ] ( ) {
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > copy_clipboard ( ) ;
else if ( auto text_view = dynamic_cast < Gtk : : TextView * > ( widget ) )
text_view - > get_buffer ( ) - > copy_clipboard ( Gtk : : Clipboard : : get ( ) ) ;
} ) ;
menu - > add_action ( " edit_paste " , [ this ] ( ) {
auto widget = get_focus ( ) ;
if ( auto entry = dynamic_cast < Gtk : : Entry * > ( widget ) )
entry - > paste_clipboard ( ) ;
else if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > paste ( ) ;
} ) ;
menu - > add_action ( " edit_find " , [ this ] ( ) {
search_and_replace_entry ( ) ;
} ) ;
menu - > add_action ( " source_spellcheck " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > spellcheck ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceSpellCheckClear " , " Clear Spelling Errors " ) , Gtk : : AccelKey ( menu . key_map [ " source_spellcheck_clear " ] ) , [ this ] ( ) {
menu - > add_action ( " source_spellcheck_clear " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > remove_spellcheck_errors ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceSpellCheckNextError " , " Go to next Spelling Error " ) , Gtk : : AccelKey ( menu . key_map [ " source_spellcheck_next_error " ] ) , [ this ] ( ) {
menu - > add_action ( " source_spellcheck_next_error " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > goto_next_spellcheck_error ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceIndentation " , " Indentation " ) ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceIndentationSetBufferTab " , " Set Current Buffer Tab " ) , Gtk : : AccelKey ( menu . key_map [ " source_indentation_set_buffer_tab " ] ) , [ this ] ( ) {
menu - > add_action ( " source_indentation_set_buffer_tab " , [ this ] ( ) {
set_tab_entry ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceIndentationAutoIndentBuffer " , " Auto-Indent Current Buffer " ) , Gtk : : AccelKey ( menu . key_map [ " source_indentation_auto_indent_buffer " ] ) , [ this ] ( ) {
Singleton : : terminal ( ) - > print ( " Auto-Indent Current Buffer will soon be implemented. \n " ) ;
menu - > add_action ( " source_indentation_auto_indent_buffer " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 & & notebook . get_current_view ( ) - > auto_indent )
notebook . get_current_view ( ) - > auto_indent ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoLine " , " Go to Line " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_line " ] ) , [ this ] ( ) {
menu - > add_action ( " source_goto_line " , [ this ] ( ) {
goto_line_entry ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceCenterCursor " , " Center Cursor " ) , Gtk : : AccelKey ( menu . key_map [ " source_center_cursor " ] ) , [ this ] ( ) {
menu - > add_action ( " source_center_cursor " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
while ( gtk_events_pending ( ) )
gtk_main_iteration ( ) ;
@ -349,32 +336,8 @@ void Window::create_menu() {
notebook . get_current_view ( ) - > scroll_to ( notebook . get_current_view ( ) - > get_buffer ( ) - > get_insert ( ) , 0.0 , 1.0 , 0.5 ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoDeclaration " , " Go to Declaration " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_declaration " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > get_declaration_location ) {
auto location = notebook . get_current_view ( ) - > get_declaration_location ( ) ;
if ( location . first . size ( ) > 0 ) {
notebook . open ( location . first ) ;
notebook . get_current_view ( ) - > get_buffer ( ) - > place_cursor ( notebook . get_current_view ( ) - > get_buffer ( ) - > get_iter_at_line_index ( location . second . line - 1 , location . second . index - 1 ) ) ;
while ( gtk_events_pending ( ) )
gtk_main_iteration ( ) ;
if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > scroll_to ( notebook . get_current_view ( ) - > get_buffer ( ) - > get_insert ( ) , 0.0 , 1.0 , 0.5 ) ;
}
}
}
} ) ;
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 ( " SourceFindDocumentation " , " Find Documentation " ) , Gtk : : AccelKey ( menu . key_map [ " source_find_documentation " ] ) , [ this ] ( ) {
menu - > add_action ( " source_find_documentation " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > get_token_data ) {
auto data = notebook . get_current_view ( ) - > get_token_data ( ) ;
@ -414,22 +377,61 @@ void Window::create_menu() {
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoNextDiagnostic " , " Go to next Diagnostic " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_next_diagnostic " ] ) , [ this ] ( ) {
menu - > add_action ( " source_goto_declaration " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > get_declaration_location ) {
auto location = notebook . get_current_view ( ) - > get_declaration_location ( ) ;
if ( location . first . size ( ) > 0 ) {
notebook . open ( location . first ) ;
auto line = static_cast < int > ( location . second . line ) - 1 ;
auto index = static_cast < int > ( location . second . index ) - 1 ;
auto buffer = notebook . get_current_view ( ) - > get_buffer ( ) ;
line = std : : min ( line , buffer - > get_line_count ( ) - 1 ) ;
if ( line > = 0 ) {
auto iter = buffer - > get_iter_at_line ( line ) ;
while ( ! iter . ends_line ( ) )
iter . forward_char ( ) ;
auto end_line_index = iter . get_line_index ( ) ;
index = std : : min ( index , end_line_index ) ;
buffer - > place_cursor ( buffer - > get_iter_at_line_index ( line , index ) ) ;
while ( gtk_events_pending ( ) )
gtk_main_iteration ( ) ;
if ( notebook . get_current_page ( ) ! = - 1 )
notebook . get_current_view ( ) - > scroll_to ( notebook . get_current_view ( ) - > get_buffer ( ) - > get_insert ( ) , 0.0 , 1.0 , 0.5 ) ;
}
}
}
}
} ) ;
menu - > add_action ( " source_goto_method " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > goto_method ) {
notebook . get_current_view ( ) - > goto_method ( ) ;
}
}
} ) ;
menu - > add_action ( " source_rename " , [ this ] ( ) {
rename_token_entry ( ) ;
} ) ;
menu - > add_action ( " source_goto_next_diagnostic " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > goto_next_diagnostic ) {
notebook . get_current_view ( ) - > goto_next_diagnostic ( ) ;
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceApplyFixIts " , " Apply Fix-Its " ) , Gtk : : AccelKey ( menu . key_map [ " source_apply_fix_its " ] ) , [ this ] ( ) {
menu - > add_action ( " source_apply_fix_its " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > apply_fix_its ) {
notebook . get_current_view ( ) - > apply_fix_its ( ) ;
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectCompileAndRun " , " Compile and Run " ) , Gtk : : AccelKey ( menu . key_map [ " compile_and_run " ] ) , [ this ] ( ) {
menu - > add_action ( " compile_and_run " , [ this ] ( ) {
if ( notebook . get_current_page ( ) = = - 1 | | compiling )
return ;
CMake cmake ( notebook . get_current_view ( ) - > file_path ) ;
@ -469,7 +471,7 @@ void Window::create_menu() {
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " Proje ctC ompile" , " Compile " ) , Gtk : : AccelKey ( menu . key_map [ " compile " ] ) , [ this ] ( ) {
menu - > add_action ( " compile " , [ this ] ( ) {
if ( notebook . get_current_page ( ) = = - 1 | | compiling )
return ;
CMake cmake ( notebook . get_current_view ( ) - > file_path ) ;
@ -481,7 +483,8 @@ void Window::create_menu() {
} ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectRunCommand " , " Run Command " ) , Gtk : : AccelKey ( menu . key_map [ " run_command " ] ) , [ this ] ( ) {
menu - > add_action ( " run_command " , [ this ] ( ) {
entry_box . clear ( ) ;
entry_box . labels . emplace_back ( ) ;
auto label_it = entry_box . labels . begin ( ) ;
@ -502,7 +505,7 @@ void Window::create_menu() {
else
run_path = Singleton : : directories ( ) - > current_path ;
Singleton : : terminal ( ) - > async_print ( " Running: " + content + ' \n ' ) ;
Singleton : : terminal ( ) - > async_execute ( content , run_path , [ this , content ] ( int exit_code ) {
Singleton : : terminal ( ) - > async_print ( content + " returned: " + std : : to_string ( exit_code ) + ' \n ' ) ;
} ) ;
@ -516,29 +519,20 @@ void Window::create_menu() {
} ) ;
entry_box . show ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectKillLastRunning " , " Kill Last Process " ) , Gtk : : AccelKey ( menu . key_map [ " kill_last_running " ] ) , [ this ] ( ) {
menu - > add_action ( " kill_last_running " , [ this ] ( ) {
Singleton : : terminal ( ) - > kill_last_async_execute ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectForceKillLastRunning " , " Force Kill Last Process " ) , Gtk : : AccelKey ( menu . key_map [ " force_kill_last_running " ] ) , [ this ] ( ) {
menu - > add_action ( " force_kill_last_running " , [ this ] ( ) {
Singleton : : terminal ( ) - > kill_last_async_execute ( true ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " WindowCloseTab " , " Close Tab " ) , Gtk : : AccelKey ( menu . key_map [ " close_tab " ] ) , [ this ] ( ) {
notebook . close_current_page ( ) ;
if ( notebook . get_current_page ( ) ! = - 1 ) {
notebook . get_current_view ( ) - > set_status ( notebook . get_current_view ( ) - > status ) ;
notebook . get_current_view ( ) - > set_info ( notebook . get_current_view ( ) - > info ) ;
}
else {
Singleton : : status ( ) - > set_text ( " " ) ;
Singleton : : info ( ) - > set_text ( " " ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " WindowNextTab " , " Next Tab " ) , Gtk : : AccelKey ( menu . key_map [ " next_tab " ] ) , [ this ] ( ) {
menu - > add_action ( " next_tab " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
notebook . open ( notebook . get_view ( ( notebook . get_current_page ( ) + 1 ) % notebook . size ( ) ) - > file_path ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " WindowPreviousTab " , " Previous Tab " ) , Gtk : : AccelKey ( menu . key_map [ " previous_tab " ] ) , [ this ] ( ) {
menu - > add_action ( " previous_tab " , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
int previous_page = notebook . get_current_page ( ) - 1 ;
if ( previous_page < 0 )
@ -546,10 +540,31 @@ void Window::create_menu() {
notebook . open ( notebook . get_view ( previous_page ) - > file_path ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " HelpAbout " , " About " ) , [ this ] ( ) {
about . show ( ) ;
about . present ( ) ;
menu - > add_action ( " close_tab " , [ this ] ( ) {
notebook . close_current_page ( ) ;
if ( notebook . get_current_page ( ) ! = - 1 ) {
notebook . get_current_view ( ) - > set_status ( notebook . get_current_view ( ) - > status ) ;
notebook . get_current_view ( ) - > set_info ( notebook . get_current_view ( ) - > info ) ;
}
else {
Singleton : : status ( ) - > set_text ( " " ) ;
Singleton : : info ( ) - > set_text ( " " ) ;
activate_menu_items ( false ) ;
}
} ) ;
activate_menu_items ( false ) ;
}
void Window : : activate_menu_items ( bool activate ) {
auto menu = Singleton : : menu ( ) ;
menu - > actions [ " source_indentation_auto_indent_buffer " ] - > set_enabled ( activate ? static_cast < bool > ( notebook . get_current_view ( ) - > auto_indent ) : false ) ;
menu - > actions [ " source_find_documentation " ] - > set_enabled ( activate ? static_cast < bool > ( notebook . get_current_view ( ) - > get_token_data ) : false ) ;
menu - > actions [ " source_goto_declaration " ] - > set_enabled ( activate ? static_cast < bool > ( notebook . get_current_view ( ) - > get_declaration_location ) : false ) ;
menu - > actions [ " source_goto_method " ] - > set_enabled ( activate ? static_cast < bool > ( notebook . get_current_view ( ) - > goto_method ) : false ) ;
menu - > actions [ " source_rename " ] - > set_enabled ( activate ? static_cast < bool > ( notebook . get_current_view ( ) - > rename_similar_tokens ) : false ) ;
menu - > actions [ " source_goto_next_diagnostic " ] - > set_enabled ( activate ? static_cast < bool > ( notebook . get_current_view ( ) - > goto_next_diagnostic ) : false ) ;
menu - > actions [ " source_apply_fix_its " ] - > set_enabled ( activate ? static_cast < bool > ( notebook . get_current_view ( ) - > apply_fix_its ) : false ) ;
}
bool Window : : on_key_press_event ( GdkEventKey * event ) {