def __on_document_changed(self, document, userData=None): # make sure the php-file-index gets updated when the text get changed if document.get_location() != None: AddiksPhpIndexApp.get().update_info_window(self) filepath = document.get_location().get_path() self.invalidate_php_fileindex(filepath) return False
def __do_fill_info_widget(self, sourceBuffer, infoLabel, proposal, labelText): if len(labelText) > 0: infoLabel.set_text(labelText) sourceBuffer.set_text(labelText) decType = proposal.get_type() decName = proposal.get_word() containingClass = proposal.get_additional_info() AddiksPhpIndexApp.get().update_info_window(self.__pluginView, (decType, decName, containingClass))
def do_activate(self): AddiksPhpIndexApp.get().register_view(self) completion = self.view.get_completion() provider = self.get_completion_provider() if provider not in completion.get_providers(): completion.add_provider(provider) self.view.connect("move-cursor", self.on_textview_move_cursor) self.view.connect("button-press-event", self.on_textview_move_cursor) # self.view.connect("key-press-event", self.on_textview_move_cursor) document = self.view.get_buffer() document.connect("changed", self.__on_document_changed) document.connect("insert-text", self.__on_document_insert) document.connect("saved", self.__on_document_saved)
def on_index_paths_manager(self, action, data=None): if self.get_index_path_manager() != None: window = self.getGladeBuilder().get_object("windowIndexPathsManager") window.show_all() else: window = AddiksPhpIndexApp.get().get_window_by_view(self).window dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE, "Not a git project!") dialog.format_secondary_text("The index-include/-exclude path'scan only be configured for files in a git workspace.") dialog.run()
def __fill_info_widget(self, sourceBuffer, infoLabel, proposal): storage = self.__pluginView.get_index_storage() decType = proposal.get_type() decName = proposal.get_word() containingClass = proposal.get_additional_info() labelText = AddiksPhpIndexApp.get().build_info_text(storage, decType, decName, containingClass) GLib.idle_add(self.__do_fill_info_widget, sourceBuffer, infoLabel, proposal, labelText)
def __on_document_insert(self, document, textIter, insertedText, length, userData=None): if document.get_location() != None and insertedText in ['\n', ';', '=', '}']: line = textIter.get_line() column = textIter.get_line_offset() lineBeginIter = document.get_iter_at_line_index(line, 0) codeLine = document.get_text(lineBeginIter, document.get_iter_at_line_index(line+1, 0), True) indention = "" while len(codeLine) > len(indention) and column > len(indention) and codeLine[len(indention)] in [" ", "\t", "*"]: indention += codeLine[len(indention)] if insertedText in [';', '=', '}']: code = document.get_text(document.get_start_iter(), document.get_end_iter(), True) analyzer = PhpFileAnalyzer(code, self, self.get_index_storage()) tokens = analyzer.get_tokens() tokenIndex = analyzer.get_token_index_by_position(textIter.get_line()+1, textIter.get_line_offset()+1) isInMethod = analyzer.is_in_method(tokenIndex) if insertedText == ';' and tokenIndex != None: # finished writing a statement? declarationType, declaredName, className = analyzer.get_declaration_by_token_index(tokenIndex) if declarationType == 'member' and tokens[tokenIndex][1] == declaredName and not isInMethod: # finished a member, add a doc-comment for that tokenIndexComment = analyzer.get_token_index_by_position(line+1, 0) if tokens[tokenIndexComment][0] not in [T_COMMENT, T_DOC_COMMENT]: commentCode = indention + "/**\n" commentCode += indention + " * @var mixed\n" commentCode += indention + " */\n" GLib.idle_add(self.do_textbuffer_insert, document, line, 0, commentCode) if insertedText == '=' and tokenIndex != None: # writing a new variable? if tokens[tokenIndex][0] == T_VARIABLE and tokens[tokenIndex-1][1] in [';', '{']: methodBlock = analyzer.get_method_block_is_in(tokenIndex) if methodBlock != None: variableName = tokens[tokenIndex][1] isFirstUsage = True for token in tokens[methodBlock[0]:tokenIndex]: if token[0] == T_VARIABLE and token[1] == variableName: isFirstUsage = False break if isFirstUsage: # added a new variable, add a doc-comment for that commentCode = indention + "/* @var " + variableName + " mixed */\n" GLib.idle_add(self.do_textbuffer_insert, document, line, 0, commentCode) if insertedText in [';', '}']: # finished writing a method, class or function? # print(code) # TODO pass if insertedText == '\n': # new line, add indention GLib.idle_add(self.do_textbuffer_insert, document, line+1, 0, indention) AddiksPhpIndexApp.get().update_info_window(self)
def do_deactivate(self): AddiksPhpIndexApp.get().unregister_view(self)
def on_index_not_build(self): window = AddiksPhpIndexApp.get().get_window_by_view(self).window dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE, "Build index first!") dialog.format_secondary_text("To perform this action, you first need to build the index for this working directory.") dialog.run() return False
def on_textview_move_cursor(self, textView=None, step=None, count=None, extendSelection=None, userData=None): GLib.idle_add(AddiksPhpIndexApp.get().update_info_window, self)
def on_show_info_window(self, action, data=None): if not self.is_index_built(): return self.on_index_not_build() AddiksPhpIndexApp.get().show_info_window(self)
def get_settings(self): return AddiksPhpIndexApp.get().get_settings()