qworkbench_wrapper.h 8.94 KB
Newer Older
con's avatar
con committed
1 2 3 4 5 6 7 8
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9 10 11
**
** Non-Open Source Usage
**
con's avatar
con committed
12 13 14
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
15 16 17 18
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
con's avatar
con committed
19 20 21 22 23 24 25 26 27 28
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
29 30 31 32
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#ifndef QWORKBENCH_WRAPPER_H
#define QWORKBENCH_WRAPPER_H

#include "metatypedeclarations.h" // required for property declarations

#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtScript/QScriptable>
#include <QtScript/QScriptValue>

namespace Core {
namespace Internal {

// Script prototype for the core interface.

hjk's avatar
hjk committed
49 50
class CorePrototype : public QObject, public QScriptable
{
con's avatar
con committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    Q_OBJECT

    Q_PROPERTY(Core::MessageManager* messageManager READ messageManager DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(Core::FileManager* fileManager READ fileManager DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(Core::EditorManager* editorManager READ editorManager DESIGNABLE false SCRIPTABLE true STORED false)

    Q_PROPERTY(QMainWindow* mainWindow READ mainWindow DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QStatusBar* statusBar READ statusBar DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QSettings* settings READ settings DESIGNABLE false SCRIPTABLE true STORED false)

public:
    typedef Core::ICore ICore;

    CorePrototype(QObject *parent);

    Core::MessageManager *messageManager() const;
    Core::FileManager *fileManager() const;
    Core::EditorManager *editorManager() const;

    QMainWindow *mainWindow() const;
    QStatusBar *statusBar() const;
    QSettings *settings() const;

public slots:
    void addAdditionalContext(int context);
    void removeAdditionalContext(int context);
    QString toString() const;

private:
    ICore *callee() const;
};

// Script prototype for the message manager.

class MessageManagerPrototype : public QObject, public QScriptable
{
    Q_OBJECT

public:
    typedef Core::MessageManager MessageManager;

    MessageManagerPrototype(QObject *parent = 0);

public slots:
    void displayStatusBarMessage(const QString &text, int ms = 0);
    void printToOutputPane(const QString &text, bool bringToForeground = true);
    QString toString() const;
};

// Script prototype for the file manager interface.

hjk's avatar
hjk committed
102 103
class FileManagerPrototype : public QObject, public QScriptable
{
con's avatar
con committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    Q_OBJECT

    Q_PROPERTY(QStringList recentFiles READ recentFiles DESIGNABLE false SCRIPTABLE true STORED false)

public:
    typedef Core::FileManager FileManager;

    FileManagerPrototype(QObject *parent = 0);
    QStringList recentFiles() const;

public slots:
    bool addFiles(const QList<Core::IFile *> &files);
    bool addFile(Core::IFile *file);
    bool removeFile(Core::IFile *file);

    QList<Core::IFile*> saveModifiedFilesSilently(const QList<Core::IFile*> &files);
    QString getSaveAsFileName(Core::IFile *file);

    bool isFileManaged(const QString &fileName) const;
    QList<Core::IFile *> managedFiles(const QString &fileName) const;

    void blockFileChange(Core::IFile *file);
    void unblockFileChange(Core::IFile *file);

    void addToRecentFiles(const QString &fileName);
    QString toString() const;

private:
    FileManager *callee() const;
};

// Script prototype for the file interface.

class FilePrototype : public QObject, public QScriptable
{
    Q_OBJECT

    Q_PROPERTY(QString fileName READ fileName DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QString defaultPath READ defaultPath DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QString suggestedFileName READ suggestedFileName DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(bool isModified READ isModified DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(bool isReadOnly READ isReadOnly DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(bool isSaveAsAllowed READ isSaveAsAllowed DESIGNABLE false SCRIPTABLE true STORED false)
public:
    typedef Core::IFile IFile;

    FilePrototype(QObject *parent = 0);

    QString fileName() const;
    QString defaultPath() const;
    QString suggestedFileName() const;

    bool isModified() const;
    bool isReadOnly() const;
    bool isSaveAsAllowed() const;

public slots:
    QString toString() const;

private:
    IFile *callee() const;
};

// Script prototype for the editor manager interface.

hjk's avatar
hjk committed
169 170
class EditorManagerPrototype : public QObject, public QScriptable
{
con's avatar
con committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    Q_OBJECT
    Q_PROPERTY(Core::IEditor* currentEditor READ currentEditor WRITE setCurrentEditor DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QList<Core::IEditor*> openedEditors READ openedEditors DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QList<Core::IEditor*> editorHistory  READ editorHistory DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QList<Core::EditorGroup *> editorGroups READ editorGroups DESIGNABLE false SCRIPTABLE true STORED false)
public:
    typedef  Core::EditorManager EditorManager;

    EditorManagerPrototype(QObject *parent = 0);

    Core::IEditor *currentEditor() const;
    void setCurrentEditor(Core::IEditor *editor);
    QList<Core::IEditor*> openedEditors() const;
    QList<Core::IEditor*> editorHistory() const;
    QList<Core::EditorGroup *> editorGroups() const;

public slots:
    QList<Core::IEditor*> editorsForFiles(QList<Core::IFile*> files) const;
    bool closeEditors(const QList<Core::IEditor*> editorsToClose, bool askAboutModifiedEditors);
    Core::IEditor *openEditor(const QString &fileName, const QString &editorKind);
    Core::IEditor *newFile(const QString &editorKind, QString titlePattern, const QString &contents);
    int makeEditorWritable(Core::IEditor *editor);

    QString toString() const;

private:
    EditorManager *callee() const;
};

// Script prototype for the editor interface.

hjk's avatar
hjk committed
202 203
class EditorPrototype :  public QObject, public QScriptable
{
con's avatar
con committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    Q_OBJECT
    Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QString kind READ kind DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(bool duplicateSupported READ duplicateSupported DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(Core::IFile* file READ file DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QToolBar* toolBar  READ toolBar DESIGNABLE false SCRIPTABLE true STORED false)

public:
    EditorPrototype(QObject *parent = 0);

    QString displayName() const;
    void setDisplayName(const QString &title);

    QString kind() const;
    bool duplicateSupported() const;

    Core::IFile *file() const;
    QToolBar* toolBar() const;

public slots:
    bool createNew(const QString &contents);
    bool open(const QString &fileName);
    Core::IEditor *duplicate(QWidget *parent);

    QString toString() const;

private:
    Core::IEditor *callee() const;
};

// Script prototype for the editor group interface with Script-managed life cycle.

hjk's avatar
hjk committed
236 237
class EditorGroupPrototype :  public QObject, public QScriptable
{
con's avatar
con committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
    Q_OBJECT
    Q_PROPERTY(int editorCount READ editorCount DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(Core::IEditor* currentEditor READ currentEditor WRITE setCurrentEditor DESIGNABLE false SCRIPTABLE true STORED false)
    Q_PROPERTY(QList<Core::IEditor*> editors READ editors DESIGNABLE false SCRIPTABLE true STORED false)

public:
    EditorGroupPrototype(QObject *parent = 0);

    int editorCount() const;
    Core::IEditor *currentEditor() const;
    void setCurrentEditor(Core::IEditor *editor);
    QList<Core::IEditor*> editors() const;

public slots:
    void addEditor(Core::IEditor *editor);
    void insertEditor(int i, Core::IEditor *editor);
    void removeEditor(Core::IEditor *editor);

    void moveEditorsFromGroup(Core::EditorGroup *group);
    void moveEditorFromGroup(Core::EditorGroup *group, Core::IEditor *editor);

    QString toString() const;

private:
    Core::EditorGroup *callee() const;
};

} // namespace Internal
} // namespace Core

hjk's avatar
hjk committed
268
#endif // QWORKBENCH_WRAPPER_H