forked from qt-creator/qt-creator
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: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -64,9 +64,11 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
@@ -233,6 +235,8 @@ EditorManagerPrivate::EditorManagerPrivate(QObject *parent) :
|
||||
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_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_saveAsCurrentEditorContextAction(new QAction(EditorManager::tr("Save &As..."), this)),
|
||||
m_revertToSavedCurrentEditorContextAction(new QAction(EditorManager::tr("Revert to Saved"), this)),
|
||||
@@ -348,6 +352,10 @@ void EditorManagerPrivate::init()
|
||||
this, SLOT(closeAllEditorsExceptVisible()));
|
||||
|
||||
//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()),
|
||||
this, SLOT(saveDocumentFromContextMenu()));
|
||||
connect(m_saveAsCurrentEditorContextAction, SIGNAL(triggered()),
|
||||
@@ -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()
|
||||
{
|
||||
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
|
||||
@@ -1860,6 +1883,14 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentMod
|
||||
QTC_ASSERT(contextMenu, return);
|
||||
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_saveAsCurrentEditorContextAction, ActionManager::command(Constants::SAVEAS)->action());
|
||||
assignAction(d->m_revertToSavedCurrentEditorContextAction, ActionManager::command(Constants::REVERTTOSAVED)->action());
|
||||
|
||||
@@ -127,6 +127,8 @@ private slots:
|
||||
static void autoSave();
|
||||
static void handleContextChange(const QList<Core::IContext *> &context);
|
||||
|
||||
static void copyFilePathFromContextMenu();
|
||||
static void copyFileNameFromContextMenu();
|
||||
static void saveDocumentFromContextMenu();
|
||||
static void saveDocumentAsFromContextMenu();
|
||||
static void revertToSavedFromContextMenu();
|
||||
@@ -198,6 +200,8 @@ private:
|
||||
QAction *m_removeAllSplitsAction;
|
||||
QAction *m_gotoNextSplitAction;
|
||||
|
||||
QAction *m_copyFilePathContextAction;
|
||||
QAction *m_copyFileNameContextAction;
|
||||
QAction *m_saveCurrentEditorContextAction;
|
||||
QAction *m_saveAsCurrentEditorContextAction;
|
||||
QAction *m_revertToSavedCurrentEditorContextAction;
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QToolButton>
|
||||
#include <QMenu>
|
||||
#include <QClipboard>
|
||||
|
||||
enum {
|
||||
debug = false
|
||||
@@ -317,24 +316,11 @@ void EditorToolBar::listContextMenu(QPoint pos)
|
||||
{
|
||||
DocumentModel::Entry *entry = DocumentModel::entryAtRow(
|
||||
d->m_editorList->currentIndex());
|
||||
QString fileName = entry ? entry->fileName() : QString();
|
||||
QString shortFileName = entry ? QFileInfo(fileName).fileName() : QString();
|
||||
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);
|
||||
menu.addSeparator();
|
||||
EditorManager::addNativeDirAndOpenWithActions(&menu, entry);
|
||||
QAction *result = menu.exec(d->m_editorList->mapToGlobal(pos));
|
||||
if (result == copyPath)
|
||||
QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
|
||||
if (result == copyFileName)
|
||||
QApplication::clipboard()->setText(shortFileName);
|
||||
menu.exec(d->m_editorList->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void EditorToolBar::makeEditorWritable()
|
||||
|
||||
Reference in New Issue
Block a user