[gedit] +LINE[:COLUMN] command line support. Fixes bug #168769.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] +LINE[:COLUMN] command line support. Fixes bug #168769.
- Date: Tue, 27 Apr 2010 11:38:57 +0000 (UTC)
commit 9d83780b1e604d4cfa44be38dac74fb2eac2a810
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Apr 26 00:46:57 2010 +0200
+LINE[:COLUMN] command line support. Fixes bug #168769.
This patch is based on Jan Nieuwenhuizen patch.
gedit/gedit-commands-file.c | 19 +++++++---
gedit/gedit-commands.h | 9 +++--
gedit/gedit-document.c | 19 ++++++++--
gedit/gedit-document.h | 2 +
gedit/gedit-session.c | 1 +
gedit/gedit-tab.c | 8 ++++
gedit/gedit-tab.h | 2 +
gedit/gedit-window.c | 5 ++-
gedit/gedit-window.h | 1 +
gedit/gedit.c | 42 +++++++++++++++++++---
plugins/filebrowser/gedit-file-browser-plugin.c | 2 +-
tests/document-loader.c | 2 +-
12 files changed, 90 insertions(+), 22 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 039f6ea..c17737e 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -123,6 +123,7 @@ load_file_list (GeditWindow *window,
const GSList *files,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create)
{
GeditTab *tab;
@@ -196,6 +197,7 @@ load_file_list (GeditWindow *window,
l->data,
encoding,
line_pos,
+ column_pos,
create);
l = g_slist_next (l);
@@ -213,6 +215,7 @@ load_file_list (GeditWindow *window,
l->data,
encoding,
line_pos,
+ column_pos,
create,
jump_to);
@@ -267,7 +270,8 @@ void
gedit_commands_load_location (GeditWindow *window,
GFile *location,
const GeditEncoding *encoding,
- gint line_pos)
+ gint line_pos,
+ gint column_pos)
{
GSList *locations = NULL;
gchar *uri;
@@ -282,7 +286,7 @@ gedit_commands_load_location (GeditWindow *window,
locations = g_slist_prepend (locations, location);
- load_file_list (window, locations, encoding, line_pos, FALSE);
+ load_file_list (window, locations, encoding, line_pos, column_pos, FALSE);
g_slist_free (locations);
}
@@ -296,14 +300,15 @@ gint
gedit_commands_load_locations (GeditWindow *window,
const GSList *locations,
const GeditEncoding *encoding,
- gint line_pos)
+ gint line_pos,
+ gint column_pos)
{
g_return_val_if_fail (GEDIT_IS_WINDOW (window), 0);
g_return_val_if_fail ((locations != NULL) && (locations->data != NULL), 0);
gedit_debug (DEBUG_COMMANDS);
- return load_file_list (window, locations, encoding, line_pos, FALSE);
+ return load_file_list (window, locations, encoding, line_pos, column_pos, FALSE);
}
/*
@@ -315,11 +320,12 @@ gint
_gedit_cmd_load_files_from_prompt (GeditWindow *window,
GSList *files,
const GeditEncoding *encoding,
- gint line_pos)
+ gint line_pos,
+ gint column_pos)
{
gedit_debug (DEBUG_COMMANDS);
- return load_file_list (window, files, encoding, line_pos, TRUE);
+ return load_file_list (window, files, encoding, line_pos, column_pos, TRUE);
}
static void
@@ -363,6 +369,7 @@ open_dialog_response_cb (GeditFileChooserDialog *dialog,
gedit_commands_load_locations (window,
files,
encoding,
+ 0,
0);
g_slist_foreach (files, (GFunc) g_object_unref, NULL);
diff --git a/gedit/gedit-commands.h b/gedit/gedit-commands.h
index 7bb06fb..c01be20 100644
--- a/gedit/gedit-commands.h
+++ b/gedit/gedit-commands.h
@@ -43,13 +43,15 @@ G_BEGIN_DECLS
void gedit_commands_load_location (GeditWindow *window,
GFile *location,
const GeditEncoding *encoding,
- gint line_pos);
+ gint line_pos,
+ gint column_pos);
/* Ignore non-existing URIs */
gint gedit_commands_load_locations (GeditWindow *window,
const GSList *locations,
const GeditEncoding *encoding,
- gint line_pos);
+ gint line_pos,
+ gint column_pos);
void gedit_commands_save_document (GeditWindow *window,
GeditDocument *document);
@@ -64,7 +66,8 @@ void gedit_commands_save_all_documents (GeditWindow *window);
gint _gedit_cmd_load_files_from_prompt (GeditWindow *window,
GSList *files,
const GeditEncoding *encoding,
- gint line_pos);
+ gint line_pos,
+ gint column_pos);
void _gedit_cmd_file_new (GtkAction *action,
GeditWindow *window);
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index e7a2b86..6eb00cf 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -82,6 +82,7 @@ static void gedit_document_load_real (GeditDocument *doc,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create);
static void gedit_document_save_real (GeditDocument *doc,
GFile *location,
@@ -127,6 +128,7 @@ struct _GeditDocumentPrivate
* to a non existing file */
const GeditEncoding *requested_encoding;
gint requested_line_pos;
+ gint requested_column_pos;
/* Saving stuff */
GeditDocumentSaver *saver;
@@ -1239,6 +1241,7 @@ reset_temp_loading_data (GeditDocument *doc)
doc->priv->requested_encoding = NULL;
doc->priv->requested_line_pos = 0;
+ doc->priv->requested_column_pos = 0;
}
static void
@@ -1291,10 +1294,15 @@ document_loader_loaded (GeditDocumentLoader *loader,
/* move the cursor at the requested line if any */
if (doc->priv->requested_line_pos > 0)
{
+ gint column;
+
+ column = (doc->priv->requested_column_pos < 1) ? 0 : doc->priv->requested_column_pos - 1;
+
/* line_pos - 1 because get_iter_at_line counts from 0 */
- gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc),
- &iter,
- doc->priv->requested_line_pos - 1);
+ gtk_text_buffer_get_iter_at_line_offset (GTK_TEXT_BUFFER (doc),
+ &iter,
+ doc->priv->requested_line_pos - 1,
+ column);
}
/* else, if enabled, to the position stored in the metadata */
else if (gedit_prefs_manager_get_restore_cursor_position ())
@@ -1390,6 +1398,7 @@ gedit_document_load_real (GeditDocument *doc,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create)
{
gchar *uri;
@@ -1411,6 +1420,7 @@ gedit_document_load_real (GeditDocument *doc,
doc->priv->create = create;
doc->priv->requested_encoding = encoding;
doc->priv->requested_line_pos = line_pos;
+ doc->priv->requested_column_pos = column_pos;
set_location (doc, location);
set_content_type (doc, NULL);
@@ -1433,6 +1443,7 @@ gedit_document_load (GeditDocument *doc,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create)
{
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
@@ -1440,7 +1451,7 @@ gedit_document_load (GeditDocument *doc,
g_return_if_fail (gedit_utils_is_valid_location (location));
g_signal_emit (doc, document_signals[LOAD], 0, location, encoding,
- line_pos, create);
+ line_pos, column_pos, create);
}
/**
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index 44b3edd..50d9d65 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -129,6 +129,7 @@ struct _GeditDocumentClass
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create);
void (* loading) (GeditDocument *document,
@@ -205,6 +206,7 @@ void gedit_document_load (GeditDocument *doc,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create);
gboolean gedit_document_load_cancel (GeditDocument *doc);
diff --git a/gedit/gedit-session.c b/gedit/gedit-session.c
index 1bf4d77..5513f4e 100644
--- a/gedit/gedit-session.c
+++ b/gedit/gedit-session.c
@@ -571,6 +571,7 @@ parse_window (GKeyFile *state_file, const char *group_name)
location,
NULL,
0,
+ 0,
FALSE,
jump_to);
if (location)
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 09d7f45..5b085e3 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -70,6 +70,7 @@ struct _GeditTabPrivate
/* tmp data for loading */
gint tmp_line_pos;
+ gint tmp_column_pos;
const GeditEncoding *tmp_encoding;
GTimer *timer;
@@ -526,6 +527,7 @@ io_loading_error_message_area_response (GtkWidget *message_area,
location,
tab->priv->tmp_encoding,
tab->priv->tmp_line_pos,
+ tab->priv->tmp_column_pos,
FALSE);
break;
case GTK_RESPONSE_YES:
@@ -1610,6 +1612,7 @@ GtkWidget *
_gedit_tab_new_from_location (GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create)
{
GeditTab *tab;
@@ -1622,6 +1625,7 @@ _gedit_tab_new_from_location (GFile *location,
location,
encoding,
line_pos,
+ column_pos,
create);
return GTK_WIDGET (tab);
@@ -1994,6 +1998,7 @@ _gedit_tab_load (GeditTab *tab,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create)
{
GeditDocument *doc;
@@ -2008,6 +2013,7 @@ _gedit_tab_load (GeditTab *tab,
gedit_tab_set_state (tab, GEDIT_TAB_STATE_LOADING);
tab->priv->tmp_line_pos = line_pos;
+ tab->priv->tmp_column_pos = column_pos;
tab->priv->tmp_encoding = encoding;
if (tab->priv->auto_save_timeout > 0)
@@ -2017,6 +2023,7 @@ _gedit_tab_load (GeditTab *tab,
location,
encoding,
line_pos,
+ column_pos,
create);
}
@@ -2053,6 +2060,7 @@ _gedit_tab_revert (GeditTab *tab)
location,
tab->priv->tmp_encoding,
0,
+ 0,
FALSE);
g_object_unref (location);
diff --git a/gedit/gedit-tab.h b/gedit/gedit-tab.h
index b3985b9..a3aa94b 100644
--- a/gedit/gedit-tab.h
+++ b/gedit/gedit-tab.h
@@ -133,6 +133,7 @@ GtkWidget *_gedit_tab_new (void);
GtkWidget *_gedit_tab_new_from_location (GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create);
gchar *_gedit_tab_get_name (GeditTab *tab);
gchar *_gedit_tab_get_tooltips (GeditTab *tab);
@@ -141,6 +142,7 @@ void _gedit_tab_load (GeditTab *tab,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create);
void _gedit_tab_revert (GeditTab *tab);
void _gedit_tab_save (GeditTab *tab);
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 57c2cf1..6e36a8a 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -1203,7 +1203,7 @@ open_recent_file (GFile *location,
locations = g_slist_prepend (locations, (gpointer) location);
- if (gedit_commands_load_locations (window, locations, NULL, 0) != 1)
+ if (gedit_commands_load_locations (window, locations, NULL, 0, 0) != 1)
{
_gedit_recent_remove (window, location);
}
@@ -2853,6 +2853,7 @@ load_uris_from_drop (GeditWindow *window,
gedit_commands_load_locations (window,
locations,
NULL,
+ 0,
0);
g_slist_foreach (locations, (GFunc) g_object_unref, NULL);
@@ -4203,6 +4204,7 @@ gedit_window_create_tab_from_location (GeditWindow *window,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create,
gboolean jump_to)
{
@@ -4214,6 +4216,7 @@ gedit_window_create_tab_from_location (GeditWindow *window,
tab = _gedit_tab_new_from_location (location,
encoding,
line_pos,
+ column_pos,
create);
if (tab == NULL)
return NULL;
diff --git a/gedit/gedit-window.h b/gedit/gedit-window.h
index 23d2cdd..8535265 100644
--- a/gedit/gedit-window.h
+++ b/gedit/gedit-window.h
@@ -109,6 +109,7 @@ GeditTab *gedit_window_create_tab_from_location (GeditWindow *window,
GFile *location,
const GeditEncoding *encoding,
gint line_pos,
+ gint column_pos,
gboolean create,
gboolean jump_to);
diff --git a/gedit/gedit.c b/gedit/gedit.c
index 27911a1..634a17c 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -90,6 +90,8 @@ static BaconMessageConnection *connection;
/* command line */
static gint line_position = 0;
+static gint column_position = 0;
+static gchar *line_column_position = NULL;
static gchar *encoding_charset = NULL;
static gboolean new_window_option = FALSE;
static gboolean new_document_option = FALSE;
@@ -137,6 +139,9 @@ static const GOptionEntry options [] =
{ "new-document", '\0', 0, G_OPTION_ARG_NONE, &new_document_option,
N_("Create a new document in an existing instance of gedit"), NULL },
+ { "+LINE[:COLUMN]", '\0', 0, G_OPTION_ARG_NONE, &line_column_position,
+ N_("Move cursor to LINE, COLUMN"), NULL },
+
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &remaining_args,
NULL, N_("[FILE...]") }, /* collects file arguments */
@@ -159,6 +164,26 @@ free_command_line_data (void)
new_window_option = FALSE;
new_document_option = FALSE;
line_position = 0;
+ column_position = 0;
+}
+
+static void
+get_line_column_position (const gchar *arg)
+{
+ gchar **split;
+
+ split = g_strsplit (arg, ":", 2);
+
+ if (split != NULL)
+ {
+ if (split[0] != NULL)
+ line_position = atoi (split[0]);
+
+ if (split[1] != NULL)
+ column_position = atoi (split[1]);
+ }
+
+ g_strfreev (split);
}
static void
@@ -173,10 +198,13 @@ gedit_get_command_line_data (void)
if (*remaining_args[i] == '+')
{
if (*(remaining_args[i] + 1) == '\0')
+ {
/* goto the last line of the document */
line_position = G_MAXINT;
+ column_position = 0;
+ }
else
- line_position = atoi (remaining_args[i] + 1);
+ get_line_column_position (remaining_args[i] + 1);
}
else
{
@@ -322,7 +350,7 @@ on_message_received (const char *message,
gint n_uris, j;
gchar **uris;
- line_position = atoi (params[1]);
+ get_line_column_position (params[1]);
if (params[2] != '\0')
encoding = gedit_encoding_get_from_charset (params[2]);
@@ -375,7 +403,8 @@ on_message_received (const char *message,
_gedit_cmd_load_files_from_prompt (window,
file_list,
encoding,
- line_position);
+ line_position,
+ column_position);
if (new_document_option)
gedit_window_create_tab (window, TRUE);
@@ -488,8 +517,8 @@ send_bacon_message (void)
command = g_string_append (command, "OPEN-URIS");
g_string_append_printf (command,
- "\t%d\t%s\t%u\t",
- line_position,
+ "\t%d:%d\t%s\t%u\t",
+ line_position, column_position,
encoding_charset ? encoding_charset : "",
g_slist_length (file_list));
@@ -725,7 +754,8 @@ main (int argc, char *argv[])
_gedit_cmd_load_files_from_prompt (window,
file_list,
encoding,
- line_position);
+ line_position,
+ column_position);
}
else
{
diff --git a/plugins/filebrowser/gedit-file-browser-plugin.c b/plugins/filebrowser/gedit-file-browser-plugin.c
index 46496f7..90bef12 100644
--- a/plugins/filebrowser/gedit-file-browser-plugin.c
+++ b/plugins/filebrowser/gedit-file-browser-plugin.c
@@ -839,7 +839,7 @@ static void
on_location_activated_cb (GeditFileBrowserWidget * tree_widget,
GFile *location, GeditWindow * window)
{
- gedit_commands_load_location (window, location, NULL, 0);
+ gedit_commands_load_location (window, location, NULL, 0, 0);
}
static void
diff --git a/tests/document-loader.c b/tests/document-loader.c
index 27fb9e2..ecceb9d 100644
--- a/tests/document-loader.c
+++ b/tests/document-loader.c
@@ -122,7 +122,7 @@ test_loader (const gchar *filename,
G_CALLBACK (on_document_loaded),
data);
- gedit_document_load (document, file, gedit_encoding_get_utf8 (), 0, FALSE);
+ gedit_document_load (document, file, gedit_encoding_get_utf8 (), 0, 0, FALSE);
while (!test_completed)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]