RefactoringRope/RefactoringClient.py

branch
server_client_variant
changeset 168
53d76b4fc1ac
parent 167
3c8e875d0326
child 170
05ef7c12a6d4
--- a/RefactoringRope/RefactoringClient.py	Sat Sep 16 18:51:19 2017 +0200
+++ b/RefactoringRope/RefactoringClient.py	Sun Sep 17 17:03:16 2017 +0200
@@ -46,6 +46,7 @@
         
         self.__methodMapping = {
             "AbortAction": self.__abortAction,
+            "CloseProject": self.__closeProject,
             "Validate": self.__validate,
             "QueryReferences": self.__queryReferences,
             "QueryDefinition": self.__queryDefinition,
@@ -54,6 +55,7 @@
             "ConfigChanged": self.__configChanged,
             "PerformSoa": self.__performSOA,
             "ReportChanged": self.__reportChanged,
+            "History": self.__processHistory,
         }
         
         from FileSystemCommands import RefactoringClientFileSystemCommands
@@ -64,6 +66,8 @@
             self.__projectpath, fscommands=self.__fsCommands)
         
         self.__progressHandle = None
+        
+        self.__changes = {}     # dict storing the retrieved changes
     
     def handleCall(self, method, params):
         """
@@ -123,6 +127,16 @@
         """
         self.__project.validate(self.__project.root)
     
+    def __closeProject(self, params):
+        """
+        Private slot to validate the project.
+        
+        @param params dictionary containing the method parameters sent by
+            the server
+        @type dict
+        """
+        self.__project.close()
+    
     def __getConfig(self, params):
         """
         Private method to send some configuration data to the server.
@@ -322,6 +336,80 @@
         except Exception:
             # simply ignore it
             pass
+    
+    def __processHistory(self, params):
+        """
+        Private method to process the various history related requests.
+        
+        @param params dictionary containing the method parameters sent by
+            the server
+        @type dict
+        """
+        subcommand = params["Subcommand"]
+        if subcommand == "Get":
+            self.__changes = {}
+            if params["Filename"]:
+                # file history
+                resource = rope.base.libutils.path_to_resource(
+                    self.__project, params["Filename"])
+                undoList = []
+                for change in reversed(self.__project.history.undo_list):
+                    if resource in change.get_changed_resources():
+                        undoList.append(change)
+                redoList = []
+                for change in self.__project.history.redo_list:
+                    if resource in change.get_changed_resources():
+                        redoList.append(change)
+            else:
+                # project history
+                undoList = list(reversed(self.__project.history.undo_list))
+                redoList = self.__project.history.redo_list
+            
+            result = {"Subcommand": "Histories"}
+            result["Undo"] = []
+            for change in undoList:
+                self.__changes[id(change)] = change
+                result["Undo"].append([str(change), id(change)])
+            result["Redo"] = []
+            for change in redoList:
+                self.__changes[id(change)] = change
+                result["Redo"].append([str(change), id(change)])
+            
+            self.sendJson("HistoryResult", result)
+        
+        elif subcommand == "GetChange":
+            result = {
+                "Subcommand": "ChangeDescription",
+                "Description": self.__changes[params["Id"]].get_description()
+            }
+            
+            self.sendJson("HistoryResult", result)
+        
+        elif subcommand in ["Undo", "Redo"]:
+            change = self.__changes[params["Id"]]
+            from ProgressHandle import ProgressHandle
+            self.__progressHandle = ProgressHandle(self, change.description,
+                                                   False)
+            if subcommand == "Undo":
+                self.__project.history.undo(
+                    change, task_handle=self.__progressHandle)
+            else:
+                self.__project.history.redo(
+                    change, task_handle=self.__progressHandle)
+            self.__progressHandle.reset()
+            self.__progressHandle = None
+            
+            result = {
+                "Subcommand": subcommand,
+                "ChangedFiles": [
+                    res.real_path for res in change.get_changed_resources()
+                ],
+            }
+            
+            self.sendJson("HistoryResult", result)
+        
+        elif subcommand == "Clear":
+            self.__project.history.clear()
 
 if __name__ == '__main__':
     if len(sys.argv) != 4:

eric ide

mercurial