Revision: 1988 http://geany.svn.sourceforge.net/geany/?rev=1988&view=rev Author: ntrel Date: 2007-10-29 09:34:12 -0700 (Mon, 29 Oct 2007)
Log Message: ----------- Add a separate menu item for diff from the current directory. Disable file and directory diff menu items if the current document has no filename. Disable project menu item when no project is open.
Modified Paths: -------------- trunk/ChangeLog trunk/plugins/svndiff.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-29 12:57:23 UTC (rev 1987) +++ trunk/ChangeLog 2007-10-29 16:34:12 UTC (rev 1988) @@ -8,6 +8,11 @@ directory diff. Don't remove filename extension for file diffs. Fix some memory leaks. + * plugins/svndiff.c: + Add a separate menu item for diff from the current directory. + Disable file and directory diff menu items if the current document + has no filename. + Disable project menu item when no project is open.
2007-10-28 Enrico Tröger enrico.troeger@uvena.de
Modified: trunk/plugins/svndiff.c =================================================================== --- trunk/plugins/svndiff.c 2007-10-29 12:57:23 UTC (rev 1987) +++ trunk/plugins/svndiff.c 2007-10-29 16:34:12 UTC (rev 1988) @@ -122,103 +122,102 @@ }
-/* Callback if menu item for the current project or directory was activated */ +/* Make a diff from the current directory */ static void svndirectory_activated(GtkMenuItem *menuitem, gpointer gdata) { - guint idx; + gint idx; gchar *base_name = NULL; gchar *locale_filename = NULL; - const gchar *project_name = NULL; + gchar *text;
idx = documents->get_cur_idx();
- if (project != NULL && NZV(project->base_path)) + g_return_if_fail(DOC_IDX_VALID(idx) && doc_list[idx].file_name != NULL); + + if (doc_list[idx].changed) { - if (doc_list[idx].file_name != NULL) - { - documents->save_file(idx, FALSE); - } - base_name = g_strdup(project->base_path); - project_name = project->name; + documents->save_file(idx, FALSE); } - else if (doc_list[idx].file_name != NULL) - { - if (doc_list[idx].changed) - { - documents->save_file(idx, FALSE); - } - locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name); - base_name = g_path_get_dirname(locale_filename); - } - else if (doc_list[idx].file_name == NULL) - { - if ( dialogs->show_save_as() ) - { - locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name); - base_name = g_path_get_dirname(locale_filename); - } - }
- if (base_name != NULL) - { - const gchar *filename; - gchar *text; + locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name); + base_name = g_path_get_dirname(locale_filename); + + text = make_diff(base_name); + if (text) + show_output(text, base_name, NULL); + g_free(text); + + g_free(base_name); + g_free(locale_filename); +} + - if (project_name != NULL) - { - filename = project_name; - } - else - { - filename = base_name; - } - text = make_diff(base_name); - if (text) - show_output(text, filename, NULL); - g_free(text); - } - else +/* Callback if menu item for the current project was activated */ +static void svnproject_activated(GtkMenuItem *menuitem, gpointer gdata) +{ + gint idx; + gchar *locale_filename = NULL; + gchar *text; + + idx = documents->get_cur_idx(); + + g_return_if_fail(project != NULL && NZV(project->base_path)); + + if (DOC_IDX_VALID(idx) && doc_list[idx].changed && doc_list[idx].file_name != NULL) { - ui->set_statusbar(FALSE, _("Could not determine a path to work in")); + documents->save_file(idx, FALSE); } + + locale_filename = utils->get_locale_from_utf8(project->base_path); + text = make_diff(locale_filename); + if (text) + show_output(text, project->name, NULL); + g_free(text); g_free(locale_filename); - g_free(base_name); }
/* Callback if menu item for a single file was activated */ static void svnfile_activated(GtkMenuItem *menuitem, gpointer gdata) { - gint idx; + gint idx; + gchar *locale_filename, *text;
idx = documents->get_cur_idx();
- if (doc_list[idx].file_name == NULL) + g_return_if_fail(DOC_IDX_VALID(idx) && doc_list[idx].file_name != NULL); + + if (doc_list[idx].changed) { - dialogs->show_save_as(); - } - else if (doc_list[idx].changed) - { documents->save_file(idx, FALSE); }
- if (doc_list[idx].file_name != NULL) - { - gchar *locale_filename, *text; + locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name);
- locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name); + text = make_diff(locale_filename); + if (text) + show_output(text, doc_list[idx].file_name, doc_list[idx].encoding); + g_free(text); + g_free(locale_filename); +}
- text = make_diff(locale_filename); - if (text) - show_output(text, doc_list[idx].file_name, doc_list[idx].encoding); - g_free(text); - g_free(locale_filename); - } - else - { - ui->set_statusbar(FALSE, - _("File is unnamed. Can't go on with processing.")); - } + +static GtkWidget *menu_svndiff_file = NULL; +static GtkWidget *menu_svndiff_dir = NULL; +static GtkWidget *menu_svndiff_project = NULL; + +static void update_menu_items() +{ + document *doc; + gboolean have_file; + + doc = documents->get_current(); + have_file = doc && doc->file_name && g_path_is_absolute(doc->file_name); + + gtk_widget_set_sensitive(menu_svndiff_file, have_file); + gtk_widget_set_sensitive(menu_svndiff_dir, have_file); + gtk_widget_set_sensitive(menu_svndiff_project, + project != NULL && NZV(project->base_path)); }
@@ -227,36 +226,21 @@ { GtkWidget *menu_svndiff = NULL; GtkWidget *menu_svndiff_menu = NULL; - GtkWidget *menu_svndiff_dir = NULL; - GtkWidget *menu_svndiff_file = NULL; GtkTooltips *tooltips = NULL;
tooltips = gtk_tooltips_new(); - //// Add an item to the Tools menu - //svndiff_item = gtk_menu_item_new_with_mnemonic(_("_SVNdiff")); - //gtk_widget_show(svndiff_item); - //gtk_container_add(GTK_CONTAINER(geany_data->tools_menu), svndiff_item); - //g_signal_connect(G_OBJECT(svndiff_item), "activate", G_CALLBACK(svnfile_activated), NULL);
- plugin_fields->flags = PLUGIN_IS_DOCUMENT_SENSITIVE;
menu_svndiff = gtk_image_menu_item_new_with_mnemonic(_("_SVNdiff")); gtk_container_add(GTK_CONTAINER(data->tools_menu), menu_svndiff);
+ g_signal_connect((gpointer) menu_svndiff, "activate", + G_CALLBACK(update_menu_items), NULL); + menu_svndiff_menu = gtk_menu_new (); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_svndiff), menu_svndiff_menu);
- // Directory - menu_svndiff_dir = gtk_menu_item_new_with_mnemonic(_("From Current _Project")); - gtk_container_add(GTK_CONTAINER (menu_svndiff_menu), menu_svndiff_dir); - gtk_tooltips_set_tip (tooltips, menu_svndiff_dir, - _("Make a diff from the current project's base path, or if there is no " - "project open, from the directory of the current active file"), NULL); - - g_signal_connect((gpointer) menu_svndiff_dir, "activate", - G_CALLBACK(svndirectory_activated), NULL); - // Single file menu_svndiff_file = gtk_menu_item_new_with_mnemonic(_("From Current _File")); gtk_container_add(GTK_CONTAINER (menu_svndiff_menu), menu_svndiff_file); @@ -266,6 +250,24 @@ g_signal_connect((gpointer) menu_svndiff_file, "activate", G_CALLBACK(svnfile_activated), NULL);
+ // Directory + menu_svndiff_dir = gtk_menu_item_new_with_mnemonic(_("From Current _Directory")); + gtk_container_add(GTK_CONTAINER (menu_svndiff_menu), menu_svndiff_dir); + gtk_tooltips_set_tip (tooltips, menu_svndiff_dir, + _("Make a diff from the directory of the current active file"), NULL); + + g_signal_connect((gpointer) menu_svndiff_dir, "activate", + G_CALLBACK(svndirectory_activated), NULL); + + // Project + menu_svndiff_project = gtk_menu_item_new_with_mnemonic(_("From Current _Project")); + gtk_container_add(GTK_CONTAINER (menu_svndiff_menu), menu_svndiff_project); + gtk_tooltips_set_tip (tooltips, menu_svndiff_project, + _("Make a diff from the current project's base path"), NULL); + + g_signal_connect((gpointer) menu_svndiff_project, "activate", + G_CALLBACK(svnproject_activated), NULL); + gtk_widget_show_all(menu_svndiff);
plugin_fields->menu_item = menu_svndiff;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.