Commit f7461944 authored by Victor Ananjevsky's avatar Victor Ananjevsky

add more options for sourceview in text dialog

parent bede827d
......@@ -987,6 +987,27 @@ 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.
.TP
.B \-\-brackets
Highlight matching brackets.
.TP
.B \-\-indent
Enable autoindent. This option also sets \fITAB\fP key as indent key.
.TP
.B \-\-smart-he=\fITYPE\fP
Set behavior of \fIHOME\fP and \fIEND\fP keys. The \fITYPE\fP is one of \fInewer\fP, \fIbefore\fP, \fIafter\fP or \fIalways\fP.
.TP
.B \-\-smart-bs
Enable smart mode for \fIBackSpace\fP. If this option is enabled BackSpace will delete spaces to the next tab position.
.TP
.B \-\-tab-width
Set tabulation step.
.TP
.B \-\-indent-width
Set indentation step.
.TP
.B \-\-spaces
Insert spaces instead of tabulation.
.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.
......
......@@ -106,7 +106,7 @@
<key name="smart-bs" type="b">
<default>false</default>
<_summary>Use smart backspace</_summary>
</key>
</key>
<key name="tab-width" type="i">
<default>8</default>
<_summary>Default tabulation width</_summary>
......@@ -116,10 +116,6 @@
<_summary>Default indentation width</_summary>
</key>
<key name="spaces" type="b">
<default>false</default>
<_summary>Show space characters</_summary>
</key>
<key name="ins-spaces" type="b">
<default>true</default>
<_summary>Insert spaces instead of tabs</_summary>
</key>
......
......@@ -38,6 +38,7 @@ GtkIconTheme *yad_icon_theme;
#ifndef STANDALONE
GSettings *settings;
GSettings *sv_settings;
#endif
GdkPixbuf *big_fallback_image = NULL;
......@@ -702,6 +703,7 @@ main (gint argc, gchar ** argv)
#ifndef STANDALONE
settings = g_settings_new ("yad.settings");
sv_settings = g_settings_new ("yad.sourceview");
#endif
yad_icon_theme = gtk_icon_theme_get_default ();
......
......@@ -58,6 +58,7 @@ static gboolean set_size_format (const gchar *, const gchar *, gpointer, GError
static gboolean set_interp (const gchar *, const gchar *, gpointer, GError **);
#ifdef HAVE_SOURCEVIEW
static gboolean set_right_margin (const gchar *, const gchar *, gpointer, GError **);
static gboolean set_smart_homend (const gchar *, const gchar *, gpointer, GError **);
#endif
static gboolean about_mode = FALSE;
......@@ -676,6 +677,20 @@ static GOptionEntry source_options[] = {
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]") },
{ "brackets", 0, 0, G_OPTION_ARG_NONE, &options.source_data.brackets,
N_("Highlight matching brackets"), NULL },
{ "indent", 0, 0, G_OPTION_ARG_NONE, &options.source_data.indent,
N_("Use autoindent"), NULL },
{ "tab-width", 0, 0, G_OPTION_ARG_INT, &options.source_data.tab_width,
N_("Set tabulation width"), N_("VALUE") },
{ "indent-width", 0, 0, G_OPTION_ARG_INT, &options.source_data.indent_width,
N_("Set indentation width"), N_("VALUE") },
{ "smart-he", 0, 0, G_OPTION_ARG_CALLBACK, set_smart_homend,
N_("Set smart Home/End behavior"), N_("TYPE") },
{ "smart-bs", 0, 0, G_OPTION_ARG_NONE, &options.source_data.smart_bs,
N_("Enable smart backspace"), NULL },
{ "spaces", 0, 0, G_OPTION_ARG_NONE, &options.source_data.spaces,
N_("Insert spaces instead of tabs"), NULL },
{ NULL }
};
#endif
......@@ -1334,6 +1349,23 @@ set_right_margin (const gchar * option_name, const gchar * value, gpointer data,
else
options.source_data.right_margin = RIGHT_MARGIN;
}
static gboolean
set_smart_homend (const gchar * option_name, const gchar * value, gpointer data, GError ** err)
{
if (strcasecmp (value, "never") == 0)
options.source_data.smart_he = GTK_SOURCE_SMART_HOME_END_DISABLED;
else if (strcasecmp (value, "before") == 0)
options.source_data.smart_he = GTK_SOURCE_SMART_HOME_END_BEFORE;
else if (strcasecmp (value, "after") == 0)
options.source_data.smart_he = GTK_SOURCE_SMART_HOME_END_AFTER;
else if (strcasecmp (value, "always") == 0)
options.source_data.smart_he = GTK_SOURCE_SMART_HOME_END_ALWAYS;
else
g_printerr (_("Unknown smart Home/End mode: %s\n"), value);
return TRUE;
}
#endif
#ifndef G_OS_WIN32
......@@ -1833,18 +1865,37 @@ yad_options_init (void)
#ifdef HAVE_SOURCEVIEW
/* Initialize sourceview data */
options.source_data.lang = NULL;
#ifndef STANDALONE
options.source_data.theme = g_settings_get_string (sv_settings, "theme");;
options.source_data.line_num = g_settings_get_boolean (sv_settings, "line-num");
options.source_data.line_hl = g_settings_get_boolean (sv_settings, "line-hl");
options.source_data.line_marks = g_settings_get_boolean (sv_settings, "line-marks");
options.source_data.m1_color = g_settings_get_string (sv_settings, "mark1-color");
options.source_data.m2_color = g_settings_get_string (sv_settings, "mark2-color");
options.source_data.right_margin = g_settings_get_int (sv_settings, "right-margin");
options.source_data.brackets = g_settings_get_boolean (sv_settings, "brackets");
options.source_data.indent = g_settings_get_boolean (sv_settings, "indent");
options.source_data.tab_width = g_settings_get_int (sv_settings, "tab-width");
options.source_data.indent_width = g_settings_get_int (sv_settings, "indent-width");
options.source_data.smart_he = g_settings_get_enum (sv_settings, "homend");
options.source_data.smart_bs = g_settings_get_boolean (sv_settings, "smart-bs");
options.source_data.spaces = g_settings_get_boolean (sv_settings, "spaces");
#else
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;
options.source_data.brackets = FALSE;
options.source_data.indent = FALSE;
options.source_data.tab_width = 8;
options.source_data.indent_width = 4;
options.source_data.smart_he = GTK_SOURCE_SMART_HOME_END_DISABLED;
options.source_data.smart_bs = FALSE;
options.source_data.spaces = FALSE;
#endif
#endif
}
......
......@@ -563,6 +563,18 @@ text_create_widget (GtkWidget * dlg)
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);
}
if (options.source_data.indent)
{
gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (text_view), TRUE);
gtk_source_view_set_indent_on_tab (GTK_SOURCE_VIEW (text_view), TRUE);
}
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (text_view), options.source_data.tab_width);
gtk_source_view_set_indent_width (GTK_SOURCE_VIEW (text_view), options.source_data.indent_width);
gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (text_view), options.source_data.smart_he);
gtk_source_view_set_smart_backspace (GTK_SOURCE_VIEW (text_view), options.source_data.smart_bs);
gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (text_view), options.source_data.spaces);
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (text_buffer), options.source_data.brackets);
#endif
#ifdef HAVE_SPELL
......
......@@ -478,9 +478,16 @@ typedef struct {
gboolean line_num;
gboolean line_hl;
gboolean line_marks;
guint right_margin;
gchar *m1_color;
gchar *m2_color;
guint right_margin;
gboolean brackets;
gboolean indent;
gint tab_width;
gint indent_width;
GtkSourceSmartHomeEndType smart_he;
gboolean smart_bs;
gboolean spaces;
} YadSourceData;
#endif
......@@ -578,6 +585,7 @@ extern GtkIconTheme *yad_icon_theme;
#ifndef STANDALONE
extern GSettings *settings;
extern GSettings *sv_settings;
#endif
extern GdkPixbuf *big_fallback_image;
......
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