--- a/RefactoringRope/Refactoring.py Thu Sep 14 19:39:11 2017 +0200 +++ b/RefactoringRope/Refactoring.py Fri Sep 15 19:50:07 2017 +0200 @@ -817,6 +817,7 @@ @return flag indicating, that undoable changes are available (boolean) """ + return False return self.__project is not None and \ len(self.__project.history.undo_list) > 0 @@ -826,6 +827,7 @@ @return flag indicating, that redoable changes are available (boolean) """ + return False return self.__project is not None and \ len(self.__project.history.redo_list) > 0 @@ -903,32 +905,30 @@ self.refactoringRedoFileHistoryAct.setEnabled( resource is not None and self.__canRedoFile(resource)) - def handleRopeError(self, err, title, handle=None): - """ - Public slot to handle a rope error. - - @param err rope exception object (Exception) - @param title title to be displayed (string) - @param handle reference to a taskhandle (ProgressHandle) + def __handleRopeError(self, result): """ - if handle is not None: - handle.reset() - ropeError = str(type(err)).split()[-1] - ropeError = ropeError[1:-2].split('.')[-1] - if ropeError == 'ModuleSyntaxError': + Private method to handle a rope error. + + @param result dictionary containing the error information + @type dict + """ + if result["Error"] == 'ModuleSyntaxError': res = E5MessageBox.warning( - self.__ui, title, - self.tr("Rope error: {0}").format(str(err)), + self.__ui, result["Title"], + self.tr("Rope error: {0}").format( + result["ErrorString"]), E5MessageBox.Ok | E5MessageBox.Open) if res == E5MessageBox.Open: e5App().getObject("ViewManager").openSourceFile( os.path.join(self.__e5project.getProjectPath(), - err.filename), - err.lineno) + result["ErrorFile"]), + result["ErrorLine"]) else: E5MessageBox.warning( - self.__ui, title, - self.tr("Rope error: {0}").format(str(err))) + self.__ui, result["Title"], + self.tr("Rope error: {0}").format( + result["ErrorString"]) + ) def __getOffset(self, editor, line, index): r""" @@ -1904,33 +1904,36 @@ line, index = aw.getCursorPosition() offset = self.__getOffset(aw, line, index) - import rope.contrib.findit - from ProgressHandle import ProgressHandle - resource = rope.base.libutils.path_to_resource( - self.__project, filename) - handle = ProgressHandle(title, True, self.__ui) - handle.show() - QApplication.processEvents() - try: - occurrences = rope.contrib.findit.find_occurrences( - self.__project, resource, offset, - unsure=True, in_hierarchy=True, task_handle=handle) - except Exception as err: - self.handleRopeError(err, title, handle) - return - handle.reset() + self.sendJson("QueryReferences", { + "Title": title, + "FileName": filename, + "Offset": offset, + }) + + def __queryReferencesResult(self, result): + """ + Private method to handle the "Query References" result sent by + the client. - if occurrences: - from MatchesDialog import MatchesDialog - self.dlg = MatchesDialog(self.__ui, True) - self.dlg.show() - for occurrence in occurrences: - self.dlg.addEntry( - occurrence.resource, occurrence.lineno, occurrence.unsure) + @param result dictionary containing the result data + @type dict + """ + if "Error" in result: + self.__handleRopeError(result) else: - E5MessageBox.warning( - self.__ui, title, - self.tr("No occurrences found.")) + title = result["Title"] + if result["EntriesCount"] > 0: + from MatchesDialog import MatchesDialog + self.dlg = MatchesDialog(self.__ui, True) + self.dlg.show() + for occurrence in result["Entries"]: + self.dlg.addEntry( + # resource, lineno, unsure + occurrence[0], occurrence[1], occurrence[2]) + else: + E5MessageBox.warning( + self.__ui, title, + self.tr("No occurrences found.")) def __queryDefinition(self): """ @@ -2251,14 +2254,14 @@ self.__projectLanguage = "" # TODO: delete this or move to client - def getProject(self): - """ - Public method to get a reference to the rope project object. - - @return reference to the rope project object (RopeProject) - """ - return self.__project - +## def getProject(self): +## """ +## Public method to get a reference to the rope project object. +## +## @return reference to the rope project object (RopeProject) +## """ +## return self.__project +## def confirmBufferIsSaved(self, editor): """ Public method to check, if an editor has unsaved changes. @@ -2268,7 +2271,7 @@ unsaved edits (boolean) """ res = editor.checkDirty() - self.__project.validate(self.__project.root) + self.sendJson("Validate", {}) return res def confirmAllBuffersSaved(self): @@ -2279,7 +2282,7 @@ (boolean) """ res = e5App().getObject("ViewManager").checkAllDirty() - self.__project.validate(self.__project.root) + self.sendJson("Validate", {}) return res def refreshEditors(self, changes): @@ -2395,6 +2398,9 @@ elif method == "ProgressReset": if self.__progressDialog is not None: self.__progressDialog.reset() + + elif method == "QueryReferencesResult": + self.__queryReferencesResult(params) def __startRefactoringClient(self, interpreter): """