Commit 869445b7 authored by hjk's avatar hjk

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 @@
#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,48 +55,26 @@ 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();
return new ProjectFilesEditor;
}
////////////////////////////////////////////////////////////////////////////////////////
//
// ProjectFilesEditable
// ProjectFilesEditor
//
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditor::ProjectFilesEditor()
{
setContext(Core::Context(Constants::C_FILESEDITOR));
addContext(Constants::C_FILESEDITOR);
setDuplicateSupported(true);
}
Core::IEditor *ProjectFilesEditor::duplicate()
{
auto widget = new ProjectFilesEditorWidget;
widget->setTextDocument(editorWidget()->textDocumentPtr());
return widget->editor();
}
////////////////////////////////////////////////////////////////////////////////////////
//
// ProjectFilesEditor
//
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditorWidget::ProjectFilesEditorWidget()
{
}
BaseTextEditor *ProjectFilesEditorWidget::createEditor()
{
return new ProjectFilesEditor;
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);
return true;
}
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::aboutToShowContextMenu,
[this] (Project *project, Node *) { m_contextMenuProject = project; });
void GenericProjectPlugin::extensionsInitialized()
{ }
void GenericProjectPlugin::updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node*)
{
m_contextMenuProject = project;
return true;
}
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;
};
......
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