Skip to content

Commit 255a8da

Browse files
committed
preferences: Update syntax scheme preference to use combo helper
1 parent 13544e8 commit 255a8da

2 files changed

Lines changed: 27 additions & 21 deletions

File tree

data/ui/preferences.ui

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
<property name="step_increment">1</property>
1616
<property name="page_increment">10</property>
1717
</object>
18+
<object class="GtkListStore" id="syntaxschemestore">
19+
<columns>
20+
<!-- column-name id -->
21+
<column type="gchararray"/>
22+
<!-- column-name name -->
23+
<column type="gchararray"/>
24+
</columns>
25+
</object>
1826
<object class="GtkListStore" id="fileorderstore">
1927
<columns>
2028
<!-- column-name id -->
@@ -494,9 +502,17 @@
494502
</packing>
495503
</child>
496504
<child>
497-
<object class="GtkComboBox" id="combobox_style_scheme">
505+
<object class="GSettingsStringComboBox" id="combobox_style_scheme">
498506
<property name="visible">True</property>
499507
<property name="can_focus">False</property>
508+
<property name="model">syntaxschemestore</property>
509+
<property name="gsettings-column">0</property>
510+
<child>
511+
<object class="GtkCellRendererText" id="syntax_scheme_renderer"/>
512+
<attributes>
513+
<attribute name="text">1</attribute>
514+
</attributes>
515+
</child>
500516
</object>
501517
<packing>
502518
<property name="expand">True</property>

meld/preferences.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ def _setting_changed(self, obj, val):
145145
self.set_property('active', idx)
146146

147147
def _active_changed(self, obj, val):
148+
active_iter = self.get_active_iter()
149+
if active_iter is None:
150+
return
148151
column = self.get_property('gsettings-column')
149-
value = self.get_model()[self.get_active_iter()][column]
152+
value = self.get_model()[active_iter][column]
150153
self.set_property('gsettings-value', value)
151154

152155

@@ -181,7 +184,8 @@ def __init__(self, parent):
181184
["adjustment1", "adjustment2", "fileorderstore",
182185
"sizegroup_editor", "timestampstore",
183186
"mergeorderstore", "sizegroup_file_order_labels",
184-
"sizegroup_file_order_combos"])
187+
"sizegroup_file_order_combos",
188+
'syntaxschemestore'])
185189
self.widget.set_transient_for(parent)
186190

187191
bindings = [
@@ -241,28 +245,14 @@ def __init__(self, parent):
241245
self.combo_merge_order.bind_to('vc-merge-file-order')
242246

243247
# Fill color schemes
244-
liststore = Gtk.ListStore(str)
245248
manager = GtkSource.StyleSchemeManager.get_default()
246-
scheme_ids = GtkSource.StyleSchemeManager.get_scheme_ids(manager)
247-
for scheme in scheme_ids:
248-
liststore.append([scheme])
249-
self.combobox_style_scheme.set_model(liststore)
250-
cell = Gtk.CellRendererText()
251-
self.combobox_style_scheme.pack_start(cell, True)
252-
self.combobox_style_scheme.add_attribute(cell, 'text',0)
253-
254-
style_scheme = settings.get_string('style-scheme')
255-
for idx,scheme in enumerate(scheme_ids):
256-
if scheme == style_scheme:
257-
self.combobox_style_scheme.set_active(idx)
258-
259-
self.combobox_style_scheme.connect("changed", self.on_combobox_style_scheme_changed)
249+
for scheme_id in manager.get_scheme_ids():
250+
scheme = manager.get_scheme(scheme_id)
251+
self.syntaxschemestore.append([scheme_id, scheme.get_name()])
252+
self.combobox_style_scheme.bind_to('style-scheme')
260253

261254
self.widget.show()
262255

263-
def on_combobox_style_scheme_changed(self, combobox):
264-
settings.set_string('style-scheme', combobox.get_model()[combobox.get_active()][0])
265-
266256
def on_checkbutton_wrap_text_toggled(self, button):
267257
if not self.checkbutton_wrap_text.get_active():
268258
wrap_mode = Gtk.WrapMode.NONE

0 commit comments

Comments
 (0)