RefactoringRope/FileSystemCommands.py

branch
server_client_variant
changeset 162
55eaaed9d590
parent 147
3f8a995f6e49
child 195
5d614a567be3
equal deleted inserted replaced
161:f5d6fb1a009b 162:55eaaed9d590
11 11
12 import os 12 import os
13 13
14 import rope.base.fscommands 14 import rope.base.fscommands
15 15
16 from E5Gui.E5Application import e5App 16
17 class RefactoringClientFileSystemCommands(object):
18 """
19 Class implementing the client side of the rope file system commands.
20 """
21 def __init__(self, client):
22 """
23 Constructor
24
25 @param client reference to the refactoring client
26 @type RefactoringClient
27 """
28 self.__client = client
29 self.__normal_actions = rope.base.fscommands.FileSystemCommands()
30
31 def create_file(self, path):
32 """
33 Public method called by rope to create a new file.
34
35 @param path new filename
36 @type str
37 """
38 self.__normal_actions.create_file(path)
39 self.__client.sendJson("FileSystemCommand", {
40 "SubCommand": "CreateFile",
41 "Path": path,
42 })
43
44 def create_folder(self, path):
45 """
46 Public method called by rope to create a new directory.
47
48 @param path new directory
49 @type str
50 """
51 self.__normal_actions.create_folder(path)
52 self.__client.sendJson("FileSystemCommand", {
53 "SubCommand": "CreateFolder",
54 "Path": path,
55 })
56
57 def move(self, path, new_location):
58 """
59 Public method called by rope to rename a file or directory.
60
61 @param path old file/directory name
62 @type str
63 @param new_location new file/directory name
64 @type str
65 """
66 self.__client.sendJson("FileSystemCommand", {
67 "SubCommand": "Move",
68 "Path": path,
69 "NewLocation": new_location,
70 })
71
72 def remove(self, path):
73 """
74 Public method called by rope to remove a file or directory.
75
76 @param path name of file/directory to remove
77 @type str
78 """
79 self.__normal_actions.remove(path)
80 self.__client.sendJson("FileSystemCommand", {
81 "SubCommand": "Remove",
82 "Path": path,
83 })
84
85 def write(self, path, data):
86 """
87 Public method called by rope to write data to a file.
88
89 @param path filename of file to write to
90 @type str
91 @param data dat to be written
92 """
93 self.__normal_actions.write(path, data)
17 94
18 95
19 class E5FileSystemCommands(object): 96 class E5FileSystemCommands(object):
20 """ 97 """
21 Class implementing file system commands for rope. 98 Class implementing file system commands for rope.
22 """ 99 """
23 def __init__(self, project): 100 def __init__(self, project):
24 """ 101 """
25 Constructor 102 Constructor
26 103
27 @param project reference to the eric4 project object (Project.Project) 104 @param project reference to the eric project object (Project.Project)
28 """ 105 """
29 self.__project = project 106 self.__project = project
30 self.__normal_actions = rope.base.fscommands.FileSystemCommands()
31 107
32 def create_file(self, path): 108 def processFileSystemCommand(self, params):
33 """ 109 """
34 Public method called by rope to create a new file. 110 Public method to process rope file system commands.
35 111
36 @param path new filename (string) 112 @param params dictionary containing the command and relevant data
113 @type dict
37 """ 114 """
38 self.__normal_actions.create_file(path) 115 command = params["SubCommand"]
116
117 if command == "CreateFile":
118 self.__createFile(params["Path"])
119
120 elif command == "CreateFolder":
121 self.__createFolder(params["Path"])
122
123 elif command == "Move":
124 self.__move(params["Path"], params["NewLocation"])
125
126 elif command == "Remove":
127 self.__remove(params["Path"])
128
129 def __createFile(self, path):
130 """
131 Private method called by rope to create a new file.
132
133 @param path new filename
134 @type str
135 """
39 self.__project.appendFile(path) 136 self.__project.appendFile(path)
40 vcs = self.__project.getVcs() 137 vcs = self.__project.getVcs()
41 if vcs is not None: 138 if vcs is not None:
42 vcs.vcsAdd(path, noDialog=True) 139 vcs.vcsAdd(path, noDialog=True)
43 140
44 def create_folder(self, path): 141 def __createFolder(self, path):
45 """ 142 """
46 Public method called by rope to create a new directory. 143 Private method called by rope to create a new directory.
47 144
48 @param path new directory (string) 145 @param path new directory
146 @type str
49 """ 147 """
50 self.__normal_actions.create_folder(path)
51 vcs = self.__project.getVcs() 148 vcs = self.__project.getVcs()
52 if vcs is not None: 149 if vcs is not None:
53 vcs.vcsAdd(path, noDialog=True) 150 vcs.vcsAdd(path, noDialog=True)
54 151
55 def move(self, path, new_location): 152 def __move(self, path, new_location):
56 """ 153 """
57 Public method called by rope to rename a file or directory. 154 Private method called by rope to rename a file or directory.
58 155
59 @param path old file/directory name (string) 156 @param path old file/directory name
60 @param new_location new file/directory name (string) 157 @type str
158 @param new_location new file/directory name
159 @type str
61 """ 160 """
62 vcs = self.__project.getVcs() 161 vcs = self.__project.getVcs()
63 if vcs is None: 162 if vcs is None:
64 if os.path.isdir(path): 163 if os.path.isdir(path):
65 self.__project.moveDirectory(path, new_location) 164 self.__project.moveDirectory(path, new_location)
66 else: 165 else:
67 self.__project.renameFile(path, new_location) 166 self.__project.renameFile(path, new_location)
68 else: 167 else:
69 vcs.vcsMove(path, self.__project, new_location, noDialog=True) 168 vcs.vcsMove(path, self.__project, new_location, noDialog=True)
70 169
71 def remove(self, path): 170 def __remove(self, path):
72 """ 171 """
73 Public method called by rope to remove a file or directory. 172 Private method called by rope to remove a file or directory.
74 173
75 @param path name of file/directory to remove (string) 174 @param path name of file/directory to remove (string)
76 """ 175 """
77 vcs = self.__project.getVcs() 176 vcs = self.__project.getVcs()
78 if vcs is None: 177 if vcs is None:
79 if os.path.isdir(path): 178 if os.path.isdir(path):
80 self.__project.removeDirectory(path) 179 self.__project.removeDirectory(path)
81 else: 180 else:
181 from E5Gui.E5Application import e5App
82 e5App().getObject("ViewManager").closeWindow(path) 182 e5App().getObject("ViewManager").closeWindow(path)
83 self.__project.removeFile(path) 183 self.__project.removeFile(path)
84 self.__normal_actions.remove(path)
85 else: 184 else:
86 vcs.vcsRemove(path, noDialog=True) 185 vcs.vcsRemove(path, noDialog=True)
87
88 def write(self, path, data):
89 """
90 Public method called by rope to write data to a file.
91
92 @param path filename of file to write to (string)
93 @param data dat to be written
94 """
95 self.__normal_actions.write(path, data)

eric ide

mercurial