RefactoringRope/FileSystemCommands.py

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

eric ide

mercurial