141 Private slot to handle the context menu request for the bookmarks tree. |
141 Private slot to handle the context menu request for the bookmarks tree. |
142 |
142 |
143 @param pos position the context menu was requested |
143 @param pos position the context menu was requested |
144 @type QPoint |
144 @type QPoint |
145 """ |
145 """ |
146 from .BookmarkNode import BookmarkNode |
146 from .BookmarkNode import BookmarkNodeType |
147 |
147 |
148 menu = QMenu() |
148 menu = QMenu() |
149 idx = self.bookmarksTree.indexAt(pos) |
149 idx = self.bookmarksTree.indexAt(pos) |
150 idx = idx.sibling(idx.row(), 0) |
150 idx = idx.sibling(idx.row(), 0) |
151 sourceIndex = self.__proxyModel.mapToSource(idx) |
151 sourceIndex = self.__proxyModel.mapToSource(idx) |
152 node = self.__bookmarksModel.node(sourceIndex) |
152 node = self.__bookmarksModel.node(sourceIndex) |
153 if idx.isValid() and node.type() != BookmarkNode.Folder: |
153 if idx.isValid() and node.type() != BookmarkNodeType.Folder: |
154 menu.addAction(self.tr("&Open"), self.__openBookmarkInCurrentTab) |
154 menu.addAction(self.tr("&Open"), self.__openBookmarkInCurrentTab) |
155 menu.addAction(self.tr("Open in New &Tab"), self.__openBookmarkInNewTab) |
155 menu.addAction(self.tr("Open in New &Tab"), self.__openBookmarkInNewTab) |
156 menu.addAction( |
156 menu.addAction( |
157 self.tr("Open in New &Background Tab"), |
157 self.tr("Open in New &Background Tab"), |
158 self.__openBookmarkInNewBackgroundTab, |
158 self.__openBookmarkInNewBackgroundTab, |
167 menu.addSeparator() |
167 menu.addSeparator() |
168 act = menu.addAction(self.tr("Edit &Name"), self.__editName) |
168 act = menu.addAction(self.tr("Edit &Name"), self.__editName) |
169 act.setEnabled( |
169 act.setEnabled( |
170 idx.flags() & Qt.ItemFlag.ItemIsEditable == Qt.ItemFlag.ItemIsEditable |
170 idx.flags() & Qt.ItemFlag.ItemIsEditable == Qt.ItemFlag.ItemIsEditable |
171 ) |
171 ) |
172 if idx.isValid() and node.type() != BookmarkNode.Folder: |
172 if idx.isValid() and node.type() != BookmarkNodeType.Folder: |
173 menu.addAction(self.tr("Edit &Address"), self.__editAddress) |
173 menu.addAction(self.tr("Edit &Address"), self.__editAddress) |
174 menu.addSeparator() |
174 menu.addSeparator() |
175 act = menu.addAction(self.tr("&Delete"), self.bookmarksTree.removeSelected) |
175 act = menu.addAction(self.tr("&Delete"), self.bookmarksTree.removeSelected) |
176 act.setEnabled( |
176 act.setEnabled( |
177 idx.flags() & Qt.ItemFlag.ItemIsDragEnabled == Qt.ItemFlag.ItemIsDragEnabled |
177 idx.flags() & Qt.ItemFlag.ItemIsDragEnabled == Qt.ItemFlag.ItemIsDragEnabled |
179 menu.addSeparator() |
179 menu.addSeparator() |
180 act = menu.addAction(self.tr("&Properties..."), self.__edit) |
180 act = menu.addAction(self.tr("&Properties..."), self.__edit) |
181 act.setEnabled( |
181 act.setEnabled( |
182 idx.flags() & Qt.ItemFlag.ItemIsEditable == Qt.ItemFlag.ItemIsEditable |
182 idx.flags() & Qt.ItemFlag.ItemIsEditable == Qt.ItemFlag.ItemIsEditable |
183 ) |
183 ) |
184 if idx.isValid() and node.type() == BookmarkNode.Folder: |
184 if idx.isValid() and node.type() == BookmarkNodeType.Folder: |
185 menu.addSeparator() |
185 menu.addSeparator() |
186 menu.addAction(self.tr("New &Folder..."), self.__newFolder) |
186 menu.addAction(self.tr("New &Folder..."), self.__newFolder) |
187 menu.exec(QCursor.pos()) |
187 menu.exec(QCursor.pos()) |
188 |
188 |
189 @pyqtSlot(QModelIndex) |
189 @pyqtSlot(QModelIndex) |
246 @type bool |
246 @type bool |
247 @param background flag indicating to open the bookmark in a new |
247 @param background flag indicating to open the bookmark in a new |
248 background tab |
248 background tab |
249 @type bool |
249 @type bool |
250 """ |
250 """ |
251 from .BookmarkNode import BookmarkNode |
251 from .BookmarkNode import BookmarkNodeType |
252 from .BookmarksModel import BookmarksModel |
252 from .BookmarksModel import BookmarksModel |
253 |
253 |
254 idx = self.bookmarksTree.currentIndex() |
254 idx = self.bookmarksTree.currentIndex() |
255 sourceIndex = self.__proxyModel.mapToSource(idx) |
255 sourceIndex = self.__proxyModel.mapToSource(idx) |
256 node = self.__bookmarksModel.node(sourceIndex) |
256 node = self.__bookmarksModel.node(sourceIndex) |
257 if ( |
257 if ( |
258 not idx.parent().isValid() |
258 not idx.parent().isValid() |
259 or node is None |
259 or node is None |
260 or node.type() == BookmarkNode.Folder |
260 or node.type() == BookmarkNodeType.Folder |
261 ): |
261 ): |
262 return |
262 return |
263 |
263 |
264 if newWindow: |
264 if newWindow: |
265 url = idx.sibling(idx.row(), 1).data(BookmarksModel.UrlRole) |
265 url = idx.sibling(idx.row(), 1).data(BookmarksModel.UrlRole) |
316 |
316 |
317 def __newFolder(self): |
317 def __newFolder(self): |
318 """ |
318 """ |
319 Private slot to add a new bookmarks folder. |
319 Private slot to add a new bookmarks folder. |
320 """ |
320 """ |
321 from .BookmarkNode import BookmarkNode |
321 from .BookmarkNode import BookmarkNode, BookmarkNodeType |
322 |
322 |
323 currentIndex = self.bookmarksTree.currentIndex() |
323 currentIndex = self.bookmarksTree.currentIndex() |
324 idx = QModelIndex(currentIndex) |
324 idx = QModelIndex(currentIndex) |
325 sourceIndex = self.__proxyModel.mapToSource(idx) |
325 sourceIndex = self.__proxyModel.mapToSource(idx) |
326 sourceNode = self.__bookmarksModel.node(sourceIndex) |
326 sourceNode = self.__bookmarksModel.node(sourceIndex) |
327 row = -1 # append new folder as the last item per default |
327 row = -1 # append new folder as the last item per default |
328 |
328 |
329 if sourceNode is not None and sourceNode.type() != BookmarkNode.Folder: |
329 if sourceNode is not None and sourceNode.type() != BookmarkNodeType.Folder: |
330 # If the selected item is not a folder, add a new folder to the |
330 # If the selected item is not a folder, add a new folder to the |
331 # parent folder, but directly below the selected item. |
331 # parent folder, but directly below the selected item. |
332 idx = idx.parent() |
332 idx = idx.parent() |
333 row = currentIndex.row() + 1 |
333 row = currentIndex.row() + 1 |
334 |
334 |