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.1KB

  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! Please be gentle, this component is still an alpha version! */\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. }