From f94c64d3693ead5ff4dcbb3340ac3faa930a6cce Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 7 May 2015 11:30:14 -0600 Subject: [PATCH] add parameters for line numbers and tab width --- gui/params.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++-- gui/source.py | 10 ++++++ gui/storage.py | 10 ++++++ gui/toplevel.py | 28 +++++++++++++++++ 4 files changed, 126 insertions(+), 3 deletions(-) diff --git a/gui/params.py b/gui/params.py index 4cc59cf..1cb0b41 100644 --- a/gui/params.py +++ b/gui/params.py @@ -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() diff --git a/gui/source.py b/gui/source.py index 14966cf..f849b4f 100644 --- a/gui/source.py +++ b/gui/source.py @@ -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) diff --git a/gui/storage.py b/gui/storage.py index 3bb119a..12cdb14 100644 --- a/gui/storage.py +++ b/gui/storage.py @@ -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) diff --git a/gui/toplevel.py b/gui/toplevel.py index d026b07..b5c9d3a 100644 --- a/gui/toplevel.py +++ b/gui/toplevel.py @@ -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