1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 102 103 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 169 170 171 172 173 174 175 176 177 178 179
|
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2015 - ROLI Ltd.
Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
b) the Affero GPL v3
Details of these licenses can be found at: www.gnu.org/licenses
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.juce.com for more information.
==============================================================================
*/
#ifndef JUCER_JUCERDOCUMENT_H_INCLUDED
#define JUCER_JUCERDOCUMENT_H_INCLUDED
#include "../Application/jucer_OpenDocumentManager.h"
#include "../Code Editor/jucer_SourceCodeEditor.h"
#include "components/jucer_ComponentTypeHandler.h"
#include "jucer_PaintRoutine.h"
#include "jucer_ComponentLayout.h"
#include "jucer_BinaryResources.h"
//==============================================================================
class JucerDocument : public ChangeBroadcaster,
private Timer,
private CodeDocument::Listener,
private OpenDocumentManager::DocumentCloseListener
{
public:
JucerDocument (SourceCodeDocument* cpp);
~JucerDocument();
static bool isValidJucerCppFile (const File&);
static XmlElement* pullMetaDataFromCppFile (const String& cpp);
static JucerDocument* createForCppFile (Project*, const File&);
void changed();
void beginTransaction();
void beginTransaction (const String& name);
virtual JucerDocument* createCopy() = 0;
virtual String getTypeName() const = 0;
SourceCodeDocument& getCppDocument() const { return *cpp; }
File getCppFile() const { return cpp->getFile(); }
File getHeaderFile() const { return getCppFile().withFileExtension (".h"); }
bool flushChangesToDocuments (Project*);
bool reloadFromDocument();
//==============================================================================
UndoManager& getUndoManager() noexcept { return undoManager; }
bool perform (UndoableAction* const action, const String& actionName);
void refreshAllPropertyComps();
//==============================================================================
const String& getClassName() const noexcept { return className; }
void setClassName (const String& newName);
const String& getComponentName() const noexcept { return componentName; }
void setComponentName (const String& newName);
String getParentClassString() const { return parentClasses; }
void setParentClasses (const String& classes);
String getConstructorParams() const { return constructorParams; }
void setConstructorParams (const String& newParams);
String getVariableInitialisers() const { return variableInitialisers; }
void setVariableInitialisers (const String& newInitlialisers);
void setFixedSize (const bool isFixed);
bool isFixedSize() const noexcept { return fixedSize; }
void setInitialSize (int w, int h);
int getInitialWidth() const noexcept { return initialWidth; }
int getInitialHeight() const noexcept { return initialHeight; }
//==============================================================================
virtual int getNumPaintRoutines() const = 0;
virtual StringArray getPaintRoutineNames() const = 0;
virtual PaintRoutine* getPaintRoutine (const int index) const = 0;
virtual ComponentLayout* getComponentLayout() const = 0;
virtual Component* createTestComponent (const bool alwaysFillBackground) = 0;
virtual void addExtraClassProperties (PropertyPanel&);
//==============================================================================
virtual void getOptionalMethods (StringArray& baseClasses,
StringArray& returnValues,
StringArray& methods,
StringArray& initialContents) const;
void setOptionalMethodEnabled (const String& methodSignature, const bool enable);
bool isOptionalMethodEnabled (const String& methodSignature) const noexcept;
//==============================================================================
BinaryResources& getResources() noexcept { return resources; }
//==============================================================================
void setSnappingGrid (const int numPixels, const bool active, const bool shown);
int getSnappingGridSize() const noexcept { return snapGridPixels; }
bool isSnapActive (const bool disableIfCtrlKeyDown) const noexcept;
bool isSnapShown() const noexcept { return snapShown; }
int snapPosition (int pos) const noexcept;
//==============================================================================
void setComponentOverlayOpacity (const float alpha);
float getComponentOverlayOpacity() const noexcept { return componentOverlayOpacity; }
//==============================================================================
static const char* const jucerCompXmlTag;
bool findTemplateFiles (String& templateH, String& templateCpp) const;
String getTemplateFile() const { return templateFile; }
void setTemplateFile (const String&);
static bool shouldUseTransMacro() noexcept { return true; }
protected:
SourceCodeDocument* cpp;
String className, componentName, templateFile;
String parentClasses, constructorParams, variableInitialisers;
bool fixedSize;
int initialWidth, initialHeight;
BinaryResources resources;
virtual XmlElement* createXml() const;
virtual bool loadFromXml (const XmlElement&);
virtual void fillInGeneratedCode (GeneratedCode&) const;
virtual void fillInPaintCode (GeneratedCode&) const;
static void addMethod (const String& base, const String& returnVal,
const String& method, const String& initialContent,
StringArray& baseClasses, StringArray& returnValues,
StringArray& methods, StringArray& initialContents);
private:
UndoManager undoManager;
int snapGridPixels;
bool snapActive, snapShown;
float componentOverlayOpacity;
StringArray activeExtraMethods;
ScopedPointer<XmlElement> currentXML;
ScopedPointer<Timer> userDocChangeTimer;
void timerCallback() override;
void codeDocumentTextInserted (const String& newText, int insertIndex) override;
void codeDocumentTextDeleted (int startIndex, int endIndex) override;
void userEditedCpp();
bool documentAboutToClose (OpenDocumentManager::Document*) override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JucerDocument)
};
#endif // JUCER_JUCERDOCUMENT_H_INCLUDED
|