mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
[Bookmarks] Various smaller changes
BookmarksTreeView: Select & ensure visibility of newly added bookmark BookmarksTools: Added function to open folder in tabs LocationCompleterModel: Removed bookmarks bits in createQuery QupZilla: loadAddress now opens new tab if current tab is pinned
This commit is contained in:
parent
83b8b0b666
commit
395b865d55
|
@ -1384,9 +1384,14 @@ void QupZilla::loadActionUrlInNewNotSelectedTab(QObject* obj)
|
|||
|
||||
void QupZilla::loadAddress(const QUrl &url)
|
||||
{
|
||||
// TOOD: If current tab is pinned, it should open new tab instead
|
||||
weView()->setFocus();
|
||||
weView()->load(url);
|
||||
if (weView()->webTab()->isPinned()) {
|
||||
int index = m_tabWidget->addView(url, qzSettings->newTabPosition);
|
||||
weView(index)->setFocus();
|
||||
}
|
||||
else {
|
||||
weView()->setFocus();
|
||||
weView()->load(url);
|
||||
}
|
||||
}
|
||||
|
||||
void QupZilla::showCookieManager()
|
||||
|
|
|
@ -291,8 +291,10 @@ void BookmarksManager::addBookmark(BookmarkItem* item)
|
|||
BookmarkItem* parent = parentForNewBookmark();
|
||||
Q_ASSERT(parent);
|
||||
|
||||
// TODO: Make sure parent is expanded
|
||||
m_bookmarks->addBookmark(parent, item);
|
||||
|
||||
ui->tree->selectBookmark(item);
|
||||
ui->tree->ensureBookmarkVisible(item);
|
||||
}
|
||||
|
||||
BookmarkItem* BookmarksManager::parentForNewBookmark() const
|
||||
|
|
|
@ -115,13 +115,8 @@ void BookmarksMenu::openFolder(BookmarkItem* item)
|
|||
{
|
||||
Q_ASSERT(item->isFolder());
|
||||
|
||||
foreach (BookmarkItem* child, item->children()) {
|
||||
if (child->isUrl()) {
|
||||
openBookmarkInNewTab(child);
|
||||
}
|
||||
else if (child->isFolder()) {
|
||||
openFolder(child);
|
||||
}
|
||||
if (m_window) {
|
||||
BookmarksTools::openFolderInTabs(m_window, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,6 +214,10 @@ void BookmarksMenu::addFolder(Menu* menu, BookmarkItem* folder)
|
|||
foreach (BookmarkItem* child, folder->children()) {
|
||||
addItem(m, child);
|
||||
}
|
||||
|
||||
if (folder->children().isEmpty()) {
|
||||
m->addAction(tr("Empty"))->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksMenu::addBookmark(Menu* menu, BookmarkItem* bookmark)
|
||||
|
|
|
@ -292,7 +292,7 @@ QModelIndex BookmarksModel::index(int row, int column, const QModelIndex &parent
|
|||
return createIndex(row, column, parentItem->children().at(row));
|
||||
}
|
||||
|
||||
QModelIndex BookmarksModel::index(BookmarkItem* item) const
|
||||
QModelIndex BookmarksModel::index(BookmarkItem* item, int column) const
|
||||
{
|
||||
BookmarkItem* parent = item->parent();
|
||||
|
||||
|
@ -300,7 +300,7 @@ QModelIndex BookmarksModel::index(BookmarkItem* item) const
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
return createIndex(parent->children().indexOf(item), 0, item);
|
||||
return createIndex(parent->children().indexOf(item), column, item);
|
||||
}
|
||||
|
||||
BookmarkItem* BookmarksModel::item(const QModelIndex &index) const
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex index(BookmarkItem* item) const;
|
||||
QModelIndex index(BookmarkItem* item, int column = 0) const;
|
||||
|
||||
BookmarkItem* item(const QModelIndex &index) const;
|
||||
|
||||
|
|
|
@ -219,26 +219,34 @@ void BookmarksTools::openBookmark(QupZilla* window, BookmarkItem* item)
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
|
||||
// TODO: Open all children in tabs for folder?
|
||||
if (!item || !item->isUrl()) {
|
||||
return;
|
||||
}
|
||||
|
||||
item->setVisitCount(item->visitCount() + 1);
|
||||
window->loadAddress(item->url());
|
||||
if (item->isFolder()) {
|
||||
openFolderInTabs(window, item);
|
||||
}
|
||||
else if (item->isUrl()) {
|
||||
item->setVisitCount(item->visitCount() + 1);
|
||||
window->loadAddress(item->url());
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksTools::openBookmarkInNewTab(QupZilla* window, BookmarkItem* item)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
|
||||
// TODO: Open all children in tabs for folder?
|
||||
if (!item || !item->isUrl()) {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
item->setVisitCount(item->visitCount() + 1);
|
||||
window->tabWidget()->addView(item->url(), item->title(), qzSettings->newTabPosition);
|
||||
if (item->isFolder()) {
|
||||
openFolderInTabs(window, item);
|
||||
}
|
||||
else if (item->isUrl()) {
|
||||
item->setVisitCount(item->visitCount() + 1);
|
||||
window->tabWidget()->addView(item->url(), item->title(), qzSettings->newTabPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksTools::openBookmarkInNewWindow(BookmarkItem* item)
|
||||
|
@ -246,3 +254,18 @@ void BookmarksTools::openBookmarkInNewWindow(BookmarkItem* item)
|
|||
item->setVisitCount(item->visitCount() + 1);
|
||||
mApp->makeNewWindow(Qz::BW_NewWindow, item->url());
|
||||
}
|
||||
|
||||
void BookmarksTools::openFolderInTabs(QupZilla* window, BookmarkItem* folder)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
Q_ASSERT(folder->isFolder());
|
||||
|
||||
foreach (BookmarkItem* child, folder->children()) {
|
||||
if (child->isUrl()) {
|
||||
openBookmarkInNewTab(window, child);
|
||||
}
|
||||
else if (child->isFolder()) {
|
||||
openFolderInTabs(window, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ public:
|
|||
static void openBookmark(QupZilla* window, BookmarkItem* item);
|
||||
static void openBookmarkInNewTab(QupZilla* window, BookmarkItem* item);
|
||||
static void openBookmarkInNewWindow(BookmarkItem* item);
|
||||
static void openFolderInTabs(QupZilla* window, BookmarkItem* folder);
|
||||
};
|
||||
|
||||
#endif // BOOKMARKSTOOLS_H
|
||||
|
|
|
@ -70,6 +70,11 @@ void BookmarksTreeView::setViewType(BookmarksTreeView::ViewType type)
|
|||
restoreExpandedState(QModelIndex());
|
||||
}
|
||||
|
||||
BookmarksModel* BookmarksTreeView::model() const
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
BookmarkItem* BookmarksTreeView::selectedBookmark() const
|
||||
{
|
||||
QList<BookmarkItem*> items = selectedBookmarks();
|
||||
|
@ -88,6 +93,27 @@ QList<BookmarkItem*> BookmarksTreeView::selectedBookmarks() const
|
|||
return items;
|
||||
}
|
||||
|
||||
void BookmarksTreeView::selectBookmark(BookmarkItem* item)
|
||||
{
|
||||
QModelIndex col0 = m_model->index(item, 0);
|
||||
QModelIndex col1 = m_model->index(item, 1);
|
||||
|
||||
selectionModel()->clearSelection();
|
||||
selectionModel()->select(col0, QItemSelectionModel::Select);
|
||||
selectionModel()->select(col1, QItemSelectionModel::Select);
|
||||
}
|
||||
|
||||
void BookmarksTreeView::ensureBookmarkVisible(BookmarkItem* item)
|
||||
{
|
||||
QModelIndex index = m_model->index(item);
|
||||
QModelIndex parent = m_model->parent(index);
|
||||
|
||||
while (parent.isValid()) {
|
||||
setExpanded(parent, true);
|
||||
parent = m_model->parent(parent);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksTreeView::indexExpanded(const QModelIndex &parent)
|
||||
{
|
||||
BookmarkItem* item = m_model->item(parent);
|
||||
|
|
|
@ -41,11 +41,17 @@ public:
|
|||
ViewType viewType() const;
|
||||
void setViewType(ViewType type);
|
||||
|
||||
BookmarksModel* model() const;
|
||||
|
||||
// Returns null if more than one (or zero) bookmarks are selected
|
||||
BookmarkItem* selectedBookmark() const;
|
||||
// Returns all selected bookmarks
|
||||
QList<BookmarkItem*> selectedBookmarks() const;
|
||||
|
||||
void selectBookmark(BookmarkItem* item);
|
||||
// Expand up to root item
|
||||
void ensureBookmarkVisible(BookmarkItem* item);
|
||||
|
||||
signals:
|
||||
// Open bookmark in current tab
|
||||
void bookmarkActivated(BookmarkItem* item);
|
||||
|
@ -76,7 +82,6 @@ private:
|
|||
Bookmarks* m_bookmarks;
|
||||
BookmarksModel* m_model;
|
||||
ViewType m_type;
|
||||
|
||||
};
|
||||
|
||||
#endif // BOOKMARKSTREEVIEW_H
|
||||
|
|
|
@ -184,18 +184,14 @@ QString LocationCompleterModel::completeDomain(const QString &text)
|
|||
}
|
||||
|
||||
QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const QString &orderBy,
|
||||
const QList<QUrl> &alreadyFound, int limit, bool bookmarks, bool exactMatch)
|
||||
const QList<QUrl> &alreadyFound, int limit, bool exactMatch)
|
||||
{
|
||||
QString table = bookmarks ? "bookmarks" : "history";
|
||||
// TODO: As bookmarks are no longer in database, replace table with "history"
|
||||
QString table = "history";
|
||||
QString query = QString("SELECT %1.id, %1.url, %1.title, history.count").arg(table);
|
||||
QStringList searchList;
|
||||
|
||||
if (bookmarks) {
|
||||
query.append(QLatin1String(", bookmarks.icon FROM bookmarks LEFT JOIN history ON bookmarks.url=history.url "));
|
||||
}
|
||||
else {
|
||||
query.append(QLatin1String(" FROM history "));
|
||||
}
|
||||
query.append(QLatin1String(" FROM history "));
|
||||
|
||||
query.append(QLatin1String("WHERE "));
|
||||
if (exactMatch) {
|
||||
|
|
|
@ -62,7 +62,7 @@ private:
|
|||
};
|
||||
|
||||
QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList<QUrl> &alreadyFound,
|
||||
int limit, bool bookmarks = false, bool exactMatch = false);
|
||||
int limit, bool exactMatch = false);
|
||||
|
||||
TabPosition tabPositionForUrl(const QUrl &url) const;
|
||||
TabPosition tabPositionForEncodedUrl(const QString &encodedUrl) const;
|
||||
|
|
Loading…
Reference in New Issue
Block a user