Commit 92b4a24e authored by Victor Ananjevsky's avatar Victor Ananjevsky

rewrite confirmation dialog. add confirmation for save in text-info dialog

parent 7561d3e2
...@@ -980,6 +980,10 @@ Enable file operations. This option adds open and save menu items to popup menu, ...@@ -980,6 +980,10 @@ Enable file operations. This option adds open and save menu items to popup menu,
.B \-\-disable-search .B \-\-disable-search
Disable search bar. Disable search bar.
.TP .TP
.B \-\-confirm\-save=\fI[TEXT]\fP
Confirm file saving if file content was changed. This option works only when \fI\-\-in-place\fP is specified.
Optional argument is a text for confirmation dialog.
.TP
Next options works only if yad builds with GtkSourceView. Next options works only if yad builds with GtkSourceView.
.TP .TP
.B \-\-lang=\fILANGUAGE\fP .B \-\-lang=\fILANGUAGE\fP
......
...@@ -36,20 +36,7 @@ file_confirm_overwrite (GtkWidget * dlg) ...@@ -36,20 +36,7 @@ file_confirm_overwrite (GtkWidget * dlg)
gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
if (g_file_test (filename, G_FILE_TEST_EXISTS)) if (g_file_test (filename, G_FILE_TEST_EXISTS))
{ return yad_confirm_dlg (GTK_WINDOW (dlg), options.file_data.confirm_text);
GtkWidget *d;
gint r;
gchar *buf;
buf = g_strcompress (options.file_data.confirm_text);
d = gtk_message_dialog_new (GTK_WINDOW (dlg), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", buf);
g_free (buf);
r = gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (d);
if (r != GTK_RESPONSE_YES)
return FALSE;
}
} }
return TRUE; return TRUE;
......
...@@ -28,6 +28,7 @@ static gboolean add_bar (const gchar *, const gchar *, gpointer, GError **); ...@@ -28,6 +28,7 @@ static gboolean add_bar (const gchar *, const gchar *, gpointer, GError **);
static gboolean add_scale_mark (const gchar *, const gchar *, gpointer, GError **); static gboolean add_scale_mark (const gchar *, const gchar *, gpointer, GError **);
static gboolean add_palette (const gchar *, const gchar *, gpointer, GError **); static gboolean add_palette (const gchar *, const gchar *, gpointer, GError **);
static gboolean add_confirm_overwrite (const gchar *, const gchar *, gpointer, GError **); static gboolean add_confirm_overwrite (const gchar *, const gchar *, gpointer, GError **);
static gboolean add_confirm_save (const gchar *, const gchar *, gpointer, GError **);
static gboolean add_file_filter (const gchar *, const gchar *, gpointer, GError **); static gboolean add_file_filter (const gchar *, const gchar *, gpointer, GError **);
static gboolean set_color_mode (const gchar *, const gchar *, gpointer, GError **); static gboolean set_color_mode (const gchar *, const gchar *, gpointer, GError **);
static gboolean set_buttons_layout (const gchar *, const gchar *, gpointer, GError **); static gboolean set_buttons_layout (const gchar *, const gchar *, gpointer, GError **);
...@@ -658,6 +659,8 @@ static GOptionEntry text_options[] = { ...@@ -658,6 +659,8 @@ static GOptionEntry text_options[] = {
N_("Save file instead of print on exit"), NULL }, N_("Save file instead of print on exit"), NULL },
{ "file-op", 0, 0, G_OPTION_ARG_NONE, &options.text_data.file_op, { "file-op", 0, 0, G_OPTION_ARG_NONE, &options.text_data.file_op,
N_("Enable file operations"), NULL }, N_("Enable file operations"), NULL },
{ "confirm-save", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, add_confirm_save,
N_("Confirm save the file if text was changed"), N_("[TEXT]") },
{ NULL } { NULL }
}; };
...@@ -962,6 +965,16 @@ add_confirm_overwrite (const gchar * option_name, const gchar * value, gpointer ...@@ -962,6 +965,16 @@ add_confirm_overwrite (const gchar * option_name, const gchar * value, gpointer
} }
static gboolean static gboolean
add_confirm_save (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{
options.text_data.confirm_save = TRUE;
if (value)
options.text_data.confirm_text = g_strdup (value);
return TRUE;
}
static gboolean
add_file_filter (const gchar * option_name, const gchar * value, gpointer data, GError ** err) add_file_filter (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{ {
GtkFileFilter *filter = gtk_file_filter_new (); GtkFileFilter *filter = gtk_file_filter_new ();
...@@ -1704,7 +1717,7 @@ yad_options_init (void) ...@@ -1704,7 +1717,7 @@ yad_options_init (void)
options.file_data.directory = FALSE; options.file_data.directory = FALSE;
options.file_data.save = FALSE; options.file_data.save = FALSE;
options.file_data.confirm_overwrite = FALSE; options.file_data.confirm_overwrite = FALSE;
options.file_data.confirm_text = N_("File exist. Overwrite?"); options.file_data.confirm_text = _("File exist. Overwrite?");
options.file_data.file_filt = NULL; options.file_data.file_filt = NULL;
options.file_data.mime_filt = NULL; options.file_data.mime_filt = NULL;
options.file_data.image_filt = NULL; options.file_data.image_filt = NULL;
...@@ -1845,6 +1858,8 @@ yad_options_init (void) ...@@ -1845,6 +1858,8 @@ yad_options_init (void)
options.text_data.hide_cursor = TRUE; options.text_data.hide_cursor = TRUE;
options.text_data.fore = NULL; options.text_data.fore = NULL;
options.text_data.back = NULL; options.text_data.back = NULL;
options.text_data.confirm_save = FALSE;
options.text_data.confirm_text = _("File was changed. Save it?");
#ifndef STANDALONE #ifndef STANDALONE
options.text_data.uri_color = g_settings_get_string (settings, "uri-color"); options.text_data.uri_color = g_settings_get_string (settings, "uri-color");
#else #else
......
...@@ -836,7 +836,19 @@ text_print_result (void) ...@@ -836,7 +836,19 @@ text_print_result (void)
return; return;
if (options.text_data.in_place && options.common_data.uri) if (options.text_data.in_place && options.common_data.uri)
{
if (text_changed)
{
if (options.text_data.confirm_save)
{
if (yad_confirm_dlg (GTK_WINDOW (gtk_widget_get_toplevel (text_view)),
options.text_data.confirm_text))
save_file_cb (NULL, NULL);
}
else
save_file_cb (NULL, NULL); save_file_cb (NULL, NULL);
}
}
else else
{ {
GtkTextIter start, end; GtkTextIter start, end;
......
...@@ -894,3 +894,22 @@ create_search_bar () ...@@ -894,3 +894,22 @@ create_search_bar ()
return sb; return sb;
} }
/* Confirmation dialog */
gboolean
yad_confirm_dlg (GtkWindow *parent, gchar *txt)
{
GtkWidget *d;
gchar *buf;
buf = g_strcompress (options.text_data.confirm_text);
d = gtk_message_dialog_new (parent, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", buf);
gtk_window_set_position (GTK_WINDOW (d), GTK_WIN_POS_CENTER_ON_PARENT);
g_free (buf);
ret = gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (d);
return (ret == GTK_RESPONSE_YES);
}
...@@ -476,6 +476,8 @@ typedef struct { ...@@ -476,6 +476,8 @@ typedef struct {
gchar *back; gchar *back;
gboolean in_place; gboolean in_place;
gboolean file_op; gboolean file_op;
gboolean confirm_save;
gchar *confirm_text;
} YadTextData; } YadTextData;
#ifdef HAVE_SOURCEVIEW #ifdef HAVE_SOURCEVIEW
...@@ -722,11 +724,13 @@ gchar *print_bool_val (gboolean val); ...@@ -722,11 +724,13 @@ gchar *print_bool_val (gboolean val);
gint run_command_sync (gchar *cmd, gchar **out); gint run_command_sync (gchar *cmd, gchar **out);
void run_command_async (gchar *cmd); void run_command_async (gchar *cmd);
gchar * pango_to_css (gchar *font); gchar *pango_to_css (gchar *font);
void open_uri (const gchar *uri); void open_uri (const gchar *uri);
YadSearchBar * create_search_bar (); YadSearchBar *create_search_bar ();
gboolean yad_confirm_dlg (GtkWindow *parent, gchar *txt);
static inline void static inline void
strip_new_line (gchar * str) strip_new_line (gchar * str)
......
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