From dcce6d6fbbf3e47f49b4a44fb4de02e3f25d1290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dutkiewicz?= Date: Wed, 11 Dec 2013 17:49:47 +0100 Subject: [PATCH] Allow to add folders and separators --- .../bookmarks/BookmarksContentsWidget.cpp | 51 +++++++++++++++---- .../bookmarks/BookmarksContentsWidget.h | 3 ++ src/ui/BookmarkPropertiesDialog.cpp | 3 +- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp b/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp index e632bad38e..5ea631f7fc 100644 --- a/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp +++ b/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp @@ -7,6 +7,7 @@ #include "ui_BookmarksContentsWidget.h" +#include #include namespace Otter @@ -27,6 +28,13 @@ BookmarksContentsWidget::BookmarksContentsWidget(Window *window) : ContentsWidge m_ui->bookmarksView->setModel(m_model); + QMenu *addMenu = new QMenu(m_ui->addButton); + addMenu->addAction(Utils::getIcon("inode-directory"), tr("Add Folder"), this, SLOT(addFolder())); + addMenu->addAction(tr("Add Bookmark"), this, SLOT(addBookmark())); + addMenu->addAction(tr("Add Separator"), this, SLOT(addSeparator())); + + m_ui->addButton->setMenu(addMenu); + connect(BookmarksManager::getInstance(), SIGNAL(folderModified(int)), this, SLOT(updateFolder(int))); connect(m_ui->bookmarksView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateActions())); connect(m_ui->propertiesButton, SIGNAL(clicked()), this, SLOT(bookmarkProperties())); @@ -104,19 +112,20 @@ void BookmarksContentsWidget::addBookmark() BookmarkInformation *bookmark = new BookmarkInformation(); bookmark->type = UrlBookmark; - int folder = 0; + BookmarkPropertiesDialog dialog(bookmark, findFolder(m_ui->bookmarksView->currentIndex()), this); - if (m_ui->bookmarksView->currentIndex().isValid()) + if (dialog.exec() == QDialog::Rejected) { - BookmarkInformation *selectedBookmark = static_cast(m_ui->bookmarksView->currentIndex().data(Qt::UserRole).value()); - - if (selectedBookmark) - { - folder = ((selectedBookmark->type == FolderBookmark) ? selectedBookmark->identifier : selectedBookmark->parent); - } + delete bookmark; } +} + +void BookmarksContentsWidget::addFolder() +{ + BookmarkInformation *bookmark = new BookmarkInformation(); + bookmark->type = FolderBookmark; - BookmarkPropertiesDialog dialog(bookmark, folder, this); + BookmarkPropertiesDialog dialog(bookmark, findFolder(m_ui->bookmarksView->currentIndex()), this); if (dialog.exec() == QDialog::Rejected) { @@ -124,6 +133,15 @@ void BookmarksContentsWidget::addBookmark() } } +void BookmarksContentsWidget::addSeparator() +{ + BookmarkInformation *bookmark = new BookmarkInformation(); + bookmark->type = SeparatorBookmark; + bookmark->parent = findFolder(m_ui->bookmarksView->currentIndex()); + + BookmarksManager::addBookmark(bookmark, bookmark->parent); +} + void BookmarksContentsWidget::deleteBookmark() { BookmarkInformation *bookmark = static_cast(m_ui->bookmarksView->currentIndex().data(Qt::UserRole).value()); @@ -297,6 +315,21 @@ HistoryInformation BookmarksContentsWidget::getHistory() const return information; } +int BookmarksContentsWidget::findFolder(const QModelIndex &index) +{ + if (index.isValid()) + { + BookmarkInformation *bookmark = static_cast(index.data(Qt::UserRole).value()); + + if (bookmark) + { + return ((bookmark->type == FolderBookmark) ? bookmark->identifier : bookmark->parent); + } + } + + return 0; +} + int BookmarksContentsWidget::getZoom() const { return 100; diff --git a/src/modules/windows/bookmarks/BookmarksContentsWidget.h b/src/modules/windows/bookmarks/BookmarksContentsWidget.h index 353a0433e2..c24340c814 100644 --- a/src/modules/windows/bookmarks/BookmarksContentsWidget.h +++ b/src/modules/windows/bookmarks/BookmarksContentsWidget.h @@ -49,10 +49,13 @@ public slots: protected: void changeEvent(QEvent *event); QStandardItem* findFolder(int folder, QStandardItem *item = NULL); + int findFolder(const QModelIndex &index); protected slots: void addBookmark(BookmarkInformation *bookmark, QStandardItem *parent = NULL); void addBookmark(); + void addFolder(); + void addSeparator(); void deleteBookmark(); void bookmarkProperties(); void updateFolder(int folder); diff --git a/src/ui/BookmarkPropertiesDialog.cpp b/src/ui/BookmarkPropertiesDialog.cpp index adca929fef..162373e278 100644 --- a/src/ui/BookmarkPropertiesDialog.cpp +++ b/src/ui/BookmarkPropertiesDialog.cpp @@ -19,7 +19,8 @@ BookmarkPropertiesDialog::BookmarkPropertiesDialog(BookmarkInformation *bookmark m_ui->setupUi(this); m_ui->titleLineEdit->setText(m_bookmark->title); m_ui->addressLineEdit->setText(m_bookmark->url); - m_ui->addressLineEdit->setEnabled(m_bookmark->type == UrlBookmark); + m_ui->addressLineEdit->setVisible(m_bookmark->type == UrlBookmark); + m_ui->addressLabel->setVisible(m_bookmark->type == UrlBookmark); m_ui->descriptionTextEdit->setPlainText(m_bookmark->description); if (bookmark->parent < 0)