44 """ |
44 """ |
45 super(RefactoringClient, self).__init__(host, port) |
45 super(RefactoringClient, self).__init__(host, port) |
46 |
46 |
47 self.__methodMapping = { |
47 self.__methodMapping = { |
48 "AbortAction": self.__abortAction, |
48 "AbortAction": self.__abortAction, |
|
49 "CloseProject": self.__closeProject, |
49 "Validate": self.__validate, |
50 "Validate": self.__validate, |
50 "QueryReferences": self.__queryReferences, |
51 "QueryReferences": self.__queryReferences, |
51 "QueryDefinition": self.__queryDefinition, |
52 "QueryDefinition": self.__queryDefinition, |
52 "QueryImplementations": self.__queryImplementations, |
53 "QueryImplementations": self.__queryImplementations, |
53 "GetConfig": self.__getConfig, |
54 "GetConfig": self.__getConfig, |
54 "ConfigChanged": self.__configChanged, |
55 "ConfigChanged": self.__configChanged, |
55 "PerformSoa": self.__performSOA, |
56 "PerformSoa": self.__performSOA, |
56 "ReportChanged": self.__reportChanged, |
57 "ReportChanged": self.__reportChanged, |
|
58 "History": self.__processHistory, |
57 } |
59 } |
58 |
60 |
59 from FileSystemCommands import RefactoringClientFileSystemCommands |
61 from FileSystemCommands import RefactoringClientFileSystemCommands |
60 self.__fsCommands = RefactoringClientFileSystemCommands(self) |
62 self.__fsCommands = RefactoringClientFileSystemCommands(self) |
61 |
63 |
62 self.__projectpath = projectPath |
64 self.__projectpath = projectPath |
63 self.__project = rope.base.project.Project( |
65 self.__project = rope.base.project.Project( |
64 self.__projectpath, fscommands=self.__fsCommands) |
66 self.__projectpath, fscommands=self.__fsCommands) |
65 |
67 |
66 self.__progressHandle = None |
68 self.__progressHandle = None |
|
69 |
|
70 self.__changes = {} # dict storing the retrieved changes |
67 |
71 |
68 def handleCall(self, method, params): |
72 def handleCall(self, method, params): |
69 """ |
73 """ |
70 Public method to handle a method call from the server. |
74 Public method to handle a method call from the server. |
71 |
75 |
120 @param params dictionary containing the method parameters sent by |
124 @param params dictionary containing the method parameters sent by |
121 the server |
125 the server |
122 @type dict |
126 @type dict |
123 """ |
127 """ |
124 self.__project.validate(self.__project.root) |
128 self.__project.validate(self.__project.root) |
|
129 |
|
130 def __closeProject(self, params): |
|
131 """ |
|
132 Private slot to validate the project. |
|
133 |
|
134 @param params dictionary containing the method parameters sent by |
|
135 the server |
|
136 @type dict |
|
137 """ |
|
138 self.__project.close() |
125 |
139 |
126 def __getConfig(self, params): |
140 def __getConfig(self, params): |
127 """ |
141 """ |
128 Private method to send some configuration data to the server. |
142 Private method to send some configuration data to the server. |
129 |
143 |
320 rope.base.libutils.report_change( |
334 rope.base.libutils.report_change( |
321 self.__project, filename, oldSource) |
335 self.__project, filename, oldSource) |
322 except Exception: |
336 except Exception: |
323 # simply ignore it |
337 # simply ignore it |
324 pass |
338 pass |
|
339 |
|
340 def __processHistory(self, params): |
|
341 """ |
|
342 Private method to process the various history related requests. |
|
343 |
|
344 @param params dictionary containing the method parameters sent by |
|
345 the server |
|
346 @type dict |
|
347 """ |
|
348 subcommand = params["Subcommand"] |
|
349 if subcommand == "Get": |
|
350 self.__changes = {} |
|
351 if params["Filename"]: |
|
352 # file history |
|
353 resource = rope.base.libutils.path_to_resource( |
|
354 self.__project, params["Filename"]) |
|
355 undoList = [] |
|
356 for change in reversed(self.__project.history.undo_list): |
|
357 if resource in change.get_changed_resources(): |
|
358 undoList.append(change) |
|
359 redoList = [] |
|
360 for change in self.__project.history.redo_list: |
|
361 if resource in change.get_changed_resources(): |
|
362 redoList.append(change) |
|
363 else: |
|
364 # project history |
|
365 undoList = list(reversed(self.__project.history.undo_list)) |
|
366 redoList = self.__project.history.redo_list |
|
367 |
|
368 result = {"Subcommand": "Histories"} |
|
369 result["Undo"] = [] |
|
370 for change in undoList: |
|
371 self.__changes[id(change)] = change |
|
372 result["Undo"].append([str(change), id(change)]) |
|
373 result["Redo"] = [] |
|
374 for change in redoList: |
|
375 self.__changes[id(change)] = change |
|
376 result["Redo"].append([str(change), id(change)]) |
|
377 |
|
378 self.sendJson("HistoryResult", result) |
|
379 |
|
380 elif subcommand == "GetChange": |
|
381 result = { |
|
382 "Subcommand": "ChangeDescription", |
|
383 "Description": self.__changes[params["Id"]].get_description() |
|
384 } |
|
385 |
|
386 self.sendJson("HistoryResult", result) |
|
387 |
|
388 elif subcommand in ["Undo", "Redo"]: |
|
389 change = self.__changes[params["Id"]] |
|
390 from ProgressHandle import ProgressHandle |
|
391 self.__progressHandle = ProgressHandle(self, change.description, |
|
392 False) |
|
393 if subcommand == "Undo": |
|
394 self.__project.history.undo( |
|
395 change, task_handle=self.__progressHandle) |
|
396 else: |
|
397 self.__project.history.redo( |
|
398 change, task_handle=self.__progressHandle) |
|
399 self.__progressHandle.reset() |
|
400 self.__progressHandle = None |
|
401 |
|
402 result = { |
|
403 "Subcommand": subcommand, |
|
404 "ChangedFiles": [ |
|
405 res.real_path for res in change.get_changed_resources() |
|
406 ], |
|
407 } |
|
408 |
|
409 self.sendJson("HistoryResult", result) |
|
410 |
|
411 elif subcommand == "Clear": |
|
412 self.__project.history.clear() |
325 |
413 |
326 if __name__ == '__main__': |
414 if __name__ == '__main__': |
327 if len(sys.argv) != 4: |
415 if len(sys.argv) != 4: |
328 print('Host, port and project path parameters are missing. Abort.') |
416 print('Host, port and project path parameters are missing. Abort.') |
329 sys.exit(1) |
417 sys.exit(1) |