[gitg/remote-operations: 2/3] Allow to edit remotes




commit a1b2d6f501be04d01137e2a14f82f82cfa8d4cde
Author: Adwait Rawat <adwait rawat gmail com>
Date:   Thu Jun 20 21:37:02 2019 +0900

    Allow to edit remotes
    
    Added feature that lets gitg edit remotes in the present remote list

 gitg/gitg-edit-remote-dialog.vala            |  69 +++++++++++++
 gitg/gitg-ref-action-edit-remote.vala        | 103 ++++++++++++++++++++
 gitg/history/gitg-history.vala               |   9 ++
 gitg/meson.build                             |   3 +
 gitg/resources/gitg-resources.xml.in         |   1 +
 gitg/resources/ui/gitg-edit-remote-dialog.ui | 139 +++++++++++++++++++++++++++
 6 files changed, 324 insertions(+)
---
diff --git a/gitg/gitg-edit-remote-dialog.vala b/gitg/gitg-edit-remote-dialog.vala
new file mode 100644
index 00000000..a10f47ba
--- /dev/null
+++ b/gitg/gitg-edit-remote-dialog.vala
@@ -0,0 +1,69 @@
+namespace Gitg
+{
+
+[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-edit-remote-dialog.ui")]
+class EditRemoteDialog : Gtk.Dialog
+{
+       [GtkChild]
+       private Gtk.Button d_button_save;
+
+       [GtkChild]
+       private Gtk.Entry d_entry_remote_name;
+
+       [GtkChild]
+       private Gtk.Entry d_entry_remote_url;
+
+       construct
+       {
+               d_entry_remote_name.changed.connect(() => {
+                       var is_name_valid = (d_entry_remote_name.text != "");
+
+                       d_entry_remote_url.changed.connect((e) => {
+                               var is_url_valid = (d_entry_remote_url.text != "");
+
+                               set_response_sensitive(Gtk.ResponseType.OK, is_name_valid && is_url_valid);
+                       });
+               });
+
+               set_default(d_button_save);
+               set_default_response(Gtk.ResponseType.OK);
+       }
+
+       public EditRemoteDialog(Gtk.Window? parent)
+       {
+               Object(use_header_bar : 1);
+
+               if (parent != null)
+               {
+                       set_transient_for(parent);
+               }
+       }
+
+       public string new_remote_name
+       {
+               owned get
+               {
+                       return d_entry_remote_name.text.strip();
+               }
+               set
+               {
+                       d_entry_remote_name.text = value;
+               }
+       }
+
+       public string new_remote_url
+       {
+               owned get
+               {
+                       return d_entry_remote_url.text.strip();
+               }
+               set
+               {
+                       d_entry_remote_url.text = value;
+               }
+       }
+}
+
+}
+
+// ex: ts=4 noet
diff --git a/gitg/gitg-ref-action-edit-remote.vala b/gitg/gitg-ref-action-edit-remote.vala
new file mode 100644
index 00000000..8e7f8da6
--- /dev/null
+++ b/gitg/gitg-ref-action-edit-remote.vala
@@ -0,0 +1,103 @@
+namespace Gitg
+{
+
+class RefActionEditRemote : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Object
+{
+       // Do this to pull in config.h before glib.h (for gettext...)
+       private const string version = Gitg.Config.VERSION;
+
+       public GitgExt.Application? application { owned get; construct set; }
+       public GitgExt.RefActionInterface action_interface { get; construct set; }
+       public Gitg.Ref reference { get; construct set; }
+       Gitg.Ref? d_remote_ref;
+       Gitg.Remote? d_remote;
+
+       public RefActionEditRemote(GitgExt.Application        application,
+                                                          GitgExt.RefActionInterface action_interface,
+                                                          Gitg.Ref                   reference)
+       {
+               Object(application:      application,
+                      action_interface: action_interface,
+                          reference:        reference);
+
+               var branch = reference as Ggit.Branch;
+
+               if (branch != null)
+               {
+                       try
+                       {
+                               d_remote_ref = branch.get_upstream() as Gitg.Ref;
+                       } catch {}
+               }
+               else if (reference.parsed_name.remote_name != null)
+               {
+                       d_remote_ref = reference;
+               }
+
+               if (d_remote_ref != null)
+               {
+                       d_remote = application.remote_lookup.lookup(d_remote_ref.parsed_name.remote_name);
+               }
+       }
+
+       public string id
+       {
+               owned get { return "/org/gnome/gitg/ref-actions/edit-remote"; }
+       }
+
+       public string display_name
+       {
+               owned get { return _("Edit remote"); }
+       }
+
+       public string description
+       {
+               owned get { return _("Edits the remote from the remotes list"); }
+       }
+
+       public bool available
+       {
+               get { return d_remote != null; }
+       }
+
+       public void activate()
+       {
+               var dlg = new EditRemoteDialog((Gtk.Window)application);
+
+               dlg.new_remote_name = d_remote_ref.parsed_name.remote_name;
+               var old_name = d_remote_ref.parsed_name.remote_name;
+               dlg.new_remote_url = d_remote.get_url();
+
+               dlg.response.connect((d, resp) => {
+                       if (resp == Gtk.ResponseType.OK)
+                       {
+                               d_remote = null;
+
+                               var repo = application.repository;
+
+                               try
+                               {
+                                       if (old_name != dlg.new_remote_name)
+                                               repo.rename_remote(old_name, dlg.new_remote_name);
+                                       repo.set_remote_url(dlg.new_remote_name, dlg.new_remote_url);
+                               }
+                               catch (Error e)
+                               {
+                                       application.show_infobar(_("Failed to edit remote"),
+                                                                                        e.message,
+                                                                Gtk.MessageType.ERROR);
+                               }
+
+                               ((Gtk.ApplicationWindow)application).activate_action("reload", null);
+                       }
+
+                       dlg.destroy();
+               });
+
+               dlg.show();
+    }
+}
+
+}
+
+// ex:set ts=4 noet
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 1f156b86..f2c25828 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -880,6 +880,15 @@ namespace GitgHistory
 
                        add_ref_action(actions, remove_remote);
 
+                       var edit_remote = new Gitg.RefActionEditRemote(application, af, reference);
+
+                       if (edit_remote.available)
+                       {
+                               actions.add(null);
+                       }
+
+                       add_ref_action(actions, edit_remote);
+
                        var fetch = new Gitg.RefActionFetch(application, af, reference);
 
                        if (fetch.available)
diff --git a/gitg/meson.build b/gitg/meson.build
index b9d8c0be..e4d77807 100644
--- a/gitg/meson.build
+++ b/gitg/meson.build
@@ -22,6 +22,7 @@ sources = gitg_sources + files(
   'preferences/gitg-preferences-dialog.vala',
   'preferences/gitg-preferences-history.vala',
   'preferences/gitg-preferences-interface.vala',
+  'gitg-edit-remote-dialog.vala',
   'gitg-animated-paned.vala',
   'gitg-application.vala',
   'gitg-author-details-dialog.vala',
@@ -43,6 +44,7 @@ sources = gitg_sources + files(
   'gitg-recursive-scanner.vala',
   'gitg-ref-action-copy-name.vala',
   'gitg-ref-action-delete.vala',
+  'gitg-ref-action-edit-remote.vala',
   'gitg-ref-action-fetch.vala',
   'gitg-ref-action-push.vala',
   'gitg-ref-action-remove-remote.vala',
@@ -101,6 +103,7 @@ resource_data = files(
   'resources/ui/gitg-create-branch-dialog.ui',
   'resources/ui/gitg-create-tag-dialog.ui',
   'resources/ui/gitg-dash-view.ui',
+  'resources/ui/gitg-edit-remote-dialog.ui',
   'resources/ui/gitg-history-paned.ui',
   'resources/ui/gitg-history-ref-header.ui',
   'resources/ui/gitg-history-ref-row.ui',
diff --git a/gitg/resources/gitg-resources.xml.in b/gitg/resources/gitg-resources.xml.in
index 5248b951..0bb070fc 100644
--- a/gitg/resources/gitg-resources.xml.in
+++ b/gitg/resources/gitg-resources.xml.in
@@ -21,6 +21,7 @@
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-create-branch-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-create-tag-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-dash-view.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/gitg-edit-remote-dialog.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-simple-notification.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-remote-notification.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/gitg-shortcuts.ui</file>
diff --git a/gitg/resources/ui/gitg-edit-remote-dialog.ui b/gitg/resources/ui/gitg-edit-remote-dialog.ui
new file mode 100644
index 00000000..a647e9c4
--- /dev/null
+++ b/gitg/resources/ui/gitg-edit-remote-dialog.ui
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="GitgEditRemoteDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="title" translatable="yes">Edit Remote</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="headerbar">
+      <object class="GtkHeaderBar" id="dialog-header_bar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">False</property>
+        <child>
+          <object class="GtkButton" id="button_cancel">
+            <property name="label" translatable="yes">_Cancel</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <property name="valign">center</property>
+            <style>
+              <class name="text-button"/>
+            </style>
+          </object>
+          <packing>
+            <property name="pack_type">start</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="d_button_save">
+            <property name="label" translatable="yes">_Save</property>
+            <property name="visible">True</property>
+            <property name="sensitive">False</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <style>
+              <class name="text-button"/>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">Remote _name:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">d_entry_remote_name</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="d_entry_remote_name">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hexpand">True</property>
+                <property name="activates_default">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">Remote _URL:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">d_entry_remote_url</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="d_entry_remote_url">
+                <property name="width_request">350</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hexpand">True</property>
+                <property name="activates_default">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="cancel">button_cancel</action-widget>
+      <action-widget response="ok">d_button_save</action-widget>
+    </action-widgets>
+  </template>
+</interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]