Commit 01d86d8c authored by Eike Ziller's avatar Eike Ziller
Browse files

Move copyFilePath/Name context actions to editor manager



Synchronizing the context menus on the open documents pane and the
editor tool bar.

Change-Id: I29f614d483a425dec58fc1247b691fd433c4acc0
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 1dd05a18
...@@ -64,9 +64,11 @@ ...@@ -64,9 +64,11 @@
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QClipboard>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
...@@ -233,6 +235,8 @@ EditorManagerPrivate::EditorManagerPrivate(QObject *parent) : ...@@ -233,6 +235,8 @@ EditorManagerPrivate::EditorManagerPrivate(QObject *parent) :
m_gotoPreviousDocHistoryAction(new QAction(EditorManager::tr("Previous Open Document in History"), this)), m_gotoPreviousDocHistoryAction(new QAction(EditorManager::tr("Previous Open Document in History"), this)),
m_goBackAction(new QAction(QIcon(QLatin1String(Constants::ICON_PREV)), EditorManager::tr("Go Back"), this)), m_goBackAction(new QAction(QIcon(QLatin1String(Constants::ICON_PREV)), EditorManager::tr("Go Back"), this)),
m_goForwardAction(new QAction(QIcon(QLatin1String(Constants::ICON_NEXT)), EditorManager::tr("Go Forward"), this)), m_goForwardAction(new QAction(QIcon(QLatin1String(Constants::ICON_NEXT)), EditorManager::tr("Go Forward"), this)),
m_copyFilePathContextAction(new QAction(EditorManager::tr("Copy Full Path to Clipboard"), this)),
m_copyFileNameContextAction(new QAction(EditorManager::tr("Copy File Name to Clipboard"), this)),
m_saveCurrentEditorContextAction(new QAction(EditorManager::tr("&Save"), this)), m_saveCurrentEditorContextAction(new QAction(EditorManager::tr("&Save"), this)),
m_saveAsCurrentEditorContextAction(new QAction(EditorManager::tr("Save &As..."), this)), m_saveAsCurrentEditorContextAction(new QAction(EditorManager::tr("Save &As..."), this)),
m_revertToSavedCurrentEditorContextAction(new QAction(EditorManager::tr("Revert to Saved"), this)), m_revertToSavedCurrentEditorContextAction(new QAction(EditorManager::tr("Revert to Saved"), this)),
...@@ -348,6 +352,10 @@ void EditorManagerPrivate::init() ...@@ -348,6 +352,10 @@ void EditorManagerPrivate::init()
this, SLOT(closeAllEditorsExceptVisible())); this, SLOT(closeAllEditorsExceptVisible()));
//Save XXX Context Actions //Save XXX Context Actions
connect(m_copyFilePathContextAction, SIGNAL(triggered()),
this, SLOT(copyFilePathFromContextMenu()));
connect(m_copyFileNameContextAction, SIGNAL(triggered()),
this, SLOT(copyFileNameFromContextMenu()));
connect(m_saveCurrentEditorContextAction, SIGNAL(triggered()), connect(m_saveCurrentEditorContextAction, SIGNAL(triggered()),
this, SLOT(saveDocumentFromContextMenu())); this, SLOT(saveDocumentFromContextMenu()));
connect(m_saveAsCurrentEditorContextAction, SIGNAL(triggered()), connect(m_saveAsCurrentEditorContextAction, SIGNAL(triggered()),
...@@ -1551,6 +1559,21 @@ void EditorManagerPrivate::handleContextChange(const QList<IContext *> &context) ...@@ -1551,6 +1559,21 @@ void EditorManagerPrivate::handleContextChange(const QList<IContext *> &context)
} }
} }
void EditorManagerPrivate::copyFilePathFromContextMenu()
{
if (!d->m_contextMenuEntry)
return;
QApplication::clipboard()->setText(Utils::FileName::fromString(
d->m_contextMenuEntry->fileName()).toUserOutput());
}
void EditorManagerPrivate::copyFileNameFromContextMenu()
{
if (!d->m_contextMenuEntry)
return;
QApplication::clipboard()->setText(QFileInfo(d->m_contextMenuEntry->fileName()).fileName());
}
void EditorManagerPrivate::saveDocumentFromContextMenu() void EditorManagerPrivate::saveDocumentFromContextMenu()
{ {
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0; IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
...@@ -1860,6 +1883,14 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentMod ...@@ -1860,6 +1883,14 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentMod
QTC_ASSERT(contextMenu, return); QTC_ASSERT(contextMenu, return);
d->m_contextMenuEntry = entry; d->m_contextMenuEntry = entry;
const QString filePath = entry ? entry->fileName() : QString();
const bool copyActionsEnabled = !filePath.isEmpty();
d->m_copyFilePathContextAction->setEnabled(copyActionsEnabled);
d->m_copyFileNameContextAction->setEnabled(copyActionsEnabled);
contextMenu->addAction(d->m_copyFilePathContextAction);
contextMenu->addAction(d->m_copyFileNameContextAction);
contextMenu->addSeparator();
assignAction(d->m_saveCurrentEditorContextAction, ActionManager::command(Constants::SAVE)->action()); assignAction(d->m_saveCurrentEditorContextAction, ActionManager::command(Constants::SAVE)->action());
assignAction(d->m_saveAsCurrentEditorContextAction, ActionManager::command(Constants::SAVEAS)->action()); assignAction(d->m_saveAsCurrentEditorContextAction, ActionManager::command(Constants::SAVEAS)->action());
assignAction(d->m_revertToSavedCurrentEditorContextAction, ActionManager::command(Constants::REVERTTOSAVED)->action()); assignAction(d->m_revertToSavedCurrentEditorContextAction, ActionManager::command(Constants::REVERTTOSAVED)->action());
......
...@@ -127,6 +127,8 @@ private slots: ...@@ -127,6 +127,8 @@ private slots:
static void autoSave(); static void autoSave();
static void handleContextChange(const QList<Core::IContext *> &context); static void handleContextChange(const QList<Core::IContext *> &context);
static void copyFilePathFromContextMenu();
static void copyFileNameFromContextMenu();
static void saveDocumentFromContextMenu(); static void saveDocumentFromContextMenu();
static void saveDocumentAsFromContextMenu(); static void saveDocumentAsFromContextMenu();
static void revertToSavedFromContextMenu(); static void revertToSavedFromContextMenu();
...@@ -198,6 +200,8 @@ private: ...@@ -198,6 +200,8 @@ private:
QAction *m_removeAllSplitsAction; QAction *m_removeAllSplitsAction;
QAction *m_gotoNextSplitAction; QAction *m_gotoNextSplitAction;
QAction *m_copyFilePathContextAction;
QAction *m_copyFileNameContextAction;
QAction *m_saveCurrentEditorContextAction; QAction *m_saveCurrentEditorContextAction;
QAction *m_saveAsCurrentEditorContextAction; QAction *m_saveAsCurrentEditorContextAction;
QAction *m_revertToSavedCurrentEditorContextAction; QAction *m_revertToSavedCurrentEditorContextAction;
......
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QToolButton> #include <QToolButton>
#include <QMenu> #include <QMenu>
#include <QClipboard>
enum { enum {
debug = false debug = false
...@@ -317,24 +316,11 @@ void EditorToolBar::listContextMenu(QPoint pos) ...@@ -317,24 +316,11 @@ void EditorToolBar::listContextMenu(QPoint pos)
{ {
DocumentModel::Entry *entry = DocumentModel::entryAtRow( DocumentModel::Entry *entry = DocumentModel::entryAtRow(
d->m_editorList->currentIndex()); d->m_editorList->currentIndex());
QString fileName = entry ? entry->fileName() : QString();
QString shortFileName = entry ? QFileInfo(fileName).fileName() : QString();
QMenu menu; QMenu menu;
QAction *copyPath = menu.addAction(tr("Copy Full Path to Clipboard"));
QAction *copyFileName = menu.addAction(tr("Copy File Name to Clipboard"));
menu.addSeparator();
if (fileName.isEmpty() || shortFileName.isEmpty()) {
copyPath->setEnabled(false);
copyFileName->setEnabled(false);
}
EditorManager::addSaveAndCloseEditorActions(&menu, entry); EditorManager::addSaveAndCloseEditorActions(&menu, entry);
menu.addSeparator(); menu.addSeparator();
EditorManager::addNativeDirAndOpenWithActions(&menu, entry); EditorManager::addNativeDirAndOpenWithActions(&menu, entry);
QAction *result = menu.exec(d->m_editorList->mapToGlobal(pos)); menu.exec(d->m_editorList->mapToGlobal(pos));
if (result == copyPath)
QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
if (result == copyFileName)
QApplication::clipboard()->setText(shortFileName);
} }
void EditorToolBar::makeEditorWritable() void EditorToolBar::makeEditorWritable()
......
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