[geany/geany-plugins] 946537: pohelper: Add a menu under Tools
Colomban Wendling
git-noreply at xxxxx
Wed Mar 13 00:45:34 UTC 2013
Branch: refs/heads/master
Author: Colomban Wendling <ban at herbesfolles.org>
Committer: Colomban Wendling <ban at herbesfolles.org>
Date: Wed, 13 Mar 2013 00:45:34 UTC
Commit: 946537f1e6f7da961d7c6d5c2cbfc4b718450d42
https://github.com/geany/geany-plugins/commit/946537f1e6f7da961d7c6d5c2cbfc4b718450d42
Log Message:
-----------
pohelper: Add a menu under Tools
Modified Paths:
--------------
build/pohelper.m4
po/POTFILES.in
pohelper/Makefile.am
pohelper/README
pohelper/data/Makefile.am
pohelper/data/menus.ui
pohelper/src/gph-plugin.c
pohelper/wscript_build
Modified: build/pohelper.m4
1 files changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -6,6 +6,7 @@ AC_DEFUN([GP_CHECK_POHELPER],
AC_CONFIG_FILES([
pohelper/Makefile
+ pohelper/data/Makefile
pohelper/src/Makefile
])
])
Modified: po/POTFILES.in
1 files changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -212,6 +212,7 @@ markdown/src/conf.c
markdown/src/plugin.c
# PoHelper
+[type: gettext/glade]pohelper/data/menus.ui
pohelper/src/gph-plugin.c
# Pretty-printer
Modified: pohelper/Makefile.am
2 files changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -1,4 +1,4 @@
include $(top_srcdir)/build/vars.auxfiles.mk
-SUBDIRS = src
+SUBDIRS = data src
plugin = pohelper
Modified: pohelper/README
8 files changed, 5 insertions(+), 3 deletions(-)
===================================================================
@@ -42,9 +42,11 @@ this plugin is part of.
Usage
=====
-First enbale the plugin the the Plugin Manager of Geany. The, you will be able
-to configure keybindings for the various actions this plugin provides under
-the Keybindings section of the Geany preferences.
+First enbale the plugin the the Plugin Manager of Geany. Once enabled,
+the plugin adds a new menu under "Tools -> Translation Helper" giving
+access to the various actions it provides. You can of course configure
+keybindings for each actions under the Keybindings section of the Geany
+preferences.
License
Modified: pohelper/data/Makefile.am
4 files changed, 4 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,4 @@
+include $(top_srcdir)/build/vars.docs.mk
+plugin = pohelper
+
+dist_plugindata_DATA = menus.ui
Modified: pohelper/data/menus.ui
223 files changed, 223 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,223 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-back</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-forward</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-back</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-forward</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image5">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-back</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image6">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-forward</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image7">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-back</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image8">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-go-forward</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkImage" id="image9">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-paste</property>
+ <property name="icon-size">1</property>
+ </object>
+ <object class="GtkMenuItem" id="root_item">
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">_Translation Helper</property>
+ <property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="menu">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="previous_string">
+ <property name="label" translatable="yes">_Previous String</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to previous string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image1</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="next_string">
+ <property name="label" translatable="yes">_Next String</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to next string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image2</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separator1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="previous_untranslated">
+ <property name="label" translatable="yes">Pre_vious Untranslated</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to previous untranslated string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image3</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="next_untranslated">
+ <property name="label" translatable="yes">Next _Untranslated</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to next untranslated string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image4</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separator2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="previous_fuzzy">
+ <property name="label" translatable="yes">Previous Fu_zzy</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to previous fuzzily translated string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image5</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="next_fuzzy">
+ <property name="label" translatable="yes">Next _Fuzzy</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to next fuzzily translated string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image6</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separator3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="previous_untranslated_or_fuzzy">
+ <property name="label" translatable="yes">Previous Untranslated or Fuzz_y</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to previous untranslated or fuzzy string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image7</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="next_untranslated_or_fuzzy">
+ <property name="label" translatable="yes">Next Untranslated _or Fuzzy</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Go to next untranslated or fuzzy string</property>
+ <property name="use_underline">True</property>
+ <property name="image">image8</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparatorMenuItem" id="separator4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="toggle_fuzziness">
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Toggle current translation fuzziness</property>
+ <property name="label" translatable="yes">_Toggle Fuzziness</property>
+ <property name="use_underline">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="paste_message_as_translation">
+ <property name="label" translatable="yes">Paste _Message as Translation</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Paste the original untranslated string to the translation</property>
+ <property name="use_underline">True</property>
+ <property name="image">image9</property>
+ <property name="use_stock">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="reflow_translation">
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text" translatable="yes">Reflow the current translation string</property>
+ <property name="label" translatable="yes">_Reflow Translation</property>
+ <property name="use_underline">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
Modified: pohelper/src/gph-plugin.c
162 files changed, 105 insertions(+), 57 deletions(-)
===================================================================
@@ -20,7 +20,6 @@
/*
* TODO:
* * allow to configure whether to update the metadata upon save
- * * add a menu in the UI
*/
#include "config.h"
@@ -44,7 +43,7 @@
PLUGIN_SET_TRANSLATABLE_INFO (
LOCALEDIR, GETTEXT_PACKAGE,
- _("Translation helper"),
+ _("Translation Helper"),
_("Improves support for GetText translation files."),
"0.1",
"Colomban Wendling <ban at herbesfolles.org>"
@@ -67,6 +66,11 @@ enum {
};
+static struct Plugin {
+ GtkWidget *menu_item;
+} plugin;
+
+
#define doc_is_po(doc) (DOC_VALID (doc) && \
(doc)->file_type && \
(doc)->file_type->id == GEANY_FILETYPES_PO)
@@ -960,75 +964,119 @@ enum {
}
}
+static const struct Action {
+ guint id;
+ const gchar *name;
+ GeanyKeyCallback callback;
+ const gchar *label;
+ const gchar *widget;
+} G_actions[] = {
+ { GPH_KB_GOTO_PREV, "goto-prev",
+ on_kb_goto_prev,
+ N_("Go to previous string"), "previous_string" },
+ { GPH_KB_GOTO_NEXT, "goto-next",
+ on_kb_goto_next,
+ N_("Go to next string"), "next_string" },
+ { GPH_KB_GOTO_PREV_UNTRANSLATED, "goto-prev-untranslated",
+ on_kb_goto_prev_untranslated,
+ N_("Go to previous untranslated string"), "previous_untranslated" },
+ { GPH_KB_GOTO_NEXT_UNTRANSLATED, "goto-next-untranslated",
+ on_kb_goto_next_untranslated,
+ N_("Go to next untranslated string"), "next_untranslated" },
+ { GPH_KB_GOTO_PREV_FUZZY, "goto-prev-fuzzy",
+ on_kb_goto_prev_fuzzy,
+ N_("Go to previous fuzzily translated string"), "previous_fuzzy" },
+ { GPH_KB_GOTO_NEXT_FUZZY, "goto-next-fuzzy",
+ on_kb_goto_next_fuzzy,
+ N_("Go to next fuzzily translated string"), "next_fuzzy" },
+ { GPH_KB_GOTO_PREV_UNTRANSLATED_OR_FUZZY, "goto-prev-untranslated-or-fuzzy",
+ on_kb_goto_prev_untranslated_or_fuzzy,
+ N_("Go to previous untranslated or fuzzy string"),
+ "previous_untranslated_or_fuzzy" },
+ { GPH_KB_GOTO_NEXT_UNTRANSLATED_OR_FUZZY, "goto-next-untranslated-or-fuzzy",
+ on_kb_goto_next_untranslated_or_fuzzy,
+ N_("Go to next untranslated or fuzzy string"),
+ "next_untranslated_or_fuzzy" },
+ { GPH_KB_PASTE_UNTRANSLATED, "paste-untranslated",
+ on_kb_paste_untranslated,
+ N_("Paste original untranslated string to translation"),
+ "paste_message_as_translation" },
+ { GPH_KB_REFLOW, "reflow",
+ on_kb_reflow,
+ N_("Reflow the current translation string"), "reflow_translation" },
+ { GPH_KB_TOGGLE_FUZZY, "toggle-fuzziness",
+ on_kb_toggle_fuzziness,
+ N_("Toggle current translation fuzziness"), "toggle_fuzziness" }
+};
+
+static void
+on_widget_kb_activate (GtkMenuItem *widget,
+ struct Action *action)
+{
+ action->callback (action->id);
+}
+
void
plugin_init (GeanyData *data)
{
GeanyKeyGroup *group;
+ GtkBuilder *builder;
+ GError *error = NULL;
+ guint i;
+
+ builder = gtk_builder_new ();
+ gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
+ if (! gtk_builder_add_from_file (builder, PKGDATADIR"/pohelper/menus.ui",
+ &error)) {
+ g_critical (_("Failed to load UI definition, please check your "
+ "installation. The error was: %s"), error->message);
+ g_error_free (error);
+ g_object_unref (builder);
+ builder = NULL;
+ plugin.menu_item = NULL;
+ } else {
+ plugin.menu_item = GTK_WIDGET (gtk_builder_get_object (builder, "root_item"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (geany->main_widgets->tools_menu),
+ plugin.menu_item);
+ }
+ /* signal handlers */
plugin_signal_connect (geany_plugin, NULL, "document-before-save", TRUE,
G_CALLBACK (on_document_save), NULL);
/* add keybindings */
group = plugin_set_key_group (geany_plugin, "pohelper", GPH_KB_COUNT, NULL);
- keybindings_set_item (group, GPH_KB_GOTO_PREV,
- on_kb_goto_prev, 0, 0,
- "goto-prev",
- _("Go to previous string"),
- NULL);
- keybindings_set_item (group, GPH_KB_GOTO_NEXT,
- on_kb_goto_next, 0, 0,
- "goto-next",
- _("Go to next string"),
- NULL);
- keybindings_set_item (group, GPH_KB_GOTO_PREV_UNTRANSLATED,
- on_kb_goto_prev_untranslated, 0, 0,
- "goto-prev-untranslated",
- _("Go to previous untranslated string"),
- NULL);
- keybindings_set_item (group, GPH_KB_GOTO_NEXT_UNTRANSLATED,
- on_kb_goto_next_untranslated, 0, 0,
- "goto-next-untranslated",
- _("Go to next untranslated string"),
- NULL);
- keybindings_set_item (group, GPH_KB_GOTO_PREV_FUZZY,
- on_kb_goto_prev_fuzzy, 0, 0,
- "goto-prev-fuzzy",
- _("Go to previous fuzzily translated string"),
- NULL);
- keybindings_set_item (group, GPH_KB_GOTO_NEXT_FUZZY,
- on_kb_goto_next_fuzzy, 0, 0,
- "goto-next-fuzzy",
- _("Go to next fuzzily translated string"),
- NULL);
- keybindings_set_item (group, GPH_KB_GOTO_PREV_UNTRANSLATED_OR_FUZZY,
- on_kb_goto_prev_untranslated_or_fuzzy, 0, 0,
- "goto-prev-untranslated-or-fuzzy",
- _("Go to previous untranslated or fuzzy string"),
- NULL);
- keybindings_set_item (group, GPH_KB_GOTO_NEXT_UNTRANSLATED_OR_FUZZY,
- on_kb_goto_next_untranslated_or_fuzzy, 0, 0,
- "goto-next-untranslated-or-fuzzy",
- _("Go to next untranslated or fuzzy string"),
- NULL);
- keybindings_set_item (group, GPH_KB_PASTE_UNTRANSLATED,
- on_kb_paste_untranslated, 0, 0,
- "paste-untranslated",
- _("Paste original untranslated string to translation"),
- NULL);
- keybindings_set_item (group, GPH_KB_REFLOW,
- on_kb_reflow, 0, 0,
- "reflow",
- _("Reflow the translated string"),
- NULL);
- keybindings_set_item (group, GPH_KB_TOGGLE_FUZZY,
- on_kb_toggle_fuzziness, 0, 0,
- "toggle-fuzziness",
- _("Toggle fuzziness of the translated string"),
- NULL);
+ for (i = 0; i < G_N_ELEMENTS (G_actions); i++) {
+ GtkWidget *widget = NULL;
+
+ if (builder && G_actions[i].widget) {
+ GObject *obj = gtk_builder_get_object (builder, G_actions[i].widget);
+
+ if (! obj || ! GTK_IS_MENU_ITEM (obj)) {
+ g_critical (_("Cannot find widget \"%s\" in the UI definition, "
+ "please check your installation."), G_actions[i].widget);
+ } else {
+ widget = GTK_WIDGET (obj);
+ g_signal_connect (widget, "activate",
+ G_CALLBACK (on_widget_kb_activate),
+ (gpointer) &G_actions[i]);
+ }
+ }
+
+ keybindings_set_item (group, G_actions[i].id, G_actions[i].callback, 0, 0,
+ G_actions[i].name, _(G_actions[i].label), widget);
+ }
+
+ if (builder) {
+ g_object_unref (builder);
+ }
}
void
plugin_cleanup (void)
{
+ if (plugin.menu_item) {
+ gtk_widget_destroy (plugin.menu_item);
+ }
}
Modified: pohelper/wscript_build
7 files changed, 6 insertions(+), 1 deletions(-)
===================================================================
@@ -20,7 +20,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-from build.wafutils import build_plugin
+from build.wafutils import build_plugin, target_is_win32
name = 'PoHelper'
@@ -31,3 +31,8 @@ includes = ['src']
build_plugin(bld, name,
sources=sources,
includes=includes)
+
+# install UI file
+prefix = '${G_PREFIX}/' if target_is_win32(bld) else ''
+datadir = '${GEANYPLUGINS_DATADIR}/geany-plugins/%s' % (name.lower())
+bld.install_files('%s%s' % (prefix, datadir), 'data/menus.ui')
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Plugins-Commits
mailing list