Commit 745ad721 authored by Victor Ananjevsky's avatar Victor Ananjevsky

add some GtkSourceView options to text-info dialog

parent 0256ab4e
......@@ -49,6 +49,8 @@ TERM_CMD - string with terminal command. Default is "xterm -e '%s'"
OPEN_CMD - string with open command. Default is "xdg-open '%s'"
DATE_FMT - string with date output format. Default is "%x". See strftime(3) for details
URI_COLOR - color for URIs in text-info dialog. Default is blue
MARK1_COLOR - color for first type of text marks in text-info dialog. Default is lightgreen
MARK2_COLOR - color for second type of text marks in text-info dialog. Default is pink
MAX_TABS - set the number of tabs for tabbed dialog. Default is 100
Defines can be added througs CFLAGS environment variable
......@@ -959,15 +959,35 @@ Set default color for background.
.B \-\-uri-color=\fICOLOR\fP
Set color for links. Default is \fIblue\fP.
.TP
.B \-\-lang=LANGUAGE
Highlight syntax for specified \fILANGUAGE\fP. This option works only if yad builds with gtksourceview.
.TP
.B \-\-theme=THEME
Set used theme to \fITHEME\fP. This option works only if yad builds with gtksourceview. Use option \fI\-\-show-themes\fP for get list of all available themes.
.TP
.B \-\-listen
Listen data from stdin even if filename was specified.
.TP
Next options works only if yad builds with GtkSourceView.
.TP
.B \-\-lang=\fILANGUAGE\fP
Highlight syntax for specified \fILANGUAGE\fP.
.TP
.B \-\-theme=\fITHEME\fP
Set used theme to \fITHEME\fP. Use option \fI\-\-show-themes\fP for get list of all available themes.
.TP
.B \-\-line-num
Show line numbers.
.TP
.B \-\-line-hl
Highlight current line.
.TP
.B \-\-line-marks
Enable line marks mode. There are two types of marks. First type sets by left mouse button and second by the right mouse button.
.TP
.B \-\-mark1-color=\fICOLOR\fP
Set background color for marks of first type to \fICOLOR\fP. Default is lightgreen.
.TP
.B \-\-mark2-color=\fICOLOR\fP
Set background color for marks of second type to \fICOLOR\fP. Default is pink.
.TP
.B \-\-right-margin=\fI[POS]\fP
Enable mark of right margin. Optional argument \fIPOS\fP is a margin position in characters. Default is 80.
.PP
If \fIfontname\fP option is specified for text dialog, the description of font must be in CSS style (not in a Pango style).
Sending FormFeed character to text dialog clears it. This symbol may be sent as \fIecho \-e '\\f'\fP.
Pressing \fICtrl+S\fP popups the search entry in text dialog.
......
......@@ -36,6 +36,14 @@
<default>'blue'</default>
<_summary>Default color for URI in text-info dialog</_summary>
</key>
<key name="mark1-color" type="s">
<default>'lightgreen'</default>
<_summary>Default color for first type of text marks in text-info dialog</_summary>
</key>
<key name="mark2-color" type="s">
<default>'pink'</default>
<_summary>Default color for second type of text marks in text-info dialog</_summary>
</key>
<key name="max-tab" type="i">
<default>100</default>
<_summary>Maximum number of tabs in notebook dialog</_summary>
......
......@@ -56,4 +56,12 @@
#define MAX_TABS 100
#endif
#ifndef MARK1_COLOR
#define MARK1_COLOR "lightgreen"
#endif
#ifndef MARK2_COLOR
#define MARK2_COLOR "pink"
#endif
#endif /* __YAD_DEFS_H__ */
......@@ -56,6 +56,9 @@ static gboolean set_scroll_policy (const gchar *, const gchar *, gpointer, GErro
static gboolean set_size_format (const gchar *, const gchar *, gpointer, GError **);
#endif
static gboolean set_interp (const gchar *, const gchar *, gpointer, GError **);
#ifdef HAVE_SOURCEVIEW
static gboolean set_right_margin (const gchar *, const gchar *, gpointer, GError **);
#endif
static gboolean about_mode = FALSE;
static gboolean version_mode = FALSE;
......@@ -661,6 +664,18 @@ static GOptionEntry source_options[] = {
N_("Use specified langauge for syntax highlighting"), N_("LANG") },
{ "theme", 0, 0, G_OPTION_ARG_STRING, &options.source_data.theme,
N_("Use specified theme"), N_("THEME") },
{ "line-num", 0, 0, G_OPTION_ARG_NONE, &options.source_data.line_num,
N_("Show line numbers"), NULL },
{ "line-hl", 0, 0, G_OPTION_ARG_NONE, &options.source_data.line_hl,
N_("Highlight current line"), NULL },
{ "line-marks", 0, 0, G_OPTION_ARG_NONE, &options.source_data.line_marks,
N_("Enable line marks"), NULL },
{ "mark1-color", 0, 0, G_OPTION_ARG_STRING, &options.source_data.m1_color,
N_("Set color for first type marks"), N_("COLOR") },
{ "mark2-color", 0, 0, G_OPTION_ARG_STRING, &options.source_data.m1_color,
N_("Set color for second type marks"), N_("COLOR") },
{ "right-margin", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, set_right_margin,
N_("Set position of right margin"), N_("[POS]") },
{ NULL }
};
#endif
......@@ -1310,6 +1325,17 @@ set_interp (const gchar * option_name, const gchar * value, gpointer data, GErro
return TRUE;
}
#if HAVE_SOURCEVIEW
static gboolean
set_right_margin (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{
if (value)
options.source_data.right_margin = atoi (value);
else
options.source_data.right_margin = RIGHT_MARGIN;
}
#endif
#ifndef G_OS_WIN32
static gboolean
set_xid_file (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
......@@ -1808,6 +1834,17 @@ yad_options_init (void)
/* Initialize sourceview data */
options.source_data.lang = NULL;
options.source_data.theme = NULL;
options.source_data.line_num = FALSE;
options.source_data.line_hl = FALSE;
options.source_data.line_marks = FALSE;
#ifndef STANDALONE
options.source_data.m1_color = g_settings_get_string (settings, "mark1-color");
options.source_data.m2_color = g_settings_get_string (settings, "mark2-color");
#else
options.source_data.m1_color = MARK1_COLOR;
options.source_data.m2_color = MARK2_COLOR;
#endif
options.source_data.right_margin = 0;
#endif
}
......
......@@ -260,6 +260,33 @@ linkify_cb (GtkTextBuffer * buf, GRegex * regex)
g_free (text);
}
#if HAVE_SOURCEVIEW
static void
line_mark_activated (GtkSourceGutter *gutter, GtkTextIter *iter, GdkEventButton *ev, gpointer d)
{
GSList *mark_list;
const gchar *mark_type;
if (ev->button == 1)
mark_type = SV_MARK1;
else if (ev->button == 3)
mark_type = SV_MARK2;
else
return;
/* get the marks already in the line */
mark_list = gtk_source_buffer_get_source_marks_at_line (GTK_SOURCE_BUFFER (text_buffer),
gtk_text_iter_get_line (iter), mark_type);
if (mark_list != NULL)
gtk_text_buffer_delete_mark (GTK_TEXT_BUFFER (text_buffer), GTK_TEXT_MARK (mark_list->data));
else
gtk_source_buffer_create_source_mark (GTK_SOURCE_BUFFER (text_buffer), NULL, mark_type, iter);
g_slist_free (mark_list);
}
#endif
static gboolean
handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
{
......@@ -505,6 +532,37 @@ text_create_widget (GtkWidget * dlg)
else
g_printerr (_("Theme %s not found\n"), options.source_data.theme);
}
gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (text_view), options.source_data.line_num);
gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (text_view), options.source_data.line_hl);
if (options.source_data.line_marks)
{
GdkRGBA color;
GtkSourceMarkAttributes *attr;
gtk_source_view_set_show_line_marks (GTK_SOURCE_VIEW (text_view), TRUE);
gdk_rgba_parse (&color, options.source_data.m1_color);
attr = gtk_source_mark_attributes_new ();
gtk_source_mark_attributes_set_background (attr, &color);
gtk_source_mark_attributes_set_icon_name (attr, "checkbox-checked-symbolic");
gtk_source_view_set_mark_attributes (GTK_SOURCE_VIEW (text_view), SV_MARK1, attr, 0);
g_object_unref (attr);
gdk_rgba_parse (&color, options.source_data.m2_color);
attr = gtk_source_mark_attributes_new ();
gtk_source_mark_attributes_set_background (attr, &color);
gtk_source_mark_attributes_set_icon_name (attr, "checkbox-checked-symbolic");
gtk_source_view_set_mark_attributes (GTK_SOURCE_VIEW (text_view), SV_MARK2, attr, 0);
g_object_unref (attr);
g_signal_connect (G_OBJECT (text_view), "line-mark-activated", G_CALLBACK (line_mark_activated), NULL);
}
if (options.source_data.right_margin > 0)
{
gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (text_view), TRUE);
gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (text_view), options.source_data.right_margin);
}
#endif
#ifdef HAVE_SPELL
......
......@@ -59,6 +59,11 @@ G_BEGIN_DECLS
#define YAD_URL_REGEX "(http|https|ftp|file)://[a-zA-Z0-9./_%#&-]+"
#define RIGHT_MARGIN 80 /* default right margin position for GtkSourceView */
#define SV_MARK1 "one"
#define SV_MARK2 "two"
typedef enum {
YAD_MODE_MESSAGE,
YAD_MODE_APP,
......@@ -470,6 +475,12 @@ typedef struct {
typedef struct {
gchar *lang;
gchar *theme;
gboolean line_num;
gboolean line_hl;
gboolean line_marks;
guint right_margin;
gchar *m1_color;
gchar *m2_color;
} YadSourceData;
#endif
......
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