You need to sign in or sign up before continuing.
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.
.B \-\-editable
Allow changes to text.
.TP
.B \-\-mime=\fITYPE\fP
Specify mime type opf input data. This options only needed for guessing appropriate syntax highlighting.
.TP
.B \-\-wrap
Enable text wrapping.
.TP
......
......@@ -376,7 +376,7 @@ handle_stdin (GIOChannel * ch, GIOCondition cond, gpointer d)
case G_IO_STATUS_EOF:
data = g_bytes_new (inbuf->str, inbuf->len);
/*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);
return FALSE;
......
......@@ -218,6 +218,8 @@ static GOptionEntry common_options[] = {
N_("Show hidden files in file selection dialogs"), NULL },
{ "filename", 0, 0, G_OPTION_ARG_FILENAME, &options.common_data.uri,
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,
N_("Set vertical orientation"), NULL },
{ "key", 0, 0, G_OPTION_ARG_INT, &options.common_data.key,
......@@ -402,8 +404,6 @@ static GOptionEntry html_options[] = {
N_("Turn on browser mode"), NULL },
{ "print-uri", 0, 0, G_OPTION_ARG_NONE, &options.html_data.print_uri,
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,
N_("Set encoding of input stream data"), N_("ENCODING") },
{ "user-agent", 0, 0, G_OPTION_ARG_STRING, &options.html_data.user_agent,
......@@ -1631,6 +1631,7 @@ yad_options_init (void)
/* Initialize common data */
options.common_data.uri = NULL;
options.common_data.mime = NULL;
options.common_data.font = NULL;
options.common_data.separator = "|";
options.common_data.item_separator = "!";
......@@ -1745,7 +1746,6 @@ yad_options_init (void)
options.html_data.uri = NULL;
options.html_data.browser = FALSE;
options.html_data.print_uri = FALSE;
options.html_data.mime = NULL;
options.html_data.encoding = NULL;
options.html_data.user_agent = "YAD-Webkit (" VERSION ")";
options.html_data.user_style = NULL;
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* 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>
......@@ -456,6 +456,9 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
GString *string;
GError *err = NULL;
gint status;
#ifdef HAVE_SOURCEVIEW
GtkSourceLanguage *lang = NULL;
#endif
string = g_string_new (NULL);
while (channel->is_readable != TRUE)
......@@ -524,18 +527,25 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
}
}
g_string_free (string, TRUE);
}
#ifdef HAVE_SOURCEVIEW
if (options.source_data.lang)
{
GtkSourceLanguage *lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (),
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
{
gchar *ctype;
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 (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
g_string_free (string, TRUE);
}
return TRUE;
}
......@@ -587,7 +597,16 @@ fill_buffer_from_file ()
if (options.source_data.lang)
lang = gtk_source_language_manager_get_language (gtk_source_language_manager_get_default (), options.source_data.lang);
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);
#endif
......
......@@ -350,7 +350,6 @@ typedef struct {
gchar *uri;
gboolean browser;
gboolean print_uri;
gchar *mime;
gchar *encoding;
gchar *user_agent;
gchar *user_style;
......@@ -505,6 +504,7 @@ typedef struct {
typedef struct {
gchar *uri;
gchar *mime;
gchar *font;
gchar *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