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/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/uniqueidmanager.h>
|
#include <coreplugin/uniqueidmanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/session.h>
|
#include <projectexplorer/session.h>
|
||||||
@@ -227,15 +228,24 @@ BookmarkView::~BookmarkView()
|
|||||||
void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
QAction *remove = menu.addAction(tr("&Remove Bookmark"));
|
QAction *moveUp = menu.addAction(tr("Move Up"));
|
||||||
QAction *removeAll = menu.addAction(tr("Remove all Bookmarks"));
|
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());
|
m_contextMenuIndex = indexAt(event->pos());
|
||||||
if (!m_contextMenuIndex.isValid())
|
if (!m_contextMenuIndex.isValid()) {
|
||||||
|
moveUp->setEnabled(false);
|
||||||
|
moveDown->setEnabled(false);
|
||||||
remove->setEnabled(false);
|
remove->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (model()->rowCount() == 0)
|
if (model()->rowCount() == 0)
|
||||||
removeAll->setEnabled(false);
|
removeAll->setEnabled(false);
|
||||||
|
|
||||||
|
connect(moveUp, SIGNAL(triggered()),
|
||||||
|
m_manager, SLOT(moveUp()));
|
||||||
|
connect(moveDown, SIGNAL(triggered()),
|
||||||
|
m_manager, SLOT(moveDown()));
|
||||||
connect(remove, SIGNAL(triggered()),
|
connect(remove, SIGNAL(triggered()),
|
||||||
this, SLOT(removeFromContextMenu()));
|
this, SLOT(removeFromContextMenu()));
|
||||||
connect(removeAll, SIGNAL(triggered()),
|
connect(removeAll, SIGNAL(triggered()),
|
||||||
@@ -251,18 +261,16 @@ void BookmarkView::removeFromContextMenu()
|
|||||||
|
|
||||||
void BookmarkView::removeBookmark(const QModelIndex& index)
|
void BookmarkView::removeBookmark(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
BookmarkManager *manager = static_cast<BookmarkManager *>(model());
|
Bookmark *bm = m_manager->bookmarkForIndex(index);
|
||||||
Bookmark *bm = manager->bookmarkForIndex(index);
|
m_manager->removeBookmark(bm);
|
||||||
manager->removeBookmark(bm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The perforcemance of this function could be greatly improved.
|
// The perforcemance of this function could be greatly improved.
|
||||||
//
|
//
|
||||||
void BookmarkView::removeAll()
|
void BookmarkView::removeAll()
|
||||||
{
|
{
|
||||||
BookmarkManager *manager = static_cast<BookmarkManager *>(model());
|
while (m_manager->rowCount()) {
|
||||||
while (manager->rowCount()) {
|
QModelIndex index = m_manager->index(0, 0);
|
||||||
QModelIndex index = manager->index(0, 0);
|
|
||||||
removeBookmark(index);
|
removeBookmark(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,6 +279,7 @@ void BookmarkView::setModel(QAbstractItemModel *model)
|
|||||||
{
|
{
|
||||||
BookmarkManager *manager = qobject_cast<BookmarkManager *>(model);
|
BookmarkManager *manager = qobject_cast<BookmarkManager *>(model);
|
||||||
QTC_ASSERT(manager, return);
|
QTC_ASSERT(manager, return);
|
||||||
|
m_manager = manager;
|
||||||
QListView::setModel(model);
|
QListView::setModel(model);
|
||||||
setSelectionModel(manager->selectionModel());
|
setSelectionModel(manager->selectionModel());
|
||||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
@@ -279,10 +288,9 @@ void BookmarkView::setModel(QAbstractItemModel *model)
|
|||||||
|
|
||||||
void BookmarkView::gotoBookmark(const QModelIndex &index)
|
void BookmarkView::gotoBookmark(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
BookmarkManager *bm = static_cast<BookmarkManager *>(model());
|
Bookmark *bk = m_manager->bookmarkForIndex(index);
|
||||||
Bookmark *bk = bm->bookmarkForIndex(index);
|
if (!m_manager->gotoBookmark(bk))
|
||||||
if (!bm->gotoBookmark(bk))
|
m_manager->removeBookmark(bk);
|
||||||
bm->removeBookmark(bk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
BookmarkContext *m_bookmarkContext;
|
BookmarkContext *m_bookmarkContext;
|
||||||
QModelIndex m_contextMenuIndex;
|
QModelIndex m_contextMenuIndex;
|
||||||
|
BookmarkManager *m_manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BookmarkContext : public Core::IContext
|
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);
|
cmd = am->registerAction(sep, QLatin1String("Bookmarks.Sep.Toggle"), textcontext);
|
||||||
mbm->addAction(cmd);
|
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
|
//Previous
|
||||||
m_prevAction = new QAction(tr("Previous Bookmark"), this);
|
m_prevAction = new QAction(tr("Previous Bookmark"), this);
|
||||||
cmd = am->registerAction(m_prevAction, BOOKMARKS_PREV_ACTION, globalcontext);
|
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_nextAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(next()));
|
||||||
connect(m_docPrevAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(prevInDocument()));
|
connect(m_docPrevAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(prevInDocument()));
|
||||||
connect(m_docNextAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(nextInDocument()));
|
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)));
|
connect(m_bookmarkManager, SIGNAL(updateActions(int)), this, SLOT(updateActions(int)));
|
||||||
updateActions(m_bookmarkManager->state());
|
updateActions(m_bookmarkManager->state());
|
||||||
addAutoReleasedObject(new BookmarkViewFactory(m_bookmarkManager));
|
addAutoReleasedObject(new BookmarkViewFactory(m_bookmarkManager));
|
||||||
@@ -192,8 +175,6 @@ void BookmarksPlugin::updateActions(int state)
|
|||||||
m_nextAction->setEnabled(hasbm);
|
m_nextAction->setEnabled(hasbm);
|
||||||
m_docPrevAction->setEnabled(hasdocbm);
|
m_docPrevAction->setEnabled(hasdocbm);
|
||||||
m_docNextAction->setEnabled(hasdocbm);
|
m_docNextAction->setEnabled(hasdocbm);
|
||||||
m_moveUpAction->setEnabled(hasbm);
|
|
||||||
m_moveDownAction->setEnabled(hasbm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarksPlugin::editorOpened(Core::IEditor *editor)
|
void BookmarksPlugin::editorOpened(Core::IEditor *editor)
|
||||||
|
|||||||
@@ -85,8 +85,6 @@ private:
|
|||||||
QAction *m_nextAction;
|
QAction *m_nextAction;
|
||||||
QAction *m_docPrevAction;
|
QAction *m_docPrevAction;
|
||||||
QAction *m_docNextAction;
|
QAction *m_docNextAction;
|
||||||
QAction *m_moveUpAction;
|
|
||||||
QAction *m_moveDownAction;
|
|
||||||
|
|
||||||
QAction *m_bookmarkMarginAction;
|
QAction *m_bookmarkMarginAction;
|
||||||
int m_bookmarkMarginActionLineNumber;
|
int m_bookmarkMarginActionLineNumber;
|
||||||
|
|||||||
Reference in New Issue
Block a user