diff -r e3924615f9a3 -r 9f687137a929 RefactoringRope/FileSystemCommands.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RefactoringRope/FileSystemCommands.py Sun Jan 23 19:55:56 2011 +0100 @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing file system commands for rope. +""" + +import os + +import rope.base.fscommands + +from E5Gui.E5Application import e5App + +class e5FileSystemCommands(object): + """ + Class implementing file system commands for rope. + """ + def __init__(self, project): + """ + Constructor + + @param project reference to the eric4 project object (Project.Project) + """ + self.__project = project + 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 (string) + """ + self.__normal_actions.create_file(path) + self.__project.appendFile(path) + vcs = self.__project.getVcs() + if vcs is not None: + vcs.vcsAdd(path, noDialog = True) + + def create_folder(self, path): + """ + Public method called by rope to create a new directory. + + @param path new directory (string) + """ + 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): + """ + Public 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) + """ + vcs = self.__project.getVcs() + if vcs is None: + if os.path.isdir(path): + self.__project.moveDirectory(path, new_location) + else: + self.__project.renameFile(path, new_location) + else: + vcs.vcsMove(path, self.__project, new_location, noDialog = True) + + def remove(self, path): + """ + Public method called by rope to remove a file or directory. + + @param path name of file/directory to remove (string) + """ + vcs = self.__project.getVcs() + if vcs is None: + if os.path.isdir(path): + self.__project.removeDirectory(path) + else: + 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)