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:
hjk
2014-08-20 00:58:38 +02:00
parent c35e928650
commit 869445b76d
4 changed files with 26 additions and 92 deletions

View File

@@ -35,7 +35,6 @@
#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditoractionhandler.h>
#include <QCoreApplication> #include <QCoreApplication>
#include <QSharedPointer>
using namespace TextEditor; using namespace TextEditor;
@@ -48,8 +47,7 @@ namespace Internal {
// //
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesFactory::ProjectFilesFactory(Manager *manager) ProjectFilesFactory::ProjectFilesFactory()
: Core::IEditorFactory(manager)
{ {
setId(Constants::FILES_EDITOR_ID); setId(Constants::FILES_EDITOR_ID);
setDisplayName(QCoreApplication::translate("OpenWith::Editors", ".files Editor")); setDisplayName(QCoreApplication::translate("OpenWith::Editors", ".files Editor"));
@@ -57,33 +55,11 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
addMimeType(Constants::INCLUDES_MIMETYPE); addMimeType(Constants::INCLUDES_MIMETYPE);
addMimeType(Constants::CONFIG_MIMETYPE); addMimeType(Constants::CONFIG_MIMETYPE);
new TextEditor::TextEditorActionHandler(this, Constants::C_FILESEDITOR); new TextEditor::TextEditorActionHandler(this, Constants::C_FILESEDITOR);
} }
Core::IEditor *ProjectFilesFactory::createEditor() Core::IEditor *ProjectFilesFactory::createEditor()
{ {
auto widget = new ProjectFilesEditorWidget; return new ProjectFilesEditor;
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();
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
@@ -92,13 +68,13 @@ Core::IEditor *ProjectFilesEditor::duplicate()
// //
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditorWidget::ProjectFilesEditorWidget() ProjectFilesEditor::ProjectFilesEditor()
{ {
} addContext(Constants::C_FILESEDITOR);
setDuplicateSupported(true);
BaseTextEditor *ProjectFilesEditorWidget::createEditor() setEditorCreator([]() { return new ProjectFilesEditor; });
{ setWidgetCreator([]() { return new BaseTextEditorWidget; });
return new ProjectFilesEditor; setDocumentCreator([]() { return new BaseTextDocument(Constants::FILES_EDITOR_ID); });
} }
} // namespace Internal } // namespace Internal

View File

@@ -31,43 +31,24 @@
#define GENERICPROJECTFILESEDITOR_H #define GENERICPROJECTFILESEDITOR_H
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <texteditor/basetextdocument.h>
#include <coreplugin/editormanager/ieditorfactory.h> #include <coreplugin/editormanager/ieditorfactory.h>
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
class Manager;
class ProjectFilesFactory: public Core::IEditorFactory class ProjectFilesFactory: public Core::IEditorFactory
{ {
Q_OBJECT
public: public:
ProjectFilesFactory(Manager *manager); ProjectFilesFactory();
Core::IEditor *createEditor(); Core::IEditor *createEditor();
}; };
class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
ProjectFilesEditorWidget();
TextEditor::BaseTextEditor *createEditor();
};
class ProjectFilesEditor : public TextEditor::BaseTextEditor class ProjectFilesEditor : public TextEditor::BaseTextEditor
{ {
Q_OBJECT
public: public:
ProjectFilesEditor(); ProjectFilesEditor();
Core::IEditor *duplicate();
}; };
} // namespace Internal } // namespace Internal

View File

@@ -46,72 +46,55 @@
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/selectablefilesmodel.h> #include <projectexplorer/selectablefilesmodel.h>
#include <QtPlugin> #include <QtPlugin>
#include <QDebug> #include <QDebug>
using namespace Core;
using namespace ProjectExplorer;
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
GenericProjectPlugin::GenericProjectPlugin() 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) bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage)
{ {
using namespace Core;
const QLatin1String mimetypesXml(":genericproject/GenericProjectManager.mimetypes.xml"); const QLatin1String mimetypesXml(":genericproject/GenericProjectManager.mimetypes.xml");
if (!MimeDatabase::addMimeTypes(mimetypesXml, errorMessage)) if (!MimeDatabase::addMimeTypes(mimetypesXml, errorMessage))
return false; return false;
Manager *manager = new Manager; addAutoReleasedObject(new Manager);
addAutoReleasedObject(new ProjectFilesFactory);
m_projectFilesEditorFactory = new ProjectFilesFactory(manager);
addObject(m_projectFilesEditorFactory);
addAutoReleasedObject(manager);
addAutoReleasedObject(new GenericMakeStepFactory); addAutoReleasedObject(new GenericMakeStepFactory);
addAutoReleasedObject(new GenericProjectWizard); addAutoReleasedObject(new GenericProjectWizard);
addAutoReleasedObject(new GenericBuildConfigurationFactory); addAutoReleasedObject(new GenericBuildConfigurationFactory);
const Context projectContext(Constants::PROJECTCONTEXT);
ActionContainer *mproject = ActionContainer *mproject =
ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT); 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); command->setAttribute(Command::CA_Hide);
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES); mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
connect(m_editFilesAction, SIGNAL(triggered()), this, SLOT(editFiles()));
connect(ProjectExplorer::ProjectExplorerPlugin::instance(), connect(editFilesAction, &QAction::triggered,
SIGNAL(aboutToShowContextMenu(ProjectExplorer::Project*,ProjectExplorer::Node*)), this, &GenericProjectPlugin::editFiles);
this, SLOT(updateContextMenu(ProjectExplorer::Project*,ProjectExplorer::Node*)));
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::aboutToShowContextMenu,
[this] (Project *project, Node *) { m_contextMenuProject = project; });
return true; return true;
} }
void GenericProjectPlugin::extensionsInitialized()
{ }
void GenericProjectPlugin::updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node*)
{
m_contextMenuProject = project;
}
void GenericProjectPlugin::editFiles() void GenericProjectPlugin::editFiles()
{ {
GenericProject *genericProject = static_cast<GenericProject *>(m_contextMenuProject); GenericProject *genericProject = static_cast<GenericProject *>(m_contextMenuProject);
ProjectExplorer::SelectableFilesDialogEditFiles sfd(genericProject->projectFilePath().toFileInfo().path(), genericProject->files(), SelectableFilesDialogEditFiles sfd(genericProject->projectFilePath().toFileInfo().path(), genericProject->files(),
Core::ICore::mainWindow()); ICore::mainWindow());
if (sfd.exec() == QDialog::Accepted) if (sfd.exec() == QDialog::Accepted)
genericProject->setFiles(sfd.selectedFiles()); genericProject->setFiles(sfd.selectedFiles());
} }

View File

@@ -43,8 +43,6 @@ class Node;
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
class ProjectFilesFactory;
class GenericProjectPlugin : public ExtensionSystem::IPlugin class GenericProjectPlugin : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
@@ -52,13 +50,11 @@ class GenericProjectPlugin : public ExtensionSystem::IPlugin
public: public:
GenericProjectPlugin(); GenericProjectPlugin();
~GenericProjectPlugin();
bool initialize(const QStringList &arguments, QString *errorString); bool initialize(const QStringList &arguments, QString *errorString);
void extensionsInitialized(); void extensionsInitialized() {}
private slots: private slots:
void updateContextMenu(ProjectExplorer::Project *, ProjectExplorer::Node *);
void editFiles(); void editFiles();
#ifdef WITH_TESTS #ifdef WITH_TESTS
@@ -67,8 +63,6 @@ private slots:
#endif // WITH_TESTS #endif // WITH_TESTS
private: private:
ProjectFilesFactory *m_projectFilesEditorFactory;
QAction *m_editFilesAction;
ProjectExplorer::Project *m_contextMenuProject; ProjectExplorer::Project *m_contextMenuProject;
}; };