src/eric7/WebBrowser/Bookmarks/BookmarksManager.py

branch
eric7
changeset 10485
287a3ae95e00
parent 10482
72d9b5ea39b4
child 10926
9ef616cd220d
equal deleted inserted replaced
10484:ad7a6d699a0d 10485:287a3ae95e00
6 """ 6 """
7 Module implementing the bookmarks manager. 7 Module implementing the bookmarks manager.
8 """ 8 """
9 9
10 import contextlib 10 import contextlib
11 import enum
11 import os 12 import os
12 import pathlib 13 import pathlib
13 14
14 from PyQt6.QtCore import ( 15 from PyQt6.QtCore import (
15 QT_TRANSLATE_NOOP, 16 QT_TRANSLATE_NOOP,
32 from .BookmarkNode import BookmarkNode, BookmarkNodeType, BookmarkTimestampType 33 from .BookmarkNode import BookmarkNode, BookmarkNodeType, BookmarkTimestampType
33 34
34 BOOKMARKBAR = QT_TRANSLATE_NOOP("BookmarksManager", "Bookmarks Bar") 35 BOOKMARKBAR = QT_TRANSLATE_NOOP("BookmarksManager", "Bookmarks Bar")
35 BOOKMARKMENU = QT_TRANSLATE_NOOP("BookmarksManager", "Bookmarks Menu") 36 BOOKMARKMENU = QT_TRANSLATE_NOOP("BookmarksManager", "Bookmarks Menu")
36 37
37 # TODO: change this to an enum 38
38 StartRoot = 0 39 class BookmarkSearchStart(enum.Enum):
39 StartMenu = 1 40 """
40 StartToolBar = 2 41 Class defining the start points for bookmark searches.
42 """
43
44 Root = 0
45 Menu = 1
46 ToolBar = 2
41 47
42 48
43 class BookmarksManager(QObject): 49 class BookmarksManager(QObject):
44 """ 50 """
45 Class implementing the bookmarks manager. 51 Class implementing the bookmarks manager.
463 url = url.toString() 469 url = url.toString()
464 nodes = self.bookmarksForUrl(url) 470 nodes = self.bookmarksForUrl(url)
465 for node in nodes: 471 for node in nodes:
466 self.bookmarksModel().entryChanged(node) 472 self.bookmarksModel().entryChanged(node)
467 473
468 def bookmarkForUrl(self, url, start=StartRoot): 474 def bookmarkForUrl(self, url, start=BookmarkSearchStart.Root):
469 """ 475 """
470 Public method to get a bookmark node for a given URL. 476 Public method to get a bookmark node for a given URL.
471 477
472 @param url URL of the bookmark to search for 478 @param url URL of the bookmark to search for
473 @type QUrl or str 479 @type QUrl or str
474 @param start indicator for the start of the search 480 @param start indicator for the start of the search
475 (StartRoot, StartMenu, StartToolBar) 481 @type BookmarkSearchStart
476 @type int
477 @return bookmark node for the given url 482 @return bookmark node for the given url
478 @rtype BookmarkNode 483 @rtype BookmarkNode
479 """ 484 """
480 if start == StartMenu: 485 if start == BookmarkSearchStart.Menu:
481 startNode = self.__menu 486 startNode = self.__menu
482 elif start == StartToolBar: 487 elif start == BookmarkSearchStart.ToolBar:
483 startNode = self.__toolbar 488 startNode = self.__toolbar
484 else: 489 else:
485 startNode = self.__bookmarkRootNode 490 startNode = self.__bookmarkRootNode
486 if startNode is None: 491 if startNode is None:
487 return None 492 return None
510 bm = node 515 bm = node
511 if bm is not None: 516 if bm is not None:
512 return bm 517 return bm
513 return None 518 return None
514 519
515 def bookmarksForUrl(self, url, start=StartRoot): 520 def bookmarksForUrl(self, url, start=BookmarkSearchStart.Root):
516 """ 521 """
517 Public method to get a list of bookmark nodes for a given URL. 522 Public method to get a list of bookmark nodes for a given URL.
518 523
519 @param url URL of the bookmarks to search for 524 @param url URL of the bookmarks to search for
520 @type QUrl or str 525 @type QUrl or str
521 @param start indicator for the start of the search 526 @param start indicator for the start of the search
522 (StartRoot, StartMenu, StartToolBar) 527 @type BookmarkSearchStart
523 @type int
524 @return list of bookmark nodes for the given url 528 @return list of bookmark nodes for the given url
525 @rtype list of BookmarkNode 529 @rtype list of BookmarkNode
526 """ 530 """
527 if start == StartMenu: 531 if start == BookmarkSearchStart.Menu:
528 startNode = self.__menu 532 startNode = self.__menu
529 elif start == StartToolBar: 533 elif start == BookmarkSearchStart.ToolBar:
530 startNode = self.__toolbar 534 startNode = self.__toolbar
531 else: 535 else:
532 startNode = self.__bookmarkRootNode 536 startNode = self.__bookmarkRootNode
533 if startNode is None: 537 if startNode is None:
534 return [] 538 return []

eric ide

mercurial