WebBrowser/Bookmarks/BookmarksMenu.py

changeset 6118
da9e08920e7c
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
equal deleted inserted replaced
6117:4cc6c171ecf6 6118:da9e08920e7c
114 if not hasBookmarks: 114 if not hasBookmarks:
115 return 115 return
116 116
117 self.addSeparator() 117 self.addSeparator()
118 act = self.addAction(self.tr("Open all in Tabs")) 118 act = self.addAction(self.tr("Open all in Tabs"))
119 act.triggered.connect(self.openAll) 119 act.triggered.connect(lambda: self.openAll(act))
120 120
121 def openAll(self): 121 def openAll(self, act):
122 """ 122 """
123 Public slot to open all the menu's items. 123 Public slot to open all the menu's items.
124 """ 124
125 menu = self.sender().parent() 125 @param act reference to the action object
126 @type QAction
127 """
128 menu = act.parent()
126 if menu is None: 129 if menu is None:
127 return 130 return
128 131
129 parent = menu.rootIndex() 132 parent = menu.rootIndex()
130 if not parent.isValid(): 133 if not parent.isValid():
158 act.menu() is None and \ 161 act.menu() is None and \
159 self.index(act).isValid(): 162 self.index(act).isValid():
160 menu = QMenu() 163 menu = QMenu()
161 v = act.data() 164 v = act.data()
162 165
163 menu.addAction( 166 act2 = menu.addAction(self.tr("Open"))
164 self.tr("Open"), 167 act2.setData(v)
165 self.__openBookmark).setData(v) 168 act2.triggered.connect(
166 menu.addAction( 169 lambda: self.__openBookmark(act2))
167 self.tr("Open in New Tab\tCtrl+LMB"), 170 act2 = menu.addAction(self.tr("Open in New Tab\tCtrl+LMB"))
168 self.__openBookmarkInNewTab).setData(v) 171 act2.setData(v)
169 menu.addAction( 172 act2.triggered.connect(
170 self.tr("Open in New Window"), 173 lambda: self.__openBookmarkInNewTab(act2))
171 self.__openBookmarkInNewWindow).setData(v) 174 act2 = menu.addAction(self.tr("Open in New Window"))
172 menu.addAction( 175 act2.setData(v)
173 self.tr("Open in New Private Window"), 176 act2.triggered.connect(
174 self.__openBookmarkInPrivateWindow).setData(v) 177 lambda: self.__openBookmarkInNewWindow(act2))
178 act2 = menu.addAction(self.tr("Open in New Private Window"))
179 act2.setData(v)
180 act2.triggered.connect(
181 lambda: self.__openBookmarkInPrivateWindow(act2))
175 menu.addSeparator() 182 menu.addSeparator()
176 183
177 menu.addAction( 184 act2 = menu.addAction(self.tr("Remove"))
178 self.tr("Remove"), 185 act2.setData(v)
179 self.__removeBookmark).setData(v) 186 act2.triggered.connect(lambda: self.__removeBookmark(act2))
180 menu.addSeparator() 187 menu.addSeparator()
181 188
182 menu.addAction( 189 act2 = menu.addAction(self.tr("Properties..."))
183 self.tr("Properties..."), 190 act2.setData(v)
184 self.__edit).setData(v) 191 act2.triggered.connect(lambda: self.__edit(act2))
185 192
186 execAct = menu.exec_(QCursor.pos()) 193 execAct = menu.exec_(QCursor.pos())
187 if execAct is not None: 194 if execAct is not None:
188 self.close() 195 self.close()
189 parent = self.parent() 196 parent = self.parent()
190 while parent is not None and isinstance(parent, QMenu): 197 while parent is not None and isinstance(parent, QMenu):
191 parent.close() 198 parent.close()
192 parent = parent.parent() 199 parent = parent.parent()
193 200
194 def __openBookmark(self): 201 def __openBookmark(self, act):
195 """ 202 """
196 Private slot to open a bookmark in the current browser tab. 203 Private slot to open a bookmark in the current browser tab.
197 """ 204
198 idx = self.index(self.sender()) 205 @param act reference to the triggering action
206 @type QAction
207 """
208 idx = self.index(act)
199 209
200 self.openUrl.emit( 210 self.openUrl.emit(
201 idx.data(BookmarksModel.UrlRole), 211 idx.data(BookmarksModel.UrlRole),
202 idx.data(Qt.DisplayRole)) 212 idx.data(Qt.DisplayRole))
203 self.__updateVisitCount(idx) 213 self.__updateVisitCount(idx)
204 214
205 def __openBookmarkInNewTab(self): 215 def __openBookmarkInNewTab(self, act):
206 """ 216 """
207 Private slot to open a bookmark in a new browser tab. 217 Private slot to open a bookmark in a new browser tab.
208 """ 218
209 idx = self.index(self.sender()) 219 @param act reference to the triggering action
220 @type QAction
221 """
222 idx = self.index(act)
210 223
211 self.newTab.emit( 224 self.newTab.emit(
212 idx.data(BookmarksModel.UrlRole), 225 idx.data(BookmarksModel.UrlRole),
213 idx.data(Qt.DisplayRole)) 226 idx.data(Qt.DisplayRole))
214 self.__updateVisitCount(idx) 227 self.__updateVisitCount(idx)
215 228
216 def __openBookmarkInNewWindow(self): 229 def __openBookmarkInNewWindow(self, act):
217 """ 230 """
218 Private slot to open a bookmark in a new window. 231 Private slot to open a bookmark in a new window.
219 """ 232
220 idx = self.index(self.sender()) 233 @param act reference to the triggering action
234 @type QAction
235 """
236 idx = self.index(act)
221 url = idx.data(BookmarksModel.UrlRole) 237 url = idx.data(BookmarksModel.UrlRole)
222 238
223 from WebBrowser.WebBrowserWindow import WebBrowserWindow 239 from WebBrowser.WebBrowserWindow import WebBrowserWindow
224 WebBrowserWindow.mainWindow().newWindow(url) 240 WebBrowserWindow.mainWindow().newWindow(url)
225 self.__updateVisitCount(idx) 241 self.__updateVisitCount(idx)
226 242
227 def __openBookmarkInPrivateWindow(self): 243 def __openBookmarkInPrivateWindow(self, act):
228 """ 244 """
229 Private slot to open a bookmark in a new private window. 245 Private slot to open a bookmark in a new private window.
230 """ 246
231 idx = self.index(self.sender()) 247 @param act reference to the triggering action
248 @type QAction
249 """
250 idx = self.index(act)
232 url = idx.data(BookmarksModel.UrlRole) 251 url = idx.data(BookmarksModel.UrlRole)
233 252
234 from WebBrowser.WebBrowserWindow import WebBrowserWindow 253 from WebBrowser.WebBrowserWindow import WebBrowserWindow
235 WebBrowserWindow.mainWindow().newPrivateWindow(url) 254 WebBrowserWindow.mainWindow().newPrivateWindow(url)
236 self.__updateVisitCount(idx) 255 self.__updateVisitCount(idx)
237 256
238 def __removeBookmark(self): 257 def __removeBookmark(self, act):
239 """ 258 """
240 Private slot to remove a bookmark. 259 Private slot to remove a bookmark.
241 """ 260
242 idx = self.index(self.sender()) 261 @param act reference to the triggering action
262 @type QAction
263 """
264 idx = self.index(act)
243 self.removeEntry(idx) 265 self.removeEntry(idx)
244 266
245 def __edit(self): 267 def __edit(self, act):
246 """ 268 """
247 Private slot to edit a bookmarks properties. 269 Private slot to edit a bookmarks properties.
270
271 @param act reference to the triggering action
272 @type QAction
248 """ 273 """
249 from .BookmarkPropertiesDialog import BookmarkPropertiesDialog 274 from .BookmarkPropertiesDialog import BookmarkPropertiesDialog
250 275
251 idx = self.index(self.sender()) 276 idx = self.index(act)
252 node = self.model().node(idx) 277 node = self.model().node(idx)
253 dlg = BookmarkPropertiesDialog(node) 278 dlg = BookmarkPropertiesDialog(node)
254 dlg.exec_() 279 dlg.exec_()
255 280
256 ############################################################################## 281 ##############################################################################
323 return 348 return
324 349
325 self.addSeparator() 350 self.addSeparator()
326 act = self.addAction(self.tr("Default Home Page")) 351 act = self.addAction(self.tr("Default Home Page"))
327 act.setData("eric:home") 352 act.setData("eric:home")
328 act.triggered.connect(self.__defaultBookmarkTriggered) 353 act.triggered.connect(
354 lambda: self.__defaultBookmarkTriggered(act))
329 act = self.addAction(self.tr("Speed Dial")) 355 act = self.addAction(self.tr("Speed Dial"))
330 act.setData("eric:speeddial") 356 act.setData("eric:speeddial")
331 act.triggered.connect(self.__defaultBookmarkTriggered) 357 act.triggered.connect(
358 lambda: self.__defaultBookmarkTriggered(act))
332 self.addSeparator() 359 self.addSeparator()
333 act = self.addAction(self.tr("Open all in Tabs")) 360 act = self.addAction(self.tr("Open all in Tabs"))
334 act.triggered.connect(self.openAll) 361 act.triggered.connect(lambda: self.openAll(act))
335 362
336 def setInitialActions(self, actions): 363 def setInitialActions(self, actions):
337 """ 364 """
338 Public method to set the list of actions that should appear first in 365 Public method to set the list of actions that should appear first in
339 the menu. 366 the menu.
342 """ 369 """
343 self.__initialActions = actions[:] 370 self.__initialActions = actions[:]
344 for act in self.__initialActions: 371 for act in self.__initialActions:
345 self.addAction(act) 372 self.addAction(act)
346 373
347 def __defaultBookmarkTriggered(self): 374 def __defaultBookmarkTriggered(self, act):
348 """ 375 """
349 Private slot handling the default bookmark menu entries. 376 Private slot handling the default bookmark menu entries.
350 """ 377
351 act = self.sender() 378 @param act reference to the action object
379 @type QAction
380 """
352 urlStr = act.data() 381 urlStr = act.data()
353 if urlStr.startswith("eric:"): 382 if urlStr.startswith("eric:"):
354 self.openUrl.emit(QUrl(urlStr), "") 383 self.openUrl.emit(QUrl(urlStr), "")

eric ide

mercurial