mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-24 01:54:22 +00:00
Introjucer: added TRANS macro to GUI designed generated code.
This commit is contained in:
parent
dc182eef2c
commit
a2ffe5e6eb
23 changed files with 84 additions and 88 deletions
|
|
@ -198,8 +198,9 @@ bool OpenDocumentManager::closeDocument (int index, bool saveIfNeeded)
|
|||
bool canClose = true;
|
||||
|
||||
for (int i = listeners.size(); --i >= 0;)
|
||||
if (! listeners.getUnchecked(i)->documentAboutToClose (doc))
|
||||
canClose = false;
|
||||
if (DocumentCloseListener* l = listeners[i])
|
||||
if (! l->documentAboutToClose (doc))
|
||||
canClose = false;
|
||||
|
||||
if (! canClose)
|
||||
return false;
|
||||
|
|
@ -219,12 +220,9 @@ bool OpenDocumentManager::closeDocument (Document* document, bool saveIfNeeded)
|
|||
void OpenDocumentManager::closeFile (const File& f, bool saveIfNeeded)
|
||||
{
|
||||
for (int i = documents.size(); --i >= 0;)
|
||||
{
|
||||
Document* d = documents.getUnchecked (i);
|
||||
|
||||
if (d->isForFile (f))
|
||||
closeDocument (i, saveIfNeeded);
|
||||
}
|
||||
if (Document* d = documents[i])
|
||||
if (d->isForFile (f))
|
||||
closeDocument (i, saveIfNeeded);
|
||||
}
|
||||
|
||||
bool OpenDocumentManager::closeAll (bool askUserToSave)
|
||||
|
|
@ -239,15 +237,10 @@ bool OpenDocumentManager::closeAll (bool askUserToSave)
|
|||
bool OpenDocumentManager::closeAllDocumentsUsingProject (Project& project, bool saveIfNeeded)
|
||||
{
|
||||
for (int i = documents.size(); --i >= 0;)
|
||||
{
|
||||
Document* d = documents.getUnchecked (i);
|
||||
|
||||
if (d->refersToProject (project))
|
||||
{
|
||||
if (! closeDocument (i, saveIfNeeded))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (Document* d = documents[i])
|
||||
if (d->refersToProject (project))
|
||||
if (! closeDocument (i, saveIfNeeded))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -255,12 +248,8 @@ bool OpenDocumentManager::closeAllDocumentsUsingProject (Project& project, bool
|
|||
bool OpenDocumentManager::anyFilesNeedSaving() const
|
||||
{
|
||||
for (int i = documents.size(); --i >= 0;)
|
||||
{
|
||||
Document* d = documents.getUnchecked (i);
|
||||
|
||||
if (d->needsSaving())
|
||||
if (documents.getUnchecked (i)->needsSaving())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -268,12 +257,8 @@ bool OpenDocumentManager::anyFilesNeedSaving() const
|
|||
bool OpenDocumentManager::saveAll()
|
||||
{
|
||||
for (int i = documents.size(); --i >= 0;)
|
||||
{
|
||||
Document* d = documents.getUnchecked (i);
|
||||
|
||||
if (! d->save())
|
||||
if (! documents.getUnchecked (i)->save())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,9 +112,9 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
OwnedArray <DocumentType> types;
|
||||
OwnedArray <Document> documents;
|
||||
Array <DocumentCloseListener*> listeners;
|
||||
OwnedArray<DocumentType> types;
|
||||
OwnedArray<Document> documents;
|
||||
Array<DocumentCloseListener*> listeners;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenDocumentManager)
|
||||
};
|
||||
|
|
@ -146,7 +146,7 @@ public:
|
|||
private:
|
||||
bool documentAboutToClose (OpenDocumentManager::Document*);
|
||||
|
||||
Array <OpenDocumentManager::Document*> previousDocs, nextDocs;
|
||||
Array<OpenDocumentManager::Document*> previousDocs, nextDocs;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -80,9 +80,9 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* component)
|
||||
String getCreationParameters (GeneratedCode& code, Component* component)
|
||||
{
|
||||
return quotedString (component->getName());
|
||||
return quotedString (component->getName(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
@ -95,7 +95,7 @@ public:
|
|||
{
|
||||
code.constructorCode
|
||||
<< memberVariableName << "->setButtonText ("
|
||||
<< quotedString (b->getButtonText()) << ");\n";
|
||||
<< quotedString (b->getButtonText(), code.shouldUseTransMacro()) << ");\n";
|
||||
}
|
||||
|
||||
if (b->getConnectedEdgeFlags() != 0)
|
||||
|
|
|
|||
|
|
@ -85,9 +85,9 @@ public:
|
|||
props.add (new ComboTextWhenNoItemsProperty (c, document));
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* component)
|
||||
String getCreationParameters (GeneratedCode& code, Component* component)
|
||||
{
|
||||
return quotedString (component->getName());
|
||||
return quotedString (component->getName(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
@ -100,8 +100,8 @@ public:
|
|||
String s;
|
||||
s << memberVariableName << "->setEditableText (" << CodeHelpers::boolLiteral (c->isTextEditable()) << ");\n"
|
||||
<< memberVariableName << "->setJustificationType (" << CodeHelpers::justificationToCode (c->getJustificationType()) << ");\n"
|
||||
<< memberVariableName << "->setTextWhenNothingSelected (" << quotedString (c->getTextWhenNothingSelected()) << ");\n"
|
||||
<< memberVariableName << "->setTextWhenNoChoicesAvailable (" << quotedString (c->getTextWhenNoChoicesAvailable()) << ");\n";
|
||||
<< memberVariableName << "->setTextWhenNothingSelected (" << quotedString (c->getTextWhenNothingSelected(), code.shouldUseTransMacro()) << ");\n"
|
||||
<< memberVariableName << "->setTextWhenNoChoicesAvailable (" << quotedString (c->getTextWhenNoChoicesAvailable(), code.shouldUseTransMacro()) << ");\n";
|
||||
|
||||
StringArray lines;
|
||||
lines.addLines (c->getProperties() ["items"].toString());
|
||||
|
|
@ -113,7 +113,7 @@ public:
|
|||
s << memberVariableName << "->addSeparator();\n";
|
||||
else
|
||||
s << memberVariableName << "->addItem ("
|
||||
<< quotedString (lines[i]) << ", " << itemId++ << ");\n";
|
||||
<< quotedString (lines[i], code.shouldUseTransMacro()) << ", " << itemId++ << ");\n";
|
||||
}
|
||||
|
||||
if (needsCallback (component))
|
||||
|
|
|
|||
|
|
@ -522,14 +522,14 @@ void ComponentTypeHandler::fillInResizeCode (GeneratedCode& code, Component* com
|
|||
code.getCallbackCode (String::empty, "void", "resized()", false) += r;
|
||||
}
|
||||
|
||||
String ComponentTypeHandler::getCreationParameters (Component*)
|
||||
String ComponentTypeHandler::getCreationParameters (GeneratedCode&, Component*)
|
||||
{
|
||||
return String::empty;
|
||||
}
|
||||
|
||||
void ComponentTypeHandler::fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
{
|
||||
String params (getCreationParameters (component));
|
||||
String params (getCreationParameters (code, component));
|
||||
const String virtualName (component->getProperties() ["virtualName"].toString());
|
||||
|
||||
String s;
|
||||
|
|
@ -557,7 +557,7 @@ void ComponentTypeHandler::fillInCreationCode (GeneratedCode& code, Component* c
|
|||
if (ttc->getTooltip().isNotEmpty())
|
||||
{
|
||||
s << memberVariableName << "->setTooltip ("
|
||||
<< quotedString (ttc->getTooltip())
|
||||
<< quotedString (ttc->getTooltip(), code.shouldUseTransMacro())
|
||||
<< ");\n";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,11 +99,11 @@ public:
|
|||
|
||||
virtual void fillInGeneratedCode (Component* component, GeneratedCode& code);
|
||||
|
||||
virtual void fillInMemberVariableDeclarations (GeneratedCode& code, Component* component, const String& memberVariableName);
|
||||
virtual void fillInResizeCode (GeneratedCode& code, Component* component, const String& memberVariableName);
|
||||
virtual void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName);
|
||||
virtual String getCreationParameters (Component* component);
|
||||
virtual void fillInDeletionCode (GeneratedCode& code, Component* component, const String& memberVariableName);
|
||||
virtual void fillInMemberVariableDeclarations (GeneratedCode&, Component*, const String& memberVariableName);
|
||||
virtual void fillInResizeCode (GeneratedCode&, Component*, const String& memberVariableName);
|
||||
virtual void fillInCreationCode (GeneratedCode&, Component*, const String& memberVariableName);
|
||||
virtual String getCreationParameters (GeneratedCode&, Component*);
|
||||
virtual void fillInDeletionCode (GeneratedCode&, Component*, const String& memberVariableName);
|
||||
|
||||
//==============================================================================
|
||||
const String& getTypeName() const noexcept { return typeName; }
|
||||
|
|
@ -136,8 +136,7 @@ protected:
|
|||
OwnedArray <ComponentColourInfo> colours;
|
||||
|
||||
private:
|
||||
ComponentTypeHandler (const ComponentTypeHandler&);
|
||||
ComponentTypeHandler& operator= (const ComponentTypeHandler&);
|
||||
JUCE_DECLARE_NON_COPYABLE (ComponentTypeHandler)
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -107,12 +107,12 @@ public:
|
|||
|
||||
String getClassName (Component* comp) const
|
||||
{
|
||||
return ((GenericComponent*) comp)->actualClassName;
|
||||
return static_cast<GenericComponent*> (comp)->actualClassName;
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* comp)
|
||||
String getCreationParameters (GeneratedCode&, Component* comp)
|
||||
{
|
||||
return ((GenericComponent*) comp)->constructorParams;
|
||||
return static_cast<GenericComponent*> (comp)->constructorParams;
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
@ -122,7 +122,7 @@ public:
|
|||
if (component->getName().isNotEmpty())
|
||||
code.constructorCode
|
||||
<< memberVariableName << "->setName ("
|
||||
<< quotedString (component->getName())
|
||||
<< quotedString (component->getName(), code.shouldUseTransMacro())
|
||||
<< ");\n\n";
|
||||
else
|
||||
code.constructorCode << "\n";
|
||||
|
|
|
|||
|
|
@ -65,13 +65,13 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* component)
|
||||
String getCreationParameters (GeneratedCode& code, Component* component)
|
||||
{
|
||||
GroupComponent* g = dynamic_cast <GroupComponent*> (component);
|
||||
|
||||
return quotedString (component->getName())
|
||||
return quotedString (component->getName(), code.shouldUseTransMacro())
|
||||
+ ",\n"
|
||||
+ quotedString (g->getText());
|
||||
+ quotedString (g->getText(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
|
|||
|
|
@ -67,13 +67,13 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* comp)
|
||||
String getCreationParameters (GeneratedCode& code, Component* comp)
|
||||
{
|
||||
HyperlinkButton* const hb = dynamic_cast <HyperlinkButton*> (comp);
|
||||
|
||||
return quotedString (hb->getButtonText())
|
||||
return quotedString (hb->getButtonText(), code.shouldUseTransMacro())
|
||||
+ ",\nURL ("
|
||||
+ quotedString (hb->getURL().toString (false))
|
||||
+ quotedString (hb->getURL().toString (false), code.shouldUseTransMacro())
|
||||
+ ")";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,12 +98,11 @@ public:
|
|||
props.add (new JucerCompOpenDocProperty (tc));
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* component)
|
||||
String getCreationParameters (GeneratedCode&, Component* component)
|
||||
{
|
||||
TestComponent* const tc = dynamic_cast <TestComponent*> (component);
|
||||
|
||||
return tc->getConstructorParams().trim();
|
||||
return dynamic_cast<TestComponent*> (component)->getConstructorParams().trim();
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
{
|
||||
ComponentTypeHandler::fillInCreationCode (code, component, memberVariableName);
|
||||
|
|
|
|||
|
|
@ -97,13 +97,13 @@ public:
|
|||
label->setFont (f);
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* component)
|
||||
String getCreationParameters (GeneratedCode& code, Component* component)
|
||||
{
|
||||
Label* const l = dynamic_cast <Label*> (component);
|
||||
|
||||
return quotedString (component->getName())
|
||||
return quotedString (component->getName(), code.shouldUseTransMacro())
|
||||
+ ",\n"
|
||||
+ quotedString (l->getText());
|
||||
+ quotedString (l->getText(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
|
|||
|
|
@ -85,9 +85,9 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* component)
|
||||
String getCreationParameters (GeneratedCode& code, Component* component)
|
||||
{
|
||||
return quotedString (component->getName());
|
||||
return quotedString (component->getName(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* comp)
|
||||
String getCreationParameters (GeneratedCode&, Component* comp)
|
||||
{
|
||||
TabbedComponent* const t = dynamic_cast <TabbedComponent*> (comp);
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ public:
|
|||
code.constructorCode
|
||||
<< memberVariableName
|
||||
<< "->addTab ("
|
||||
<< quotedString (t->getTabNames() [i])
|
||||
<< quotedString (t->getTabNames() [i], code.shouldUseTransMacro())
|
||||
<< ", "
|
||||
<< CodeHelpers::colourToCode (t->getTabBackgroundColour (i));
|
||||
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ public:
|
|||
addColourProperties (t, document, props);
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* component)
|
||||
String getCreationParameters (GeneratedCode& code, Component* component)
|
||||
{
|
||||
return quotedString (component->getName());
|
||||
return quotedString (component->getName(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
@ -116,7 +116,7 @@ public:
|
|||
<< memberVariableName << "->setCaretVisible (" << CodeHelpers::boolLiteral (te->isCaretVisible()) << ");\n"
|
||||
<< memberVariableName << "->setPopupMenuEnabled (" << CodeHelpers::boolLiteral (te->isPopupMenuEnabled()) << ");\n"
|
||||
<< getColourIntialisationCode (component, memberVariableName)
|
||||
<< memberVariableName << "->setText (" << quotedString (te->getProperties() ["initialText"].toString()) << ");\n\n";
|
||||
<< memberVariableName << "->setText (" << quotedString (te->getProperties() ["initialText"].toString(), code.shouldUseTransMacro()) << ");\n\n";
|
||||
|
||||
code.constructorCode += s;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,9 +73,9 @@ public:
|
|||
addColourProperties (t, document, props);
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* comp)
|
||||
String getCreationParameters (GeneratedCode& code, Component* comp)
|
||||
{
|
||||
return quotedString (comp->getName());
|
||||
return quotedString (comp->getName(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
|
|||
|
|
@ -97,9 +97,9 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
String getCreationParameters (Component* comp)
|
||||
String getCreationParameters (GeneratedCode& code, Component* comp)
|
||||
{
|
||||
return quotedString (comp->getName());
|
||||
return quotedString (comp->getName(), code.shouldUseTransMacro());
|
||||
}
|
||||
|
||||
void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ void ButtonDocument::fillInGeneratedCode (GeneratedCode& code) const
|
|||
{
|
||||
JucerDocument::fillInGeneratedCode (code);
|
||||
|
||||
code.parentClassInitialiser = "Button (" + quotedString (code.componentName) + ")";
|
||||
code.parentClassInitialiser = "Button (" + quotedString (code.componentName, shouldUseTransMacro()) + ")";
|
||||
code.removeCallback ("void", "paint (Graphics& g)");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "../jucer_Headers.h"
|
||||
#include "jucer_GeneratedCode.h"
|
||||
|
||||
#include "jucer_JucerDocument.h"
|
||||
|
||||
//==============================================================================
|
||||
GeneratedCode::GeneratedCode (const JucerDocument* const doc)
|
||||
|
|
@ -229,6 +229,11 @@ static String getIncludeFileCode (StringArray files)
|
|||
return s;
|
||||
}
|
||||
|
||||
bool GeneratedCode::shouldUseTransMacro() const noexcept
|
||||
{
|
||||
return document->shouldUseTransMacro();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static void replaceTemplate (String& text, const String& itemName, const String& value)
|
||||
{
|
||||
|
|
@ -297,11 +302,10 @@ static void copyAcrossUserSections (String& dest, const String& src)
|
|||
|
||||
if (getUserSection (srcLines, tag, sourceLines))
|
||||
{
|
||||
int j;
|
||||
for (j = endLine - i; --j > 0;)
|
||||
for (int j = endLine - i; --j > 0;)
|
||||
dstLines.remove (i + 1);
|
||||
|
||||
for (j = 0; j < sourceLines.size(); ++j)
|
||||
for (int j = 0; j < sourceLines.size(); ++j)
|
||||
dstLines.insert (++i, sourceLines [j].trimEnd());
|
||||
|
||||
++i;
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ public:
|
|||
String getCallbackDefinitions() const;
|
||||
StringArray getExtraParentClasses() const;
|
||||
|
||||
bool shouldUseTransMacro() const noexcept;
|
||||
|
||||
private:
|
||||
String getClassDeclaration() const;
|
||||
String getInitialiserList() const;
|
||||
|
|
|
|||
|
|
@ -426,7 +426,7 @@ void JucerDocument::fillInGeneratedCode (GeneratedCode& code) const
|
|||
code.initialisers.addLines (variableInitialisers);
|
||||
|
||||
if (! componentName.isEmpty())
|
||||
code.constructorCode << "setName (" + quotedString (componentName) + ");\n";
|
||||
code.constructorCode << "setName (" + quotedString (componentName, shouldUseTransMacro()) + ");\n";
|
||||
|
||||
// call these now, just to make sure they're the first two methods in the list.
|
||||
code.getCallbackCode (String::empty, "void", "paint (Graphics& g)", false)
|
||||
|
|
|
|||
|
|
@ -133,6 +133,8 @@ public:
|
|||
String getTemplateFile() const { return templateFile; }
|
||||
void setTemplateFile (const String&);
|
||||
|
||||
static bool shouldUseTransMacro() noexcept { return true; }
|
||||
|
||||
protected:
|
||||
SourceCodeDocument* cpp;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#ifndef __JUCER_UTILITYFUNCTIONS_JUCEHEADER__
|
||||
#define __JUCER_UTILITYFUNCTIONS_JUCEHEADER__
|
||||
|
||||
inline String quotedString (const String& s)
|
||||
inline String quotedString (const String& s, bool wrapInTransMacro)
|
||||
{
|
||||
const int embeddedIndex = s.indexOfIgnoreCase ("%%");
|
||||
|
||||
|
|
@ -48,18 +48,23 @@ inline String quotedString (const String& s)
|
|||
String result;
|
||||
|
||||
if (s1.isNotEmpty())
|
||||
result << quotedString (s1) << " + ";
|
||||
result << quotedString (s1, wrapInTransMacro) << " + ";
|
||||
|
||||
result << code;
|
||||
|
||||
if (s2.isNotEmpty())
|
||||
result << " + " << quotedString (s2);
|
||||
result << " + " << quotedString (s2, wrapInTransMacro);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return CodeHelpers::stringLiteral (s);
|
||||
String lit (CodeHelpers::stringLiteral (s));
|
||||
|
||||
if (wrapInTransMacro && lit.startsWithChar ('"'))
|
||||
return "TRANS(" + lit + ")";
|
||||
|
||||
return lit;
|
||||
}
|
||||
|
||||
inline String castToFloat (const String& expression)
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public:
|
|||
r << "g.setFont ("
|
||||
<< FontPropertyComponent::getCompleteFontCode (font, typefaceName)
|
||||
<< ");\ng.drawText ("
|
||||
<< quotedString (text)
|
||||
<< quotedString (text, code.shouldUseTransMacro())
|
||||
<< ",\n "
|
||||
<< x << ", " << y << ", " << w << ", " << h
|
||||
<< ",\n "
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue