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.

99 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-12 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 "../JuceDemoHeader.h"
  19. //==============================================================================
  20. class CodeEditorDemo : public Component,
  21. private FilenameComponentListener
  22. {
  23. public:
  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. setOpaque (true);
  30. // Create the editor..
  31. addAndMakeVisible (editor = new CodeEditorComponent (codeDocument, &cppTokeniser));
  32. editor->loadContent ("\n"
  33. "/* Code editor demo!\n"
  34. "\n"
  35. " To see a real-world example of the code editor\n"
  36. " in action, try the Introjucer!\n"
  37. "\n"
  38. "*/\n"
  39. "\n");
  40. // Create a file chooser control to load files into it..
  41. addAndMakeVisible (fileChooser);
  42. fileChooser.addListener (this);
  43. }
  44. ~CodeEditorDemo()
  45. {
  46. fileChooser.removeListener (this);
  47. }
  48. void paint (Graphics& g) override
  49. {
  50. g.fillAll (Colours::lightgrey);
  51. }
  52. void resized() override
  53. {
  54. Rectangle<int> r (getLocalBounds().reduced (8));
  55. fileChooser.setBounds (r.removeFromTop (25));
  56. editor->setBounds (r.withTrimmedTop (8));
  57. }
  58. private:
  59. // this is the document that the editor component is showing
  60. CodeDocument codeDocument;
  61. // this is a tokeniser to apply the C++ syntax highlighting
  62. CPlusPlusCodeTokeniser cppTokeniser;
  63. // the editor component
  64. ScopedPointer<CodeEditorComponent> editor;
  65. FilenameComponent fileChooser;
  66. void filenameComponentChanged (FilenameComponent*) override
  67. {
  68. editor->loadContent (fileChooser.getCurrentFile().loadFileAsString());
  69. }
  70. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CodeEditorDemo);
  71. };
  72. // This static object will register this demo type in a global list of demos..
  73. static JuceDemoType<CodeEditorDemo> demo ("10 Components: Code Editor");