diff --git a/shared/help/bookmarkmanager.h b/shared/help/bookmarkmanager.h index a8afa867e65b92909617f3b4942ff812755e3eb4..c40d8672db0ff2cb8b3770966a38a75e5bbf97f0 100644 --- a/shared/help/bookmarkmanager.h +++ b/shared/help/bookmarkmanager.h @@ -95,8 +95,10 @@ private: QSortFilterProxyModel *proxyModel; }; -class TreeView : public QTreeView { +class TreeView : public QTreeView +{ Q_OBJECT + public: TreeView(QWidget* parent = 0) : QTreeView(parent) {} void subclassKeyPressEvent(QKeyEvent* event) @@ -159,18 +161,18 @@ class BookmarkManager : public QObject Q_OBJECT public: - BookmarkManager(QHelpEngineCore* helpEngine); + BookmarkManager(QHelpEngineCore *helpEngine); ~BookmarkManager(); - BookmarkModel* treeBookmarkModel(); - BookmarkModel* listBookmarkModel(); + BookmarkModel *treeBookmarkModel(); + BookmarkModel *listBookmarkModel(); void saveBookmarks(); QStringList bookmarkFolders() const; - QModelIndex addNewFolder(const QModelIndex& index); + QModelIndex addNewFolder(const QModelIndex &index); void removeBookmarkItem(QTreeView *treeView, const QModelIndex& index); - void showBookmarkDialog(QWidget* parent, const QString &name, const QString &url); - void addNewBookmark(const QModelIndex& index, const QString &name, const QString &url); + void showBookmarkDialog(QWidget *parent, const QString &name, const QString &url); + void addNewBookmark(const QModelIndex &index, const QString &name, const QString &url); void setupBookmarkModels(); private slots: diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp index 0e8482b6f98add4f0920557a7aa7418188837e12..fd4541a01dd2b13f6d1e94f15bd1a0a25d012c53 100644 --- a/src/plugins/bookmarks/bookmarkmanager.cpp +++ b/src/plugins/bookmarks/bookmarkmanager.cpp @@ -396,11 +396,16 @@ void BookmarkManager::toggleBookmark() if (!editor) return; - const QFileInfo fi(editor->file()->fileName()); - const int editorLine = editor->currentLine(); + toggleBookmark(editor->file()->fileName(), editor->currentLine()); +} + +void BookmarkManager::toggleBookmark(const QString &fileName, int lineNumber) +{ + const QFileInfo fi(fileName); + const int editorLine = lineNumber; // Remove any existing bookmark on this line - if (Bookmark *mark = findBookmark(fi.path(), fi.fileName(), editorLine)) { + if (Bookmark *mark = findBookmark(fi.path(), fi.fileName(), lineNumber)) { // TODO check if the bookmark is really on the same markable Interface removeBookmark(mark); return; diff --git a/src/plugins/bookmarks/bookmarkmanager.h b/src/plugins/bookmarks/bookmarkmanager.h index 3b03e32d670c411f4e1ce7b43459bfeb43500e2b..d3a2fc9a322b0fbb5feda3fafd1c2d22744b6174 100644 --- a/src/plugins/bookmarks/bookmarkmanager.h +++ b/src/plugins/bookmarks/bookmarkmanager.h @@ -34,15 +34,15 @@ #ifndef BOOKMARKMANAGER_H #define BOOKMARKMANAGER_H +#include <coreplugin/icontext.h> +#include <coreplugin/inavigationwidgetfactory.h> + #include <QtCore/QAbstractItemModel> -#include <QtGui/QListView> #include <QtCore/QList> +#include <QtGui/QListView> #include <QtGui/QPixmap> #include <QtGui/QStyledItemDelegate> -#include <coreplugin/icontext.h> -#include <coreplugin/inavigationwidgetfactory.h> - namespace ProjectExplorer { class SessionManager; } @@ -89,10 +89,16 @@ public: // 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}; + enum Roles { + Filename = Qt::UserRole, + LineNumber = Qt::UserRole + 1, + Directory = Qt::UserRole + 2, + LineText = Qt::UserRole + 3 + }; public slots: void toggleBookmark(); + void toggleBookmark(const QString &fileName, int lineNumber); void nextInDocument(); void prevInDocument(); void next(); @@ -108,6 +114,7 @@ private slots: void updateActionStatus(); void gotoBookmark(Bookmark *bookmark); void loadBookmarks(); + private: TextEditor::ITextEditor *currentTextEditor() const; ProjectExplorer::SessionManager* sessionManager() const; @@ -120,8 +127,8 @@ private: static QString bookmarkToString(const Bookmark *b); void saveBookmarks(); - typedef QMultiMap<QString, Bookmark*> FileNameBookmarksMap; - typedef QMap<QString, FileNameBookmarksMap*> DirectoryFileBookmarksMap; + typedef QMultiMap<QString, Bookmark *> FileNameBookmarksMap; + typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap; DirectoryFileBookmarksMap m_bookmarksMap; Core::ICore *m_core; @@ -138,7 +145,7 @@ class BookmarkView : public QListView public: BookmarkView(QWidget *parent = 0); ~BookmarkView(); - void setModel(QAbstractItemModel * model); + void setModel(QAbstractItemModel *model); public slots: void gotoBookmark(const QModelIndex &index); protected slots: @@ -146,7 +153,7 @@ protected slots: void removeAll(); protected: void contextMenuEvent(QContextMenuEvent *event); - void removeBookmark(const QModelIndex& index); + void removeBookmark(const QModelIndex &index); private: BookmarkContext *m_bookmarkContext; QModelIndex m_contextMenuIndex; diff --git a/src/plugins/bookmarks/bookmarksplugin.cpp b/src/plugins/bookmarks/bookmarksplugin.cpp index fa749f7bef9004e952d10b4674d5d399f624abed..83c8ec397ee4ef01e4555c3a29815fca59a2a9c2 100644 --- a/src/plugins/bookmarks/bookmarksplugin.cpp +++ b/src/plugins/bookmarks/bookmarksplugin.cpp @@ -36,17 +36,22 @@ #include "bookmarks_global.h" #include <texteditor/texteditorconstants.h> +#include <texteditor/itexteditor.h> #include <coreplugin/icore.h> +#include <coreplugin/editormanager/ieditor.h> +#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/coreconstants.h> #include <coreplugin/uniqueidmanager.h> #include <coreplugin/actionmanager/actionmanagerinterface.h> #include <QtCore/qplugin.h> +#include <QtCore/QDebug> + #include <QtGui/QMenu> -#include <QDebug> using namespace Bookmarks::Constants; using namespace Bookmarks::Internal; +using namespace TextEditor; BookmarksPlugin *BookmarksPlugin::m_instance = 0; @@ -159,6 +164,19 @@ bool BookmarksPlugin::initialize(const QStringList & /*arguments*/, QString *) updateActions(m_bookmarkManager->state()); addAutoReleasedObject(new BookmarkViewFactory(m_bookmarkManager)); + m_bookmarkMarginAction = new QAction(this); + m_bookmarkMarginAction->setText("Toggle Bookmark"); + //m_bookmarkAction->setIcon(QIcon(":/gdbdebugger/images/breakpoint.svg")); + connect(m_bookmarkMarginAction, SIGNAL(triggered()), + this, SLOT(bookmarkMarginActionTriggered())); + + // EditorManager + QObject *editorManager = m_core->editorManager(); + connect(editorManager, SIGNAL(editorAboutToClose(Core::IEditor*)), + this, SLOT(editorAboutToClose(Core::IEditor*))); + connect(editorManager, SIGNAL(editorOpened(Core::IEditor*)), + this, SLOT(editorOpened(Core::IEditor*))); + return true; } @@ -169,7 +187,6 @@ BookmarksPlugin::~BookmarksPlugin() void BookmarksPlugin::updateActions(int state) { - const bool hasbm = state >= BookmarkManager::HasBookMarks; const bool hasdocbm = state == BookmarkManager::HasBookmarksInDocument; @@ -182,4 +199,32 @@ void BookmarksPlugin::updateActions(int state) m_moveDownAction->setEnabled(hasbm); } +void BookmarksPlugin::editorOpened(Core::IEditor *editor) +{ + connect(editor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), + this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); +} + +void BookmarksPlugin::editorAboutToClose(Core::IEditor *editor) +{ + disconnect(editor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), + this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); +} + +void BookmarksPlugin::requestContextMenu(TextEditor::ITextEditor *editor, + int lineNumber, QMenu *menu) +{ + m_bookmarkMarginActionLineNumber = lineNumber; + m_bookmarkMarginActionFileName = editor->file()->fileName(); + menu->addAction(m_bookmarkMarginAction); +} + +void BookmarksPlugin::bookmarkMarginActionTriggered() +{ + m_bookmarkManager->toggleBookmark( + m_bookmarkMarginActionFileName, + m_bookmarkMarginActionLineNumber + ); +} + Q_EXPORT_PLUGIN(BookmarksPlugin) diff --git a/src/plugins/bookmarks/bookmarksplugin.h b/src/plugins/bookmarks/bookmarksplugin.h index a5d919eb974a1c7d29094893c7c4c637f16c7c2f..2a60bb04a34e94131b4ed71b3f48160f875efaa9 100644 --- a/src/plugins/bookmarks/bookmarksplugin.h +++ b/src/plugins/bookmarks/bookmarksplugin.h @@ -31,18 +31,26 @@ ** ***************************************************************************/ -#ifndef BOOKMARKS_H -#define BOOKMARKS_H +#ifndef BOOKMARKSPLUGIN_H +#define BOOKMARKSPLUGIN_H + +#include <extensionsystem/iplugin.h> #include <QtCore/QObject> #include <QtCore/QMultiMap> -#include <extensionsystem/iplugin.h> - -QT_FORWARD_DECLARE_CLASS(QAction) +QT_BEGIN_NAMESPACE +class QAction; +class QMenu; +QT_END_NAMESPACE namespace Core { class ICore; +class IEditor; +} + +namespace TextEditor { +class ITextEditor; } namespace Bookmarks { @@ -67,6 +75,13 @@ public: public slots: void updateActions(int stateMask); +private slots: + void editorOpened(Core::IEditor *editor); + void editorAboutToClose(Core::IEditor *editor); + void requestContextMenu(TextEditor::ITextEditor *editor, + int lineNumber, QMenu *menu); + void bookmarkMarginActionTriggered(); + private: static BookmarksPlugin *m_instance; BookmarkManager *m_bookmarkManager; @@ -79,6 +94,10 @@ private: QAction *m_docNextAction; QAction *m_moveUpAction; QAction *m_moveDownAction; + + QAction *m_bookmarkMarginAction; + int m_bookmarkMarginActionLineNumber; + QString m_bookmarkMarginActionFileName; }; } // namespace Internal diff --git a/src/plugins/coreplugin/editormanager/ieditor.h b/src/plugins/coreplugin/editormanager/ieditor.h index 7cbac8130ff4eab8894be93fbe4b85ae260f42dd..1f087e67e97b199e38c2019b059f9739d891cc14 100644 --- a/src/plugins/coreplugin/editormanager/ieditor.h +++ b/src/plugins/coreplugin/editormanager/ieditor.h @@ -100,4 +100,4 @@ signals: } // namespace Core -#endif //IEDITOR_H +#endif // IEDITOR_H diff --git a/src/plugins/cpptools/searchsymbols.h b/src/plugins/cpptools/searchsymbols.h index 948f9d78e84ea72898f3e1b87f8baf6f26edac88..1fe276b6bea8c310f2aed3939109056f4259b823 100644 --- a/src/plugins/cpptools/searchsymbols.h +++ b/src/plugins/cpptools/searchsymbols.h @@ -44,6 +44,8 @@ #include <QMetaType> #include <QString> +#include <functional> + namespace CppTools { namespace Internal { diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index b11472a5243db7bf7ca0ed202a8e8789ffa0b066..feb63fa0c306da890538993d03b4871526d425e2 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -250,6 +250,12 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *error_mes m_gdbRunningContext = uidm->uniqueIdentifier(Constants::GDBRUNNING); + m_breakpointMarginAction = new QAction(this); + m_breakpointMarginAction->setText("Toggle Breakpoint"); + //m_breakpointMarginAction->setIcon(QIcon(":/gdbdebugger/images/breakpoint.svg")); + connect(m_breakpointMarginAction, SIGNAL(triggered()), + this, SLOT(breakpointMarginActionTriggered())); + //Core::IActionContainer *mcppcontext = // actionManager->actionContainer(CppEditor::Constants::M_CONTEXT); @@ -502,6 +508,8 @@ void DebuggerPlugin::editorOpened(Core::IEditor *editor) this, SLOT(requestMark(TextEditor::ITextEditor*,int))); connect(editor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*,QPoint,int)), this, SLOT(showToolTip(TextEditor::ITextEditor*,QPoint,int))); + connect(textEditor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), + this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); } } @@ -512,9 +520,27 @@ void DebuggerPlugin::editorAboutToClose(Core::IEditor *editor) this, SLOT(requestMark(TextEditor::ITextEditor*,int))); disconnect(editor, SIGNAL(tooltipRequested(TextEditor::ITextEditor*,QPoint,int)), this, SLOT(showToolTip(TextEditor::ITextEditor*,QPoint,int))); + disconnect(textEditor, SIGNAL(markContextMenuRequested(TextEditor::ITextEditor*,int,QMenu*)), + this, SLOT(requestContextMenu(TextEditor::ITextEditor*,int,QMenu*))); } } +void DebuggerPlugin::requestContextMenu(TextEditor::ITextEditor *editor, + int lineNumber, QMenu *menu) +{ + m_breakpointMarginActionLineNumber = lineNumber; + m_breakpointMarginActionFileName = editor->file()->fileName(); + menu->addAction(m_breakpointMarginAction); +} + +void DebuggerPlugin::breakpointMarginActionTriggered() +{ + m_manager->toggleBreakpoint( + m_breakpointMarginActionFileName, + m_breakpointMarginActionLineNumber + ); +} + void DebuggerPlugin::requestMark(TextEditor::ITextEditor *editor, int lineNumber) { m_manager->toggleBreakpoint(editor->file()->fileName(), lineNumber); diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h index 7dfcae1ffe7f3006a69a644130ba86b807be3174..91ffe4dbf770a43fa839f9d27e4c49818c373d2a 100644 --- a/src/plugins/debugger/debuggerplugin.h +++ b/src/plugins/debugger/debuggerplugin.h @@ -84,10 +84,14 @@ private slots: void setSessionValue(const QString &name, const QVariant &value); void queryConfigValue(const QString &name, QVariant *value); void setConfigValue(const QString &name, const QVariant &value); + void requestContextMenu(TextEditor::ITextEditor *editor, + int lineNumber, QMenu *menu); void resetLocation(); void gotoLocation(const QString &fileName, int line, bool setMarker); + void breakpointMarginActionTriggered(); + private: friend class DebuggerManager; friend class DebugMode; // FIXME: Just a hack now so that it can access the views @@ -104,6 +108,10 @@ private: QString m_previousMode; LocationMark *m_locationMark; int m_gdbRunningContext; + + QAction *m_breakpointMarginAction; + int m_breakpointMarginActionLineNumber; + QString m_breakpointMarginActionFileName; }; } // namespace Internal