Skip to content

Commit

Permalink
Allow to add folders and separators
Browse files Browse the repository at this point in the history
  • Loading branch information
Emdek committed Dec 11, 2013
1 parent ed8bee9 commit dcce6d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
51 changes: 42 additions & 9 deletions src/modules/windows/bookmarks/BookmarksContentsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ui_BookmarksContentsWidget.h"

#include <QtWidgets/QMenu>
#include <QtWidgets/QMessageBox>

namespace Otter
Expand All @@ -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()));
Expand Down Expand Up @@ -104,26 +112,36 @@ 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<BookmarkInformation*>(m_ui->bookmarksView->currentIndex().data(Qt::UserRole).value<void*>());

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)
{
delete bookmark;
}
}

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<BookmarkInformation*>(m_ui->bookmarksView->currentIndex().data(Qt::UserRole).value<void*>());
Expand Down Expand Up @@ -297,6 +315,21 @@ HistoryInformation BookmarksContentsWidget::getHistory() const
return information;
}

int BookmarksContentsWidget::findFolder(const QModelIndex &index)
{
if (index.isValid())
{
BookmarkInformation *bookmark = static_cast<BookmarkInformation*>(index.data(Qt::UserRole).value<void*>());

if (bookmark)
{
return ((bookmark->type == FolderBookmark) ? bookmark->identifier : bookmark->parent);
}
}

return 0;
}

int BookmarksContentsWidget::getZoom() const
{
return 100;
Expand Down
3 changes: 3 additions & 0 deletions src/modules/windows/bookmarks/BookmarksContentsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/ui/BookmarkPropertiesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dcce6d6

Please sign in to comment.