mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-17 00:44:19 +00:00
Introjucer: wizards for auto-generating new Component classes
This commit is contained in:
parent
6e631bceb1
commit
d24ee139d3
21 changed files with 582 additions and 77 deletions
|
|
@ -29,21 +29,24 @@
|
|||
//==============================================================================
|
||||
namespace
|
||||
{
|
||||
bool fillInNewCppFileTemplate (const File& file, const Project::Item& item, const char* templateName)
|
||||
inline String fillInBasicTemplateFields (const File& file, const Project::Item& item, const char* templateName)
|
||||
{
|
||||
String s = item.project.getFileTemplate (templateName)
|
||||
return item.project.getFileTemplate (templateName)
|
||||
.replace ("FILENAME", file.getFileName(), false)
|
||||
.replace ("DATE", Time::getCurrentTime().toString (true, true, true), false)
|
||||
.replace ("AUTHOR", SystemStats::getFullUserName(), false)
|
||||
.replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (file), false);
|
||||
.replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (file), false)
|
||||
.replace ("INCLUDE_CORRESPONDING_HEADER", CodeHelpers::createIncludeStatement (file.withFileExtension (".h"), file));
|
||||
}
|
||||
|
||||
return FileHelpers::overwriteFileWithNewDataIfDifferent (file, s);
|
||||
bool fillInNewCppFileTemplate (const File& file, const Project::Item& item, const char* templateName)
|
||||
{
|
||||
return FileHelpers::overwriteFileWithNewDataIfDifferent (file, fillInBasicTemplateFields (file, item, templateName));
|
||||
}
|
||||
|
||||
const int menuBaseID = 0x12d83f0;
|
||||
}
|
||||
|
||||
|
||||
//==============================================================================
|
||||
class NewCppFileWizard : public NewFileWizard::Type
|
||||
{
|
||||
|
|
@ -57,12 +60,12 @@ public:
|
|||
const File newFile (askUserToChooseNewFile ("SourceCode.cpp", "*.cpp", parent));
|
||||
|
||||
if (newFile != File::nonexistent)
|
||||
create (parent, newFile);
|
||||
create (parent, newFile, "jucer_NewCppFileTemplate_cpp");
|
||||
}
|
||||
|
||||
static bool create (Project::Item parent, const File& newFile)
|
||||
static bool create (Project::Item parent, const File& newFile, const char* templateName)
|
||||
{
|
||||
if (fillInNewCppFileTemplate (newFile, parent, "jucer_NewCppFileTemplate_cpp"))
|
||||
if (fillInNewCppFileTemplate (newFile, parent, templateName))
|
||||
{
|
||||
parent.addFile (newFile, 0, true);
|
||||
return true;
|
||||
|
|
@ -86,12 +89,12 @@ public:
|
|||
const File newFile (askUserToChooseNewFile ("SourceCode.h", "*.h", parent));
|
||||
|
||||
if (newFile != File::nonexistent)
|
||||
create (parent, newFile);
|
||||
create (parent, newFile, "jucer_NewCppFileTemplate_h");
|
||||
}
|
||||
|
||||
static bool create (Project::Item parent, const File& newFile)
|
||||
static bool create (Project::Item parent, const File& newFile, const char* templateName)
|
||||
{
|
||||
if (fillInNewCppFileTemplate (newFile, parent, "jucer_NewCppFileTemplate_h"))
|
||||
if (fillInNewCppFileTemplate (newFile, parent, templateName))
|
||||
{
|
||||
parent.addFile (newFile, 0, true);
|
||||
return true;
|
||||
|
|
@ -116,12 +119,91 @@ public:
|
|||
|
||||
if (newFile != File::nonexistent)
|
||||
{
|
||||
if (NewHeaderFileWizard::create (parent, newFile.withFileExtension ("h")))
|
||||
NewCppFileWizard::create (parent, newFile.withFileExtension ("cpp"));
|
||||
if (NewCppFileWizard::create (parent, newFile.withFileExtension ("h"), "jucer_NewCppFileTemplate_h"))
|
||||
NewCppFileWizard::create (parent, newFile.withFileExtension ("cpp"), "jucer_NewCppFileTemplate_cpp");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
class NewComponentFileWizard : public NewFileWizard::Type
|
||||
{
|
||||
public:
|
||||
NewComponentFileWizard() {}
|
||||
|
||||
String getName() { return "Component class (split between a CPP & header)"; }
|
||||
|
||||
void createNewFile (Project::Item parent)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
AlertWindow aw (TRANS ("Create new Component class"),
|
||||
TRANS ("Please enter the name for the new class"),
|
||||
AlertWindow::NoIcon, nullptr);
|
||||
|
||||
aw.addTextEditor (getClassNameFieldName(), String::empty, String::empty, false);
|
||||
aw.addButton (TRANS ("Create Files"), 1, KeyPress (KeyPress::returnKey));
|
||||
aw.addButton (TRANS ("Cancel"), 0, KeyPress (KeyPress::escapeKey));
|
||||
|
||||
if (aw.runModalLoop() == 0)
|
||||
break;
|
||||
|
||||
const String className (aw.getTextEditorContents (getClassNameFieldName()).trim());
|
||||
|
||||
if (className == CodeHelpers::makeValidIdentifier (className, false, true, false))
|
||||
{
|
||||
const File newFile (askUserToChooseNewFile (className + ".h", "*.h;*.cpp", parent));
|
||||
|
||||
if (newFile != File::nonexistent)
|
||||
createFiles (parent, className, newFile);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool create (const String& className, Project::Item parent,
|
||||
const File& newFile, const char* templateName)
|
||||
{
|
||||
String content = fillInBasicTemplateFields (newFile, parent, templateName)
|
||||
.replace ("COMPONENTCLASS", className)
|
||||
.replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (parent.project.getAppIncludeFile(), newFile));
|
||||
|
||||
if (FileHelpers::overwriteFileWithNewDataIfDifferent (newFile, content))
|
||||
{
|
||||
parent.addFile (newFile, 0, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
showFailedToWriteMessage (newFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void createFiles (Project::Item parent, const String& className, const File& newFile)
|
||||
{
|
||||
if (create (className, parent, newFile.withFileExtension ("h"), "jucer_NewComponentTemplate_h"))
|
||||
create (className, parent, newFile.withFileExtension ("cpp"), "jucer_NewComponentTemplate_cpp");
|
||||
}
|
||||
|
||||
static String getClassNameFieldName() { return "Class Name"; }
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
class NewSingleFileComponentFileWizard : public NewComponentFileWizard
|
||||
{
|
||||
public:
|
||||
NewSingleFileComponentFileWizard() {}
|
||||
|
||||
String getName() { return "Component class (in a single source file)"; }
|
||||
|
||||
void createFiles (Project::Item parent, const String& className, const File& newFile)
|
||||
{
|
||||
create (className, parent, newFile.withFileExtension ("h"), "jucer_NewInlineComponentTemplate_h");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//==============================================================================
|
||||
void NewFileWizard::Type::showFailedToWriteMessage (const File& file)
|
||||
{
|
||||
|
|
@ -151,6 +233,8 @@ NewFileWizard::NewFileWizard()
|
|||
registerWizard (new NewCppFileWizard());
|
||||
registerWizard (new NewHeaderFileWizard());
|
||||
registerWizard (new NewCppAndHeaderFileWizard());
|
||||
registerWizard (new NewComponentFileWizard());
|
||||
registerWizard (new NewSingleFileComponentFileWizard());
|
||||
}
|
||||
|
||||
NewFileWizard::~NewFileWizard()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue