Permalink
Browse files

Add actions for next/prev edit point and balance tag inward/outward.

  • Loading branch information...
1 parent ae5d780 commit 3fc149b23780a936f21daf6c7331cf9d302e3788 Matthew Brush committed Jul 12, 2011
Showing with 182 additions and 20 deletions.
  1. +101 −15 src/plugin.c
  2. +14 −4 src/zen-controller.c
  3. +1 −1 src/zen-controller.h
  4. +66 −0 src/zen-editor.c
View
@@ -74,42 +74,92 @@ static struct ZenCodingPlugin
plugin;
+static void init_config(struct ZenCodingPlugin *plugin);
-static void init_config(struct ZenCodingPlugin *plugin);
+/* TODO: cleanup all the callbacks/keybindings/menu items */
static void on_expand_abbreviation(GtkMenuItem *menuitem, struct ZenCodingPlugin *plugin)
{
zen_controller_run_action(plugin->zen_controller, "expand_abbreviation");
}
+
+static void on_expand_abbreviation_keybinding(guint key_id)
+{
+ on_expand_abbreviation(NULL, &plugin);
+}
+
+
static void on_expand_wrap(GtkMenuItem *menuitem, struct ZenCodingPlugin *plugin)
{
zen_controller_run_action(plugin->zen_controller, "wrap_with_abbreviation");
}
-static void on_profile_toggled(GtkCheckMenuItem *item, const gchar *profile_name)
+static void on_expand_wrap_keybinding(guint key_id)
{
- if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item)))
- {
- zen_controller_set_active_profile(plugin.zen_controller, profile_name);
- ui_set_statusbar(TRUE, _("Zen Coding: Selected profile '%s'"),
- gtk_menu_item_get_label(GTK_MENU_ITEM(item)));
- }
+ on_expand_wrap(NULL, &plugin);
}
-static void on_expand_abbreviation_keybinding(guint key_id)
+static void on_next_insertion_point(GtkMenuItem *menuitem, struct ZenCodingPlugin *plugin)
{
- on_expand_abbreviation(NULL, &plugin);
+ zen_controller_run_action(plugin->zen_controller, "next_edit_point");
}
-static void on_expand_wrap_keybinding(guint key_id)
+static void on_next_insertion_point_keybinding(guint key_id)
{
- on_expand_wrap(NULL, &plugin);
+ on_next_insertion_point(NULL, &plugin);
+}
+
+
+static void on_previous_insertion_point(GtkMenuItem *menuitem, struct ZenCodingPlugin *plugin)
+{
+ zen_controller_run_action(plugin->zen_controller, "prev_edit_point");
+}
+
+
+static void on_previous_insertion_point_keybinding(guint key_id)
+{
+ on_previous_insertion_point(NULL, &plugin);
+}
+
+
+static void on_match_pair_outward(GtkMenuItem *item, struct ZenCodingPlugin *plugin)
+{
+ zen_controller_run_action(plugin->zen_controller, "match_pair_outward");
+}
+
+
+static void on_match_pair_outward_keybinding(guint key_id)
+{
+ on_match_pair_outward(NULL, &plugin);
+}
+
+
+static void on_match_pair_inward(GtkMenuItem *item, struct ZenCodingPlugin *plugin)
+{
+ zen_controller_run_action(plugin->zen_controller, "match_pair_inward");
+}
+
+
+static void on_match_pair_inward_keybinding(guint key_id)
+{
+ on_match_pair_inward(NULL, &plugin);
+}
+
+
+static void on_profile_toggled(GtkCheckMenuItem *item, const gchar *profile_name)
+{
+ if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item)))
+ {
+ zen_controller_set_active_profile(plugin.zen_controller, profile_name);
+ ui_set_statusbar(TRUE, _("Zen Coding: Selected profile '%s'"),
+ gtk_menu_item_get_label(GTK_MENU_ITEM(item)));
+ }
}
@@ -166,6 +216,42 @@ static void build_zc_menu(GeanyKeyGroup *kg, struct ZenCodingPlugin *plugin)
_("Wrap with Abbreviation"),
item);
+ item = gtk_menu_item_new_with_label(_("Next insertion point"));
+ g_signal_connect(item, "activate", G_CALLBACK(on_next_insertion_point), plugin);
+ gtk_menu_append(GTK_MENU(menu), item);
+ keybindings_set_item(kg, 2,
+ (GeanyKeyCallback) on_next_insertion_point_keybinding,
+ GDK_n, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "next_insertion_point",
+ _("Next insertion point"),
+ item);
+
+ item = gtk_menu_item_new_with_label(_("Previous insertion point"));
+ g_signal_connect(item, "activate", G_CALLBACK(on_previous_insertion_point), plugin);
+ gtk_menu_append(GTK_MENU(menu), item);
+ keybindings_set_item(kg, 3,
+ (GeanyKeyCallback) on_previous_insertion_point_keybinding,
+ GDK_p, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "previous_insertion_point",
+ _("Previous insertion point"),
+ item);
+
+ item = gtk_menu_item_new_with_label(_("Balance Tag Outward"));
+ g_signal_connect(item, "activate", G_CALLBACK(on_match_pair_outward), plugin);
+ gtk_menu_append(GTK_MENU(menu), item);
+ keybindings_set_item(kg, 4,
+ (GeanyKeyCallback) on_match_pair_outward_keybinding,
+ GDK_R, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "match_pair_outward",
+ _("Balance Tag Outward"),
+ item);
+
+ item = gtk_menu_item_new_with_label(_("Balance Tag Inward"));
+ g_signal_connect(item, "activate", G_CALLBACK(on_match_pair_inward), plugin);
+ gtk_menu_append(GTK_MENU(menu), item);
+ keybindings_set_item(kg, 5,
+ (GeanyKeyCallback) on_match_pair_inward_keybinding,
+ GDK_L, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "match_pair_inward",
+ _("Balance Tag Inward"),
+ item);
+
item = gtk_separator_menu_item_new();
gtk_menu_append(GTK_MENU(menu), item);
@@ -259,7 +345,7 @@ static void on_monitor_changed(GFileMonitor *monitor, GFile *file,
if (plugin->zen_controller != NULL)
zen_controller_free(plugin->zen_controller);
- plugin->zen_controller = zen_controller_new(plugin->config_dir);
+ plugin->zen_controller = zen_controller_new(plugin->config_dir, ZEN_PROFILES_PATH);
if (plugin->zen_controller == NULL)
g_warning(_("Failed re-initializing Zen Coding after settings change detected"));
@@ -405,13 +491,13 @@ void plugin_init(GeanyData *data)
memset(&plugin, 0, sizeof(struct ZenCodingPlugin));
- kg = plugin_set_key_group(geany_plugin, "zencoding", 2, NULL);
+ kg = plugin_set_key_group(geany_plugin, "zencoding", 6, NULL);
build_zc_menu(kg, &plugin);
init_config(&plugin);
- plugin.zen_controller = zen_controller_new(plugin.config_dir);
+ plugin.zen_controller = zen_controller_new(plugin.config_dir, ZEN_PROFILES_PATH);
zen_controller_set_active_profile(plugin.zen_controller, "xhtml");
View
@@ -39,7 +39,7 @@ extern GeanyData *geany_data;
extern GeanyFunctions *geany_functions;
-ZenController *zen_controller_new(const char *zendir)
+ZenController *zen_controller_new(const char *zendir, const char *profiles_dir)
{
ZenController *result;
char zen_path[PATH_MAX + 20] = { 0 };
@@ -122,10 +122,8 @@ ZenController *zen_controller_new(const char *zendir)
Py_XDECREF(module);
result->editor = PyObject_CallObject(cls, NULL);
- /*result->editor = PyInstance_New(cls, NULL, NULL);*/
if (result->editor == NULL)
{
- //fprintf(stderr, "%s: %d: Here\n", __FILE__, __LINE__);
if (PyErr_Occurred())
PyErr_Print();
Py_XDECREF(cls);
@@ -176,6 +174,18 @@ ZenController *zen_controller_new(const char *zendir)
return NULL;
}
+ /* Initialize/setup profiles */
+ PyObject *res;
+ res = PyObject_CallMethod(result->editor, "init_profiles", "(s)", profiles_dir);
+ if (res == NULL)
+ {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ g_warning("Unable to initialize profiles");
+ }
+ else
+ Py_XDECREF(res);
+
return result;
}
@@ -222,7 +232,7 @@ void zen_controller_run_action(ZenController *zen, const char *action_name)
g_return_if_fail(zen != NULL);
g_return_if_fail(action_name != NULL);
- ui_set_statusbar(TRUE, _("Zen Coding: Running '%s' action"), action_name);
+ ui_set_statusbar(FALSE, _("Zen Coding: Running '%s' action"), action_name);
doc = document_get_current();
if (!DOC_VALID(doc))
View
@@ -42,7 +42,7 @@ struct _ZenController
};
-ZenController *zen_controller_new(const char *zendir);
+ZenController *zen_controller_new(const char *zendir, const char *profiles_dir);
void zen_controller_free(ZenController *zen);
void zen_controller_run_action(ZenController *zen, const char *action_name);
void zen_controller_set_active_profile(ZenController *zen, const char *profile);
View
@@ -504,6 +504,71 @@ ZenEditor_set_profile_name(ZenEditor *self, PyObject *args)
}
+static PyObject *
+ZenEditor_init_profiles(ZenEditor *self, PyObject *args)
+{
+ gint result = -1;
+ gchar *profiles_dir = NULL, *runcode = NULL;
+ static const gchar *runfmt =
+ "import os\n"
+ "from ConfigParser import SafeConfigParser\n"
+ "import zencoding.utils\n"
+ "for cfg_file in os.listdir('%s'):\n"
+ " if cfg_file.endswith('.conf'):\n"
+ " cfg_file = os.path.join('%s', cfg_file)\n"
+ " p = SafeConfigParser()\n"
+ " p.read(cfg_file)\n"
+ " if p.has_section('profile') and p.has_option('profile', 'name'):\n"
+ " d = {}\n"
+ " name = p.get('profile', 'name')\n"
+ " if not name: continue\n"
+ " if p.has_option('profile', 'tag_case'):\n"
+ " d['case'] = p.get('profile', 'tag_case').lower()\n"
+ " if p.has_option('profile', 'attr_case'):\n"
+ " d['attr_case'] = p.get('profile', 'attr_case').lower()\n"
+ " if p.has_option('profile', 'attr_quotes'):\n"
+ " d['attr_quotes'] = p.get('profile', 'attr_quotes').lower()\n"
+ " if p.has_option('profile', 'tag_nl'):\n"
+ " if p.get('profile', 'tag_nl').lower() == 'decide':\n"
+ " d['tag_nl'] = 'decide'\n"
+ " else:\n"
+ " d['tag_nl'] = p.getboolean('profile', 'tag_nl')\n"
+ " if p.has_option('profile', 'place_cursor'):\n"
+ " d['place_cursor'] = p.getboolean('profile', 'place_cursor')\n"
+ " if p.has_option('profile', 'indent'):\n"
+ " d['indent'] = p.getboolean('profile', 'indent')\n"
+ " if p.has_option('profile', 'self_closing_tag'):\n"
+ " if p.get('profile', 'self_closing_tag').lower() == 'xhtml':\n"
+ " d['self_closing_tag'] = 'xhtml'\n"
+ " else:\n"
+ " d['self_closing_tag'] = p.getboolean('profile', \n"
+ " 'self_closing_tag')\n"
+ " zencoding.utils.setup_profile(name, d)\n";
+
+
+ if (runfmt == NULL) /* run once */
+ Py_RETURN_TRUE;
+
+ if (PyArg_ParseTuple(args, "s", &profiles_dir))
+ {
+ if (profiles_dir != NULL)
+ {
+ runcode = g_strdup_printf(runfmt, profiles_dir, profiles_dir);
+ result = PyRun_SimpleString(runcode);
+ g_free(runcode);
+ }
+ }
+
+ if (result == 0)
+ {
+ runfmt = NULL;
+ Py_RETURN_TRUE;
+ }
+
+ Py_RETURN_FALSE;
+}
+
+
static PyObject *
ZenEditor_get_syntax(ZenEditor *self, PyObject *args)
{
@@ -635,6 +700,7 @@ static PyMethodDef ZenEditor_methods[] = {
{"prompt", (PyCFunction)ZenEditor_prompt, METH_VARARGS},
{"get_selection", (PyCFunction)ZenEditor_get_selection, METH_VARARGS},
{"get_file_path", (PyCFunction)ZenEditor_get_file_path, METH_VARARGS},
+ {"init_profiles", (PyCFunction)ZenEditor_init_profiles, METH_VARARGS},
{NULL}
};

0 comments on commit 3fc149b

Please sign in to comment.