forked from qt-creator/qt-creator
QmlDesigner.TabViewContextMenu: Remove direct dependencies
The code for creating new files and addFileToVersionControl can be moved to the DocumentManager. Change-Id: I222a32f245da24d7308289a9bb6d30574da55387 Reviewed-by: Marco Bubke <marco.bubke@digia.com>
This commit is contained in:
@@ -28,24 +28,19 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "tabviewdesigneraction.h"
|
#include "tabviewdesigneraction.h"
|
||||||
|
#include "addtabtotabviewdialog.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
|
||||||
|
|
||||||
#include <utils/textfileformat.h>
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <coreplugin/iversioncontrol.h>
|
|
||||||
#include <coreplugin/vcsmanager.h>
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <documentmanager.h>
|
||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
#include <modelnode.h>
|
#include <modelnode.h>
|
||||||
#include <nodeabstractproperty.h>
|
#include <nodeabstractproperty.h>
|
||||||
#include "addtabtotabviewdialog.h"
|
#include <qmldesignerplugin.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -102,35 +97,6 @@ bool TabViewDesignerAction::isEnabled(const SelectionContext &selectionContext)
|
|||||||
return isVisible(selectionContext);
|
return isVisible(selectionContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TabViewDesignerAction::createFile(const QString &filePath)
|
|
||||||
{
|
|
||||||
Utils::TextFileFormat textFileFormat;
|
|
||||||
textFileFormat.codec = Core::EditorManager::defaultTextCodec();
|
|
||||||
QString errorMessage;
|
|
||||||
|
|
||||||
const QString componentString("import QtQuick 2.1\nimport QtQuick.Controls 1.0\n\nItem {\n\n}");
|
|
||||||
|
|
||||||
return textFileFormat.writeFile(filePath, componentString, &errorMessage);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabViewDesignerAction::addNewFileToVersionControl(const QString &directoryPath, const QString &newFilePath)
|
|
||||||
{
|
|
||||||
Core::IVersionControl *versionControl = Core::VcsManager::findVersionControlForDirectory(directoryPath);
|
|
||||||
if (versionControl && versionControl->supportsOperation(Core::IVersionControl::AddOperation)) {
|
|
||||||
const QMessageBox::StandardButton button =
|
|
||||||
QMessageBox::question(Core::ICore::mainWindow(),
|
|
||||||
Core::VcsManager::msgAddToVcsTitle(),
|
|
||||||
Core::VcsManager::msgPromptToAddToVcs(QStringList(newFilePath), versionControl),
|
|
||||||
QMessageBox::Yes | QMessageBox::No);
|
|
||||||
if (button == QMessageBox::Yes && !versionControl->vcsAdd(newFilePath)) {
|
|
||||||
QMessageBox::warning(Core::ICore::mainWindow(),
|
|
||||||
Core::VcsManager::msgAddToVcsFailedTitle(),
|
|
||||||
Core::VcsManager::msgToAddToVcsFailed(QStringList(newFilePath), versionControl));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ModelNode findTabViewModelNode(const ModelNode ¤tModelNode)
|
static ModelNode findTabViewModelNode(const ModelNode ¤tModelNode)
|
||||||
{
|
{
|
||||||
if (currentModelNode.metaInfo().isSubclassOf("QtQuick.Controls.TabView", -1, -1))
|
if (currentModelNode.metaInfo().isSubclassOf("QtQuick.Controls.TabView", -1, -1))
|
||||||
@@ -150,10 +116,10 @@ void TabViewDesignerAction::addNewTab()
|
|||||||
if (QFileInfo(newFilePath).exists()) {
|
if (QFileInfo(newFilePath).exists()) {
|
||||||
QMessageBox::warning(Core::ICore::mainWindow(), tr("Naming Error"), tr("Component already exists."));
|
QMessageBox::warning(Core::ICore::mainWindow(), tr("Naming Error"), tr("Component already exists."));
|
||||||
} else {
|
} else {
|
||||||
bool fileCreated = createFile(newFilePath);
|
bool fileCreated = DocumentManager::createFile(newFilePath, QStringLiteral("import QtQuick 2.1\nimport QtQuick.Controls 1.0\n\nItem {\n\n}"));
|
||||||
|
|
||||||
if (fileCreated) {
|
if (fileCreated) {
|
||||||
addNewFileToVersionControl(directoryPath, newFilePath);
|
DocumentManager::addFileToVersionControl(directoryPath, newFilePath);
|
||||||
|
|
||||||
ModelNode tabViewModelNode = findTabViewModelNode(selectionContext().currentSingleSelectedNode());
|
ModelNode tabViewModelNode = findTabViewModelNode(selectionContext().currentSingleSelectedNode());
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,6 @@ protected:
|
|||||||
bool isVisible(const SelectionContext &selectionContext) const;
|
bool isVisible(const SelectionContext &selectionContext) const;
|
||||||
bool isEnabled(const SelectionContext &selectionContext) const;
|
bool isEnabled(const SelectionContext &selectionContext) const;
|
||||||
|
|
||||||
bool createFile(const QString &filePath);
|
|
||||||
void addNewFileToVersionControl(const QString &directoryPath, const QString &newFileName);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addNewTab();
|
void addNewTab();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,6 +37,14 @@
|
|||||||
#include <bindingproperty.h>
|
#include <bindingproperty.h>
|
||||||
#include <variantproperty.h>
|
#include <variantproperty.h>
|
||||||
|
|
||||||
|
#include <utils/textfileformat.h>
|
||||||
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/iversioncontrol.h>
|
||||||
|
#include <coreplugin/vcsmanager.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
static inline DesignDocument* currentDesignDocument()
|
static inline DesignDocument* currentDesignDocument()
|
||||||
@@ -262,5 +270,31 @@ void DocumentManager::goIntoComponent(const ModelNode &modelNode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DocumentManager::createFile(const QString &filePath, const QString &contents)
|
||||||
|
{
|
||||||
|
Utils::TextFileFormat textFileFormat;
|
||||||
|
textFileFormat.codec = Core::EditorManager::defaultTextCodec();
|
||||||
|
QString errorMessage;
|
||||||
|
|
||||||
|
return textFileFormat.writeFile(filePath, contents, &errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DocumentManager::addFileToVersionControl(const QString &directoryPath, const QString &newFilePath)
|
||||||
|
{
|
||||||
|
Core::IVersionControl *versionControl = Core::VcsManager::findVersionControlForDirectory(directoryPath);
|
||||||
|
if (versionControl && versionControl->supportsOperation(Core::IVersionControl::AddOperation)) {
|
||||||
|
const QMessageBox::StandardButton button =
|
||||||
|
QMessageBox::question(Core::ICore::mainWindow(),
|
||||||
|
Core::VcsManager::msgAddToVcsTitle(),
|
||||||
|
Core::VcsManager::msgPromptToAddToVcs(QStringList(newFilePath), versionControl),
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
if (button == QMessageBox::Yes && !versionControl->vcsAdd(newFilePath)) {
|
||||||
|
QMessageBox::warning(Core::ICore::mainWindow(),
|
||||||
|
Core::VcsManager::msgAddToVcsFailedTitle(),
|
||||||
|
Core::VcsManager::msgToAddToVcsFailed(QStringList(newFilePath), versionControl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ public:
|
|||||||
|
|
||||||
static void goIntoComponent(const ModelNode &modelNode);
|
static void goIntoComponent(const ModelNode &modelNode);
|
||||||
|
|
||||||
|
static bool createFile(const QString &filePath, const QString &contents);
|
||||||
|
static void addFileToVersionControl(const QString &directoryPath, const QString &newFilePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<Core::IEditor *,QPointer<DesignDocument> > m_designDocumentHash;
|
QHash<Core::IEditor *,QPointer<DesignDocument> > m_designDocumentHash;
|
||||||
QPointer<DesignDocument> m_currentDesignDocument;
|
QPointer<DesignDocument> m_currentDesignDocument;
|
||||||
|
|||||||
Reference in New Issue
Block a user