Kaydet (Commit) 7939b900 authored tarafından Nick Treleaven's avatar Nick Treleaven

Fix filename encoding for new files at startup from the command-line.

Make socket open command support filename:line:column syntax.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2795 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 8f38a691
2008-07-21 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/main.c, src/socket.c, src/main.h:
Fix filename encoding for new files at startup from the command-line.
Make socket open command support filename:line:column syntax.
2008-07-20 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/keybindings.c:
......
......@@ -634,45 +634,40 @@ static void signal_cb(gint sig)
}
static void handle_cl_filename(gchar *const filename)
/* Used for command-line arguments at startup or from socket.
* this will strip any :line:col filename suffix from locale_filename */
gboolean main_handle_filename(gchar *locale_filename)
{
GeanyDocument *doc;
gint line = -1, column = -1;
if (filename != NULL)
{
gint line = -1, column = -1;
g_return_val_if_fail(locale_filename, FALSE);
get_line_and_column_from_filename(filename, &line, &column);
if (line >= 0)
cl_options.goto_line = line;
if (column >= 0)
cl_options.goto_column = column;
}
get_line_and_column_from_filename(locale_filename, &line, &column);
if (line >= 0)
cl_options.goto_line = line;
if (column >= 0)
cl_options.goto_column = column;
if (filename != NULL &&
g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
{
doc = document_open_file(filename, FALSE, NULL, NULL);
/* add recent file manually because opening_session_files is set */
if (doc != NULL)
ui_add_recent_file(doc->file_name);
}
else if (filename != NULL)
{ /* create new file if it doesn't exist */
doc = document_new_file(filename, NULL, NULL);
if (doc != NULL)
{
doc = document_open_file(locale_filename, FALSE, NULL, NULL);
/* add recent file manually if opening_session_files is set */
if (doc != NULL && main_status.opening_session_files)
ui_add_recent_file(doc->file_name);
}
return TRUE;
}
else
{
const gchar *msg = _("Could not find file '%s'.");
{ /* create new file with the given filename */
gchar *utf8_filename = utils_get_utf8_from_locale(locale_filename);
g_printerr(msg, filename); /* also print to the terminal */
g_printerr("\n");
ui_set_statusbar(TRUE, msg, filename);
doc = document_new_file(utf8_filename, NULL, NULL);
if (doc != NULL)
ui_add_recent_file(doc->file_name);
g_free(utf8_filename);
return TRUE;
}
return FALSE;
}
......@@ -687,7 +682,14 @@ static gboolean open_cl_files(gint argc, gchar **argv)
{
gchar *filename = get_argv_filename(argv[i]);
handle_cl_filename(filename);
if (filename && !main_handle_filename(filename))
{
const gchar *msg = _("Could not find file '%s'.");
g_printerr(msg, filename); /* also print to the terminal */
g_printerr("\n");
ui_set_statusbar(TRUE, msg, filename);
}
g_free(filename);
}
return TRUE;
......
......@@ -53,4 +53,6 @@ gchar *get_argv_filename(const gchar *filename);
void main_quit(void);
gboolean main_handle_filename(gchar *locale_filename);
#endif
......@@ -142,7 +142,7 @@ void send_open_command(gint sock, gint argc, gchar **argv)
socket_fd_write_all(sock, "open\n", 5);
for(i = 1; i < argc && argv[i] != NULL; i++)
for (i = 1; i < argc && argv[i] != NULL; i++)
{
filename = get_argv_filename(argv[i]);
......@@ -484,20 +484,9 @@ static void handle_input_filename(const gchar *buf)
utf8_filename = g_strdup(buf);
locale_filename = utils_get_locale_from_utf8(utf8_filename);
if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
document_open_file(locale_filename, FALSE, NULL, NULL);
else
{ /* create new file if it doesn't exist */
GeanyDocument *doc;
doc = document_new_file(utf8_filename, NULL, NULL);
if (doc != NULL)
ui_add_recent_file(doc->file_name);
else
geany_debug("got data from socket, but it does not look like a filename");
}
g_free(utf8_filename);
if (locale_filename)
main_handle_filename(locale_filename);
g_free(locale_filename);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment