Allow '+<number' and '-<number>' as values for Goto Line inputs to jump relative to the current line (closes #2997238).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4894 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2010-05-09 15:48:55 +00:00
parent 819bf8e99a
commit e382869a16
5 changed files with 49 additions and 20 deletions

View File

@ -5,9 +5,12 @@
* src/ui_utils.h, src/ui_utils.c: * src/ui_utils.h, src/ui_utils.c:
Add public, generic callback ui_editable_insert_text_callback() Add public, generic callback ui_editable_insert_text_callback()
to restrict GtkEntry text inputs to +/- and numeric values only. 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 Add special variant dialogs_show_input_goto_line() to use a normal
GtkEntry together with dialogs_show_input_goto_line() for text input. 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> 2010-05-08 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -1176,21 +1176,45 @@ on_find_in_files1_activate (GtkMenuItem *menuitem,
} }
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 void
on_go_to_line_activate (GtkMenuItem *menuitem, on_go_to_line_activate (GtkMenuItem *menuitem,
gpointer user_data) 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:"), result = dialogs_show_input_goto_line(
&val, 1, 100000000, 1)) _("Go to Line"), _("Enter the line you want to go to:"), value);
if (result != NULL)
{ {
GeanyDocument *doc = document_get_current(); GeanyDocument *doc = document_get_current();
gint offset;
gint line_no;
g_return_if_fail(doc != NULL); 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(); utils_beep();
/* remember value for future calls */
g_snprintf(value, sizeof(value), "%s", result);
g_free(result);
} }
} }
@ -1199,10 +1223,13 @@ void
on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data) on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data)
{ {
GeanyDocument *doc = document_get_current(); GeanyDocument *doc = document_get_current();
gint offset;
gint line_no;
g_return_if_fail(doc != NULL); 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(); utils_beep();
else else
keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR); keybindings_send_command(GEANY_KEY_GROUP_FOCUS, GEANY_KEYS_FOCUS_EDITOR);

View File

@ -4589,15 +4589,22 @@ void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type)
/* Convenience function for editor_goto_pos() to pass in a line number. */ /* 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; gint pos;
g_return_val_if_fail(editor, FALSE); 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; 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); return editor_goto_pos(editor, pos, TRUE);
} }

View File

@ -288,7 +288,7 @@ void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap);
gboolean editor_goto_pos(GeanyEditor *editor, gint pos, gboolean mark); 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); void editor_set_indentation_guides(GeanyEditor *editor);

View File

@ -93,21 +93,13 @@ static void delegate_entry_changed_cb(GtkEditable *editable, GeanyEntryAction *a
} }
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) static void geany_entry_action_connect_proxy(GtkAction *action, GtkWidget *widget)
{ {
GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action); GeanyEntryActionPrivate *priv = GEANY_ENTRY_ACTION_GET_PRIVATE(action);
if (priv->numeric) 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, "changed", G_CALLBACK(delegate_entry_changed_cb), action);
g_signal_connect(priv->entry, "activate", G_CALLBACK(delegate_entry_activate_cb), action); g_signal_connect(priv->entry, "activate", G_CALLBACK(delegate_entry_activate_cb), action);