@ -16,9 +16,10 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL) {
set_events ( Gdk : : POINTER_MOTION_MASK | Gdk : : FOCUS_CHANGE_MASK | Gdk : : SCROLL_MASK ) ;
add ( box ) ;
MainConfig ( ) ; //Read the configs here
PluginApi ( & this - > notebook ) ; //Initialise plugins
add_menu ( ) ;
MainConfig ( this - > menu ) ; //Read the configs here
PluginApi ( & this - > notebook , & this - > menu ) ; //Initialise plugins
create_menu ( ) ;
box . pack_start ( menu . get_widget ( ) , Gtk : : PACK_SHRINK ) ;
box . pack_start ( entry_box , Gtk : : PACK_SHRINK ) ;
@ -59,67 +60,66 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL) {
}
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( auto menu_item = dynamic_cast < Gtk : : MenuItem * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceGotoDeclaration " ) ) )
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 * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceGotoMethod " ) ) )
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 * > ( Singleton : : menu ( ) - > ui_manager - > get_widget ( " /MenuBar/SourceMenu/SourceRename " ) ) )
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 ) ;
}
} ) ;
INFO ( " Window created " ) ;
} // Window constructor
void Window : : add_menu ( ) {
auto menu = Singleton : : menu ( ) ;
void Window : : create_menu ( ) {
INFO ( " Adding actions to 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 ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " FileNewFile " , " New file " ) , Gtk : : AccelKey ( menu - > key_map [ " new_file " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewFile " , " New file " ) , Gtk : : AccelKey ( menu . key_map [ " new_file " ] ) , [ this ] ( ) {
new_file_entry ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " FileOpenFile " , " Open file " ) , Gtk : : AccelKey ( menu - > key_map [ " open_file " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFile " , " Open file " ) , Gtk : : AccelKey ( menu . key_map [ " open_file " ] ) , [ this ] ( ) {
open_file_dialog ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " FileOpenFolder " , " Open folder " ) , Gtk : : AccelKey ( menu - > key_map [ " open_folder " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFolder " , " Open folder " ) , Gtk : : AccelKey ( menu . key_map [ " open_folder " ] ) , [ this ] ( ) {
open_folder_dialog ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " FileSaveAs " , " Save as " ) , Gtk : : AccelKey ( menu - > key_map [ " save_as " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileSaveAs " , " Save as " ) , Gtk : : AccelKey ( menu . key_map [ " save_as " ] ) , [ this ] ( ) {
save_file_dialog ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " FileSave " , " Save " ) , Gtk : : AccelKey ( menu - > key_map [ " save " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileSave " , " Save " ) , Gtk : : AccelKey ( menu . key_map [ " save " ] ) , [ this ] ( ) {
notebook . save_current ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " EditCopy " , " Copy " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_copy " ] ) , [ this ] ( ) {
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 ] ( ) {
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 ] ( ) {
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 ( ) - > 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 ( ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " EditUndo " , " Undo " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_undo " ] ) , [ this ] ( ) {
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 ( ) ;
@ -129,7 +129,7 @@ void Window::add_menu() {
}
INFO ( " Done undo " ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " EditRedo " , " Redo " ) , Gtk : : AccelKey ( menu - > key_map [ " edit_redo " ] ) , [ this ] ( ) {
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 ( ) ;
@ -140,7 +140,7 @@ void Window::add_menu() {
INFO ( " Done Redo " ) ;
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " SourceGotoDeclaration " , " Go to declaration " ) , Gtk : : AccelKey ( menu - > key_map [ " source_goto_declaration " ] ) , [ this ] ( ) {
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 ( ) ;
@ -154,18 +154,18 @@ void Window::add_menu() {
}
}
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " SourceGotoMethod " , " Go to method " ) , Gtk : : AccelKey ( menu - > key_map [ " source_goto_method " ] ) , [ this ] ( ) {
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 ] ( ) {
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 )
return ;
notebook . save_current ( ) ;
@ -185,7 +185,7 @@ void Window::add_menu() {
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 )
return ;
notebook . save_current ( ) ;
@ -204,13 +204,12 @@ void Window::add_menu() {
}
} ) ;
menu - > action_group - > add ( Gtk : : Action : : create ( " WindowCloseTab " , " Close tab " ) , Gtk : : AccelKey ( menu - > key_map [ " close_tab " ] ) , [ this ] ( ) {
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 ( ) ) ;
menu - > build ( ) ;
add_accel_group ( menu . ui_manager - > get_accel_group ( ) ) ;
menu . build ( ) ;
INFO ( " Menu build " )
box . pack_start ( menu - > get_widget ( ) , Gtk : : PACK_SHRINK ) ;
}
bool Window : : on_key_press_event ( GdkEventKey * event ) {