[geany/geany] ae45e8: Merge pull request #328 from ntrel/infobar-save
Nick Treleaven
git-noreply at xxxxx
Tue Sep 23 14:24:48 UTC 2014
Branch: refs/heads/master
Author: Nick Treleaven <nick.treleaven at btinternet.com>
Committer: Nick Treleaven <nick.treleaven at btinternet.com>
Date: Tue, 23 Sep 2014 14:24:48 UTC
Commit: ae45e8344f20968cc2f1655a63471ca447dd16ab
https://github.com/geany/geany/commit/ae45e8344f20968cc2f1655a63471ca447dd16ab
Log Message:
-----------
Merge pull request #328 from ntrel/infobar-save
Confirm whether to save protected documents instead of ignoring save
Modified Paths:
--------------
src/document.c
Modified: src/document.c
63 lines changed, 56 insertions(+), 7 deletions(-)
===================================================================
@@ -111,6 +111,13 @@ typedef struct
* it contains the new value */
} undo_action;
+/* Custom document info bar response IDs */
+enum
+{
+ RESPONSE_DOCUMENT_RELOAD = 1,
+ RESPONSE_DOCUMENT_SAVE,
+};
+
static guint doc_id_counter = 0;
@@ -1581,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);
@@ -1839,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.
@@ -1882,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 */
@@ -3213,17 +3260,19 @@ 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);
doc->priv->info_bars[MSG_TYPE_RELOAD] = NULL;
- if (response_id == GTK_RESPONSE_REJECT)
+ if (response_id == RESPONSE_DOCUMENT_RELOAD)
document_reload_file(doc, doc->encoding);
- else if (response_id == GTK_RESPONSE_ACCEPT)
+ else if (response_id == RESPONSE_DOCUMENT_SAVE)
document_save_file(doc, FALSE);
}
+
static gboolean on_sci_key(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
GtkInfoBar *bar = GTK_INFO_BAR(data);
@@ -3271,8 +3320,8 @@ static void monitor_reload_file(GeanyDocument *doc)
GtkWidget *bar;
bar = document_show_message(doc, GTK_MESSAGE_QUESTION, on_monitor_reload_file_response,
- _("_Reload"), GTK_RESPONSE_REJECT,
- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ _("_Reload"), RESPONSE_DOCUMENT_RELOAD,
+ _("_Overwrite"), RESPONSE_DOCUMENT_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("Do you want to reload it?"),
_("The file '%s' on the disk is more recent than the current buffer."),
@@ -3293,7 +3342,7 @@ static void on_monitor_resave_missing_file_response(GtkWidget *bar,
{
unprotect_document(doc);
- if (response_id == GTK_RESPONSE_ACCEPT)
+ if (response_id == RESPONSE_DOCUMENT_SAVE)
dialogs_show_save_as();
doc->priv->info_bars[MSG_TYPE_RESAVE] = NULL;
@@ -3311,7 +3360,7 @@ static void monitor_resave_missing_file(GeanyDocument *doc)
bar = document_show_message(doc, GTK_MESSAGE_WARNING,
on_monitor_resave_missing_file_response,
- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_SAVE, RESPONSE_DOCUMENT_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL, GTK_RESPONSE_NONE,
_("Try to resave the file?"),
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list