From The Compiler, 5 Years ago, written in Diff-output.
Embed
  1. diff --git a/qutebrowser/utils/completer.py b/qutebrowser/utils/completer.py
  2. index 510ad3c..5085e62 100644
  3. --- a/qutebrowser/utils/completer.py
  4. +++ b/qutebrowser/utils/completer.py
  5. @@ -55,13 +55,13 @@ class Completer(QObject):
  6.          self._win_id = win_id
  7.          self._ignore_change = False
  8.  
  9. -        self.models = {
  10. +        self._models = {
  11.              usertypes.Completion.option: {},
  12.              usertypes.Completion.value: {},
  13.          }
  14.          self._init_static_completions()
  15.          self._init_setting_completions()
  16. -        self._init_quickmark_completions()
  17. +        self.init_quickmark_completions()
  18.  
  19.      def __repr__(self):
  20.          return utils.get_repr(self)
  21. @@ -74,30 +74,35 @@ class Completer(QObject):
  22.  
  23.      def _init_static_completions(self):
  24.          """Initialize the static completion models."""
  25. -        self.models[usertypes.Completion.command] = CFM(
  26. +        self._models[usertypes.Completion.command] = CFM(
  27.              models.CommandCompletionModel(self), self)
  28. -        self.models[usertypes.Completion.helptopic] = CFM(
  29. +        self._models[usertypes.Completion.helptopic] = CFM(
  30.              models.HelpCompletionModel(self), self)
  31.  
  32.      def _init_setting_completions(self):
  33.          """Initialize setting completion models."""
  34. -        self.models[usertypes.Completion.section] = CFM(
  35. +        self._models[usertypes.Completion.section] = CFM(
  36.              models.SettingSectionCompletionModel(self), self)
  37. -        self.models[usertypes.Completion.option] = {}
  38. -        self.models[usertypes.Completion.value] = {}
  39. +        self._models[usertypes.Completion.option] = {}
  40. +        self._models[usertypes.Completion.value] = {}
  41.          for sectname in configdata.DATA:
  42.              model = models.SettingOptionCompletionModel(sectname, self)
  43. -            self.models[usertypes.Completion.option][sectname] = CFM(
  44. +            self._models[usertypes.Completion.option][sectname] = CFM(
  45.                  model, self)
  46. -            self.models[usertypes.Completion.value][sectname] = {}
  47. +            self._models[usertypes.Completion.value][sectname] = {}
  48.              for opt in configdata.DATA[sectname].keys():
  49.                  model = models.SettingValueCompletionModel(sectname, opt, self)
  50. -                self.models[usertypes.Completion.value][sectname][opt] = CFM(
  51. +                self._models[usertypes.Completion.value][sectname][opt] = CFM(
  52.                      model, self)
  53.  
  54. -    def _init_quickmark_completions(self):
  55. +    @pyqtSlot()
  56. +    def init_quickmark_completions(self):
  57.          """Initialize quickmark completion models."""
  58. -        self.models[usertypes.Completion.quickmark] = CFM(
  59. +        try:
  60. +            self._models[usertypes.Completion.quickmark].deleteLater()
  61. +        except KeyError:
  62. +            pass
  63. +        self._models[usertypes.Completion.quickmark] = CFM(
  64.              models.QuickmarkCompletionModel(self), self)
  65.  
  66.      def _get_new_completion(self, parts, cursor_part):
  67. @@ -109,7 +114,7 @@ class Completer(QObject):
  68.          """
  69.          if cursor_part == 0:
  70.              # '|' or 'set|'
  71. -            return self.models[usertypes.Completion.command]
  72. +            return self._models[usertypes.Completion.command]
  73.          # delegate completion to command
  74.          try:
  75.              completions = cmdutils.cmd_dict[parts[0]].completion
  76. @@ -133,17 +138,17 @@ class Completer(QObject):
  77.              ', '.join(dbg_completions)))
  78.          if completion == usertypes.Completion.option:
  79.              section = parts[cursor_part - 1]
  80. -            model = self.models[completion].get(section)
  81. +            model = self._models[completion].get(section)
  82.          elif completion == usertypes.Completion.value:
  83.              section = parts[cursor_part - 2]
  84.              option = parts[cursor_part - 1]
  85.              try:
  86. -                model = self.models[completion][section][option]
  87. +                model = self._models[completion][section][option]
  88.              except KeyError:
  89.                  # No completion model for this section/option.
  90.                  model = None
  91.          else:
  92. -            model = self.models.get(completion)
  93. +            model = self._models.get(completion)
  94.          return model
  95.  
  96.      def _quote(self, s):
  97. @@ -186,11 +191,6 @@ class Completer(QObject):
  98.              self._ignore_change = True
  99.              self.change_completed_part.emit(data, False)
  100.  
  101. -    @pyqtSlot()
  102. -    def on_quickmarks_changed(self):
  103. -        self.clear()
  104. -        self._init_quickmark_completions()
  105. -
  106.      @pyqtSlot(str, list, int)
  107.      def on_update_completion(self, prefix, parts, cursor_part):
  108.          """Schedule updating/enabling completion.
  109. diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py
  110. index 6138095..317743e 100644
  111. --- a/qutebrowser/widgets/mainwindow.py
  112. +++ b/qutebrowser/widgets/mainwindow.py
  113. @@ -119,10 +119,6 @@ class MainWindow(QWidget):
  114.          config.on_change(self.resize_completion, 'completion', 'height')
  115.          config.on_change(self.resize_completion, 'completion', 'shrink')
  116.  
  117. -        quickmark_model = self._get_object('completer').models[usertypes.Completion.quickmark]
  118. -        quickmark_manager = objreg.get('quickmark-manager')
  119. -        quickmark_manager.changed.connect(quickmark_model.srcmodel.on_quickmarks_changed)
  120. -
  121.          #self.retranslateUi(MainWindow)
  122.          #self.tabWidget.setCurrentIndex(0)
  123.          #QtCore.QMetaObject.connectSlotsByName(MainWindow)
  124. @@ -264,6 +260,12 @@ class MainWindow(QWidget):
  125.          # downloads
  126.          tabs.start_download.connect(download_manager.fetch)
  127.  
  128. +        # quickmark completion
  129. +        completer = self._get_object('completer')
  130. +        quickmark_manager = objreg.get('quickmark-manager')
  131. +        quickmark_manager.changed.connect(completer.init_quickmark_completions)
  132. +
  133. +
  134.      @pyqtSlot()
  135.      def resize_completion(self):
  136.          """Adjust completion according to config."""
  137.  

Replies to completion diff #2 rss

Title Name Language When
Re: completion diff #2 The Compiler diff 5 Years ago.