Skip to content

Commit

Permalink
Added sourceview language detected to statusbar. Added app->langname …
Browse files Browse the repository at this point in the history
…to hold detected language name to avoid repeated calls to gtk_source_language_get_name.
  • Loading branch information
David C. Rankin committed Jul 18, 2018
1 parent 2095560 commit 953c73f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
5 changes: 3 additions & 2 deletions gtk_appdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ g_print ("app->exename : %s\n"
app->poscurend = FALSE; /* (bug with Quit) remove trailing ws on save */
#ifdef HAVESOURCEVIEW
app->langmgr = gtk_source_language_manager_get_default();
app->language = NULL;
app->language = NULL; /* sourceview langmgr language */
app->langname = NULL; /* language name (owned by mgr, do not free) */
// app->schememgr = gtk_source_style_scheme_manager_get_default();
// app->schemeids = gtk_source_style_scheme_manager_get_scheme_ids (app->schememgr);
app->highlight = TRUE; /* show syntax highlight */
app->lineno = FALSE; /* show line numbers (sourceview) */
app->linehghlt = TRUE; /* highlight current line */
app->laststyle = NULL;
app->comment_single = NULL; /* single line comment | all are */
app->comment_blk_beg = NULL; /* blobk comment begin | literals */
app->comment_blk_beg = NULL; /* block comment begin | literals */
app->comment_blk_end = NULL; /* block comment end | do not free */
#endif
#ifndef HAVEMSWIN
Expand Down
1 change: 1 addition & 0 deletions gtk_appdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ typedef struct {
GtkSourceBuffer *buffer;
GtkSourceLanguageManager *langmgr;
GtkSourceLanguage *language;
const gchar *langname; /* name of language from sourceview guess */
// GtkSourceStyleSchemeManager *schememgr;
// const gchar * const *schemeids;
GtkWidget *stylelist;
Expand Down
7 changes: 6 additions & 1 deletion gtk_sourceview.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ GtkSourceLanguage *sourcelanguage_lookup (const gchar *name, gpointer data)
lang_ids[i]);
lmname = gtk_source_language_get_name (lang);

if (*lmname == *name && g_strcmp0 (lmname, name) == 0)
if (*lmname == *name && g_strcmp0 (lmname, name) == 0) {
app->langname = lmname;
return ((app->language = lang));
}
}

return NULL;
Expand Down Expand Up @@ -530,6 +532,9 @@ void sourceview_guess_language (kwinst *app)
app->filename, content_type);
gtk_source_buffer_set_language (app->buffer, app->language);

if (app->language)
app->langname = gtk_source_language_get_name (app->language);

sourceview_set_comment_syntax (app);

if (app->laststyle)
Expand Down
22 changes: 19 additions & 3 deletions gtk_statusbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,26 @@ void status_set_default (kwinst *app)
app->lines = gtk_text_buffer_get_line_count (buffer);
app->col = gtk_text_iter_get_line_offset (&iter);

#ifdef HAVESOURCEVIEW
if (app->langname) {
status = g_strdup_printf (" line:%5d / %d col:%4d | %s | %s | %s | %s",
app->line + 1, app->lines, app->col + 1,
app->overwrite ? "OVR" : "INS",
app->eolnm[app->eol], bomstr[app->bom],
app->langname);
}
else {
status = g_strdup_printf (" line:%5d / %d col:%4d | %s | %s | %s",
app->line + 1, app->lines, app->col + 1,
app->overwrite ? "OVR" : "INS",
app->eolnm[app->eol], bomstr[app->bom]);
}
#else
status = g_strdup_printf (" line:%5d / %d col:%4d | %s | %s | %s",
app->line + 1, app->lines, app->col + 1,
app->overwrite ? "OVR" : "INS",
app->eolnm[app->eol], bomstr[app->bom]);
app->line + 1, app->lines, app->col + 1,
app->overwrite ? "OVR" : "INS",
app->eolnm[app->eol], bomstr[app->bom]);
#endif

if (app->cid) /* pop previous statusbar entry */
gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->cid);
Expand Down

0 comments on commit 953c73f

Please sign in to comment.