The beginnings of a layout editor

This commit is contained in:
Chris Jones 2010-01-30 00:27:57 +00:00
parent 061aef9fd8
commit 0501ceb8d4
3 changed files with 116 additions and 2 deletions

View File

@ -206,6 +206,7 @@ DEFAULTS = {
}, },
}, },
'layouts': { 'layouts': {
'default': {'type': 'Terminal'}
}, },
'plugins': { 'plugins': {
}, },
@ -265,6 +266,25 @@ class Config(object):
"""List all configured profiles""" """List all configured profiles"""
return(self.base.profiles.keys()) return(self.base.profiles.keys())
def add_layout(self, layout):
"""Add a new layout"""
return(self.base.add_layout(layout))
def del_layout(self, layout):
"""Delete a layout"""
if self.base.layouts.has_key(layout):
del(self.base.layouts[layout])
def rename_layout(self, layout, newname):
"""Rename a layout"""
if self.base.layouts.has_key(layout):
self.base.layouts[newname] = self.base.layouts[layout]
del(self.base.layouts[layout])
def list_layouts(self):
"""List all configured layouts"""
return(self.base.layouts.keys())
def get_system_font(self): def get_system_font(self):
"""Look up the system font""" """Look up the system font"""
if 'gconf' not in globals(): if 'gconf' not in globals():
@ -547,3 +567,10 @@ class ConfigBase(Borg):
self.profiles[profile] = copy(DEFAULTS['profiles']['default']) self.profiles[profile] = copy(DEFAULTS['profiles']['default'])
return(True) return(True)
def add_layout(self, layout):
"""Add a new layout"""
if layout in self.layouts:
return(False)
self.layouts[layout] = {'type': 'Terminal'}
return(True)

View File

@ -2063,7 +2063,7 @@
<child> <child>
<object class="GtkCellRendererText" id="cellrenderertext12"> <object class="GtkCellRendererText" id="cellrenderertext12">
<property name="editable">True</property> <property name="editable">True</property>
<signal name="edited" handler="on_profilename_edited"/> <signal name="edited" handler="on_layout_name_edited"/>
</object> </object>
<attributes> <attributes>
<attribute name="text">0</attribute> <attribute name="text">0</attribute>

View File

@ -184,7 +184,15 @@ class PrefsEditor:
selection.select_iter(self.profileiters['default']) selection.select_iter(self.profileiters['default'])
## Layouts tab ## Layouts tab
# FIXME: Implement this widget = guiget('layoutlist')
liststore = widget.get_model()
layouts = self.config.list_layouts()
self.layoutiters = {}
for layout in layouts:
self.layoutiters[layout] = liststore.append([layout])
selection = widget.get_selection()
selection.connect('changed', self.on_layout_selection_changed)
selection.select_iter(self.layoutiters['default'])
## Keybindings tab ## Keybindings tab
widget = guiget('keybindingtreeview') widget = guiget('keybindingtreeview')
@ -599,6 +607,10 @@ class PrefsEditor:
value = 'escape-sequence' value = 'escape-sequence'
self.config['delete_binding'] = value self.config['delete_binding'] = value
def store_layout(self, layout):
"""Store a layout"""
pass
def on_profileaddbutton_clicked(self, _button): def on_profileaddbutton_clicked(self, _button):
"""Add a new profile to the list""" """Add a new profile to the list"""
guiget = self.builder.get_object guiget = self.builder.get_object
@ -635,6 +647,42 @@ class PrefsEditor:
model.remove(rowiter) model.remove(rowiter)
selection.select_iter(model.get_iter_first()) selection.select_iter(model.get_iter_first())
def on_layoutaddbutton_clicked(self, _button):
"""Add a new layout to the list"""
guiget = self.builder.get_object
treeview = guiget('layoutlist')
model = treeview.get_model()
values = [ r[0] for r in model ]
newlayout = _('New Layout')
if newlayout in values:
i = 1
while newlayout in values:
i = i + 1
newlayout = '%s %d' % (_('New Layout'), i)
if self.config.add_layout(newlayout):
model.append([newlayout])
def on_layoutremovebutton_clicked(self, _button):
"""Remove a layout from the list"""
guiget = self.builder.get_object
treeview = guiget('layoutlist')
selection = treeview.get_selection()
(model, rowiter) = selection.get_selected()
layout = model.get_value(rowiter, 0)
if layout == 'default':
# We shouldn't let people delete this layout
return
self.previous_sekection = None
self.config.del_layout(layout)
model.remove(rowiter)
selection.select_iter(model.get_iter_first())
def on_use_custom_command_checkbutton_toggled(self, checkbox): def on_use_custom_command_checkbutton_toggled(self, checkbox):
"""Toggling the use_custom_command checkbox needs to alter the """Toggling the use_custom_command checkbox needs to alter the
sensitivity of the custom_command entrybox""" sensitivity of the custom_command entrybox"""
@ -737,6 +785,45 @@ class PrefsEditor:
if oldname == self.previous_selection: if oldname == self.previous_selection:
self.previous_selection = newtext self.previous_selection = newtext
def on_layout_selection_changed(self, selection):
"""A different layout was selected"""
if self.previous_selection is not None:
dbg('Storing: %s' % self.previous_selection)
self.store_layout(self.previous_selection)
(listmodel, rowiter) = selection.get_selected()
if not rowiter:
# Something is wrong, just jump to the first item in the list
treeview = selection.get_tree_view()
liststore = treeview.get_model()
selection.select_iter(liststore.get_iter_first())
return
layout = listmodel.get_value(rowiter, 0)
self.set_profile_values(layout)
self.previous_selection = layout
widget = self.builder.get_object('layoutremovebutton')
if layout == 'default':
widget.set_sensitive(False)
else:
widget.set_sensitive(True)
def on_layout_name_edited(self, cell, path, newtext):
"""Update a layout name"""
oldname = cell.get_property('text')
if oldname == newtext:
return
dbg('Changing %s to %s' % (oldname, newtext))
self.config.rename_layout(oldname, newtext)
widget = self.builder.get_object('layoutlist')
model = widget.get_model()
itera = model.get_iter(path)
model.set_value(itera, 0, newtext)
if oldname == self.previous_selection:
self.previous_selection = newtext
def on_color_scheme_combobox_changed(self, widget): def on_color_scheme_combobox_changed(self, widget):
"""Update the fore/background colour pickers""" """Update the fore/background colour pickers"""
value = None value = None