Kaydet (Commit) 06e40e51 authored tarafından Nick Treleaven's avatar Nick Treleaven

Confirm whether to save protected documents

(Reuses existing strings).
üst 7450a992
......@@ -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);
......
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