forked from qt-creator/qt-creator
Move the "Move Up/Down" items from bookmarks menu to bookmarks view.
Better would be to support drag and drop in the view, but this might be better than nothing. Task-number: QTCREATORBUG-466
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/uniqueidmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
@@ -227,15 +228,24 @@ BookmarkView::~BookmarkView()
|
||||
void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu menu;
|
||||
QAction *remove = menu.addAction(tr("&Remove Bookmark"));
|
||||
QAction *removeAll = menu.addAction(tr("Remove all Bookmarks"));
|
||||
QAction *moveUp = menu.addAction(tr("Move Up"));
|
||||
QAction *moveDown = menu.addAction(tr("Move Down"));
|
||||
QAction *remove = menu.addAction(tr("&Remove"));
|
||||
QAction *removeAll = menu.addAction(tr("Remove All"));
|
||||
m_contextMenuIndex = indexAt(event->pos());
|
||||
if (!m_contextMenuIndex.isValid())
|
||||
if (!m_contextMenuIndex.isValid()) {
|
||||
moveUp->setEnabled(false);
|
||||
moveDown->setEnabled(false);
|
||||
remove->setEnabled(false);
|
||||
}
|
||||
|
||||
if (model()->rowCount() == 0)
|
||||
removeAll->setEnabled(false);
|
||||
|
||||
connect(moveUp, SIGNAL(triggered()),
|
||||
m_manager, SLOT(moveUp()));
|
||||
connect(moveDown, SIGNAL(triggered()),
|
||||
m_manager, SLOT(moveDown()));
|
||||
connect(remove, SIGNAL(triggered()),
|
||||
this, SLOT(removeFromContextMenu()));
|
||||
connect(removeAll, SIGNAL(triggered()),
|
||||
@@ -251,18 +261,16 @@ void BookmarkView::removeFromContextMenu()
|
||||
|
||||
void BookmarkView::removeBookmark(const QModelIndex& index)
|
||||
{
|
||||
BookmarkManager *manager = static_cast<BookmarkManager *>(model());
|
||||
Bookmark *bm = manager->bookmarkForIndex(index);
|
||||
manager->removeBookmark(bm);
|
||||
Bookmark *bm = m_manager->bookmarkForIndex(index);
|
||||
m_manager->removeBookmark(bm);
|
||||
}
|
||||
|
||||
// The perforcemance of this function could be greatly improved.
|
||||
//
|
||||
void BookmarkView::removeAll()
|
||||
{
|
||||
BookmarkManager *manager = static_cast<BookmarkManager *>(model());
|
||||
while (manager->rowCount()) {
|
||||
QModelIndex index = manager->index(0, 0);
|
||||
while (m_manager->rowCount()) {
|
||||
QModelIndex index = m_manager->index(0, 0);
|
||||
removeBookmark(index);
|
||||
}
|
||||
}
|
||||
@@ -271,6 +279,7 @@ void BookmarkView::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
BookmarkManager *manager = qobject_cast<BookmarkManager *>(model);
|
||||
QTC_ASSERT(manager, return);
|
||||
m_manager = manager;
|
||||
QListView::setModel(model);
|
||||
setSelectionModel(manager->selectionModel());
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
@@ -279,10 +288,9 @@ void BookmarkView::setModel(QAbstractItemModel *model)
|
||||
|
||||
void BookmarkView::gotoBookmark(const QModelIndex &index)
|
||||
{
|
||||
BookmarkManager *bm = static_cast<BookmarkManager *>(model());
|
||||
Bookmark *bk = bm->bookmarkForIndex(index);
|
||||
if (!bm->gotoBookmark(bk))
|
||||
bm->removeBookmark(bk);
|
||||
Bookmark *bk = m_manager->bookmarkForIndex(index);
|
||||
if (!m_manager->gotoBookmark(bk))
|
||||
m_manager->removeBookmark(bk);
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
@@ -151,6 +151,7 @@ protected:
|
||||
private:
|
||||
BookmarkContext *m_bookmarkContext;
|
||||
QModelIndex m_contextMenuIndex;
|
||||
BookmarkManager *m_manager;
|
||||
};
|
||||
|
||||
class BookmarkContext : public Core::IContext
|
||||
|
||||
@@ -98,21 +98,6 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *)
|
||||
cmd = am->registerAction(sep, QLatin1String("Bookmarks.Sep.Toggle"), textcontext);
|
||||
mbm->addAction(cmd);
|
||||
|
||||
// Move Up
|
||||
m_moveUpAction = new QAction(tr("Move Up"), this);
|
||||
cmd = am->registerAction(m_moveUpAction, BOOKMARKS_MOVEUP_ACTION, context);
|
||||
mbm->addAction(cmd);
|
||||
|
||||
// Move Down
|
||||
m_moveDownAction = new QAction(tr("Move Down"), this);
|
||||
cmd = am->registerAction(m_moveDownAction, BOOKMARKS_MOVEDOWN_ACTION, context);
|
||||
mbm->addAction(cmd);
|
||||
|
||||
sep = new QAction(this);
|
||||
sep->setSeparator(true);
|
||||
cmd = am->registerAction(sep, QLatin1String("Bookmarks.Sep.Navigation"), context);
|
||||
mbm->addAction(cmd);
|
||||
|
||||
//Previous
|
||||
m_prevAction = new QAction(tr("Previous Bookmark"), this);
|
||||
cmd = am->registerAction(m_prevAction, BOOKMARKS_PREV_ACTION, globalcontext);
|
||||
@@ -155,8 +140,6 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *)
|
||||
connect(m_nextAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(next()));
|
||||
connect(m_docPrevAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(prevInDocument()));
|
||||
connect(m_docNextAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(nextInDocument()));
|
||||
connect(m_moveUpAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(moveUp()));
|
||||
connect(m_moveDownAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(moveDown()));
|
||||
connect(m_bookmarkManager, SIGNAL(updateActions(int)), this, SLOT(updateActions(int)));
|
||||
updateActions(m_bookmarkManager->state());
|
||||
addAutoReleasedObject(new BookmarkViewFactory(m_bookmarkManager));
|
||||
@@ -192,8 +175,6 @@ void BookmarksPlugin::updateActions(int state)
|
||||
m_nextAction->setEnabled(hasbm);
|
||||
m_docPrevAction->setEnabled(hasdocbm);
|
||||
m_docNextAction->setEnabled(hasdocbm);
|
||||
m_moveUpAction->setEnabled(hasbm);
|
||||
m_moveDownAction->setEnabled(hasbm);
|
||||
}
|
||||
|
||||
void BookmarksPlugin::editorOpened(Core::IEditor *editor)
|
||||
|
||||
@@ -85,8 +85,6 @@ private:
|
||||
QAction *m_nextAction;
|
||||
QAction *m_docPrevAction;
|
||||
QAction *m_docNextAction;
|
||||
QAction *m_moveUpAction;
|
||||
QAction *m_moveDownAction;
|
||||
|
||||
QAction *m_bookmarkMarginAction;
|
||||
int m_bookmarkMarginActionLineNumber;
|
||||
|
||||
Reference in New Issue
Block a user