Commit 0e0471d6 authored by Eike Ziller's avatar Eike Ziller
Browse files

EditorToolBar: Show editor context menu when clicking on file icon



Change-Id: I0a66d7a2a77ed0b2c7c87005887a7847bb9ee5f5
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent e0c5d236
......@@ -83,8 +83,7 @@ EditorView::EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent) :
connect(m_toolBar, SIGNAL(verticalSplitClicked()), this, SLOT(splitVertically()));
connect(m_toolBar, SIGNAL(splitNewWindowClicked()), this, SLOT(splitNewWindow()));
connect(m_toolBar, SIGNAL(closeSplitClicked()), this, SLOT(closeSplit()));
connect(m_toolBar, &EditorToolBar::listContextMenuRequested,
this, &EditorView::showListContextMenu);
m_toolBar->setMenuProvider([this](QMenu *menu) { fillListContextMenu(menu); });
tl->addWidget(m_toolBar);
}
......@@ -316,16 +315,14 @@ void EditorView::listSelectionActivated(int index)
EditorManagerPrivate::activateEditorForEntry(this, DocumentModel::entryAtRow(index));
}
void EditorView::showListContextMenu(QPoint pos)
void EditorView::fillListContextMenu(QMenu *menu)
{
IEditor *editor = currentEditor();
DocumentModel::Entry entry;
entry.document = editor ? editor->document() : 0;
QMenu menu;
EditorManager::addSaveAndCloseEditorActions(&menu, &entry, editor);
menu.addSeparator();
EditorManager::addNativeDirAndOpenWithActions(&menu, &entry);
menu.exec(pos);
DocumentModel::Entry *entry = editor ? DocumentModel::entryForDocument(editor->document())
: 0;
EditorManager::addSaveAndCloseEditorActions(menu, entry, editor);
menu->addSeparator();
EditorManager::addNativeDirAndOpenWithActions(menu, entry);
}
void EditorView::splitHorizontally()
......
......@@ -46,6 +46,7 @@ class QAction;
class QComboBox;
class QFrame;
class QLabel;
class QMenu;
class QSplitter;
class QStackedLayout;
class QStackedWidget;
......@@ -114,7 +115,6 @@ protected:
private slots:
void closeCurrentEditor();
void listSelectionActivated(int index);
void showListContextMenu(QPoint pos);
void splitHorizontally();
void splitVertically();
void splitNewWindow();
......@@ -125,6 +125,7 @@ private:
friend class SplitterOrView; // for setParentSplitterOrView
void setParentSplitterOrView(SplitterOrView *splitterOrView);
void fillListContextMenu(QMenu *menu);
void updateNavigatorActions();
void updateToolBar(IEditor *editor);
void checkProjectLoaded(IEditor *editor);
......
......@@ -70,6 +70,8 @@ struct EditorToolBarPrivate
QToolButton *m_closeEditorButton;
QToolButton *m_lockButton;
QToolButton *m_dragHandle;
QMenu *m_dragHandleMenu;
EditorToolBar::MenuProvider m_menuProvider;
QAction *m_goBackAction;
QAction *m_goForwardAction;
QToolButton *m_backButton;
......@@ -127,10 +129,11 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
d->m_lockButton->setAutoRaise(true);
d->m_lockButton->setEnabled(false);
d->m_dragHandle->setCheckable(false);
d->m_dragHandle->setChecked(false);
d->m_dragHandle->setProperty("noArrow", true);
d->m_dragHandle->setToolTip(tr("Drag to drag documents between splits"));
d->m_dragHandle->installEventFilter(this);
d->m_dragHandleMenu = new QMenu(d->m_dragHandle);
d->m_dragHandle->setMenu(d->m_dragHandleMenu);
connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked()));
connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked()));
......@@ -194,7 +197,15 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
// a private slot connection
connect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
connect(d->m_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint)));
connect(d->m_editorList, &QComboBox::customContextMenuRequested, [this](QPoint p) {
QMenu menu;
fillListContextMenu(&menu);
menu.exec(d->m_editorList->mapToGlobal(p));
});
connect(d->m_dragHandleMenu, &QMenu::aboutToShow, [this]() {
d->m_dragHandleMenu->clear();
fillListContextMenu(d->m_dragHandleMenu);
});
connect(d->m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
connect(d->m_closeEditorButton, SIGNAL(clicked()), this, SLOT(closeEditor()), Qt::QueuedConnection);
connect(d->m_horizontalSplitAction, SIGNAL(triggered()),
......@@ -302,6 +313,11 @@ void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
}
}
void EditorToolBar::setMenuProvider(const EditorToolBar::MenuProvider &provider)
{
d->m_menuProvider = provider;
}
void EditorToolBar::setCurrentEditor(IEditor *editor)
{
IDocument *document = editor ? editor->document() : 0;
......@@ -326,19 +342,17 @@ void EditorToolBar::changeActiveEditor(int row)
EditorManager::activateEditorForEntry(DocumentModel::entryAtRow(row));
}
void EditorToolBar::listContextMenu(QPoint pos)
void EditorToolBar::fillListContextMenu(QMenu *menu)
{
if (d->m_isStandalone) {
IEditor *editor = EditorManager::currentEditor();
DocumentModel::Entry entry;
entry.document = editor ? editor->document() : 0;
QMenu menu;
EditorManager::addSaveAndCloseEditorActions(&menu, &entry, editor);
menu.addSeparator();
EditorManager::addNativeDirAndOpenWithActions(&menu, &entry);
menu.exec(d->m_editorList->mapToGlobal(pos));
if (d->m_menuProvider) {
d->m_menuProvider(menu);
} else {
emit listContextMenuRequested(d->m_editorList->mapToGlobal(pos));
IEditor *editor = EditorManager::currentEditor();
DocumentModel::Entry *entry = editor ? DocumentModel::entryForDocument(editor->document())
: 0;
EditorManager::addSaveAndCloseEditorActions(menu, entry, editor);
menu->addSeparator();
EditorManager::addNativeDirAndOpenWithActions(menu, entry);
}
}
......@@ -422,11 +436,12 @@ bool EditorToolBar::eventFilter(QObject *obj, QEvent *event)
if (obj == d->m_dragHandle) {
if (event->type() == QEvent::MouseButtonPress) {
auto me = static_cast<QMouseEvent *>(event);
if (me->buttons() == Qt::LeftButton) {
if (me->buttons() == Qt::LeftButton)
d->m_dragStartPosition = me->pos();
return true;
}
return Utils::StyledBar::eventFilter(obj, event);
return true; // do not pop up menu already on press
} else if (event->type() == QEvent::MouseButtonRelease) {
d->m_dragHandle->showMenu();
return true;
} else if (event->type() == QEvent::MouseMove) {
auto me = static_cast<QMouseEvent *>(event);
if (me->buttons() != Qt::LeftButton)
......
......@@ -36,6 +36,12 @@
#include <QIcon>
#include <functional>
QT_BEGIN_NAMESPACE
class QMenu;
QT_END_NAMESPACE
namespace Core {
class IEditor;
class IDocument;
......@@ -54,6 +60,7 @@ public:
explicit EditorToolBar(QWidget *parent = 0);
virtual ~EditorToolBar();
typedef std::function<void(QMenu*)> MenuProvider;
enum ToolbarCreationFlags { FlagsNone = 0, FlagsStandalone = 1 };
/**
......@@ -68,6 +75,7 @@ public:
void setCurrentEditor(IEditor *editor);
void setToolbarCreationFlags(ToolbarCreationFlags flags);
void setMenuProvider(const MenuProvider &provider);
/**
* Adds a toolbar to the widget and sets invisible by default.
......@@ -93,7 +101,6 @@ signals:
void splitNewWindowClicked();
void closeSplitClicked();
void listSelectionActivated(int row);
void listContextMenuRequested(QPoint globalpos);
void currentDocumentMoved();
protected:
......@@ -102,7 +109,6 @@ protected:
private slots:
void updateEditorListSelection(Core::IEditor *newSelection);
void changeActiveEditor(int row);
void listContextMenu(QPoint pos);
void makeEditorWritable();
void checkDocumentStatus();
......@@ -110,6 +116,7 @@ private slots:
void updateActionShortcuts();
private:
void fillListContextMenu(QMenu *menu);
void updateToolBar(QWidget *toolBar);
EditorToolBarPrivate *d;
......
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