refactor: browser use object
This commit is contained in:
parent
d519843e52
commit
336ea968de
|
@ -22,15 +22,7 @@ QtObject:
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc init*(self: BrowserView) =
|
proc init*(self: BrowserView) =
|
||||||
var bookmarks: seq[Bookmark] = @[]
|
let bookmarks = self.status.browser.getBookmarks()
|
||||||
try:
|
|
||||||
let responseResult = self.status.browser.getBookmarks().parseJson["result"]
|
|
||||||
if responseResult.kind != JNull:
|
|
||||||
for bookmark in responseResult:
|
|
||||||
bookmarks.add(Bookmark(url: bookmark["url"].getStr, name: bookmark["name"].getStr, imageUrl: bookmark["imageUrl"].getStr))
|
|
||||||
except:
|
|
||||||
# Bad JSON. Just use the empty array
|
|
||||||
discard
|
|
||||||
self.bookmarks.setNewData(bookmarks)
|
self.bookmarks.setNewData(bookmarks)
|
||||||
|
|
||||||
proc bookmarksChanged*(self: BrowserView) {.signal.}
|
proc bookmarksChanged*(self: BrowserView) {.signal.}
|
||||||
|
@ -43,7 +35,7 @@ QtObject:
|
||||||
notify = bookmarksChanged
|
notify = bookmarksChanged
|
||||||
|
|
||||||
proc addBookmark*(self: BrowserView, url: string, name: string) {.slot.} =
|
proc addBookmark*(self: BrowserView, url: string, name: string) {.slot.} =
|
||||||
let bookmark = self.status.browser.storeBookmark(url, name)
|
let bookmark = self.status.browser.storeBookmark(Bookmark(url: url, name: name))
|
||||||
self.bookmarks.addBookmarkItemToList(bookmark)
|
self.bookmarks.addBookmarkItemToList(bookmark)
|
||||||
self.bookmarksChanged()
|
self.bookmarksChanged()
|
||||||
|
|
||||||
|
@ -55,12 +47,12 @@ QtObject:
|
||||||
self.status.browser.deleteBookmark(url)
|
self.status.browser.deleteBookmark(url)
|
||||||
self.bookmarksChanged()
|
self.bookmarksChanged()
|
||||||
|
|
||||||
proc modifyBookmark*(self: BrowserView, ogUrl: string, newUrl: string, newName: string) {.slot.} =
|
proc modifyBookmark*(self: BrowserView, originalUrl: string, newUrl: string, newName: string) {.slot.} =
|
||||||
let index = self.bookmarks.getBookmarkIndexByUrl(ogUrl)
|
let index = self.bookmarks.getBookmarkIndexByUrl(originalUrl)
|
||||||
if index == -1:
|
if index == -1:
|
||||||
# Somehow we don't know this URL. Let's just add it as a new one
|
|
||||||
self.addBookmark(newUrl, newName)
|
self.addBookmark(newUrl, newName)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.bookmarks.modifyBookmarkItemFromList(index, newUrl, newName)
|
self.bookmarks.modifyBookmarkItemFromList(index, newUrl, newName)
|
||||||
self.status.browser.updateBookmark(ogUrl, newUrl, newName)
|
self.status.browser.updateBookmark(originalUrl, Bookmark(url: newUrl, name: newName))
|
||||||
self.bookmarksChanged()
|
self.bookmarksChanged()
|
||||||
|
|
|
@ -35,6 +35,6 @@ GridView {
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
browserModel.removeBookmark("")
|
browserModel.removeBookmark("")
|
||||||
}
|
}
|
||||||
browserModel.addBookmark("", qsTr("Add Favorite"))
|
browserModel.addBookmark("", qsTr("Add Favorite"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue