@ -108,20 +108,23 @@ void Window::create_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 ( ) ;
} ) ;
} ) ;
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 ( ) ;
new_file_dialog ( ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewFolder " , " New Folder " ) , Gtk : : AccelKey ( menu . key_map [ " new_folder " ] ) , [ this ] ( ) {
new_folder_dialog ( ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewProject " , " New Project " ) ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewProject " , " New Project " ) ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewProjectCpp " , " C++ " ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileNewProjectCpp " , " C++ " ) , [ this ] ( ) {
new_cpp_project_dialog ( ) ;
new_cpp_project_dialog ( ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFile " , " Open f ile " ) , Gtk : : AccelKey ( menu . key_map [ " open_file " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFile " , " Open F ile " ) , Gtk : : AccelKey ( menu . key_map [ " open_file " ] ) , [ this ] ( ) {
open_file_dialog ( ) ;
open_file_dialog ( ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFolder " , " Open f older " ) , Gtk : : AccelKey ( menu . key_map [ " open_folder " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileOpenFolder " , " Open F older " ) , Gtk : : AccelKey ( menu . key_map [ " open_folder " ] ) , [ this ] ( ) {
open_folder_dialog ( ) ;
open_folder_dialog ( ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " FileSaveAs " , " Save a s " ) , Gtk : : AccelKey ( menu . key_map [ " save_as " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " FileSaveAs " , " Save A s " ) , Gtk : : AccelKey ( menu . key_map [ " save_as " ] ) , [ this ] ( ) {
save_file_dialog ( ) ;
save_file_dialog ( ) ;
} ) ;
} ) ;
@ -174,17 +177,17 @@ void Window::create_menu() {
INFO ( " Done Redo " ) ;
INFO ( " Done Redo " ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoLine " , " Go to l ine " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_line " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoLine " , " Go to L ine " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_line " ] ) , [ this ] ( ) {
goto_line_entry ( ) ;
goto_line_entry ( ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceCenterCursor " , " Center c ursor " ) , Gtk : : AccelKey ( menu . key_map [ " source_center_cursor " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " SourceCenterCursor " , " Center C ursor " ) , Gtk : : AccelKey ( menu . key_map [ " source_center_cursor " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
while ( gtk_events_pending ( ) )
while ( gtk_events_pending ( ) )
gtk_main_iteration ( ) ;
gtk_main_iteration ( ) ;
notebook . get_current_view ( ) - > scroll_to ( notebook . get_current_view ( ) - > get_buffer ( ) - > get_insert ( ) , 0.0 , 1.0 , 0.5 ) ;
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 d eclaration " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_declaration " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoDeclaration " , " Go to D eclaration " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_declaration " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > get_declaration_location ) {
if ( notebook . get_current_view ( ) - > get_declaration_location ) {
auto location = notebook . get_current_view ( ) - > get_declaration_location ( ) ;
auto location = notebook . get_current_view ( ) - > get_declaration_location ( ) ;
@ -198,7 +201,7 @@ void Window::create_menu() {
}
}
}
}
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoMethod " , " Go to m ethod " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_method " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " SourceGotoMethod " , " Go to M ethod " ) , Gtk : : AccelKey ( menu . key_map [ " source_goto_method " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_page ( ) ! = - 1 ) {
if ( notebook . get_current_view ( ) - > goto_method ) {
if ( notebook . get_current_view ( ) - > goto_method ) {
notebook . get_current_view ( ) - > goto_method ( ) ;
notebook . get_current_view ( ) - > goto_method ( ) ;
@ -209,7 +212,7 @@ void Window::create_menu() {
rename_token_entry ( ) ;
rename_token_entry ( ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectCompileAndRun " , " Compile A nd Run " ) , Gtk : : AccelKey ( menu . key_map [ " compile_and_run " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " ProjectCompileAndRun " , " Compile a nd Run " ) , Gtk : : AccelKey ( menu . key_map [ " compile_and_run " ] ) , [ this ] ( ) {
if ( notebook . get_current_page ( ) = = - 1 | | compiling )
if ( notebook . get_current_page ( ) = = - 1 | | compiling )
return ;
return ;
CMake cmake ( notebook . get_current_view ( ) - > file_path ) ;
CMake cmake ( notebook . get_current_view ( ) - > file_path ) ;
@ -289,7 +292,7 @@ void Window::create_menu() {
Singleton : : terminal ( ) - > kill_last_async_execute ( true ) ;
Singleton : : terminal ( ) - > kill_last_async_execute ( true ) ;
} ) ;
} ) ;
menu . action_group - > add ( Gtk : : Action : : create ( " WindowCloseTab " , " Close t ab " ) , Gtk : : AccelKey ( menu . key_map [ " close_tab " ] ) , [ this ] ( ) {
menu . action_group - > add ( Gtk : : Action : : create ( " WindowCloseTab " , " Close T ab " ) , Gtk : : AccelKey ( menu . key_map [ " close_tab " ] ) , [ this ] ( ) {
notebook . close_current_page ( ) ;
notebook . close_current_page ( ) ;
} ) ;
} ) ;
add_accel_group ( menu . ui_manager - > get_accel_group ( ) ) ;
add_accel_group ( menu . ui_manager - > get_accel_group ( ) ) ;
@ -346,35 +349,62 @@ void Window::hide() {
Gtk : : Window : : hide ( ) ;
Gtk : : Window : : hide ( ) ;
}
}
void Window : : new_file_entry ( ) {
void Window : : new_file_dialog ( ) {
entry_box . clear ( ) ;
Gtk : : FileChooserDialog dialog ( " Please create a new file " , Gtk : : FILE_CHOOSER_ACTION_SAVE ) ;
entry_box . entries . emplace_back ( " untitled " , [ this ] ( const std : : string & content ) {
if ( directories . current_path ! = " " )
std : : string filename = content ;
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , directories . current_path . string ( ) . c_str ( ) ) ;
if ( filename ! = " " ) {
else
if ( directories . current_path ! = " " & & ! boost : : filesystem : : path ( filename ) . is_absolute ( ) )
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
filename = directories . current_path . string ( ) + " / " + filename ;
dialog . set_transient_for ( * this ) ;
boost : : filesystem : : path p ( filename ) ;
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
if ( boost : : filesystem : : exists ( p ) ) {
dialog . add_button ( " Cancel " , Gtk : : RESPONSE_CANCEL ) ;
Singleton : : terminal ( ) - > print ( " Error: " + p . string ( ) + " already exists. \n " ) ;
dialog . add_button ( " Save " , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
boost : : filesystem : : path path = dialog . get_filename ( ) ;
if ( path ! = " " ) {
if ( boost : : filesystem : : exists ( path ) ) {
Singleton : : terminal ( ) - > print ( " Error: " + path . string ( ) + " already exists. \n " ) ;
}
}
else {
else {
if ( juci : : filesystem : : write ( p ) ) {
if ( juci : : filesystem : : write ( path ) ) {
if ( directories . current_path ! = " " )
if ( directories . current_path ! = " " )
directories . update ( ) ;
directories . update ( ) ;
notebook . open ( boost : : filesystem : : canonical ( p ) . string ( ) ) ;
notebook . open ( path . string ( ) ) ;
Singleton : : terminal ( ) - > print ( " New file " + p . string ( ) + " created. \n " ) ;
Singleton : : terminal ( ) - > print ( " New file " + path . string ( ) + " created. \n " ) ;
}
}
else
else
Singleton : : terminal ( ) - > print ( " Error: could not create new file " + p . string ( ) + " . \n " ) ;
Singleton : : terminal ( ) - > print ( " Error: could not create new file " + path . string ( ) + " . \n " ) ;
}
}
}
}
}
entry_box . hide ( ) ;
}
} ) ;
auto entry_it = entry_box . entries . begin ( ) ;
void Window : : new_folder_dialog ( ) {
entry_box . buttons . emplace_back ( " Create file " , [ this , entry_it ] ( ) {
auto time_now = std : : chrono : : system_clock : : to_time_t ( std : : chrono : : system_clock : : now ( ) ) ;
entry_it - > activate ( ) ;
Gtk : : FileChooserDialog dialog ( " Please create a new folder " , Gtk : : FILE_CHOOSER_ACTION_CREATE_FOLDER ) ;
} ) ;
if ( directories . current_path ! = " " )
entry_box . show ( ) ;
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , directories . current_path . string ( ) . c_str ( ) ) ;
else
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
dialog . set_transient_for ( * this ) ;
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
dialog . add_button ( " Cancel " , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " Create " , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
boost : : filesystem : : path path = dialog . get_filename ( ) ;
if ( boost : : filesystem : : last_write_time ( path ) > = time_now ) {
if ( directories . current_path ! = " " )
directories . update ( ) ;
Singleton : : terminal ( ) - > print ( " New folder " + path . string ( ) + " created. \n " ) ;
}
else
Singleton : : terminal ( ) - > print ( " Error: " + path . string ( ) + " already exists. \n " ) ;
directories . select ( path ) ;
}
}
}
void Window : : new_cpp_project_dialog ( ) {
void Window : : new_cpp_project_dialog ( ) {
@ -384,9 +414,9 @@ void Window::new_cpp_project_dialog() {
else
else
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
dialog . set_transient_for ( * this ) ;
dialog . set_transient_for ( * this ) ;
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
dialog . add_button ( " _ Cancel" , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " Cancel " , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " Select " , Gtk : : RESPONSE_OK ) ;
dialog . add_button ( " Create " , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
if ( result = = Gtk : : RESPONSE_OK ) {
@ -427,9 +457,9 @@ void Window::open_folder_dialog() {
else
else
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
dialog . set_transient_for ( * this ) ;
dialog . set_transient_for ( * this ) ;
//Add response buttons the the dialog:
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
dialog . add_button ( " _ Cancel" , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " Cancel " , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " Select " , Gtk : : RESPONSE_OK ) ;
dialog . add_button ( " Open " , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
int result = dialog . run ( ) ;
@ -447,28 +477,8 @@ void Window::open_file_dialog() {
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
gtk_file_chooser_set_current_folder ( ( GtkFileChooser * ) dialog . gobj ( ) , boost : : filesystem : : current_path ( ) . string ( ) . c_str ( ) ) ;
dialog . set_transient_for ( * this ) ;
dialog . set_transient_for ( * this ) ;
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
dialog . add_button ( " Cancel " , Gtk : : RESPONSE_CANCEL ) ;
//Add response buttons the the dialog:
dialog . add_button ( " Open " , Gtk : : RESPONSE_OK ) ;
dialog . add_button ( " _Cancel " , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " _Open " , Gtk : : RESPONSE_OK ) ;
//Add filters, so that only certain file types can be selected:
Glib : : RefPtr < Gtk : : FileFilter > filter_text = Gtk : : FileFilter : : create ( ) ;
filter_text - > set_name ( " Text files " ) ;
filter_text - > add_mime_type ( " text/plain " ) ;
dialog . add_filter ( filter_text ) ;
Glib : : RefPtr < Gtk : : FileFilter > filter_cpp = Gtk : : FileFilter : : create ( ) ;
filter_cpp - > set_name ( " C/C++ files " ) ;
filter_cpp - > add_mime_type ( " text/x-c " ) ;
filter_cpp - > add_mime_type ( " text/x-c++ " ) ;
filter_cpp - > add_mime_type ( " text/x-c-header " ) ;
dialog . add_filter ( filter_cpp ) ;
Glib : : RefPtr < Gtk : : FileFilter > filter_any = Gtk : : FileFilter : : create ( ) ;
filter_any - > set_name ( " Any files " ) ;
filter_any - > add_pattern ( " * " ) ;
dialog . add_filter ( filter_any ) ;
int result = dialog . run ( ) ;
int result = dialog . run ( ) ;
@ -485,8 +495,8 @@ void Window::save_file_dialog() {
Gtk : : FileChooserDialog dialog ( * this , " Please choose a file " , Gtk : : FILE_CHOOSER_ACTION_SAVE ) ;
Gtk : : FileChooserDialog dialog ( * this , " Please choose a file " , Gtk : : FILE_CHOOSER_ACTION_SAVE ) ;
gtk_file_chooser_set_filename ( ( GtkFileChooser * ) dialog . gobj ( ) , notebook . get_current_view ( ) - > file_path . c_str ( ) ) ;
gtk_file_chooser_set_filename ( ( GtkFileChooser * ) dialog . gobj ( ) , notebook . get_current_view ( ) - > file_path . c_str ( ) ) ;
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
dialog . set_position ( Gtk : : WindowPosition : : WIN_POS_CENTER_ALWAYS ) ;
dialog . add_button ( " _ Cancel" , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " Cancel " , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( " _ Save" , Gtk : : RESPONSE_OK ) ;
dialog . add_button ( " Save " , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
if ( result = = Gtk : : RESPONSE_OK ) {