Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/bookmarks.py

changeset 1011
0b118aefae5b
child 1017
919147f2b518
equal deleted inserted replaced
1010:06393b5f5330 1011:0b118aefae5b
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the bookmarks extension interface.
8 """
9
10 import os
11
12 from PyQt4.QtCore import QObject
13 from PyQt4.QtGui import QDialog, QInputDialog
14
15 from ..HgDialog import HgDialog
16
17 from .HgBookmarksListDialog import HgBookmarksListDialog
18 from .HgBookmarkDialog import HgBookmarkDialog
19 from .HgBookmarkRenameDialog import HgBookmarkRenameDialog
20
21
22 class Bookmarks(QObject):
23 """
24 Class implementing the bookmarks extension interface.
25 """
26 def __init__(self, vcs):
27 """
28 Constructor
29 """
30 QObject.__init__(self, vcs)
31
32 self.vcs = vcs
33
34 self.bookmarksListDlg = None
35 self.bookmarksList = []
36
37 def shutdown(self):
38 """
39 Public method used to shutdown the bookmarks interface.
40 """
41 if self.bookmarksListDlg is not None:
42 self.bookmarksListDlg.close()
43
44 def hgListBookmarks(self, path):
45 """
46 Public method used to list the available bookmarks.
47
48 @param path directory name of the project (string)
49 """
50 self.bookmarksList = []
51
52 self.bookmarksListDlg = HgBookmarksListDialog(self.vcs)
53 self.bookmarksListDlg.show()
54 self.bookmarksListDlg.start(path, self.bookmarksList)
55
56 def hgGetLoadedBookmarksList(self):
57 """
58 Public method to get the list of loaded bookmarks.
59
60 @return list of loaded bookmarks (list of string)
61 """
62 return self.bookmarksList[:]
63
64 def hgBookmarkDefine(self, name):
65 """
66 Public method to define a bookmark.
67
68 @param name file/directory name (string)
69 """
70 dname, fname = self.vcs.splitPath(name)
71
72 # find the root of the repo
73 repodir = str(dname)
74 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
75 repodir = os.path.dirname(repodir)
76 if repodir == os.sep:
77 return
78
79 dlg = HgBookmarkDialog(self.vcs.tagsList, self.vcs.branchesList,
80 self.bookmarksList)
81 if dlg.exec_() == QDialog.Accepted:
82 rev, bookmark = dlg.getData()
83
84 args = []
85 args.append("bookmarks")
86 if rev:
87 args.append("--rev")
88 args.append(rev)
89 args.append(bookmark)
90
91 dia = HgDialog(self.trUtf8('Mercurial Bookmark'))
92 res = dia.startProcess(args, repodir)
93 if res:
94 dia.exec_()
95
96 def hgBookmarkDelete(self, name):
97 """
98 Public method to delete a bookmark.
99
100 @param name file/directory name (string)
101 """
102 dname, fname = self.vcs.splitPath(name)
103
104 # find the root of the repo
105 repodir = str(dname)
106 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
107 repodir = os.path.dirname(repodir)
108 if repodir == os.sep:
109 return
110
111 bookmark, ok = QInputDialog.getItem(
112 None,
113 self.trUtf8("Delete Bookmark"),
114 self.trUtf8("Select the bookmark to be deleted:"),
115 [""] + self.bookmarksList,
116 0, True)
117 if ok and bookmark:
118 args = []
119 args.append("bookmarks")
120 args.append("--delete")
121 args.append(bookmark)
122
123 dia = HgDialog(self.trUtf8('Delete Mercurial Bookmark'))
124 res = dia.startProcess(args, repodir)
125 if res:
126 dia.exec_()
127
128 def hgBookmarkRename(self, name):
129 """
130 Public method to rename a bookmark.
131
132 @param name file/directory name (string)
133 """
134 dname, fname = self.vcs.splitPath(name)
135
136 # find the root of the repo
137 repodir = str(dname)
138 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
139 repodir = os.path.dirname(repodir)
140 if repodir == os.sep:
141 return
142
143 dlg = HgBookmarkRenameDialog(self.bookmarksList)
144 if dlg.exec_() == QDialog.Accepted:
145 newName, oldName = dlg.getData()
146
147 args = []
148 args.append("bookmarks")
149 args.append("--rename")
150 args.append(oldName)
151 args.append(newName)
152
153 dia = HgDialog(self.trUtf8('Delete Mercurial Bookmark'))
154 res = dia.startProcess(args, repodir)
155 if res:
156 dia.exec_()

eric ide

mercurial