[gedit-plugins/wip/rpm-plugin] Add RPM ChangeLog plugin
- From: Igor Gnatenko <ignatenko src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins/wip/rpm-plugin] Add RPM ChangeLog plugin
- Date: Sun, 6 Jul 2014 23:25:30 +0000 (UTC)
commit 1011c24d25743d20862ea5ec67c6f27669465cc3
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 | 9 ++
.../rpmchangelog/rpmchangelog.plugin.desktop.in.in | 10 ++
plugins/rpmchangelog/rpmchangelog.py | 135 ++++++++++++++++++++
po/POTFILES.in | 3 +
8 files changed, 184 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&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..53cab4a
--- /dev/null
+++ b/plugins/rpmchangelog/org.gnome.gedit.plugins.rpmchangelog.gschema.xml.in.in
@@ -0,0 +1,9 @@
+<schemalist>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.plugins.rpmchangelog"
path="/org/gnome/gedit/plugins/rpmchangelog/">
+ <key name="hotkey" type="s">
+ <default>'<Contro>l'</default>
+ <_summary>Hotkey</_summary>
+ <_description>Hotkey for adding new RPM ChangeLog entry.</_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..058d229
--- /dev/null
+++ b/plugins/rpmchangelog/rpmchangelog.py
@@ -0,0 +1,135 @@
+# -*- 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 *
+
+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"), "add_entry", None)
+
+ def do_deactivate(self):
+ self.app.remove_accelerator("add_entry", 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 JoinLinesViewActivatable(GObject.Object, Gedit.ViewActivatable):
+ view = GObject.property(type=Gedit.View)
+
+ def __init__(self):
+ GObject.Object.__init__(self)
+
+ def do_activate(self):
+ self.view.add_changelog_entry_view_activatable = self
+ self.view.connect('populate-popup', self.populate_popup)
+
+ 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 add_changelog_entry(self):
+ doc = self.view.get_buffer()
+ if doc is None:
+ return
+
+ doc.begin_user_action()
+
+ # If there is a selection use it, otherwise join the
+ # next line
+ try:
+ start, end = doc.get_selection_bounds()
+ except ValueError:
+ start = doc.get_iter_at_mark(doc.get_insert())
+ end = start.copy()
+ end.forward_line()
+
+ end_mark = doc.create_mark(None, end)
+
+ if not start.ends_line():
+ start.forward_to_line_end()
+
+ # Include trailing spaces in the chunk to be removed
+ while start.backward_char() and start.get_char() in ('\t', ' '):
+ pass
+ start.forward_char()
+
+ while doc.get_iter_at_mark(end_mark).compare(start) == 1:
+ end = start.copy()
+ while end.get_char() in ('\r', '\n', ' ', '\t'):
+ end.forward_char()
+ doc.delete(start, end)
+
+ doc.insert(start, ' ')
+ start.forward_to_line_end()
+
+ doc.delete_mark(end_mark)
+ doc.end_user_action()
+
+# 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]