Skip to content
Browse files

pohelper: Add a menu under Tools

  • Loading branch information...
1 parent 55dd6b5 commit 946537f1e6f7da961d7c6d5c2cbfc4b718450d42 @b4n b4n committed Mar 12, 2013
Showing with 346 additions and 62 deletions.
  1. +1 −0 build/pohelper.m4
  2. +1 −0 po/POTFILES.in
  3. +1 −1 pohelper/Makefile.am
  4. +5 −3 pohelper/README
  5. +4 −0 pohelper/data/Makefile.am
  6. +223 −0 pohelper/data/menus.ui
  7. +105 −57 pohelper/src/gph-plugin.c
  8. +6 −1 pohelper/wscript_build
View
1 build/pohelper.m4
@@ -6,6 +6,7 @@ AC_DEFUN([GP_CHECK_POHELPER],
AC_CONFIG_FILES([
pohelper/Makefile
+ pohelper/data/Makefile
pohelper/src/Makefile
])
])
View
1 po/POTFILES.in
@@ -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
View
2 pohelper/Makefile.am
@@ -1,4 +1,4 @@
include $(top_srcdir)/build/vars.auxfiles.mk
-SUBDIRS = src
+SUBDIRS = data src
plugin = pohelper
View
8 pohelper/README
@@ -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
View
4 pohelper/data/Makefile.am
@@ -0,0 +1,4 @@
+include $(top_srcdir)/build/vars.docs.mk
+plugin = pohelper
+
+dist_plugindata_DATA = menus.ui
View
223 pohelper/data/menus.ui
@@ -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>
View
162 pohelper/src/gph-plugin.c
@@ -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_VERSION_CHECK (211) /* FIXME: what's the version really required? */
PLUGIN_SET_TRANSLATABLE_INFO (
LOCALEDIR, GETTEXT_PACKAGE,
- _("Translation helper"),
+ _("Translation Helper"),
_("Improves support for GetText translation files."),
"0.1",
"Colomban Wendling <ban@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 @@ on_kb_toggle_fuzziness (guint key_id)
}
}
+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);
+ }
}
View
7 pohelper/wscript_build
@@ -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')

0 comments on commit 946537f

Please sign in to comment.
Something went wrong with that request. Please try again.