Beispiel #1
0
 def populate(self, offset):
     self.view.empty_list()
     for command in reversed(self.items):
         item = view.DocumentAutocompleteItem(command, offset)
         self.view.prepend(item)
     if len(self.items) > 0:
         self.view.select_first()
Beispiel #2
0
    def update_autocomplete_position(self, can_show=False):
        buffer = self.document.get_buffer()
        if buffer != None:
            self.number_of_matches = 0
            if self.autocomplete_visible == False and can_show == False: return
            insert_iter = buffer.get_iter_at_mark(buffer.get_insert())
            if self.insert_iter_offset == None: self.insert_iter_offset = insert_iter.get_offset()
            if self.insert_iter_offset != insert_iter.get_offset():
                self.insert_iter_offset = insert_iter.get_offset()
                self.current_word = self.get_current_word(insert_iter)
                self.insert_iter_matched = False
                self.view.empty_list()

                items = list()
                try: items = self.static_proposals[self.current_word[1:].lower()]
                except KeyError: pass
                try: items += self.dynamic_proposals[self.current_word[1:].lower()][:5 - len(items)]
                except KeyError: pass
                items.reverse()

                self.number_of_matches = len(items)
                for command in items:
                    item = view.DocumentAutocompleteItem(command)
                    self.view.prepend(item)
                    self.insert_iter_matched = True
                    self.view.select_first()

            if self.insert_iter_matched:
                self.autocomplete_height = self.view.get_allocated_height()
                full_autocomplete_height = 114
                self.autocomplete_width = self.view.get_allocated_width()

                iter_location = self.document_view.source_view.get_iter_location(insert_iter)
                gutter = self.document_view.source_view.get_window(Gtk.TextWindowType.LEFT)
                if gutter != None:
                    gutter_width = gutter.get_width()
                else:
                    gutter_width = 0
                x_offset = - self.document_view.scrolled_window.get_hadjustment().get_value()
                y_offset = - self.document_view.scrolled_window.get_vadjustment().get_value()
                x_position = x_offset + iter_location.x - 4 + gutter_width - len(self.current_word) * self.char_width
                y_position = y_offset + iter_location.y + self.line_height + self.shortcuts_bar_height

                show_x = False
                show_y = False
                if y_position >= self.line_height - 1 + self.shortcuts_bar_height and y_position <= self.document_view.scrolled_window.get_allocated_height() - full_autocomplete_height:
                    self.view.set_margin_top(y_position)
                    show_y = True
                elif y_position >= self.line_height - 1 + self.shortcuts_bar_height and y_position <= self.document_view.scrolled_window.get_allocated_height() + self.shortcuts_bar_height:
                    self.view.set_margin_top(y_position - self.autocomplete_height - self.line_height)
                    show_y = True
                else:
                    show_y = False

                if x_position >= 0 and x_position <= self.main_window.preview_paned.get_allocated_width() - self.autocomplete_width:
                    self.view.set_margin_left(x_position)
                    show_x = True
                elif x_position >= 0 and x_position <= self.main_window.preview_paned.get_allocated_width():
                    self.view.set_margin_left(x_position - self.autocomplete_width)
                    show_x = True
                else:
                    show_x = False

                if show_x and show_y:
                    self.view.show_all()
                    self.autocomplete_visible = True
                else:
                    self.view.hide()
                    self.autocomplete_visible = False
            else:
                self.view.hide()
                self.autocomplete_visible = False