From a22eb570984d2053f9393db23b33f5163196dc13 Mon Sep 17 00:00:00 2001 From: step- Date: Thu, 17 Sep 2020 21:16:47 +0200 Subject: [PATCH] 16 Fix --back and --fore in GtkSourceView builds. Cheat sheet about how options interplay in GtkSourceView-enabled builds **SYNTAX HIGHLIGHT A SHELL SCRIPT file.sh** - yad --text-view --lang=sh < file.sh - yad --text-view --lang=sh --filename=file.sh - yad --text-view --filename.sh In the last line, the correct filename EXTENSION, ".sh" must be given to get syntax highlighting. Use --lang if the correct extension can't be given. Any of the above commands can also take option --theme but if neither --lang nor --filename are given, --theme by itself is ignored. **CHANGE TEXT BACKGROUND / FOREGROUND COLOR** - yad --text-view --back=yellow --fore=red < file Do not pass any of --lang or --filename otherwise yad will ignore --back and --fore and attempt to syntax highlight the input text. --- configure.ac | 8 +++--- data/yad.1 | 16 +++++------ src/text.c | 75 ++++++++++++++++++++++++++++++---------------------- 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/configure.ac b/configure.ac index 7bbf065..31d4af3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # write PACKAGE_URL as "http" not "https" for About dialog to display a clickable link in the Credits tab. -AC_INIT([YAD], [0.42.15], [https://github.com/v1cont/yad/issues], yad, [http://github.com/v1cont/yad]) +AC_INIT([YAD], [0.42.16], [https://github.com/v1cont/yad/issues], yad, [http://github.com/v1cont/yad]) AC_CONFIG_AUX_DIR([build]) AM_INIT_AUTOMAKE([1.11 foreign dist-xz no-dist-gzip]) @@ -25,7 +25,7 @@ AC_ARG_WITH([gtk], [with_gtk=gtk2]) case "$with_gtk" in - gtk3) + gtk3) GTK_MODULE="gtk+-3.0" GTK_REQUIRED="3.0.0" GTK_PRINT="gtk+-unix-print-3.0" @@ -148,7 +148,7 @@ AM_CONDITIONAL([BUILD_IB], [test x$build_ib = xyes]) # ******************************* # Internationalization -# ******************************* +# ******************************* GETTEXT_PACKAGE=yad AC_SUBST([GETTEXT_PACKAGE]) @@ -165,7 +165,7 @@ AC_SUBST([AM_LDFLAGS]) # ******************************* AC_CONFIG_FILES([ -Makefile +Makefile po/Makefile.in src/Makefile data/Makefile diff --git a/data/yad.1 b/data/yad.1 index f389ef6..5ebd330 100644 --- a/data/yad.1 +++ b/data/yad.1 @@ -863,16 +863,16 @@ Kill parent process if cancel button was pressed. .SS Text info options .TP .B \-\-filename=\fIFILENAME\fP -Open specified file. +Open specified file. Filename extension determines syntax language if yad was built with \fIGtkSourceView\fP support. Use option \fI\-\-lang\fP to override extension. .TP .B \-\-editable Allow changes to text. .TP .B \-\-fore=\fICOLOR\fP -Set foreground color of text. +Set text foreground color. This option is ignored if any of \fI\-\-lang\fP and \fI\-\-filename\fP are given and yad was built with \fIGtkSourceView\fP support. .TP .B \-\-back=\fICOLOR\fP -Set background color of text. +Set text background color. This option is ignored if any of \fI\-\-lang\fP and \fI\-\-filename\fP are given and yad was built with \fIGtkSourceView\fP support. .TP .B \-\-fontname=\fIFONTNAME\fP Set text font. \fIFONTNAME\fP must be in a Pango font description format. By default \fIMonospace\fP is used. @@ -900,10 +900,10 @@ Make links in text clickable. Links opens with \fIxdg-open\fP command. 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. +Highlight syntax for specified \fILANGUAGE\fP. This option works only if yad was built with \fIGtkSourceView\fP support. .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. +Set highlight theme to \fITHEME\fP. This option needs any of \fI\-\-lang\fP or \fI\-\-filename\fP. It works only if yad was built with \fIGtkSourceView\fP support. Use option \fI\-\-show-themes\fP to list all available themes. .TP .B \-\-listen Listen data from stdin even if filename was specified. @@ -975,13 +975,13 @@ Show summary of options. Display an about dialog. .TP .B \-\-version -Show version of program. +Show program version and exit. Use \fI\-\-about\fP to view build options. .TP .B \-\-show-langs -Show list of possible languages for spell checking. Available only if yad builds with \fIGtkSpell\fP support. +Show list of possible languages for spell checking. Available only if yad was built with \fIGtkSpell\fP support. .TP .B \-\-show-themes -Show list of possible GtkSourceView themes. Available only if yad builds with \fIGtkSourceView\fP support. +Show list of possible highlight themes. Available only if yad was built with \fIGtkSourceView\fP support. .PP Also the standard GTK+ options are accepted. diff --git a/src/text.c b/src/text.c index cac3af4..580f2f3 100644 --- a/src/text.c +++ b/src/text.c @@ -424,10 +424,15 @@ fill_buffer_from_file () #ifdef HAVE_SOURCEVIEW if (options.source_data.lang) + { lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), options.source_data.lang); - else + gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang); + } + else if (options.common_data.uri) + { lang = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), options.common_data.uri, NULL); - gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang); + gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang); + } #endif } @@ -453,8 +458,16 @@ text_create_widget (GtkWidget * dlg) gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w), options.hscroll_policy, options.vscroll_policy); #ifdef HAVE_SOURCEVIEW - text_buffer = (GObject *) gtk_source_buffer_new (NULL); - text_view = gtk_source_view_new_with_buffer (GTK_SOURCE_BUFFER (text_buffer)); + if (options.source_data.lang || options.common_data.uri) + { + text_buffer = (GObject *) gtk_source_buffer_new (NULL); + text_view = gtk_source_view_new_with_buffer (GTK_SOURCE_BUFFER (text_buffer)); + } + else + { + text_buffer = (GObject *) gtk_text_buffer_new (NULL); + text_view = gtk_text_view_new_with_buffer (GTK_TEXT_BUFFER (text_buffer)); + } #else text_buffer = (GObject *) gtk_text_buffer_new (NULL); text_view = gtk_text_view_new_with_buffer (GTK_TEXT_BUFFER (text_buffer)); @@ -470,34 +483,8 @@ text_create_widget (GtkWidget * dlg) if (options.text_data.wrap) gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR); - if (options.text_data.fore) - { -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA clr; - if (gdk_rgba_parse (&clr, options.text_data.fore)) - gtk_widget_override_color (text_view, GTK_STATE_FLAG_NORMAL, &clr); -#else - GdkColor clr; - if (gdk_color_parse (options.text_data.fore, &clr)) - gtk_widget_modify_text (text_view, GTK_STATE_NORMAL, &clr); -#endif - } - - if (options.text_data.back) - { -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA clr; - if (gdk_rgba_parse (&clr, options.text_data.back)) - gtk_widget_override_background_color (text_view, GTK_STATE_FLAG_NORMAL, &clr); -#else - GdkColor clr; - if (gdk_color_parse (options.text_data.back, &clr)) - gtk_widget_modify_base (text_view, GTK_STATE_NORMAL, &clr); -#endif - } - #ifdef HAVE_SOURCEVIEW - if (options.source_data.theme) + if (options.source_data.theme && (options.source_data.lang || options.common_data.uri)) { GtkSourceStyleScheme *scheme = NULL; GtkSourceStyleSchemeManager *mgr; @@ -534,6 +521,32 @@ text_create_widget (GtkWidget * dlg) } #endif + if (options.text_data.fore) + { +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA clr; + if (gdk_rgba_parse (&clr, options.text_data.fore)) + gtk_widget_override_color (text_view, GTK_STATE_FLAG_NORMAL, &clr); +#else + GdkColor clr; + if (gdk_color_parse (options.text_data.fore, &clr)) + gtk_widget_modify_text (text_view, GTK_STATE_NORMAL, &clr); +#endif + } + + if (options.text_data.back) + { +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA clr; + if (gdk_rgba_parse (&clr, options.text_data.back)) + gtk_widget_override_background_color (text_view, GTK_STATE_FLAG_NORMAL, &clr); +#else + GdkColor clr; + if (gdk_color_parse (options.text_data.back, &clr)) + gtk_widget_modify_base (text_view, GTK_STATE_NORMAL, &clr); +#endif + } + /* set font */ if (options.common_data.font) fd = pango_font_description_from_string (options.common_data.font);