1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-17 00:44:19 +00:00

Projucer: fixed the way the GUI editor generates include paths

This commit is contained in:
jules 2016-04-18 17:28:57 +01:00
parent 6fc4d5aac6
commit 60cd2d7b67
16 changed files with 80 additions and 81 deletions

View file

@ -595,10 +595,7 @@ static const unsigned char temp_binary_data_7[] =
"#define %%headerGuard%%\r\n"
"\r\n"
"//[Headers] -- You can add your own extra header files here --\r\n"
"\r\n"
"#include \"JuceHeader.h\" // you may want to edit this path to\r\n"
" // something more appropriate for your app.\r\n"
"\r\n"
"%%includeJUCEHeader%%\r\n"
"//[/Headers]\r\n"
"\r\n"
"%%includeFilesH%%\r\n"
@ -4027,7 +4024,7 @@ const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) throw
case 0x51b49ac5: numBytes = 4255; return jucer_AudioPluginFilterTemplate_cpp;
case 0x488afa0a: numBytes = 2114; return jucer_AudioPluginFilterTemplate_h;
case 0xabad7041: numBytes = 2151; return jucer_ComponentTemplate_cpp;
case 0xfc72fe86: numBytes = 2243; return jucer_ComponentTemplate_h;
case 0xfc72fe86: numBytes = 2131; return jucer_ComponentTemplate_h;
case 0x0b66646c: numBytes = 886; return jucer_ContentCompTemplate_cpp;
case 0x6fa10171: numBytes = 924; return jucer_ContentCompTemplate_h;
case 0x28d496ad: numBytes = 1161; return jucer_InlineComponentTemplate_h;

View file

@ -31,7 +31,7 @@ namespace BinaryData
const int jucer_ComponentTemplate_cppSize = 2151;
extern const char* jucer_ComponentTemplate_h;
const int jucer_ComponentTemplate_hSize = 2243;
const int jucer_ComponentTemplate_hSize = 2131;
extern const char* jucer_ContentCompTemplate_cpp;
const int jucer_ContentCompTemplate_cppSize = 886;

View file

@ -21,10 +21,7 @@
#define %%headerGuard%%
//[Headers] -- You can add your own extra header files here --
#include "JuceHeader.h" // you may want to edit this path to
// something more appropriate for your app.
%%includeJUCEHeader%%
//[/Headers]
%%includeFilesH%%

View file

@ -107,9 +107,10 @@ public:
{
ComponentTypeHandler::fillInCreationCode (code, component, memberVariableName);
TestComponent* const tc = dynamic_cast<TestComponent*> (component);
code.includeFilesH.add (tc->getFilename().replace (".cpp", ".h"));
if (TestComponent* const tc = dynamic_cast<TestComponent*> (component))
code.includeFilesH.add (tc->findFile().withFileExtension (".h"));
else
jassertfalse;
}
//==============================================================================
@ -193,9 +194,8 @@ private:
};
//==============================================================================
class JucerCompOpenDocProperty : public ButtonPropertyComponent
struct JucerCompOpenDocProperty : public ButtonPropertyComponent
{
public:
JucerCompOpenDocProperty (TestComponent* const c)
: ButtonPropertyComponent ("edit", false),
component (c)
@ -213,14 +213,12 @@ private:
return "Open file for editing";
}
private:
TestComponent* const component;
};
//==============================================================================
class ConstructorParamsProperty : public ComponentTextProperty <TestComponent>
struct ConstructorParamsProperty : public ComponentTextProperty <TestComponent>
{
public:
ConstructorParamsProperty (TestComponent* comp, JucerDocument& doc)
: ComponentTextProperty <TestComponent> ("constructor params", 512, false, comp, doc)
{
@ -238,9 +236,8 @@ private:
}
private:
class ConstructorParamChangeAction : public ComponentUndoableAction <TestComponent>
struct ConstructorParamChangeAction : public ComponentUndoableAction <TestComponent>
{
public:
ConstructorParamChangeAction (TestComponent* const comp, ComponentLayout& l, const String& newValue_)
: ComponentUndoableAction <TestComponent> (comp, l),
newValue (newValue_)

View file

@ -165,14 +165,13 @@ public:
if (isTabUsingJucerComp (t, i))
{
ScopedPointer<JucerDocument> doc
(JucerDocument::createForCppFile (nullptr, code.document->getCppFile()
.getSiblingFile (getTabJucerFile (t, i))));
File jucerCpp = code.document->getCppFile().getSiblingFile (getTabJucerFile (t, i));
ScopedPointer<JucerDocument> doc (JucerDocument::createForCppFile (nullptr, jucerCpp));
if (doc != nullptr)
{
code.includeFilesCPP.add (getTabJucerFile (t, i).replace (".cpp", ".h"));
code.includeFilesCPP.add (jucerCpp.withFileExtension (".h"));
contentClassName = doc->getClassName();
}
}

View file

@ -211,14 +211,12 @@ String GeneratedCode::getInitialiserList() const
return s;
}
static String getIncludeFileCode (StringArray files)
static String getIncludeFileCode (const Array<File>& files, const File& targetFile)
{
String s;
files = getCleanedStringArray (files);
for (int i = 0; i < files.size(); ++i)
s << "#include \"" << files[i] << "\"\n";
s << CodeHelpers::createIncludeStatement (files.getReference(i), targetFile) << newLine;
return s;
}
@ -320,13 +318,13 @@ static void copyAcrossUserSections (String& dest, const String& src)
//==============================================================================
void GeneratedCode::applyToCode (String& code,
const String& fileNameRoot,
const bool isForPreview,
const String& oldFileWithUserData) const
const File& targetFile,
const String& oldFileWithUserData,
Project* project) const
{
// header guard..
String headerGuard ("__JUCE_HEADER_");
headerGuard << String::toHexString ((className + "xx" + fileNameRoot).hashCode64()).toUpperCase() << "__";
headerGuard << String::toHexString ((className + "xx" + targetFile.getFileNameWithoutExtension()).hashCode64()).toUpperCase() << "__";
replaceTemplate (code, "headerGuard", headerGuard);
replaceTemplate (code, "version", JUCEApplicationBase::getInstance()->getApplicationVersion());
@ -338,26 +336,23 @@ void GeneratedCode::applyToCode (String& code,
replaceTemplate (code, "classDeclaration", getClassDeclaration());
replaceTemplate (code, "privateMemberDeclarations", privateMemberDeclarations);
replaceTemplate (code, "publicMemberDeclarations", getCallbackDeclarations() + "\n" + publicMemberDeclarations);
replaceTemplate (code, "publicMemberDeclarations", getCallbackDeclarations() + newLine + publicMemberDeclarations);
replaceTemplate (code, "methodDefinitions", getCallbackDefinitions());
replaceTemplate (code, "includeFilesH", getIncludeFileCode (includeFilesH));
replaceTemplate (code, "includeFilesCPP", getIncludeFileCode (includeFilesCPP));
File juceHeaderFile = project != nullptr ? project->getAppIncludeFile()
: targetFile.getSiblingFile ("JuceHeader.h");
replaceTemplate (code, "includeJUCEHeader", CodeHelpers::createIncludeStatement (juceHeaderFile, targetFile));
replaceTemplate (code, "includeFilesH", getIncludeFileCode (includeFilesH, targetFile));
replaceTemplate (code, "includeFilesCPP", getIncludeFileCode (includeFilesCPP, targetFile));
replaceTemplate (code, "constructor", constructorCode);
replaceTemplate (code, "destructor", destructorCode);
if (! isForPreview)
{
replaceTemplate (code, "metadata", jucerMetadata);
replaceTemplate (code, "staticMemberDefinitions", staticMemberDefinitions);
}
else
{
replaceTemplate (code, "metadata", " << Metadata isn't shown in the code preview >>\n");
replaceTemplate (code, "staticMemberDefinitions", "// Static member declarations and resources would go here... (these aren't shown in the code preview)");
}
replaceTemplate (code, "metadata", jucerMetadata);
replaceTemplate (code, "staticMemberDefinitions", staticMemberDefinitions);
copyAcrossUserSections (code, oldFileWithUserData);
}

View file

@ -25,6 +25,7 @@
#ifndef JUCER_GENERATEDCODE_H_INCLUDED
#define JUCER_GENERATEDCODE_H_INCLUDED
#include "../project/jucer_Project.h"
class JucerDocument;
@ -41,9 +42,9 @@ public:
//==============================================================================
void applyToCode (String& code,
const String& fileNameRoot,
const bool isForPreview,
const String& oldFileWithUserData = String::empty) const;
const File& targetFile,
const String& oldFileWithUserData,
Project* project) const;
int getUniqueSuffix();
@ -58,7 +59,7 @@ public:
String constructorParams;
String privateMemberDeclarations;
String publicMemberDeclarations;
StringArray includeFilesH, includeFilesCPP;
Array<File> includeFilesH, includeFilesCPP;
String constructorCode;
String destructorCode;
String staticMemberDefinitions;

View file

@ -110,7 +110,7 @@ void JucerDocument::timerCallback()
stopTimer();
beginTransaction();
flushChangesToDocuments();
flushChangesToDocuments (nullptr);
}
}
@ -511,7 +511,7 @@ bool JucerDocument::findTemplateFiles (String& headerContent, String& cppContent
const File f (getCppFile().getSiblingFile (templateFile));
const File templateCpp (f.withFileExtension (".cpp"));
const File templateH (f.withFileExtension (".h"));
const File templateH (f.withFileExtension (".h"));
headerContent = templateH.loadFileAsString();
cppContent = templateCpp.loadFileAsString();
@ -536,12 +536,12 @@ static String fixLineEndings (const String& s)
while (lines.size() > 0 && lines [lines.size() - 1].trim().isEmpty())
lines.remove (lines.size() - 1);
lines.add (String::empty);
lines.add (String());
return lines.joinIntoString ("\r\n");
}
bool JucerDocument::flushChangesToDocuments()
bool JucerDocument::flushChangesToDocuments (Project* project)
{
String headerTemplate, cppTemplate;
if (! findTemplateFiles (headerTemplate, cppTemplate))
@ -551,17 +551,20 @@ bool JucerDocument::flushChangesToDocuments()
fillInGeneratedCode (generated);
const File headerFile (getHeaderFile());
generated.includeFilesCPP.insert (0, headerFile.getFileName());
generated.includeFilesCPP.insert (0, headerFile);
OpenDocumentManager& odm = ProjucerApplication::getApp().openDocumentManager;
if (SourceCodeDocument* header = dynamic_cast<SourceCodeDocument*> (odm.openFile (nullptr, getHeaderFile())))
if (SourceCodeDocument* header = dynamic_cast<SourceCodeDocument*> (odm.openFile (nullptr, headerFile)))
{
String existingHeader (header->getCodeDocument().getAllContent());
String existingCpp (cpp->getCodeDocument().getAllContent());
generated.applyToCode (headerTemplate, headerFile.getFileNameWithoutExtension(), false, existingHeader);
generated.applyToCode (cppTemplate, headerFile.getFileNameWithoutExtension(), false, existingCpp);
generated.applyToCode (headerTemplate, headerFile,
existingHeader, project);
generated.applyToCode (cppTemplate, headerFile.withFileExtension (".cpp"),
existingCpp, project);
headerTemplate = fixLineEndings (headerTemplate);
cppTemplate = fixLineEndings (cppTemplate);
@ -719,7 +722,7 @@ public:
String getName() override { return "GUI Component"; }
void createNewFile (Project::Item parent) override
void createNewFile (Project& project, Project::Item parent) override
{
const File newFile (askUserToChooseNewFile (String (defaultClassName) + ".h", "*.h;*.cpp", parent));
@ -743,7 +746,7 @@ public:
{
jucerDoc->setClassName (newFile.getFileNameWithoutExtension());
jucerDoc->flushChangesToDocuments();
jucerDoc->flushChangesToDocuments (&project);
jucerDoc = nullptr;
cpp->save();

View file

@ -44,7 +44,7 @@ public:
static bool isValidJucerCppFile (const File&);
static XmlElement* pullMetaDataFromCppFile (const String& cpp);
static JucerDocument* createForCppFile (Project* project, const File&);
static JucerDocument* createForCppFile (Project*, const File&);
void changed();
void beginTransaction();
@ -58,7 +58,7 @@ public:
File getCppFile() const { return cpp->getFile(); }
File getHeaderFile() const { return getCppFile().withFileExtension (".h"); }
bool flushChangesToDocuments();
bool flushChangesToDocuments (Project*);
bool reloadFromDocument();
//==============================================================================

View file

@ -69,7 +69,7 @@ static StringArray recursiveFiles;
File TestComponent::findFile() const
{
if (filename.isEmpty())
return File::nonexistent;
return File();
if (ownerDocument != nullptr)
return ownerDocument->getCppFile().getSiblingFile (filename);

View file

@ -56,10 +56,10 @@ public:
void setToInitialSize();
//==============================================================================
void paint (Graphics& g);
void resized();
void paint (Graphics&) override;
void resized() override;
static void showInDialogBox (JucerDocument& design);
static void showInDialogBox (JucerDocument&);
// reloads any test comps that need to do so
static void reloadAll();

View file

@ -62,8 +62,8 @@ public:
{
TreeView* tree = getOwnerView();
const int numSelected = tree->getNumSelectedItems();
OwnedArray <File> filesToTrash;
OwnedArray <Project::Item> itemsToRemove;
OwnedArray<File> filesToTrash;
OwnedArray<Project::Item> itemsToRemove;
for (int i = 0; i < numSelected; ++i)
{
@ -352,9 +352,8 @@ protected:
void triggerAsyncRename (const Project::Item& itemToRename)
{
class RenameMessage : public CallbackMessage
struct RenameMessage : public CallbackMessage
{
public:
RenameMessage (TreeView* const t, const Project::Item& i)
: tree (t), itemToRename (i) {}
@ -374,7 +373,7 @@ protected:
(new RenameMessage (getOwnerView(), itemToRename))->post();
}
static void moveItems (OwnedArray <Project::Item>& selectedNodes, Project::Item destNode, int insertIndex)
static void moveItems (OwnedArray<Project::Item>& selectedNodes, Project::Item destNode, int insertIndex)
{
for (int i = selectedNodes.size(); --i >= 0;)
{

View file

@ -171,8 +171,18 @@ public:
case 1002: browseToAddExistingFiles(); break;
default:
NewFileWizard().runWizardFromMenu (menuID, item);
jassert (getProject() != nullptr);
NewFileWizard().runWizardFromMenu (menuID, *getProject(), item);
break;
}
}
Project* getProject()
{
if (TreeView* tv = getOwnerView())
if (ProjectContentComponent* pcc = tv->findParentComponentOfClass<ProjectContentComponent>())
return pcc->getProject();
return nullptr;
}
};

View file

@ -131,7 +131,7 @@ public:
tree.setRootItem (nullptr);
}
void setRoot (JucerTreeViewBase* root);
void setRoot (JucerTreeViewBase*);
void saveOpenness();
void deleteSelectedItems()

View file

@ -56,7 +56,7 @@ public:
String getName() override { return "CPP File"; }
void createNewFile (Project::Item parent) override
void createNewFile (Project&, Project::Item parent) override
{
const File newFile (askUserToChooseNewFile ("SourceCode.cpp", "*.cpp", parent));
@ -85,7 +85,7 @@ public:
String getName() override { return "Header File"; }
void createNewFile (Project::Item parent) override
void createNewFile (Project&, Project::Item parent) override
{
const File newFile (askUserToChooseNewFile ("SourceCode.h", "*.h", parent));
@ -114,7 +114,7 @@ public:
String getName() override { return "CPP & Header File"; }
void createNewFile (Project::Item parent) override
void createNewFile (Project&, Project::Item parent) override
{
const File newFile (askUserToChooseNewFile ("SourceCode.h", "*.h;*.cpp", parent));
@ -134,7 +134,7 @@ public:
String getName() override { return "Component class (split between a CPP & header)"; }
void createNewFile (Project::Item parent) override
void createNewFile (Project&, Project::Item parent) override
{
for (;;)
{
@ -249,11 +249,11 @@ void NewFileWizard::addWizardsToMenu (PopupMenu& m) const
m.addItem (menuBaseID + i, "Add New " + wizards.getUnchecked(i)->getName() + "...");
}
bool NewFileWizard::runWizardFromMenu (int chosenMenuItemID, const Project::Item& projectGroupToAddTo) const
bool NewFileWizard::runWizardFromMenu (int chosenMenuItemID, Project& project, const Project::Item& projectGroupToAddTo) const
{
if (Type* wiz = wizards [chosenMenuItemID - menuBaseID])
{
wiz->createNewFile (projectGroupToAddTo);
wiz->createNewFile (project, projectGroupToAddTo);
return true;
}

View file

@ -46,7 +46,7 @@ public:
//==============================================================================
virtual String getName() = 0;
virtual void createNewFile (Project::Item projectGroupToAddTo) = 0;
virtual void createNewFile (Project&, Project::Item projectGroupToAddTo) = 0;
protected:
//==============================================================================
@ -58,7 +58,8 @@ public:
//==============================================================================
void addWizardsToMenu (PopupMenu&) const;
bool runWizardFromMenu (int chosenMenuItemID, const Project::Item& projectGroupToAddTo) const;
bool runWizardFromMenu (int chosenMenuItemID, Project&,
const Project::Item& projectGroupToAddTo) const;
void registerWizard (Type*);