The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

440 lines
14KB

  1. /*
  2. ==============================================================================
  3. This is an automatically generated file created by the Jucer!
  4. Creation date: 14 Feb 2010 3:06:06 pm
  5. Be careful when adding custom code to these files, as only the code within
  6. the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  7. and re-saved.
  8. Jucer version: 1.12
  9. ------------------------------------------------------------------------------
  10. The Jucer is part of the JUCE library - "Jules' Utility Class Extensions"
  11. Copyright 2004-6 by Raw Material Software ltd.
  12. ==============================================================================
  13. */
  14. //[Headers] You can add your own extra header files here...
  15. #include "../model/jucer_ProjectExporter.h"
  16. //[/Headers]
  17. #include "jucer_ProjectInformationComponent.h"
  18. //[MiscUserDefs] You can add your own user definitions and misc code here...
  19. class PropertiesWithHelpComponent : public Component,
  20. public Timer
  21. {
  22. public:
  23. PropertiesWithHelpComponent (Project& project_, int tabIndex_)
  24. : project (project_), lastComp (0), tabIndex (tabIndex_)
  25. {
  26. addAndMakeVisible (panel = new PropertyPanel());
  27. startTimer (150);
  28. }
  29. ~PropertiesWithHelpComponent()
  30. {
  31. deleteAllChildren();
  32. }
  33. PropertyPanel* getPanel() const { return panel; }
  34. void rebuildProperties()
  35. {
  36. panel->clear();
  37. Array <PropertyComponent*> props;
  38. if (tabIndex == 0)
  39. {
  40. // The main project tab...
  41. project.createPropertyEditors (props);
  42. }
  43. else if (tabIndex == 1)
  44. {
  45. // The Juce options tab...
  46. OwnedArray <Project::JuceConfigFlag> flags;
  47. project.getJuceConfigFlags (flags);
  48. StringArray possibleValues;
  49. possibleValues.add ("Enabled");
  50. possibleValues.add ("Disabled");
  51. possibleValues.add ("(Use default from juce_Config.h)");
  52. for (int i = 0; i < flags.size(); ++i)
  53. {
  54. if ((int) flags[i]->value.getValue() == 0)
  55. flags[i]->value = 3;
  56. ChoicePropertyComponent* c = new ChoicePropertyComponent (flags[i]->value, flags[i]->symbol, possibleValues);
  57. c->setTooltip (flags[i]->description);
  58. c->setPreferredHeight (22);
  59. props.add (c);
  60. }
  61. }
  62. else if (tabIndex < 2 + project.getNumConfigurations())
  63. {
  64. // A config tab..
  65. project.getConfiguration (tabIndex - 2).createPropertyEditors (props);
  66. }
  67. else
  68. {
  69. // An export tab..
  70. ScopedPointer <ProjectExporter> exp (project.createExporter (tabIndex - (2 + project.getNumConfigurations())));
  71. if (exp != 0)
  72. exp->createPropertyEditors (props);
  73. }
  74. panel->addProperties (props);
  75. }
  76. void visibilityChanged()
  77. {
  78. if (isVisible())
  79. rebuildProperties();
  80. }
  81. void paint (Graphics& g)
  82. {
  83. g.setColour (Colour::greyLevel (0.15f));
  84. g.setFont (13.0f);
  85. TextLayout tl;
  86. tl.appendText (lastTip, Font (14.0f));
  87. tl.layout (getWidth() - 10, Justification::left, true); // try to make it look nice
  88. if (tl.getNumLines() > 3)
  89. tl.layout (getWidth() - 10, Justification::left, false); // too big, so just squash it in..
  90. tl.drawWithin (g, 5, panel->getBottom() + 2, getWidth() - 10,
  91. getHeight() - panel->getBottom() - 4,
  92. Justification::centredLeft);
  93. }
  94. void resized()
  95. {
  96. panel->setBounds (0, 0, getWidth(), jmax (getHeight() - 60, proportionOfHeight (0.6f)));
  97. }
  98. void timerCallback()
  99. {
  100. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  101. if (newComp != lastComp)
  102. {
  103. lastComp = newComp;
  104. String newTip (findTip (newComp));
  105. if (newTip != lastTip)
  106. {
  107. lastTip = newTip;
  108. repaint (0, panel->getBottom(), getWidth(), getHeight());
  109. }
  110. }
  111. }
  112. private:
  113. Project& project;
  114. PropertyPanel* panel;
  115. TextLayout layout;
  116. Component* lastComp;
  117. String lastTip;
  118. int tabIndex;
  119. const String findTip (Component* c)
  120. {
  121. while (c != 0 && c != this)
  122. {
  123. TooltipClient* tc = dynamic_cast <TooltipClient*> (c);
  124. if (tc != 0)
  125. {
  126. String tip (tc->getTooltip());
  127. if (tip.isNotEmpty())
  128. return tip;
  129. }
  130. c = c->getParentComponent();
  131. }
  132. return String::empty;
  133. }
  134. };
  135. //[/MiscUserDefs]
  136. //==============================================================================
  137. ProjectInformationComponent::ProjectInformationComponent (Project& project_)
  138. : project (project_),
  139. configTabBox (0),
  140. editConfigsButton (0),
  141. openProjectButton (0),
  142. editExportersButton (0)
  143. {
  144. addAndMakeVisible (configTabBox = new TabbedComponent (TabbedButtonBar::TabsAtTop));
  145. configTabBox->setTabBarDepth (30);
  146. configTabBox->setCurrentTabIndex (-1);
  147. addAndMakeVisible (editConfigsButton = new TextButton (String::empty));
  148. editConfigsButton->setButtonText (T("Add/Remove Configurations..."));
  149. editConfigsButton->addButtonListener (this);
  150. addAndMakeVisible (openProjectButton = new TextButton (String::empty));
  151. openProjectButton->setButtonText (T("Open Project in "));
  152. openProjectButton->addButtonListener (this);
  153. addAndMakeVisible (editExportersButton = new TextButton (String::empty));
  154. editExportersButton->setButtonText (T("Add/Remove Exporters..."));
  155. editExportersButton->addButtonListener (this);
  156. //[UserPreSize]
  157. rebuildConfigTabs();
  158. #if JUCE_MAC || JUCE_WINDOWS
  159. openProjectButton->setCommandToTrigger (commandManager, CommandIDs::openProjectInIDE, true);
  160. openProjectButton->setButtonText (commandManager->getNameOfCommand (CommandIDs::openProjectInIDE));
  161. #else
  162. openProjectButton->setVisible (false);
  163. #endif
  164. //[/UserPreSize]
  165. setSize (600, 400);
  166. //[Constructor] You can add your own custom stuff here..
  167. configTabBox->setOutline (1);
  168. configTabBox->setColour (TabbedComponent::outlineColourId, Colours::black);
  169. editConfigsButton->setTriggeredOnMouseDown (true);
  170. project.addChangeListener (this);
  171. //[/Constructor]
  172. }
  173. ProjectInformationComponent::~ProjectInformationComponent()
  174. {
  175. //[Destructor_pre]. You can add your own custom destruction code here..
  176. project.removeChangeListener (this);
  177. //[/Destructor_pre]
  178. deleteAndZero (configTabBox);
  179. deleteAndZero (editConfigsButton);
  180. deleteAndZero (openProjectButton);
  181. deleteAndZero (editExportersButton);
  182. //[Destructor]. You can add your own custom destruction code here..
  183. //[/Destructor]
  184. }
  185. //==============================================================================
  186. void ProjectInformationComponent::paint (Graphics& g)
  187. {
  188. //[UserPrePaint] Add your own custom painting code here..
  189. //[/UserPrePaint]
  190. //[UserPaint] Add your own custom painting code here..
  191. //[/UserPaint]
  192. }
  193. void ProjectInformationComponent::resized()
  194. {
  195. configTabBox->setBounds (8, 0, getWidth() - 16, getHeight() - 36);
  196. editConfigsButton->setBounds (8, getHeight() - 26, 192, 22);
  197. openProjectButton->setBounds (384, getHeight() - 26, 208, 22);
  198. editExportersButton->setBounds (208, getHeight() - 26, 160, 22);
  199. //[UserResized] Add your own custom resize handling here..
  200. //[/UserResized]
  201. }
  202. void ProjectInformationComponent::buttonClicked (Button* buttonThatWasClicked)
  203. {
  204. //[UserbuttonClicked_Pre]
  205. //[/UserbuttonClicked_Pre]
  206. if (buttonThatWasClicked == editConfigsButton)
  207. {
  208. //[UserButtonCode_editConfigsButton] -- add your button handler code here..
  209. showConfigMenu();
  210. //[/UserButtonCode_editConfigsButton]
  211. }
  212. else if (buttonThatWasClicked == openProjectButton)
  213. {
  214. //[UserButtonCode_openProjectButton] -- add your button handler code here..
  215. //[/UserButtonCode_openProjectButton]
  216. }
  217. else if (buttonThatWasClicked == editExportersButton)
  218. {
  219. //[UserButtonCode_editExportersButton] -- add your button handler code here..
  220. showExporterMenu();
  221. //[/UserButtonCode_editExportersButton]
  222. }
  223. //[UserbuttonClicked_Post]
  224. //[/UserbuttonClicked_Post]
  225. }
  226. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  227. void ProjectInformationComponent::rebuildConfigTabs()
  228. {
  229. configTabBox->clearTabs();
  230. int index = 0;
  231. PropertiesWithHelpComponent* panel = new PropertiesWithHelpComponent (project, index++);
  232. configTabBox->addTab ("Project Settings", Colours::lightslategrey, panel, true, -1);
  233. panel = new PropertiesWithHelpComponent (project, index++);
  234. configTabBox->addTab ("Juce Flags", Colours::lightblue, panel, true, -1);
  235. int i;
  236. for (i = 0; i < project.getNumConfigurations(); ++i)
  237. {
  238. panel = new PropertiesWithHelpComponent (project, index++);
  239. Project::BuildConfiguration config (project.getConfiguration (i));
  240. configTabBox->addTab (config.getName().toString(), Colour::greyLevel (0.65f), panel, true, -1);
  241. }
  242. for (i = 0; i < project.getNumExporters(); ++i)
  243. {
  244. ScopedPointer <ProjectExporter> exp (project.createExporter (i));
  245. if (exp != 0)
  246. {
  247. panel = new PropertiesWithHelpComponent (project, index++);
  248. configTabBox->addTab (exp->getName(), Colours::lightsteelblue, panel, true, -1);
  249. }
  250. }
  251. lastProjectType = (Project::ProjectType) (int) project.getProjectType().getValue();
  252. }
  253. void ProjectInformationComponent::updateConfigTabs()
  254. {
  255. if (configTabBox->getNumTabs() != project.getNumConfigurations() + project.getNumExporters() + 2
  256. || lastProjectType != (Project::ProjectType) (int) project.getProjectType().getValue())
  257. {
  258. rebuildConfigTabs();
  259. }
  260. else
  261. {
  262. for (int i = 0; i < project.getNumConfigurations(); ++i)
  263. {
  264. Project::BuildConfiguration config (project.getConfiguration (i));
  265. configTabBox->setTabName (i + 2, config.getName().toString());
  266. }
  267. }
  268. }
  269. void ProjectInformationComponent::showConfigMenu()
  270. {
  271. PopupMenu m;
  272. m.addItem (1, "Add a new empty configuration");
  273. PopupMenu createCopyMenu, removeMenu;
  274. for (int i = 0; i < project.getNumConfigurations(); ++i)
  275. {
  276. Project::BuildConfiguration config (project.getConfiguration (i));
  277. createCopyMenu.addItem (i + 10000, "Create a copy of '" + config.getName().toString() + "'");
  278. removeMenu.addItem (i + 20000, "Delete configuration '" + config.getName().toString() + "'");
  279. }
  280. m.addSubMenu ("Add a copy of an existing configuration", createCopyMenu);
  281. m.addSubMenu ("Remove configuration", removeMenu);
  282. const int r = m.showAt (editConfigsButton);
  283. if (r >= 20000)
  284. {
  285. project.deleteConfiguration (r - 20000);
  286. }
  287. else if (r >= 10000)
  288. {
  289. Project::BuildConfiguration configToCopy (project.getConfiguration (r - 10000));
  290. project.addNewConfiguration (&configToCopy);
  291. }
  292. else if (r == 1)
  293. {
  294. project.addNewConfiguration (0);
  295. }
  296. }
  297. void ProjectInformationComponent::showExporterMenu()
  298. {
  299. PopupMenu m;
  300. PopupMenu createMenu, removeMenu;
  301. int i;
  302. for (i = 0; i < project.getNumExporters(); ++i)
  303. {
  304. ScopedPointer<ProjectExporter> exp (project.createExporter (i));
  305. if (exp != 0)
  306. removeMenu.addItem (i + 20000, "Delete " + exp->getName());
  307. }
  308. StringArray exporters (ProjectExporter::getExporterNames());
  309. for (i = 0; i < exporters.size(); ++i)
  310. createMenu.addItem (i + 10000, "Create a new " + exporters[i] + " target");
  311. m.addSubMenu ("Create new export target", createMenu);
  312. m.addSubMenu ("Remove export target", removeMenu);
  313. const int r = m.showAt (editExportersButton);
  314. if (r >= 20000)
  315. project.deleteExporter (r - 20000);
  316. else if (r >= 10000)
  317. project.addNewExporter (r - 10000);
  318. }
  319. void ProjectInformationComponent::changeListenerCallback (void*)
  320. {
  321. updateConfigTabs();
  322. }
  323. //[/MiscUserCode]
  324. //==============================================================================
  325. #if 0
  326. /* -- Jucer information section --
  327. This is where the Jucer puts all of its metadata, so don't change anything in here!
  328. BEGIN_JUCER_METADATA
  329. <JUCER_COMPONENT documentType="Component" className="ProjectInformationComponent"
  330. componentName="" parentClasses="public Component, public ChangeListener"
  331. constructorParams="Project&amp; project_" variableInitialisers="project (project_)"
  332. snapPixels="8" snapActive="1" snapShown="0" overlayOpacity="0.330000013"
  333. fixedSize="0" initialWidth="600" initialHeight="400">
  334. <BACKGROUND backgroundColour="f6f9ff"/>
  335. <TABBEDCOMPONENT name="" id="962c1575c4142253" memberName="configTabBox" virtualName=""
  336. explicitFocusOrder="0" pos="8 0 16M 36M" orientation="top" tabBarDepth="30"
  337. initialTab="-1"/>
  338. <TEXTBUTTON name="" id="b6625dfcdb1f4755" memberName="editConfigsButton"
  339. virtualName="" explicitFocusOrder="0" pos="8 26R 192 22" buttonText="Add/Remove Configurations..."
  340. connectedEdges="0" needsCallback="1" radioGroupId="0"/>
  341. <TEXTBUTTON name="" id="a550a652e2666ee7" memberName="openProjectButton"
  342. virtualName="" explicitFocusOrder="0" pos="384 26R 208 22" buttonText="Open Project in "
  343. connectedEdges="0" needsCallback="1" radioGroupId="0"/>
  344. <TEXTBUTTON name="" id="c1f6e5f9811b307e" memberName="editExportersButton"
  345. virtualName="" explicitFocusOrder="0" pos="208 26R 160 22" buttonText="Add/Remove Exporters..."
  346. connectedEdges="0" needsCallback="1" radioGroupId="0"/>
  347. </JUCER_COMPONENT>
  348. END_JUCER_METADATA
  349. */
  350. #endif