3 Copyright (C) 2000 Naba Kumar <naba@gnome.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <libanjuta/resources.h>
32 #include "text_editor.h"
35 #include "fileselection.h"
36 #include "utilities.h"
42 extern gboolean closing_state
;
44 gint
on_anjuta_delete (GtkWidget
*w
, GdkEvent
*event
, gpointer data
)
49 gboolean file_not_saved
;
50 gint max_recent_files
, max_recent_prjs
;
54 file_not_saved
= FALSE
;
56 anjuta_preferences_get_int (ANJUTA_PREFERENCES (app
->preferences
),
57 MAXIMUM_RECENT_FILES
);
59 anjuta_preferences_get_int (ANJUTA_PREFERENCES (app
->preferences
),
60 MAXIMUM_RECENT_PROJECTS
);
61 list
= app
->text_editor_list
;
65 if (te
->full_filename
)
67 glist_path_dedup(update_string_list (app
->recent_files
,
70 if (!text_editor_is_saved (te
))
71 file_not_saved
= TRUE
;
72 list
= g_list_next (list
);
74 if (app
->project_dbase
->project_is_open
)
76 app
->recent_projects
=
77 glist_path_dedup(update_string_list (app
->recent_projects
,
78 app
->project_dbase
->proj_filename
,
81 anjuta_app_save_settings (app
);
83 /* No need to check for saved project, as it is done in
84 close project call later. */
89 dialog
= gtk_message_dialog_new (GTK_WINDOW (app
),
90 GTK_DIALOG_DESTROY_WITH_PARENT
,
93 _("One or more files are not saved.\n"
94 "Do you still want to exit?"));
95 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
96 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
97 GTK_STOCK_QUIT
, GTK_RESPONSE_YES
,
99 response
= gtk_dialog_run (GTK_DIALOG (dialog
));
100 gtk_widget_destroy (dialog
);
101 if (response
== GTK_RESPONSE_YES
)
102 anjuta_clean_exit ();
106 anjuta_app_clean_exit (app
);
111 on_anjuta_destroy (GtkWidget
* w
, gpointer data
)
113 /* Nothing to be done here */
117 on_anjuta_dnd_drop (gchar
* filename
, gpointer data
)
119 anjuta_goto_file_line (filename
, 0);
123 on_anjuta_window_focus_in_event (GtkWidget
* widget
,
124 GdkEventFocus
* event
, gpointer user_data
)
129 if (g_list_length (GTK_NOTEBOOK (app
->notebook
)->children
) > 0)
132 gtk_notebook_get_current_page (GTK_NOTEBOOK
135 te
= anjuta_get_notebook_text_editor (page_num
);
139 else if (app
->text_editor_list
== NULL
)
145 /* If there is TextEditor in the list, but no page
146 * * in the notebook, we don't change the current
151 if (te
== anjuta_get_current_text_editor ())
153 anjuta_set_current_text_editor (te
);
159 mS__
= GDK_SHIFT_MASK
,
160 m_C_
= GDK_CONTROL_MASK
,
161 m__M
= GDK_MOD1_MASK
,
162 mSC_
= GDK_SHIFT_MASK
| GDK_CONTROL_MASK
,
166 ID_NEXTBUFFER
= 1, /* Note: the value mustn't be 0 ! */
173 unsigned int gdk_key
;
177 static ShortcutMapping global_keymap
[] = {
178 { m_C_
, GDK_Tab
, ID_NEXTBUFFER
},
179 { mSC_
, GDK_ISO_Left_Tab
, ID_PREVBUFFER
},
180 { m__M
, GDK_1
, ID_FIRSTBUFFER
},
181 { m__M
, GDK_2
, ID_FIRSTBUFFER
+ 1},
182 { m__M
, GDK_3
, ID_FIRSTBUFFER
+ 2},
183 { m__M
, GDK_4
, ID_FIRSTBUFFER
+ 3},
184 { m__M
, GDK_5
, ID_FIRSTBUFFER
+ 4},
185 { m__M
, GDK_6
, ID_FIRSTBUFFER
+ 5},
186 { m__M
, GDK_7
, ID_FIRSTBUFFER
+ 6},
187 { m__M
, GDK_8
, ID_FIRSTBUFFER
+ 7},
188 { m__M
, GDK_9
, ID_FIRSTBUFFER
+ 8},
189 { m__M
, GDK_0
, ID_FIRSTBUFFER
+ 9},
194 on_anjuta_window_key_press_event (GtkWidget
*widget
,
201 g_return_val_if_fail (widget
!= NULL
, FALSE
);
202 g_return_val_if_fail (GNOME_IS_APP (widget
), FALSE
);
203 g_return_val_if_fail (event
!= NULL
, FALSE
);
205 modifiers
= event
->state
& (GDK_SHIFT_MASK
| GDK_CONTROL_MASK
| GDK_MOD1_MASK
);
207 for (i
= 0; global_keymap
[i
].id
; i
++)
208 if (event
->keyval
== global_keymap
[i
].gdk_key
&&
209 (event
->state
& global_keymap
[i
].modifiers
) == global_keymap
[i
].modifiers
)
212 if (!global_keymap
[i
].id
)
215 switch (global_keymap
[i
].id
) {
217 case ID_PREVBUFFER
: {
218 GtkNotebook
*notebook
= GTK_NOTEBOOK (app
->notebook
);
222 if (!notebook
->children
)
230 pages_nb
= g_list_length (notebook
->children
);
231 cur_page
= gtk_notebook_get_current_page (notebook
);
233 if (global_keymap
[i
].id
== ID_NEXTBUFFER
)
234 cur_page
= (cur_page
< pages_nb
- 1) ? cur_page
+ 1 : 0;
236 cur_page
= cur_page
? cur_page
- 1 : pages_nb
-1;
238 gtk_notebook_set_page (notebook
, cur_page
);
243 if (global_keymap
[i
].id
>= ID_FIRSTBUFFER
&&
244 global_keymap
[i
].id
<= (ID_FIRSTBUFFER
+ 9))
246 GtkNotebook
*notebook
= GTK_NOTEBOOK (app
->notebook
);
247 int page_req
= global_keymap
[i
].id
- ID_FIRSTBUFFER
;
249 if (!notebook
->children
)
251 gtk_notebook_set_page(notebook
, page_req
);
257 /* Note: No reason for a shortcut to do more than one thing a time */
258 gtk_signal_emit_stop_by_name (GTK_OBJECT (widget
), "key_press_event");
264 on_anjuta_window_key_release_event (GtkWidget
*widget
,
268 g_return_val_if_fail (widget
!= NULL
, FALSE
);
269 g_return_val_if_fail (GNOME_IS_APP (widget
), FALSE
);
270 g_return_val_if_fail (event
!= NULL
, FALSE
);
272 if (g_tabbing
&& ((event
->keyval
== GDK_Control_L
) ||
273 (event
->keyval
== GDK_Control_R
)))
275 GtkNotebook
*notebook
= GTK_NOTEBOOK (app
->notebook
);
280 if (anjuta_preferences_get_int (app
->preferences
,
281 EDITOR_TABS_RECENT_FIRST
))
284 TTimo: move the current notebook page to first position
285 that maintains Ctrl-TABing on a list of most recently edited files
287 cur_page
= gtk_notebook_get_current_page (notebook
);
288 widget
= gtk_notebook_get_nth_page (notebook
, cur_page
);
289 gtk_notebook_reorder_child (notebook
, widget
, 0);
296 on_open_filesel_ok_clicked (GtkButton
* button
, gpointer user_data
)
298 gchar
*full_filename
;
299 gchar
*entry_filename
= NULL
;
304 list
= fileselection_get_filelist(app
->fileselection
);
305 elements
= g_list_length(list
);
306 /* If filename is only written in entry but not selected (Bug #506441) */
309 entry_filename
= fileselection_get_filename(app
->fileselection
);
312 list
= g_list_append(list
, entry_filename
);
316 for(i
=0;i
<elements
;i
++)
318 full_filename
= g_strdup(g_list_nth_data(list
,i
));
321 anjuta_goto_file_line (full_filename
, -1);
322 g_free (full_filename
);
327 g_list_remove(list
, entry_filename
);
328 g_free(entry_filename
);
337 gchar
*full_filename
, *saved_filename
, *saved_full_filename
;
342 full_filename
= fileselection_get_filename (app
->save_as_fileselection
);
346 te
= anjuta_get_current_text_editor ();
347 g_return_if_fail (te
!= NULL
);
348 g_return_if_fail (strlen (extract_filename (full_filename
)) != 0);
350 saved_filename
= te
->filename
;
351 saved_full_filename
= te
->full_filename
;
353 te
->full_filename
= g_strdup (full_filename
);
354 te
->filename
= g_strdup (extract_filename (full_filename
));
355 status
= text_editor_save_file (te
, TRUE
);
356 gtk_widget_hide (app
->save_as_fileselection
);
359 g_free (te
->filename
);
360 te
->filename
= saved_filename
;
361 g_free (te
->full_filename
);
362 te
->full_filename
= saved_full_filename
;
363 if (closing_state
) closing_state
= FALSE
;
364 g_free (full_filename
);
368 g_free (saved_filename
);
369 if (saved_full_filename
)
371 g_free (saved_full_filename
);
375 anjuta_remove_current_text_editor ();
376 closing_state
= FALSE
;
380 text_editor_set_hilite_type(te
);
381 if (te
->mode
== TEXT_EDITOR_PAGED
)
386 gtk_notebook_get_current_page (GTK_NOTEBOOK
388 g_return_if_fail (page_num
>= 0);
390 gtk_notebook_get_nth_page (GTK_NOTEBOOK
391 (app
->notebook
), page_num
);
393 /* gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (app->notebook),
395 anjuta_get_notebook_text_editor
396 (page_num)->filename);
398 label
= GTK_LABEL(te
->widgets
.tab_label
);
399 gtk_label_set_text(GTK_LABEL(label
), anjuta_get_notebook_text_editor
400 (page_num
)->filename
);
402 gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(app
->notebook
),
404 anjuta_get_notebook_text_editor
405 (page_num
)->filename
);
408 anjuta_update_title ();
409 g_free (full_filename
);
414 on_save_as_filesel_ok_clicked (GtkButton
* button
, gpointer user_data
)
418 filename
= fileselection_get_filename (app
->save_as_fileselection
);
419 if (file_is_regular (filename
))
422 dialog
= gtk_message_dialog_new (GTK_WINDOW (app
),
423 GTK_DIALOG_DESTROY_WITH_PARENT
,
424 GTK_MESSAGE_QUESTION
,
426 _("The file '%s' already exists.\n"
427 "Do you want to replace it with the one you are saving?"),
429 gtk_dialog_add_button (GTK_DIALOG(dialog
),
431 GTK_RESPONSE_CANCEL
);
432 anjuta_dialog_add_button (GTK_DIALOG (dialog
),
436 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
438 gtk_widget_destroy (dialog
);
444 if (anjuta_preferences_get_int (ANJUTA_PREFERENCES (app
->preferences
),
445 EDITOR_TABS_ORDERING
))
446 anjuta_order_tabs ();
450 on_save_as_filesel_cancel_clicked (GtkButton
* button
, gpointer user_data
)
452 gtk_widget_hide (app
->save_as_fileselection
);
453 closing_state
= FALSE
;
457 build_msg_save_real (void)
462 filename
= fileselection_get_filename (app
->save_as_build_msg_sel
);
463 msgfile
= fopen(filename
, "w");
466 anjuta_error (_("Could not open file for writing"));
470 an_message_manager_save_build(app
->messages
, msgfile
);
478 on_build_msg_save_ok_clicked(GtkButton
* button
, gpointer user_data
)
482 filename
= fileselection_get_filename (app
->save_as_build_msg_sel
);
483 if (file_is_regular (filename
))
486 dialog
= gtk_message_dialog_new (GTK_WINDOW (app
),
487 GTK_DIALOG_DESTROY_WITH_PARENT
,
488 GTK_MESSAGE_QUESTION
,
490 _("The file '%s' already exists.\n"
491 "Do you want to replace it with the one you are saving?."),
493 gtk_dialog_add_button (GTK_DIALOG (dialog
),
495 GTK_RESPONSE_CANCEL
);
496 anjuta_dialog_add_button (GTK_DIALOG (dialog
),
500 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
501 build_msg_save_real ();
502 gtk_widget_destroy (dialog
);
505 build_msg_save_real ();
510 on_build_msg_save_cancel_clicked(GtkButton
* button
, gpointer user_data
)
512 gtk_widget_hide (app
->save_as_build_msg_sel
);
513 closing_state
= FALSE
;
518 on_prj_list_undock_button_clicked (GtkButton
* button
, gpointer user_data
)
520 project_dbase_undock (app
->project_dbase
);
525 on_prj_list_hide_button_clicked (GtkButton
* button
, gpointer user_data
)
527 project_dbase_hide (app
->project_dbase
);
532 on_mesg_win_hide_button_clicked (GtkButton
* button
, gpointer user_data
)
534 gtk_widget_hide(GTK_WIDGET(app
->messages
));
539 on_mesg_win_undock_button_clicked (GtkButton
* button
, gpointer user_data
)
541 an_message_manager_undock (app
->messages
);
547 on_anjuta_progress_cancel (gpointer data
)
549 app
->in_progress
= FALSE
;
550 app
->progress_cancel_cb (data
);
555 on_anjuta_progress_cb (gpointer data
)
557 return (app
->progress_value
);