Revision: 414 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=414&view=rev Author: kugel- Date: 2009-01-31 19:53:01 +0000 (Sat, 31 Jan 2009)
Log Message: ----------- Rework diff a little: a) Remove duplicated code by using the same function for dir diff and basedir diff. Use function parameter to decide which of both to use. b) if basedir diff was used, show the name of the basedir in the created xxx.vc.diff (instead of the current doc's dir). c) tiny cleanup in the function too
Modified Paths: -------------- branches/GeanyVC_menu_redesign/geanyvc.c
Modified: branches/GeanyVC_menu_redesign/geanyvc.c =================================================================== --- branches/GeanyVC_menu_redesign/geanyvc.c 2009-01-31 19:42:35 UTC (rev 413) +++ branches/GeanyVC_menu_redesign/geanyvc.c 2009-01-31 19:53:01 UTC (rev 414) @@ -635,52 +635,14 @@ } }
-/* Make a diff from the current directory */ -static void -vcdiff_dir_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) -{ - gchar *base_name = NULL; - gchar *text = NULL; - const VC_RECORD *vc; - GeanyDocument *doc;
- doc = document_get_current(); - g_return_if_fail(doc != NULL && doc->file_name != NULL);
- if (doc->changed) - { - document_save_file(doc, FALSE); - } - - base_name = g_path_get_dirname(doc->file_name); - - vc = find_vc(base_name); - g_return_if_fail(vc); - - execute_command(vc, &text, NULL, base_name, VC_COMMAND_DIFF_DIR, NULL, NULL); - if (text) - { - setptr(base_name, g_strconcat(base_name, ".vc.diff", NULL)); - show_output(text, base_name, NULL); - g_free(text); - } - else - { - ui_set_statusbar(FALSE, _("No changes were made.")); - } - - g_free(base_name); -} - - /* Callback if menu item for the base directory was activated */ static void -vcdiff_basedir_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) +vcdiff_dir_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, gint flags) { gchar *text = NULL; - gchar *name; - gchar *basedir; - gchar *base_name; + gchar *dir; const VC_RECORD *vc; GeanyDocument *doc;
@@ -695,16 +657,24 @@ vc = find_vc(doc->file_name); g_return_if_fail(vc);
- basedir = vc->get_base_dir(doc->file_name); - g_return_if_fail(basedir); + if (flags & FLAG_BASEDIR) + { + dir = vc->get_base_dir(doc->file_name); + } + else if (flags & FLAG_DIR) + { + dir = g_path_get_dirname(doc->file_name); + } + else + return; + g_return_if_fail(dir);
- execute_command(vc, &text, NULL, basedir, VC_COMMAND_DIFF_DIR, NULL, NULL); + execute_command(vc, &text, NULL, dir, VC_COMMAND_DIFF_DIR, NULL, NULL); if (text) { - base_name = g_path_get_dirname(doc->file_name); - name = g_strconcat(base_name, ".vc.diff", NULL); + gchar *name; + name = g_strconcat(dir, ".vc.diff", NULL); show_output(text, name, NULL); - g_free(base_name); g_free(text); g_free(name); } @@ -712,7 +682,7 @@ { ui_set_statusbar(FALSE, _("No changes were made.")); } - g_free(basedir); + g_free(dir); }
static void @@ -909,11 +879,11 @@ }
static void -vcrevert_dir_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, gint gdata) +vcrevert_dir_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, gint flags) { command_with_question_activated(NULL, VC_COMMAND_REVERT_DIR, _("Do you really want to revert: %s?"), - FLAG_RELOAD | gdata | FLAG_FORCE_ASK); + FLAG_RELOAD | flags | FLAG_FORCE_ASK); }
static void @@ -1550,13 +1520,13 @@ static void kbdiff_dir(G_GNUC_UNUSED guint key_id) { - vcdiff_dir_activated(NULL, NULL); + vcdiff_dir_activated(NULL, FLAG_DIR); }
static void kbdiff_basedir(G_GNUC_UNUSED guint key_id) { - vcdiff_basedir_activated(NULL, NULL); + vcdiff_dir_activated(NULL, FLAG_BASEDIR); }
static void @@ -2005,7 +1975,7 @@ _("Make a diff from the directory of the current active file"), NULL);
g_signal_connect((gpointer) menu_vc_diff_dir, "activate", - G_CALLBACK(vcdiff_dir_activated), NULL); + G_CALLBACK(vcdiff_dir_activated), (gpointer)FLAG_DIR);
/* Revert current dir */ menu_vc_revert_dir = gtk_menu_item_new_with_mnemonic(_("_Revert")); @@ -2045,7 +2015,7 @@ _("Make a diff from the top VC directory"), NULL);
g_signal_connect((gpointer) menu_vc_diff_basedir, "activate", - G_CALLBACK(vcdiff_basedir_activated), NULL); + G_CALLBACK(vcdiff_dir_activated), (gpointer)FLAG_BASEDIR);
/* Revert everything */ menu_vc_revert_basedir = gtk_menu_item_new_with_mnemonic(_("_Revert"));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org