[Xfce4-commits] <thunar-vcs-plugin:master> * tvp-git-helper/tgh-reset{, -dialog}.[ch]: Replaced the reset dialog by message boxes.

Peter de Ridder noreply at xfce.org
Fri Oct 23 16:00:01 CEST 2009


Updating branch refs/heads/master
         to 4ec787eadf9705d7b66af44f83aaf78df17f4383 (commit)
       from 93e8e9f94d7e43f9cb927fd0a6e25ae69c662b9e (commit)

commit 4ec787eadf9705d7b66af44f83aaf78df17f4383
Author: Peter de Ridder <peter at xfce.org>
Date:   Fri Oct 23 14:58:34 2009 +0200

    * tvp-git-helper/tgh-reset{,-dialog}.[ch]: Replaced the reset dialog by
      message boxes.

 tvp-git-helper/Makefile.am        |    2 -
 tvp-git-helper/tgh-reset-dialog.c |  186 -------------------------------------
 tvp-git-helper/tgh-reset-dialog.h |   50 ----------
 tvp-git-helper/tgh-reset.c        |   79 ++++++----------
 4 files changed, 31 insertions(+), 286 deletions(-)

diff --git a/tvp-git-helper/Makefile.am b/tvp-git-helper/Makefile.am
index 838b0ca..96717b6 100644
--- a/tvp-git-helper/Makefile.am
+++ b/tvp-git-helper/Makefile.am
@@ -36,8 +36,6 @@ tvp_git_helper_SOURCES =						\
 	tgh-file-selection-dialog.c					\
 	tgh-log-dialog.h						\
 	tgh-log-dialog.c						\
-	tgh-reset-dialog.h						\
-	tgh-reset-dialog.c						\
 	tgh-status-dialog.h						\
 	tgh-status-dialog.c						\
 	tgh-transfer-dialog.h						\
diff --git a/tvp-git-helper/tgh-reset-dialog.c b/tvp-git-helper/tgh-reset-dialog.c
deleted file mode 100644
index 73c7049..0000000
--- a/tvp-git-helper/tgh-reset-dialog.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*-
- * 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-reset-dialog.h"
-
-static void cancel_clicked (GtkButton*, gpointer);
-
-struct _TghResetDialog
-{
-  GtkDialog dialog;
-
-  GtkWidget *tree_view;
-  GtkWidget *close;
-  GtkWidget *cancel;
-};
-
-struct _TghResetDialogClass
-{
-  GtkDialogClass dialog_class;
-};
-
-G_DEFINE_TYPE (TghResetDialog, tgh_reset_dialog, GTK_TYPE_DIALOG)
-
-enum {
-  SIGNAL_CANCEL = 0,
-  SIGNAL_COUNT
-};
-
-static guint signals[SIGNAL_COUNT];
-
-static void
-tgh_reset_dialog_class_init (TghResetDialogClass *klass)
-{
-  signals[SIGNAL_CANCEL] = g_signal_new("cancel-clicked",
-    G_OBJECT_CLASS_TYPE (klass),
-    G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
-    0, NULL, NULL,
-    g_cclosure_marshal_VOID__VOID,
-    G_TYPE_NONE, 0);
-}
-
-enum {
-  COLUMN_PATH = 0,
-  COLUMN_STAT,
-  COLUMN_COUNT
-};
-
-static void
-tgh_reset_dialog_init (TghResetDialog *dialog)
-{
-  GtkWidget *button;
-  GtkWidget *tree_view;
-  GtkWidget *scroll_window;
-  GtkCellRenderer *renderer;
-  GtkTreeModel *model;
-
-  scroll_window = gtk_scrolled_window_new (NULL, NULL);
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-
-  dialog->tree_view = tree_view = gtk_tree_view_new ();
-  
-  renderer = gtk_cell_renderer_text_new ();
-  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
-                                               -1, _("Path"),
-                                               renderer, "text",
-                                               COLUMN_PATH, NULL);
-  
-  renderer = gtk_cell_renderer_text_new ();
-  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
-                                               -1, _("Status"),
-                                               renderer, "text",
-                                               COLUMN_STAT, NULL);
-
-  model = GTK_TREE_MODEL (gtk_list_store_new (COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING));
-
-  gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model);
-
-  g_object_unref (model);
-
-  gtk_container_add (GTK_CONTAINER (scroll_window), tree_view);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), scroll_window, TRUE, TRUE, 0);
-  gtk_widget_show (tree_view);
-  gtk_widget_show (scroll_window);
-
-  gtk_window_set_title (GTK_WINDOW (dialog), _("Reset"));
-
-  dialog->close = button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
-  gtk_widget_hide (button);
-
-  dialog->cancel = button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
-  gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), button, FALSE, TRUE, 0);
-  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cancel_clicked), dialog);
-  gtk_widget_show (button);
-
-  gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400);
-}
-
-GtkWidget*
-tgh_reset_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags flags)
-{
-  TghResetDialog *dialog = g_object_new (TGH_TYPE_RESET_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);
-}
-
-void       
-tgh_reset_dialog_add (TghResetDialog *dialog, const gchar *file, const gchar *state)
-{
-  GtkTreeModel *model;
-  GtkTreeIter iter;
-  GtkTreePath *path;
-
-  g_return_if_fail (TGH_IS_RESET_DIALOG (dialog));
-
-  model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tree_view));
-
-  gtk_list_store_append (GTK_LIST_STORE (model), &iter);
-  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                      COLUMN_PATH, file,
-                      COLUMN_STAT, state,
-                      -1);
-
-  path = gtk_tree_model_get_path (model, &iter);
-  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (dialog->tree_view), path, NULL, FALSE, 0, 0);
-
-  gtk_tree_path_free (path);
-}
-
-void
-tgh_reset_dialog_done (TghResetDialog *dialog)
-{
-  g_return_if_fail (TGH_IS_RESET_DIALOG (dialog));
-
-  gtk_widget_hide (dialog->cancel);
-  gtk_widget_show (dialog->close);
-}
-
-static void
-cancel_clicked (GtkButton *button, gpointer user_data)
-{
-  TghResetDialog *dialog = TGH_RESET_DIALOG (user_data);
-  
-  gtk_widget_hide (dialog->cancel);
-  gtk_widget_show (dialog->close);
-  
-  g_signal_emit (dialog, signals[SIGNAL_CANCEL], 0);
-}
-
diff --git a/tvp-git-helper/tgh-reset-dialog.h b/tvp-git-helper/tgh-reset-dialog.h
deleted file mode 100644
index b1324ce..0000000
--- a/tvp-git-helper/tgh-reset-dialog.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*-
- * 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_RESET_DIALOG_H__
-#define __TGH_RESET_DIALOG_H__
-
-#include <gtk/gtk.h>
-
-G_BEGIN_DECLS;
-
-typedef struct _TghResetDialogClass TghResetDialogClass;
-typedef struct _TghResetDialog      TghResetDialog;
-
-#define TGH_TYPE_RESET_DIALOG             (tgh_reset_dialog_get_type ())
-#define TGH_RESET_DIALOG(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), TGH_TYPE_RESET_DIALOG, TghResetDialog))
-#define TGH_RESET_DIALOG_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), TGH_TYPE_RESET_DIALOG, TghResetDialogClass))
-#define TGH_IS_RESET_DIALOG(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TGH_TYPE_RESET_DIALOG))
-#define TGH_IS_RESET_DIALOG_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), TGH_TYPE_RESET_DIALOG))
-#define TGH_RESET_DIALOG_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), TGH_TYPE_RESET_DIALOG, TghResetDialogClass))
-
-GType      tgh_reset_dialog_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL;
-
-GtkWidget* tgh_reset_dialog_new      (const gchar *title,
-                                       GtkWindow *parent,
-                                       GtkDialogFlags flags) G_GNUC_MALLOC G_GNUC_INTERNAL;
-
-void       tgh_reset_dialog_add      (TghResetDialog *dialog,
-                                       const gchar *path,
-                                       const gchar *action);
-void       tgh_reset_dialog_done     (TghResetDialog *dialog);
-
-G_END_DECLS;
-
-#endif /* !__TGH_RESET_DIALOG_H__ */
diff --git a/tvp-git-helper/tgh-reset.c b/tvp-git-helper/tgh-reset.c
index 6daa82f..7a4414d 100644
--- a/tvp-git-helper/tgh-reset.c
+++ b/tvp-git-helper/tgh-reset.c
@@ -30,78 +30,59 @@
 #include "tgh-common.h"
 #include "tgh-dialog-common.h"
 #include "tgh-file-selection-dialog.h"
-#include "tgh-reset-dialog.h"
 
 #include "tgh-reset.h"
 
-typedef struct
+struct exit_args
 {
-  TghOutputParser parent;
+  TghOutputParser *parser;
   GtkWidget *dialog;
-} ResetParser;
+};
 
-static void reset_parser_func(ResetParser *parser, gchar *line)
+static void child_exit(GPid pid, gint status, gpointer user_data)
 {
-  TghResetDialog *dialog = TGH_RESET_DIALOG(parser->dialog);
-  if(line)
-  {
-    gchar *file = line;
-    gchar *state = strchr(line, ':');
-    if(state)
-    {
-      *state++ = '\0';
-      state = g_strstrip(state);
-    }
-    else
-    {
-      state = "";
-      file = g_strstrip(file);
-    }
+  struct exit_args *args = user_data;
 
-    tgh_reset_dialog_add(dialog, file, state);
-  }
-  else
+  gtk_widget_destroy(args->dialog);
+
+  if(WEXITSTATUS(status) <= 1)
   {
-    tgh_reset_dialog_done(dialog);
-    g_free(parser);
+    GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_OTHER, GTK_BUTTONS_CLOSE, _("Reset finished"));
+    tgh_dialog_start(GTK_DIALOG(dialog), TRUE);
   }
-}
-
-static TghOutputParser* reset_parser_new(GtkWidget *dialog)
-{
-  ResetParser *parser = g_new(ResetParser, 1);
-
-  TGH_OUTPUT_PARSER(parser)->parse = TGH_OUTPUT_PARSER_FUNC(reset_parser_func);
 
-  parser->dialog = dialog;
+  tgh_child_exit(pid, status, args->parser);
 
-  return TGH_OUTPUT_PARSER(parser);
+  g_free(args);
 }
 
 static gboolean reset_spawn (GtkWidget *dialog, gchar **files, GPid *pid)
 {
   GError *error = NULL;
-  gint fd_out, fd_err;
-  GIOChannel *chan_out, *chan_err;
+  gint fd_err;
+  GIOChannel *chan_err;
   TghOutputParser *parser;
   gsize length;
   gint i;
   gchar **argv;
+  struct exit_args *args;
 
-  length = 3;
+  length = 5;
   length += g_strv_length(files);
 
   argv = g_new(gchar*, length);
 
   argv[0] = "git";
   argv[1] = "reset";
+  argv[2] = "-q";
+  argv[3] = "--";
   argv[length-1] = NULL;
 
-  i = 2;
+  i = 4;
   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, NULL, &fd_err, &error))
   {
     g_free (argv);
     return FALSE;
@@ -110,11 +91,13 @@ static gboolean reset_spawn (GtkWidget *dialog, gchar **files, GPid *pid)
 
   parser = tgh_error_parser_new(GTK_WIDGET(dialog));
 
-  g_child_watch_add(*pid, (GChildWatchFunc)tgh_child_exit, parser);
+  args = g_new(struct exit_args, 1);
+  args->parser = parser;
+  args->dialog = dialog;
+
+  g_child_watch_add(*pid, (GChildWatchFunc)child_exit, args);
 
-  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, reset_parser_new(dialog));
   g_io_add_watch(chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser);
 
   return TRUE;
@@ -137,7 +120,7 @@ gboolean tgh_reset (gchar **files, GPid *pid)
     }
 
   dialog = tgh_file_selection_dialog_new (_("Reset"), NULL, 0, TGH_FILE_SELECTION_FLAG_ADDED);
-  if(gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
   {
     gtk_widget_destroy (dialog);
     return FALSE;
@@ -146,13 +129,13 @@ gboolean tgh_reset (gchar **files, GPid *pid)
   files = tgh_file_selection_dialog_get_files (TGH_FILE_SELECTION_DIALOG (dialog));
   gtk_widget_destroy (dialog);
 
-  if(!files)
+  if (!files)
     return FALSE;
 
-  dialog = tgh_reset_dialog_new(NULL, NULL, 0);
-  g_signal_connect(dialog, "cancel-clicked", tgh_cancel, NULL);
-	tgh_dialog_start (GTK_DIALOG (dialog), TRUE);
+  dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_OTHER, GTK_BUTTONS_CANCEL, _("Reset ..."));
+  g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (tgh_cancel), NULL);
+  tgh_dialog_start (GTK_DIALOG(dialog), TRUE);
 
-  return reset_spawn(dialog, files, pid);
+  return reset_spawn (dialog, files, pid);
 }
 



More information about the Xfce4-commits mailing list