add parameters for line numbers and tab width

This commit is contained in:
Tom Tromey
2015-05-07 11:30:14 -06:00
parent 7956c96cae
commit f94c64d369
4 changed files with 126 additions and 3 deletions

View File

@@ -57,12 +57,20 @@ class _ShowTitleBase(gdb.Command):
class _StoredParameter(gdb.Parameter):
# NAME_FORMAT is like "%s" - NAME is substituted.
# To construct the parameter name, "gui " is prefixed.
def __init__(self, name_format, name, default, *args):
def __init__(self, name_format, name, default, c_class, p_kind, *args):
full_name = 'gui ' + name_format % name
self.storage_name = '-'.join((name_format % name).split(' '))
storage = gui.storage.storage_manager
super(_StoredParameter, self).__init__(full_name, *args)
val = storage.get(self.storage_name)
super(_StoredParameter, self).__init__(full_name, c_class, p_kind,
*args)
if p_kind is gdb.PARAM_BOOLEAN:
val = storage.getboolean(self.storage_name)
elif p_kind is gdb.PARAM_STRING or p_kind is gdb.PARAM_ENUM:
val = storage.get(self.storage_name)
elif p_kind is gdb.PARAM_ZINTEGER:
val = storage.getint(self.storage_name)
else:
raise "WHOOPS"
# Don't record the first setting.
self.storage = None
if val is None:
@@ -189,6 +197,71 @@ class _Missing(_StoredParameter):
v = "off"
return "Whether to warn about missing gdb features: " + v
class _Lines(_StoredParameter):
# Silly gdb requirement.
""
set_doc = "Set whether to display line numbers in the source window."
show_doc = "Show whether to display line numbers in the source window."
def __init__(self):
super(_Lines, self).__init__('%s', 'line-numbers', False,
gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)
@in_gdb_thread
def get_show_string(self, pvalue):
return "The current title format for the %s is: %s" % (self.name,
self.value)
@in_gdb_thread
def get_set_string(self):
super(_Lines, self).get_set_string()
gui.toplevel.state.set_line_numbers(self.value)
return ""
class _Lines(_StoredParameter):
# Silly gdb requirement.
""
set_doc = "Set whether to display line numbers in the source window."
show_doc = "Show whether to display line numbers in the source window."
def __init__(self):
super(_Lines, self).__init__('%s', 'line-numbers', False,
gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)
@in_gdb_thread
def get_show_string(self, pvalue):
return "Whether to display line numbers in the source window is: %s" % self.value
@in_gdb_thread
def get_set_string(self):
super(_Lines, self).get_set_string()
gui.toplevel.state.set_line_numbers(self.value)
return ""
class _Tabs(_StoredParameter):
# Silly gdb requirement.
""
set_doc = "Set width of tabs in the source window."
show_doc = "Show width of tabs in the source window."
def __init__(self):
super(_Tabs, self).__init__('%s', 'tab-width', 8,
gdb.COMMAND_NONE, gdb.PARAM_ZINTEGER)
@in_gdb_thread
def get_show_string(self, pvalue):
return "The tab width in the source window is: %d" % self.value
@in_gdb_thread
def get_set_string(self):
super(_Tabs, self).get_set_string()
gui.toplevel.state.set_tab_width(self.value)
return ""
_SetBase()
_SetTitleBase()
_ShowBase()
@@ -201,3 +274,5 @@ _Title('display', '\\W{command} [GDB Display @\\W{number}]')
_Title('log', '[GDB Log @\\W{number}]\\W{default}')
warn_missing = _Missing()
line_numbers = _Lines()
tab_width = _Tabs()

View File

@@ -224,6 +224,8 @@ class SourceWindow(gui.updatewindow.UpdateWindow):
self.buttons[name] = builder.get_object(name)
self.view.modify_font(gui.params.font_manager.get_font())
self.view.set_show_line_numbers(gui.params.line_numbers.value)
self.view.set_tab_width(gui.params.tab_width.value)
attrs = GtkSource.MarkAttributes()
# FIXME: really we want a little green dot...
@@ -294,3 +296,11 @@ class SourceWindow(gui.updatewindow.UpdateWindow):
@in_gtk_thread
def set_font(self, pango_font):
self.view.modify_font(pango_font)
@in_gtk_thread
def set_line_numbers(self, want_lines):
self.view.set_show_line_numbers(want_lines)
@in_gtk_thread
def set_tab_width(self, width):
self.view.set_tab_width(width)

View File

@@ -42,6 +42,16 @@ class StorageManager:
return self.config.get('general', name)
return None
def getboolean(self, name):
if self.config.has_option('general', name):
return self.config.getboolean('general', name)
return None
def getint(self, name):
if self.config.has_option('general', name):
return self.config.getint('general', name)
return None
def set(self, name, value):
self.config.set('general', name, value)

View File

@@ -83,6 +83,26 @@ class _ToplevelState(object):
def update_titles(self):
gui.startup.send_to_gtk(lambda: self._do_update_titles)
@in_gtk_thread
def _do_set_line_numbers(self, want_lines):
with self.toplevel_lock:
for num in self.toplevels:
self.toplevels[num].set_line_numbers(want_lines)
@in_gdb_thread
def set_line_numbers(self, want_lines):
gui.startup.send_to_gtk(lambda: self._do_set_line_numbers(want_lines))
@in_gtk_thread
def _do_set_tab_width(self, width):
with self.toplevel_lock:
for num in self.toplevels:
self.toplevels[num].set_title(width)
@in_gdb_thread
def set_tab_width(self, width):
gui.startup.send_to_gtk(lambda: self._do_set_tab_width(width))
@in_gtk_thread
def windows(self):
return self.toplevels.values()
@@ -115,3 +135,11 @@ class Toplevel(object):
fmt = gui.params.title_params[self.window_type].value
title = gui.gdbutil.substitute_prompt_with_window(fmt, self)
self.window.set_title(title)
@in_gtk_thread
def set_line_numbers(self, want_lines):
pass
@in_gtk_thread
def set_tab_width(self, width):
pass