Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Thu, 09 Jun 2016 13:22:18 UTC Commit: f66df036048fb76f0dc2305ef0c6ce32b1f5ba28 https://github.com/geany/geany-plugins/commit/f66df036048fb76f0dc2305ef0c6ce...
Log Message: ----------- Merge pull request #366 from b4n/shiftcolumn/less-deprecated
Shiftcolumn: Geany deprecation fixes + a simple fix
Modified Paths: -------------- shiftcolumn/src/shiftcolumn.c
Modified: shiftcolumn/src/shiftcolumn.c 41 lines changed, 14 insertions(+), 27 deletions(-) =================================================================== @@ -52,15 +52,13 @@ enum{ KB_SHIFT_RIGHT, KB_COUNT }; -PLUGIN_KEY_GROUP(shiftcolumn, KB_COUNT)
static void shift_left_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata){ gchar *txt; gchar *txt_i; gchar char_before; - gint txt_len;
gint startpos; gint endpos; @@ -105,21 +103,19 @@ static void shift_left_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, if(startline == endline){
/* get the text in question */ - txt_len = endpos - startpos; - txt_i = g_malloc(txt_len + 1); - txt = g_malloc(txt_len + 2); - sci_get_selected_text(sci, txt_i); + txt_i = sci_get_selection_contents(sci);
char_before = sci_get_char_at(sci, startpos - 1);
/* set up new text buf */ - (void) g_sprintf(txt, "%s%c", txt_i, char_before); + txt = g_strdup_printf("%s%c", txt_i, char_before);
/* start undo */ sci_start_undo_action(sci);
/* put the new text in */ sci_set_selection_start(sci, startpos - 1); + sci_set_selection_end(sci, endpos); sci_replace_sel(sci, txt);
/* select the right bit again */ @@ -174,15 +170,11 @@ static void shift_left_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol);
- txt_len = sci_get_selected_text_length(sci); - txt_i = g_malloc(txt_len + 1); - txt = g_malloc(txt_len + 2); - - sci_get_selected_text(sci, txt_i); + txt_i = sci_get_selection_contents(sci); char_before = sci_get_char_at(sci, linepos + startcol - 1);
/* set up new text buf */ - (void) g_sprintf(txt, "%s%c", txt_i, char_before); + txt = g_strdup_printf("%s%c", txt_i, char_before);
/* put the new text in */ sci_set_selection_start(sci, linepos + startcol - 1); @@ -211,7 +203,6 @@ static void shift_right_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, gchar *txt; gchar *txt_i; gchar char_after; - gint txt_len;
gint startpos; gint endpos; @@ -252,20 +243,18 @@ static void shift_right_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, if(startline == endline){
/* get the text in question */ - txt_len = endpos - startpos; - txt_i = g_malloc(txt_len + 1); - txt = g_malloc(txt_len + 2); - sci_get_selected_text(sci, txt_i); + txt_i = sci_get_selection_contents(sci);
char_after = sci_get_char_at(sci, endpos);
/* set up new text buf */ - (void) g_sprintf(txt, "%c%s", char_after, txt_i); + txt = g_strdup_printf("%c%s", char_after, txt_i);
/* start undo */ sci_start_undo_action(sci);
/* put the new text in */ + sci_set_selection_start(sci, startpos); sci_set_selection_end(sci, endpos + 1); sci_replace_sel(sci, txt);
@@ -311,15 +300,11 @@ static void shift_right_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol);
- txt_len = sci_get_selected_text_length(sci); - txt_i = g_malloc(txt_len + 1); - txt = g_malloc(txt_len + 2); - - sci_get_selected_text(sci, txt_i); + txt_i = sci_get_selection_contents(sci); char_after = sci_get_char_at(sci, linepos + endcol);
/* set up new text buf */ - (void) g_sprintf(txt, "%c%s", char_after, txt_i); + txt = g_strdup_printf("%c%s", char_after, txt_i);
/* put the new text in */ sci_set_selection_end(sci, linepos + endcol + 1); @@ -365,6 +350,7 @@ static void kb_shift_right(G_GNUC_UNUSED guint key_id){ }
void plugin_init(G_GNUC_UNUSED GeanyData *data){ + GeanyKeyGroup *key_group;
menu_item_shift_left = gtk_menu_item_new_with_mnemonic(_("Shift Left")); gtk_widget_show(menu_item_shift_left); @@ -385,9 +371,10 @@ void plugin_init(G_GNUC_UNUSED GeanyData *data){ ui_add_document_sensitive(menu_item_shift_left);
/* setup keybindings */ - keybindings_set_item(plugin_key_group, KB_SHIFT_LEFT, kb_shift_left, + key_group = plugin_set_key_group(geany_plugin, "shiftcolumn", KB_COUNT, NULL); + keybindings_set_item(key_group, KB_SHIFT_LEFT, kb_shift_left, 0, GDK_CONTROL_MASK, "shift_left", _("Shift Left"), menu_item_shift_left); - keybindings_set_item(plugin_key_group, KB_SHIFT_RIGHT, kb_shift_right, + keybindings_set_item(key_group, KB_SHIFT_RIGHT, kb_shift_right, 0, GDK_CONTROL_MASK, "shift_right", _("Shift Right"), menu_item_shift_right); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).