Commit 8d5a53ed authored by Victor Ananjevsky's avatar Victor Ananjevsky

add --in-place option to text-info dialog

parent 1f54c751
......@@ -963,6 +963,9 @@ Set color for links. Default is \fIblue\fP.
.B \-\-listen
Listen data from stdin even if filename was specified.
.TP
.B \-\-in-place
Save file on exit instead of print it content on stdout. This option works only if file was specified from command-line.
.TP
Next options works only if yad builds with GtkSourceView.
.TP
.B \-\-lang=\fILANGUAGE\fP
......
......@@ -650,6 +650,8 @@ static GOptionEntry text_options[] = {
N_("Use specified color for links"), N_("COLOR") },
{ "formatted", 0, 0, G_OPTION_ARG_NONE, &options.text_data.formatted,
N_("Use pango markup"), NULL },
{ "in-place", 0, 0, G_OPTION_ARG_NONE, &options.text_data.in_place,
N_("Save file instead of print on exit"), NULL },
{ NULL }
};
......@@ -1839,6 +1841,7 @@ yad_options_init (void)
options.text_data.uri_color = URI_COLOR;
#endif
options.text_data.formatted = FALSE;
options.text_data.in_place = FALSE;
#ifdef HAVE_SOURCEVIEW
/* Initialize sourceview data */
......
......@@ -644,6 +644,29 @@ text_print_result (void)
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (text_buffer), &start, &end);
text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (text_buffer), &start, &end, 0);
g_print ("%s", text);
if (options.text_data.in_place && options.common_data.uri)
{
GStatBuf st;
GError *err = NULL;
/* g_file_set_contents changes the file permissions. so it must kept and restore after file saving */
if (g_stat (options.common_data.uri, &st) == 0)
{
if (!g_file_set_contents (options.common_data.uri, text, -1, &err))
{
g_printerr ("Cannot save file %s: %s\n", options.common_data.uri, err->message);
g_error_free (err);
}
else
{
/* restore permissions */
g_chmod (options.common_data.uri, st.st_mode);
}
}
else
g_printerr ("Cannot stat file %s\n", options.common_data.uri);
}
else
g_print ("%s", text);
g_free (text);
}
......@@ -23,7 +23,9 @@
#include <config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <fcntl.h>
#include <gdk/gdkx.h>
......@@ -33,6 +35,7 @@
#include <glib/gi18n.h>
#include <glib/gprintf.h>
#include <glib/gstdio.h>
#ifdef HAVE_HTML
#include <webkit2/webkit2.h>
......@@ -469,6 +472,7 @@ typedef struct {
gboolean formatted;
gchar *fore;
gchar *back;
gboolean in_place;
} YadTextData;
#ifdef HAVE_SOURCEVIEW
......
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