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 180
|
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#include "../CodeEditor/jucer_OpenDocumentManager.h"
#include "../CodeEditor/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
{
public:
JucerDocument (SourceCodeDocument* cpp);
~JucerDocument() override;
static bool isValidJucerCppFile (const File&);
static std::unique_ptr<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);
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; }
//==============================================================================
void refreshCustomCodeFromDocument();
protected:
SourceCodeDocument* cpp;
String className, componentName, templateFile;
String parentClasses, constructorParams, variableInitialisers;
bool fixedSize = false;
int initialWidth = 600, initialHeight = 400;
BinaryResources resources;
virtual std::unique_ptr<XmlElement> createXml() const;
virtual bool loadFromXml (const XmlElement&);
virtual void fillInGeneratedCode (GeneratedCode&) const;
virtual void fillInPaintCode (GeneratedCode&) const;
virtual void applyCustomPaintSnippets (StringArray&) {}
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 = 8;
bool snapActive = true, snapShown = true;
float componentOverlayOpacity = 0.33f;
StringArray activeExtraMethods;
std::unique_ptr<XmlElement> currentXML;
std::unique_ptr<Timer> userDocChangeTimer;
void timerCallback() override;
void codeDocumentTextInserted (const String& newText, int insertIndex) override;
void codeDocumentTextDeleted (int startIndex, int endIndex) override;
void userEditedCpp();
void extractCustomPaintSnippetsFromCppFile (const String& cpp);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JucerDocument)
};
|