diff options
author | con <qtc-commiter@nokia.com> | 2008-12-02 12:01:29 +0100 |
---|---|---|
committer | con <qtc-commiter@nokia.com> | 2008-12-02 12:01:29 +0100 |
commit | 05c35356abc31549c5db6eba31fb608c0365c2a0 (patch) | |
tree | be044530104267afaff13f8943889cb97f8c8bad /src/plugins/bookmarks | |
download | qt-creator-05c35356abc31549c5db6eba31fb608c0365c2a0.tar.gz |
Initial import
Diffstat (limited to 'src/plugins/bookmarks')
-rw-r--r-- | src/plugins/bookmarks/Bookmarks.pluginspec | 12 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmark.cpp | 96 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmark.h | 85 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarkmanager.cpp | 742 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarkmanager.h | 193 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarks.pro | 18 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarks.qrc | 5 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarks_global.h | 56 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarksplugin.cpp | 185 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarksplugin.h | 86 | ||||
-rw-r--r-- | src/plugins/bookmarks/images/bookmark.png | bin | 0 -> 913 bytes |
11 files changed, 1478 insertions, 0 deletions
diff --git a/src/plugins/bookmarks/Bookmarks.pluginspec b/src/plugins/bookmarks/Bookmarks.pluginspec new file mode 100644 index 0000000000..359ab6d203 --- /dev/null +++ b/src/plugins/bookmarks/Bookmarks.pluginspec @@ -0,0 +1,12 @@ +<plugin name="Bookmarks" version="0.9.1" compatVersion="0.9.1"> + <vendor>Nokia Corporation</vendor> + <copyright>(C) 2008 Nokia Corporation</copyright> + <license>Nokia Technology Preview License Agreement</license> + <description>Bookmarks in text editors.</description> + <url>http://www.trolltech.com/</url> + <dependencyList> + <dependency name="TextEditor" version="0.9.1"/> + <dependency name="ProjectExplorer" version="0.9.1"/> + <dependency name="Core" version="0.9.1"/> + </dependencyList> +</plugin> diff --git a/src/plugins/bookmarks/bookmark.cpp b/src/plugins/bookmarks/bookmark.cpp new file mode 100644 index 0000000000..41f4659cb7 --- /dev/null +++ b/src/plugins/bookmarks/bookmark.cpp @@ -0,0 +1,96 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "bookmark.h" +#include "bookmarkmanager.h" +#include <QtCore/QDebug> +#include <QtGui/QTextBlock> + +using namespace Bookmarks::Internal; + +const QIcon Bookmark::m_bookmarkIcon = QIcon(":/bookmarks/images/bookmark.png"); + +Bookmark::Bookmark(const QString& fileName, int lineNumber, BookmarkManager *manager) + : BaseTextMark(fileName, lineNumber), m_manager(manager) +{ + m_fileName = fileName; + m_fileInfo.setFile(fileName); + m_onlyFile = m_fileInfo.fileName(); + m_path = m_fileInfo.path(); + m_lineNumber= lineNumber; +} + +QIcon Bookmark::icon() const +{ + return m_bookmarkIcon; +} + +void Bookmark::removedFromEditor() +{ + m_manager->removeBookmark(this); +} + +void Bookmark::updateLineNumber(int lineNumber) +{ + if (lineNumber != m_lineNumber) { + m_lineNumber = lineNumber; + m_manager->updateBookmark(this); + } +} + +void Bookmark::updateBlock(const QTextBlock &block) +{ + if (m_lineText != block.text()) { + m_lineText = block.text(); + m_manager->updateBookmark(this); + } +} + +QString Bookmark::lineText() const +{ + return m_lineText; +} + +QString Bookmark::filePath() const +{ + return m_fileName; +} + +QString Bookmark::fileName() const +{ + return m_onlyFile; +} + +QString Bookmark::path() const +{ + return m_path; +} diff --git a/src/plugins/bookmarks/bookmark.h b/src/plugins/bookmarks/bookmark.h new file mode 100644 index 0000000000..d54d6af3e5 --- /dev/null +++ b/src/plugins/bookmarks/bookmark.h @@ -0,0 +1,85 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef BOOKMARK_H +#define BOOKMARK_H + +#include <texteditor/itexteditor.h> +#include <texteditor/basetextmark.h> + +QT_BEGIN_NAMESPACE +class QTreeWidgetItem; +QT_END_NAMESPACE + +#include <QtCore/QFileInfo> + +namespace Bookmarks { +namespace Internal { + +class BookmarkManager; + +class Bookmark : public TextEditor::BaseTextMark +{ + Q_OBJECT +public: + Bookmark(const QString& fileName, int lineNumber, BookmarkManager *manager); + + QIcon icon() const; + + void updateLineNumber(int lineNumber); + void updateBlock(const QTextBlock &block); + void removedFromEditor(); + + QString filePath() const; + QString fileName() const; + QString path() const; + QString lineText() const; + + inline int lineNumber() const { return m_lineNumber; } + +private: + static const QIcon m_bookmarkIcon; + + BookmarkManager *m_manager; + int m_lineNumber; + QString m_name; + QString m_fileName; + QString m_onlyFile; + QString m_path; + QString m_lineText; + QFileInfo m_fileInfo; +}; + +} // namespace Internal +} // namespace Bookmarks + +#endif // BOOKMARK_H diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp new file mode 100644 index 0000000000..bb26bfbd4f --- /dev/null +++ b/src/plugins/bookmarks/bookmarkmanager.cpp @@ -0,0 +1,742 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "bookmarkmanager.h" +#include "bookmark.h" +#include "bookmarksplugin.h" +#include "bookmarks_global.h" + +#include <projectexplorer/ProjectExplorerInterfaces> +#include <coreplugin/icore.h> +#include <coreplugin/editormanager/editormanager.h> +#include <coreplugin/uniqueidmanager.h> +#include <texteditor/basetexteditor.h> + +#include <QtGui/QAction> +#include <QtCore/QFileInfo> +#include <QtCore/QDebug> +#include <QtGui/QPainter> +#include <QtGui/QContextMenuEvent> + +Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*) + +using namespace Bookmarks; +using namespace Bookmarks::Internal; +using namespace ProjectExplorer; + +BookmarkDelegate::BookmarkDelegate(QObject *parent) + : QStyledItemDelegate(parent), m_normalPixmap(0), m_selectedPixmap(0) +{ +} + +BookmarkDelegate::~BookmarkDelegate() +{ + delete m_normalPixmap; + delete m_selectedPixmap; +} + +QSize BookmarkDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QStyleOptionViewItemV4 opt = option; + initStyleOption(&opt, index); + + QFontMetrics fm(option.font); + QSize s; + s.setWidth(option.rect.width()); + s.setHeight(fm.height() * 2 + 10); + return s; +} + +void BookmarkDelegate::generateGradientPixmap(int width, int height, QColor color, bool selected) const +{ + + QColor c = color; + c.setAlpha(0); + + QPixmap *pixmap = new QPixmap(width+1, height); + pixmap->fill(c); + + QPainter painter(pixmap); + painter.setPen(Qt::NoPen); + + QLinearGradient lg; + lg.setCoordinateMode(QGradient::ObjectBoundingMode); + lg.setFinalStop(1,0); + + lg.setColorAt(0, c); + lg.setColorAt(0.4, color); + + painter.setBrush(lg); + painter.drawRect(0, 0, width+1, height); + + if (selected) + m_selectedPixmap = pixmap; + else + m_normalPixmap = pixmap; +} + +void BookmarkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QStyleOptionViewItemV4 opt = option; + initStyleOption(&opt, index); + painter->save(); + + QFontMetrics fm(opt.font); + static int lwidth = fm.width("8888") + 18; + + QColor backgroundColor; + QColor textColor; + + bool selected = opt.state & QStyle::State_Selected; + + if (selected) { + painter->setBrush(opt.palette.highlight().color()); + backgroundColor = opt.palette.highlight().color(); + if (!m_selectedPixmap) + generateGradientPixmap(lwidth, fm.height()+1, backgroundColor, selected); + } else { + painter->setBrush(opt.palette.background().color()); + backgroundColor = opt.palette.background().color(); + if (!m_normalPixmap) + generateGradientPixmap(lwidth, fm.height(), backgroundColor, selected); + } + painter->setPen(Qt::NoPen); + painter->drawRect(opt.rect); + + // Set Text Color + if (opt.state & QStyle::State_Selected) + textColor = opt.palette.highlightedText().color(); + else + textColor = opt.palette.text().color(); + + painter->setPen(textColor); + + + // TopLeft + QString topLeft = index.data(BookmarkManager::Filename ).toString(); + painter->drawText(6, 2 + opt.rect.top() + fm.ascent(), topLeft); + + QString topRight = index.data(BookmarkManager::LineNumber).toString(); + // Check wheter we need to be fancy and paint some background + int fwidth = fm.width(topLeft); + if (fwidth + lwidth > opt.rect.width()) { + int left = opt.rect.right() - lwidth; + painter->drawPixmap(left, opt.rect.top(), selected? *m_selectedPixmap : *m_normalPixmap); + } + // topRight + painter->drawText(opt.rect.right() - fm.width(topRight) - 6 , 2 + opt.rect.top() + fm.ascent(), topRight); + + // Directory + QColor mix; + mix.setRgbF(0.7 * textColor.redF() + 0.3 * backgroundColor.redF(), + 0.7 * textColor.greenF() + 0.3 * backgroundColor.greenF(), + 0.7 * textColor.blueF() + 0.3 * backgroundColor.blueF()); + painter->setPen(mix); +// +// QString directory = index.data(BookmarkManager::Directory).toString(); +// int availableSpace = opt.rect.width() - 12; +// if (fm.width(directory) > availableSpace) { +// // We need a shorter directory +// availableSpace -= fm.width("..."); +// +// int pos = directory.size(); +// int idx; +// forever { +// idx = directory.lastIndexOf("/", pos-1); +// if(idx == -1) { +// // Can't happen, this means the string did fit after all? +// break; +// } +// int width = fm.width(directory.mid(idx, pos-idx)); +// if (width > availableSpace) { +// directory = "..." + directory.mid(pos); +// break; +// } else { +// pos = idx; +// availableSpace -= width; +// } +// } +// } +// +// painter->drawText(3, opt.rect.top() + fm.ascent() + fm.height() + 6, directory); + + QString lineText = index.data(BookmarkManager::LineText).toString().trimmed(); + painter->drawText(6, opt.rect.top() + fm.ascent() + fm.height() + 6, lineText); + + // Separator lines + painter->setPen(QColor::fromRgb(150,150,150)); + painter->drawLine(0, opt.rect.bottom(), opt.rect.right(), opt.rect.bottom()); + painter->restore(); +} + +BookmarkView::BookmarkView(QWidget *parent) + : QListView(parent) +{ + setWindowTitle(tr("Bookmarks")); + setWindowIcon(QIcon(":/bookmarks/images/bookmark.png")); + + connect(this, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(gotoBookmark(const QModelIndex &))); + + m_bookmarkContext = new BookmarkContext(this); + Core::ICore *core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>(); + core->addContextObject(m_bookmarkContext); + + setItemDelegate(new BookmarkDelegate(this)); + setFrameStyle(QFrame::NoFrame); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setFocusPolicy(Qt::NoFocus); +} + +BookmarkView::~BookmarkView() +{ + Core::ICore *core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>(); + core->removeContextObject(m_bookmarkContext); +} + +void BookmarkView::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu menu; + QAction *remove = menu.addAction("&Remove Bookmark"); + QAction *removeAll = menu.addAction("Remove all Bookmarks"); + m_contextMenuIndex = indexAt(event->pos()); + if (!m_contextMenuIndex.isValid()) + remove->setEnabled(false); + + if (model()->rowCount() == 0) + removeAll->setEnabled(false); + + connect(remove, SIGNAL(triggered()), + this, SLOT(removeFromContextMenu())); + connect(removeAll, SIGNAL(triggered()), + this, SLOT(removeAll())); + + + menu.exec(mapToGlobal(event->pos())); +} + +void BookmarkView::removeFromContextMenu() +{ + + removeBookmark(m_contextMenuIndex); +} + +void BookmarkView::removeBookmark(const QModelIndex& index) +{ + BookmarkManager *manager = static_cast<BookmarkManager *>(model()); + Bookmark *bm = manager->bookmarkForIndex(index); + 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); + removeBookmark(index); + } +} + +void BookmarkView::setModel(QAbstractItemModel *model) +{ + BookmarkManager *manager = qobject_cast<BookmarkManager *>(model); + Q_ASSERT(manager); + QListView::setModel(model); + setSelectionModel(manager->selectionModel()); + setSelectionMode(QAbstractItemView::SingleSelection); + setSelectionBehavior(QAbstractItemView::SelectRows); +} + +void BookmarkView::gotoBookmark(const QModelIndex &index) +{ + static_cast<BookmarkManager *>(model())->gotoBookmark(index); +} + +//// +// BookmarkContext +//// + +BookmarkContext::BookmarkContext(BookmarkView *widget) + : m_bookmarkView(widget) +{ + Core::ICore *core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>(); + m_context << core->uniqueIDManager()->uniqueIdentifier(Constants::BOOKMARKS_CONTEXT); +} + +QList<int> BookmarkContext::context() const +{ + return m_context; +} + +QWidget *BookmarkContext::widget() +{ + return m_bookmarkView; +} + +//// +// BookmarkManager +//// + +BookmarkManager::BookmarkManager() : + m_core(BookmarksPlugin::core()), + m_bookmarkIcon(QIcon(QLatin1String(":/bookmarks/images/bookmark.png"))) +{ + m_selectionModel = new QItemSelectionModel(this, this); + + connect(m_core, SIGNAL(contextChanged(Core::IContext*)), + this, SLOT(updateActionStatus())); + + ExtensionSystem::PluginManager *pm = m_core->pluginManager(); + ProjectExplorerPlugin *projectExplorer = pm->getObject<ProjectExplorerPlugin>(); + + connect(projectExplorer->session(), SIGNAL(sessionLoaded()), + this, SLOT(loadBookmarks())); + + updateActionStatus(); +} + +BookmarkManager::~BookmarkManager() +{ + DirectoryFileBookmarksMap::iterator it, end; + end = m_bookmarksMap.end(); + for (it = m_bookmarksMap.begin(); it != end; ++it) { + FileNameBookmarksMap *bookmarks = it.value(); + qDeleteAll(bookmarks->values()); + delete bookmarks; + } +} + +QItemSelectionModel *BookmarkManager::selectionModel() const +{ + return m_selectionModel; +} + +QModelIndex BookmarkManager::index(int row, int column, const QModelIndex &parent) const +{ + if (parent.isValid()) + return QModelIndex(); + else + return createIndex(row, column, 0); +} + +QModelIndex BookmarkManager::parent(const QModelIndex &) const +{ + return QModelIndex(); +} + +int BookmarkManager::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + else + return m_bookmarksList.count(); +} + +int BookmarkManager::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return 3; +} + +QVariant BookmarkManager::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.column() !=0 || index.row() < 0 || index.row() >= m_bookmarksList.count()) + return QVariant(); + + if (role == BookmarkManager::Filename) + return m_bookmarksList.at(index.row())->fileName(); + else if (role == BookmarkManager::LineNumber) + return m_bookmarksList.at(index.row())->lineNumber(); + else if (role == BookmarkManager::Directory) + return m_bookmarksList.at(index.row())->path(); + else if (role == BookmarkManager::LineText) + return m_bookmarksList.at(index.row())->lineText(); + else if (role == Qt::ToolTipRole) + return m_bookmarksList.at(index.row())->filePath(); + + return QVariant(); +} + +void BookmarkManager::toggleBookmark() +{ + TextEditor::ITextEditor *editor = currentTextEditor(); + if (!editor) + return; + + const QFileInfo fi(editor->file()->fileName()); + const int editorLine = editor->currentLine(); + + // Remove any existing bookmark on this line + if (Bookmark *mark = findBookmark(fi.path(), fi.fileName(), editorLine)) { + // TODO check if the bookmark is really on the same markable Interface + removeBookmark(mark); + return; + } + + // Add a new bookmark if no bookmark existed on this line + Bookmark *bookmark = new Bookmark(fi.filePath(), editorLine, this); + addBookmark(bookmark); +} + +void BookmarkManager::updateBookmark(Bookmark *bookmark) +{ + int idx = m_bookmarksList.indexOf(bookmark); + emit dataChanged(index(idx, 0, QModelIndex()), index(idx, 2, QModelIndex())); + saveBookmarks(); +} + +void BookmarkManager::removeBookmark(Bookmark *bookmark) +{ + const QFileInfo fi(bookmark->filePath() ); + FileNameBookmarksMap *files = m_bookmarksMap.value(fi.path()); + + FileNameBookmarksMap::iterator i = files->begin(); + while (i != files->end()) { + if (i.value() == bookmark) { + files->erase(i); + delete bookmark; + break; + } + ++i; + } + if (files->count() <= 0) { + m_bookmarksMap.remove(fi.path()); + delete files; + } + + int idx = m_bookmarksList.indexOf(bookmark); + beginRemoveRows(QModelIndex(), idx, idx); + m_bookmarksList.removeAt(idx); + endRemoveRows(); + + if (selectionModel()->currentIndex().isValid()) + selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), QItemSelectionModel::Select | QItemSelectionModel::Clear); + + updateActionStatus(); + saveBookmarks(); +} + +Bookmark *BookmarkManager::bookmarkForIndex(QModelIndex index) +{ + if (!index.isValid() || index.row() >= m_bookmarksList.size()) + return 0; + return m_bookmarksList.at(index.row()); +} + +void BookmarkManager::gotoBookmark(const QModelIndex &idx) +{ + gotoBookmark(m_bookmarksList.at(idx.row())); +} + +void BookmarkManager::gotoBookmark(Bookmark* bookmark) +{ + TextEditor::BaseTextEditor::openEditorAt(bookmark->filePath(), + bookmark->lineNumber()); +} + +void BookmarkManager::nextInDocument() +{ + documentPrevNext(true); +} + +void BookmarkManager::prevInDocument() +{ + documentPrevNext(false); +} + +void BookmarkManager::documentPrevNext(bool next) +{ + TextEditor::ITextEditor *editor = currentTextEditor(); + int editorLine = editor->currentLine(); + QFileInfo fi(editor->file()->fileName()); + if (!m_bookmarksMap.contains(fi.path())) + return; + + int firstLine = -1; + int lastLine = -1; + int prevLine = -1; + int nextLine = -1; + const QList<Bookmark*> marks = m_bookmarksMap.value(fi.path())->values(fi.fileName()); + for (int i = 0; i < marks.count(); ++i) { + int markLine = marks.at(i)->lineNumber(); + if (firstLine == -1 || firstLine > markLine) + firstLine = markLine; + if (lastLine < markLine) + lastLine = markLine; + if (markLine < editorLine && prevLine < markLine) + prevLine = markLine; + if (markLine > editorLine && + (nextLine == -1 || nextLine > markLine)) + nextLine = markLine; + } + + m_core->editorManager()->addCurrentPositionToNavigationHistory(true); + if (next) { + if (nextLine == -1) + editor->gotoLine(firstLine); + else + editor->gotoLine(nextLine); + } else { + if (prevLine == -1) + editor->gotoLine(lastLine); + else + editor->gotoLine(prevLine); + } + m_core->editorManager()->addCurrentPositionToNavigationHistory(); +} + +void BookmarkManager::next() +{ + QModelIndex current = selectionModel()->currentIndex(); + if (!current.isValid()) + return; + int row = current.row() + 1; + if (row == m_bookmarksList.size()) + row = 0; + QModelIndex newIndex = current.sibling(row, current.column()); + selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select | QItemSelectionModel::Clear); + gotoBookmark(newIndex); +} + +void BookmarkManager::prev() +{ + QModelIndex current = selectionModel()->currentIndex(); + if (!current.isValid()) + return; + int row = current.row(); + if (row == 0) + row = m_bookmarksList.size(); + --row; + QModelIndex newIndex = current.sibling(row, current.column()); + selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select | QItemSelectionModel::Clear); + gotoBookmark(newIndex); +} + +TextEditor::ITextEditor *BookmarkManager::currentTextEditor() const +{ + Core::IEditor *currEditor = m_core->editorManager()->currentEditor(); + if (!currEditor) + return 0; + return qobject_cast<TextEditor::ITextEditor *>(currEditor); +} + +/* Returns the current session. */ +SessionManager* BookmarkManager::sessionManager() const +{ + ExtensionSystem::PluginManager *pm = m_core->pluginManager(); + ProjectExplorerPlugin *pe = pm->getObject<ProjectExplorerPlugin>(); + return pe->session(); +} + +BookmarkManager::State BookmarkManager::state() const +{ + if (m_bookmarksMap.empty()) + return NoBookMarks; + + TextEditor::ITextEditor *editor = currentTextEditor(); + if (!editor) + return HasBookMarks; + + const QFileInfo fi(editor->file()->fileName()); + + const DirectoryFileBookmarksMap::const_iterator dit = m_bookmarksMap.constFind(fi.path()); + if (dit == m_bookmarksMap.constEnd()) + return HasBookMarks; + + return HasBookmarksInDocument; +} + +void BookmarkManager::updateActionStatus() +{ + emit updateActions(state()); +} + +void BookmarkManager::moveUp() +{ + QModelIndex current = selectionModel()->currentIndex(); + int row = current.row(); + if (row == 0) + row = m_bookmarksList.size(); + --row; + + // swap current.row() and row + + Bookmark *b = m_bookmarksList.at(row); + m_bookmarksList[row] = m_bookmarksList.at(current.row()); + m_bookmarksList[current.row()] = b; + + QModelIndex topLeft = current.sibling(row, 0); + QModelIndex bottomRight = current.sibling(current.row(), 2); + emit dataChanged(topLeft, bottomRight); + selectionModel()->setCurrentIndex(current.sibling(row, 0), QItemSelectionModel::Select | QItemSelectionModel::Clear); +} + +void BookmarkManager::moveDown() +{ + QModelIndex current = selectionModel()->currentIndex(); + int row = current.row(); + ++row; + if (row == m_bookmarksList.size()) + row = 0; + + // swap current.row() and row + Bookmark *b = m_bookmarksList.at(row); + m_bookmarksList[row] = m_bookmarksList.at(current.row()); + m_bookmarksList[current.row()] = b; + + QModelIndex topLeft = current.sibling(current.row(), 0); + QModelIndex bottomRight = current.sibling(row, 2); + emit dataChanged(topLeft, bottomRight); + selectionModel()->setCurrentIndex(current.sibling(row, 0), QItemSelectionModel::Select | QItemSelectionModel::Clear); +} + +/* Returns the bookmark at the given file and line number, or 0 if no such bookmark exists. */ +Bookmark* BookmarkManager::findBookmark(const QString &path, const QString &fileName, int lineNumber) +{ + if (m_bookmarksMap.contains(path)) { + foreach (Bookmark *bookmark, m_bookmarksMap.value(path)->values(fileName)) { + if (bookmark->lineNumber() == lineNumber) + return bookmark; + } + } + return 0; +} + +/* Adds a bookmark to the internal data structures. The 'userset' parameter + * determines whether action status should be updated and whether the bookmarks + * should be saved to the session settings. + */ +void BookmarkManager::addBookmark(Bookmark *bookmark, bool userset) +{ + beginInsertRows(QModelIndex(), m_bookmarksList.size(), m_bookmarksList.size()); + const QFileInfo fi(bookmark->filePath()); + const QString &path = fi.path(); + + if (!m_bookmarksMap.contains(path)) + m_bookmarksMap.insert(path, new FileNameBookmarksMap()); + m_bookmarksMap.value(path)->insert(fi.fileName(), bookmark); + + m_bookmarksList.append(bookmark); + + endInsertRows(); + if (userset) { + updateActionStatus(); + saveBookmarks(); + } + selectionModel()->setCurrentIndex(index(m_bookmarksList.size()-1 , 0, QModelIndex()), QItemSelectionModel::Select | QItemSelectionModel::Clear); +} + +/* Adds a new bookmark based on information parsed from the string. */ +void BookmarkManager::addBookmark(const QString &s) +{ + int index2 = s.lastIndexOf(':'); + int index1 = s.indexOf(':'); + if (index2 != -1 || index1 != -1) { + const QString &filePath = s.mid(index1+1, index2-index1-1); + const int lineNumber = s.mid(index2 + 1).toInt(); + const QFileInfo fi(filePath); + + if (!filePath.isEmpty() && !findBookmark(fi.path(), fi.fileName(), lineNumber)) { + Bookmark *b = new Bookmark(filePath, lineNumber, this); + addBookmark(b, false); + } + } else { + qDebug() << "BookmarkManager::addBookmark() Invalid bookmark string:" << s; + } +} + +/* Puts the bookmark in a string for storing it in the settings. */ +QString BookmarkManager::bookmarkToString(const Bookmark *b) +{ + const QLatin1Char colon(':'); + // Empty string was the name of the bookmark, which now is always "" + return QLatin1String("") + colon + b->filePath() + colon + QString::number(b->lineNumber()); +} + +/* Saves the bookmarks to the session settings. */ +void BookmarkManager::saveBookmarks() +{ + SessionManager *s = sessionManager(); + if (!s) + return; + + QStringList list; + foreach (const FileNameBookmarksMap *bookmarksMap, m_bookmarksMap) + foreach (const Bookmark *bookmark, *bookmarksMap) + list << bookmarkToString(bookmark); + + s->setValue("Bookmarks", list); +} + +/* Loads the bookmarks from the session settings. */ +void BookmarkManager::loadBookmarks() +{ + SessionManager *s = sessionManager(); + if (!s) + return; + + const QStringList &list = s->value("Bookmarks").toStringList(); + foreach (const QString &bookmarkString, list) + addBookmark(bookmarkString); + + updateActionStatus(); +} + +// BookmarkViewFactory + +BookmarkViewFactory::BookmarkViewFactory(BookmarkManager *bm) + : m_manager(bm) +{ + +} + +QString BookmarkViewFactory::displayName() +{ + return "Bookmarks"; +} + +QKeySequence BookmarkViewFactory::activationSequence() +{ + return QKeySequence(Qt::ALT + Qt::Key_M); +} + +Core::NavigationView BookmarkViewFactory::createWidget() +{ + BookmarkView *bookmarkView = new BookmarkView(); + bookmarkView->setModel(m_manager); + Core::NavigationView view; + view.widget = bookmarkView; + return view; +} diff --git a/src/plugins/bookmarks/bookmarkmanager.h b/src/plugins/bookmarks/bookmarkmanager.h new file mode 100644 index 0000000000..45e4bf3b7b --- /dev/null +++ b/src/plugins/bookmarks/bookmarkmanager.h @@ -0,0 +1,193 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef BOOKMARKMANAGER_H +#define BOOKMARKMANAGER_H + +#include <QtCore/QAbstractItemModel> +#include <QtGui/QListView> +#include <QtCore/QList> +#include <QtGui/QPixmap> +#include <QtGui/QStyledItemDelegate> + +#include <coreplugin/icontext.h> +#include <coreplugin/inavigationwidgetfactory.h> + +namespace ProjectExplorer { +class SessionManager; +} + +namespace Core { +class ICore; +class IEditor; +} + +namespace TextEditor { +class ITextEditor; +} + +namespace Bookmarks { +namespace Internal { + +class Bookmark; +class BookmarksPlugin; +class BookmarkContext; + +class BookmarkManager : public QAbstractItemModel +{ + Q_OBJECT + +public: + BookmarkManager(); + ~BookmarkManager(); + void updateBookmark(Bookmark *bookmark); + void removeBookmark(Bookmark *bookmark); // Does not remove the mark + Bookmark *bookmarkForIndex(QModelIndex index); + + enum State { NoBookMarks, HasBookMarks, HasBookmarksInDocument }; + State state() const; + + // Model stuff + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &child) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + void gotoBookmark(const QModelIndex &); + + // this QItemSelectionModel is shared by all views + QItemSelectionModel *selectionModel() const; + + enum Roles {Filename = Qt::UserRole, LineNumber = Qt::UserRole + 1, Directory = Qt::UserRole + 2, LineText = Qt::UserRole + 3}; + +public slots: + void toggleBookmark(); + void nextInDocument(); + void prevInDocument(); + void next(); + void prev(); + void moveUp(); + void moveDown(); + +signals: + void updateActions(int state); + void currentIndexChanged(const QModelIndex &); + +private slots: + void updateActionStatus(); + void gotoBookmark(Bookmark *bookmark); + void loadBookmarks(); +private: + TextEditor::ITextEditor *currentTextEditor() const; + ProjectExplorer::SessionManager* sessionManager() const; + + void documentPrevNext(bool next); + + Bookmark* findBookmark(const QString &path, const QString &fileName, int lineNumber); + void addBookmark(Bookmark *bookmark, bool userset = true); + void addBookmark(const QString &s); + static QString bookmarkToString(const Bookmark *b); + void saveBookmarks(); + + typedef QMultiMap<QString, Bookmark*> FileNameBookmarksMap; + typedef QMap<QString, FileNameBookmarksMap*> DirectoryFileBookmarksMap; + + DirectoryFileBookmarksMap m_bookmarksMap; + Core::ICore *m_core; + + QIcon m_bookmarkIcon; + + QList<Bookmark *> m_bookmarksList; + QItemSelectionModel *m_selectionModel; +}; + +class BookmarkView : public QListView { + Q_OBJECT +public: + BookmarkView(QWidget *parent = 0); + ~BookmarkView(); + void setModel(QAbstractItemModel * model); +public slots: + void gotoBookmark(const QModelIndex &index); +protected slots: + void removeFromContextMenu(); + void removeAll(); +protected: + void contextMenuEvent(QContextMenuEvent *event); + void removeBookmark(const QModelIndex& index); +private: + BookmarkContext *m_bookmarkContext; + QModelIndex m_contextMenuIndex; +}; + +class BookmarkContext : public Core::IContext +{ +public: + BookmarkContext(BookmarkView *widget); + virtual QList<int> context() const; + virtual QWidget *widget(); +private: + BookmarkView *m_bookmarkView; + QList<int> m_context; +}; + +class BookmarkViewFactory : public Core::INavigationWidgetFactory +{ +public: + BookmarkViewFactory(BookmarkManager *bm); + virtual QString displayName(); + virtual QKeySequence activationSequence(); + virtual Core::NavigationView createWidget(); +private: + BookmarkManager *m_manager; +}; + +class BookmarkDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + BookmarkDelegate(QObject * parent = 0); + ~BookmarkDelegate(); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + +private: + void generateGradientPixmap(int width, int height, QColor color, bool selected) const; + mutable QPixmap *m_normalPixmap; + mutable QPixmap *m_selectedPixmap; +}; + +} // namespace Internal +} // namespace Bookmarks + +#endif // BOOKMARKMANAGER_H diff --git a/src/plugins/bookmarks/bookmarks.pro b/src/plugins/bookmarks/bookmarks.pro new file mode 100644 index 0000000000..1fcbffff7b --- /dev/null +++ b/src/plugins/bookmarks/bookmarks.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +TARGET = Bookmarks + +include(../../qworkbenchplugin.pri) +include(../../plugins/projectexplorer/projectexplorer.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../plugins/texteditor/texteditor.pri) + +HEADERS += bookmarksplugin.h \ + bookmark.h \ + bookmarkmanager.h \ + bookmarks_global.h + +SOURCES += bookmarksplugin.cpp \ + bookmark.cpp \ + bookmarkmanager.cpp + +RESOURCES += bookmarks.qrc diff --git a/src/plugins/bookmarks/bookmarks.qrc b/src/plugins/bookmarks/bookmarks.qrc new file mode 100644 index 0000000000..f0a890bf37 --- /dev/null +++ b/src/plugins/bookmarks/bookmarks.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/bookmarks" > + <file>images/bookmark.png</file> + </qresource> +</RCC> diff --git a/src/plugins/bookmarks/bookmarks_global.h b/src/plugins/bookmarks/bookmarks_global.h new file mode 100644 index 0000000000..e29f4e5865 --- /dev/null +++ b/src/plugins/bookmarks/bookmarks_global.h @@ -0,0 +1,56 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef BOOKMARKS_GLOBAL_H +#define BOOKMARKS_GLOBAL_H + +namespace Bookmarks { +namespace Constants { + +const char * const BOOKMARKS_TOGGLE_ACTION = "Bookmarks.Toggle"; +const char * const BOOKMARKS_MOVEUP_ACTION = "Bookmarks.MoveUp"; +const char * const BOOKMARKS_MOVEDOWN_ACTION = "Bookmarks.MoveDown"; +const char * const BOOKMARKS_PREV_ACTION = "Bookmarks.Previous"; +const char * const BOOKMARKS_NEXT_ACTION = "Bookmarks.Next"; +const char * const BOOKMARKS_PREVDIR_ACTION = "Bookmarks.Previous.Directory"; +const char * const BOOKMARKS_NEXTDIR_ACTION = "Bookmarks.Next.Directory"; +const char * const BOOKMARKS_PREVDOC_ACTION = "Bookmarks.Previous.Document"; +const char * const BOOKMARKS_NEXTDOC_ACTION = "Bookmarks.Next.Document"; + +const char * const BOOKMARKS_MENU = "Bookmarks.Menu"; +const char * const BOOKMARKS_CONTEXT = "Bookmarks"; + +} //namespace Constants +} //namespace Bookmarks + +#endif //BOOKMARKS_GLOBAL_H + diff --git a/src/plugins/bookmarks/bookmarksplugin.cpp b/src/plugins/bookmarks/bookmarksplugin.cpp new file mode 100644 index 0000000000..76df8e5777 --- /dev/null +++ b/src/plugins/bookmarks/bookmarksplugin.cpp @@ -0,0 +1,185 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "bookmarksplugin.h" +#include "bookmarkmanager.h" +#include "bookmarks_global.h" + +#include <QtCore/qplugin.h> +#include <QtGui/QMenu> +#include <QDebug> + +#include <texteditor/texteditorconstants.h> +#include <coreplugin/icore.h> +#include <coreplugin/coreconstants.h> +#include <coreplugin/uniqueidmanager.h> +#include <coreplugin/actionmanager/actionmanagerinterface.h> + +using namespace Bookmarks::Constants; +using namespace Bookmarks::Internal; + +BookmarksPlugin *BookmarksPlugin::m_instance = 0; + +BookmarksPlugin::BookmarksPlugin(): + m_bookmarkManager(0), + m_core(0) +{ + m_instance = this; +} + +void BookmarksPlugin::extensionsInitialized() +{ +} + +bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *) +{ + m_core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>(); + Core::ActionManagerInterface *am = m_core->actionManager(); + + QList<int> context = QList<int>() << m_core->uniqueIDManager()-> + uniqueIdentifier(Constants::BOOKMARKS_CONTEXT); + QList<int> textcontext, globalcontext; + textcontext << m_core->uniqueIDManager()-> + uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR); + globalcontext << Core::Constants::C_GLOBAL_ID; + + Core::IActionContainer *mtools = + am->actionContainer(Core::Constants::M_TOOLS); + + Core::IActionContainer *mbm = + am->createMenu(QLatin1String(BOOKMARKS_MENU)); + mbm->menu()->setTitle(tr("&Bookmarks")); + mtools->addMenu(mbm); + + //Toggle + m_toggleAction = new QAction(tr("Toggle Bookmark"), this); + Core::ICommand *cmd = + am->registerAction(m_toggleAction, BOOKMARKS_TOGGLE_ACTION, textcontext); +#ifndef Q_OS_MAC + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+M"))); +#else + cmd->setDefaultKeySequence(QKeySequence(tr("Meta+M"))); +#endif + mbm->addAction(cmd); + + QAction *sep = new QAction(this); + sep->setSeparator(true); + 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); +#ifndef Q_OS_MAC + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+,"))); +#else + cmd->setDefaultKeySequence(QKeySequence(tr("Meta+,"))); +#endif + mbm->addAction(cmd); + + //Next + m_nextAction = new QAction(tr("Next Bookmark"), this); + cmd = am->registerAction(m_nextAction, BOOKMARKS_NEXT_ACTION, globalcontext); +#ifndef Q_OS_MAC + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+."))); +#else + cmd->setDefaultKeySequence(QKeySequence(tr("Meta+."))); +#endif + mbm->addAction(cmd); + + sep = new QAction(this); + sep->setSeparator(true); + cmd = am->registerAction(sep, QLatin1String("Bookmarks.Sep.DirNavigation"), globalcontext); + mbm->addAction(cmd); + + //Previous Doc + m_docPrevAction = new QAction(tr("Previous Bookmark In Document"), this); + cmd = am->registerAction(m_docPrevAction, BOOKMARKS_PREVDOC_ACTION, globalcontext); + mbm->addAction(cmd); + + //Next Doc + m_docNextAction = new QAction(tr("Next Bookmark In Document"), this); + cmd = am->registerAction(m_docNextAction, BOOKMARKS_NEXTDOC_ACTION, globalcontext); + mbm->addAction(cmd); + + m_bookmarkManager = new BookmarkManager; + + connect(m_toggleAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(toggleBookmark())); + connect(m_prevAction, SIGNAL(triggered()), m_bookmarkManager, SLOT(prev())); + 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)); + + return true; +} + +BookmarksPlugin::~BookmarksPlugin() +{ + delete m_bookmarkManager; +} + +void BookmarksPlugin::updateActions(int state) +{ + + const bool hasbm = state >= BookmarkManager::HasBookMarks; + const bool hasdocbm = state == BookmarkManager::HasBookmarksInDocument; + + m_toggleAction->setEnabled(true); + m_prevAction->setEnabled(hasbm); + m_nextAction->setEnabled(hasbm); + m_docPrevAction->setEnabled(hasdocbm); + m_docNextAction->setEnabled(hasdocbm); + m_moveUpAction->setEnabled(hasbm); + m_moveDownAction->setEnabled(hasbm); +} + +Q_EXPORT_PLUGIN(BookmarksPlugin) diff --git a/src/plugins/bookmarks/bookmarksplugin.h b/src/plugins/bookmarks/bookmarksplugin.h new file mode 100644 index 0000000000..7da45ef5ee --- /dev/null +++ b/src/plugins/bookmarks/bookmarksplugin.h @@ -0,0 +1,86 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef BOOKMARKS_H +#define BOOKMARKS_H + +#include <QtCore/QObject> +#include <QtCore/QMultiMap> + +#include <extensionsystem/iplugin.h> + +QT_FORWARD_DECLARE_CLASS(QAction) + +namespace Core { +class ICore; +} + +namespace Bookmarks { +namespace Internal { + +class BookmarkManager; + +class BookmarksPlugin : public ExtensionSystem::IPlugin +{ + Q_OBJECT + +public: + BookmarksPlugin(); + ~BookmarksPlugin(); + + static BookmarksPlugin *instance() { return m_instance; } + static Core::ICore *core() { return m_instance->m_core; } + + bool initialize(const QStringList &arguments, QString *error_message); + void extensionsInitialized(); + +public slots: + void updateActions(int stateMask); + +private: + static BookmarksPlugin *m_instance; + BookmarkManager *m_bookmarkManager; + Core::ICore *m_core; + + QAction *m_toggleAction; + QAction *m_prevAction; + QAction *m_nextAction; + QAction *m_docPrevAction; + QAction *m_docNextAction; + QAction *m_moveUpAction; + QAction *m_moveDownAction; +}; + +} // namespace Internal +} // namespace Bookmarks + +#endif // BOOKMARKS_H diff --git a/src/plugins/bookmarks/images/bookmark.png b/src/plugins/bookmarks/images/bookmark.png Binary files differnew file mode 100644 index 0000000000..7b2e5fd0ce --- /dev/null +++ b/src/plugins/bookmarks/images/bookmark.png |