[gedit-plugins/wip/rpm-plugin] Add RPM ChangeLog plugin



commit 879b0755f6d98e20cc6a76204fe241e108fb9ee0
Author: Igor Gnatenko <i gnatenko brain gmail com>
Date:   Mon Jul 7 01:48:29 2014 +0400

    Add RPM ChangeLog plugin
    
    Signed-off-by: Igor Gnatenko <i gnatenko brain gmail com>

 configure.ac                                       |    4 +-
 plugins/Makefile.am                                |    1 +
 plugins/rpmchangelog/Makefile.am                   |   10 ++
 .../gedit-rpmchangelog.metainfo.xml.in             |   13 ++
 ...me.gedit.plugins.rpmchangelog.gschema.xml.in.in |   19 +++
 .../rpmchangelog/rpmchangelog.plugin.desktop.in.in |   10 ++
 plugins/rpmchangelog/rpmchangelog.py               |  164 ++++++++++++++++++++
 po/POTFILES.in                                     |    3 +
 8 files changed, 223 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c417727..8649b07 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,7 +90,7 @@ AC_ARG_ENABLE([verify-all],
 C_PLUGINS="bookmarks drawspaces wordcompletion"
 
 # Python plugins that don't need special dependencies, besides python
-PY_PLUGINS="bracketcompletion charmap codecomment colorpicker colorschemer commander dashboard joinlines 
multiedit smartspaces textsize"
+PY_PLUGINS="bracketcompletion charmap codecomment colorpicker colorschemer commander dashboard joinlines 
multiedit rpmchangelog smartspaces textsize"
 
 PLUGINS="$C_PLUGINS"
 disabled_plugins=""
@@ -244,6 +244,8 @@ plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml.in
 plugins/git/git.plugin.desktop.in
 plugins/joinlines/joinlines.plugin.desktop.in
 plugins/multiedit/multiedit.plugin.desktop.in
+plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml.in
+plugins/rpmchangelog/rpmchangelog.plugin.desktop.in
 plugins/smartspaces/smartspaces.plugin.desktop.in
 plugins/synctex/synctex.plugin.desktop.in
 plugins/terminal/org.gnome.gedit.plugins.terminal.gschema.xml.in
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 2a1da64..e5f77ca 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -25,6 +25,7 @@ include plugins/drawspaces/Makefile.am
 include plugins/git/Makefile.am
 include plugins/joinlines/Makefile.am
 include plugins/multiedit/Makefile.am
+include plugins/rpmchangelog/Makefile.am
 include plugins/smartspaces/Makefile.am
 include plugins/synctex/Makefile.am
 include plugins/terminal/Makefile.am
diff --git a/plugins/rpmchangelog/Makefile.am b/plugins/rpmchangelog/Makefile.am
new file mode 100644
index 0000000..e318382
--- /dev/null
+++ b/plugins/rpmchangelog/Makefile.am
@@ -0,0 +1,10 @@
+if ENABLE_PYTHON
+plugin_PYTHON +=       plugins/rpmchangelog/rpmchangelog.py
+plugin_in_files += plugins/rpmchangelog/rpmchangelog.plugin.desktop.in
+appstream_in_files += plugins/rpmchangelog/gedit-rpmchangelog.metainfo.xml.in
+gsettings_SCHEMAS += plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml
+else
+dist_plugin_in_files += plugins/rpmchangelog/rpmchangelog.plugin.desktop.in
+dist_appstream_in_files += plugins/rpmchangelog/gedit-rpmchangelog.metainfo.xml.in
+dist_gsettings_SCHEMAS += plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml
+endif
diff --git a/plugins/rpmchangelog/gedit-rpmchangelog.metainfo.xml.in 
b/plugins/rpmchangelog/gedit-rpmchangelog.metainfo.xml.in
new file mode 100644
index 0000000..08c9bc9
--- /dev/null
+++ b/plugins/rpmchangelog/gedit-rpmchangelog.metainfo.xml.in
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright 2014 Igor Gnatenko <ignatenko gnome org> -->
+<component type="addon">
+  <id>gedit-rpmchangelog</id>
+  <extends>gedit.desktop</extends>
+  <_name>RPM ChangeLog</_name>
+  <_summary>Add RPM ChangeLog entry</_summary>
+  <url type="homepage">https://wiki.gnome.org/Apps/Gedit/ShippedPlugins</url>
+  <url type="bugtracker">https://bugzilla.gnome.org/enter_bug.cgi?product=gedit&amp;component=Plugins</url>
+  <metadata_license>CC0-1.0</metadata_license>
+  <project_license>GPL-2.0+</project_license>
+  <updatecontact>ignatenko gnome org</updatecontact>
+</component>
diff --git a/plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml.in.in 
b/plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml.in.in
new file mode 100644
index 0000000..1f62f8c
--- /dev/null
+++ b/plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml.in.in
@@ -0,0 +1,19 @@
+<schemalist>
+  <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.plugins.rpmchangelog" 
path="/org/gnome/gedit/plugins/rpmchangelog/">
+    <key name="hotkey" type="s">
+      <default>'&lt;Alt&gt;l'</default>
+      <_summary>Hotkey</_summary>
+      <_description>Hotkey for adding new RPM ChangeLog entry.</_description>
+    </key>
+    <key name="username" type="s">
+      <default>'Firstname Lastname'</default>
+      <_summary>Username</_summary>
+      <_description>Firstname and Lastname of packager.</_description>
+    </key>
+    <key name="email" type="s">
+      <default>'me example com'</default>
+      <_summary>E-mail</_summary>
+      <_description>Email of packager.</_description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/plugins/rpmchangelog/rpmchangelog.plugin.desktop.in.in 
b/plugins/rpmchangelog/rpmchangelog.plugin.desktop.in.in
new file mode 100644
index 0000000..1e9e8ad
--- /dev/null
+++ b/plugins/rpmchangelog/rpmchangelog.plugin.desktop.in.in
@@ -0,0 +1,10 @@
+[Plugin]
+Loader=python3
+Module=rpmchangelog
+IAge=3
+_Name=RPM ChangeLog
+_Description=Add RPM ChangeLog entry
+Authors=Igor Gnatenko <ignatenko gnome org>
+Copyright=Copyright © 2014 Igor Gnatenko
+Website=http://www.gedit.org
+Version= VERSION@
diff --git a/plugins/rpmchangelog/rpmchangelog.py b/plugins/rpmchangelog/rpmchangelog.py
new file mode 100644
index 0000000..a46a87e
--- /dev/null
+++ b/plugins/rpmchangelog/rpmchangelog.py
@@ -0,0 +1,164 @@
+# -*- coding: utf-8 -*-
+#  RPM ChangeLog plugin
+#  This file is part of gedit
+#
+#  Copyright (C) 2014 Igor Gnatenko
+#
+#  This program 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.
+#
+#  This program 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 this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor,
+#  Boston, MA 02110-1301, USA.
+
+from gi.repository import GObject, Gio, Gtk, Gedit
+import gettext
+from gpdefs import *
+from datetime import datetime
+
+try:
+    gettext.bindtextdomain(GETTEXT_PACKAGE, GP_LOCALEDIR)
+    _ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s)
+except:
+    _ = lambda s: s
+
+class RPMChangeLogAppActivatable(GObject.Object, Gedit.AppActivatable):
+    app = GObject.property(type=Gedit.App)
+
+    def __init__(self):
+        GObject.Object.__init__(self)
+        self.settings = Gio.Settings.new("org.gnome.gedit.plugins.rpmchangelog")
+
+    def do_activate(self):
+        self.app.add_accelerator(self.settings.get_string("hotkey"), "win.addchangelogentry", None)
+
+    def do_deactivate(self):
+        self.app.remove_accelerator("win.addchangelogentry", None)
+
+
+class RPMChangeLogWindowActivatable(GObject.Object, Gedit.WindowActivatable):
+    window = GObject.property(type=Gedit.Window)
+
+    def __init__(self):
+        GObject.Object.__init__(self)
+
+    def do_activate(self):
+        action = Gio.SimpleAction(name="addchangelogentry")
+        action.connect('activate', lambda a, p: self.add_changelog_entry())
+        self.window.add_action(action)
+
+    def do_deactivate(self):
+        self.window.remove_action("addchangelogentry")
+
+    def do_update_state(self):
+        view = self.window.get_active_view()
+        self.window.lookup_action("addchangelogentry").set_enabled(
+                view is not None and view.get_editable())
+
+    def add_changelog_entry(self):
+        view = self.window.get_active_view()
+        if view and hasattr(view, "rpm_changelog_view_activatable"):
+            view.rpm_changelog_view_activatable.add_changelog_entry()
+
+class RPMChangeLogViewActivatable(GObject.Object, Gedit.ViewActivatable):
+    view = GObject.property(type=Gedit.View)
+
+    def __init__(self):
+        GObject.Object.__init__(self)
+        self.settings = Gio.Settings.new("org.gnome.gedit.plugins.rpmchangelog")
+
+    def do_activate(self):
+        self.view.rpm_changelog_view_activatable = self
+        self.view.connect('populate-popup', self.populate_popup)
+        self.username = self.settings.get_string("username")
+        self.email = self.settings.get_string("email")
+
+    def do_deactivate(self):
+        delattr(self.view, "rpm_changelog_view_activatable")
+
+    def populate_popup(self, view, popup):
+        if not isinstance(popup, Gtk.MenuShell):
+            return
+
+        item = Gtk.SeparatorMenuItem()
+        item.show()
+        popup.append(item)
+
+        item = Gtk.MenuItem.new_with_mnemonic(_("Add _ChangeLog Entry"))
+        item.set_sensitive(self.view.get_editable())
+        item.show()
+        item.connect('activate', lambda i: self.add_changelog_entry())
+        popup.append(item)
+
+    def _get_val(self, start):
+        stop = start.copy()
+        stop.forward_to_line_end()
+        while not start.get_char() in (' ', '\t'):
+            start.forward_char()
+        while start.get_char() in (' ', '\t'):
+            start.forward_char()
+        return start.get_text(stop)
+
+    def add_changelog_entry(self):
+        doc = self.view.get_buffer()
+        if doc is None:
+            return
+
+        doc.begin_user_action()
+
+        start_iter = doc.get_start_iter()
+        end_iter = doc.get_end_iter()
+        start_mark = doc.create_mark(None, start_iter)
+        end_mark = doc.create_mark(None, end_iter)
+
+        version = doc.get_iter_at_mark(start_mark).forward_search("Version:", 0, None)
+        if version:
+            start, stop = version
+        else:
+            return
+        version_str = self._get_val(start)
+
+        release = doc.get_iter_at_mark(start_mark).forward_search("Release:", 0, None)
+        if release:
+            start, stop = release
+        else:
+            return
+        release_str = self._get_val(start)
+        release_str = release_str.replace("%{?dist}", "")
+
+        changelog = doc.get_iter_at_mark(start_mark).forward_search("%changelog", 0, None)
+        if changelog:
+            start, stop = changelog
+        else:
+            stop = end_iter.copy()
+            stop.backward_char()
+            if stop.get_char() != '\n':
+                stop.forward_char()
+                doc.insert(stop, "\n", -1)
+            else:
+                stop.forward_char()
+            doc.insert(stop, "\n%changelog", -1)
+        d = datetime.utcnow().strftime("%a %b %d %Y")
+        str_ins = "\n* {} {} <{}> - {}-{}".format(d, self.username, self.email, version_str, release_str)
+        doc.insert(stop, str_ins, -1)
+        doc.insert(stop, "\n- ", -1)
+        cursor = stop.copy()
+        cursor.forward_to_line_end()
+        stop.forward_char()
+        if stop.get_char() != '\n':
+            stop.backward_char()
+            doc.insert(stop, "\n", -1)
+
+
+        doc.end_user_action()
+        doc.place_cursor(cursor)
+
+# ex:ts=4:et:
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c47c692..10ec227 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -40,6 +40,9 @@ plugins/multiedit/multiedit.plugin.desktop.in.in
 plugins/multiedit/gedit-multiedit.metainfo.xml.in
 plugins/multiedit/multiedit/viewactivatable.py
 plugins/multiedit/multiedit/windowactivatable.py
+plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml.in.in
+plugins/rpmchangelog/rpmchangelog.plugin.desktop.in.in
+plugins/rpmchangelog/gedit-rpmchangelog.metainfo.xml.in
 plugins/smartspaces/smartspaces.plugin.desktop.in.in
 plugins/smartspaces/gedit-smartspaces.metainfo.xml.in
 plugins/synctex/synctex.plugin.desktop.in.in


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