From 06e40e512fd4d88aeed8401e6e433ea24bc31e18 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 3 Sep 2014 17:43:17 +0100 Subject: [PATCH] Confirm whether to save protected documents (Reuses existing strings). --- src/document.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/document.c b/src/document.c index 2e9900353..21801c70b 100644 --- a/src/document.c +++ b/src/document.c @@ -1588,6 +1588,7 @@ static void protect_document(GeanyDocument *doc) sci_set_readonly(doc->editor->sci, TRUE); } + static void unprotect_document(GeanyDocument *doc) { g_return_if_fail(doc->priv->protected > 0); @@ -1846,6 +1847,41 @@ static gchar *save_doc(GeanyDocument *doc, const gchar *locale_filename, return NULL; } + +static gboolean save_file_handle_infobars(GeanyDocument *doc, gboolean force) +{ + GtkWidget *bar = NULL; + + document_show_tab(doc); + + if (doc->priv->info_bars[MSG_TYPE_RELOAD]) + { + if (!dialogs_show_question_full(NULL, _("_Overwrite"), GTK_STOCK_CANCEL, + _("Overwrite?"), + _("The file '%s' on the disk is more recent than the current buffer."), + doc->file_name)) + return FALSE; + bar = doc->priv->info_bars[MSG_TYPE_RELOAD]; + } + else if (doc->priv->info_bars[MSG_TYPE_RESAVE]) + { + if (!dialogs_show_question_full(NULL, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, + _("Try to resave the file?"), + _("File \"%s\" was not found on disk!"), + doc->file_name)) + return FALSE; + bar = doc->priv->info_bars[MSG_TYPE_RESAVE]; + } + else + { + g_assert_not_reached(); + return FALSE; + } + gtk_info_bar_response(GTK_INFO_BAR(bar), RESPONSE_DOCUMENT_SAVE); + return TRUE; +} + + /** * Saves the document. * Also shows the Save As dialog if necessary. @@ -1889,10 +1925,14 @@ gboolean document_save_file(GeanyDocument *doc, gboolean force) } /* the "changed" flag should exclude the "readonly" flag, but check it anyway for safety */ - if (doc->readonly || doc->priv->protected) + if (doc->readonly) return FALSE; if (!force && !doc->changed) return FALSE; + if (doc->priv->protected) + { + return save_file_handle_infobars(doc, force); + } fp = project_get_file_prefs(); /* replaces tabs with spaces but only if the current file is not a Makefile */ @@ -3220,6 +3260,7 @@ static GtkWidget* document_show_message(GeanyDocument *doc, GtkMessageType msgty return info_widget; } + static void on_monitor_reload_file_response(GtkWidget *bar, gint response_id, GeanyDocument *doc) { unprotect_document(doc); @@ -3231,6 +3272,7 @@ static void on_monitor_reload_file_response(GtkWidget *bar, gint response_id, Ge document_save_file(doc, FALSE); } + static gboolean on_sci_key(GtkWidget *widget, GdkEventKey *event, gpointer data) { GtkInfoBar *bar = GTK_INFO_BAR(data); -- 2.11.4.GIT