From 3f30a4cc9611f9bde5072da1d2f570487cdda34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sat, 2 Jun 2007 16:14:07 +0000 Subject: [PATCH] Applied patch from Dave Moore to add simple code navigation (thank you). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1590 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- geany.glade | 123 +++++++++++++++++++++++++++++++------- src/Makefile.am | 1 + src/callbacks.c | 27 ++++++++- src/callbacks.h | 7 +++ src/geany.h | 2 + src/interface.c | 68 +++++++++++++++++---- src/keyfile.c | 6 +- src/main.c | 5 ++ src/navqueue.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++ src/navqueue.h | 38 ++++++++++++ src/prefs.c | 6 ++ src/ui_utils.c | 4 ++ 12 files changed, 404 insertions(+), 37 deletions(-) create mode 100644 src/navqueue.c create mode 100644 src/navqueue.h diff --git a/geany.glade b/geany.glade index 8a330c03a..c06622a25 100644 --- a/geany.glade +++ b/geany.glade @@ -1448,7 +1448,7 @@ True GTK_ORIENTATION_HORIZONTAL - GTK_TOOLBAR_BOTH + GTK_TOOLBAR_ICONS True True @@ -1620,6 +1620,53 @@ + + + True + False + Navigate back a location + gtk-go-back + True + True + False + + + + False + True + + + + + + True + False + Navigate forward a location + gtk-go-forward + True + True + False + + + + False + True + + + + + + True + True + True + True + + + False + False + + + True @@ -1861,6 +1908,19 @@ + + + True + False + True + True + + + False + False + + + True @@ -4367,11 +4427,49 @@ Bottom + + + True + Display the Redo and Undo buttons in the toolbar + Show Redo and Undo buttons + True + GTK_RELIEF_NORMAL + False + False + False + True + + + 0 + False + False + + + + + + True + Display the Back and Forward buttons in the toolbar used for code navigation + Show Back and Forward buttons + True + GTK_RELIEF_NORMAL + False + False + False + True + + + 0 + False + False + + + True Display the Compile and Run buttons in the toolbar - Show Compile and Run + Show Compile and Run buttons True GTK_RELIEF_NORMAL False @@ -4409,26 +4507,7 @@ Bottom True Display the Zoom In and Zoom Out buttons in the toolbar - Show Zoom In and Zoom Out - True - GTK_RELIEF_NORMAL - False - False - False - True - - - 0 - False - False - - - - - - True - Display the Redo and Undo buttons in the toolbar - Show Redo and Undo buttons + Show Zoom In and Zoom Out buttons True GTK_RELIEF_NORMAL False diff --git a/src/Makefile.am b/src/Makefile.am index c867ef4e3..82d309451 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ SRCS = \ keyfile.c keyfile.h \ main.c main.h geany.h \ msgwindow.c msgwindow.h \ + navqueue.c navqueue.h \ notebook.c notebook.h \ prefs.c prefs.h \ project.c project.h \ diff --git a/src/callbacks.c b/src/callbacks.c index aff612636..747ca55cd 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -58,6 +58,7 @@ #include "symbols.h" #include "tools.h" #include "project.h" +#include "navqueue.h" #ifdef HAVE_VTE # include "vte.h" @@ -77,7 +78,6 @@ static gboolean ignore_toolbar_toggle = FALSE; // flag to indicate that an insert callback was triggered from the file menu, // so we need to store the current cursor position in editor_info.click_pos. -/// TODO rename me static gboolean insert_callback_from_menu = FALSE; // represents the state at switching a notebook page(in the left treeviews widget), to not emit @@ -1216,10 +1216,20 @@ on_goto_tag_activate (GtkMenuItem *menuitem, tmtag = symbols_find_in_workspace(editor_info.current_word, type); if (tmtag != NULL) { + gint old_idx = document_get_cur_idx(); // get idx before switching the file + if (utils_goto_file_line( tmtag->atts.entry.file->work_object.file_name, TRUE, tmtag->atts.entry.line)) + { + // first add old file as old position + navqueue_new_position(doc_list[old_idx].tm_file->file_name, + sci_get_line_from_position(doc_list[old_idx].sci, editor_info.click_pos) + 1); + + navqueue_new_position(tmtag->atts.entry.file->work_object.file_name, + tmtag->atts.entry.line); return; + } } // if we are here, there was no match and we are beeping ;-) utils_beep(); @@ -2226,3 +2236,18 @@ on_menu_toggle_all_additional_widgets1_activate } +void +on_forward_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + navqueue_go_forward(); +} + + +void +on_back_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + navqueue_go_back(); +} + diff --git a/src/callbacks.h b/src/callbacks.h index ce01a0c94..a351f07e8 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -608,6 +608,13 @@ void on_menu_toggle_all_additional_widgets1_activate (GtkMenuItem *menuitem, gpointer user_data); +void +on_back_activate (GtkMenuItem *menuitem, + gpointer user_data); + +void +on_forward_activate (GtkMenuItem *menuitem, + gpointer user_data); void on_file1_activate (GtkMenuItem *menuitem, diff --git a/src/geany.h b/src/geany.h index b8b8ec3dd..da2e2c1c5 100644 --- a/src/geany.h +++ b/src/geany.h @@ -110,6 +110,7 @@ typedef struct MyApp gboolean pref_toolbar_show_search; gboolean pref_toolbar_show_goto; gboolean pref_toolbar_show_undo; + gboolean pref_toolbar_show_navigation; gboolean pref_toolbar_show_compile; gboolean pref_toolbar_show_zoom; gboolean pref_toolbar_show_colour; @@ -167,6 +168,7 @@ typedef struct MyApp GtkWidget *undo_items[3]; GtkWidget *save_buttons[4]; GtkWidget *sensitive_buttons[39]; + GtkWidget *navigation_buttons[2]; GtkWidget *open_colorsel; GtkWidget *open_fontsel; GtkWidget *open_filesel; diff --git a/src/interface.c b/src/interface.c index 34893d996..5729c81c6 100644 --- a/src/interface.c +++ b/src/interface.c @@ -213,6 +213,9 @@ create_window1 (void) GtkWidget *toolbutton_undo; GtkWidget *toolbutton_redo; GtkWidget *separatortoolitem9; + GtkWidget *toolbutton_back; + GtkWidget *toolbutton_forward; + GtkWidget *separatortoolitem10; GtkWidget *tmp_image; GtkWidget *toolbutton13; GtkWidget *toolbutton26; @@ -230,6 +233,7 @@ create_window1 (void) GtkWidget *entry_goto_line; GtkWidget *toolbutton25; GtkWidget *separatortoolitem8; + GtkWidget *separatortoolitem1; GtkWidget *toolbutton19; GtkWidget *vpaned1; GtkWidget *hpaned1; @@ -983,7 +987,7 @@ create_window1 (void) toolbar1 = gtk_toolbar_new (); gtk_widget_show (toolbar1); gtk_box_pack_start (GTK_BOX (vbox1), toolbar1, FALSE, FALSE, 0); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar1), GTK_TOOLBAR_BOTH); + gtk_toolbar_set_style (GTK_TOOLBAR (toolbar1), GTK_TOOLBAR_ICONS); tmp_toolbar_icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar1)); menutoolbutton1 = (GtkWidget*) gtk_menu_tool_button_new_from_stock ("gtk-new"); @@ -1040,6 +1044,22 @@ create_window1 (void) gtk_widget_show (separatortoolitem9); gtk_container_add (GTK_CONTAINER (toolbar1), separatortoolitem9); + toolbutton_back = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-go-back"); + gtk_widget_show (toolbutton_back); + gtk_container_add (GTK_CONTAINER (toolbar1), toolbutton_back); + gtk_widget_set_sensitive (toolbutton_back, FALSE); + gtk_tool_item_set_tooltip (GTK_TOOL_ITEM (toolbutton_back), tooltips, _("Navigate back a location"), NULL); + + toolbutton_forward = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-go-forward"); + gtk_widget_show (toolbutton_forward); + gtk_container_add (GTK_CONTAINER (toolbar1), toolbutton_forward); + gtk_widget_set_sensitive (toolbutton_forward, FALSE); + gtk_tool_item_set_tooltip (GTK_TOOL_ITEM (toolbutton_forward), tooltips, _("Navigate forward a location"), NULL); + + separatortoolitem10 = (GtkWidget*) gtk_separator_tool_item_new (); + gtk_widget_show (separatortoolitem10); + gtk_container_add (GTK_CONTAINER (toolbar1), separatortoolitem10); + tmp_image = gtk_image_new_from_stock ("gtk-convert", tmp_toolbar_icon_size); gtk_widget_show (tmp_image); toolbutton13 = (GtkWidget*) gtk_tool_button_new (tmp_image, _("Compile")); @@ -1120,6 +1140,11 @@ create_window1 (void) gtk_container_add (GTK_CONTAINER (toolbar1), separatortoolitem8); gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (separatortoolitem8), FALSE); + separatortoolitem1 = (GtkWidget*) gtk_separator_tool_item_new (); + gtk_widget_show (separatortoolitem1); + gtk_container_add (GTK_CONTAINER (toolbar1), separatortoolitem1); + gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (separatortoolitem1), FALSE); + toolbutton19 = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-quit"); gtk_widget_show (toolbutton19); gtk_container_add (GTK_CONTAINER (toolbar1), toolbutton19); @@ -1519,6 +1544,12 @@ create_window1 (void) g_signal_connect ((gpointer) toolbutton_redo, "clicked", G_CALLBACK (on_redo1_activate), NULL); + g_signal_connect ((gpointer) toolbutton_back, "clicked", + G_CALLBACK (on_back_activate), + NULL); + g_signal_connect ((gpointer) toolbutton_forward, "clicked", + G_CALLBACK (on_forward_activate), + NULL); g_signal_connect ((gpointer) toolbutton13, "clicked", G_CALLBACK (on_compile_button_clicked), NULL); @@ -1748,6 +1779,9 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, toolbutton_undo, "toolbutton_undo"); GLADE_HOOKUP_OBJECT (window1, toolbutton_redo, "toolbutton_redo"); GLADE_HOOKUP_OBJECT (window1, separatortoolitem9, "separatortoolitem9"); + GLADE_HOOKUP_OBJECT (window1, toolbutton_back, "toolbutton_back"); + GLADE_HOOKUP_OBJECT (window1, toolbutton_forward, "toolbutton_forward"); + GLADE_HOOKUP_OBJECT (window1, separatortoolitem10, "separatortoolitem10"); GLADE_HOOKUP_OBJECT (window1, toolbutton13, "toolbutton13"); GLADE_HOOKUP_OBJECT (window1, toolbutton26, "toolbutton26"); GLADE_HOOKUP_OBJECT (window1, separatortoolitem6, "separatortoolitem6"); @@ -1764,6 +1798,7 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, entry_goto_line, "entry_goto_line"); GLADE_HOOKUP_OBJECT (window1, toolbutton25, "toolbutton25"); GLADE_HOOKUP_OBJECT (window1, separatortoolitem8, "separatortoolitem8"); + GLADE_HOOKUP_OBJECT (window1, separatortoolitem1, "separatortoolitem1"); GLADE_HOOKUP_OBJECT (window1, toolbutton19, "toolbutton19"); GLADE_HOOKUP_OBJECT (window1, vpaned1, "vpaned1"); GLADE_HOOKUP_OBJECT (window1, hpaned1, "hpaned1"); @@ -2436,10 +2471,11 @@ create_prefs_dialog (void) GtkWidget *alignment14; GtkWidget *vbox16; GtkWidget *check_toolbar_fileops; + GtkWidget *check_toolbar_undo; + GtkWidget *check_toolbar_navigation; GtkWidget *check_toolbar_compile; GtkWidget *check_toolbar_colour; GtkWidget *check_toolbar_zoom; - GtkWidget *check_toolbar_undo; GtkWidget *check_toolbar_search; GtkWidget *check_toolbar_goto; GtkWidget *check_toolbar_quit; @@ -3065,7 +3101,21 @@ create_prefs_dialog (void) gtk_tooltips_set_tip (tooltips, check_toolbar_fileops, _("Display the New, Open, Close, Save and Reload buttons in the toolbar"), NULL); gtk_button_set_focus_on_click (GTK_BUTTON (check_toolbar_fileops), FALSE); - check_toolbar_compile = gtk_check_button_new_with_mnemonic (_("Show Compile and Run")); + check_toolbar_undo = gtk_check_button_new_with_mnemonic (_("Show Redo and Undo buttons")); + gtk_widget_show (check_toolbar_undo); + gtk_box_pack_start (GTK_BOX (vbox16), check_toolbar_undo, FALSE, FALSE, 0); + GTK_WIDGET_UNSET_FLAGS (check_toolbar_undo, GTK_CAN_FOCUS); + gtk_tooltips_set_tip (tooltips, check_toolbar_undo, _("Display the Redo and Undo buttons in the toolbar"), NULL); + gtk_button_set_focus_on_click (GTK_BUTTON (check_toolbar_undo), FALSE); + + check_toolbar_navigation = gtk_check_button_new_with_mnemonic (_("Show Back and Forward buttons")); + gtk_widget_show (check_toolbar_navigation); + gtk_box_pack_start (GTK_BOX (vbox16), check_toolbar_navigation, FALSE, FALSE, 0); + GTK_WIDGET_UNSET_FLAGS (check_toolbar_navigation, GTK_CAN_FOCUS); + gtk_tooltips_set_tip (tooltips, check_toolbar_navigation, _("Display the Back and Forward buttons in the toolbar used for code navigation"), NULL); + gtk_button_set_focus_on_click (GTK_BUTTON (check_toolbar_navigation), FALSE); + + check_toolbar_compile = gtk_check_button_new_with_mnemonic (_("Show Compile and Run buttons")); gtk_widget_show (check_toolbar_compile); gtk_box_pack_start (GTK_BOX (vbox16), check_toolbar_compile, FALSE, FALSE, 0); GTK_WIDGET_UNSET_FLAGS (check_toolbar_compile, GTK_CAN_FOCUS); @@ -3079,20 +3129,13 @@ create_prefs_dialog (void) gtk_tooltips_set_tip (tooltips, check_toolbar_colour, _("Display the Colour Chooser button in the toolbar"), NULL); gtk_button_set_focus_on_click (GTK_BUTTON (check_toolbar_colour), FALSE); - check_toolbar_zoom = gtk_check_button_new_with_mnemonic (_("Show Zoom In and Zoom Out")); + check_toolbar_zoom = gtk_check_button_new_with_mnemonic (_("Show Zoom In and Zoom Out buttons")); gtk_widget_show (check_toolbar_zoom); gtk_box_pack_start (GTK_BOX (vbox16), check_toolbar_zoom, FALSE, FALSE, 0); GTK_WIDGET_UNSET_FLAGS (check_toolbar_zoom, GTK_CAN_FOCUS); gtk_tooltips_set_tip (tooltips, check_toolbar_zoom, _("Display the Zoom In and Zoom Out buttons in the toolbar"), NULL); gtk_button_set_focus_on_click (GTK_BUTTON (check_toolbar_zoom), FALSE); - check_toolbar_undo = gtk_check_button_new_with_mnemonic (_("Show Redo and Undo buttons")); - gtk_widget_show (check_toolbar_undo); - gtk_box_pack_start (GTK_BOX (vbox16), check_toolbar_undo, FALSE, FALSE, 0); - GTK_WIDGET_UNSET_FLAGS (check_toolbar_undo, GTK_CAN_FOCUS); - gtk_tooltips_set_tip (tooltips, check_toolbar_undo, _("Display the Redo and Undo buttons in the toolbar"), NULL); - gtk_button_set_focus_on_click (GTK_BUTTON (check_toolbar_undo), FALSE); - check_toolbar_search = gtk_check_button_new_with_mnemonic (_("Show Search field")); gtk_widget_show (check_toolbar_search); gtk_box_pack_start (GTK_BOX (vbox16), check_toolbar_search, FALSE, FALSE, 0); @@ -4057,10 +4100,11 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, alignment14, "alignment14"); GLADE_HOOKUP_OBJECT (prefs_dialog, vbox16, "vbox16"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_fileops, "check_toolbar_fileops"); + GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_undo, "check_toolbar_undo"); + GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_navigation, "check_toolbar_navigation"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_compile, "check_toolbar_compile"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_colour, "check_toolbar_colour"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_zoom, "check_toolbar_zoom"); - GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_undo, "check_toolbar_undo"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_search, "check_toolbar_search"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_goto, "check_toolbar_goto"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_toolbar_quit, "check_toolbar_quit"); diff --git a/src/keyfile.c b/src/keyfile.c index 4d6af1f95..fb670ce37 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -145,7 +145,7 @@ void configuration_save() GtkTextBuffer *buffer; GtkTextIter start, end; - g_key_file_load_from_file(config, configfile, 0, NULL); + g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); // gets the text from the scribble textview buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(lookup_widget(app->window, "textview_scribble"))); @@ -251,6 +251,7 @@ void configuration_save() g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show_goto", app->pref_toolbar_show_goto); g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show_zoom", app->pref_toolbar_show_zoom); g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show_undo", app->pref_toolbar_show_undo); + g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show_navigation", app->pref_toolbar_show_navigation); g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show_compile", app->pref_toolbar_show_compile); g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show_colour", app->pref_toolbar_show_colour); g_key_file_set_boolean(config, PACKAGE, "pref_toolbar_show_fileops", app->pref_toolbar_show_fileops); @@ -358,7 +359,7 @@ gboolean configuration_load() setptr(configfile, g_strconcat(app->datadir, G_DIR_SEPARATOR_S "geany.conf", NULL)); } - g_key_file_load_from_file(config, configfile, 0, NULL); + g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); app->toolbar_visible = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show", TRUE); { @@ -458,6 +459,7 @@ gboolean configuration_load() app->pref_toolbar_show_zoom = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_zoom", FALSE); app->pref_toolbar_show_compile = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_compile", TRUE); app->pref_toolbar_show_undo = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_undo", FALSE); + app->pref_toolbar_show_navigation = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_navigation", TRUE); app->pref_toolbar_show_colour = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_colour", TRUE); app->pref_toolbar_show_fileops = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_fileops", TRUE); app->pref_toolbar_show_quit = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_quit", TRUE); diff --git a/src/main.c b/src/main.c index bd53541ab..f439675a8 100644 --- a/src/main.c +++ b/src/main.c @@ -59,6 +59,7 @@ #include "symbols.h" #include "project.h" #include "tools.h" +#include "navqueue.h" #ifdef HAVE_SOCKET # include "socket.h" @@ -332,6 +333,8 @@ static void main_init(void) app->sensitive_buttons[36] = lookup_widget(app->window, "menu_format1"); app->sensitive_buttons[37] = lookup_widget(app->window, "menu_open_selected_file1"); app->sensitive_buttons[38] = lookup_widget(app->window, "menu_insert_special_chars1"); + app->navigation_buttons[0] = lookup_widget(app->window, "toolbutton_back"); + app->navigation_buttons[1] = lookup_widget(app->window, "toolbutton_forward"); app->redo_items[0] = lookup_widget(app->popup_menu, "redo1"); app->redo_items[1] = lookup_widget(app->window, "menu_redo2"); app->redo_items[2] = lookup_widget(app->window, "toolbutton_redo"); @@ -721,6 +724,7 @@ gint main(gint argc, gchar **argv) gtk_tree_model_foreach(GTK_TREE_MODEL(tv.store_openfiles), treeviews_find_node, GINT_TO_POINTER(idx)); build_menu_update(idx); treeviews_update_tag_list(idx, FALSE); + navqueue_init(); #ifdef G_OS_WIN32 // hide "Build" menu item, at least until it is available for Windows @@ -763,6 +767,7 @@ void main_quit() socket_finalize(); #endif + navqueue_free(); keybindings_free(); filetypes_save_commands(); filetypes_free_types(); diff --git a/src/navqueue.c b/src/navqueue.c new file mode 100644 index 000000000..6f4acc530 --- /dev/null +++ b/src/navqueue.c @@ -0,0 +1,154 @@ +/* + * navqueue.c - this file is part of Geany, a fast and lightweight IDE + * + * Copyright 2007 Dave Moore + * + * 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. + * + */ + +#include "geany.h" + +#include "navqueue.h" +#include "sciwrappers.h" +#include "document.h" +#include "utils.h" + + +// for the navigation history queue +typedef struct +{ + gchar *file; + /// TODO maybe it is better to work on positions than on lines to be more accurate when + /// switching back or forward, sci_get_position_from_line() could be used for tm_tag lines + gint line; +} filepos; + +GQueue *navigation_queue; +guint nav_queue_pos; + + +void navqueue_init() +{ + navigation_queue = g_queue_new(); + nav_queue_pos = 0; +} + + +void navqueue_free() +{ + while (! g_queue_is_empty(navigation_queue)) + { + g_free(g_queue_pop_tail(navigation_queue)); + } + g_queue_free(navigation_queue); +} + + +static void adjust_buttons() +{ + if (g_queue_get_length(navigation_queue) < 2) + { + gtk_widget_set_sensitive(app->navigation_buttons[0], FALSE); + gtk_widget_set_sensitive(app->navigation_buttons[1], FALSE); + return; + } + if (nav_queue_pos == 0) + { + gtk_widget_set_sensitive(app->navigation_buttons[0], TRUE); + gtk_widget_set_sensitive(app->navigation_buttons[1], FALSE); + return; + } + // forward should be sensitive since where not at the start + gtk_widget_set_sensitive(app->navigation_buttons[1], TRUE); + + // back should be sensitive if there's a place to go back to + (nav_queue_pos < g_queue_get_length(navigation_queue) - 1) ? + gtk_widget_set_sensitive(app->navigation_buttons[0], TRUE) : + gtk_widget_set_sensitive(app->navigation_buttons[0], FALSE); +} + + +void navqueue_new_position(gchar *file, gint line) +{ + filepos *npos; + guint i; + + npos = g_new0(filepos, 1); + npos->file = file; + npos->line = line; + + // if we've jumped to a new position from + // inside the queue rather than going forward + if (nav_queue_pos > 0) + { + for (i = 0; i < nav_queue_pos; i++) + { + g_free(g_queue_pop_head(navigation_queue)); + } + nav_queue_pos = 0; + } + /// TODO add check to not add an entry if "Go To Defintion" on a definition is used + g_queue_push_head(navigation_queue, npos); + adjust_buttons(); +} + + +void navqueue_go_back() +{ + filepos *fprev; + + // return if theres no place to go back to + if (g_queue_is_empty(navigation_queue) || + nav_queue_pos >= g_queue_get_length(navigation_queue) - 1) + return; + + // jump back + fprev = g_queue_peek_nth(navigation_queue, nav_queue_pos + 1); + if (utils_goto_file_line(fprev->file, TRUE, fprev->line)) + { + nav_queue_pos++; + } + else + { + /// TODO: add option to re open the file + g_queue_pop_nth(navigation_queue, nav_queue_pos + 1); + } + adjust_buttons(); +} + + +void navqueue_go_forward() +{ + filepos *fnext; + + if (nav_queue_pos < 1 || g_queue_get_length(navigation_queue) < 2) + return; + + // jump forward + fnext = g_queue_peek_nth(navigation_queue, nav_queue_pos - 1); + if (utils_goto_file_line(fnext->file, TRUE, fnext->line)) + { + nav_queue_pos--; + } + else + { + /// TODO: add option to re open the file + g_queue_pop_nth(navigation_queue, nav_queue_pos - 1); + } + + adjust_buttons(); +} + diff --git a/src/navqueue.h b/src/navqueue.h new file mode 100644 index 000000000..1c4e84456 --- /dev/null +++ b/src/navqueue.h @@ -0,0 +1,38 @@ +/* + * navqueue.h - this file is part of Geany, a fast and lightweight IDE + * + * Copyright 2007 Dave Moore + * + * 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. + * + */ + + +#ifndef GEANY_NAVQUEUE_H +#define GEANY_NAVQUEUE_H 1 + + +void navqueue_init(); + +void navqueue_free(); + +void navqueue_new_position(gchar *file, gint line); + +void navqueue_go_back(); + +void navqueue_go_forward(); + + +#endif diff --git a/src/prefs.c b/src/prefs.c index 5c07af957..6f3d91b1c 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -182,6 +182,9 @@ void prefs_init_dialog(void) widget = lookup_widget(app->prefs_dialog, "check_toolbar_undo"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_undo); + widget = lookup_widget(app->prefs_dialog, "check_toolbar_navigation"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_navigation); + widget = lookup_widget(app->prefs_dialog, "check_toolbar_colour"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_toolbar_show_colour); @@ -508,6 +511,9 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat widget = lookup_widget(app->prefs_dialog, "check_toolbar_undo"); app->pref_toolbar_show_undo = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = lookup_widget(app->prefs_dialog, "check_toolbar_navigation"); + app->pref_toolbar_show_navigation = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = lookup_widget(app->prefs_dialog, "check_toolbar_compile"); app->pref_toolbar_show_compile = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); diff --git a/src/ui_utils.c b/src/ui_utils.c index 73bff5ecc..3d899aa3e 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -673,6 +673,10 @@ void ui_update_toolbar_items() 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); + // navigation + ui_widget_show_hide(lookup_widget(app->window, "toolbutton_back"), app->pref_toolbar_show_navigation); + ui_widget_show_hide(lookup_widget(app->window, "toolbutton_forward"), app->pref_toolbar_show_navigation); + ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem10"), app->pref_toolbar_show_navigation); // quit ui_widget_show_hide(lookup_widget(app->window, "toolbutton19"), app->pref_toolbar_show_quit); ui_widget_show_hide(lookup_widget(app->window, "separatortoolitem8"), app->pref_toolbar_show_quit);