Skip to content

Commit

Permalink
tools: use theme's default colors and handle style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartolini committed Jan 8, 2024
1 parent b6a35ae commit e9edf1c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog
* Added the ability to copy the path of files in the Project Browser.
* Fixed unit preview in the Resource Chooser.
* The Console will now show a single line with a counter instead of spamming the view with duplicated entries.
* Fixed Console's text color in dark/light mode.

0.49.0 --- 27 Nov 2023
----------------------
Expand Down
41 changes: 27 additions & 14 deletions tools/widgets/console_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,15 @@ public class ConsoleView : Gtk.Box
_text_view.editable = false;
_text_view.can_focus = false;

// // Create tags for color-formatted text
Gtk.TextTag tag_info = new Gtk.TextTag("info");
tag_info.foreground_rgba = { 0.7, 0.7, 0.7, 1.0 };
Gtk.TextTag tag_warning = new Gtk.TextTag("warning");
tag_warning.foreground_rgba = { 1.0, 1.0, 0.4, 1.0 };
Gtk.TextTag tag_error = new Gtk.TextTag("error");
tag_error.foreground_rgba = { 1.0, 0.4, 0.4, 1.0 };
Gtk.TextTag tag_time = new Gtk.TextTag("time");
tag_time.foreground_rgba = get_style_context().get_color(Gtk.StateFlags.NORMAL);

// Create tags for color-formatted text.
Gtk.TextBuffer tb = _text_view.buffer;
tb.tag_table.add(tag_info);
tb.tag_table.add(tag_warning);
tb.tag_table.add(tag_error);
tb.tag_table.add(tag_time);
tb.tag_table.add(new Gtk.TextTag("info"));
tb.tag_table.add(new Gtk.TextTag("warning"));
tb.tag_table.add(new Gtk.TextTag("error"));
tb.tag_table.add(new Gtk.TextTag("time"));

this.style_updated.connect(update_style);
update_style();

Gtk.TextIter end_iter;
tb.get_end_iter(out end_iter);
Expand Down Expand Up @@ -581,6 +575,25 @@ public class ConsoleView : Gtk.Box
return GLib.Source.REMOVE;
});
}

private void update_style()
{
Gtk.TextBuffer tb = _text_view.buffer;
Gtk.TextTag tag_warning = tb.tag_table.lookup("warning");
Gtk.TextTag tag_error = tb.tag_table.lookup("error");
Gtk.TextTag tag_info = tb.tag_table.lookup("info");
Gtk.TextTag tag_time = tb.tag_table.lookup("time");

Gdk.RGBA col;
get_style_context().lookup_color("warning_color", out col);
tag_warning.foreground_rgba = col;
get_style_context().lookup_color("error_color", out col);
tag_error.foreground_rgba = col;
get_style_context().lookup_color("theme_fg_color", out col);
tag_info.foreground_rgba = col;
get_style_context().lookup_color("success_color", out col);
tag_time.foreground_rgba = col;
}
}

} /* namespace Crown */

0 comments on commit e9edf1c

Please sign in to comment.