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.

93 lines
3.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucedemo_headers.h"
  18. //==============================================================================
  19. class CodeEditorDemo : public Component,
  20. public FilenameComponentListener
  21. {
  22. public:
  23. //==============================================================================
  24. CodeEditorDemo()
  25. : fileChooser ("File", File::nonexistent, true, false, false,
  26. "*.cpp;*.h;*.hpp;*.c;*.mm;*.m", String::empty,
  27. "Choose a C++ file to open it in the editor")
  28. {
  29. setName ("Code Editor");
  30. setOpaque (true);
  31. // Create the editor..
  32. addAndMakeVisible (editor = new CodeEditorComponent (codeDocument, &cppTokeniser));
  33. editor->loadContent ("\n\n/* Code editor demo! To see a real-world example of the "
  34. "code editor in action, try the Introjucer! */\n\n");
  35. // Create a file chooser control to load files into it..
  36. addAndMakeVisible (&fileChooser);
  37. fileChooser.addListener (this);
  38. }
  39. ~CodeEditorDemo()
  40. {
  41. }
  42. void filenameComponentChanged (FilenameComponent*)
  43. {
  44. editor->loadContent (fileChooser.getCurrentFile().loadFileAsString());
  45. }
  46. void paint (Graphics& g)
  47. {
  48. g.fillAll (Colours::lightgrey);
  49. }
  50. void resized()
  51. {
  52. editor->setBounds (10, 45, getWidth() - 20, getHeight() - 55);
  53. fileChooser.setBounds (10, 10, getWidth() - 20, 25);
  54. }
  55. private:
  56. // this is the document that the editor component is showing
  57. CodeDocument codeDocument;
  58. // this is a tokeniser to do the c++ syntax highlighting
  59. CPlusPlusCodeTokeniser cppTokeniser;
  60. // the editor component
  61. ScopedPointer<CodeEditorComponent> editor;
  62. FilenameComponent fileChooser;
  63. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CodeEditorDemo)
  64. };
  65. //==============================================================================
  66. Component* createCodeEditorDemo()
  67. {
  68. return new CodeEditorDemo();
  69. }