Commit 0e8d02aa authored by hjk's avatar hjk

populate texteditor margin context menu

parent 45c4d73e
......@@ -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:
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......@@ -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
......
......@@ -100,4 +100,4 @@ signals:
} // namespace Core
#endif //IEDITOR_H
#endif // IEDITOR_H
......@@ -44,6 +44,8 @@
#include <QMetaType>
#include <QString>
#include <functional>
namespace CppTools {
namespace Internal {
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment