[Xfce4-commits] <thunar-vcs-plugin:master> * thunar-vcs-plugin/tvp-git-action.c tvp-git-helper/main.c tvp-git-helper/tgh-common.[ch] tvp-git-helper/tgh-clean{, -dialog}.[ch]: Added clean action.

Peter de Ridder noreply at xfce.org
Sun Oct 25 23:12:01 CET 2009


Updating branch refs/heads/master
         to 308bd813b02dc820e6a5857d8c765afd13120222 (commit)
       from ef4219bf85cd30b554dab08ba8e3d6730b51304b (commit)

commit 308bd813b02dc820e6a5857d8c765afd13120222
Author: Peter de Ridder <peter at xfce.org>
Date:   Sun Oct 25 23:07:25 2009 +0100

    * thunar-vcs-plugin/tvp-git-action.c tvp-git-helper/main.c
      tvp-git-helper/tgh-common.[ch]
      tvp-git-helper/tgh-clean{,-dialog}.[ch]: Added clean action.

 README                                      |    3 +-
 thunar-vcs-plugin/tvp-git-action.c          |    1 +
 tvp-git-helper/Makefile.am                  |    4 +
 tvp-git-helper/main.c                       |   17 +++
 tvp-git-helper/tgh-clean-dialog.c           |  171 +++++++++++++++++++++++++++
 tvp-git-helper/tgh-clean-dialog.h           |   58 +++++++++
 tvp-git-helper/{tgh-add.c => tgh-clean.c}   |   77 ++++++++----
 tvp-git-helper/{tgh-clone.h => tgh-clean.h} |    8 +-
 tvp-git-helper/tgh-common.c                 |   86 +++++++++++++-
 tvp-git-helper/tgh-common.h                 |    2 +
 10 files changed, 389 insertions(+), 38 deletions(-)

diff --git a/README b/README
index 5ec7ec6..f74b1cc 100644
--- a/README
+++ b/README
@@ -9,7 +9,8 @@ The current features are:
   export, import, lock, log, move, properties, relocate, resolved, revert,
   status, switch, unlock, update.
 - Subversion info in file properties dialog.
-- Limmited git support: add, blame, branch, clone, log, reset, stash, status.
+- Limmited git support: add, blame, branch, clean, clone, log, reset, stash,
+  status.
 
 
 Usage
diff --git a/thunar-vcs-plugin/tvp-git-action.c b/thunar-vcs-plugin/tvp-git-action.c
index ce1edba..59d58a4 100644
--- a/thunar-vcs-plugin/tvp-git-action.c
+++ b/thunar-vcs-plugin/tvp-git-action.c
@@ -268,6 +268,7 @@ tvp_git_action_create_menu_item (GtkAction *action)
   if(tvp_action->property.is_parent)
     add_subaction (action, GTK_MENU_SHELL(menu), "tvp::branch", Q_("Menu|Branch"), _("Branch"), NULL, "--branch");
     add_subaction_u(GTK_MENU_SHELL(menu), "tvp::checkout", Q_("Menu|Checkout"), _("Checkout"), GTK_STOCK_CONNECT, _("Checkout"));
+  add_subaction (action, GTK_MENU_SHELL(menu), "tvp::clean", Q_("Menu|Clean"), _("Clean"), GTK_STOCK_CLEAR, "--clean");
   if(tvp_action->property.is_parent)
     add_subaction (action, GTK_MENU_SHELL(menu), "tvp::clone", Q_("Menu|Clone"), _("Clone"), GTK_STOCK_COPY, "--clone");
     add_subaction_u(GTK_MENU_SHELL(menu), "tvp::commit", Q_("Menu|Commit"), _("Commit"), GTK_STOCK_APPLY, _("Commit"));
diff --git a/tvp-git-helper/Makefile.am b/tvp-git-helper/Makefile.am
index 12a1932..1957d9c 100644
--- a/tvp-git-helper/Makefile.am
+++ b/tvp-git-helper/Makefile.am
@@ -20,6 +20,8 @@ tvp_git_helper_SOURCES =						\
 	tgh-blame.c							\
 	tgh-branch.h							\
 	tgh-branch.c							\
+	tgh-clean.h							\
+	tgh-clean.c							\
 	tgh-clone.h							\
 	tgh-clone.c							\
 	tgh-common.h							\
@@ -38,6 +40,8 @@ tvp_git_helper_SOURCES =						\
 	tgh-blame-dialog.c						\
 	tgh-branch-dialog.h						\
 	tgh-branch-dialog.c						\
+	tgh-clean-dialog.h						\
+	tgh-clean-dialog.c						\
 	tgh-file-selection-dialog.h					\
 	tgh-file-selection-dialog.c					\
 	tgh-log-dialog.h						\
diff --git a/tvp-git-helper/main.c b/tvp-git-helper/main.c
index c1e6458..0690662 100644
--- a/tvp-git-helper/main.c
+++ b/tvp-git-helper/main.c
@@ -34,6 +34,7 @@
 #include "tgh-blame.h"
 #include "tgh-branch.h"
 #include "tgh-clone.h"
+#include "tgh-clean.h"
 #include "tgh-log.h"
 #include "tgh-reset.h"
 #include "tgh-stash.h"
@@ -58,6 +59,7 @@ int main (int argc, char *argv[])
   gboolean add = FALSE;
   gboolean blame = FALSE;
   gboolean branch = FALSE;
+  gboolean clean = FALSE;
   gboolean clone = FALSE;
   gboolean log = FALSE;
   gboolean reset = FALSE;
@@ -94,6 +96,12 @@ int main (int argc, char *argv[])
     { NULL, '\0', 0, 0, NULL, NULL, NULL }
   };
 
+  GOptionEntry clean_options_table[] =
+  {
+    { "clean", '\0', 0, G_OPTION_ARG_NONE, &clean, N_("Execute clean action"), NULL },
+    { NULL, '\0', 0, 0, NULL, NULL, NULL }
+  };
+
   GOptionEntry clone_options_table[] =
   {
     { "clone", '\0', 0, G_OPTION_ARG_NONE, &clone, N_("Execute clone action"), NULL },
@@ -144,6 +152,10 @@ int main (int argc, char *argv[])
   g_option_group_add_entries(option_group, branch_options_table);
   g_option_context_add_group(option_context, option_group);
 
+  option_group = g_option_group_new("clean", N_("Clone Related Options:"), N_("Clean"), NULL, NULL);
+  g_option_group_add_entries(option_group, clean_options_table);
+  g_option_context_add_group(option_context, option_group);
+
   option_group = g_option_group_new("clone", N_("Clone Related Options:"), N_("Clone"), NULL, NULL);
   g_option_group_add_entries(option_group, clone_options_table);
   g_option_context_add_group(option_context, option_group);
@@ -191,6 +203,11 @@ int main (int argc, char *argv[])
     has_child = tgh_branch(files, &pid);
   }
 
+  if(clean)
+  {
+    has_child = tgh_clean(files, &pid);
+  }
+
   if(clone)
   {
     has_child = tgh_clone(files, &pid);
diff --git a/tvp-git-helper/tgh-clean-dialog.c b/tvp-git-helper/tgh-clean-dialog.c
new file mode 100644
index 0000000..24c2f6c
--- /dev/null
+++ b/tvp-git-helper/tgh-clean-dialog.c
@@ -0,0 +1,171 @@
+/*-
+ * Copyright (c) 2006 Peter de Ridder <peter at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <thunar-vfs/thunar-vfs.h>
+#include <gtk/gtk.h>
+
+#include "tgh-clean-dialog.h"
+
+struct _TghCleanDialog
+{
+  GtkDialog dialog;
+
+  GtkWidget *directories;
+  GtkWidget *ignore;
+  GtkWidget *force;
+};
+
+struct _TghCleanDialogClass
+{
+  GtkDialogClass dialog_class;
+};
+
+G_DEFINE_TYPE (TghCleanDialog, tgh_clean_dialog, GTK_TYPE_DIALOG)
+
+static void
+tgh_clean_dialog_class_init (TghCleanDialogClass *klass)
+{
+}
+
+static void
+tgh_clean_dialog_init (TghCleanDialog *dialog)
+{
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  GtkCellRenderer *renderer;
+
+  dialog->directories = gtk_check_button_new_with_label (_("Remove directories."));
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), dialog->directories, FALSE, TRUE, 0);
+  gtk_widget_show(dialog->directories);
+
+  model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT));
+
+  dialog->ignore = gtk_combo_box_new_with_model (model);
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), dialog->ignore, FALSE, TRUE, 0);
+  gtk_widget_show(dialog->ignore);
+
+  gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+      0, _("Excldue ignored files"),
+      1, TGH_CLEAN_IGNORE_EXCLUDE,
+      -1);
+
+  gtk_combo_box_set_active_iter (GTK_COMBO_BOX (dialog->ignore), &iter);
+
+  gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+      0, _("Include ignored files"),
+      1, TGH_CLEAN_IGNORE_INCLUDE,
+      -1);
+
+  gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+      0, _("Only ignored files"),
+      1, TGH_CLEAN_IGNORE_ONLY,
+      -1);
+
+  g_object_unref (model);
+
+  renderer = gtk_cell_renderer_text_new ();
+  gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (dialog->ignore), renderer, TRUE);
+  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (dialog->ignore), renderer, "text", 0);
+
+  dialog->force = gtk_check_button_new_with_label (_("Force clean."));
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), dialog->force, FALSE, TRUE, 0);
+  gtk_widget_show(dialog->force);
+
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Clean"));
+
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+      GTK_STOCK_OK, GTK_RESPONSE_OK,
+      NULL);
+  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1);
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+}
+
+GtkWidget*
+tgh_clean_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags flags)
+{
+  TghCleanDialog *dialog = g_object_new (TSH_TYPE_TRUST_DIALOG, NULL);
+
+  if(title)
+    gtk_window_set_title (GTK_WINDOW(dialog), title);
+
+  if(parent)
+    gtk_window_set_transient_for (GTK_WINDOW(dialog), parent);
+
+  if(flags & GTK_DIALOG_MODAL)
+    gtk_window_set_modal (GTK_WINDOW(dialog), TRUE);
+
+  if(flags & GTK_DIALOG_DESTROY_WITH_PARENT)
+    gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE);
+
+  if(flags & GTK_DIALOG_NO_SEPARATOR)
+    gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
+
+  return GTK_WIDGET(dialog);
+}
+
+gboolean
+tgh_clean_dialog_get_diretories (TghCleanDialog *dialog)
+{
+  g_return_val_if_fail (TGH_IS_CLEAN_DIALOG (dialog), FALSE);
+
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->directories));
+}
+
+TghCleanIgnore
+tgh_clean_dialog_get_ignore (TghCleanDialog *dialog)
+{
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  TghCleanIgnore ignore;
+  GValue value;
+
+  memset(&value, 0, sizeof(GValue));
+
+  g_return_val_if_fail (TGH_IS_CLEAN_DIALOG (dialog), TGH_CLEAN_IGNORE_EXCLUDE);
+
+  g_return_val_if_fail (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->ignore), &iter), TGH_CLEAN_IGNORE_EXCLUDE);
+
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->ignore));
+  gtk_tree_model_get_value (model, &iter, 1, &value);
+
+  ignore = g_value_get_int (&value);
+
+  g_value_unset(&value);
+
+  return ignore;
+}
+
+gboolean
+tgh_clean_dialog_get_force (TghCleanDialog *dialog)
+{
+  g_return_val_if_fail (TGH_IS_CLEAN_DIALOG (dialog), FALSE);
+
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->force));
+}
+
diff --git a/tvp-git-helper/tgh-clean-dialog.h b/tvp-git-helper/tgh-clean-dialog.h
new file mode 100644
index 0000000..78ddeec
--- /dev/null
+++ b/tvp-git-helper/tgh-clean-dialog.h
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2006 Peter de Ridder <peter at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __TGH_CLEAN_DIALOG_H__
+#define __TGH_CLEAN_DIALOG_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS;
+
+typedef enum
+{
+  TGH_CLEAN_IGNORE_EXCLUDE,
+  TGH_CLEAN_IGNORE_INCLUDE,
+  TGH_CLEAN_IGNORE_ONLY
+} TghCleanIgnore;
+
+typedef struct _TghCleanDialogClass TghCleanDialogClass;
+typedef struct _TghCleanDialog      TghCleanDialog;
+
+#define TSH_TYPE_TRUST_DIALOG             (tgh_clean_dialog_get_type ())
+#define TGH_CLEAN_DIALOG(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), TSH_TYPE_TRUST_DIALOG, TghCleanDialog))
+#define TGH_CLEAN_DIALOG_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), TSH_TYPE_TRUST_DIALOG, TghCleanDialogClass))
+#define TGH_IS_CLEAN_DIALOG(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TSH_TYPE_TRUST_DIALOG))
+#define TGH_IS_CLEAN_DIALOG_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), TSH_TYPE_TRUST_DIALOG))
+#define TGH_CLEAN_DIALOG_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), TSH_TYPE_TRUST_DIALOG, TghCleanDialogClass))
+
+GType      tgh_clean_dialog_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL;
+
+GtkWidget* tgh_clean_dialog_new      (const gchar *title,
+                                      GtkWindow *parent,
+                                      GtkDialogFlags flags) G_GNUC_MALLOC G_GNUC_INTERNAL;
+
+gboolean       tgh_clean_dialog_get_diretories (TghCleanDialog *dialog);
+
+TghCleanIgnore tgh_clean_dialog_get_ignore     (TghCleanDialog *dialog);
+
+gboolean       tgh_clean_dialog_get_force      (TghCleanDialog *dialog);
+
+G_END_DECLS;
+
+#endif /* !__TGH_CLEAN_DIALOG_H__ */
diff --git a/tvp-git-helper/tgh-add.c b/tvp-git-helper/tgh-clean.c
similarity index 51%
copy from tvp-git-helper/tgh-add.c
copy to tvp-git-helper/tgh-clean.c
index f55816d..ca1fa53 100644
--- a/tvp-git-helper/tgh-add.c
+++ b/tvp-git-helper/tgh-clean.c
@@ -37,12 +37,12 @@
 
 #include "tgh-common.h"
 #include "tgh-dialog-common.h"
-#include "tgh-file-selection-dialog.h"
+#include "tgh-clean-dialog.h"
 #include "tgh-notify-dialog.h"
 
-#include "tgh-add.h"
+#include "tgh-clean.h"
 
-static gboolean add_spawn (GtkWidget *dialog, gchar **files, GPid *pid)
+static gboolean clean_spawn (GtkWidget *dialog, gchar **files, gboolean direcotries, TghCleanIgnore ignore, gboolean force, GPid *pid)
 {
   GError *error = NULL;
   gint fd_out, fd_err;
@@ -52,43 +52,66 @@ static gboolean add_spawn (GtkWidget *dialog, gchar **files, GPid *pid)
   gint i;
   gchar **argv;
 
-  length = 5;
-  length += g_strv_length(files);
+  length = 4;
+  if (direcotries)
+    length++;
+  if (ignore != TGH_CLEAN_IGNORE_EXCLUDE)
+    length++;
+  if (force)
+    length++;
+  length += g_strv_length (files);
 
-  argv = g_new(gchar*, length);
+  argv = g_new (gchar*, length);
 
   argv[0] = "git";
-  argv[1] = "add";
-  argv[2] = "-v";
-  argv[3] = "--";
+  argv[1] = "clean";
   argv[length-1] = NULL;
 
-  i = 4;
-  while(*files)
+  i = 2;
+  if (direcotries)
+    argv[i++] = "-d";
+  switch (ignore)
+  {
+    case TGH_CLEAN_IGNORE_EXCLUDE:
+      break;
+    case TGH_CLEAN_IGNORE_INCLUDE:
+      argv[i++] = "-x";
+      break;
+    case TGH_CLEAN_IGNORE_ONLY:
+      argv[i++] = "-X";
+      break;
+  }
+  if (force)
+    argv[i++] = "-f";
+  argv[i++] = "--";
+
+  while (*files)
     argv[i++] = *files++;
 
-  if(!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, &fd_out, &fd_err, &error))
+  if (!g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, &fd_out, &fd_err, &error))
   {
     g_free (argv);
     return FALSE;
   }
   g_free (argv);
 
-  parser = tgh_error_parser_new(GTK_WIDGET(dialog));
+  parser = tgh_error_parser_new (GTK_WIDGET (dialog));
 
-  g_child_watch_add(*pid, (GChildWatchFunc)tgh_child_exit, parser);
+  g_child_watch_add (*pid, (GChildWatchFunc)tgh_child_exit, parser);
 
-  chan_out = g_io_channel_unix_new(fd_out);
-  chan_err = g_io_channel_unix_new(fd_err);
-  g_io_add_watch(chan_out, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, tgh_notify_parser_new(GTK_WIDGET(dialog)));
-  g_io_add_watch(chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser);
+  chan_out = g_io_channel_unix_new (fd_out);
+  chan_err = g_io_channel_unix_new (fd_err);
+  g_io_add_watch (chan_out, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, tgh_clean_parser_new (dialog));
+  g_io_add_watch (chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser);
 
   return TRUE;
 }
 
-gboolean tgh_add (gchar **files, GPid *pid)
+gboolean tgh_clean (gchar **files, GPid *pid)
 {
   GtkWidget *dialog;
+  gboolean direcotries, force;
+  TghCleanIgnore ignore;
 
   if (files)
     if (chdir(files[0]))
@@ -102,23 +125,23 @@ gboolean tgh_add (gchar **files, GPid *pid)
       g_free (dirname);
     }
 
-  dialog = tgh_file_selection_dialog_new (_("Add"), NULL, 0, TGH_FILE_SELECTION_FLAG_MODIFIED|TGH_FILE_SELECTION_FLAG_UNTRACKED);
+  dialog = tgh_clean_dialog_new (NULL, NULL, 0);
   if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
   {
     gtk_widget_destroy (dialog);
     return FALSE;
   }
-  g_strfreev (files);
-  files = tgh_file_selection_dialog_get_files (TGH_FILE_SELECTION_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
 
-  if (!files)
-    return FALSE;
+  direcotries = tgh_clean_dialog_get_diretories (TGH_CLEAN_DIALOG (dialog));
+  ignore = tgh_clean_dialog_get_ignore (TGH_CLEAN_DIALOG (dialog));
+  force = tgh_clean_dialog_get_force (TGH_CLEAN_DIALOG (dialog));
+
+  gtk_widget_destroy (dialog);
 
-  dialog = tgh_notify_dialog_new (_("Add"), NULL, 0);
+  dialog = tgh_notify_dialog_new (_("Clean"), NULL, 0);
   g_signal_connect (dialog, "cancel-clicked", tgh_cancel, NULL);
   tgh_dialog_start (GTK_DIALOG(dialog), TRUE);
 
-  return add_spawn (dialog, files, pid);
+  return clean_spawn (dialog, files, direcotries, ignore, force, pid);
 }
 
diff --git a/tvp-git-helper/tgh-clone.h b/tvp-git-helper/tgh-clean.h
similarity index 86%
copy from tvp-git-helper/tgh-clone.h
copy to tvp-git-helper/tgh-clean.h
index d8af9da..cadb048 100644
--- a/tvp-git-helper/tgh-clone.h
+++ b/tvp-git-helper/tgh-clean.h
@@ -14,14 +14,14 @@
  * Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef __TGH_CLONE_H__
-#define __TGH_CLONE_H__
+#ifndef __TGH_CLEAN_H__
+#define __TGH_CLEAN_H__
 
 G_BEGIN_DECLS
 
-gboolean tgh_clone (gchar **, GPid *);
+gboolean tgh_clean (gchar **, GPid *);
 
 G_END_DECLS
 
-#endif /*__TGH_CLONE_H__*/
+#endif /*__TGH_CLEAN_H__*/
 
diff --git a/tvp-git-helper/tgh-common.c b/tvp-git-helper/tgh-common.c
index 26150ca..8daddac 100644
--- a/tvp-git-helper/tgh-common.c
+++ b/tvp-git-helper/tgh-common.c
@@ -46,12 +46,41 @@
 #include "tgh-common.h"
 
 static void
-create_error_dialog(GtkWindow *parent, gchar *message)
+create_error_dialog (GtkWindow *parent, gchar *message)
 {
-  GtkWidget *error;
-  error = gtk_message_dialog_new(GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Status failed"));
-  gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(error), "%s", g_strstrip(message));
-  tgh_dialog_start(GTK_DIALOG(error), FALSE);
+  if (TGH_IS_NOTIFY_DIALOG (parent))
+  {
+    gchar **lines, **iter;
+    lines = g_strsplit_set (message, "\r\n", -1);
+
+    for (iter = lines; *iter; iter++)
+    {
+      gchar *action, *text;
+
+      if ((*iter)[1])
+      {
+        text = *iter;
+        action = strchr (text, ':');
+        if (action)
+        {
+          *action = '\0';
+          text = action+2;
+          action = *iter;
+        }
+
+        tgh_notify_dialog_add (TGH_NOTIFY_DIALOG (parent), action, text);
+      }
+    }
+
+    g_strfreev (lines);
+  }
+  else
+  {
+    GtkWidget *error;
+    error = gtk_message_dialog_new (parent?GTK_WINDOW (parent):NULL, parent?GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL:0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Failed"));
+    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error), "%s", g_strstrip (message));
+    tgh_dialog_start (GTK_DIALOG (error), FALSE);
+  }
 }
 
 void
@@ -70,7 +99,7 @@ void
 tgh_child_exit(GPid pid, gint status, gpointer user_data)
 {
   TghErrorParser *parser = user_data;
-  if(WEXITSTATUS(status) > 1)
+  if(WEXITSTATUS(status))
   {
     if(parser->done)
       create_error_dialog(GTK_WINDOW(parser->dialog), parser->error);
@@ -493,6 +522,51 @@ tgh_blame_parser_new (GtkWidget *dialog)
   return TGH_OUTPUT_PARSER (parser);
 }
 
+typedef struct {
+  TghOutputParser parent;
+  GtkWidget *dialog;
+} TghCleanParser;
+
+static void
+clean_parser_func(TghNotifyParser *parser, gchar *line)
+{
+  TghNotifyDialog *dialog = TGH_NOTIFY_DIALOG(parser->dialog);
+  if(line)
+  {
+    gchar *action, *file;
+
+    action = file = line;
+    if (g_ascii_strncasecmp (line, "Would ", 6) == 0)
+      file += 6;
+
+    if (g_ascii_strncasecmp (file, "Not ", 4) == 0)
+      file += 4;
+
+    file = strchr (file, ' ');
+    *file++ = '\0';
+    file[strlen (file)-1] = '\0';
+
+    tgh_notify_dialog_add(dialog, action, file);
+  }
+  else
+  {
+    tgh_notify_dialog_done(dialog);
+    g_free(parser);
+  }
+}
+
+TghOutputParser*
+tgh_clean_parser_new (GtkWidget *dialog)
+{
+  TghCleanParser *parser = g_new(TghCleanParser,1);
+
+  TGH_OUTPUT_PARSER(parser)->parse = TGH_OUTPUT_PARSER_FUNC(clean_parser_func);
+
+  parser->dialog = dialog;
+
+  return TGH_OUTPUT_PARSER(parser);
+}
+
 gboolean
 tgh_parse_output_func(GIOChannel *source, GIOCondition condition, gpointer data)
 {
diff --git a/tvp-git-helper/tgh-common.h b/tvp-git-helper/tgh-common.h
index d324aee..a8c26fb 100644
--- a/tvp-git-helper/tgh-common.h
+++ b/tvp-git-helper/tgh-common.h
@@ -49,6 +49,8 @@ TghOutputParser* tgh_stash_show_parser_new (GtkWidget *);
 
 TghOutputParser* tgh_blame_parser_new      (GtkWidget *);
 
+TghOutputParser* tgh_clean_parser_new      (GtkWidget *);
+
 gboolean tgh_parse_output_func  (GIOChannel *, GIOCondition, gpointer);
 
 G_END_DECLS



More information about the Xfce4-commits mailing list