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.

97 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../jucedemo_headers.h"
  19. //==============================================================================
  20. class CodeEditorDemo : public Component,
  21. public FilenameComponentListener
  22. {
  23. public:
  24. //==============================================================================
  25. CodeEditorDemo()
  26. {
  27. setName ("Code Editor");
  28. setOpaque (true);
  29. // Create the editor..
  30. addAndMakeVisible (editor = new CodeEditorComponent (codeDocument, &cppTokeniser));
  31. // Create a file chooser control to load files into it..
  32. addAndMakeVisible (fileChooser = new FilenameComponent ("File", File::nonexistent, true, false, false,
  33. "*.cpp;*.h;*.hpp;*.c;*.mm;*.m", String::empty,
  34. "Choose a C++ file to open it in the editor"));
  35. fileChooser->addListener (this);
  36. editor->loadContent ("\n\n/* Code editor demo! Please be gentle, this component is still an alpha version! */\n\n");
  37. }
  38. ~CodeEditorDemo()
  39. {
  40. deleteAllChildren();
  41. }
  42. void filenameComponentChanged (FilenameComponent* fileComponentThatHasChanged)
  43. {
  44. File f (fileChooser->getCurrentFile());
  45. editor->loadContent (f.loadFileAsString());
  46. }
  47. void paint (Graphics& g)
  48. {
  49. g.fillAll (Colours::lightgrey);
  50. }
  51. void resized()
  52. {
  53. editor->setBounds (10, 45, getWidth() - 20, getHeight() - 55);
  54. fileChooser->setBounds (10, 10, getWidth() - 20, 25);
  55. }
  56. //==============================================================================
  57. juce_UseDebuggingNewOperator
  58. private:
  59. // this is the document that the editor component is showing
  60. CodeDocument codeDocument;
  61. // this is a tokeniser to do the c++ syntax highlighting
  62. CPlusPlusCodeTokeniser cppTokeniser;
  63. // the editor component
  64. CodeEditorComponent* editor;
  65. FilenameComponent* fileChooser;
  66. };
  67. //==============================================================================
  68. Component* createCodeEditorDemo()
  69. {
  70. return new CodeEditorDemo();
  71. }