Commit e14b20dd authored by Victor Ananjevsky's avatar Victor Ananjevsky

improve geussing on syntax highlighting in text-info dialog. --mime option moved to common section

parent 1d30e86f
...@@ -947,6 +947,9 @@ Open specified file. ...@@ -947,6 +947,9 @@ Open specified file.
.B \-\-editable .B \-\-editable
Allow changes to text. Allow changes to text.
.TP .TP
.B \-\-mime=\fITYPE\fP
Specify mime type opf input data. This options only needed for guessing appropriate syntax highlighting.
.TP
.B \-\-wrap .B \-\-wrap
Enable text wrapping. Enable text wrapping.
.TP .TP
......
...@@ -376,7 +376,7 @@ handle_stdin (GIOChannel * ch, GIOCondition cond, gpointer d) ...@@ -376,7 +376,7 @@ handle_stdin (GIOChannel * ch, GIOCondition cond, gpointer d)
case G_IO_STATUS_EOF: case G_IO_STATUS_EOF:
data = g_bytes_new (inbuf->str, inbuf->len); data = g_bytes_new (inbuf->str, inbuf->len);
/*g_string_free (inbuf, TRUE); */ /* FIXME: IS THAT NEEDED ??? (and where) */ /*g_string_free (inbuf, TRUE); */ /* FIXME: IS THAT NEEDED ??? (and where) */
webkit_web_view_load_bytes (view, data, options.html_data.mime, options.html_data.encoding, NULL); webkit_web_view_load_bytes (view, data, options.common_data.mime, options.html_data.encoding, NULL);
g_bytes_unref (data); g_bytes_unref (data);
return FALSE; return FALSE;
......
...@@ -218,6 +218,8 @@ static GOptionEntry common_options[] = { ...@@ -218,6 +218,8 @@ static GOptionEntry common_options[] = {
N_("Show hidden files in file selection dialogs"), NULL }, N_("Show hidden files in file selection dialogs"), NULL },
{ "filename", 0, 0, G_OPTION_ARG_FILENAME, &options.common_data.uri, { "filename", 0, 0, G_OPTION_ARG_FILENAME, &options.common_data.uri,
N_("Set source filename"), N_("FILENAME") }, N_("Set source filename"), N_("FILENAME") },
{ "mime", 0, 0, G_OPTION_ARG_STRING, &options.common_data.mime,
N_("Set mime type of input data"), N_("TYPE") },
{ "vertical", 0, 0, G_OPTION_ARG_NONE, &options.common_data.vertical, { "vertical", 0, 0, G_OPTION_ARG_NONE, &options.common_data.vertical,
N_("Set vertical orientation"), NULL }, N_("Set vertical orientation"), NULL },
{ "key", 0, 0, G_OPTION_ARG_INT, &options.common_data.key, { "key", 0, 0, G_OPTION_ARG_INT, &options.common_data.key,
...@@ -402,8 +404,6 @@ static GOptionEntry html_options[] = { ...@@ -402,8 +404,6 @@ static GOptionEntry html_options[] = {
N_("Turn on browser mode"), NULL }, N_("Turn on browser mode"), NULL },
{ "print-uri", 0, 0, G_OPTION_ARG_NONE, &options.html_data.print_uri, { "print-uri", 0, 0, G_OPTION_ARG_NONE, &options.html_data.print_uri,
N_("Print clicked uri to stdout"), NULL }, N_("Print clicked uri to stdout"), NULL },
{ "mime", 0, 0, G_OPTION_ARG_STRING, &options.html_data.mime,
N_("Set mime type of input stream data"), N_("TYPE") },
{ "encoding", 0, 0, G_OPTION_ARG_STRING, &options.html_data.encoding, { "encoding", 0, 0, G_OPTION_ARG_STRING, &options.html_data.encoding,
N_("Set encoding of input stream data"), N_("ENCODING") }, N_("Set encoding of input stream data"), N_("ENCODING") },
{ "user-agent", 0, 0, G_OPTION_ARG_STRING, &options.html_data.user_agent, { "user-agent", 0, 0, G_OPTION_ARG_STRING, &options.html_data.user_agent,
...@@ -1631,6 +1631,7 @@ yad_options_init (void) ...@@ -1631,6 +1631,7 @@ yad_options_init (void)
/* Initialize common data */ /* Initialize common data */
options.common_data.uri = NULL; options.common_data.uri = NULL;
options.common_data.mime = NULL;
options.common_data.font = NULL; options.common_data.font = NULL;
options.common_data.separator = "|"; options.common_data.separator = "|";
options.common_data.item_separator = "!"; options.common_data.item_separator = "!";
...@@ -1745,7 +1746,6 @@ yad_options_init (void) ...@@ -1745,7 +1746,6 @@ yad_options_init (void)
options.html_data.uri = NULL; options.html_data.uri = NULL;
options.html_data.browser = FALSE; options.html_data.browser = FALSE;
options.html_data.print_uri = FALSE; options.html_data.print_uri = FALSE;
options.html_data.mime = NULL;
options.html_data.encoding = NULL; options.html_data.encoding = NULL;
options.html_data.user_agent = "YAD-Webkit (" VERSION ")"; options.html_data.user_agent = "YAD-Webkit (" VERSION ")";
options.html_data.user_style = NULL; options.html_data.user_style = NULL;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with YAD. If not, see <http://www.gnu.org/licenses/>. * along with YAD. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright (C) 2008-2021, Victor Ananjevsky <ananasik@gmail.com> * Copyright (C) 2008-2022, Victor Ananjevsky <victor@sanana.kiev.ua>
*/ */
#include <pango/pango.h> #include <pango/pango.h>
...@@ -456,6 +456,9 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data) ...@@ -456,6 +456,9 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
GString *string; GString *string;
GError *err = NULL; GError *err = NULL;
gint status; gint status;
#ifdef HAVE_SOURCEVIEW
GtkSourceLanguage *lang = NULL;
#endif
string = g_string_new (NULL); string = g_string_new (NULL);
while (channel->is_readable != TRUE) while (channel->is_readable != TRUE)
...@@ -524,18 +527,25 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data) ...@@ -524,18 +527,25 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
} }
} }
g_string_free (string, TRUE);
}
#ifdef HAVE_SOURCEVIEW #ifdef HAVE_SOURCEVIEW
if (options.source_data.lang) if (options.source_data.lang)
lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), options.source_data.lang);
else
{ {
GtkSourceLanguage *lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), gchar *ctype;
options.source_data.lang); if (options.common_data.mime && *options.common_data.mime)
gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang); ctype = g_content_type_from_mime_type (options.common_data.mime);
else
ctype = g_content_type_guess (NULL, string->str, string->len, NULL);
lang = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), options.common_data.uri, ctype);
g_free (ctype);
} }
gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang);
#endif #endif
g_string_free (string, TRUE);
}
return TRUE; return TRUE;
} }
...@@ -587,7 +597,16 @@ fill_buffer_from_file () ...@@ -587,7 +597,16 @@ fill_buffer_from_file ()
if (options.source_data.lang) if (options.source_data.lang)
lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), options.source_data.lang); lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), options.source_data.lang);
else else
lang = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), options.common_data.uri, NULL); {
gchar *ctype = NULL;
if (options.common_data.mime && *options.common_data.mime)
ctype = g_content_type_from_mime_type (options.common_data.mime);
else
ctype = g_content_type_guess (options.common_data.uri, NULL, 0, NULL);
lang = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), options.common_data.uri, ctype);
g_free (ctype);
}
gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang); gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (text_buffer), lang);
#endif #endif
......
...@@ -350,7 +350,6 @@ typedef struct { ...@@ -350,7 +350,6 @@ typedef struct {
gchar *uri; gchar *uri;
gboolean browser; gboolean browser;
gboolean print_uri; gboolean print_uri;
gchar *mime;
gchar *encoding; gchar *encoding;
gchar *user_agent; gchar *user_agent;
gchar *user_style; gchar *user_style;
...@@ -505,6 +504,7 @@ typedef struct { ...@@ -505,6 +504,7 @@ typedef struct {
typedef struct { typedef struct {
gchar *uri; gchar *uri;
gchar *mime;
gchar *font; gchar *font;
gchar *separator; gchar *separator;
gchar *item_separator; gchar *item_separator;
......
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