From 6738d43dee95b2fe15d67bfcbff2f5b6e0971d7c Mon Sep 17 00:00:00 2001 From: Dimitar Zhekov Date: Mon, 21 Nov 2011 20:33:37 +0200 Subject: [PATCH] --read-only cleanup Use the global variable only when needed and add an initializer for it in the default options. --- src/document.c | 2 +- src/main.c | 12 +++--------- src/socket.c | 4 +--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/document.c b/src/document.c index 48c9885f..cf3fdcc9 100644 --- a/src/document.c +++ b/src/document.c @@ -1162,7 +1162,7 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename doc->has_bom = filedata.bom; store_saved_encoding(doc); /* store the opened encoding for undo/redo */ - doc->readonly = readonly || filedata.readonly || cl_options.readonly; + doc->readonly = readonly || filedata.readonly; sci_set_readonly(doc->editor->sci, doc->readonly); /* update line number margin width */ diff --git a/src/main.c b/src/main.c index 17059ab8..20d3d713 100644 --- a/src/main.c +++ b/src/main.c @@ -497,7 +497,7 @@ static void parse_command_line_options(gint *argc, gchar ***argv) GError *error = NULL; GOptionContext *context; gint i; - CommandLineOptions def_clo = {FALSE, NULL, TRUE, -1, -1, FALSE, FALSE}; + CommandLineOptions def_clo = {FALSE, NULL, TRUE, -1, -1, FALSE, FALSE, FALSE}; /* first initialise cl_options fields with default values */ cl_options = def_clo; @@ -774,7 +774,7 @@ gboolean main_handle_filename(const gchar *locale_filename) if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { - doc = document_open_file(filename, FALSE, NULL, NULL); + doc = document_open_file(filename, cl_options.readonly, NULL, NULL); /* add recent file manually if opening_session_files is set */ if (doc != NULL && main_status.opening_session_files) ui_add_recent_document(doc); @@ -887,19 +887,13 @@ void main_load_project_from_command_line(const gchar *locale_filename, gboolean static void load_startup_files(gint argc, gchar **argv) { gboolean load_project_from_cl = FALSE; - gboolean cl_files_opened = FALSE; /* ATM when opening a project file any other filenames are ignored */ load_project_from_cl = (argc > 1) && g_str_has_suffix(argv[1], ".geany"); if (load_project_from_cl && argc > 2) g_print("Ignoring extra filenames after %s", argv[1]); - if (!load_project_from_cl) - cl_files_opened = open_cl_files(argc, argv); - /* switch readonly mode off for session files, future files and projects */ - cl_options.readonly = FALSE; - - if (! cl_files_opened) + if (load_project_from_cl || ! open_cl_files(argc, argv)) { if (prefs.load_session) { diff --git a/src/socket.c b/src/socket.c index 02994793..92432fc4 100644 --- a/src/socket.c +++ b/src/socket.c @@ -601,13 +601,11 @@ gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpoint { if (strncmp(buf, "open", 4) == 0) { - if (strncmp(buf+4, "ro", 2) == 0) /* open in readonly? */ - cl_options.readonly = TRUE; + cl_options.readonly = strncmp(buf+4, "ro", 2) == 0; /* open in readonly? */ while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.') { handle_input_filename(g_strstrip(buf)); } - cl_options.readonly = FALSE; /* disable again for future files */ popup = TRUE; } else if (strncmp(buf, "doclist", 7) == 0)