Revision: 4894 http://geany.svn.sourceforge.net/geany/?rev=4894&view=rev Author: eht16 Date: 2010-05-09 15:48:55 +0000 (Sun, 09 May 2010)
Log Message: ----------- Allow '+<number' and '-<number>' as values for Goto Line inputs to jump relative to the current line (closes #2997238).
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/editor.c trunk/src/editor.h trunk/src/geanyentryaction.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-05-09 15:48:42 UTC (rev 4893) +++ trunk/ChangeLog 2010-05-09 15:48:55 UTC (rev 4894) @@ -5,9 +5,12 @@ * src/ui_utils.h, src/ui_utils.c: Add public, generic callback ui_editable_insert_text_callback() to restrict GtkEntry text inputs to +/- and numeric values only. - * src/dialogsh, src/dialogs.c: + * src/dialogs.h, src/dialogs.c: Add special variant dialogs_show_input_goto_line() to use a normal GtkEntry together with dialogs_show_input_goto_line() for text input. + * src/geanyentryaction.c, src/callbacks.c, src/editor.c, src/editor.h: + Allow '+<number' and '-<number>' as values for Goto Line inputs + to jump relative to the current line (closes #2997238).
2010-05-08 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2010-05-09 15:48:42 UTC (rev 4893) +++ trunk/src/callbacks.c 2010-05-09 15:48:55 UTC (rev 4894) @@ -1176,21 +1176,45 @@ }
+static void get_line_and_offset_from_text(const gchar *text, gint *line_no, gint *offset) +{ + if (*text == '+' || *text == '-') + { + *line_no = atoi(text + 1); + *offset = (*text == '+') ? 1 : -1; + } + else + { + *line_no = atoi(text) - 1; + *offset = 0; + } +} + + void on_go_to_line_activate (GtkMenuItem *menuitem, gpointer user_data) { - static gdouble val = 1; + static gchar value[16] = ""; + gchar *result;
- if (dialogs_show_input_numeric(_("Go to Line"), _("Enter the line you want to go to:"), - &val, 1, 100000000, 1)) + result = dialogs_show_input_goto_line( + _("Go to Line"), _("Enter the line you want to go to:"), value); + if (result != NULL) { GeanyDocument *doc = document_get_current(); + gint offset; + gint line_no;
g_return_if_fail(doc != NULL);
- if (! editor_goto_line(doc->editor, (gint) val - 1)) + get_line_and_offset_from_text(result, &line_no, &offset); + if (! editor_goto_line(doc->editor, line_no, offset)) utils_beep(); + /* remember value for future calls */ + g_snprintf(value, sizeof(value), "%s", result); + + g_free(result); } }
@@ -1199,10 +1223,13 @@ on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data) { GeanyDocument *doc = document_get_current(); + gint offset; + gint line_no;
g_return_if_fail(doc != NULL);
- if (! editor_goto_line(doc->editor, atoi(text) - 1)) + get_line_and_offset_from_text(text, &line_no, &offset); + if (! editor_goto_line(doc->editor, line_no, offset)) utils_beep(); else keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2010-05-09 15:48:42 UTC (rev 4893) +++ trunk/src/editor.c 2010-05-09 15:48:55 UTC (rev 4894) @@ -4589,15 +4589,22 @@
/* Convenience function for editor_goto_pos() to pass in a line number. */ -gboolean editor_goto_line(GeanyEditor *editor, gint line) +gboolean editor_goto_line(GeanyEditor *editor, gint line_no, gint offset) { gint pos;
g_return_val_if_fail(editor, FALSE); - if (line < 0 || line >= sci_get_line_count(editor->sci)) + if (line_no < 0 || line_no >= sci_get_line_count(editor->sci)) return FALSE;
- pos = sci_get_position_from_line(editor->sci, line); + if (offset != 0) + { + gint current_line = sci_get_current_line(editor->sci); + line_no *= offset; + line_no = current_line + line_no; + } + + pos = sci_get_position_from_line(editor->sci, line_no); return editor_goto_pos(editor, pos, TRUE); }
Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2010-05-09 15:48:42 UTC (rev 4893) +++ trunk/src/editor.h 2010-05-09 15:48:55 UTC (rev 4894) @@ -288,7 +288,7 @@
gboolean editor_goto_pos(GeanyEditor *editor, gint pos, gboolean mark);
-gboolean editor_goto_line(GeanyEditor *editor, gint line_no); +gboolean editor_goto_line(GeanyEditor *editor, gint line_no, gint offset);
void editor_set_indentation_guides(GeanyEditor *editor);
Modified: trunk/src/geanyentryaction.c =================================================================== --- trunk/src/geanyentryaction.c 2010-05-09 15:48:42 UTC (rev 4893) +++ trunk/src/geanyentryaction.c 2010-05-09 15:48:55 UTC (rev 4894) @@ -93,21 +93,13 @@ }
-static void entry_insert_text_cb(GtkEditable *editable, gchar *new_text, gint new_text_len, - gint *position, GeanyEntryAction *action) -{ - /* don't insert any text when it is not a digit */ - if (! isdigit(*new_text)) - g_signal_stop_emission_by_name(editable, "insert-text"); -} - - static void geany_entry_action_connect_proxy(GtkAction *action, GtkWidget *widget) { GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
if (priv->numeric) - g_signal_connect(priv->entry, "insert-text", G_CALLBACK(entry_insert_text_cb), action); + g_signal_connect(priv->entry, "insert-text", + G_CALLBACK(ui_editable_insert_text_callback), NULL); g_signal_connect(priv->entry, "changed", G_CALLBACK(delegate_entry_changed_cb), action); g_signal_connect(priv->entry, "activate", G_CALLBACK(delegate_entry_activate_cb), action);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.