Helpviewer/Bookmarks/BookmarksMenu.py

changeset 1671
1443546b92ad
parent 1509
c0b5e693b0eb
child 1713
56fdde8a2441
equal deleted inserted replaced
1670:6fd889391d2c 1671:1443546b92ad
20 20
21 class BookmarksMenu(E5ModelMenu): 21 class BookmarksMenu(E5ModelMenu):
22 """ 22 """
23 Class implementing the bookmarks menu base class. 23 Class implementing the bookmarks menu base class.
24 24
25 @signal openUrl(QUrl, str) emitted to open a URL in the current tab 25 @signal openUrl(QUrl, str) emitted to open a URL with the given title in the
26 @signal newUrl(QUrl, str) emitted to open a URL in a new tab 26 current tab
27 @signal newUrl(QUrl, str) emitted to open a URL with the given title in a
28 new tab
27 """ 29 """
28 openUrl = pyqtSignal(QUrl, str) 30 openUrl = pyqtSignal(QUrl, str)
29 newUrl = pyqtSignal(QUrl, str) 31 newUrl = pyqtSignal(QUrl, str)
30 32
31 def __init__(self, parent=None): 33 def __init__(self, parent=None):
91 if not hasBookmarks: 93 if not hasBookmarks:
92 return 94 return
93 95
94 self.addSeparator() 96 self.addSeparator()
95 act = self.addAction(self.trUtf8("Open all in Tabs")) 97 act = self.addAction(self.trUtf8("Open all in Tabs"))
96 act.triggered[()].connect(self.__openAll) 98 act.triggered[()].connect(self.openAll)
97 99
98 def __openAll(self): 100 def openAll(self):
99 """ 101 """
100 Private slot to open all the menu's items. 102 Public slot to open all the menu's items.
101 """ 103 """
102 menu = self.sender().parent() 104 menu = self.sender().parent()
103 if menu is None: 105 if menu is None:
104 return 106 return
105 107
185 187
186 188
187 class BookmarksMenuBarMenu(BookmarksMenu): 189 class BookmarksMenuBarMenu(BookmarksMenu):
188 """ 190 """
189 Class implementing a dynamically populated menu for bookmarks. 191 Class implementing a dynamically populated menu for bookmarks.
190 """ 192
193 @signal openUrl(QUrl, str) emitted to open a URL with the given title in the
194 current tab
195 """
196 openUrl = pyqtSignal(QUrl, str)
197
191 def __init__(self, parent=None): 198 def __init__(self, parent=None):
192 """ 199 """
193 Constructor 200 Constructor
194 201
195 @param parent reference to the parent widget (QWidget) 202 @param parent reference to the parent widget (QWidget)
220 self.__bookmarksManager.bookmarksModel()\ 227 self.__bookmarksManager.bookmarksModel()\
221 .nodeIndex(self.__bookmarksManager.toolbar()), 228 .nodeIndex(self.__bookmarksManager.toolbar()),
222 1, self) 229 1, self)
223 return True 230 return True
224 231
232 def postPopulated(self):
233 """
234 Public method to add any actions after the tree.
235 """
236 if self.isEmpty():
237 return
238
239 parent = self.rootIndex()
240
241 hasBookmarks = False
242
243 for i in range(parent.model().rowCount(parent)):
244 child = parent.model().index(i, 0, parent)
245
246 if child.data(BookmarksModel.TypeRole) == BookmarkNode.Bookmark:
247 hasBookmarks = True
248 break
249
250 if not hasBookmarks:
251 return
252
253 self.addSeparator()
254 act = self.addAction(self.trUtf8("Default Home Page"))
255 act.setData("eric:home")
256 act.triggered[()].connect(self.__defaultBookmarkTriggered)
257 act = self.addAction(self.trUtf8("Speed Dial"))
258 act.setData("eric:speeddial")
259 act.triggered[()].connect(self.__defaultBookmarkTriggered)
260 self.addSeparator()
261 act = self.addAction(self.trUtf8("Open all in Tabs"))
262 act.triggered[()].connect(self.openAll)
263
225 def setInitialActions(self, actions): 264 def setInitialActions(self, actions):
226 """ 265 """
227 Public method to set the list of actions that should appear first in the menu. 266 Public method to set the list of actions that should appear first in the menu.
228 267
229 @param actions list of initial actions (list of QAction) 268 @param actions list of initial actions (list of QAction)
230 """ 269 """
231 self.__initialActions = actions[:] 270 self.__initialActions = actions[:]
232 for act in self.__initialActions: 271 for act in self.__initialActions:
233 self.addAction(act) 272 self.addAction(act)
273
274 def __defaultBookmarkTriggered(self):
275 """
276 Private slot handling the default bookmark menu entries.
277 """
278 act = self.sender()
279 urlStr = act.data()
280 if urlStr.startswith("eric:"):
281 self.openUrl.emit(QUrl(urlStr), "")

eric ide

mercurial