RefactoringRope/FileSystemCommands.py

changeset 1
9f687137a929
child 20
83b71483e198
equal deleted inserted replaced
0:e3924615f9a3 1:9f687137a929
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing file system commands for rope.
8 """
9
10 import os
11
12 import rope.base.fscommands
13
14 from E5Gui.E5Application import e5App
15
16 class e5FileSystemCommands(object):
17 """
18 Class implementing file system commands for rope.
19 """
20 def __init__(self, project):
21 """
22 Constructor
23
24 @param project reference to the eric4 project object (Project.Project)
25 """
26 self.__project = project
27 self.__normal_actions = rope.base.fscommands.FileSystemCommands()
28
29 def create_file(self, path):
30 """
31 Public method called by rope to create a new file.
32
33 @param path new filename (string)
34 """
35 self.__normal_actions.create_file(path)
36 self.__project.appendFile(path)
37 vcs = self.__project.getVcs()
38 if vcs is not None:
39 vcs.vcsAdd(path, noDialog = True)
40
41 def create_folder(self, path):
42 """
43 Public method called by rope to create a new directory.
44
45 @param path new directory (string)
46 """
47 self.__normal_actions.create_folder(path)
48 vcs = self.__project.getVcs()
49 if vcs is not None:
50 vcs.vcsAdd(path, noDialog = True)
51
52 def move(self, path, new_location):
53 """
54 Public method called by rope to rename a file or directory.
55
56 @param path old file/directory name (string)
57 @param new_location new file/directory name (string)
58 """
59 vcs = self.__project.getVcs()
60 if vcs is None:
61 if os.path.isdir(path):
62 self.__project.moveDirectory(path, new_location)
63 else:
64 self.__project.renameFile(path, new_location)
65 else:
66 vcs.vcsMove(path, self.__project, new_location, noDialog = True)
67
68 def remove(self, path):
69 """
70 Public method called by rope to remove a file or directory.
71
72 @param path name of file/directory to remove (string)
73 """
74 vcs = self.__project.getVcs()
75 if vcs is None:
76 if os.path.isdir(path):
77 self.__project.removeDirectory(path)
78 else:
79 e5App().getObject("ViewManager").closeWindow(path)
80 self.__project.removeFile(path)
81 self.__normal_actions.remove(path)
82 else:
83 vcs.vcsRemove(path, noDialog = True)
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 (string)
90 @param data dat to be written
91 """
92 self.__normal_actions.write(path, data)

eric ide

mercurial