genericprojectfileseditor.cpp 4.79 KB
Newer Older
1 2 3 4 5 6
#include "genericprojectfileseditor.h"
#include "genericprojectmanager.h"
#include "genericprojectconstants.h"

#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
7 8
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
9 10 11 12 13 14 15 16

using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;


////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesEditable
////////////////////////////////////////////////////////////////////////////////////////
17

18 19 20 21 22 23 24 25
ProjectFilesFactory::ProjectFilesFactory(Manager *manager,
                                         TextEditor::TextEditorActionHandler *handler)
    : Core::IEditorFactory(manager),
      _manager(manager),
      _actionHandler(handler)
{
    _mimeTypes.append(QLatin1String(Constants::FILES_MIMETYPE));
    _mimeTypes.append(QLatin1String(Constants::INCLUDES_MIMETYPE));
Roberto Raggi's avatar
Roberto Raggi committed
26
    _mimeTypes.append(QLatin1String(Constants::CONFIG_MIMETYPE));
27 28 29
}

ProjectFilesFactory::~ProjectFilesFactory()
30 31
{
}
32 33

Manager *ProjectFilesFactory::manager() const
34 35 36
{
    return _manager;
}
37 38 39 40

Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent)
{
    ProjectFilesEditor *ed = new ProjectFilesEditor(parent, this, _actionHandler);
41
    ed->initialize();
42 43 44 45
    return ed->editableInterface();
}

QStringList ProjectFilesFactory::mimeTypes() const
46 47 48
{
    return _mimeTypes;
}
49 50

QString ProjectFilesFactory::kind() const
51 52 53
{
    return QLatin1String(Constants::FILES_EDITOR);
}
54 55 56 57 58 59 60 61 62 63 64 65 66 67

Core::IFile *ProjectFilesFactory::open(const QString &fileName)
{
    Core::EditorManager *editorManager = Core::EditorManager::instance();

    if (Core::IEditor *editor = editorManager->openEditor(fileName, kind()))
        return editor->file();

    return 0;
}

////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesEditable
////////////////////////////////////////////////////////////////////////////////////////
68

69 70 71 72 73 74 75 76 77 78 79
ProjectFilesEditable::ProjectFilesEditable(ProjectFilesEditor *editor)
    : TextEditor::BaseTextEditorEditable(editor)
{
    Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
    _context << uidm->uniqueIdentifier(Constants::C_FILESEDITOR);
}

ProjectFilesEditable::~ProjectFilesEditable()
{ }

QList<int> ProjectFilesEditable::context() const
80 81 82
{
    return _context;
}
83 84

const char *ProjectFilesEditable::kind() const
85 86 87
{
    return Constants::FILES_EDITOR;
}
88 89

bool ProjectFilesEditable::duplicateSupported() const
90 91 92
{
    return true;
}
93 94 95 96 97 98 99

Core::IEditor *ProjectFilesEditable::duplicate(QWidget *parent)
{
    ProjectFilesEditor *parentEditor = qobject_cast<ProjectFilesEditor *>(editor());
    ProjectFilesEditor *editor = new ProjectFilesEditor(parent,
                                                        parentEditor->factory(),
                                                        parentEditor->actionHandler());
100
    editor->initialize();
101 102 103 104 105 106
    return editor->editableInterface();
}

////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesEditor
////////////////////////////////////////////////////////////////////////////////////////
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121
ProjectFilesEditor::ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *factory,
                                       TextEditor::TextEditorActionHandler *handler)
    : TextEditor::BaseTextEditor(parent),
      _factory(factory),
      _actionHandler(handler)
{
    Manager *manager = factory->manager();
    ProjectFilesDocument *doc = new ProjectFilesDocument(manager);
    setBaseTextDocument(doc);
}

ProjectFilesEditor::~ProjectFilesEditor()
{ }

122 123 124 125 126 127 128 129 130 131
void ProjectFilesEditor::initialize()
{
    TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance();

    connect(settings, SIGNAL(fontSettingsChanged(const TextEditor::FontSettings&)),
            this, SLOT(setFontSettings(const TextEditor::FontSettings&)));

    setFontSettings(settings->fontSettings());
}

132
ProjectFilesFactory *ProjectFilesEditor::factory() const
133 134 135
{
    return _factory;
}
136 137

TextEditor::TextEditorActionHandler *ProjectFilesEditor::actionHandler() const
138 139 140
{
    return _actionHandler;
}
141 142

TextEditor::BaseTextEditorEditable *ProjectFilesEditor::createEditableInterface()
143 144 145
{
    return new ProjectFilesEditable(this);
}
146 147 148 149

////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesDocument
////////////////////////////////////////////////////////////////////////////////////////
150

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
ProjectFilesDocument::ProjectFilesDocument(Manager *manager)
    : _manager(manager)
{
    setMimeType(QLatin1String(Constants::FILES_MIMETYPE));
}

ProjectFilesDocument::~ProjectFilesDocument()
{ }

bool ProjectFilesDocument::save(const QString &name)
{
    if (! BaseTextDocument::save(name))
        return false;

    _manager->notifyChanged(name);
    return true;
}