Skip to content

Commit 6d38d8c

Browse files
committed
gutterrendererchunk: Refactor some ugliness and create new consts module
1 parent 47146d8 commit 6d38d8c

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

meld/const.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# Chunk action mode, set by filediff and used in gutterrendererchunk
3+
MODE_REPLACE = 0
4+
MODE_DELETE = 1
5+
MODE_INSERT = 2

meld/filediff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from .ui import findbar
4646
from .ui import gnomeglade
4747

48+
from meld.const import MODE_REPLACE, MODE_DELETE, MODE_INSERT
4849
from meld.settings import meldsettings, settings
4950
from .util.compat import text_type
5051
from meld.sourceview import LanguageManager
@@ -103,7 +104,6 @@ def clean(self, size_hint):
103104

104105

105106
MASK_SHIFT, MASK_CTRL = 1, 2
106-
MODE_REPLACE, MODE_DELETE, MODE_INSERT = 0, 1, 2
107107

108108

109109
class CursorDetails(object):

meld/gutterrendererchunk.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2013 Kai Willadsen <kai.willadsen@gmail.com>
1+
# Copyright (C) 2013-2014 Kai Willadsen <kai.willadsen@gmail.com>
22
#
33
# This program is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -17,34 +17,32 @@
1717
from gi.repository import GtkSource
1818

1919
from meld.conf import _
20+
from meld.const import MODE_REPLACE, MODE_DELETE, MODE_INSERT
2021

22+
# Fixed size of the renderer. Ideally this would be font-dependent and
23+
# would adjust to other textview attributes, but that's both quite difficult
24+
# and not necessarily desirable.
25+
LINE_HEIGHT = 16
2126

22-
# FIXME: This is obviously beyond horrible
23-
line_height = 16
24-
icon_theme = Gtk.IconTheme.get_default()
25-
load = lambda x: icon_theme.load_icon(x, line_height, 0)
26-
pixbuf_apply0 = load("meld-change-apply-right")
27-
pixbuf_apply1 = load("meld-change-apply-left")
28-
pixbuf_delete = load("meld-change-delete")
29-
pixbuf_copy = load("meld-change-copy")
3027

31-
# FIXME: import order issues
32-
MODE_REPLACE, MODE_DELETE, MODE_INSERT = 0, 1, 2
28+
def load(icon_name):
29+
icon_theme = Gtk.IconTheme.get_default()
30+
return icon_theme.load_icon(icon_name, LINE_HEIGHT, 0)
3331

3432

3533
class GutterRendererChunkAction(GtkSource.GutterRendererPixbuf):
3634
__gtype_name__ = "GutterRendererChunkAction"
3735

3836
ACTION_MAP = {
3937
'LTR': {
40-
MODE_REPLACE: pixbuf_apply0,
41-
MODE_DELETE: pixbuf_delete,
42-
MODE_INSERT: pixbuf_copy,
38+
MODE_REPLACE: load("meld-change-apply-right"),
39+
MODE_DELETE: load("meld-change-delete"),
40+
MODE_INSERT: load("meld-change-copy"),
4341
},
4442
'RTL': {
45-
MODE_REPLACE: pixbuf_apply1,
46-
MODE_DELETE: pixbuf_delete,
47-
MODE_INSERT: pixbuf_copy,
43+
MODE_REPLACE: load("meld-change-apply-left"),
44+
MODE_DELETE: load("meld-change-delete"),
45+
MODE_INSERT: load("meld-change-copy"),
4846
}
4947
}
5048

@@ -58,7 +56,7 @@ def __init__(self, from_pane, to_pane, views, filediff, linediffer):
5856
# FIXME: Don't pass in the linediffer; pass a generator like elsewhere
5957
self.linediffer = linediffer
6058
self.mode = MODE_REPLACE
61-
self.set_size(line_height)
59+
self.set_size(LINE_HEIGHT)
6260
direction = 'LTR' if from_pane < to_pane else 'RTL'
6361
self.action_map = self.ACTION_MAP[direction]
6462
self.filediff = filediff

0 commit comments

Comments
 (0)