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.

94 lines
3.2KB

  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. : fileChooser ("File", File::nonexistent, true, false, false,
  27. "*.cpp;*.h;*.hpp;*.c;*.mm;*.m", String::empty,
  28. "Choose a C++ file to open it in the editor")
  29. {
  30. setName ("Code Editor");
  31. setOpaque (true);
  32. // Create the editor..
  33. addAndMakeVisible (editor = new CodeEditorComponent (codeDocument, &cppTokeniser));
  34. editor->loadContent ("\n\n/* Code editor demo! To see a real-world example of the "
  35. "code editor in action, try the Introjucer! */\n\n");
  36. // Create a file chooser control to load files into it..
  37. addAndMakeVisible (&fileChooser);
  38. fileChooser.addListener (this);
  39. }
  40. ~CodeEditorDemo()
  41. {
  42. }
  43. void filenameComponentChanged (FilenameComponent*)
  44. {
  45. editor->loadContent (fileChooser.getCurrentFile().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. private:
  57. // this is the document that the editor component is showing
  58. CodeDocument codeDocument;
  59. // this is a tokeniser to do the c++ syntax highlighting
  60. CPlusPlusCodeTokeniser cppTokeniser;
  61. // the editor component
  62. ScopedPointer<CodeEditorComponent> editor;
  63. FilenameComponent fileChooser;
  64. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CodeEditorDemo)
  65. };
  66. //==============================================================================
  67. Component* createCodeEditorDemo()
  68. {
  69. return new CodeEditorDemo();
  70. }