Commit ac832d8e authored by Kai Willadsen's avatar Kai Willadsen

meld: Migrate from CSS to GtkSourceView style schemes

parent e5635207
......@@ -184,6 +184,7 @@ def setup_resources():
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GtkSource
if GObject.pygobject_version <= (3, 11):
GObject.threads_init()
......@@ -203,6 +204,9 @@ def setup_resources():
Gdk.Screen.get_default(), provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
style_path = os.path.join(meld.conf.DATADIR, "styles")
GtkSource.StyleSchemeManager.get_default().append_search_path(style_path)
def setup_settings():
import meld.conf
......@@ -255,8 +259,8 @@ if __name__ == '__main__':
setup_logging()
disable_stdout_buffering()
check_requirements()
setup_settings()
setup_resources()
setup_settings()
environment_hacks()
import meld.meldapp
......
@define-color insert-bg #d0ffa3;
@define-color insert-outline shade(@insert-bg, 0.8);
@define-color insert-text #008800;
@define-color delete-bg White;
@define-color delete-outline shade(@delete-bg, 0.8);
@define-color delete-text #880000;
@define-color replace-bg #bdddff;
@define-color replace-outline shade(@replace-bg, 0.8);
@define-color replace-text #0044dd;
@define-color conflict-bg #ffa5a3;
@define-color conflict-outline shade(@conflict-bg, 0.8);
@define-color conflict-text #ff0000;
@define-color error-bg #fce94f;
@define-color error-outline shade(@error-bg, 0.8);
@define-color error-text #faad3d;
@define-color inline-bg #8ac2ff;
@define-color unknown-text #888888;
@define-color current-line-highlight #ffff00;
@define-color syncpoint-outline #555555;
@define-color current-chunk-highlight alpha(#ffffff, 0.5);
.meld-notebook-toolbar.toolbar {
background-image: none;
background-color: @theme_base_color;
......
<style-scheme id="meld-base" _name="Meld base scheme" version="1.0">
<author>Kai Willadsen</author>
<_description>Base color scheme for Meld highlighting</_description>
<!-- Meld -->
<style name="meld:insert" background="#d0ffa3" foreground="#008800" line-background="#a5ff4c"/>
<style name="meld:replace" background="#bdddff" foreground="#0044dd" line-background="#65b2ff"/>
<style name="meld:conflict" background="#ffa5a3" foreground="#ff0000" line-background="#ff4f4c"/>
<style name="meld:delete" background="#ffffff" foreground="#880000" line-background="#cccccc"/>
<style name="meld:error" background="#fce94f" foreground="#faad3d" line-background="#fade0a"/>
<style name="meld:inline" background="#8ac2ff"/>
<style name="meld:current-line-highlight" background="#ffff00"/>
<style name="meld:unknown-text" background="#888888"/>
<style name="meld:syncpoint-outline" background="#555555"/>
<style name="meld:current-chunk-highlight" background="rgba(255, 255, 255, 0.5)"/>
</style-scheme>
......@@ -73,8 +73,7 @@ class DiffMap(Gtk.DrawingArea):
def do_style_updated(self, *args):
Gtk.DrawingArea.do_style_updated(self)
style = self.get_style_context()
self.fill_colors, self.line_colors = get_common_theme(style)
self.fill_colors, self.line_colors = get_common_theme()
def on_scrollbar_style_updated(self, scrollbar):
value = GObject.Value(int)
......
......@@ -113,9 +113,7 @@ class GutterRendererChunkAction(GtkSource.GutterRendererPixbuf):
def do_style_updated(self):
# GtkSource.GutterRendererPixbuf.do_style_updated(self)
# FIXME: Should be self.get_view() or something, but when and how?
widget = self.views[0]
style = widget.get_style_context()
self.fill_colors, self.line_colors = get_common_theme(style)
self.fill_colors, self.line_colors = get_common_theme()
def do_draw(self, context, background_area, cell_area, start, end, state):
line = start.get_line()
......
......@@ -56,8 +56,7 @@ class LinkMap(Gtk.DrawingArea):
def do_style_updated(self, *args):
Gtk.DrawingArea.do_style_updated(self)
style = self.get_style_context()
self.fill_colors, self.line_colors = get_common_theme(style)
self.fill_colors, self.line_colors = get_common_theme()
def do_draw(self, context):
if not self.filediff:
......
......@@ -143,28 +143,36 @@ def make_tool_button_widget(label):
return hbox
def colour_lookup_with_fallback(style, name, default):
found, colour = style.lookup_color(name)
if not found:
colour = Gdk.RGBA()
colour.parse(default)
def colour_lookup_with_fallback(source_style, name, attribute, default):
style = source_style.get_style(name)
if style:
style_attr = getattr(style.props, attribute)
if style_attr:
default = style_attr
colour = Gdk.RGBA()
colour.parse(default)
return colour
def get_common_theme(style):
lookup = lambda *args: colour_lookup_with_fallback(style, *args)
def get_common_theme():
# TODO: Everywhere that calls get_common_theme needs to bind to the
# gsettings style-scheme key instead of triggering on style_updated
from meld.settings import meldsettings
source_style = meldsettings.style_scheme
lookup = lambda *args: colour_lookup_with_fallback(source_style, *args)
fill_colours = {
"insert": lookup("insert-bg", "DarkSeaGreen1"),
"delete": lookup("insert-bg", "DarkSeaGreen1"),
"conflict": lookup("conflict-bg", "Pink"),
"replace": lookup("replace-bg", "#ddeeff"),
"current-chunk-highlight": lookup("current-chunk-highlight", '#ffffff')
"insert": lookup("meld:insert", "background", "DarkSeaGreen1"),
"delete": lookup("meld:insert", "background", "DarkSeaGreen1"),
"conflict": lookup("meld:conflict", "background", "Pink"),
"replace": lookup("meld:replace", "background", "#ddeeff"),
"current-chunk-highlight": lookup(
"meld:current-chunk-highlight", "background", '#ffffff')
}
line_colours = {
"insert": lookup("insert-outline", "#77f077"),
"delete": lookup("insert-outline", "#77f077"),
"conflict": lookup("conflict-outline", "#f0768b"),
"replace": lookup("replace-outline", "#8bbff3"),
"insert": lookup("meld:insert", "line-background", "#77f077"),
"delete": lookup("meld:insert", "line-background", "#77f077"),
"conflict": lookup("meld:conflict", "line-background", "#f0768b"),
"replace": lookup("meld:replace", "line-background", "#8bbff3"),
}
return fill_colours, line_colours
......
......@@ -146,16 +146,16 @@ class MeldSourceView(GtkSource.View):
def do_style_updated(self):
GtkSource.View.do_style_updated(self)
style = self.get_style_context()
style = self.get_buffer().get_style_scheme()
self.highlight_color = colour_lookup_with_fallback(
style, "current-line-highlight", "#ffff00")
style, "meld:current-line-highlight", "background", "#ffff00")
self.syncpoint_color = colour_lookup_with_fallback(
style, "syncpoint-outline", "#555555")
self.fill_colors, self.line_colors = get_common_theme(style)
style, "meld:syncpoint-outline", "foreground", "#555555")
self.fill_colors, self.line_colors = get_common_theme()
tag = self.get_buffer().get_tag_table().lookup("inline")
tag.props.background_rgba = colour_lookup_with_fallback(
style, "inline-bg", "LightSteelBlue2")
style, "meld:inline", "background", "LightSteelBlue2")
def do_draw_layer(self, layer, context):
if layer != Gtk.TextViewLayer.BELOW:
......
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