Commit 869445b7 authored by hjk's avatar hjk
Browse files

GenericProjectManager: General editor related code consolidation



Convert to new editor setup scheme, minor cleanups.

Change-Id: I1ac9169b9d397500317595a1a964347b0f7de19d
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent c35e9286
...@@ -35,7 +35,6 @@ ...@@ -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 { ...@@ -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,48 +55,26 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager) ...@@ -57,48 +55,26 @@ 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::ProjectFilesEditor() ProjectFilesEditor::ProjectFilesEditor()
{ {
setContext(Core::Context(Constants::C_FILESEDITOR)); addContext(Constants::C_FILESEDITOR);
setDuplicateSupported(true); setDuplicateSupported(true);
} setEditorCreator([]() { return new ProjectFilesEditor; });
setWidgetCreator([]() { return new BaseTextEditorWidget; });
Core::IEditor *ProjectFilesEditor::duplicate() setDocumentCreator([]() { return new BaseTextDocument(Constants::FILES_EDITOR_ID); });
{
auto widget = new ProjectFilesEditorWidget;
widget->setTextDocument(editorWidget()->textDocumentPtr());
return widget->editor();
}
////////////////////////////////////////////////////////////////////////////////////////
//
// ProjectFilesEditor
//
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditorWidget::ProjectFilesEditorWidget()
{
}
BaseTextEditor *ProjectFilesEditorWidget::createEditor()
{
return new ProjectFilesEditor;
} }
} // namespace Internal } // namespace Internal
......
...@@ -31,43 +31,24 @@ ...@@ -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
......
...@@ -46,72 +46,55 @@ ...@@ -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*)));
return true; connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::aboutToShowContextMenu,
} [this] (Project *project, Node *) { m_contextMenuProject = project; });
void GenericProjectPlugin::extensionsInitialized() return true;
{ }
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());
} }
......
...@@ -43,8 +43,6 @@ class Node; ...@@ -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 ...@@ -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: ...@@ -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;
}; };
......
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