forked from qt-creator/qt-creator
GenericProjectManager: General editor related code consolidation
Convert to new editor setup scheme, minor cleanups. Change-Id: I1ac9169b9d397500317595a1a964347b0f7de19d Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -35,7 +35,6 @@
|
||||
#include <texteditor/texteditoractionhandler.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QSharedPointer>
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
@@ -48,8 +47,7 @@ namespace Internal {
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
|
||||
: Core::IEditorFactory(manager)
|
||||
ProjectFilesFactory::ProjectFilesFactory()
|
||||
{
|
||||
setId(Constants::FILES_EDITOR_ID);
|
||||
setDisplayName(QCoreApplication::translate("OpenWith::Editors", ".files Editor"));
|
||||
@@ -57,33 +55,11 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
|
||||
addMimeType(Constants::INCLUDES_MIMETYPE);
|
||||
addMimeType(Constants::CONFIG_MIMETYPE);
|
||||
new TextEditor::TextEditorActionHandler(this, Constants::C_FILESEDITOR);
|
||||
|
||||
}
|
||||
|
||||
Core::IEditor *ProjectFilesFactory::createEditor()
|
||||
{
|
||||
auto widget = new ProjectFilesEditorWidget;
|
||||
widget->setSimpleTextDocument(Constants::FILES_EDITOR_ID);
|
||||
return widget->editor();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ProjectFilesEditable
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProjectFilesEditor::ProjectFilesEditor()
|
||||
{
|
||||
setContext(Core::Context(Constants::C_FILESEDITOR));
|
||||
setDuplicateSupported(true);
|
||||
}
|
||||
|
||||
Core::IEditor *ProjectFilesEditor::duplicate()
|
||||
{
|
||||
auto widget = new ProjectFilesEditorWidget;
|
||||
widget->setTextDocument(editorWidget()->textDocumentPtr());
|
||||
return widget->editor();
|
||||
return new ProjectFilesEditor;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -92,13 +68,13 @@ Core::IEditor *ProjectFilesEditor::duplicate()
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProjectFilesEditorWidget::ProjectFilesEditorWidget()
|
||||
ProjectFilesEditor::ProjectFilesEditor()
|
||||
{
|
||||
}
|
||||
|
||||
BaseTextEditor *ProjectFilesEditorWidget::createEditor()
|
||||
{
|
||||
return new ProjectFilesEditor;
|
||||
addContext(Constants::C_FILESEDITOR);
|
||||
setDuplicateSupported(true);
|
||||
setEditorCreator([]() { return new ProjectFilesEditor; });
|
||||
setWidgetCreator([]() { return new BaseTextEditorWidget; });
|
||||
setDocumentCreator([]() { return new BaseTextDocument(Constants::FILES_EDITOR_ID); });
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -31,43 +31,24 @@
|
||||
#define GENERICPROJECTFILESEDITOR_H
|
||||
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <texteditor/basetextdocument.h>
|
||||
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
|
||||
namespace GenericProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class Manager;
|
||||
|
||||
class ProjectFilesFactory: public Core::IEditorFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProjectFilesFactory(Manager *manager);
|
||||
ProjectFilesFactory();
|
||||
|
||||
Core::IEditor *createEditor();
|
||||
};
|
||||
|
||||
class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProjectFilesEditorWidget();
|
||||
|
||||
TextEditor::BaseTextEditor *createEditor();
|
||||
};
|
||||
|
||||
class ProjectFilesEditor : public TextEditor::BaseTextEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProjectFilesEditor();
|
||||
|
||||
Core::IEditor *duplicate();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -46,72 +46,55 @@
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/selectablefilesmodel.h>
|
||||
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace GenericProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
GenericProjectPlugin::GenericProjectPlugin()
|
||||
: m_projectFilesEditorFactory(0), m_editFilesAction(0), m_contextMenuProject(0)
|
||||
: m_contextMenuProject(0)
|
||||
{ }
|
||||
|
||||
GenericProjectPlugin::~GenericProjectPlugin()
|
||||
{
|
||||
removeObject(m_projectFilesEditorFactory);
|
||||
delete m_projectFilesEditorFactory;
|
||||
}
|
||||
|
||||
bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage)
|
||||
{
|
||||
using namespace Core;
|
||||
|
||||
const QLatin1String mimetypesXml(":genericproject/GenericProjectManager.mimetypes.xml");
|
||||
|
||||
if (!MimeDatabase::addMimeTypes(mimetypesXml, errorMessage))
|
||||
return false;
|
||||
|
||||
Manager *manager = new Manager;
|
||||
|
||||
m_projectFilesEditorFactory = new ProjectFilesFactory(manager);
|
||||
addObject(m_projectFilesEditorFactory);
|
||||
|
||||
addAutoReleasedObject(manager);
|
||||
addAutoReleasedObject(new Manager);
|
||||
addAutoReleasedObject(new ProjectFilesFactory);
|
||||
addAutoReleasedObject(new GenericMakeStepFactory);
|
||||
addAutoReleasedObject(new GenericProjectWizard);
|
||||
addAutoReleasedObject(new GenericBuildConfigurationFactory);
|
||||
|
||||
const Context projectContext(Constants::PROJECTCONTEXT);
|
||||
ActionContainer *mproject =
|
||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
|
||||
m_editFilesAction = new QAction(tr("Edit Files..."), this);
|
||||
|
||||
Command *command = ActionManager::registerAction(m_editFilesAction, "GenericProjectManager.EditFiles", projectContext);
|
||||
auto editFilesAction = new QAction(tr("Edit Files..."), this);
|
||||
Command *command = ActionManager::registerAction(editFilesAction,
|
||||
"GenericProjectManager.EditFiles", Context(Constants::PROJECTCONTEXT));
|
||||
command->setAttribute(Command::CA_Hide);
|
||||
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
|
||||
connect(m_editFilesAction, SIGNAL(triggered()), this, SLOT(editFiles()));
|
||||
|
||||
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
|
||||
SIGNAL(aboutToShowContextMenu(ProjectExplorer::Project*,ProjectExplorer::Node*)),
|
||||
this, SLOT(updateContextMenu(ProjectExplorer::Project*,ProjectExplorer::Node*)));
|
||||
connect(editFilesAction, &QAction::triggered,
|
||||
this, &GenericProjectPlugin::editFiles);
|
||||
|
||||
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::aboutToShowContextMenu,
|
||||
[this] (Project *project, Node *) { m_contextMenuProject = project; });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GenericProjectPlugin::extensionsInitialized()
|
||||
{ }
|
||||
|
||||
void GenericProjectPlugin::updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node*)
|
||||
{
|
||||
m_contextMenuProject = project;
|
||||
}
|
||||
|
||||
void GenericProjectPlugin::editFiles()
|
||||
{
|
||||
GenericProject *genericProject = static_cast<GenericProject *>(m_contextMenuProject);
|
||||
ProjectExplorer::SelectableFilesDialogEditFiles sfd(genericProject->projectFilePath().toFileInfo().path(), genericProject->files(),
|
||||
Core::ICore::mainWindow());
|
||||
SelectableFilesDialogEditFiles sfd(genericProject->projectFilePath().toFileInfo().path(), genericProject->files(),
|
||||
ICore::mainWindow());
|
||||
if (sfd.exec() == QDialog::Accepted)
|
||||
genericProject->setFiles(sfd.selectedFiles());
|
||||
}
|
||||
|
||||
@@ -43,8 +43,6 @@ class Node;
|
||||
namespace GenericProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class ProjectFilesFactory;
|
||||
|
||||
class GenericProjectPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -52,13 +50,11 @@ class GenericProjectPlugin : public ExtensionSystem::IPlugin
|
||||
|
||||
public:
|
||||
GenericProjectPlugin();
|
||||
~GenericProjectPlugin();
|
||||
|
||||
bool initialize(const QStringList &arguments, QString *errorString);
|
||||
void extensionsInitialized();
|
||||
void extensionsInitialized() {}
|
||||
|
||||
private slots:
|
||||
void updateContextMenu(ProjectExplorer::Project *, ProjectExplorer::Node *);
|
||||
void editFiles();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
@@ -67,8 +63,6 @@ private slots:
|
||||
#endif // WITH_TESTS
|
||||
|
||||
private:
|
||||
ProjectFilesFactory *m_projectFilesEditorFactory;
|
||||
QAction *m_editFilesAction;
|
||||
ProjectExplorer::Project *m_contextMenuProject;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user