48 super(RefactoringServer, self).__init__( |
48 super(RefactoringServer, self).__init__( |
49 "RefactoringServer", parent=parent) |
49 "RefactoringServer", parent=parent) |
50 |
50 |
51 self.__plugin = plugin |
51 self.__plugin = plugin |
52 self.__ui = parent |
52 self.__ui = parent |
|
53 self.__vm = e5App().getObject("ViewManager") |
53 self.__e5project = e5App().getObject("Project") |
54 self.__e5project = e5App().getObject("Project") |
54 self.__projectpath = '' |
55 self.__projectpath = '' |
55 self.__projectLanguage = "" |
56 self.__projectLanguage = "" |
56 self.__projectopen = False |
57 self.__projectopen = False |
57 self.__ropeConfig = {} |
58 self.__ropeConfig = {} |
828 |
829 |
829 def __showRefactoringHistoryMenu(self): |
830 def __showRefactoringHistoryMenu(self): |
830 """ |
831 """ |
831 Private slot called before the refactoring history menu is shown. |
832 Private slot called before the refactoring history menu is shown. |
832 """ |
833 """ |
833 aw = e5App().getObject("ViewManager").activeWindow() |
834 aw = self.__vm.activeWindow() |
834 enable = aw is not None and bool(aw.getFileName()) |
835 enable = aw is not None and bool(aw.getFileName()) |
835 |
836 |
836 self.refactoringFileHistoryAct.setEnabled(enable) |
837 self.refactoringFileHistoryAct.setEnabled(enable) |
837 |
838 |
838 def handleRopeError(self, result): |
839 def handleRopeError(self, result): |
857 self.__ui, title, |
858 self.__ui, title, |
858 self.tr("Rope error: {0}").format( |
859 self.tr("Rope error: {0}").format( |
859 result["ErrorString"]), |
860 result["ErrorString"]), |
860 E5MessageBox.Ok | E5MessageBox.Open) |
861 E5MessageBox.Ok | E5MessageBox.Open) |
861 if res == E5MessageBox.Open: |
862 if res == E5MessageBox.Open: |
862 e5App().getObject("ViewManager").openSourceFile( |
863 self.__vm.openSourceFile( |
863 os.path.join(self.__e5project.getProjectPath(), |
864 os.path.join(self.__e5project.getProjectPath(), |
864 result["ErrorFile"]), |
865 result["ErrorFile"]), |
865 result["ErrorLine"]) |
866 result["ErrorLine"]) |
866 elif result["Error"] == "InterruptedTaskError": |
867 elif result["Error"] == "InterruptedTaskError": |
867 return True |
868 return True |
1072 @param kind kind of extraction to be done |
1073 @param kind kind of extraction to be done |
1073 @type str ("method" or "variable") |
1074 @type str ("method" or "variable") |
1074 """ |
1075 """ |
1075 assert kind in ["variable", "method"] |
1076 assert kind in ["variable", "method"] |
1076 |
1077 |
1077 aw = e5App().getObject("ViewManager").activeWindow() |
1078 aw = self.__vm.activeWindow() |
1078 |
1079 |
1079 if aw is None: |
1080 if aw is None: |
1080 return |
1081 return |
1081 |
1082 |
1082 if not aw.hasSelectedText(): |
1083 if not aw.hasSelectedText(): |
1150 Private slot to handle the Move Method action. |
1151 Private slot to handle the Move Method action. |
1151 |
1152 |
1152 @param moveKind kind of move to be performed |
1153 @param moveKind kind of move to be performed |
1153 @type str (one of 'move_method' or 'move_module') |
1154 @type str (one of 'move_method' or 'move_module') |
1154 """ |
1155 """ |
1155 aw = e5App().getObject("ViewManager").activeWindow() |
1156 aw = self.__vm.activeWindow() |
1156 |
1157 |
1157 if aw is None: |
1158 if aw is None: |
1158 return |
1159 return |
1159 |
1160 |
1160 if moveKind == "move_method": |
1161 if moveKind == "move_method": |
1753 Note: This is executed upon a mouse click sequence. |
1754 Note: This is executed upon a mouse click sequence. |
1754 |
1755 |
1755 @param editor reference to the calling editor |
1756 @param editor reference to the calling editor |
1756 @type QScintilla.Editor |
1757 @type QScintilla.Editor |
1757 """ |
1758 """ |
1758 filename = editor.getFileName() |
1759 if self.__projectopen: |
1759 line, index = editor.getCursorPosition() |
1760 filename = editor.getFileName() |
1760 offset = self.__getOffset(editor, line, index) |
1761 line, index = editor.getCursorPosition() |
1761 |
1762 offset = self.__getOffset(editor, line, index) |
1762 self.sendJson("QueryDefinition", { |
1763 |
1763 "Title": "", |
1764 self.sendJson("QueryDefinition", { |
1764 "FileName": filename, |
1765 "Title": "", |
1765 "Offset": offset, |
1766 "FileName": filename, |
1766 "Source": editor.text(), |
1767 "Offset": offset, |
1767 "Subcommand": "Goto", |
1768 "Source": editor.text(), |
1768 }) |
1769 "Subcommand": "Goto", |
|
1770 }) |
1769 |
1771 |
1770 def __queryDefinitionResult(self, result): |
1772 def __queryDefinitionResult(self, result): |
1771 """ |
1773 """ |
1772 Private method to handle the "Query Definition" result sent by |
1774 Private method to handle the "Query Definition" result sent by |
1773 the client. |
1775 the client. |
1794 if "Error" not in result: |
1796 if "Error" not in result: |
1795 # ignore errors silently |
1797 # ignore errors silently |
1796 if "Location" in result: |
1798 if "Location" in result: |
1797 location = result["Location"] |
1799 location = result["Location"] |
1798 try: |
1800 try: |
1799 e5App().getObject("ViewManager").openSourceFile( |
1801 self.__vm.openSourceFile( |
1800 location[0], location[1], addNext=True) |
1802 location[0], location[1], addNext=True) |
1801 except TypeError: |
1803 except TypeError: |
1802 # backward compatibility; <= 17.03 |
1804 # backward compatibility; <= 17.03 |
1803 e5App().getObject("ViewManager").openSourceFile( |
1805 self.__vm.openSourceFile( |
1804 location[0], location[1], next=True) |
1806 location[0], location[1], next=True) |
1805 else: |
1807 else: |
1806 e5App().getObject("UserInterface").statusBar().showMessage( |
1808 e5App().getObject("UserInterface").statusBar().showMessage( |
1807 self.tr('No definition found'), 5000) |
1809 self.tr('No definition found'), 5000) |
1808 |
1810 |
1809 def __queryImplementations(self): |
1811 def __queryImplementations(self): |
1810 """ |
1812 """ |
1811 Private slot to handle the Find Implementations action. |
1813 Private slot to handle the Find Implementations action. |
1812 """ |
1814 """ |
1813 aw = e5App().getObject("ViewManager").activeWindow() |
1815 aw = self.__vm.activeWindow() |
1814 |
1816 |
1815 if aw is None: |
1817 if aw is None: |
1816 return |
1818 return |
1817 |
1819 |
1818 title = self.tr("Find Implementations") |
1820 title = self.tr("Find Implementations") |
2137 Public method to check, if any editor has unsaved changes. |
2139 Public method to check, if any editor has unsaved changes. |
2138 |
2140 |
2139 @return flag indicating, that no editor contains unsaved edits |
2141 @return flag indicating, that no editor contains unsaved edits |
2140 @rtype bool |
2142 @rtype bool |
2141 """ |
2143 """ |
2142 res = e5App().getObject("ViewManager").checkAllDirty() |
2144 res = self.__vm.checkAllDirty() |
2143 self.sendJson("Validate", {}) |
2145 self.sendJson("Validate", {}) |
2144 return res |
2146 return res |
2145 |
2147 |
2146 def refreshEditors(self, changedFiles): |
2148 def refreshEditors(self, changedFiles): |
2147 """ |
2149 """ |
2148 Public method to refresh modified editors. |
2150 Public method to refresh modified editors. |
2149 |
2151 |
2150 @param changedFiles list of changed files |
2152 @param changedFiles list of changed files |
2151 @type list of str |
2153 @type list of str |
2152 """ |
2154 """ |
2153 vm = e5App().getObject("ViewManager") |
2155 openFiles = [Utilities.normcasepath(f) |
2154 openFiles = [Utilities.normcasepath(f) for f in vm.getOpenFilenames()] |
2156 for f in self.__vm.getOpenFilenames()] |
2155 |
2157 |
2156 for fileName in changedFiles: |
2158 for fileName in changedFiles: |
2157 normfile = Utilities.normcasepath(fileName) |
2159 normfile = Utilities.normcasepath(fileName) |
2158 if normfile in openFiles: |
2160 if normfile in openFiles: |
2159 editor = vm.getEditor(normfile)[1] |
2161 editor = self.__vm.getEditor(normfile)[1] |
2160 editor.refresh() |
2162 editor.refresh() |
2161 |
2163 |
2162 aw = vm.activeWindow() |
2164 aw = self.__vm.activeWindow() |
2163 if aw is not None: |
2165 if aw is not None: |
2164 filename = aw.getFileName() |
2166 filename = aw.getFileName() |
2165 if filename is not None: |
2167 if filename is not None: |
2166 vm.openSourceFile(filename, aw.getCursorPosition()[0] + 1) |
2168 self.__vm.openSourceFile(filename, |
|
2169 aw.getCursorPosition()[0] + 1) |
2167 |
2170 |
2168 def reportChanged(self, filename, oldSource): |
2171 def reportChanged(self, filename, oldSource): |
2169 """ |
2172 """ |
2170 Public slot to report some changed sources. |
2173 Public slot to report some changed sources. |
2171 |
2174 |
2174 @param oldSource source code before the change |
2177 @param oldSource source code before the change |
2175 @type str |
2178 @type str |
2176 """ |
2179 """ |
2177 if self.__e5project.isOpen() and \ |
2180 if self.__e5project.isOpen() and \ |
2178 self.__e5project.isProjectFile(filename): |
2181 self.__e5project.isProjectFile(filename): |
2179 self.sendJson("ReportChanged", { |
2182 editor = self.__vm.getOpenEditor(filename) |
2180 "FileName": filename, |
2183 if editor is not None and \ |
2181 "OldSource": oldSource, |
2184 editor.getLanguage() == self.__ropeConfig["PythonVersion"]: |
2182 }) |
2185 self.sendJson("ReportChanged", { |
|
2186 "FileName": filename, |
|
2187 "OldSource": oldSource, |
|
2188 }) |
2183 |
2189 |
2184 ####################################################################### |
2190 ####################################################################### |
2185 ## Methods below handle the network connection |
2191 ## Methods below handle the network connection |
2186 ####################################################################### |
2192 ####################################################################### |
2187 |
2193 |
2246 """ |
2252 """ |
2247 client = os.path.join(os.path.dirname(__file__), |
2253 client = os.path.join(os.path.dirname(__file__), |
2248 "RefactoringClient.py") |
2254 "RefactoringClient.py") |
2249 ok = self.startClient(interpreter, client, [self.__projectpath]) |
2255 ok = self.startClient(interpreter, client, [self.__projectpath]) |
2250 return ok |
2256 return ok |
|
2257 |
|
2258 ######################################################################### |
|
2259 ## Methods below handle setting/unsetting the mouse click handler methods |
|
2260 ######################################################################### |
|
2261 |
|
2262 def connectEditor(self, editor): |
|
2263 """ |
|
2264 Public method to connect an editor. |
|
2265 |
|
2266 @param editor reference to the editor |
|
2267 @type QScintilla.Editor |
|
2268 """ |
|
2269 |
|
2270 if self.__plugin.getPreferences("MouseClickEnabled"): |
|
2271 self.__disconnectMouseClickHandler(editor) |
|
2272 self.__connectMouseClickHandler(editor) |
|
2273 |
|
2274 def disconnectEditor(self, editor): |
|
2275 """ |
|
2276 Public method to disconnect an editor. |
|
2277 |
|
2278 @param editor reference to the editor |
|
2279 @type QScintilla.Editor |
|
2280 """ |
|
2281 self.__disconnectMouseClickHandler(editor) |
|
2282 |
|
2283 def __connectMouseClickHandler(self, editor): |
|
2284 """ |
|
2285 Private method to connect the mouse click handler to an editor. |
|
2286 |
|
2287 @param editor reference to the editor |
|
2288 @type QScintilla.Editor |
|
2289 """ |
|
2290 if self.__plugin.getPreferences("MouseClickGotoButton"): |
|
2291 editor.setMouseClickHandler( |
|
2292 "rope", |
|
2293 self.__plugin.getPreferences("MouseClickGotoModifiers"), |
|
2294 self.__plugin.getPreferences("MouseClickGotoButton"), |
|
2295 self.gotoDefinition |
|
2296 ) |
|
2297 |
|
2298 def __disconnectMouseClickHandler(self, editor): |
|
2299 """ |
|
2300 Private method to disconnect the mouse click handler from an editor. |
|
2301 |
|
2302 @param editor reference to the editor |
|
2303 @type QScintilla.Editor |
|
2304 """ |
|
2305 editor.removeMouseClickHandlers("rope") |