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.

725 lines
24KB

  1. /*
  2. Copyright (C) 2012 Rory Walsh
  3. Cabbage is free software; you can redistribute it
  4. and/or modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. Cabbage is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with Csound; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA
  15. */
  16. #include "CodeWindow.h"
  17. //==============================================================================
  18. CodeWindow::CodeWindow(String name):DocumentWindow (name, Colours::black,
  19. DocumentWindow::allButtons),
  20. fontSize(15),
  21. showOutput(true),
  22. csoundOutputText(""),
  23. debugMessage(""),
  24. firstTime(true),
  25. font(String("Courier New"), 15, 1),
  26. showingHelp(false)
  27. {
  28. setApplicationCommandManagerToWatch(&commandManager);
  29. commandManager.registerAllCommandsForTarget(this);
  30. addKeyListener(commandManager.getKeyMappings());
  31. textEditor = new CsoundCodeEditor("csound", csoundDoc, &csoundToker);
  32. restoreWindowStateFromString (appProperties->getUserSettings()->getValue ("mainWindowPos"));
  33. textEditor->addActionListener(this);
  34. this->setTitleBarHeight(20);
  35. this->setColour(DocumentWindow::backgroundColourId, CabbageUtils::getBackgroundSkin());
  36. setMenuBar(this, 25);
  37. setVisible(true);
  38. this->setWantsKeyboardFocus(false);
  39. if(!appProperties->getUserSettings()->getValue("EditorColourScheme", var(0)).getIntValue())
  40. setEditorColourScheme("white");
  41. else if(appProperties->getUserSettings()->getValue("EditorColourScheme", var(0)).getIntValue())
  42. setEditorColourScheme("dark");
  43. RecentlyOpenedFilesList recentFiles;
  44. recentFiles.restoreFromString (appProperties->getUserSettings()
  45. ->getValue ("recentlyOpenedFiles"));
  46. csdFile = recentFiles.getFile (0);
  47. csoundDoc.replaceAllContent(csdFile.loadFileAsString());
  48. //cabbageTimer->addActionListener(this);
  49. //cabbageTimer->startTimedEvent(10, "splash");
  50. setResizable(true, false);
  51. String opcodeFile = File(File::getSpecialLocation(File::currentExecutableFile)).getParentDirectory().getFullPathName();
  52. opcodeFile += "/opcodes.txt";
  53. Logger::writeToLog(opcodeFile);
  54. if(File(opcodeFile).existsAsFile())
  55. textEditor->setOpcodeStrings(File(opcodeFile).loadFileAsString());
  56. //else csound->Message("Could not open opcodes.txt file, parameter display disabled..");
  57. //set up popup for displaying info regarding opcodes..
  58. popupDisplay = new PopupDisplay("Poppy");
  59. popupDisplay->addActionListener(this);
  60. popupDisplay->setTitleBarHeight(0);
  61. popupDisplay->addToDesktop(0);
  62. popupDisplay->setVisible(false);
  63. htmlHelp = new WebBrowserComponent(false);
  64. setContentNonOwned(textEditor, false);
  65. }
  66. CodeWindow::~CodeWindow(){
  67. setMenuBar(0);
  68. setApplicationCommandManagerToWatch(nullptr);
  69. commandManager.deleteInstance();
  70. deleteAndZero(textEditor);
  71. }
  72. void CodeWindow::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  73. {
  74. KeyboardShortcutKeys shortcuts(appProperties->getUserSettings()->getXmlValue("KeyboardShortcutXmlData"));
  75. switch (commandID)
  76. {
  77. //file commands
  78. case CommandIDs::fileNew:
  79. result.setInfo (String("New"), String("Create a new file"), CommandCategories::file, 0);
  80. result.addDefaultKeypress ('n', ModifierKeys::commandModifier);
  81. break;
  82. case CommandIDs::fileOpen:
  83. result.setInfo (String("Open"), String("Open a file"), CommandCategories::file, 0);
  84. result.addDefaultKeypress ('o', ModifierKeys::commandModifier);
  85. break;
  86. case CommandIDs::fileSave:
  87. result.setInfo (String("Save"), String("Save a file"), CommandCategories::file, 0);
  88. result.addDefaultKeypress ('s', ModifierKeys::commandModifier);
  89. break;
  90. case CommandIDs::fileSaveAs:
  91. result.setInfo (String("Save as"), String("Save file as.."), CommandCategories::file, 0);
  92. result.addDefaultKeypress ('s', ModifierKeys::shiftModifier | ModifierKeys::commandModifier);
  93. break;
  94. case CommandIDs::fileQuit:
  95. result.setInfo (String("Quit"), String("Quit"), CommandCategories::file, 0);
  96. result.addDefaultKeypress ('s', ModifierKeys::shiftModifier | ModifierKeys::commandModifier);
  97. break;
  98. case CommandIDs::fileUpdateGUI:
  99. result.setInfo (String("Update GUI"), String("Update GUI"), CommandCategories::file, 0);
  100. result.addDefaultKeypress ('#', ModifierKeys::commandModifier);
  101. break;
  102. case CommandIDs::fileKeyboardShorts:
  103. result.setInfo (String("Keyboard Shortcuts"), String("Update GUI"), CommandCategories::file, 0);
  104. break;
  105. //edit commands
  106. case CommandIDs::editUndo:
  107. result.setInfo (String("Undo"), String("Undo last action"), CommandCategories::edit, 0);
  108. result.addDefaultKeypress ('z', ModifierKeys::commandModifier);
  109. break;
  110. case CommandIDs::editRedo:
  111. result.setInfo (String("Redo"), String("Redo last action"), CommandCategories::edit, 0);
  112. result.addDefaultKeypress ('z', ModifierKeys::shiftModifier | ModifierKeys::commandModifier);
  113. break;
  114. case CommandIDs::editCut:
  115. result.setInfo (String("Cut"), String("Cut selection"), CommandCategories::edit, 0);
  116. result.addDefaultKeypress ('x', ModifierKeys::commandModifier);
  117. break;
  118. case CommandIDs::editCopy:
  119. result.setInfo (String("Copy"), String("Copy selection"), CommandCategories::edit, 0);
  120. result.addDefaultKeypress ('c', ModifierKeys::commandModifier);
  121. break;
  122. case CommandIDs::editPaste:
  123. result.setInfo (String("Paste"), String("Paste selection"), CommandCategories::edit, 0);
  124. result.addDefaultKeypress ('v', ModifierKeys::commandModifier);
  125. break;
  126. case CommandIDs::editToggleComments:
  127. result.setInfo (String("Toggle comments"), String("Toggle comments"), CommandCategories::edit, 0);
  128. result.addDefaultKeypress ('t', ModifierKeys::commandModifier);
  129. break;
  130. case CommandIDs::editZoomIn:
  131. result.setInfo (String("Zoom in"), String("Zoom in"), CommandCategories::edit, 0);
  132. result.addDefaultKeypress ('=', ModifierKeys::commandModifier);
  133. break;
  134. case CommandIDs::editZoomOut:
  135. result.setInfo (String("Zoom out"), String("Zoom out"), CommandCategories::edit, 0);
  136. result.addDefaultKeypress ('-', ModifierKeys::commandModifier);
  137. break;
  138. case CommandIDs::whiteBackground:
  139. result.setInfo (String("White background"), String("White scheme"), CommandCategories::edit, 0);
  140. break;
  141. case CommandIDs::blackBackground:
  142. result.setInfo (String("Dark background"), String("Dark scheme"), CommandCategories::edit, 0);
  143. break;
  144. case CommandIDs::insertFromRepo:
  145. result.setInfo (String("Insert from repo"), String("Insert from repo"), CommandCategories::edit, 0);
  146. //result.defaultKeypresses.add (KeyPress::createFromDescription(shortcuts.getKeyPress("InsertFromRepo")));
  147. //result.addDefaultKeypress (KeyPress::createFromDescription(shortcuts.getKeyPress("InsertFromRepo")));
  148. break;
  149. case CommandIDs::addFromRepo:
  150. result.setInfo (String("Add from repo"), String("Add from repo"), CommandCategories::edit, 0);
  151. result.addDefaultKeypress ('j', ModifierKeys::commandModifier);
  152. break;
  153. case CommandIDs::insertRecentEvent:
  154. result.setInfo (String("Insert recent event"), String("Insert recent event"), CommandCategories::edit, 0);
  155. result.addDefaultKeypress ('e', ModifierKeys::commandModifier | ModifierKeys::altModifier);
  156. break;
  157. case CommandIDs::openPythonEditor:
  158. result.setInfo (String("Insert Python code"), String("Insert Python code"), CommandCategories::edit, 0);
  159. result.addDefaultKeypress ('p', ModifierKeys::commandModifier | ModifierKeys::altModifier);
  160. break;
  161. case CommandIDs::AudioSettings:
  162. result.setInfo (String("Audio Settings"), String("Edit audio settings"), CommandCategories::edit, 0);
  163. break;
  164. //interactive commands
  165. case CommandIDs::commOrchUpdateInstrument:
  166. result.setInfo (String("Update entire instr"), String("Update entire instr"), CommandCategories::command, 0);
  167. result.addDefaultKeypress ('u', ModifierKeys::commandModifier);
  168. break;
  169. case CommandIDs::startSession:
  170. result.setInfo (String("Restart Session"), String("Restart Session"), CommandCategories::command, 0);
  171. result.addDefaultKeypress ('r', ModifierKeys::commandModifier);
  172. break;
  173. case CommandIDs::commOrchUpdateMultiLine:
  174. result.setInfo (String("Update orc multi-line"), String("Update orch mutli-line"), CommandCategories::command, 0);
  175. result.addDefaultKeypress ('m', ModifierKeys::commandModifier);
  176. break;
  177. case CommandIDs::commOrchUpdateSingleLine:
  178. result.setInfo (String("Update orc single-line"), String("Update orch single-line"), CommandCategories::command, 0);
  179. result.addDefaultKeypress ('l', ModifierKeys::commandModifier);
  180. break;
  181. case CommandIDs::commScoUpdateMultiLine:
  182. result.setInfo (String("Update sco multi-line"), String("Update orch multi-line"), CommandCategories::command, 0);
  183. result.addDefaultKeypress ('p', ModifierKeys::commandModifier);
  184. break;
  185. case CommandIDs::commScoUpdateSingleLine:
  186. result.setInfo (String("Update sco single-line"), String("Update orch multi-line"), CommandCategories::command, 0);
  187. result.addDefaultKeypress ('e', ModifierKeys::commandModifier);
  188. break;
  189. case CommandIDs::commOrcUpdateChannel:
  190. result.setInfo (String("Update channel"), String("Update channel"), CommandCategories::command, 0);
  191. result.addDefaultKeypress ('c', ModifierKeys::altModifier | ModifierKeys::commandModifier);
  192. break;
  193. case CommandIDs::viewCsoundHelp:
  194. #ifndef MACOSX
  195. result.setInfo (String("Toggle Csound Manual F1"), String("Toggle Csound Manual"), CommandCategories::help, 0);
  196. result.defaultKeypresses.add(KeyPress(KeyPress::F1Key));
  197. #else
  198. result.setInfo (String("Toggle Csound Manual Ctrl+1"), String("Toggle Csound Manual"), CommandCategories::help, 0);
  199. result.addDefaultKeypress ('1', ModifierKeys::commandModifier);
  200. #endif
  201. break;
  202. case CommandIDs::viewCabbageHelp:
  203. result.setInfo (String("Toggle Cabbage Manual"), String("Toggle Cabbage Manual"), CommandCategories::help, 0);
  204. break;
  205. }
  206. }
  207. //==============================================================================
  208. PopupMenu CodeWindow::getMenuForIndex (int topLevelMenuIndex, const String& menuName)
  209. {
  210. PopupMenu m1, m2;
  211. m1.clear();
  212. m2.clear();
  213. m2.setLookAndFeel(&getLookAndFeel());
  214. if(topLevelMenuIndex==0)
  215. {
  216. //m1.addCommandItem(&commandManager, CommandIDs::fileNew);
  217. //m1.addCommandItem(&commandManager, CommandIDs::fileOpen);
  218. //RecentlyOpenedFilesList recentFiles;
  219. //recentFiles.restoreFromString (appProperties->getUserSettings()
  220. // ->getValue ("recentlyOpenedFiles"));
  221. //PopupMenu recentFilesMenu;
  222. //recentFiles.createPopupMenuItems (recentFilesMenu, 100, true, true);
  223. //m1.addSubMenu ("Open recent file", recentFilesMenu);
  224. m1.addCommandItem(&commandManager, CommandIDs::fileSave);
  225. m1.addCommandItem(&commandManager, CommandIDs::fileSaveAs);
  226. m1.addCommandItem(&commandManager, CommandIDs::fileQuit);
  227. //m1.addCommandItem(&commandManager, CommandIDs::fileKeyboardShorts);
  228. return m1;
  229. }
  230. else if(topLevelMenuIndex==1)
  231. {
  232. m1.addCommandItem(&commandManager, CommandIDs::editUndo);
  233. m1.addCommandItem(&commandManager, CommandIDs::editRedo);
  234. m1.addCommandItem(&commandManager, CommandIDs::editCut);
  235. m1.addCommandItem(&commandManager, CommandIDs::editCopy);
  236. m1.addCommandItem(&commandManager, CommandIDs::editPaste);
  237. m1.addCommandItem(&commandManager, CommandIDs::editToggleComments);
  238. m1.addSeparator();
  239. m2.addCommandItem(&commandManager, CommandIDs::editZoomIn);
  240. m2.addCommandItem(&commandManager, CommandIDs::editZoomOut);
  241. m1.addSubMenu(String("Font Size"), m2);
  242. m2.clear();
  243. m2.addCommandItem(&commandManager, CommandIDs::whiteBackground);
  244. m2.addCommandItem(&commandManager, CommandIDs::blackBackground);
  245. m1.addSubMenu("Change editor theme", m2);
  246. m1.addCommandItem(&commandManager, CommandIDs::AudioSettings);
  247. //m1.addCommandItem(&commandManager, CommandIDs::insertFromRepo);
  248. //m1.addCommandItem(&commandManager, CommandIDs::addFromRepo);
  249. //m1.addCommandItem(&commandManager, CommandIDs::insertRecentEvent);
  250. //m1.addCommandItem(&commandManager, CommandIDs::openPythonEditor);
  251. return m1;
  252. }
  253. //else if(topLevelMenuIndex==2)
  254. // {
  255. //m1.addCommandItem(&commandManager, CommandIDs::startSession);
  256. //m1.addCommandItem(&commandManager, CommandIDs::commOrchUpdateInstrument);
  257. //m1.addCommandItem(&commandManager, CommandIDs::commOrcUpdateChannel);
  258. //m1.addCommandItem(&commandManager, CommandIDs::commOrchUpdateMultiLine);
  259. //m1.addCommandItem(&commandManager, CommandIDs::commOrchUpdateSingleLine);
  260. //m1.addCommandItem(&commandManager, CommandIDs::commScoUpdateMultiLine);
  261. //m1.addCommandItem(&commandManager, CommandIDs::commScoUpdateSingleLine);
  262. // return m1;
  263. // }
  264. else if(topLevelMenuIndex==2)
  265. {
  266. m1.addCommandItem(&commandManager, CommandIDs::viewCsoundHelp);
  267. m1.addCommandItem(&commandManager, CommandIDs::viewCabbageHelp);
  268. return m1;
  269. }
  270. else return m1;
  271. }
  272. bool CodeWindow::perform (const InvocationInfo& info)
  273. {
  274. Logger::writeToLog(String(info.commandID));
  275. //---------------------------------------------------------------------------------------------
  276. if(info.commandID==CommandIDs::fileNew)
  277. {
  278. String tempFile = File::getSpecialLocation(File::userHomeDirectory).getFullPathName()+"/liveCodeSession.csd";
  279. Logger::writeToLog(tempFile);
  280. csdFile = tempFile;
  281. csoundDoc.replaceAllContent(csdFile.loadFileAsString());
  282. toggleTextWindows();
  283. }
  284. else if(info.commandID==CommandIDs::fileSave)
  285. {
  286. Logger::writeToLog("fileSaved");
  287. sendActionMessage("fileSaved");
  288. }
  289. else if(info.commandID==CommandIDs::fileSaveAs)
  290. {
  291. Logger::writeToLog("fileSaveAs");
  292. sendActionMessage("fileSaveAs");
  293. }
  294. else if(info.commandID==CommandIDs::fileOpen)
  295. {
  296. Logger::writeToLog("fileOpen");
  297. sendActionMessage("fileOpen");
  298. }
  299. else if(info.commandID==CommandIDs::AudioSettings)
  300. {
  301. sendActionMessage("audioSettings");
  302. }
  303. else if(info.commandID==CommandIDs::fileQuit)
  304. {
  305. JUCEApplication::getInstance()->systemRequestedQuit();
  306. }
  307. else if(info.commandID==CommandIDs::editUndo)
  308. {
  309. textEditor->undo();
  310. }
  311. else if(info.commandID==CommandIDs::fileKeyboardShorts)
  312. {
  313. DialogWindow::LaunchOptions o;
  314. o.content.setOwned(new ShortcutsPanel());
  315. o.dialogTitle = TRANS("Keyboard Shortcuts");
  316. o.dialogBackgroundColour = Colours::black;
  317. o.resizable = false;
  318. o.useNativeTitleBar = false;
  319. o.escapeKeyTriggersCloseButton = true;
  320. //o.content->setLookAndFeel(&this->getLookAndFeel());
  321. o.launchAsync();
  322. }
  323. else if(info.commandID==CommandIDs::editCut)
  324. {
  325. textEditor->cutToClipboard();
  326. }
  327. else if(info.commandID==CommandIDs::editCopy)
  328. {
  329. textEditor->copyToClipboard();
  330. }
  331. else if(info.commandID==CommandIDs::editPaste)
  332. {
  333. textEditor->pasteFromClipboard();
  334. }
  335. else if(info.commandID==CommandIDs::editRedo)
  336. {
  337. textEditor->redo();
  338. }
  339. else if(info.commandID==CommandIDs::editToggleComments)
  340. {
  341. textEditor->toggleComments();
  342. }
  343. else if(info.commandID==CommandIDs::editZoomIn)
  344. {
  345. setFontSize("in");
  346. }
  347. else if(info.commandID==CommandIDs::editZoomOut)
  348. {
  349. setFontSize("out");
  350. }
  351. else if(info.commandID==CommandIDs::whiteBackground)
  352. {
  353. setEditorColourScheme("white");
  354. }
  355. else if(info.commandID==CommandIDs::blackBackground)
  356. {
  357. setEditorColourScheme("dark");
  358. }
  359. else if(info.commandID==CommandIDs::insertRecentEvent)
  360. {
  361. }
  362. else if(info.commandID==CommandIDs::insertFromRepo)
  363. {
  364. popupDisplay->setVisible(false);
  365. CodeWindow::insertFromRepo();
  366. }
  367. else if(info.commandID==CommandIDs::openPythonEditor)
  368. {
  369. /*if(pythonEditor==nullptr){
  370. pythonEditor = new PythonEditor("Python Editor");
  371. //pythonEditor->textEditor->setLookAndFeel(lookAndFeel);
  372. //pythonEditor->setLookAndFeel(lookAndFeel);
  373. pythonEditor->addActionListener(this);
  374. pythonEditor->setAlwaysOnTop(true);
  375. pythonEditor->setVisible(true);
  376. pythonEditor->textEditor->setColour(CodeEditorComponent::backgroundColourId, Colour::fromRGB(40, 40, 40));
  377. }
  378. pythonEditor->toFront(true);
  379. cabbageTimer->startTimedEvent(1, "pythonFocus");
  380. //pythonEditor->textEditor->highlightLine("oscil 1");
  381. */
  382. }
  383. else if(info.commandID==CommandIDs::addFromRepo)
  384. {
  385. textEditor->addToRepository();
  386. }
  387. else if(info.commandID==CommandIDs::viewCsoundHelp)
  388. {
  389. sendActionMessage("toggleCsoundOutput");
  390. sendActionMessage("hideOutputWindow");
  391. toggleManuals("Csound");
  392. }
  393. else if(info.commandID==CommandIDs::viewCabbageHelp)
  394. {
  395. sendActionMessage("toggleCsoundOutput");
  396. sendActionMessage("hideOutputWindow");
  397. toggleManuals("Cabbage");
  398. }
  399. return true;
  400. }
  401. //=======================================================
  402. // toggle manuals
  403. //=======================================================
  404. void CodeWindow::toggleManuals(String manual)
  405. {
  406. if(!showingHelp)
  407. if(manual=="Csound")
  408. {
  409. String helpDir;
  410. if(manual=="Csound")
  411. helpDir = appProperties->getUserSettings()->getValue("CsoundHelpDir", "");
  412. if(helpDir.length()<2)
  413. CabbageUtils::showMessage("Please set the Csound manual directory in the Preference menu", &getLookAndFeel());
  414. else{
  415. CodeDocument::Position pos1, pos2;
  416. pos1 = textEditor->getDocument().findWordBreakBefore(textEditor->getCaretPos());
  417. pos2 = textEditor->getDocument().findWordBreakAfter(textEditor->getCaretPos());
  418. String opcode = csoundDoc.getTextBetween(pos1, pos2);
  419. URL urlCsound(helpDir+"/"+opcode.trim()+String(".html"));
  420. String urlCabbage;
  421. ChildProcess process;
  422. File temp1(urlCsound.toString(false));
  423. if(temp1.exists()){
  424. #ifdef LINUX
  425. if(!process.start("xdg-open "+urlCsound.toString(false).toUTF8()))
  426. CabbageUtils::showMessage("couldn't show file", &getLookAndFeel());
  427. #else
  428. htmlHelp->goToURL(urlCsound.toString(false));
  429. showingHelp = true;
  430. setContentNonOwned(nullptr, false);
  431. setContentNonOwned(htmlHelp, false);
  432. #endif
  433. }
  434. }
  435. }
  436. else{
  437. String path;
  438. #if defined(LINUX) || defined(MACOSX)
  439. path = File::getSpecialLocation(File::currentExecutableFile).getParentDirectory().getFullPathName()+"/Docs/cabbage.html";
  440. #else
  441. path = File::getSpecialLocation(File::currentExecutableFile).getParentDirectory().getFullPathName()+"\\Docs\\cabbage.html";
  442. #endif
  443. if(!File(path).existsAsFile())
  444. CabbageUtils::showMessage(
  445. "Could not find Cabbage manual. Make sure\n\
  446. it is located in the Docs folder in the same\n\
  447. directory as the main Cabbage executable", &getLookAndFeel());
  448. else{
  449. ChildProcess process;
  450. File temp1(path);
  451. if(temp1.exists()){
  452. #ifdef LINUX
  453. if(!process.start("xdg-open "+path))
  454. CabbageUtils::showMessage("couldn't show file", &getLookAndFeel());
  455. #else
  456. htmlHelp->goToURL(path);
  457. showingHelp = true;
  458. setContentNonOwned(nullptr, false);
  459. setContentNonOwned(htmlHelp, false);
  460. #endif
  461. }
  462. }
  463. }
  464. else{
  465. setContentNonOwned(nullptr, false);
  466. setContentNonOwned(textEditor, false);
  467. showingHelp = false;
  468. }
  469. }
  470. void CodeWindow::toggleTextWindows()
  471. {
  472. /*
  473. if(showOutput){
  474. setContentNonOwned(textEditor, false);
  475. setMenuBar(this, 25);
  476. stopTimer();
  477. if(firstTime)
  478. outputTextEditor->setText("");
  479. firstTime==false;
  480. repaint();
  481. }
  482. else{
  483. startTimer(100);
  484. setContentNonOwned(outputTextEditor, false);
  485. setMenuBar(this, 25);
  486. outputTextEditor->setFont(Font(String("Courier New"), 15, 1));
  487. repaint();
  488. }
  489. showOutput=!showOutput;
  490. */
  491. }
  492. void CodeWindow::setEditorColourScheme(String theme){
  493. setColourScheme(theme);
  494. }
  495. void CodeWindow::actionListenerCallback(const String &message){
  496. Logger::writeToLog(message);
  497. if(message=="splash")
  498. toggleTextWindows();
  499. //else if(message=="pythonFocus")
  500. // pythonEditor->textEditor->grabKeyboardFocus();
  501. else if(message=="make popup invisible"){
  502. popupDisplay->setTopLeftPosition(1000, 1000);
  503. popupDisplay->setVisible(false);
  504. }
  505. else if(message=="sendPythonEvent"){
  506. /* String text = pythonEditor->textEditor->getSelectedText();
  507. String event = "pyruni {{\n";
  508. if(text.length()>0)
  509. event << text;
  510. event << "\n}}";
  511. Logger::writeToLog(event);
  512. // csound->CompileOrc(event.toUTF8());
  513. this->grabKeyboardFocus();
  514. */
  515. }
  516. else if(message=="return focus to editor"){
  517. textEditor->grabKeyboardFocus();
  518. }
  519. else if(message.contains("popupDisplay")){
  520. int width = (font.getStringWidth(textEditor->getOpcodeToken(2)) > font.getStringWidth(textEditor->getOpcodeToken(3)) ?
  521. font.getStringWidth(textEditor->getOpcodeToken(2)) :
  522. font.getStringWidth(textEditor->getOpcodeToken(3)));
  523. //popupDisplay->killSplash();
  524. popupDisplay->setSize(width, 50);
  525. popupDisplay->box->setSize(width, 50);
  526. popupDisplay->setVisible(true);
  527. popupDisplay->setAlwaysOnTop(true);
  528. popupDisplay->addToDesktop(0);
  529. popupDisplay->setTopLeftPosition(this->getCaretScreenPosition().getTopLeft());
  530. //popupDisplay->setBounds(this->getCaretScreenPosition().getX(),
  531. // this->getCaretScreenPosition().getY()+18.f,
  532. // width, 50);
  533. //popupDisplay->setWantsKeyboardFocus(false);
  534. popupDisplay->setText(textEditor->getOpcodeToken(2).removeCharacters("\""),
  535. textEditor->getOpcodeToken(3).removeCharacters("\""));
  536. textEditor->toFront(true);
  537. //cabbageTimer->startTimedEvent(1, "return focus to editor");
  538. textEditor->grabKeyboardFocus();
  539. }
  540. }
  541. void CodeWindow::timerCallback(){
  542. // if(showOutput){
  543. // outputTextEditor->setText(csoundOutputText);
  544. // outputTextEditor->setCaretPosition(outputTextEditor->getText().length());
  545. // }
  546. }
  547. void CodeWindow::insertFromRepo(){
  548. int repoIndex = 1;
  549. PopupMenu m;
  550. StringArray repoEntries;
  551. m.setLookAndFeel(&this->getLookAndFeel());
  552. ScopedPointer<XmlElement> xmlElement;
  553. xmlElement = appProperties->getUserSettings()->getXmlValue("CopeRepoXmlData");
  554. forEachXmlChildElement (*xmlElement, e)
  555. {
  556. m.addItem(repoIndex, e->getTagName());
  557. repoEntries.add(e->getTagName());
  558. repoIndex++;
  559. }
  560. const int result = m.showAt(getCaretScreenPosition());
  561. forEachXmlChildElement (*xmlElement, e)
  562. {
  563. if(e->getTagName()==repoEntries[result-1])
  564. textEditor->insertText(e->getAllSubText());
  565. }
  566. xmlElement = nullptr;
  567. }
  568. //===============================================================================
  569. void CodeWindow::newFile(String type)
  570. {
  571. String untitledCSD;
  572. if(type=="effect"){
  573. untitledCSD=
  574. "<Cabbage>\n"
  575. "form size(400, 300), caption(\"Untitled\"), pluginID(\"plu1\")\n"
  576. "\n"
  577. "</Cabbage>\n"
  578. "<CsoundSynthesizer>\n"
  579. "<CsOptions>\n"
  580. "-n -d\n"
  581. "</CsOptions>\n"
  582. "<CsInstruments>\n"
  583. "sr = 44100\n"
  584. "ksmps = 64\n"
  585. "nchnls = 2\n"
  586. "0dbfs=1\n"
  587. "\n"
  588. "instr 1\n"
  589. "a1 inch 1\n"
  590. "a2 inch 2\n"
  591. "\n"
  592. "\n"
  593. ";outs a1, a2\n"
  594. "endin\n"
  595. "\n"
  596. "</CsInstruments> \n"
  597. "<CsScore>\n"
  598. "f1 0 1024 10 1\n"
  599. "i1 0 3600\n"
  600. "</CsScore>\n"
  601. "</CsoundSynthesizer>";
  602. }
  603. else if(type=="instrument")
  604. {
  605. untitledCSD=
  606. "<Cabbage>\n"
  607. "form size(400, 300), caption(\"Untitled\"), pluginID(\"plu1\")\n"
  608. "keyboard bounds(10, 200, 360, 100)\n"
  609. "\n"
  610. "</Cabbage>\n"
  611. "<CsoundSynthesizer>\n"
  612. "<CsOptions>\n"
  613. "-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5\n"
  614. "</CsOptions>\n"
  615. "<CsInstruments>\n"
  616. "sr = 44100\n"
  617. "ksmps = 64\n"
  618. "nchnls = 2\n"
  619. "0dbfs=1\n"
  620. "\n"
  621. "instr 1\n"
  622. "a1 oscili p5, p4, 1\n"
  623. "outs a1, a1"
  624. "\n"
  625. "endin\n"
  626. "\n"
  627. "</CsInstruments> \n"
  628. "<CsScore>\n"
  629. "f1 0 1024 10 1\n"
  630. "f0 3600\n"
  631. "</CsScore>\n"
  632. "</CsoundSynthesizer>";
  633. }
  634. csoundDoc.replaceAllContent(untitledCSD);
  635. unSaved = true;
  636. sendActionMessage("fileSavedAs");
  637. }