mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-16 00:34:19 +00:00
Introjucer: code editor popup menu helper function to insert a new class declaration.
This commit is contained in:
parent
52378249d1
commit
97ed2ac915
16 changed files with 186 additions and 14 deletions
|
|
@ -211,7 +211,11 @@ GenericCodeEditorComponent::GenericCodeEditorComponent (const File& f, CodeDocum
|
|||
|
||||
GenericCodeEditorComponent::~GenericCodeEditorComponent() {}
|
||||
|
||||
enum { showInFinderID = 0x2fe821e3 };
|
||||
enum
|
||||
{
|
||||
showInFinderID = 0x2fe821e3,
|
||||
insertComponentID = 0x2fe821e4
|
||||
};
|
||||
|
||||
void GenericCodeEditorComponent::addPopupMenuItems (PopupMenu& menu, const MouseEvent* e)
|
||||
{
|
||||
|
|
@ -569,3 +573,46 @@ void CppCodeEditorComponent::insertTextAtCaret (const String& newText)
|
|||
|
||||
GenericCodeEditorComponent::insertTextAtCaret (newText);
|
||||
}
|
||||
|
||||
void CppCodeEditorComponent::addPopupMenuItems (PopupMenu& menu, const MouseEvent* e)
|
||||
{
|
||||
GenericCodeEditorComponent::addPopupMenuItems (menu, e);
|
||||
|
||||
menu.addSeparator();
|
||||
menu.addItem (insertComponentID, TRANS("Insert code for a new Component class..."));
|
||||
}
|
||||
|
||||
void CppCodeEditorComponent::performPopupMenuAction (int menuItemID)
|
||||
{
|
||||
if (menuItemID == insertComponentID)
|
||||
insertComponentClass();
|
||||
|
||||
GenericCodeEditorComponent::performPopupMenuAction (menuItemID);
|
||||
}
|
||||
|
||||
void CppCodeEditorComponent::insertComponentClass()
|
||||
{
|
||||
AlertWindow aw (TRANS ("Insert a new Component class"),
|
||||
TRANS ("Please enter a name for the new class"),
|
||||
AlertWindow::NoIcon, nullptr);
|
||||
|
||||
const char* classNameField = "Class Name";
|
||||
|
||||
aw.addTextEditor (classNameField, String::empty, String::empty, false);
|
||||
aw.addButton (TRANS ("Insert Code"), 1, KeyPress (KeyPress::returnKey));
|
||||
aw.addButton (TRANS ("Cancel"), 0, KeyPress (KeyPress::escapeKey));
|
||||
|
||||
while (aw.runModalLoop() != 0)
|
||||
{
|
||||
const String className (aw.getTextEditorContents (classNameField).trim());
|
||||
|
||||
if (className == CodeHelpers::makeValidIdentifier (className, false, true, false))
|
||||
{
|
||||
String code (BinaryData::jucer_InlineComponentTemplate_h);
|
||||
code = code.replace ("COMPONENTCLASS", className);
|
||||
|
||||
insertTextAtCaret (code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue