@ -27,10 +27,12 @@ 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 ( vpaned ) ;
directory_and_notebook_panes . pack1 ( * Singleton : : directories ( ) , Gtk : : SHRINK ) ;
@ -87,26 +89,7 @@ Window::Window() : 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/SourceIndentation/SourceIndentationAutoIndentBuffer")))
menu_item - > set_sensitive ( ( bool ) notebook . get_current_view ( ) - > auto_indent ) ;
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 ) ;
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 ) ; */
activate_menu_items ( ) ;
Singleton : : directories ( ) - > select ( notebook . get_current_view ( ) - > file_path ) ;
@ -145,11 +128,14 @@ Window::Window() : compiling(false) {
void Window : : configure ( ) {
MainConfig ( ) ; // Read the configs here
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 : : set_menu_actions ( ) {
@ -276,33 +262,8 @@ void Window::set_menu_actions() {
}
} ) ;
/*
menu . action_group - > add ( Gtk : : Action : : create ( " EditCopy " , " Copy " ) , Gtk : : AccelKey ( 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 ( 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 ( 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 ( key_map [ " edit_find " ] ) , [ this ] ( ) {
search_and_replace_entry ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " EditUndo " , " Undo " ) , Gtk : : AccelKey ( 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 ( ) ) {
@ -311,7 +272,7 @@ void Window::set_menu_actions() {
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " EditRedo " , " Redo " ) , Gtk : : AccelKey ( 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 ( ) ) {
@ -321,31 +282,58 @@ void Window::set_menu_actions() {
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceSpellCheck " , " Spell Check " ) ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceSpellCheckBuffer " , " Spell Check Buffer " ) , Gtk : : AccelKey ( 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 ( 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 ( 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 ( 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 ( key_map [ " source_indentation_auto_indent_buffer " ] ) , [ this ] ( ) {
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 ( 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 ( 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 ( ) ;
@ -353,44 +341,8 @@ void Window::set_menu_actions() {
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 ( 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 ) ;
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 . action_group - > add ( Gtk : : Action : : create ( " SourceGotoMethod " , " Go to Method " ) , Gtk : : AccelKey ( 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 ( key_map [ " source_rename " ] ) , [ this ] ( ) {
rename_token_entry ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceFindDocumentation " , " Find Documentation " ) , Gtk : : AccelKey ( 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 ( ) ;
@ -430,14 +382,53 @@ void Window::set_menu_actions() {
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoNextDiagnostic " , " Go to next Diagnostic " ) , Gtk : : AccelKey ( 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 ( 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 ( ) ;
@ -445,7 +436,8 @@ void Window::set_menu_actions() {
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectCompileAndRun " , " Compile and Run " ) , Gtk : : AccelKey ( 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 ) ;
@ -485,7 +477,7 @@ void Window::set_menu_actions() {
}
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " Proje ctC ompile" , " Compile " ) , Gtk : : AccelKey ( 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 ) ;
@ -497,7 +489,8 @@ void Window::set_menu_actions() {
} ) ;
}
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectRunCommand " , " Run Command " ) , Gtk : : AccelKey ( 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 ( ) ;
@ -532,29 +525,21 @@ void Window::set_menu_actions() {
} ) ;
entry_box . show ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectKillLastRunning " , " Kill Last Process " ) , Gtk : : AccelKey ( 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 ( 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 ( 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 ( 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 ( 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 )
@ -562,7 +547,31 @@ void Window::set_menu_actions() {
notebook . open ( notebook . get_view ( previous_page ) - > file_path ) ;
}
} ) ;
*/
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 ) {