[gitg] Implemented basic Create Tag
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Implemented basic Create Tag
- Date: Sun, 20 Jul 2014 17:04:55 +0000 (UTC)
commit c20c308faac59f0991b493b10c15cd5782f7ad85
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Sun Jul 20 20:03:50 2014 +0300
Implemented basic Create Tag
gitg/Makefile.am | 2 +
gitg/gitg-commit-action-create-tag.vala | 131 +++++++++++++++++++++
gitg/gitg-create-tag-dialog.vala | 163 +++++++++++++++++++++++++++
gitg/history/gitg-history.vala | 5 +
gitg/resources/gitg-resources.xml | 1 +
gitg/resources/ui/gitg-create-tag-dialog.ui | 137 ++++++++++++++++++++++
gitg/resources/ui/style.css | 3 +-
po/POTFILES.in | 2 +
po/POTFILES.skip | 2 +
9 files changed, 445 insertions(+), 1 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 28ff9b9..ec6340a 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -64,6 +64,8 @@ gitg_gitg_VALASOURCES = \
gitg/gitg-ref-action-delete.vala \
gitg/gitg-commit-action-create-branch.vala \
gitg/gitg-create-branch-dialog.vala \
+ gitg/gitg-commit-action-create-tag.vala \
+ gitg/gitg-create-tag-dialog.vala \
gitg/preferences/gitg-preferences-commit.vala \
gitg/preferences/gitg-preferences-dialog.vala \
gitg/preferences/gitg-preferences-interface.vala \
diff --git a/gitg/gitg-commit-action-create-tag.vala b/gitg/gitg-commit-action-create-tag.vala
new file mode 100644
index 0000000..adad871
--- /dev/null
+++ b/gitg/gitg-commit-action-create-tag.vala
@@ -0,0 +1,131 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can 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.
+ *
+ * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+
+class CommitActionCreateTag : GitgExt.UIElement, GitgExt.Action, GitgExt.CommitAction, 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.Commit commit { get; construct set; }
+
+ public CommitActionCreateTag(GitgExt.Application application,
+ GitgExt.RefActionInterface action_interface,
+ Gitg.Commit commit)
+ {
+ Object(application: application,
+ action_interface: action_interface,
+ commit: commit);
+ }
+
+ public string id
+ {
+ owned get { return "/org/gnome/gitg/commit-actions/create-tag"; }
+ }
+
+ public string display_name
+ {
+ owned get { return _("Create Tag"); }
+ }
+
+ public string description
+ {
+ owned get { return _("Create a new tag at the selected commit"); }
+ }
+
+ public void activate()
+ {
+ var dlg = new CreateTagDialog((Gtk.Window)application);
+
+ dlg.response.connect((d, resp) => {
+ if (resp == Gtk.ResponseType.OK)
+ {
+ Ggit.OId? tagid = null;
+
+ var repo = application.repository;
+
+ var msg = Ggit.message_prettify(dlg.new_tag_message, false, '#');
+ var name = dlg.new_tag_name;
+
+ try
+ {
+ if (msg.length == 0)
+ {
+ tagid = repo.create_tag_lightweight(name,
+ commit,
+ Ggit.CreateFlags.NONE);
+ }
+ else
+ {
+ Ggit.Signature? author = null;
+
+ try
+ {
+ author =
repo.get_signature_with_environment(application.environment);
+ } catch {}
+
+ tagid = repo.create_tag(name, commit, author, msg,
Ggit.CreateFlags.NONE);
+ }
+ }
+ catch (Error e)
+ {
+ application.show_infobar(_("Failed to create tag"),
+ e.message,
+ Gtk.MessageType.ERROR);
+
+ tagid = null;
+ }
+
+ Ggit.Ref? tag = null;
+
+ if (tagid != null)
+ {
+ try
+ {
+ tag = repo.lookup_reference(@"refs/tags/$name");
+ }
+ catch (Error e)
+ {
+ application.show_infobar(_("Failed to lookup tag"),
+ e.message,
+ Gtk.MessageType.ERROR);
+ }
+ }
+
+ if (tag != null)
+ {
+ action_interface.add_ref((Gitg.Ref)tag);
+ }
+ }
+
+ dlg.destroy();
+ finished();
+ });
+
+ dlg.show();
+ }
+}
+
+}
+
+// ex:set ts=4 noet
diff --git a/gitg/gitg-create-tag-dialog.vala b/gitg/gitg-create-tag-dialog.vala
new file mode 100644
index 0000000..92c45e9
--- /dev/null
+++ b/gitg/gitg-create-tag-dialog.vala
@@ -0,0 +1,163 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can 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.
+ *
+ * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+
+[GtkTemplate (ui = "/org/gnome/gitg/ui/gitg-create-tag-dialog.ui")]
+class CreateTagDialog : Gtk.Dialog
+{
+ // Do this to pull in config.h before glib.h (for gettext...)
+ private const string version = Gitg.Config.VERSION;
+
+ [GtkChild]
+ private Gtk.Button d_button_create;
+
+ [GtkChild]
+ private Gtk.Entry d_entry_tag_name;
+
+ [GtkChild]
+ private Gtk.TextView d_text_view_message;
+
+ private Gtk.TextTag d_info_tag;
+ private bool d_is_showing_user_info;
+ private Settings d_font_settings;
+
+ construct
+ {
+ d_font_settings = new Settings("org.gnome.desktop.interface");
+
+ update_font_settings();
+
+ d_font_settings.changed["monospace-font-name"].connect((s, k) => {
+ update_font_settings();
+ });
+
+ d_entry_tag_name.changed.connect(() => {
+ d_button_create.sensitive = (new_tag_name.length != 0);
+ });
+
+ set_default(d_button_create);
+
+ var buf = d_text_view_message.buffer;
+ d_info_tag = buf.create_tag("info");
+
+ d_text_view_message.style_updated.connect(() => {
+ update_info_tag();
+ });
+
+ d_text_view_message.focus_in_event.connect(() => {
+ if (d_is_showing_user_info)
+ {
+ Gtk.TextIter start, end;
+ buf.get_bounds(out start, out end);
+
+ buf.delete(ref start, ref end);
+ }
+
+ return false;
+ });
+
+ d_text_view_message.focus_out_event.connect(() => {
+ show_user_info();
+ return false;
+ });
+
+ update_info_tag();
+ show_user_info();
+
+ set_default_response(Gtk.ResponseType.OK);
+ }
+
+ private void update_font_settings()
+ {
+ var mfont = d_font_settings.get_string("monospace-font-name");
+ var desc = Pango.FontDescription.from_string(mfont);
+
+ d_text_view_message.override_font(desc);
+ }
+
+ private void show_user_info()
+ {
+ var buf = d_text_view_message.buffer;
+
+ Gtk.TextIter start, end;
+ buf.get_bounds(out start, out end);
+
+ if (start.compare(end) == 0 && !d_text_view_message.has_focus)
+ {
+ buf.insert_with_tags(start,
+ _("Provide a message to create an annotated tag"),
+ -1,
+ d_info_tag);
+
+ d_is_showing_user_info = true;
+ }
+ else
+ {
+ d_is_showing_user_info = false;
+ }
+ }
+
+ private void update_info_tag()
+ {
+ var ctx = d_text_view_message.get_style_context();
+ d_info_tag.foreground_rgba = ctx.get_color(Gtk.StateFlags.INSENSITIVE);
+ }
+
+ public CreateTagDialog(Gtk.Window? parent)
+ {
+ Object(use_header_bar : 1);
+
+ if (parent != null)
+ {
+ set_transient_for(parent);
+ }
+ }
+
+ public string new_tag_name
+ {
+ owned get
+ {
+ return d_entry_tag_name.text.strip();
+ }
+ }
+
+ public string new_tag_message
+ {
+ owned get
+ {
+ if (d_is_showing_user_info)
+ {
+ return "";
+ }
+
+ var buf = d_text_view_message.buffer;
+
+ Gtk.TextIter start, end;
+ buf.get_bounds(out start, out end);
+
+ return buf.get_text(start, end, false);
+ }
+ }
+}
+
+}
+
+// ex: ts=4 noet
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 8b5cd94..ab9e322 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -517,6 +517,11 @@ namespace GitgHistory
af,
commit));
+ add_commit_action(actions,
+ new Gitg.CommitActionCreateTag(application,
+ af,
+ commit));
+
var exts = new Peas.ExtensionSet(Gitg.PluginsEngine.get_default(),
typeof(GitgExt.CommitAction),
"application",
diff --git a/gitg/resources/gitg-resources.xml b/gitg/resources/gitg-resources.xml
index a5bae93..f9e831d 100644
--- a/gitg/resources/gitg-resources.xml
+++ b/gitg/resources/gitg-resources.xml
@@ -16,6 +16,7 @@
<file compressed="true" preprocess="xml-stripblanks">ui/gitg-commit-paned.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/gitg-commit-dialog.ui</file>
<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">ui/style.css</file>
</gresource>
</gresources>
diff --git a/gitg/resources/ui/gitg-create-tag-dialog.ui b/gitg/resources/ui/gitg-create-tag-dialog.ui
new file mode 100644
index 0000000..493da9a
--- /dev/null
+++ b/gitg/resources/ui/gitg-create-tag-dialog.ui
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.12 -->
+ <template class="GitgCreateTagDialog" parent="GtkDialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Create Tag</property>
+ <property name="resizable">True</property>
+ <property name="modal">True</property>
+ <property name="default_width">600</property>
+ <property name="default_height">300</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_create">
+ <property name="label" translatable="yes">C_reate</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">Tag _name:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">d_entry_tag_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_tag_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="GtkScrolledWindow" id="scrolled_window_message">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="shadow_type">in</property>
+ <property name="vexpand">True</property>
+ <property name="hexpand">True</property>
+ <child>
+ <object class="GtkSourceView" id="d_text_view_message">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="left_margin">2</property>
+ <property name="right_margin">2</property>
+ <property name="auto_indent">True</property>
+ <property name="show_right_margin">True</property>
+ <property name="right_margin_position">72</property>
+ <property name="smart_home_end">after</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">2</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="-6">button_cancel</action-widget>
+ <action-widget response="-5">d_button_create</action-widget>
+ </action-widgets>
+ </template>
+</interface>
diff --git a/gitg/resources/ui/style.css b/gitg/resources/ui/style.css
index 5c51d52..b0d8e1b 100644
--- a/gitg/resources/ui/style.css
+++ b/gitg/resources/ui/style.css
@@ -42,7 +42,8 @@ GtkToolbar#toolbar_subnav {
border-bottom: 0px;
}
-GitgSidebar:insensitive {
+GitgSidebar:insensitive,
+GitgCreateTagDialog GtkTextView:insensitive {
color: @insensitive_fg_color;
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9736c07..51b458c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ gitg/gitg-dash-view.vala
gitg/gitg-ref-action-delete.vala
gitg/gitg-ref-action-rename.vala
gitg/gitg-commit-action-create-branch.vala
+gitg/gitg-commit-action-create-tag.vala
gitg/gitg.vala
gitg/gitg-window.vala
gitg/history/gitg-history-refs-list.vala
@@ -30,6 +31,7 @@ plugins/files/gitg-files.vala
[type: gettext/glade]gitg/resources/ui/gitg-commit-dialog.ui
[type: gettext/glade]gitg/resources/ui/gitg-commit-paned.ui
[type: gettext/glade]gitg/resources/ui/gitg-create-branch-dialog.ui
+[type: gettext/glade]gitg/resources/ui/gitg-create-tag-dialog.ui
[type: gettext/glade]gitg/resources/ui/gitg-history-paned.ui
[type: gettext/glade]gitg/resources/ui/gitg-menus.ui
[type: gettext/glade]gitg/resources/ui/gitg-preferences-commit.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index c0da5e9..730df40 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -10,6 +10,8 @@ gitg/gitg-dash-view.c
gitg/gitg-ref-action-delete.c
gitg/gitg-ref-action-rename.c
gitg/gitg-commit-action-create-branch.c
+gitg/gitg-commit-action-create-tag.c
+gitg/gitg-create-tag-dialog.c
gitg/gitg-window.c
gitg/history/gitg-history.c
gitg/history/gitg-history-refs-list.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]