From 5c945d6de5029f6bbccc7ee4d5df2d4353938834 Mon Sep 17 00:00:00 2001 From: James Liggett Date: Mon, 28 Apr 2008 01:08:15 -0700 Subject: [PATCH] Implement support for checking out (reverting) files. --- TODO.tasks | 10 +- plugins/git/Makefile.am | 6 +- plugins/git/anjuta-git.glade | 161 ++++++++++++++++++++++++++++++- plugins/git/anjuta-git.ui | 1 + plugins/git/git-checkout-files-command.c | 91 +++++++++++++++++ plugins/git/git-checkout-files-command.h | 63 ++++++++++++ plugins/git/git-checkout-files-dialog.c | 140 +++++++++++++++++++++++++++ plugins/git/git-checkout-files-dialog.h | 33 +++++++ plugins/git/plugin.c | 10 +- 9 files changed, 507 insertions(+), 8 deletions(-) create mode 100644 plugins/git/git-checkout-files-command.c create mode 100644 plugins/git/git-checkout-files-command.h create mode 100644 plugins/git/git-checkout-files-dialog.c create mode 100644 plugins/git/git-checkout-files-dialog.h diff --git a/TODO.tasks b/TODO.tasks index ab7d852c..481722a4 100644 --- a/TODO.tasks +++ b/TODO.tasks @@ -648,11 +648,6 @@ Fix c++/gobject class generator to allow adding members, methods, signals, prope - - Reverting uncommitted changes - - - Ignoring files @@ -740,6 +735,11 @@ Fix c++/gobject class generator to allow adding members, methods, signals, prope List branches and switch to selected one + + + + + Reverting uncommitted changes diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am index 85174096..5cb9d7eb 100644 --- a/plugins/git/Makefile.am +++ b/plugins/git/Makefile.am @@ -95,7 +95,11 @@ libanjuta_git_la_SOURCES = \ git-reset-files-command.c \ git-reset-files-command.h \ git-unstage-dialog.c \ - git-unstage-dialog.h + git-unstage-dialog.h \ + git-checkout-files-command.c \ + git-checkout-files-command.h \ + git-checkout-files-dialog.c \ + git-checkout-files-dialog.h libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS) diff --git a/plugins/git/anjuta-git.glade b/plugins/git/anjuta-git.glade index 9e276119..1cfa5e2e 100644 --- a/plugins/git/anjuta-git.glade +++ b/plugins/git/anjuta-git.glade @@ -1,6 +1,6 @@ - + @@ -1383,4 +1383,163 @@ + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + Check Out Files + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + GTK_SHADOW_NONE + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 12 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + + + 600 + 250 + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + 0 + ANJUTA_VCS_STATUS_MODIFIED | ANJUTA_VCS_STATUS_ADDED | ANJUTA_VCS_STATUS_DELETED + + + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + <b>Select Files to Check Out:</b> + True + + + label_item + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + True + Retrieving status... + + + False + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + GTK_BUTTONBOX_START + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-select-all + True + 0 + + + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-clear + True + 0 + + + 1 + + + + + False + 2 + + + + + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_BUTTONBOX_END + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-cancel + True + -6 + + + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-ok + True + -5 + + + 1 + + + + + False + GTK_PACK_END + + + + + diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui index ea61dda2..fe045db3 100644 --- a/plugins/git/anjuta-git.ui +++ b/plugins/git/anjuta-git.ui @@ -6,6 +6,7 @@ + diff --git a/plugins/git/git-checkout-files-command.c b/plugins/git/git-checkout-files-command.c new file mode 100644 index 00000000..108934f5 --- /dev/null +++ b/plugins/git/git-checkout-files-command.c @@ -0,0 +1,91 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * anjuta is free software. + * + * You may 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. + * + * anjuta 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 anjuta. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#include "git-checkout-files-command.h" + +struct _GitCheckoutFilesCommandPriv +{ + GList *paths; +}; + +G_DEFINE_TYPE (GitCheckoutFilesCommand, git_checkout_files_command, GIT_TYPE_COMMAND); + +static guint +git_checkout_files_command_run (AnjutaCommand *command) +{ + GitCheckoutFilesCommand *self; + + self = GIT_CHECKOUT_FILES_COMMAND (command); + + git_command_add_arg (GIT_COMMAND (self), "checkout"); + git_command_add_list_to_args (GIT_COMMAND (self), self->priv->paths); + + return 0; +} + +static void +git_checkout_files_command_init (GitCheckoutFilesCommand *self) +{ + self->priv = g_new0 (GitCheckoutFilesCommandPriv, 1); +} + +static void +git_checkout_files_command_finalize (GObject *object) +{ + GitCheckoutFilesCommand *self; + + self = GIT_CHECKOUT_FILES_COMMAND (object); + + git_command_free_path_list (self->priv->paths); + g_free (self->priv); + + G_OBJECT_CLASS (git_checkout_files_command_parent_class)->finalize (object); +} + +static void +git_checkout_files_command_class_init (GitCheckoutFilesCommandClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + GitCommandClass* parent_class = GIT_COMMAND_CLASS (klass); + AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass); + + object_class->finalize = git_checkout_files_command_finalize; + parent_class->output_handler = git_command_send_output_to_info; + command_class->run = git_checkout_files_command_run; +} + + +GitCheckoutFilesCommand * +git_checkout_files_command_new (const gchar *working_directory, GList *paths) +{ + GitCheckoutFilesCommand *self; + + self = g_object_new (GIT_TYPE_CHECKOUT_FILES_COMMAND, + "working-directory", working_directory, + NULL); + + self->priv->paths = git_command_copy_path_list (paths); + + return self; +} diff --git a/plugins/git/git-checkout-files-command.h b/plugins/git/git-checkout-files-command.h new file mode 100644 index 00000000..e8593591 --- /dev/null +++ b/plugins/git/git-checkout-files-command.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * anjuta is free software. + * + * You may 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. + * + * anjuta 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 anjuta. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GIT_CHECKOUT_FILES_COMMAND_H_ +#define _GIT_CHECKOUT_FILES_COMMAND_H_ + +#include +#include "git-command.h" + +G_BEGIN_DECLS + +#define GIT_TYPE_CHECKOUT_FILES_COMMAND (git_checkout_files_command_get_type ()) +#define GIT_CHECKOUT_FILES_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_CHECKOUT_FILES_COMMAND, GitCheckoutFilesCommand)) +#define GIT_CHECKOUT_FILES_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_CHECKOUT_FILES_COMMAND, GitCheckoutFilesCommandClass)) +#define GIT_IS_CHECKOUT_FILES_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_CHECKOUT_FILES_COMMAND)) +#define GIT_IS_CHECKOUT_FILES_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_CHECKOUT_FILES_COMMAND)) +#define GIT_CHECKOUT_FILES_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_CHECKOUT_FILES_COMMAND, GitCheckoutFilesCommandClass)) + +typedef struct _GitCheckoutFilesCommandClass GitCheckoutFilesCommandClass; +typedef struct _GitCheckoutFilesCommand GitCheckoutFilesCommand; +typedef struct _GitCheckoutFilesCommandPriv GitCheckoutFilesCommandPriv; + +struct _GitCheckoutFilesCommandClass +{ + GitCommandClass parent_class; +}; + +struct _GitCheckoutFilesCommand +{ + GitCommand parent_instance; + + GitCheckoutFilesCommandPriv *priv; +}; + +GType git_checkout_files_command_get_type (void) G_GNUC_CONST; +GitCheckoutFilesCommand *git_checkout_files_command_new (const gchar *working_directory, + GList *paths); + + +G_END_DECLS + +#endif /* _GIT_CHECKOUT_FILES_COMMAND_H_ */ diff --git a/plugins/git/git-checkout-files-dialog.c b/plugins/git/git-checkout-files-dialog.c new file mode 100644 index 00000000..5af47ecd --- /dev/null +++ b/plugins/git/git-checkout-files-dialog.c @@ -0,0 +1,140 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * anjuta is free software. + * + * You may 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. + * + * anjuta 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 anjuta. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#include "git-checkout-files-dialog.h" + +static void +on_checkout_files_command_finished (AnjutaCommand *command, guint return_code, + Git *plugin) +{ + AnjutaStatus *status; + + status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell, + NULL); + + anjuta_status (status, _("Git: Files checked out."), 5); + + report_errors (command, return_code); + + g_object_unref (command); +} + + +static void +on_checkout_files_dialog_response (GtkDialog *dialog, gint response_id, + GitUIData *data) +{ + GtkWidget *status_view; + GList *selected_paths; + GitCheckoutFilesCommand *checkout_files_command; + + if (response_id == GTK_RESPONSE_OK) + { + status_view = glade_xml_get_widget (data->gxml, "status_view"); + selected_paths = anjuta_vcs_status_tree_view_get_selected (ANJUTA_VCS_STATUS_TREE_VIEW (status_view)); + checkout_files_command = git_checkout_files_command_new (data->plugin->project_root_directory, + selected_paths); + + git_command_free_path_list (selected_paths); + + g_signal_connect (G_OBJECT (checkout_files_command), "command-finished", + G_CALLBACK (on_checkout_files_command_finished), + data->plugin); + + anjuta_command_start (ANJUTA_COMMAND (checkout_files_command)); + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); + git_ui_data_free (data); +} + +static void +checkout_files_dialog (Git *plugin) +{ + GladeXML *gxml; + GtkWidget *dialog; + GtkWidget *select_all_button; + GtkWidget *clear_button; + GtkWidget *status_view; + GtkWidget *status_progress_bar; + GitStatusCommand *status_command; + GitUIData *data; + + gxml = glade_xml_new (GLADE_FILE, "checkout_files_dialog", NULL); + + dialog = glade_xml_get_widget (gxml, "checkout_files_dialog"); + select_all_button = glade_xml_get_widget (gxml, "select_all_button"); + clear_button = glade_xml_get_widget (gxml, "clear_button"); + status_view = glade_xml_get_widget (gxml, "status_view"); + status_progress_bar = glade_xml_get_widget (gxml, "status_progress_bar"); + + status_command = git_status_command_new (plugin->project_root_directory, + GIT_STATUS_SECTION_NOT_UPDATED); + + g_signal_connect (G_OBJECT (select_all_button), "clicked", + G_CALLBACK (select_all_status_items), + status_view); + + g_signal_connect (G_OBJECT (clear_button), "clicked", + G_CALLBACK (clear_all_status_selections), + status_view); + + pulse_progress_bar (GTK_PROGRESS_BAR (status_progress_bar)); + + g_signal_connect (G_OBJECT (status_command), "command-finished", + G_CALLBACK (cancel_data_arrived_signal_disconnect), + status_view); + + g_signal_connect (G_OBJECT (status_command), "command-finished", + G_CALLBACK (hide_pulse_progress_bar), + status_progress_bar); + + g_signal_connect (G_OBJECT (status_command), "command-finished", + G_CALLBACK (on_command_finished), + NULL); + + g_signal_connect (G_OBJECT (status_command), "data-arrived", + G_CALLBACK (on_status_command_data_arrived), + status_view); + + g_object_weak_ref (G_OBJECT (status_view), + (GWeakNotify) disconnect_data_arrived_signals, + status_command); + + anjuta_command_start (ANJUTA_COMMAND (status_command)); + + data = git_ui_data_new (plugin, gxml); + + g_signal_connect(G_OBJECT (dialog), "response", + G_CALLBACK (on_checkout_files_dialog_response), + data); + + gtk_widget_show_all (dialog); +} + +void +on_menu_git_checkout_files (GtkAction *action, Git *plugin) +{ + checkout_files_dialog (plugin); +} diff --git a/plugins/git/git-checkout-files-dialog.h b/plugins/git/git-checkout-files-dialog.h new file mode 100644 index 00000000..c23906d1 --- /dev/null +++ b/plugins/git/git-checkout-files-dialog.h @@ -0,0 +1,33 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * anjuta is free software. + * + * You may 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. + * + * anjuta 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 anjuta. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GIT_CHECKOUT_FILES_DIALOG_H +#define _GIT_CHECKOUT_FILES_DIALOG_H + +#include "git-checkout-files-command.h" +#include "git-ui-utils.h" + +void on_menu_git_checkout_files (GtkAction *action, Git *plugin); + +#endif diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c index 370bc352..d7cf0db6 100644 --- a/plugins/git/plugin.c +++ b/plugins/git/plugin.c @@ -30,6 +30,7 @@ #include "git-create-branch-dialog.h" #include "git-delete-branch-dialog.h" #include "git-unstage-dialog.h" +#include "git-checkout-files-dialog.h" #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui" @@ -60,7 +61,14 @@ static GtkActionEntry actions_git[] = { NULL, /* Tooltip */ G_CALLBACK (on_menu_git_unstage) /* action callback */ }, - + { + "ActionGitCheckoutFiles", /* Action name */ + GTK_STOCK_UNDO, /* Stock icon, if any */ + N_("_Check out files..."), /* Display label */ + NULL, /* short-cut */ + NULL, /* Tooltip */ + G_CALLBACK (on_menu_git_checkout_files) /* action callback */ + }, { "ActionGitResolve", /* Action name */ GTK_STOCK_PREFERENCES, /* Stock icon, if any */ -- 2.11.4.GIT