From a63fc1e40e85d9f2a3df522f3345eb60fa45ba6f Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 5 Sep 2006 14:24:47 +0000 Subject: [PATCH] Moved UI related utils from utils.c to ui_utils.c git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@790 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 10 + po/POTFILES.in | 1 + src/Makefile.am | 1 + src/about.c | 3 +- src/callbacks.c | 59 +-- src/document.c | 39 +- src/keybindings.c | 3 +- src/keyfile.c | 3 +- src/main.c | 27 +- src/makefile.win32 | 2 +- src/msgwindow.c | 3 +- src/notebook.c | 4 +- src/prefs.c | 11 +- src/sci_cb.c | 11 +- src/treeviews.c | 1 - src/ui_utils.c | 1050 ++++++++++++++++++++++++++++++++++++++++++++ src/ui_utils.h | 97 ++++ src/utils.c | 1025 +----------------------------------------- src/utils.h | 75 +--- src/vte.c | 1 - 20 files changed, 1256 insertions(+), 1170 deletions(-) create mode 100644 src/ui_utils.c create mode 100644 src/ui_utils.h diff --git a/ChangeLog b/ChangeLog index ce01a73f..50c2d33d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-09-05 Nick Treleaven + + * src/utils.c, src/utils.h, src/ui_utils.c, src/ui_utils.h, + src/keybindings.c, src/about.c, src/treeviews.c, src/msgwindow.c, + src/callbacks.c, src/notebook.c, src/sci_cb.c, src/keyfile.c, + src/vte.c, src/document.c, src/prefs.c, src/main.c, + po/POTFILES.in, src/Makefile.am, src/makefile.win32: + Moved UI related utils from utils.c to ui_utils.c. + + 2006-09-04 Nick Treleaven * src/keyfile.c, src/main.c, src/main.h: diff --git a/po/POTFILES.in b/po/POTFILES.in index 7c4169e5..463267a8 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -7,6 +7,7 @@ src/support.c src/dialogs.c src/document.c src/utils.c +src/ui_utils.c src/filetypes.c src/highlighting.c src/win32.c diff --git a/src/Makefile.am b/src/Makefile.am index 89327a53..942d39eb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,6 +26,7 @@ SRCS = \ sciwrappers.c sciwrappers.h \ document.c document.h \ utils.c utils.h \ + ui_utils.c ui_utils.h \ support.c support.h \ interface.c interface.h \ callbacks.c callbacks.h diff --git a/src/about.c b/src/about.c index f34a4631..3562eed5 100644 --- a/src/about.c +++ b/src/about.c @@ -23,6 +23,7 @@ #include "about.h" #include "geany.h" #include "utils.h" +#include "ui_utils.h" #include "support.h" static GtkWidget *gb_window = NULL; @@ -130,7 +131,7 @@ static GtkWidget *create_dialog(void) gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), header_eventbox, FALSE, FALSE, 0); // set image - icon = utils_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE); + icon = ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE); gtk_image_set_from_pixbuf(GTK_IMAGE(header_image), icon); gtk_window_set_icon(GTK_WINDOW(dialog), icon); diff --git a/src/callbacks.c b/src/callbacks.c index 387a049d..c344e9e3 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -38,6 +38,7 @@ #include "document.h" #include "sciwrappers.h" #include "sci_cb.h" +#include "ui_utils.h" #include "utils.h" #include "dialogs.h" #include "about.h" @@ -270,8 +271,8 @@ on_save_all1_activate (GtkMenuItem *menuitem, else document_save_file(idx, FALSE); } - utils_update_tag_list(cur_idx, TRUE); - utils_set_window_title(cur_idx); + ui_update_tag_list(cur_idx, TRUE); + ui_set_window_title(cur_idx); } @@ -321,8 +322,8 @@ on_edit1_activate (GtkMenuItem *menuitem, gpointer user_data) { gint idx = document_get_cur_idx(); - utils_update_menu_copy_items(idx); - utils_update_insert_include_item(idx, 1); + ui_update_menu_copy_items(idx); + ui_update_insert_include_item(idx, 1); } @@ -504,7 +505,7 @@ on_reload_as_activate (GtkMenuItem *menuitem, { document_reload_file(idx, charset); if (charset != NULL) - utils_update_statusbar(idx, -1); + ui_update_statusbar(idx, -1); } g_free(basename); } @@ -632,7 +633,7 @@ on_toolbar_large_icons1_activate (GtkMenuItem *menuitem, if (ignore_toolbar_toggle) return; app->toolbar_icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR; - utils_update_toolbar_icons(GTK_ICON_SIZE_LARGE_TOOLBAR); + ui_update_toolbar_icons(GTK_ICON_SIZE_LARGE_TOOLBAR); } @@ -643,7 +644,7 @@ on_toolbar_small_icons1_activate (GtkMenuItem *menuitem, if (ignore_toolbar_toggle) return; app->toolbar_icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR; - utils_update_toolbar_icons(GTK_ICON_SIZE_SMALL_TOOLBAR); + ui_update_toolbar_icons(GTK_ICON_SIZE_SMALL_TOOLBAR); } @@ -733,11 +734,11 @@ on_notebook1_switch_page (GtkNotebook *notebook, gtk_tree_model_foreach(GTK_TREE_MODEL(tv.store_openfiles), treeviews_find_node, GINT_TO_POINTER(idx)); document_set_text_changed(idx); - utils_document_show_hide(idx); // update the document menu - utils_build_show_hide(idx); - utils_update_statusbar(idx, -1); - utils_set_window_title(idx); - utils_update_tag_list(idx, FALSE); + ui_document_show_hide(idx); // update the document menu + ui_build_show_hide(idx); + ui_update_statusbar(idx, -1); + ui_set_window_title(idx); + ui_update_tag_list(idx, FALSE); } } @@ -905,10 +906,10 @@ on_file_save_dialog_response (GtkDialog *dialog, utils_replace_filename(idx); document_save_file(idx, TRUE); - utils_build_show_hide(idx); + ui_build_show_hide(idx); // finally add current file to recent files menu - utils_add_recent_file(doc_list[idx].file_name); + ui_add_recent_file(doc_list[idx].file_name); } else gtk_widget_hide(app->save_filesel); } @@ -935,7 +936,7 @@ on_font_apply_button_clicked (GtkButton *button, fontname = gtk_font_selection_dialog_get_font_name( GTK_FONT_SELECTION_DIALOG(app->open_fontsel)); - utils_set_editor_font(fontname); + ui_set_editor_font(fontname); g_free(fontname); } @@ -1170,7 +1171,7 @@ on_show_toolbar1_toggled (GtkCheckMenuItem *checkmenuitem, if (app->ignore_callback) return; app->toolbar_visible = (app->toolbar_visible) ? FALSE : TRUE;; - utils_widget_show_hide(GTK_WIDGET(app->toolbar), app->toolbar_visible); + ui_widget_show_hide(GTK_WIDGET(app->toolbar), app->toolbar_visible); } @@ -1179,7 +1180,7 @@ on_fullscreen1_toggled (GtkCheckMenuItem *checkmenuitem, gpointer user_data) { app->fullscreen = (app->fullscreen) ? FALSE : TRUE; - utils_set_fullscreen(); + ui_set_fullscreen(); } @@ -1190,7 +1191,7 @@ on_show_messages_window1_toggled (GtkCheckMenuItem *checkmenuitem, if (app->ignore_callback) return; app->msgwindow_visible = (app->msgwindow_visible) ? FALSE : TRUE; - utils_widget_show_hide(lookup_widget(app->window, "scrolledwindow1"), app->msgwindow_visible); + ui_widget_show_hide(lookup_widget(app->window, "scrolledwindow1"), app->msgwindow_visible); } @@ -1199,7 +1200,7 @@ on_markers_margin1_toggled (GtkCheckMenuItem *checkmenuitem, gpointer user_data) { app->show_markers_margin = (app->show_markers_margin) ? FALSE : TRUE; - utils_show_markers_margin(); + ui_show_markers_margin(); } @@ -1208,7 +1209,7 @@ on_show_line_numbers1_toggled (GtkCheckMenuItem *checkmenuitem, gpointer user_data) { app->show_linenumber_margin = (app->show_linenumber_margin) ? FALSE : TRUE; - utils_show_linenumber_margin(); + ui_show_linenumber_margin(); } @@ -1236,7 +1237,7 @@ on_set_file_readonly1_toggled (GtkCheckMenuItem *checkmenuitem, if (idx == -1 || ! doc_list[idx].is_valid) return; doc_list[idx].readonly = ! doc_list[idx].readonly; sci_set_readonly(doc_list[idx].sci, doc_list[idx].readonly); - utils_update_statusbar(idx, -1); + ui_update_statusbar(idx, -1); } } @@ -1464,13 +1465,13 @@ on_openfiles_tree_popup_clicked (GtkMenuItem *menuitem, case 3: { app->sidebar_openfiles_visible = FALSE; - utils_treeviews_showhide(FALSE); + ui_treeviews_show_hide(FALSE); break; } case 4: { app->sidebar_visible = FALSE; - utils_treeviews_showhide(TRUE); + ui_treeviews_show_hide(TRUE); break; } } @@ -1488,13 +1489,13 @@ on_taglist_tree_popup_clicked (GtkMenuItem *menuitem, case 0: { app->sidebar_symbol_visible = FALSE; - utils_treeviews_showhide(FALSE); + ui_treeviews_show_hide(FALSE); break; } case 1: { app->sidebar_visible = FALSE; - utils_treeviews_showhide(TRUE); + ui_treeviews_show_hide(TRUE); break; } } @@ -2311,7 +2312,7 @@ on_recent_file_activate (GtkMenuItem *menuitem, gchar *locale_filename = utils_get_locale_from_utf8((gchar*) user_data); document_open_file(-1, locale_filename, 0, FALSE, NULL, NULL); - utils_recent_file_loaded((gchar*) user_data); + ui_recent_file_loaded((gchar*) user_data); g_free(locale_filename); } @@ -2396,7 +2397,7 @@ on_encoding_change (GtkMenuItem *menuitem, doc_list[idx].encoding = g_strdup(encodings[i].charset); doc_list[idx].changed = TRUE; document_set_text_changed(idx); - utils_update_statusbar(idx, -1); + ui_update_statusbar(idx, -1); gtk_widget_set_sensitive(lookup_widget(app->window, "menu_write_unicode_bom1"), utils_is_unicode_charset(doc_list[idx].encoding)); } @@ -2436,7 +2437,7 @@ on_menu_show_sidebar1_toggled (GtkCheckMenuItem *checkmenuitem, app->sidebar_symbol_visible = TRUE; app->sidebar_openfiles_visible = TRUE; } - utils_treeviews_showhide(TRUE); + ui_treeviews_show_hide(TRUE); } @@ -2454,7 +2455,7 @@ on_menu_write_unicode_bom1_toggled (GtkCheckMenuItem *checkmenuitem, doc_list[idx].changed = TRUE; document_set_text_changed(idx); - utils_update_statusbar(idx, -1); + ui_update_statusbar(idx, -1); } } diff --git a/src/document.c b/src/document.c index 047f4ebd..d7a4bbf0 100644 --- a/src/document.c +++ b/src/document.c @@ -51,6 +51,7 @@ #include "msgwindow.h" #include "templates.h" #include "treeviews.h" +#include "ui_utils.h" #include "utils.h" #include "encodings.h" #include "notebook.h" @@ -179,8 +180,8 @@ void document_change_tab_color(gint index) void document_set_text_changed(gint index) { document_change_tab_color(index); - utils_save_buttons_toggle(doc_list[index].changed); - utils_set_window_title(index); + ui_save_buttons_toggle(doc_list[index].changed); + ui_set_window_title(index); } @@ -290,7 +291,7 @@ gint document_create_new_sci(const gchar *filename) g_signal_connect((GtkWidget*) sci, "button-press-event", G_CALLBACK(on_editor_button_press_event), GINT_TO_POINTER(new_idx)); - utils_close_buttons_toggle(); + ui_close_buttons_toggle(); // store important pointers in the tab list this->file_name = (filename) ? g_strdup(filename) : NULL; @@ -344,12 +345,12 @@ gboolean document_remove(guint page_num) doc_list[idx].tm_file = NULL; if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0) { - utils_update_tag_list(-1, FALSE); + ui_update_tag_list(-1, FALSE); //on_notebook1_switch_page(GTK_NOTEBOOK(app->notebook), NULL, 0, NULL); - utils_set_window_title(-1); - utils_save_buttons_toggle(FALSE); - utils_close_buttons_toggle(); - utils_build_show_hide(-1); + ui_set_window_title(-1); + ui_save_buttons_toggle(FALSE); + ui_close_buttons_toggle(); + ui_build_show_hide(-1); } } else geany_debug("Error: idx: %d page_num: %d", idx, page_num); @@ -383,13 +384,13 @@ void document_new_file(filetype *ft) //document_set_filetype(idx, (ft == NULL) ? filetypes[GEANY_FILETYPES_ALL] : ft); document_set_filetype(idx, ft); if (ft == NULL) filetypes[GEANY_FILETYPES_ALL]->style_func_ptr(doc_list[idx].sci); - utils_set_window_title(idx); - utils_build_show_hide(idx); - utils_update_tag_list(idx, FALSE); + ui_set_window_title(idx); + ui_build_show_hide(idx); + ui_update_tag_list(idx, FALSE); doc_list[idx].mtime = time(NULL); doc_list[idx].changed = FALSE; document_set_text_changed(idx); - utils_document_show_hide(idx); //update the document menu + ui_document_show_hide(idx); //update the document menu #ifdef G_OS_WIN32 sci_set_eol_mode(doc_list[idx].sci, SC_EOL_CRLF); #else @@ -628,7 +629,7 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado sci_set_readonly(doc_list[idx].sci, readonly); document_set_filetype(idx, use_ft); - utils_build_show_hide(idx); + ui_build_show_hide(idx); } else { @@ -636,13 +637,13 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado } document_set_text_changed(idx); - utils_document_show_hide(idx); //update the document menu + ui_document_show_hide(idx); //update the document menu g_free(data); // finally add current file to recent files menu, but not the files from the last session - if (! app->opening_session_files) utils_add_recent_file(utf8_filename); + if (! app->opening_session_files) ui_add_recent_file(utf8_filename); if (reload) msgwin_status_add(_("File %s reloaded."), utf8_filename); @@ -794,7 +795,7 @@ void document_save_file(gint idx, gboolean force) gtk_label_set_text(GTK_LABEL(doc_list[idx].tabmenu_label), basename); treeviews_openfiles_update(doc_list[idx].iter, doc_list[idx].file_name); msgwin_status_add(_("File %s saved."), doc_list[idx].file_name); - utils_update_statusbar(idx, -1); + ui_update_statusbar(idx, -1); treeviews_openfiles_update(doc_list[idx].iter, basename); g_free(basename); #ifdef HAVE_VTE @@ -1082,13 +1083,13 @@ void document_update_tag_list(gint idx, gboolean update) tm_workspace_add_object(doc_list[idx].tm_file); if (update) tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE); - utils_update_tag_list(idx, TRUE); + ui_update_tag_list(idx, TRUE); } else { if (tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE)) { - utils_update_tag_list(idx, TRUE); + ui_update_tag_list(idx, TRUE); } else { @@ -1148,7 +1149,7 @@ void document_set_filetype(gint idx, filetype *type) } } sci_colourise(doc_list[idx].sci, 0, -1); - utils_build_show_hide(idx); + ui_build_show_hide(idx); } diff --git a/src/keybindings.c b/src/keybindings.c index d1e6b755..a545d5ae 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -27,6 +27,7 @@ #include "keybindings.h" #include "support.h" #include "utils.h" +#include "ui_utils.h" #include "document.h" #include "callbacks.h" #include "prefs.h" @@ -706,7 +707,7 @@ static void cb_func_toggle_sidebar(void) app->sidebar_symbol_visible = TRUE; } - utils_treeviews_showhide(TRUE); + ui_treeviews_show_hide(TRUE); gtk_notebook_set_current_page(GTK_NOTEBOOK(app->treeview_notebook), active_page); } diff --git a/src/keyfile.c b/src/keyfile.c index 2fcfab21..15d3f11a 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -33,6 +33,7 @@ #include "support.h" #include "keyfile.h" +#include "ui_utils.h" #include "utils.h" #include "document.h" #include "sciwrappers.h" @@ -556,7 +557,7 @@ void configuration_apply_settings() { gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_fullscreen1")), TRUE); app->fullscreen = TRUE; - utils_set_fullscreen(); + ui_set_fullscreen(); } } diff --git a/src/main.c b/src/main.c index b6ab5298..6371b39d 100644 --- a/src/main.c +++ b/src/main.c @@ -44,6 +44,7 @@ #include "support.h" #include "callbacks.h" +#include "ui_utils.h" #include "utils.h" #include "document.h" #include "keyfile.h" @@ -149,7 +150,7 @@ void geany_debug(gchar const *format, ...) * (all the following code is not perfect but it works for the moment) */ static void apply_settings(void) { - utils_update_fold_items(); + ui_update_fold_items(); // toolbar, message window and sidebar are by default visible, so don't change it if it is true if (! app->toolbar_visible) @@ -172,7 +173,7 @@ static void apply_settings(void) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_show_sidebar1")), FALSE); app->ignore_callback = FALSE; } - utils_treeviews_showhide(TRUE); + ui_treeviews_show_hide(TRUE); // sets the icon style of the toolbar switch (app->toolbar_icon_style) { @@ -202,7 +203,7 @@ static void apply_settings(void) { gtk_toolbar_set_icon_size(GTK_TOOLBAR(app->toolbar), app->toolbar_icon_size); } - utils_update_toolbar_icons(app->toolbar_icon_size); + ui_update_toolbar_icons(app->toolbar_icon_size); // line number and markers margin are by default enabled if (! app->show_markers_margin) @@ -238,7 +239,7 @@ static void apply_settings(void) gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), app->tab_pos_msgwin); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->treeview_notebook), app->tab_pos_sidebar); - utils_update_toolbar_items(); + ui_update_toolbar_items(); } @@ -546,8 +547,8 @@ gint main(gint argc, gchar **argv) #endif if (no_msgwin) app->msgwindow_visible = FALSE; - utils_create_insert_menu_items(); - utils_create_insert_date_menu_items(); + ui_create_insert_menu_items(); + ui_create_insert_date_menu_items(); keybindings_init(); notebook_init(); templates_init(); @@ -560,7 +561,7 @@ gint main(gint argc, gchar **argv) } configuration_read_filetype_extensions(); - gtk_window_set_icon(GTK_WINDOW(app->window), utils_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE)); + gtk_window_set_icon(GTK_WINDOW(app->window), ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE)); // registering some basic events g_signal_connect(G_OBJECT(app->window), "delete_event", G_CALLBACK(on_exit_clicked), NULL); @@ -620,8 +621,8 @@ gint main(gint argc, gchar **argv) { if (! configuration_open_files()) { - utils_update_popup_copy_items(-1); - utils_update_popup_reundo_items(-1); + ui_update_popup_copy_items(-1); + ui_update_popup_reundo_items(-1); } } app->opening_session_files = FALSE; @@ -629,14 +630,14 @@ gint main(gint argc, gchar **argv) // open a new file if no other file was opened if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0) document_new_file(NULL); - utils_close_buttons_toggle(); - utils_save_buttons_toggle(FALSE); + ui_close_buttons_toggle(); + ui_save_buttons_toggle(FALSE); idx = document_get_cur_idx(); gtk_widget_grab_focus(GTK_WIDGET(doc_list[idx].sci)); gtk_tree_model_foreach(GTK_TREE_MODEL(tv.store_openfiles), treeviews_find_node, GINT_TO_POINTER(idx)); - utils_build_show_hide(idx); - utils_update_tag_list(idx, FALSE); + ui_build_show_hide(idx); + ui_update_tag_list(idx, FALSE); #ifdef G_OS_WIN32 // hide "Build" menu item, at least until it is available for Windows diff --git a/src/makefile.win32 b/src/makefile.win32 index 80fdf6ff..0d3230b3 100644 --- a/src/makefile.win32 +++ b/src/makefile.win32 @@ -45,7 +45,7 @@ ALL_GTK_LIBS= \ CCFLAGS=-Wall -O2 -g -mms-bitfields $(DEFINES) $(INCLUDEDIRS) OBJS = treeviews.o templates.o encodings.o about.o prefs.o win32.o build.o msgwindow.o dialogs.o \ - filetypes.o interface.o main.o support.o callbacks.o utils.o \ + filetypes.o interface.o main.o support.o callbacks.o utils.o ui_utils.o \ highlighting.o sci_cb.o document.o sciwrappers.o keyfile.o keybindings.o search.o notebook.o .c.o: diff --git a/src/msgwindow.c b/src/msgwindow.c index d5257fa3..02e47dae 100644 --- a/src/msgwindow.c +++ b/src/msgwindow.c @@ -28,6 +28,7 @@ #include "support.h" #include "callbacks.h" #include "msgwindow.h" +#include "ui_utils.h" #include "utils.h" #include "document.h" @@ -231,7 +232,7 @@ void msgwin_status_add(gchar const *format, ...) va_end(args); // display status message in status bar - utils_set_statusbar(string, FALSE); + ui_set_statusbar(string, FALSE); gtk_list_store_append(msgwindow.store_status, &iter); //gtk_list_store_insert(msgwindow.store_status, &iter, 0); diff --git a/src/notebook.c b/src/notebook.c index 45f5e2a9..60bfaa9d 100644 --- a/src/notebook.c +++ b/src/notebook.c @@ -24,7 +24,7 @@ #include "geany.h" #include "notebook.h" #include "document.h" -#include "utils.h" +#include "ui_utils.h" #include "treeviews.h" #define GEANY_DND_NOTEBOOK_TAB_TYPE "geany_dnd_notebook_tab" @@ -257,7 +257,7 @@ gint notebook_new_tab(gint doc_idx, gchar *title, GtkWidget *page) hbox = gtk_hbox_new(FALSE, 0); but = gtk_button_new(); gtk_container_add(GTK_CONTAINER(but), - utils_new_image_from_inline(GEANY_IMAGE_SMALL_CROSS, FALSE)); + ui_new_image_from_inline(GEANY_IMAGE_SMALL_CROSS, FALSE)); gtk_container_set_border_width(GTK_CONTAINER(but), 0); gtk_widget_set_size_request(but, 19, 18); diff --git a/src/prefs.c b/src/prefs.c index 5d62902c..92b1a007 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -29,6 +29,7 @@ #include "prefs.h" #include "support.h" #include "dialogs.h" +#include "ui_utils.h" #include "utils.h" #include "msgwindow.h" #include "sciwrappers.h" @@ -495,7 +496,7 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat widget = lookup_widget(app->prefs_dialog, "check_folding"); app->pref_editor_folding = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - utils_update_fold_items(); + ui_update_fold_items(); widget = lookup_widget(app->prefs_dialog, "check_indent"); app->pref_editor_show_indent_guide = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); @@ -607,10 +608,10 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat #endif // apply the changes made - utils_update_toolbar_items(); - utils_update_toolbar_icons(app->toolbar_icon_size); + ui_update_toolbar_items(); + ui_update_toolbar_icons(app->toolbar_icon_size); gtk_toolbar_set_style(GTK_TOOLBAR(app->toolbar), app->toolbar_icon_style); - utils_treeviews_showhide(FALSE); + ui_treeviews_show_hide(FALSE); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(app->notebook), app->tab_pos_editor); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(msgwindow.notebook), app->tab_pos_msgwin); @@ -714,7 +715,7 @@ void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data) } case 3: { - utils_set_editor_font(fontbtn); + ui_set_editor_font(fontbtn); break; } #ifdef HAVE_VTE diff --git a/src/sci_cb.c b/src/sci_cb.c index 59444881..08339c57 100644 --- a/src/sci_cb.c +++ b/src/sci_cb.c @@ -30,6 +30,7 @@ #include "sci_cb.h" #include "document.h" #include "sciwrappers.h" +#include "ui_utils.h" #include "utils.h" #include "main.h" @@ -70,9 +71,9 @@ on_editor_button_press_event (GtkWidget *widget, sci_cb_find_current_word(doc_list[idx].sci, editor_info.click_pos, current_word, sizeof current_word); - utils_update_popup_goto_items((current_word[0] != '\0') ? TRUE : FALSE); - utils_update_popup_copy_items(idx); - utils_update_insert_include_item(idx, 0); + ui_update_popup_goto_items((current_word[0] != '\0') ? TRUE : FALSE); + ui_update_popup_copy_items(idx); + ui_update_insert_include_item(idx, 0); gtk_menu_popup(GTK_MENU(app->popup_menu), NULL, NULL, NULL, NULL, event->button, event->time); return TRUE; @@ -131,12 +132,12 @@ void on_editor_notification(GtkWidget *editor, gint scn, gpointer lscn, gpointer gint pos = sci_get_current_position(sci); // undo / redo menu update - utils_update_popup_reundo_items(idx); + ui_update_popup_reundo_items(idx); // brace highlighting sci_cb_highlight_braces(sci, pos); - utils_update_statusbar(idx, pos); + ui_update_statusbar(idx, pos); #if 0 /// experimental code for inverting selections diff --git a/src/treeviews.c b/src/treeviews.c index fe67ff23..b020b8ab 100644 --- a/src/treeviews.c +++ b/src/treeviews.c @@ -25,7 +25,6 @@ #include "geany.h" #include "support.h" #include "callbacks.h" -#include "utils.h" #include "treeviews.h" #include "document.h" diff --git a/src/ui_utils.c b/src/ui_utils.c new file mode 100644 index 00000000..5ef5a8a1 --- /dev/null +++ b/src/ui_utils.c @@ -0,0 +1,1050 @@ +/* + * ui_utils.c - this file is part of Geany, a fast and lightweight IDE + * + * Copyright 2006 Enrico Troeger + * Copyright 2006 Nick Treleaven + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $Id$ + */ + + +#include "geany.h" + +#include + +#include "ui_utils.h" +#include "sciwrappers.h" +#include "document.h" +#include "support.h" +#include "msgwindow.h" +#include "utils.h" +#include "callbacks.h" +#include "encodings.h" +#include "dialogs.h" +#include "images.c" +#include "treeviews.h" + + +static void ui_update_recent_menu(); + +static void ui_recreate_recent_menu(); + + +/* allow_override is TRUE if text can be ignored when another message has been set + * that didn't use allow_override and has not timed out. */ +void ui_set_statusbar(const gchar *text, gboolean allow_override) +{ + static glong last_time = 0; + GTimeVal timeval; + const gint GEANY_STATUS_TIMEOUT = 1; + + g_get_current_time(&timeval); + + if (! allow_override) + { + gtk_statusbar_pop(GTK_STATUSBAR(app->statusbar), 1); + gtk_statusbar_push(GTK_STATUSBAR(app->statusbar), 1, text); + last_time = timeval.tv_sec; + } + else + if (timeval.tv_sec > last_time + GEANY_STATUS_TIMEOUT) + { + gtk_statusbar_pop(GTK_STATUSBAR(app->statusbar), 1); + gtk_statusbar_push(GTK_STATUSBAR(app->statusbar), 1, text); + } +} + + +/* updates the status bar */ +void ui_update_statusbar(gint idx, gint pos) +{ + gchar *text; + const gchar *cur_tag; + guint line, col; + + if (idx == -1) idx = document_get_cur_idx(); + + if (idx >= 0 && doc_list[idx].is_valid) + { + utils_get_current_function(idx, &cur_tag); + + if (pos == -1) pos = sci_get_current_position(doc_list[idx].sci); + line = sci_get_line_from_position(doc_list[idx].sci, pos); + col = sci_get_col_from_position(doc_list[idx].sci, pos); + + text = g_strdup_printf(_("%c line: % 4d column: % 3d selection: % 4d %s mode: %s%s cur. function: %s encoding: %s %s filetype: %s"), + (doc_list[idx].changed) ? 42 : 32, + (line + 1), (col + 1), + sci_get_selected_text_length(doc_list[idx].sci) - 1, + doc_list[idx].do_overwrite ? _("OVR") : _("INS"), + document_get_eol_mode(idx), + (doc_list[idx].readonly) ? ", read only" : "", + cur_tag, + (doc_list[idx].encoding) ? doc_list[idx].encoding : _("unknown"), + (utils_is_unicode_charset(doc_list[idx].encoding)) ? ((doc_list[idx].has_bom) ? _("(with BOM)") : _("(without BOM)")) : "", + (doc_list[idx].file_type) ? doc_list[idx].file_type->title : _("unknown")); + ui_set_statusbar(text, TRUE); //can be overridden by status messages + g_free(text); + } + else + { + ui_set_statusbar("", TRUE); //can be overridden by status messages + } +} + + +/* This sets the window title according to the current filename. */ +void ui_set_window_title(gint index) +{ + gchar *title; + + if (index >= 0) + { + title = g_strdup_printf ("%s: %s %s", + PACKAGE, + (doc_list[index].file_name != NULL) ? g_filename_to_utf8(doc_list[index].file_name, -1, NULL, NULL, NULL) : _("untitled"), + doc_list[index].changed ? _("(Unsaved)") : ""); + gtk_window_set_title(GTK_WINDOW(app->window), title); + g_free(title); + } + else + gtk_window_set_title(GTK_WINDOW(app->window), PACKAGE); +} + + +void ui_set_editor_font(const gchar *font_name) +{ + gint i, size; + gchar *fname; + PangoFontDescription *font_desc; + + g_return_if_fail(font_name != NULL); + // do nothing if font has not changed + if (app->editor_font != NULL) + if (strcmp(font_name, app->editor_font) == 0) return; + + g_free(app->editor_font); + app->editor_font = g_strdup(font_name); + + font_desc = pango_font_description_from_string(app->editor_font); + + fname = g_strdup_printf("!%s", pango_font_description_get_family(font_desc)); + size = pango_font_description_get_size(font_desc) / PANGO_SCALE; + + /* We copy the current style, and update the font in all open tabs. */ + for(i = 0; i < GEANY_MAX_OPEN_FILES; i++) + { + if (doc_list[i].sci) + { + document_set_font(i, fname, size); + } + } + pango_font_description_free(font_desc); + + msgwin_status_add(_("Font updated (%s)."), app->editor_font); + g_free(fname); +} + + +void ui_set_fullscreen() +{ + if (app->fullscreen) + { + gtk_window_fullscreen(GTK_WINDOW(app->window)); + } + else + { + gtk_window_unfullscreen(GTK_WINDOW(app->window)); + } +} + + +void ui_update_tag_list(gint idx, gboolean update) +{ + GList *tmp; + const GList *tags; + + if (gtk_bin_get_child(GTK_BIN(app->tagbar))) + gtk_container_remove(GTK_CONTAINER(app->tagbar), gtk_bin_get_child(GTK_BIN(app->tagbar))); + + if (app->default_tag_tree == NULL) + { + GtkTreeIter iter; + GtkTreeStore *store = gtk_tree_store_new(1, G_TYPE_STRING); + app->default_tag_tree = gtk_tree_view_new(); + treeviews_prepare_taglist(app->default_tag_tree, store); + gtk_tree_store_append(store, &iter, NULL); + gtk_tree_store_set(store, &iter, 0, _("No tags found"), -1); + gtk_widget_show(app->default_tag_tree); + g_object_ref((gpointer)app->default_tag_tree); // to hold it after removing + } + + // make all inactive, because there is no more tab left, or something strange occured + if (idx == -1 || doc_list[idx].file_type == NULL || ! doc_list[idx].file_type->has_tags) + { + gtk_widget_set_sensitive(app->tagbar, FALSE); + gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); + return; + } + + if (update) + { // updating the tag list in the left tag window + if (doc_list[idx].tag_tree == NULL) + { + doc_list[idx].tag_store = gtk_tree_store_new(1, G_TYPE_STRING); + doc_list[idx].tag_tree = gtk_tree_view_new(); + treeviews_prepare_taglist(doc_list[idx].tag_tree, doc_list[idx].tag_store); + gtk_widget_show(doc_list[idx].tag_tree); + g_object_ref((gpointer)doc_list[idx].tag_tree); // to hold it after removing + } + + tags = utils_get_tag_list(idx, tm_tag_max_t); + if (doc_list[idx].tm_file != NULL && tags != NULL) + { + GtkTreeIter iter; + GtkTreeModel *model; + + doc_list[idx].has_tags = TRUE; + gtk_tree_store_clear(doc_list[idx].tag_store); + // unref the store to speed up the filling(from TreeView Tutorial) + model = gtk_tree_view_get_model(GTK_TREE_VIEW(doc_list[idx].tag_tree)); + g_object_ref(model); // Make sure the model stays with us after the tree view unrefs it + gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), NULL); // Detach model from view + + treeviews_init_tag_list(idx); + for (tmp = (GList*)tags; tmp; tmp = g_list_next(tmp)) + { + switch (((GeanySymbol*)tmp->data)->type) + { + case tm_tag_prototype_t: + case tm_tag_function_t: + { + if (tv.tag_function.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_function)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_macro_t: + case tm_tag_macro_with_arg_t: + { + if (tv.tag_macro.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_macro)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_class_t: + { + if (tv.tag_class.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_class)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_member_t: + { + if (tv.tag_member.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_member)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_typedef_t: + case tm_tag_enum_t: + case tm_tag_union_t: + case tm_tag_struct_t: + { + if (tv.tag_struct.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_struct)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_variable_t: + { + if (tv.tag_variable.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_variable)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + case tm_tag_namespace_t: + { + if (tv.tag_namespace.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_namespace)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + break; + } + default: + { + if (tv.tag_other.stamp == -1) break; + gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_other)); + gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); + } + } + } + gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), model); // Re-attach model to view + g_object_unref(model); + gtk_tree_view_expand_all(GTK_TREE_VIEW(doc_list[idx].tag_tree)); + + gtk_widget_set_sensitive(app->tagbar, TRUE); + gtk_container_add(GTK_CONTAINER(app->tagbar), doc_list[idx].tag_tree); + /// TODO why I have to do this here? + g_object_ref((gpointer)doc_list[idx].tag_tree); + } + else + { // tags == NULL + gtk_widget_set_sensitive(app->tagbar, FALSE); + gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); + } + } + else + { // update == FALSE + if (doc_list[idx].has_tags) + { + gtk_widget_set_sensitive(app->tagbar, TRUE); + gtk_container_add(GTK_CONTAINER(app->tagbar), doc_list[idx].tag_tree); + } + else + { + gtk_widget_set_sensitive(app->tagbar, FALSE); + gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); + } + } +} + + +void ui_update_popup_reundo_items(gint index) +{ + gboolean enable_undo; + gboolean enable_redo; + + if (index == -1) + { + enable_undo = FALSE; + enable_redo = FALSE; + } + else + { + enable_undo = sci_can_undo(doc_list[index].sci); + enable_redo = sci_can_redo(doc_list[index].sci); + } + + // index 0 is the popup menu, 1 is the menubar + gtk_widget_set_sensitive(app->undo_items[0], enable_undo); + gtk_widget_set_sensitive(app->undo_items[1], enable_undo); + gtk_widget_set_sensitive(app->undo_items[2], enable_undo); + + gtk_widget_set_sensitive(app->redo_items[0], enable_redo); + gtk_widget_set_sensitive(app->redo_items[1], enable_redo); + gtk_widget_set_sensitive(app->redo_items[2], enable_redo); +} + + +void ui_update_popup_copy_items(gint index) +{ + gboolean enable; + guint i; + + if (index == -1) enable = FALSE; + else enable = sci_can_copy(doc_list[index].sci); + + for(i = 0; i < (sizeof(app->popup_items)/sizeof(GtkWidget*)); i++) + gtk_widget_set_sensitive(app->popup_items[i], enable); +} + + +void ui_update_popup_goto_items(gboolean enable) +{ + gtk_widget_set_sensitive(app->popup_goto_items[0], enable); + gtk_widget_set_sensitive(app->popup_goto_items[1], enable); + gtk_widget_set_sensitive(app->popup_goto_items[2], enable); +} + + +void ui_update_menu_copy_items(gint idx) +{ + gboolean enable = FALSE; + guint i; + GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(app->window)); + + if (IS_SCINTILLA(focusw)) + enable = (idx == -1) ? FALSE : sci_can_copy(doc_list[idx].sci); + else + if (GTK_IS_EDITABLE(focusw)) + enable = gtk_editable_get_selection_bounds(GTK_EDITABLE(focusw), NULL, NULL); + else + if (GTK_IS_TEXT_VIEW(focusw)) + { + GtkTextBuffer *buffer = gtk_text_view_get_buffer( + GTK_TEXT_VIEW(focusw)); + enable = gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL); + } + + for(i = 0; i < (sizeof(app->menu_copy_items)/sizeof(GtkWidget*)); i++) + gtk_widget_set_sensitive(app->menu_copy_items[i], enable); +} + + +void ui_update_insert_include_item(gint idx, gint item) +{ + gboolean enable = FALSE; + + if (idx == -1 || doc_list[idx].file_type == NULL) enable = FALSE; + else if (doc_list[idx].file_type->id == GEANY_FILETYPES_C || + doc_list[idx].file_type->id == GEANY_FILETYPES_CPP) + { + enable = TRUE; + } + gtk_widget_set_sensitive(app->menu_insert_include_item[item], enable); +} + + +void ui_update_fold_items() +{ + gtk_widget_set_sensitive(lookup_widget(app->window, "menu_fold_all1"), app->pref_editor_folding); + gtk_widget_set_sensitive(lookup_widget(app->window, "menu_unfold_all1"), app->pref_editor_folding); +} + + +static void insert_include_items(GtkMenu *me, GtkMenu *mp, gchar **includes, gchar *label) +{ + guint i = 0; + GtkWidget *tmp_menu; + GtkWidget *tmp_popup; + GtkWidget *edit_menu, *edit_menu_item; + GtkWidget *popup_menu, *popup_menu_item; + + edit_menu = gtk_menu_new(); + popup_menu = gtk_menu_new(); + edit_menu_item = gtk_menu_item_new_with_label(label); + popup_menu_item = gtk_menu_item_new_with_label(label); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(edit_menu_item), edit_menu); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(popup_menu_item), popup_menu); + + while (includes[i] != NULL) + { + tmp_menu = gtk_menu_item_new_with_label(includes[i]); + tmp_popup = gtk_menu_item_new_with_label(includes[i]); + gtk_container_add(GTK_CONTAINER(edit_menu), tmp_menu); + gtk_container_add(GTK_CONTAINER(popup_menu), tmp_popup); + g_signal_connect((gpointer) tmp_menu, "activate", G_CALLBACK(on_insert_include_activate), + (gpointer) includes[i]); + g_signal_connect((gpointer) tmp_popup, "activate", G_CALLBACK(on_insert_include_activate), + (gpointer) includes[i]); + i++; + } + gtk_widget_show_all(edit_menu_item); + gtk_widget_show_all(popup_menu_item); + gtk_container_add(GTK_CONTAINER(me), edit_menu_item); + gtk_container_add(GTK_CONTAINER(mp), popup_menu_item); +} + + +void ui_create_insert_menu_items() +{ + GtkMenu *menu_edit = GTK_MENU(lookup_widget(app->window, "insert_include2_menu")); + GtkMenu *menu_popup = GTK_MENU(lookup_widget(app->popup_menu, "insert_include1_menu")); + GtkWidget *blank; + const gchar *c_includes_stdlib[] = { + "assert.h", "ctype.h", "errno.h", "float.h", "limits.h", "locale.h", "math.h", "setjmp.h", + "signal.h", "stdarg.h", "stddef.h", "stdio.h", "stdlib.h", "string.h", "time.h", NULL + }; + const gchar *c_includes_c99[] = { + "complex.h", "fenv.h", "inttypes.h", "iso646.h", "stdbool.h", "stdint.h", + "tgmath.h", "wchar.h", "wctype.h", NULL + }; + const gchar *c_includes_cpp[] = { + "cstdio", "cstring", "cctype", "cmath", "ctime", "cstdlib", "cstdarg", NULL + }; + const gchar *c_includes_cppstdlib[] = { + "iostream", "fstream", "iomanip", "sstream", "exception", "stdexcept", + "memory", "locale", NULL + }; + const gchar *c_includes_stl[] = { + "bitset", "dequev", "list", "map", "set", "queue", "stack", "vector", "algorithm", + "iterator", "functional", "string", "complex", "valarray", NULL + }; + + blank = gtk_menu_item_new_with_label("#include \"...\""); + gtk_container_add(GTK_CONTAINER(menu_edit), blank); + gtk_widget_show(blank); + g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_insert_include_activate), + (gpointer) "blank"); + blank = gtk_separator_menu_item_new (); + gtk_container_add(GTK_CONTAINER(menu_edit), blank); + gtk_widget_show(blank); + + blank = gtk_menu_item_new_with_label("#include \"...\""); + gtk_container_add(GTK_CONTAINER(menu_popup), blank); + gtk_widget_show(blank); + g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_insert_include_activate), + (gpointer) "blank"); + blank = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(menu_popup), blank); + gtk_widget_show(blank); + + insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_stdlib, _("C Standard Library")); + insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_c99, _("ISO C99")); + insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_cpp, _("C++ (C Standard Library)")); + insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_cppstdlib, _("C++ Standard Library")); + insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_stl, _("C++ STL")); +} + + +static void insert_date_items(GtkMenu *me, GtkMenu *mp, gchar *label) +{ + GtkWidget *item; + + item = gtk_menu_item_new_with_label(label); + gtk_container_add(GTK_CONTAINER(me), item); + gtk_widget_show(item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), label); + + item = gtk_menu_item_new_with_label(label); + gtk_container_add(GTK_CONTAINER(mp), item); + gtk_widget_show(item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), label); +} + + +void ui_create_insert_date_menu_items() +{ + GtkMenu *menu_edit = GTK_MENU(lookup_widget(app->window, "insert_date1_menu")); + GtkMenu *menu_popup = GTK_MENU(lookup_widget(app->popup_menu, "insert_date2_menu")); + GtkWidget *item; + + insert_date_items(menu_edit, menu_popup, _("dd.mm.yyyy")); + insert_date_items(menu_edit, menu_popup, _("mm.dd.yyyy")); + insert_date_items(menu_edit, menu_popup, _("yyyy/mm/dd")); + + item = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(menu_edit), item); + gtk_widget_show(item); + item = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(menu_popup), item); + gtk_widget_show(item); + + insert_date_items(menu_edit, menu_popup, _("dd.mm.yyyy hh:mm:ss")); + insert_date_items(menu_edit, menu_popup, _("mm.dd.yyyy hh:mm:ss")); + insert_date_items(menu_edit, menu_popup, _("yyyy/mm/dd hh:mm:ss")); + + item = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(menu_edit), item); + gtk_widget_show(item); + item = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(menu_popup), item); + gtk_widget_show(item); + + item = gtk_menu_item_new_with_label(_("Use custom date format")); + gtk_container_add(GTK_CONTAINER(menu_edit), item); + gtk_widget_show(item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), + _("Use custom date format")); + g_object_set_data_full(G_OBJECT(app->window), "insert_date_custom1", gtk_widget_ref(item), + (GDestroyNotify)gtk_widget_unref); + + item = gtk_menu_item_new_with_label(_("Use custom date format")); + gtk_container_add(GTK_CONTAINER(menu_popup), item); + gtk_widget_show(item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), + _("Use custom date format")); + g_object_set_data_full(G_OBJECT(app->popup_menu), "insert_date_custom2", gtk_widget_ref(item), + (GDestroyNotify)gtk_widget_unref); + + insert_date_items(menu_edit, menu_popup, _("Set custom date format")); +} + + +void ui_save_buttons_toggle(gboolean enable) +{ + guint i; + gboolean dirty_tabs = FALSE; + + gtk_widget_set_sensitive(app->save_buttons[0], enable); + gtk_widget_set_sensitive(app->save_buttons[1], enable); + + // save all menu item and tool button + for (i = 0; i < (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); i++) + { + // count the amount of files where changes were made and if there are some, + // we need the save all button / item + if (! dirty_tabs && doc_list[i].is_valid && doc_list[i].changed) + dirty_tabs = TRUE; + } + + gtk_widget_set_sensitive(app->save_buttons[2], (dirty_tabs > 0) ? TRUE : FALSE); + gtk_widget_set_sensitive(app->save_buttons[3], (dirty_tabs > 0) ? TRUE : FALSE); +} + + +void ui_close_buttons_toggle() +{ + guint i; + gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) ? TRUE : FALSE; + + for(i = 0; i < (sizeof(app->sensitive_buttons)/sizeof(GtkWidget*)); i++) + gtk_widget_set_sensitive(app->sensitive_buttons[i], enable); +} + + +void ui_widget_show_hide(GtkWidget *widget, gboolean show) +{ + if (show) + { + gtk_widget_show(widget); + } + else + { + gtk_widget_hide(widget); + } +} + + +void ui_build_show_hide(gint idx) +{ +#ifndef G_OS_WIN32 + gboolean is_header = FALSE; + gchar *ext = NULL; + filetype *ft; + + if (idx == -1 || doc_list[idx].file_type == NULL) + { + gtk_widget_set_sensitive(lookup_widget(app->window, "menu_build1"), FALSE); + gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1"))); + gtk_widget_set_sensitive(app->compile_button, FALSE); + gtk_widget_set_sensitive(app->run_button, FALSE); + return; + } + else + gtk_widget_set_sensitive(lookup_widget(app->window, "menu_build1"), TRUE); + + ft = doc_list[idx].file_type; + + if (doc_list[idx].file_name) + { + ext = strrchr(doc_list[idx].file_name, '.'); + } + + // TODO: separate function for matching headers, perhaps based on file extensions + if (! ext || utils_strcmp(ext + 1, "h") || utils_strcmp(ext + 1, "hpp") || + utils_strcmp(ext + 1, "hxx")) + { + is_header = TRUE; + } + + gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1"))); + + switch (ft->id) + { + case GEANY_FILETYPES_C: // intended fallthrough, C and C++ behave equal + case GEANY_FILETYPES_CPP: + { + if (ft->menu_items->menu == NULL) + { + ft->menu_items->menu = dialogs_create_build_menu_gen(idx); + g_object_ref((gpointer)ft->menu_items->menu); // to hold it after removing + + } + gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), + ft->menu_items->menu); + + if (is_header) + { + gtk_widget_set_sensitive(app->compile_button, FALSE); + gtk_widget_set_sensitive(app->run_button, FALSE); + if (ft->menu_items->can_compile) + gtk_widget_set_sensitive(ft->menu_items->item_compile, FALSE); + if (ft->menu_items->can_link) + gtk_widget_set_sensitive(ft->menu_items->item_link, FALSE); + if (ft->menu_items->can_exec) + gtk_widget_set_sensitive(ft->menu_items->item_exec, FALSE); + } + else + { + gtk_widget_set_sensitive(app->compile_button, TRUE); + gtk_widget_set_sensitive(app->run_button, TRUE); + if (ft->menu_items->can_compile) + gtk_widget_set_sensitive(ft->menu_items->item_compile, TRUE); + if (ft->menu_items->can_link) + gtk_widget_set_sensitive(ft->menu_items->item_link, TRUE); + if (ft->menu_items->can_exec) + gtk_widget_set_sensitive(ft->menu_items->item_exec, TRUE); + } + + break; + } + case GEANY_FILETYPES_LATEX: + { + if (ft->menu_items->menu == NULL) + { + ft->menu_items->menu = dialogs_create_build_menu_tex(idx); + g_object_ref((gpointer)ft->menu_items->menu); // to hold it after removing + } + if (doc_list[idx].file_name == NULL) + { + gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), + ft->menu_items->menu); + gtk_widget_set_sensitive(app->compile_button, FALSE); + gtk_widget_set_sensitive(app->run_button, FALSE); + } + else + { + gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), + ft->menu_items->menu); + gtk_widget_set_sensitive(app->compile_button, ft->menu_items->can_compile); + gtk_widget_set_sensitive(app->run_button, ft->menu_items->can_exec); + } + + break; + } + default: + { + if (ft->menu_items->menu == NULL) + { + ft->menu_items->menu = dialogs_create_build_menu_gen(idx); + g_object_ref((gpointer)ft->menu_items->menu); // to hold it after removing + } + if (doc_list[idx].file_name == NULL) + { + gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), + ft->menu_items->menu); + gtk_widget_set_sensitive(app->compile_button, FALSE); + gtk_widget_set_sensitive(app->run_button, FALSE); + if (ft->menu_items->can_compile) + gtk_widget_set_sensitive(ft->menu_items->item_compile, FALSE); + if (ft->menu_items->can_link) + gtk_widget_set_sensitive(ft->menu_items->item_link, FALSE); + if (ft->menu_items->can_exec) gtk_widget_set_sensitive(ft->menu_items->item_exec, FALSE); + } + else + { + gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), + ft->menu_items->menu); + gtk_widget_set_sensitive(app->compile_button, ft->menu_items->can_compile); + gtk_widget_set_sensitive(app->run_button, ft->menu_items->can_exec); + if (ft->menu_items->can_compile) + gtk_widget_set_sensitive(ft->menu_items->item_compile, TRUE); + if (ft->menu_items->can_link) + gtk_widget_set_sensitive(ft->menu_items->item_link, TRUE); + if (ft->menu_items->can_exec) + gtk_widget_set_sensitive(ft->menu_items->item_exec, TRUE); + } + } + } +#endif +} + + +void ui_treeviews_show_hide(gboolean force) +{ + GtkWidget *widget; + +/* geany_debug("\nSidebar: %s\nSymbol: %s\nFiles: %s", ui_btoa(app->sidebar_visible), + ui_btoa(app->sidebar_symbol_visible), ui_btoa(app->sidebar_openfiles_visible)); +*/ + + if (! force && ! app->sidebar_visible && (app->sidebar_openfiles_visible || + app->sidebar_symbol_visible)) + { + app->sidebar_visible = TRUE; + } + else if (! app->sidebar_openfiles_visible && ! app->sidebar_symbol_visible) + { + app->sidebar_visible = FALSE; + } + + widget = lookup_widget(app->window, "menu_show_sidebar1"); + if (app->sidebar_visible != gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) + { + app->ignore_callback = TRUE; + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), app->sidebar_visible); + app->ignore_callback = FALSE; + } + + ui_widget_show_hide(app->treeview_notebook, app->sidebar_visible); + + ui_widget_show_hide(gtk_notebook_get_nth_page( + GTK_NOTEBOOK(app->treeview_notebook), 0), app->sidebar_symbol_visible); + ui_widget_show_hide(gtk_notebook_get_nth_page( + GTK_NOTEBOOK(app->treeview_notebook), 1), app->sidebar_openfiles_visible); +} + + +void ui_document_show_hide(gint idx) +{ + gchar *widget_name; + + if (idx == -1 || ! doc_list[idx].is_valid) return; + app->ignore_callback = TRUE; + + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_line_breaking1")), + doc_list[idx].line_breaking); + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_use_auto_indention1")), + doc_list[idx].use_auto_indention); + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "set_file_readonly1")), + doc_list[idx].readonly); + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_write_unicode_bom1")), + doc_list[idx].has_bom); + + switch (sci_get_eol_mode(doc_list[idx].sci)) + { + case SC_EOL_CR: widget_name = "cr"; break; + case SC_EOL_LF: widget_name = "lf"; break; + default: widget_name = "crlf"; break; + } + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, widget_name)), + TRUE); + + gtk_widget_set_sensitive(lookup_widget(app->window, "menu_write_unicode_bom1"), + utils_is_unicode_charset(doc_list[idx].encoding)); + + encodings_select_radio_item(doc_list[idx].encoding); + filetypes_select_radio_item(doc_list[idx].file_type); + + app->ignore_callback = FALSE; + +} + + +void ui_update_toolbar_icons(GtkIconSize size) +{ + GtkWidget *button_image = NULL; + GtkWidget *widget = NULL; + GtkWidget *oldwidget = NULL; + + // destroy old widget + widget = lookup_widget(app->window, "toolbutton22"); + oldwidget = gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(widget)); + if (oldwidget && GTK_IS_WIDGET(oldwidget)) gtk_widget_destroy(oldwidget); + // create new widget + button_image = ui_new_image_from_inline(GEANY_IMAGE_SAVE_ALL, FALSE); + gtk_widget_show(button_image); + gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(widget), button_image); + + gtk_toolbar_set_icon_size(GTK_TOOLBAR(app->toolbar), size); +} + + +void ui_update_toolbar_items() +{ + // show toolbar + GtkWidget *widget = lookup_widget(app->window, "menu_show_toolbar1"); + if (app->toolbar_visible && ! gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) + { + app->toolbar_visible = ! app->toolbar_visible; // will be changed by the toggled callback + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE); + } + else if (! app->toolbar_visible && gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) + { + app->toolbar_visible = ! app->toolbar_visible; // will be changed by the toggled callback + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), FALSE); + } + + // fileops + ui_widget_show_hide(lookup_widget(app->window, "menutoolbutton1"), app->pref_toolbar_show_fileops); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton9"), app->pref_toolbar_show_fileops); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton10"), app->pref_toolbar_show_fileops); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton22"), app->pref_toolbar_show_fileops); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton23"), app->pref_toolbar_show_fileops); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton15"), app->pref_toolbar_show_fileops); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem7"), app->pref_toolbar_show_fileops); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem2"), app->pref_toolbar_show_fileops); + // search + ui_widget_show_hide(lookup_widget(app->window, "entry1"), app->pref_toolbar_show_search); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton18"), app->pref_toolbar_show_search); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem5"), app->pref_toolbar_show_search); + // goto line + ui_widget_show_hide(lookup_widget(app->window, "entry_goto_line"), app->pref_toolbar_show_goto); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton25"), app->pref_toolbar_show_goto); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem8"), app->pref_toolbar_show_goto); + // compile + ui_widget_show_hide(lookup_widget(app->window, "toolbutton13"), app->pref_toolbar_show_compile); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton26"), app->pref_toolbar_show_compile); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem6"), app->pref_toolbar_show_compile); + // colour + ui_widget_show_hide(lookup_widget(app->window, "toolbutton24"), app->pref_toolbar_show_colour); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem3"), app->pref_toolbar_show_colour); + // zoom + ui_widget_show_hide(lookup_widget(app->window, "toolbutton20"), app->pref_toolbar_show_zoom); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton21"), app->pref_toolbar_show_zoom); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem4"), app->pref_toolbar_show_zoom); + // undo + ui_widget_show_hide(lookup_widget(app->window, "toolbutton_undo"), app->pref_toolbar_show_undo); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton_redo"), app->pref_toolbar_show_undo); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem9"), app->pref_toolbar_show_undo); +} + + +GdkPixbuf *ui_new_pixbuf_from_inline(gint img, gboolean small_img) +{ + switch(img) + { + case GEANY_IMAGE_SMALL_CROSS: return gdk_pixbuf_new_from_inline(-1, close_small_inline, FALSE, NULL); break; + case GEANY_IMAGE_LOGO: return gdk_pixbuf_new_from_inline(-1, aladin_inline, FALSE, NULL); break; + case GEANY_IMAGE_SAVE_ALL: + { + if ((app->toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR) || small_img) + { + return gdk_pixbuf_scale_simple(gdk_pixbuf_new_from_inline(-1, save_all_inline, FALSE, NULL), + 16, 16, GDK_INTERP_HYPER); + } + else + { + return gdk_pixbuf_new_from_inline(-1, save_all_inline, FALSE, NULL); + } + break; + } + case GEANY_IMAGE_NEW_ARROW: + { + if ((app->toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR) || small_img) + { + return gdk_pixbuf_scale_simple(gdk_pixbuf_new_from_inline(-1, newfile_inline, FALSE, NULL), + 16, 16, GDK_INTERP_HYPER); + } + else + { + return gdk_pixbuf_new_from_inline(-1, newfile_inline, FALSE, NULL); + } + break; + } + default: return NULL; + } + + //return gtk_image_new_from_pixbuf(pixbuf); +} + + +GtkWidget *ui_new_image_from_inline(gint img, gboolean small_img) +{ + return gtk_image_new_from_pixbuf(ui_new_pixbuf_from_inline(img, small_img)); +} + + +void ui_add_recent_file(const gchar *filename) +{ + if (g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp) == NULL) + { + g_queue_push_head(app->recent_queue, g_strdup(filename)); + if (g_queue_get_length(app->recent_queue) > app->mru_length) + { + g_free(g_queue_pop_tail(app->recent_queue)); + } + ui_update_recent_menu(); + } +} + + +static void ui_update_recent_menu() +{ + GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu"); + GtkWidget *recent_files_item = lookup_widget(app->window, "recent_files1"); + GtkWidget *tmp; + gchar *filename; + GList *children; + + if (g_queue_get_length(app->recent_queue) == 0) + { + gtk_widget_set_sensitive(recent_files_item, FALSE); + return; + } + else if (! GTK_WIDGET_SENSITIVE(recent_files_item)) + { + gtk_widget_set_sensitive(recent_files_item, TRUE); + } + + // clean the MRU list before adding an item + children = gtk_container_get_children(GTK_CONTAINER(recent_menu)); + if (g_list_length(children) > app->mru_length - 1) + { + GList *item = g_list_nth(children, app->mru_length - 1); + while (item != NULL) + { + if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data)); + item = g_list_next(item); + } + } + + filename = g_queue_peek_head(app->recent_queue); + tmp = gtk_menu_item_new_with_label(filename); + gtk_widget_show(tmp); + gtk_menu_shell_prepend(GTK_MENU_SHELL(recent_menu), tmp); + g_signal_connect((gpointer) tmp, "activate", + G_CALLBACK(on_recent_file_activate), (gpointer) filename); +} + + +static void ui_recreate_recent_menu() +{ + GList *item, *children; + void *data; + GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu"); + + children = gtk_container_get_children(GTK_CONTAINER(recent_menu)); + + // remove all menu items (but not the list elements) + for (item = children; item != NULL; item = g_list_next(item)) + { + data = item->data; + if (! GTK_IS_MENU_ITEM(data)) continue; + gtk_widget_destroy(GTK_WIDGET(data)); + } + dialogs_create_recent_menu(); +} + + +void ui_recent_file_loaded(const gchar *filename) +{ + GList *item = + g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp); + gchar *data; + + g_return_if_fail(item != NULL); + // first reorder the queue + data = item->data; + g_queue_remove(app->recent_queue, data); + g_queue_push_head(app->recent_queue, data); + + // now recreate the recent files menu + ui_recreate_recent_menu(); +} + + +void ui_show_markers_margin() +{ + gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); + + for(i = 0; i < max; i++) + { + idx = document_get_n_idx(i); + sci_set_symbol_margin(doc_list[idx].sci, app->show_markers_margin); + } +} + + +void ui_show_linenumber_margin() +{ + gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); + + for(i = 0; i < max; i++) + { + idx = document_get_n_idx(i); + sci_set_line_numbers(doc_list[idx].sci, app->show_linenumber_margin, 0); + } +} + + + diff --git a/src/ui_utils.h b/src/ui_utils.h new file mode 100644 index 00000000..ab67fa84 --- /dev/null +++ b/src/ui_utils.h @@ -0,0 +1,97 @@ +/* + * ui_utils.h - this file is part of Geany, a fast and lightweight IDE + * + * Copyright 2006 Enrico Troeger + * Copyright 2006 Nick Treleaven + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $Id$ + */ + +#ifndef GEANY_UI_UTILS_H +#define GEANY_UI_UTILS_H 1 + +/* allow_override is TRUE if text can be ignored when another message has been set + * that didn't use allow_override and has not timed out. */ +void ui_set_statusbar(const gchar *text, gboolean allow_override); + +void ui_update_statusbar(gint idx, gint pos); + + +/* This sets the window title according to the current filename. */ +void ui_set_window_title(gint index); + +void ui_set_editor_font(const gchar *font_name); + +void ui_set_fullscreen(); + + +void ui_update_tag_list(gint idx, gboolean update); + + +void ui_update_popup_reundo_items(gint idx); + +void ui_update_popup_copy_items(gint idx); + +void ui_update_popup_goto_items(gboolean enable); + + +void ui_update_menu_copy_items(gint idx); + +void ui_update_insert_include_item(gint idx, gint item); + +void ui_update_fold_items(); + + +void ui_create_insert_menu_items(); + +void ui_create_insert_date_menu_items(); + + +void ui_save_buttons_toggle(gboolean enable); + +void ui_close_buttons_toggle(); + + +void ui_widget_show_hide(GtkWidget *widget, gboolean show); + +void ui_build_show_hide(gint); + +void ui_treeviews_show_hide(gboolean force); + +void ui_document_show_hide(gint idx); + + +void ui_update_toolbar_icons(GtkIconSize size); + +void ui_update_toolbar_items(); + + +GdkPixbuf *ui_new_pixbuf_from_inline(gint img, gboolean small_img); + +GtkWidget *ui_new_image_from_inline(gint img, gboolean small_img); + + +void ui_add_recent_file(const gchar *filename); + +void ui_recent_file_loaded(const gchar *filename); + + +void ui_show_markers_margin(); + +void ui_show_linenumber_margin(); + +#endif diff --git a/src/utils.c b/src/utils.c index d1ae227b..6611a988 100644 --- a/src/utils.c +++ b/src/utils.c @@ -39,27 +39,15 @@ #endif #include "support.h" -#include "interface.h" -#include "callbacks.h" #include "document.h" -#include "msgwindow.h" -#include "encodings.h" -#include "templates.h" -#include "treeviews.h" #include "sciwrappers.h" #include "dialogs.h" #include "win32.h" #include "main.h" +#include "encodings.h" #include "utils.h" -#include "images.c" - - -static void utils_update_recent_menu(); - -static void utils_recreate_recent_menu(); - void utils_start_browser(const gchar *uri) { @@ -97,187 +85,6 @@ void utils_start_browser(const gchar *uri) } -/* allow_override is TRUE if text can be ignored when another message has been set - * that didn't use allow_override and has not timed out. */ -void utils_set_statusbar(const gchar *text, gboolean allow_override) -{ - static glong last_time = 0; - GTimeVal timeval; - const gint GEANY_STATUS_TIMEOUT = 1; - - g_get_current_time(&timeval); - - if (! allow_override) - { - gtk_statusbar_pop(GTK_STATUSBAR(app->statusbar), 1); - gtk_statusbar_push(GTK_STATUSBAR(app->statusbar), 1, text); - last_time = timeval.tv_sec; - } - else - if (timeval.tv_sec > last_time + GEANY_STATUS_TIMEOUT) - { - gtk_statusbar_pop(GTK_STATUSBAR(app->statusbar), 1); - gtk_statusbar_push(GTK_STATUSBAR(app->statusbar), 1, text); - } -} - - -/* updates the status bar */ -void utils_update_statusbar(gint idx, gint pos) -{ - gchar *text; - const gchar *cur_tag; - guint line, col; - - if (idx == -1) idx = document_get_cur_idx(); - - if (idx >= 0 && doc_list[idx].is_valid) - { - utils_get_current_function(idx, &cur_tag); - - if (pos == -1) pos = sci_get_current_position(doc_list[idx].sci); - line = sci_get_line_from_position(doc_list[idx].sci, pos); - col = sci_get_col_from_position(doc_list[idx].sci, pos); - - text = g_strdup_printf(_("%c line: % 4d column: % 3d selection: % 4d %s mode: %s%s cur. function: %s encoding: %s %s filetype: %s"), - (doc_list[idx].changed) ? 42 : 32, - (line + 1), (col + 1), - sci_get_selected_text_length(doc_list[idx].sci) - 1, - doc_list[idx].do_overwrite ? _("OVR") : _("INS"), - document_get_eol_mode(idx), - (doc_list[idx].readonly) ? ", read only" : "", - cur_tag, - (doc_list[idx].encoding) ? doc_list[idx].encoding : _("unknown"), - (utils_is_unicode_charset(doc_list[idx].encoding)) ? ((doc_list[idx].has_bom) ? _("(with BOM)") : _("(without BOM)")) : "", - (doc_list[idx].file_type) ? doc_list[idx].file_type->title : _("unknown")); - utils_set_statusbar(text, TRUE); //can be overridden by status messages - g_free(text); - } - else - { - utils_set_statusbar("", TRUE); //can be overridden by status messages - } -} - - -void utils_update_popup_reundo_items(gint index) -{ - gboolean enable_undo; - gboolean enable_redo; - - if (index == -1) - { - enable_undo = FALSE; - enable_redo = FALSE; - } - else - { - enable_undo = sci_can_undo(doc_list[index].sci); - enable_redo = sci_can_redo(doc_list[index].sci); - } - - // index 0 is the popup menu, 1 is the menubar - gtk_widget_set_sensitive(app->undo_items[0], enable_undo); - gtk_widget_set_sensitive(app->undo_items[1], enable_undo); - gtk_widget_set_sensitive(app->undo_items[2], enable_undo); - - gtk_widget_set_sensitive(app->redo_items[0], enable_redo); - gtk_widget_set_sensitive(app->redo_items[1], enable_redo); - gtk_widget_set_sensitive(app->redo_items[2], enable_redo); -} - - -void utils_update_popup_copy_items(gint index) -{ - gboolean enable; - guint i; - - if (index == -1) enable = FALSE; - else enable = sci_can_copy(doc_list[index].sci); - - for(i = 0; i < (sizeof(app->popup_items)/sizeof(GtkWidget*)); i++) - gtk_widget_set_sensitive(app->popup_items[i], enable); -} - - -void utils_update_menu_copy_items(gint idx) -{ - gboolean enable = FALSE; - guint i; - GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(app->window)); - - if (IS_SCINTILLA(focusw)) - enable = (idx == -1) ? FALSE : sci_can_copy(doc_list[idx].sci); - else - if (GTK_IS_EDITABLE(focusw)) - enable = gtk_editable_get_selection_bounds(GTK_EDITABLE(focusw), NULL, NULL); - else - if (GTK_IS_TEXT_VIEW(focusw)) - { - GtkTextBuffer *buffer = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(focusw)); - enable = gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL); - } - - for(i = 0; i < (sizeof(app->menu_copy_items)/sizeof(GtkWidget*)); i++) - gtk_widget_set_sensitive(app->menu_copy_items[i], enable); -} - - -void utils_update_insert_include_item(gint idx, gint item) -{ - gboolean enable = FALSE; - - if (idx == -1 || doc_list[idx].file_type == NULL) enable = FALSE; - else if (doc_list[idx].file_type->id == GEANY_FILETYPES_C || - doc_list[idx].file_type->id == GEANY_FILETYPES_CPP) - { - enable = TRUE; - } - gtk_widget_set_sensitive(app->menu_insert_include_item[item], enable); -} - - -void utils_update_popup_goto_items(gboolean enable) -{ - gtk_widget_set_sensitive(app->popup_goto_items[0], enable); - gtk_widget_set_sensitive(app->popup_goto_items[1], enable); - gtk_widget_set_sensitive(app->popup_goto_items[2], enable); -} - - -void utils_save_buttons_toggle(gboolean enable) -{ - guint i; - gboolean dirty_tabs = FALSE; - - gtk_widget_set_sensitive(app->save_buttons[0], enable); - gtk_widget_set_sensitive(app->save_buttons[1], enable); - - // save all menu item and tool button - for (i = 0; i < (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); i++) - { - // count the amount of files where changes were made and if there are some, - // we need the save all button / item - if (! dirty_tabs && doc_list[i].is_valid && doc_list[i].changed) - dirty_tabs = TRUE; - } - - gtk_widget_set_sensitive(app->save_buttons[2], (dirty_tabs > 0) ? TRUE : FALSE); - gtk_widget_set_sensitive(app->save_buttons[3], (dirty_tabs > 0) ? TRUE : FALSE); -} - - -void utils_close_buttons_toggle(void) -{ - guint i; - gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) ? TRUE : FALSE; - - for(i = 0; i < (sizeof(app->sensitive_buttons)/sizeof(GtkWidget*)); i++) - gtk_widget_set_sensitive(app->sensitive_buttons[i], enable); -} - - /* taken from anjuta, to determine the EOL mode of the file */ gint utils_get_line_endings(gchar* buffer, glong size) { @@ -384,59 +191,6 @@ gboolean utils_is_opening_brace(gchar c) } -void utils_set_editor_font(const gchar *font_name) -{ - gint i, size; - gchar *fname; - PangoFontDescription *font_desc; - - g_return_if_fail(font_name != NULL); - // do nothing if font has not changed - if (app->editor_font != NULL) - if (strcmp(font_name, app->editor_font) == 0) return; - - g_free(app->editor_font); - app->editor_font = g_strdup(font_name); - - font_desc = pango_font_description_from_string(app->editor_font); - - fname = g_strdup_printf("!%s", pango_font_description_get_family(font_desc)); - size = pango_font_description_get_size(font_desc) / PANGO_SCALE; - - /* We copy the current style, and update the font in all open tabs. */ - for(i = 0; i < GEANY_MAX_OPEN_FILES; i++) - { - if (doc_list[i].sci) - { - document_set_font(i, fname, size); - } - } - pango_font_description_free(font_desc); - - msgwin_status_add(_("Font updated (%s)."), app->editor_font); - g_free(fname); -} - - -/* This sets the window title according to the current filename. */ -void utils_set_window_title(gint index) -{ - gchar *title; - - if (index >= 0) - { - title = g_strdup_printf ("%s: %s %s", - PACKAGE, - (doc_list[index].file_name != NULL) ? g_filename_to_utf8(doc_list[index].file_name, -1, NULL, NULL, NULL) : _("untitled"), - doc_list[index].changed ? _("(Unsaved)") : ""); - gtk_window_set_title(GTK_WINDOW(app->window), title); - g_free(title); - } - else - gtk_window_set_title(GTK_WINDOW(app->window), PACKAGE); -} - - const GList *utils_get_tag_list(gint idx, guint tag_types) { static GList *tag_names = NULL; @@ -547,70 +301,6 @@ gboolean utils_goto_line(gint idx, gint line) } -GdkPixbuf *utils_new_pixbuf_from_inline(gint img, gboolean small_img) -{ - switch(img) - { - case GEANY_IMAGE_SMALL_CROSS: return gdk_pixbuf_new_from_inline(-1, close_small_inline, FALSE, NULL); break; - case GEANY_IMAGE_LOGO: return gdk_pixbuf_new_from_inline(-1, aladin_inline, FALSE, NULL); break; - case GEANY_IMAGE_SAVE_ALL: - { - if ((app->toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR) || small_img) - { - return gdk_pixbuf_scale_simple(gdk_pixbuf_new_from_inline(-1, save_all_inline, FALSE, NULL), - 16, 16, GDK_INTERP_HYPER); - } - else - { - return gdk_pixbuf_new_from_inline(-1, save_all_inline, FALSE, NULL); - } - break; - } - case GEANY_IMAGE_NEW_ARROW: - { - if ((app->toolbar_icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR) || small_img) - { - return gdk_pixbuf_scale_simple(gdk_pixbuf_new_from_inline(-1, newfile_inline, FALSE, NULL), - 16, 16, GDK_INTERP_HYPER); - } - else - { - return gdk_pixbuf_new_from_inline(-1, newfile_inline, FALSE, NULL); - } - break; - } - default: return NULL; - } - - //return gtk_image_new_from_pixbuf(pixbuf); -} - - -void utils_update_toolbar_icons(GtkIconSize size) -{ - GtkWidget *button_image = NULL; - GtkWidget *widget = NULL; - GtkWidget *oldwidget = NULL; - - // destroy old widget - widget = lookup_widget(app->window, "toolbutton22"); - oldwidget = gtk_tool_button_get_icon_widget(GTK_TOOL_BUTTON(widget)); - if (oldwidget && GTK_IS_WIDGET(oldwidget)) gtk_widget_destroy(oldwidget); - // create new widget - button_image = utils_new_image_from_inline(GEANY_IMAGE_SAVE_ALL, FALSE); - gtk_widget_show(button_image); - gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(widget), button_image); - - gtk_toolbar_set_icon_size(GTK_TOOLBAR(app->toolbar), size); -} - - -GtkWidget *utils_new_image_from_inline(gint img, gboolean small_img) -{ - return gtk_image_new_from_pixbuf(utils_new_pixbuf_from_inline(img, small_img)); -} - - gint utils_write_file(const gchar *filename, const gchar *text) { FILE *fp; @@ -645,193 +335,6 @@ gint utils_write_file(const gchar *filename, const gchar *text) } -void utils_show_markers_margin(void) -{ - gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); - - for(i = 0; i < max; i++) - { - idx = document_get_n_idx(i); - sci_set_symbol_margin(doc_list[idx].sci, app->show_markers_margin); - } -} - - -void utils_show_linenumber_margin(void) -{ - gint i, idx, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); - - for(i = 0; i < max; i++) - { - idx = document_get_n_idx(i); - sci_set_line_numbers(doc_list[idx].sci, app->show_linenumber_margin, 0); - } -} - - -void utils_set_fullscreen(void) -{ - if (app->fullscreen) - { - gtk_window_fullscreen(GTK_WINDOW(app->window)); - } - else - { - gtk_window_unfullscreen(GTK_WINDOW(app->window)); - } -} - - -void utils_update_tag_list(gint idx, gboolean update) -{ - GList *tmp; - const GList *tags; - - if (gtk_bin_get_child(GTK_BIN(app->tagbar))) - gtk_container_remove(GTK_CONTAINER(app->tagbar), gtk_bin_get_child(GTK_BIN(app->tagbar))); - - if (app->default_tag_tree == NULL) - { - GtkTreeIter iter; - GtkTreeStore *store = gtk_tree_store_new(1, G_TYPE_STRING); - app->default_tag_tree = gtk_tree_view_new(); - treeviews_prepare_taglist(app->default_tag_tree, store); - gtk_tree_store_append(store, &iter, NULL); - gtk_tree_store_set(store, &iter, 0, _("No tags found"), -1); - gtk_widget_show(app->default_tag_tree); - g_object_ref((gpointer)app->default_tag_tree); // to hold it after removing - } - - // make all inactive, because there is no more tab left, or something strange occured - if (idx == -1 || doc_list[idx].file_type == NULL || ! doc_list[idx].file_type->has_tags) - { - gtk_widget_set_sensitive(app->tagbar, FALSE); - gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); - return; - } - - if (update) - { // updating the tag list in the left tag window - if (doc_list[idx].tag_tree == NULL) - { - doc_list[idx].tag_store = gtk_tree_store_new(1, G_TYPE_STRING); - doc_list[idx].tag_tree = gtk_tree_view_new(); - treeviews_prepare_taglist(doc_list[idx].tag_tree, doc_list[idx].tag_store); - gtk_widget_show(doc_list[idx].tag_tree); - g_object_ref((gpointer)doc_list[idx].tag_tree); // to hold it after removing - } - - tags = utils_get_tag_list(idx, tm_tag_max_t); - if (doc_list[idx].tm_file != NULL && tags != NULL) - { - GtkTreeIter iter; - GtkTreeModel *model; - - doc_list[idx].has_tags = TRUE; - gtk_tree_store_clear(doc_list[idx].tag_store); - // unref the store to speed up the filling(from TreeView Tutorial) - model = gtk_tree_view_get_model(GTK_TREE_VIEW(doc_list[idx].tag_tree)); - g_object_ref(model); // Make sure the model stays with us after the tree view unrefs it - gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), NULL); // Detach model from view - - treeviews_init_tag_list(idx); - for (tmp = (GList*)tags; tmp; tmp = g_list_next(tmp)) - { - switch (((GeanySymbol*)tmp->data)->type) - { - case tm_tag_prototype_t: - case tm_tag_function_t: - { - if (tv.tag_function.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_function)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_macro_t: - case tm_tag_macro_with_arg_t: - { - if (tv.tag_macro.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_macro)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_class_t: - { - if (tv.tag_class.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_class)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_member_t: - { - if (tv.tag_member.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_member)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_typedef_t: - case tm_tag_enum_t: - case tm_tag_union_t: - case tm_tag_struct_t: - { - if (tv.tag_struct.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_struct)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_variable_t: - { - if (tv.tag_variable.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_variable)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - case tm_tag_namespace_t: - { - if (tv.tag_namespace.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_namespace)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - break; - } - default: - { - if (tv.tag_other.stamp == -1) break; - gtk_tree_store_append(doc_list[idx].tag_store, &iter, &(tv.tag_other)); - gtk_tree_store_set(doc_list[idx].tag_store, &iter, 0, ((GeanySymbol*)tmp->data)->str, -1); - } - } - } - gtk_tree_view_set_model(GTK_TREE_VIEW(doc_list[idx].tag_tree), model); // Re-attach model to view - g_object_unref(model); - gtk_tree_view_expand_all(GTK_TREE_VIEW(doc_list[idx].tag_tree)); - - gtk_widget_set_sensitive(app->tagbar, TRUE); - gtk_container_add(GTK_CONTAINER(app->tagbar), doc_list[idx].tag_tree); - /// TODO why I have to do this here? - g_object_ref((gpointer)doc_list[idx].tag_tree); - } - else - { // tags == NULL - gtk_widget_set_sensitive(app->tagbar, FALSE); - gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); - } - } - else - { // update == FALSE - if (doc_list[idx].has_tags) - { - gtk_widget_set_sensitive(app->tagbar, TRUE); - gtk_container_add(GTK_CONTAINER(app->tagbar), doc_list[idx].tag_tree); - } - else - { - gtk_widget_set_sensitive(app->tagbar, FALSE); - gtk_container_add(GTK_CONTAINER(app->tagbar), app->default_tag_tree); - } - } -} - - gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const gchar *charset) { gchar *utf8_content = NULL; @@ -1215,152 +718,6 @@ gdouble utils_scale_round (gdouble val, gdouble factor) } -void utils_widget_show_hide(GtkWidget *widget, gboolean show) -{ - if (show) - { - gtk_widget_show(widget); - } - else - { - gtk_widget_hide(widget); - } -} - - -void utils_build_show_hide(gint idx) -{ -#ifndef G_OS_WIN32 - gboolean is_header = FALSE; - gchar *ext = NULL; - filetype *ft; - - if (idx == -1 || doc_list[idx].file_type == NULL) - { - gtk_widget_set_sensitive(lookup_widget(app->window, "menu_build1"), FALSE); - gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1"))); - gtk_widget_set_sensitive(app->compile_button, FALSE); - gtk_widget_set_sensitive(app->run_button, FALSE); - return; - } - else - gtk_widget_set_sensitive(lookup_widget(app->window, "menu_build1"), TRUE); - - ft = doc_list[idx].file_type; - - if (doc_list[idx].file_name) - { - ext = strrchr(doc_list[idx].file_name, '.'); - } - - if (! ext || utils_strcmp(ext + 1, "h") || utils_strcmp(ext + 1, "hpp") || utils_strcmp(ext + 1, "hxx")) - { - is_header = TRUE; - } - - gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1"))); - - switch (ft->id) - { - case GEANY_FILETYPES_C: // intended fallthrough, C and C++ behave equal - case GEANY_FILETYPES_CPP: - { - if (ft->menu_items->menu == NULL) - { - ft->menu_items->menu = dialogs_create_build_menu_gen(idx); - g_object_ref((gpointer)ft->menu_items->menu); // to hold it after removing - - } - gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), - ft->menu_items->menu); - - if (is_header) - { - gtk_widget_set_sensitive(app->compile_button, FALSE); - gtk_widget_set_sensitive(app->run_button, FALSE); - if (ft->menu_items->can_compile) - gtk_widget_set_sensitive(ft->menu_items->item_compile, FALSE); - if (ft->menu_items->can_link) - gtk_widget_set_sensitive(ft->menu_items->item_link, FALSE); - if (ft->menu_items->can_exec) - gtk_widget_set_sensitive(ft->menu_items->item_exec, FALSE); - } - else - { - gtk_widget_set_sensitive(app->compile_button, TRUE); - gtk_widget_set_sensitive(app->run_button, TRUE); - if (ft->menu_items->can_compile) - gtk_widget_set_sensitive(ft->menu_items->item_compile, TRUE); - if (ft->menu_items->can_link) - gtk_widget_set_sensitive(ft->menu_items->item_link, TRUE); - if (ft->menu_items->can_exec) - gtk_widget_set_sensitive(ft->menu_items->item_exec, TRUE); - } - - break; - } - case GEANY_FILETYPES_LATEX: - { - if (ft->menu_items->menu == NULL) - { - ft->menu_items->menu = dialogs_create_build_menu_tex(idx); - g_object_ref((gpointer)ft->menu_items->menu); // to hold it after removing - } - if (doc_list[idx].file_name == NULL) - { - gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), - ft->menu_items->menu); - gtk_widget_set_sensitive(app->compile_button, FALSE); - gtk_widget_set_sensitive(app->run_button, FALSE); - } - else - { - gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), - ft->menu_items->menu); - gtk_widget_set_sensitive(app->compile_button, ft->menu_items->can_compile); - gtk_widget_set_sensitive(app->run_button, ft->menu_items->can_exec); - } - - break; - } - default: - { - if (ft->menu_items->menu == NULL) - { - ft->menu_items->menu = dialogs_create_build_menu_gen(idx); - g_object_ref((gpointer)ft->menu_items->menu); // to hold it after removing - } - if (doc_list[idx].file_name == NULL) - { - gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), - ft->menu_items->menu); - gtk_widget_set_sensitive(app->compile_button, FALSE); - gtk_widget_set_sensitive(app->run_button, FALSE); - if (ft->menu_items->can_compile) - gtk_widget_set_sensitive(ft->menu_items->item_compile, FALSE); - if (ft->menu_items->can_link) - gtk_widget_set_sensitive(ft->menu_items->item_link, FALSE); - if (ft->menu_items->can_exec) gtk_widget_set_sensitive(ft->menu_items->item_exec, FALSE); - } - else - { - gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), - ft->menu_items->menu); - gtk_widget_set_sensitive(app->compile_button, ft->menu_items->can_compile); - gtk_widget_set_sensitive(app->run_button, ft->menu_items->can_exec); - if (ft->menu_items->can_compile) - gtk_widget_set_sensitive(ft->menu_items->item_compile, TRUE); - if (ft->menu_items->can_link) - gtk_widget_set_sensitive(ft->menu_items->item_link, TRUE); - if (ft->menu_items->can_exec) - gtk_widget_set_sensitive(ft->menu_items->item_exec, TRUE); - } - } - } -#endif -} - - /* (taken from libexo from os-cillation) * NULL-safe string comparison. Returns TRUE if both a and b are * NULL or if a and b refer to valid strings which are equal. @@ -1417,7 +774,7 @@ gchar utils_brace_opposite(gchar ch) } -gchar *utils_get_hostname(void) +gchar *utils_get_hostname() { #ifndef HAVE_GETHOSTNAME return g_strdup("localhost"); @@ -1573,7 +930,7 @@ gint utils_strpos(const gchar *haystack, const gchar *needle) } -gchar *utils_get_date_time(void) +gchar *utils_get_date_time() { time_t tp = time(NULL); const struct tm *tm = localtime(&tp); @@ -1584,7 +941,7 @@ gchar *utils_get_date_time(void) } -gchar *utils_get_date(void) +gchar *utils_get_date() { time_t tp = time(NULL); const struct tm *tm = localtime(&tp); @@ -1595,155 +952,6 @@ gchar *utils_get_date(void) } -static void insert_include_items(GtkMenu *me, GtkMenu *mp, gchar **includes, gchar *label) -{ - guint i = 0; - GtkWidget *tmp_menu; - GtkWidget *tmp_popup; - GtkWidget *edit_menu, *edit_menu_item; - GtkWidget *popup_menu, *popup_menu_item; - - edit_menu = gtk_menu_new(); - popup_menu = gtk_menu_new(); - edit_menu_item = gtk_menu_item_new_with_label(label); - popup_menu_item = gtk_menu_item_new_with_label(label); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(edit_menu_item), edit_menu); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(popup_menu_item), popup_menu); - - while (includes[i] != NULL) - { - tmp_menu = gtk_menu_item_new_with_label(includes[i]); - tmp_popup = gtk_menu_item_new_with_label(includes[i]); - gtk_container_add(GTK_CONTAINER(edit_menu), tmp_menu); - gtk_container_add(GTK_CONTAINER(popup_menu), tmp_popup); - g_signal_connect((gpointer) tmp_menu, "activate", G_CALLBACK(on_insert_include_activate), - (gpointer) includes[i]); - g_signal_connect((gpointer) tmp_popup, "activate", G_CALLBACK(on_insert_include_activate), - (gpointer) includes[i]); - i++; - } - gtk_widget_show_all(edit_menu_item); - gtk_widget_show_all(popup_menu_item); - gtk_container_add(GTK_CONTAINER(me), edit_menu_item); - gtk_container_add(GTK_CONTAINER(mp), popup_menu_item); -} - - -void utils_create_insert_menu_items(void) -{ - GtkMenu *menu_edit = GTK_MENU(lookup_widget(app->window, "insert_include2_menu")); - GtkMenu *menu_popup = GTK_MENU(lookup_widget(app->popup_menu, "insert_include1_menu")); - GtkWidget *blank; - const gchar *c_includes_stdlib[] = { - "assert.h", "ctype.h", "errno.h", "float.h", "limits.h", "locale.h", "math.h", "setjmp.h", - "signal.h", "stdarg.h", "stddef.h", "stdio.h", "stdlib.h", "string.h", "time.h", NULL - }; - const gchar *c_includes_c99[] = { - "complex.h", "fenv.h", "inttypes.h", "iso646.h", "stdbool.h", "stdint.h", - "tgmath.h", "wchar.h", "wctype.h", NULL - }; - const gchar *c_includes_cpp[] = { - "cstdio", "cstring", "cctype", "cmath", "ctime", "cstdlib", "cstdarg", NULL - }; - const gchar *c_includes_cppstdlib[] = { - "iostream", "fstream", "iomanip", "sstream", "exception", "stdexcept", - "memory", "locale", NULL - }; - const gchar *c_includes_stl[] = { - "bitset", "dequev", "list", "map", "set", "queue", "stack", "vector", "algorithm", - "iterator", "functional", "string", "complex", "valarray", NULL - }; - - blank = gtk_menu_item_new_with_label("#include \"...\""); - gtk_container_add(GTK_CONTAINER(menu_edit), blank); - gtk_widget_show(blank); - g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_insert_include_activate), - (gpointer) "blank"); - blank = gtk_separator_menu_item_new (); - gtk_container_add(GTK_CONTAINER(menu_edit), blank); - gtk_widget_show(blank); - - blank = gtk_menu_item_new_with_label("#include \"...\""); - gtk_container_add(GTK_CONTAINER(menu_popup), blank); - gtk_widget_show(blank); - g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_insert_include_activate), - (gpointer) "blank"); - blank = gtk_separator_menu_item_new(); - gtk_container_add(GTK_CONTAINER(menu_popup), blank); - gtk_widget_show(blank); - - insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_stdlib, _("C Standard Library")); - insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_c99, _("ISO C99")); - insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_cpp, _("C++ (C Standard Library)")); - insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_cppstdlib, _("C++ Standard Library")); - insert_include_items(menu_edit, menu_popup, (gchar**) c_includes_stl, _("C++ STL")); -} - - -static void insert_date_items(GtkMenu *me, GtkMenu *mp, gchar *label) -{ - GtkWidget *item; - - item = gtk_menu_item_new_with_label(label); - gtk_container_add(GTK_CONTAINER(me), item); - gtk_widget_show(item); - g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), label); - - item = gtk_menu_item_new_with_label(label); - gtk_container_add(GTK_CONTAINER(mp), item); - gtk_widget_show(item); - g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), label); -} - - -void utils_create_insert_date_menu_items(void) -{ - GtkMenu *menu_edit = GTK_MENU(lookup_widget(app->window, "insert_date1_menu")); - GtkMenu *menu_popup = GTK_MENU(lookup_widget(app->popup_menu, "insert_date2_menu")); - GtkWidget *item; - - insert_date_items(menu_edit, menu_popup, _("dd.mm.yyyy")); - insert_date_items(menu_edit, menu_popup, _("mm.dd.yyyy")); - insert_date_items(menu_edit, menu_popup, _("yyyy/mm/dd")); - - item = gtk_separator_menu_item_new(); - gtk_container_add(GTK_CONTAINER(menu_edit), item); - gtk_widget_show(item); - item = gtk_separator_menu_item_new(); - gtk_container_add(GTK_CONTAINER(menu_popup), item); - gtk_widget_show(item); - - insert_date_items(menu_edit, menu_popup, _("dd.mm.yyyy hh:mm:ss")); - insert_date_items(menu_edit, menu_popup, _("mm.dd.yyyy hh:mm:ss")); - insert_date_items(menu_edit, menu_popup, _("yyyy/mm/dd hh:mm:ss")); - - item = gtk_separator_menu_item_new(); - gtk_container_add(GTK_CONTAINER(menu_edit), item); - gtk_widget_show(item); - item = gtk_separator_menu_item_new(); - gtk_container_add(GTK_CONTAINER(menu_popup), item); - gtk_widget_show(item); - - item = gtk_menu_item_new_with_label(_("Use custom date format")); - gtk_container_add(GTK_CONTAINER(menu_edit), item); - gtk_widget_show(item); - g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), - _("Use custom date format")); - g_object_set_data_full(G_OBJECT(app->window), "insert_date_custom1", gtk_widget_ref(item), - (GDestroyNotify)gtk_widget_unref); - - item = gtk_menu_item_new_with_label(_("Use custom date format")); - gtk_container_add(GTK_CONTAINER(menu_popup), item); - gtk_widget_show(item); - g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_insert_date_activate), - _("Use custom date format")); - g_object_set_data_full(G_OBJECT(app->popup_menu), "insert_date_custom2", gtk_widget_ref(item), - (GDestroyNotify)gtk_widget_unref); - - insert_date_items(menu_edit, menu_popup, _("Set custom date format")); -} - - gchar *utils_get_initials(gchar *name) { gint i = 1, j = 1; @@ -1762,102 +970,6 @@ gchar *utils_get_initials(gchar *name) } -void utils_update_fold_items(void) -{ - gtk_widget_set_sensitive(lookup_widget(app->window, "menu_fold_all1"), app->pref_editor_folding); - gtk_widget_set_sensitive(lookup_widget(app->window, "menu_unfold_all1"), app->pref_editor_folding); -} - - -void utils_add_recent_file(const gchar *filename) -{ - if (g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp) == NULL) - { - g_queue_push_head(app->recent_queue, g_strdup(filename)); - if (g_queue_get_length(app->recent_queue) > app->mru_length) - { - g_free(g_queue_pop_tail(app->recent_queue)); - } - utils_update_recent_menu(); - } -} - - -static void utils_update_recent_menu() -{ - GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu"); - GtkWidget *recent_files_item = lookup_widget(app->window, "recent_files1"); - GtkWidget *tmp; - gchar *filename; - GList *children; - - if (g_queue_get_length(app->recent_queue) == 0) - { - gtk_widget_set_sensitive(recent_files_item, FALSE); - return; - } - else if (! GTK_WIDGET_SENSITIVE(recent_files_item)) - { - gtk_widget_set_sensitive(recent_files_item, TRUE); - } - - // clean the MRU list before adding an item - children = gtk_container_get_children(GTK_CONTAINER(recent_menu)); - if (g_list_length(children) > app->mru_length - 1) - { - GList *item = g_list_nth(children, app->mru_length - 1); - while (item != NULL) - { - if (GTK_IS_MENU_ITEM(item->data)) gtk_widget_destroy(GTK_WIDGET(item->data)); - item = g_list_next(item); - } - } - - filename = g_queue_peek_head(app->recent_queue); - tmp = gtk_menu_item_new_with_label(filename); - gtk_widget_show(tmp); - gtk_menu_shell_prepend(GTK_MENU_SHELL(recent_menu), tmp); - g_signal_connect((gpointer) tmp, "activate", - G_CALLBACK(on_recent_file_activate), (gpointer) filename); -} - - -static void utils_recreate_recent_menu() -{ - GList *item, *children; - void *data; - GtkWidget *recent_menu = lookup_widget(app->window, "recent_files1_menu"); - - children = gtk_container_get_children(GTK_CONTAINER(recent_menu)); - - // remove all menu items (but not the list elements) - for (item = children; item != NULL; item = g_list_next(item)) - { - data = item->data; - if (! GTK_IS_MENU_ITEM(data)) continue; - gtk_widget_destroy(GTK_WIDGET(data)); - } - dialogs_create_recent_menu(); -} - - -void utils_recent_file_loaded(const gchar *filename) -{ - GList *item = - g_queue_find_custom(app->recent_queue, filename, (GCompareFunc) strcmp); - gchar *data; - - g_return_if_fail(item != NULL); - // first reorder the queue - data = item->data; - g_queue_remove(app->recent_queue, data); - g_queue_push_head(app->recent_queue, data); - - // now recreate the recent files menu - utils_recreate_recent_menu(); -} - - /* Wrapper functions for Key-File-Parser from GLib in keyfile.c to reduce code size */ gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gchar *key, const gint default_value) { @@ -1978,45 +1090,10 @@ gchar *utils_get_hex_from_color(GdkColor *color) } -void utils_treeviews_showhide(gboolean force) -{ - GtkWidget *widget; - -/* geany_debug("\nSidebar: %s\nSymbol: %s\nFiles: %s", utils_btoa(app->sidebar_visible), - utils_btoa(app->sidebar_symbol_visible), utils_btoa(app->sidebar_openfiles_visible)); -*/ - - if (! force && ! app->sidebar_visible && (app->sidebar_openfiles_visible || - app->sidebar_symbol_visible)) - { - app->sidebar_visible = TRUE; - } - else if (! app->sidebar_openfiles_visible && ! app->sidebar_symbol_visible) - { - app->sidebar_visible = FALSE; - } - - widget = lookup_widget(app->window, "menu_show_sidebar1"); - if (app->sidebar_visible != gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) - { - app->ignore_callback = TRUE; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), app->sidebar_visible); - app->ignore_callback = FALSE; - } - - utils_widget_show_hide(app->treeview_notebook, app->sidebar_visible); - - utils_widget_show_hide(gtk_notebook_get_nth_page( - GTK_NOTEBOOK(app->treeview_notebook), 0), app->sidebar_symbol_visible); - utils_widget_show_hide(gtk_notebook_get_nth_page( - GTK_NOTEBOOK(app->treeview_notebook), 1), app->sidebar_openfiles_visible); -} - - /* Get directory from current file in the notebook. * Returns dir string that should be freed or NULL, depending on whether current file is valid. * (thanks to Nick Treleaven for this patch) */ -gchar *utils_get_current_file_dir(void) +gchar *utils_get_current_file_dir() { gint cur_idx = document_get_cur_idx(); @@ -2037,7 +1114,7 @@ gchar *utils_get_current_file_dir(void) /* very simple convenience function */ -void utils_beep(void) +void utils_beep() { if (app->beep_on_errors) gdk_beep(); } @@ -2199,56 +1276,6 @@ GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, GIOFunc func, gp } -void utils_update_toolbar_items(void) -{ - // show toolbar - GtkWidget *widget = lookup_widget(app->window, "menu_show_toolbar1"); - if (app->toolbar_visible && ! gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) - { - app->toolbar_visible = ! app->toolbar_visible; // will be changed by the toggled callback - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), TRUE); - } - else if (! app->toolbar_visible && gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) - { - app->toolbar_visible = ! app->toolbar_visible; // will be changed by the toggled callback - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), FALSE); - } - - // fileops - utils_widget_show_hide(lookup_widget(app->window, "menutoolbutton1"), app->pref_toolbar_show_fileops); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton9"), app->pref_toolbar_show_fileops); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton10"), app->pref_toolbar_show_fileops); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton22"), app->pref_toolbar_show_fileops); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton23"), app->pref_toolbar_show_fileops); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton15"), app->pref_toolbar_show_fileops); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem7"), app->pref_toolbar_show_fileops); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem2"), app->pref_toolbar_show_fileops); - // search - utils_widget_show_hide(lookup_widget(app->window, "entry1"), app->pref_toolbar_show_search); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton18"), app->pref_toolbar_show_search); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem5"), app->pref_toolbar_show_search); - // goto line - utils_widget_show_hide(lookup_widget(app->window, "entry_goto_line"), app->pref_toolbar_show_goto); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton25"), app->pref_toolbar_show_goto); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem8"), app->pref_toolbar_show_goto); - // compile - utils_widget_show_hide(lookup_widget(app->window, "toolbutton13"), app->pref_toolbar_show_compile); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton26"), app->pref_toolbar_show_compile); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem6"), app->pref_toolbar_show_compile); - // colour - utils_widget_show_hide(lookup_widget(app->window, "toolbutton24"), app->pref_toolbar_show_colour); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem3"), app->pref_toolbar_show_colour); - // zoom - utils_widget_show_hide(lookup_widget(app->window, "toolbutton20"), app->pref_toolbar_show_zoom); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton21"), app->pref_toolbar_show_zoom); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem4"), app->pref_toolbar_show_zoom); - // undo - utils_widget_show_hide(lookup_widget(app->window, "toolbutton_undo"), app->pref_toolbar_show_undo); - utils_widget_show_hide(lookup_widget(app->window, "toolbutton_redo"), app->pref_toolbar_show_undo); - utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem9"), app->pref_toolbar_show_undo); -} - - gchar **utils_read_file_in_array(const gchar *filename) { gchar **result = NULL; @@ -2442,46 +1469,6 @@ gboolean utils_is_unicode_charset(const gchar *string) } -void utils_document_show_hide(gint idx) -{ - gchar *widget_name; - - if (idx == -1 || ! doc_list[idx].is_valid) return; - app->ignore_callback = TRUE; - - gtk_check_menu_item_set_active( - GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_line_breaking1")), - doc_list[idx].line_breaking); - gtk_check_menu_item_set_active( - GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_use_auto_indention1")), - doc_list[idx].use_auto_indention); - gtk_check_menu_item_set_active( - GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "set_file_readonly1")), - doc_list[idx].readonly); - gtk_check_menu_item_set_active( - GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "menu_write_unicode_bom1")), - doc_list[idx].has_bom); - - switch (sci_get_eol_mode(doc_list[idx].sci)) - { - case SC_EOL_CR: widget_name = "cr"; break; - case SC_EOL_LF: widget_name = "lf"; break; - default: widget_name = "crlf"; break; - } - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, widget_name)), - TRUE); - - gtk_widget_set_sensitive(lookup_widget(app->window, "menu_write_unicode_bom1"), - utils_is_unicode_charset(doc_list[idx].encoding)); - - encodings_select_radio_item(doc_list[idx].encoding); - filetypes_select_radio_item(doc_list[idx].file_type); - - app->ignore_callback = FALSE; - -} - - /* Wraps a string in place, replacing a space with a newline character. * wrapstart is the minimum position to start wrapping or -1 for default */ gboolean utils_wrap_string(gchar *string, gint wrapstart) diff --git a/src/utils.h b/src/utils.h index 999fed6e..a44d0224 100644 --- a/src/utils.h +++ b/src/utils.h @@ -27,28 +27,6 @@ void utils_start_browser(const gchar *uri); -/* allow_override is TRUE if text can be ignored when another message has been set - * that didn't use allow_override and has not timed out. */ -void utils_set_statusbar(const gchar *text, gboolean allow_override); - -void utils_update_statusbar(gint idx, gint pos); - -void utils_set_buttons_state(gboolean enable); - -void utils_update_popup_reundo_items(gint idx); - -void utils_update_popup_copy_items(gint idx); - -void utils_update_insert_include_item(gint idx, gint item); - -void utils_update_menu_copy_items(gint idx); - -void utils_update_popup_goto_items(gboolean enable); - -void utils_save_buttons_toggle(gboolean enable); - -void utils_close_buttons_toggle(void); - /* taken from anjuta, to determine the EOL mode of the file */ gint utils_get_line_endings(gchar* buffer, glong size); @@ -56,11 +34,6 @@ gboolean utils_isbrace(gchar c); gboolean utils_is_opening_brace(gchar c); -/* This sets the window title according to the current filename. */ -void utils_set_window_title(gint index); - -void utils_set_editor_font(const gchar *font_name); - const GList *utils_get_tag_list(gint idx, guint tag_types); gint utils_get_local_tag(gint idx, const gchar *qual_name); @@ -69,26 +42,8 @@ gboolean utils_goto_file_line(const gchar *file, gboolean is_tm_filename, gint l gboolean utils_goto_line(gint idx, gint line); -GdkPixbuf *utils_new_pixbuf_from_inline(gint img, gboolean small_img); - -GtkWidget *utils_new_image_from_inline(gint img, gboolean small_img); - gint utils_write_file(const gchar *filename, const gchar *text); -void utils_show_indention_guides(void); - -void utils_show_white_space(void); - -void utils_show_linenumber_margin(void); - -void utils_show_markers_margin(void); - -void utils_show_line_endings(void); - -void utils_set_fullscreen(void); - -void utils_update_tag_list(gint idx, gboolean update); - gchar *utils_convert_to_utf8(const gchar *buffer, gsize size, gchar **used_encoding); gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const gchar *charset); @@ -122,10 +77,6 @@ gboolean utils_is_absolute_path(const gchar *path); gdouble utils_scale_round(gdouble val, gdouble factor); -void utils_widget_show_hide(GtkWidget *widget, gboolean show); - -void utils_build_show_hide(gint); - /* (taken from libexo from os-cillation) * NULL-safe string comparison. Returns TRUE if both a and b are * NULL or if a and b refer to valid strings which are equal. @@ -139,7 +90,7 @@ gchar *utils_remove_ext_from_filename(const gchar *filename); gchar utils_brace_opposite(gchar ch); -gchar *utils_get_hostname(void); +gchar *utils_get_hostname(); gint utils_make_settings_dir(const gchar *dir, const gchar *data_dir, const gchar *doc_dir); @@ -147,22 +98,12 @@ gchar *utils_str_replace(gchar *haystack, const gchar *needle, const gchar *repl gint utils_strpos(const gchar* haystack, const gchar * needle); -gchar *utils_get_date_time(void); +gchar *utils_get_date_time(); -gchar *utils_get_date(void); - -void utils_create_insert_menu_items(void); - -void utils_create_insert_date_menu_items(void); +gchar *utils_get_date(); gchar *utils_get_initials(gchar *name); -void utils_update_toolbar_icons(GtkIconSize size); - -void utils_add_recent_file(const gchar *filename); - -void utils_recent_file_loaded(const gchar *filename); - gboolean utils_get_setting_boolean(GKeyFile *config, const gchar *section, const gchar *key, const gboolean default_value); gint utils_get_setting_integer(GKeyFile *config, const gchar *section, const gchar *key, const gint default_value); @@ -177,17 +118,13 @@ gint utils_compare_symbol(const GeanySymbol *a, const GeanySymbol *b); gchar *utils_get_hex_from_color(GdkColor *color); -void utils_treeviews_showhide(gboolean force); - gchar *utils_get_current_file_dir(); -void utils_beep(void); +void utils_beep(); gchar *utils_make_human_readable_str(unsigned long long size, unsigned long block_size, unsigned long display_unit); -void utils_update_fold_items(void); - /* utils_strtod() converts a string containing a hex colour ("0x00ff00") into an integer. * Basically, it is the same as strtod() would do, but it does not understand hex colour values, * before ANSI-C99. With with_route set, it takes strings of the format "#00ff00". */ @@ -200,8 +137,6 @@ TMTag *utils_find_tm_tag(const GPtrArray *tags, const gchar *tag_name); GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, GIOFunc func, gpointer data); -void utils_update_toolbar_items(void); - gchar **utils_read_file_in_array(const gchar *filename); /* Contributed by Stefan Oltmanns, thanks. @@ -212,8 +147,6 @@ gchar *utils_scan_unicode_bom(const gchar *string); gboolean utils_is_unicode_charset(const gchar *string); -void utils_document_show_hide(gint idx); - /* Wraps a string in place, replacing a space with a newline character. * wrapstart is the minimum position to start wrapping or -1 for default */ gboolean utils_wrap_string(gchar *string, gint wrapstart); diff --git a/src/vte.c b/src/vte.c index 91a9f187..c7da911c 100644 --- a/src/vte.c +++ b/src/vte.c @@ -31,7 +31,6 @@ #include "vte.h" #include "msgwindow.h" #include "support.h" -#include "utils.h" #include "callbacks.h" #include "main.h"