--- a/src/eric7/WebBrowser/Bookmarks/BookmarksManager.py Sun Jan 07 11:42:41 2024 +0100 +++ b/src/eric7/WebBrowser/Bookmarks/BookmarksManager.py Sun Jan 07 12:40:00 2024 +0100 @@ -8,6 +8,7 @@ """ import contextlib +import enum import os import pathlib @@ -34,10 +35,15 @@ BOOKMARKBAR = QT_TRANSLATE_NOOP("BookmarksManager", "Bookmarks Bar") BOOKMARKMENU = QT_TRANSLATE_NOOP("BookmarksManager", "Bookmarks Menu") -# TODO: change this to an enum -StartRoot = 0 -StartMenu = 1 -StartToolBar = 2 + +class BookmarkSearchStart(enum.Enum): + """ + Class defining the start points for bookmark searches. + """ + + Root = 0 + Menu = 1 + ToolBar = 2 class BookmarksManager(QObject): @@ -465,21 +471,20 @@ for node in nodes: self.bookmarksModel().entryChanged(node) - def bookmarkForUrl(self, url, start=StartRoot): + def bookmarkForUrl(self, url, start=BookmarkSearchStart.Root): """ Public method to get a bookmark node for a given URL. @param url URL of the bookmark to search for @type QUrl or str @param start indicator for the start of the search - (StartRoot, StartMenu, StartToolBar) - @type int + @type BookmarkSearchStart @return bookmark node for the given url @rtype BookmarkNode """ - if start == StartMenu: + if start == BookmarkSearchStart.Menu: startNode = self.__menu - elif start == StartToolBar: + elif start == BookmarkSearchStart.ToolBar: startNode = self.__toolbar else: startNode = self.__bookmarkRootNode @@ -512,21 +517,20 @@ return bm return None - def bookmarksForUrl(self, url, start=StartRoot): + def bookmarksForUrl(self, url, start=BookmarkSearchStart.Root): """ Public method to get a list of bookmark nodes for a given URL. @param url URL of the bookmarks to search for @type QUrl or str @param start indicator for the start of the search - (StartRoot, StartMenu, StartToolBar) - @type int + @type BookmarkSearchStart @return list of bookmark nodes for the given url @rtype list of BookmarkNode """ - if start == StartMenu: + if start == BookmarkSearchStart.Menu: startNode = self.__menu - elif start == StartToolBar: + elif start == BookmarkSearchStart.ToolBar: startNode = self.__toolbar else: startNode = self.__bookmarkRootNode