diff -r f5d6fb1a009b -r 55eaaed9d590 RefactoringRope/FileSystemCommands.py --- a/RefactoringRope/FileSystemCommands.py Mon Sep 11 19:15:44 2017 +0200 +++ b/RefactoringRope/FileSystemCommands.py Mon Sep 11 19:55:45 2017 +0200 @@ -13,7 +13,84 @@ import rope.base.fscommands -from E5Gui.E5Application import e5App + +class RefactoringClientFileSystemCommands(object): + """ + Class implementing the client side of the rope file system commands. + """ + def __init__(self, client): + """ + Constructor + + @param client reference to the refactoring client + @type RefactoringClient + """ + self.__client = client + self.__normal_actions = rope.base.fscommands.FileSystemCommands() + + def create_file(self, path): + """ + Public method called by rope to create a new file. + + @param path new filename + @type str + """ + self.__normal_actions.create_file(path) + self.__client.sendJson("FileSystemCommand", { + "SubCommand": "CreateFile", + "Path": path, + }) + + def create_folder(self, path): + """ + Public method called by rope to create a new directory. + + @param path new directory + @type str + """ + self.__normal_actions.create_folder(path) + self.__client.sendJson("FileSystemCommand", { + "SubCommand": "CreateFolder", + "Path": path, + }) + + def move(self, path, new_location): + """ + Public method called by rope to rename a file or directory. + + @param path old file/directory name + @type str + @param new_location new file/directory name + @type str + """ + self.__client.sendJson("FileSystemCommand", { + "SubCommand": "Move", + "Path": path, + "NewLocation": new_location, + }) + + def remove(self, path): + """ + Public method called by rope to remove a file or directory. + + @param path name of file/directory to remove + @type str + """ + self.__normal_actions.remove(path) + self.__client.sendJson("FileSystemCommand", { + "SubCommand": "Remove", + "Path": path, + }) + + def write(self, path, data): + """ + Public method called by rope to write data to a file. + + @param path filename of file to write to + @type str + @param data dat to be written + """ + self.__normal_actions.write(path, data) class E5FileSystemCommands(object): @@ -24,40 +101,62 @@ """ Constructor - @param project reference to the eric4 project object (Project.Project) + @param project reference to the eric project object (Project.Project) """ self.__project = project - self.__normal_actions = rope.base.fscommands.FileSystemCommands() - def create_file(self, path): + def processFileSystemCommand(self, params): + """ + Public method to process rope file system commands. + + @param params dictionary containing the command and relevant data + @type dict """ - Public method called by rope to create a new file. + command = params["SubCommand"] + + if command == "CreateFile": + self.__createFile(params["Path"]) + + elif command == "CreateFolder": + self.__createFolder(params["Path"]) + + elif command == "Move": + self.__move(params["Path"], params["NewLocation"]) - @param path new filename (string) + elif command == "Remove": + self.__remove(params["Path"]) + + def __createFile(self, path): """ - self.__normal_actions.create_file(path) + Private method called by rope to create a new file. + + @param path new filename + @type str + """ self.__project.appendFile(path) vcs = self.__project.getVcs() if vcs is not None: vcs.vcsAdd(path, noDialog=True) - def create_folder(self, path): + def __createFolder(self, path): """ - Public method called by rope to create a new directory. + Private method called by rope to create a new directory. - @param path new directory (string) + @param path new directory + @type str """ - self.__normal_actions.create_folder(path) vcs = self.__project.getVcs() if vcs is not None: vcs.vcsAdd(path, noDialog=True) - def move(self, path, new_location): + def __move(self, path, new_location): """ - Public method called by rope to rename a file or directory. + Private method called by rope to rename a file or directory. - @param path old file/directory name (string) - @param new_location new file/directory name (string) + @param path old file/directory name + @type str + @param new_location new file/directory name + @type str """ vcs = self.__project.getVcs() if vcs is None: @@ -68,9 +167,9 @@ else: vcs.vcsMove(path, self.__project, new_location, noDialog=True) - def remove(self, path): + def __remove(self, path): """ - Public method called by rope to remove a file or directory. + Private method called by rope to remove a file or directory. @param path name of file/directory to remove (string) """ @@ -79,17 +178,8 @@ if os.path.isdir(path): self.__project.removeDirectory(path) else: + from E5Gui.E5Application import e5App e5App().getObject("ViewManager").closeWindow(path) self.__project.removeFile(path) - self.__normal_actions.remove(path) else: vcs.vcsRemove(path, noDialog=True) - - def write(self, path, data): - """ - Public method called by rope to write data to a file. - - @param path filename of file to write to (string) - @param data dat to be written - """ - self.__normal_actions.write(path, data)