openshot-audio  0.1.7
Classes | Public Types | Public Member Functions | Friends | List of all members
CodeEditorComponent Class Reference

#include <juce_CodeEditorComponent.h>

Inheritance diagram for CodeEditorComponent:
TextInputTarget

Classes

class  CodeEditorLine
 
struct  ColourScheme
 
class  GutterComponent
 
class  Pimpl
 
struct  State
 

Public Types

enum  ColourIds {
  backgroundColourId = 0x1004500, highlightColourId = 0x1004502, defaultTextColourId = 0x1004503, lineNumberBackgroundId = 0x1004504,
  lineNumberTextId = 0x1004505
}
 
- Public Types inherited from TextInputTarget
enum  VirtualKeyboardType {
  textKeyboard = 0, numericKeyboard, decimalKeyboard, urlKeyboard,
  emailAddressKeyboard, phoneNumberKeyboard
}
 

Public Member Functions

 CodeEditorComponent (CodeDocument &document, CodeTokeniser *codeTokeniser)
 
 ~CodeEditorComponent ()
 
CodeDocumentgetDocument () const noexcept
 
void loadContent (const String &newContent)
 
float getCharWidth () const noexcept
 
int getLineHeight () const noexcept
 
int getNumLinesOnScreen () const noexcept
 
int getFirstLineOnScreen () const noexcept
 
int getNumColumnsOnScreen () const noexcept
 
CodeDocument::Position getCaretPos () const
 
Rectangle< intgetCaretRectangle () override
 
void moveCaretTo (const CodeDocument::Position &newPos, bool selecting)
 
Rectangle< intgetCharacterBounds (const CodeDocument::Position &pos) const
 
CodeDocument::Position getPositionAt (int x, int y)
 
CodeDocument::Position getSelectionStart () const
 
CodeDocument::Position getSelectionEnd () const
 
void setLineNumbersShown (bool shouldBeShown)
 
bool moveCaretLeft (bool moveInWholeWordSteps, bool selecting)
 
bool moveCaretRight (bool moveInWholeWordSteps, bool selecting)
 
bool moveCaretUp (bool selecting)
 
bool moveCaretDown (bool selecting)
 
bool scrollDown ()
 
bool scrollUp ()
 
bool pageUp (bool selecting)
 
bool pageDown (bool selecting)
 
bool moveCaretToTop (bool selecting)
 
bool moveCaretToStartOfLine (bool selecting)
 
bool moveCaretToEnd (bool selecting)
 
bool moveCaretToEndOfLine (bool selecting)
 
bool deleteBackwards (bool moveInWholeWordSteps)
 
bool deleteForwards (bool moveInWholeWordSteps)
 
bool deleteWhitespaceBackwardsToTabStop ()
 
virtual bool copyToClipboard ()
 
virtual bool cutToClipboard ()
 
virtual bool pasteFromClipboard ()
 
bool undo ()
 
bool redo ()
 
void selectRegion (const CodeDocument::Position &start, const CodeDocument::Position &end)
 
bool selectAll ()
 
void deselectAll ()
 
void scrollToLine (int newFirstLineOnScreen)
 
void scrollBy (int deltaLines)
 
void scrollToColumn (int newFirstColumnOnScreen)
 
void scrollToKeepCaretOnScreen ()
 
void scrollToKeepLinesOnScreen (Range< int > linesToShow)
 
void insertTextAtCaret (const String &textToInsert) override
 
void insertTabAtCaret ()
 
void indentSelection ()
 
void unindentSelection ()
 
Range< intgetHighlightedRegion () const override
 
bool isHighlightActive () const noexcept
 
void setHighlightedRegion (const Range< int > &newRange) override
 
String getTextInRange (const Range< int > &range) const override
 
void setTabSize (int numSpacesPerTab, bool insertSpacesInsteadOfTabCharacters)
 
int getTabSize () const noexcept
 
bool areSpacesInsertedForTabs () const
 
String getTabString (int numSpaces) const
 
void setFont (const Font &newFont)
 
const FontgetFont () const noexcept
 
void setReadOnly (bool shouldBeReadOnly) noexcept
 
bool isReadOnly () const noexcept
 
void setColourScheme (const ColourScheme &scheme)
 
const ColourSchemegetColourScheme () const noexcept
 
Colour getColourForTokenType (int tokenType) const
 
void setScrollbarThickness (int thickness)
 
int getScrollbarThickness () const noexcept
 
virtual void handleReturnKey ()
 
virtual void handleTabKey ()
 
virtual void handleEscapeKey ()
 
virtual void addPopupMenuItems (PopupMenu &menuToAddTo, const MouseEvent *mouseClickEvent)
 
virtual void performPopupMenuAction (int menuItemID)
 
void setCommandManager (ApplicationCommandManager *newManager) noexcept
 
void paint (Graphics &) override
 
void resized () override
 
bool keyPressed (const KeyPress &) override
 
void mouseDown (const MouseEvent &) override
 
void mouseDrag (const MouseEvent &) override
 
void mouseUp (const MouseEvent &) override
 
void mouseDoubleClick (const MouseEvent &) override
 
void mouseWheelMove (const MouseEvent &, const MouseWheelDetails &) override
 
void focusGained (FocusChangeType) override
 
void focusLost (FocusChangeType) override
 
bool isTextInputActive () const override
 
void setTemporaryUnderlining (const Array< Range< int > > &) override
 
ApplicationCommandTargetgetNextCommandTarget () override
 
void getAllCommands (Array< CommandID > &) override
 
void getCommandInfo (CommandID, ApplicationCommandInfo &) override
 
bool perform (const InvocationInfo &) override
 
- Public Member Functions inherited from TextInputTarget
 TextInputTarget ()
 
virtual ~TextInputTarget ()
 
virtual VirtualKeyboardType getKeyboardType ()
 

Friends

class Pimpl
 
struct ContainerDeletePolicy< Pimpl >
 
class GutterComponent
 
struct ContainerDeletePolicy< GutterComponent >
 

Detailed Description

A text editor component designed specifically for source code.

This is designed to handle syntax highlighting and fast editing of very large files.

Member Enumeration Documentation

A set of colour IDs to use to change the colour of various aspects of the editor.

These constants can be used either via the Component::setColour(), or LookAndFeel::setColour() methods.

See Also
Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
Enumerator
backgroundColourId 

A colour to use to fill the editor's background.

highlightColourId 

The colour to use for the highlighted background under selected text.

defaultTextColourId 

The colour to use for text when no syntax colouring is enabled.

lineNumberBackgroundId 

The colour to use for filling the background of the line-number gutter.

lineNumberTextId 

The colour to use for drawing the line numbers.

Constructor & Destructor Documentation

CodeEditorComponent::CodeEditorComponent ( CodeDocument document,
CodeTokeniser codeTokeniser 
)

Creates an editor for a document.

The tokeniser object is optional - pass nullptr to disable syntax highlighting. The object that you pass in is not owned or deleted by the editor - you must make sure that it doesn't get deleted while this component is still using it.

See Also
CodeDocument
CodeEditorComponent::~CodeEditorComponent ( )

Destructor.

Member Function Documentation

void CodeEditorComponent::addPopupMenuItems ( PopupMenu menuToAddTo,
const MouseEvent mouseClickEvent 
)
virtual

This adds the items to the popup menu.

By default it adds the cut/copy/paste items, but you can override this if you need to replace these with your own items.

If you want to add your own items to the existing ones, you can override this, call the base class's addPopupMenuItems() method, then append your own items.

When the menu has been shown, performPopupMenuAction() will be called to perform the item that the user has chosen.

If this was triggered by a mouse-click, the mouseClickEvent parameter will be a pointer to the info about it, or may be null if the menu is being triggered by some other means.

See Also
performPopupMenuAction, setPopupMenuEnabled, isPopupMenuEnabled
bool CodeEditorComponent::areSpacesInsertedForTabs ( ) const
inline

Returns true if the tab key will insert spaces instead of actual tab characters.

See Also
setTabSize
bool CodeEditorComponent::copyToClipboard ( )
virtual
bool CodeEditorComponent::cutToClipboard ( )
virtual
bool CodeEditorComponent::deleteBackwards ( bool  moveInWholeWordSteps)
bool CodeEditorComponent::deleteForwards ( bool  moveInWholeWordSteps)
bool CodeEditorComponent::deleteWhitespaceBackwardsToTabStop ( )
void CodeEditorComponent::deselectAll ( )
void CodeEditorComponent::focusGained ( FocusChangeType  )
override
void CodeEditorComponent::focusLost ( FocusChangeType  )
override
void CodeEditorComponent::getAllCommands ( Array< CommandID > &  commands)
override
CodeDocument::Position CodeEditorComponent::getCaretPos ( ) const
inline

Returns the current caret position.

Rectangle< int > CodeEditorComponent::getCaretRectangle ( )
overridevirtual

Returns the position of the caret, relative to the editor's origin.

Implements TextInputTarget.

Rectangle< int > CodeEditorComponent::getCharacterBounds ( const CodeDocument::Position pos) const

Returns the on-screen position of a character in the document. The rectangle returned is relative to this component's top-left origin.

float CodeEditorComponent::getCharWidth ( ) const
inlinenoexcept

Returns the standard character width.

Colour CodeEditorComponent::getColourForTokenType ( int  tokenType) const

Returns one the syntax highlighting colour for the given token. The token type values are dependent on the tokeniser being used.

See Also
setColourScheme
const ColourScheme& CodeEditorComponent::getColourScheme ( ) const
inlinenoexcept

Returns the current syntax highlighting colour scheme.

void CodeEditorComponent::getCommandInfo ( CommandID  commandID,
ApplicationCommandInfo result 
)
override
CodeDocument& CodeEditorComponent::getDocument ( ) const
inlinenoexcept

Returns the code document that this component is editing.

int CodeEditorComponent::getFirstLineOnScreen ( ) const
inlinenoexcept

Returns the index of the first line that's visible at the top of the editor.

const Font& CodeEditorComponent::getFont ( ) const
inlinenoexcept

Returns the font that the editor is using.

Range< int > CodeEditorComponent::getHighlightedRegion ( ) const
overridevirtual

Returns the extents of the selected text region, or an empty range if nothing is selected,

Implements TextInputTarget.

int CodeEditorComponent::getLineHeight ( ) const
inlinenoexcept

Returns the height of a line of text, in pixels.

ApplicationCommandTarget * CodeEditorComponent::getNextCommandTarget ( )
override
int CodeEditorComponent::getNumColumnsOnScreen ( ) const
inlinenoexcept

Returns the number of whole columns visible on the screen. This doesn't include any cut-off columns at the right-hand edge.

int CodeEditorComponent::getNumLinesOnScreen ( ) const
inlinenoexcept

Returns the number of whole lines visible on the screen, This doesn't include a cut-off line that might be visible at the bottom if the component's height isn't an exact multiple of the line-height.

CodeDocument::Position CodeEditorComponent::getPositionAt ( int  x,
int  y 
)

Finds the character at a given on-screen position. The coordinates are relative to this component's top-left origin.

int CodeEditorComponent::getScrollbarThickness ( ) const
inlinenoexcept

Returns the thickness of the scrollbars.

CodeDocument::Position CodeEditorComponent::getSelectionEnd ( ) const
inline

Returns the end of the selection as a position.

CodeDocument::Position CodeEditorComponent::getSelectionStart ( ) const
inline

Returns the start of the selection as a position.

int CodeEditorComponent::getTabSize ( ) const
inlinenoexcept

Returns the current number of spaces per tab.

See Also
setTabSize
String CodeEditorComponent::getTabString ( int  numSpaces) const

Returns a string containing spaces or tab characters to generate the given number of spaces.

String CodeEditorComponent::getTextInRange ( const Range< int > &  range) const
overridevirtual

Returns a specified sub-section of the text.

Implements TextInputTarget.

void CodeEditorComponent::handleEscapeKey ( )
virtual

Called when the escape key is pressed - this can be overridden for custom behaviour.

void CodeEditorComponent::handleReturnKey ( )
virtual

Called when the return key is pressed - this can be overridden for custom behaviour.

void CodeEditorComponent::handleTabKey ( )
virtual

Called when the tab key is pressed - this can be overridden for custom behaviour.

void CodeEditorComponent::indentSelection ( )
void CodeEditorComponent::insertTabAtCaret ( )
void CodeEditorComponent::insertTextAtCaret ( const String textToInsert)
overridevirtual

Inserts some text, overwriting the selected text region, if there is one.

Implements TextInputTarget.

bool CodeEditorComponent::isHighlightActive ( ) const
noexcept
bool CodeEditorComponent::isReadOnly ( ) const
inlinenoexcept

Returns true if the editor is set to be read-only.

bool CodeEditorComponent::isTextInputActive ( ) const
overridevirtual

Returns true if this input target is currently accepting input. For example, a text editor might return false if it's in read-only mode.

Implements TextInputTarget.

bool CodeEditorComponent::keyPressed ( const KeyPress key)
override
void CodeEditorComponent::loadContent ( const String newContent)

Loads the given content into the document. This will completely reset the CodeDocument object, clear its undo history, and fill it with this text.

void CodeEditorComponent::mouseDoubleClick ( const MouseEvent e)
override
void CodeEditorComponent::mouseDown ( const MouseEvent e)
override
void CodeEditorComponent::mouseDrag ( const MouseEvent e)
override
void CodeEditorComponent::mouseUp ( const MouseEvent )
override
void CodeEditorComponent::mouseWheelMove ( const MouseEvent e,
const MouseWheelDetails wheel 
)
override
bool CodeEditorComponent::moveCaretDown ( bool  selecting)
bool CodeEditorComponent::moveCaretLeft ( bool  moveInWholeWordSteps,
bool  selecting 
)
bool CodeEditorComponent::moveCaretRight ( bool  moveInWholeWordSteps,
bool  selecting 
)
void CodeEditorComponent::moveCaretTo ( const CodeDocument::Position newPos,
bool  selecting 
)

Moves the caret. If selecting is true, the section of the document between the current caret position and the new one will become selected. If false, any currently selected region will be deselected.

bool CodeEditorComponent::moveCaretToEnd ( bool  selecting)
bool CodeEditorComponent::moveCaretToEndOfLine ( bool  selecting)
bool CodeEditorComponent::moveCaretToStartOfLine ( bool  selecting)
bool CodeEditorComponent::moveCaretToTop ( bool  selecting)
bool CodeEditorComponent::moveCaretUp ( bool  selecting)
bool CodeEditorComponent::pageDown ( bool  selecting)
bool CodeEditorComponent::pageUp ( bool  selecting)
void CodeEditorComponent::paint ( Graphics g)
override
bool CodeEditorComponent::pasteFromClipboard ( )
virtual
bool CodeEditorComponent::perform ( const InvocationInfo &  info)
override
void CodeEditorComponent::performPopupMenuAction ( int  menuItemID)
virtual

This is called to perform one of the items that was shown on the popup menu.

If you've overridden addPopupMenuItems(), you should also override this to perform the actions that you've added.

If you've overridden addPopupMenuItems() but have still left the default items on the menu, remember to call the superclass's performPopupMenuAction() so that it can perform the default actions if that's what the user clicked on.

See Also
addPopupMenuItems, setPopupMenuEnabled, isPopupMenuEnabled
bool CodeEditorComponent::redo ( )
void CodeEditorComponent::resized ( )
override
void CodeEditorComponent::scrollBy ( int  deltaLines)
bool CodeEditorComponent::scrollDown ( )
void CodeEditorComponent::scrollToColumn ( int  newFirstColumnOnScreen)
void CodeEditorComponent::scrollToKeepCaretOnScreen ( )
void CodeEditorComponent::scrollToKeepLinesOnScreen ( Range< int linesToShow)
void CodeEditorComponent::scrollToLine ( int  newFirstLineOnScreen)
bool CodeEditorComponent::scrollUp ( )
bool CodeEditorComponent::selectAll ( )
void CodeEditorComponent::selectRegion ( const CodeDocument::Position start,
const CodeDocument::Position end 
)
void CodeEditorComponent::setColourScheme ( const ColourScheme scheme)

Changes the syntax highlighting scheme. The token type values are dependent on the tokeniser being used - use CodeTokeniser::getTokenTypes() to get a list of the token types.

See Also
getColourForTokenType
void CodeEditorComponent::setCommandManager ( ApplicationCommandManager newManager)
noexcept

Specifies a commmand-manager which the editor will notify whenever the state of any of its commands changes. If you're making use of the editor's ApplicationCommandTarget interface, then you should also use this to tell it which command manager it should use. Make sure that the manager does not go out of scope while the editor is using it. You can pass a nullptr here to disable this.

void CodeEditorComponent::setFont ( const Font newFont)

Changes the font. Make sure you only use a fixed-width font, or this component will look pretty nasty!

void CodeEditorComponent::setHighlightedRegion ( const Range< int > &  newRange)
overridevirtual

Sets the currently-selected text region.

Implements TextInputTarget.

void CodeEditorComponent::setLineNumbersShown ( bool  shouldBeShown)

Enables or disables the line-number display in the gutter.

void CodeEditorComponent::setReadOnly ( bool  shouldBeReadOnly)
noexcept

Makes the editor read-only.

void CodeEditorComponent::setScrollbarThickness ( int  thickness)

Changes the size of the scrollbars.

void CodeEditorComponent::setTabSize ( int  numSpacesPerTab,
bool  insertSpacesInsteadOfTabCharacters 
)

Changes the current tab settings. This lets you change the tab size and whether pressing the tab key inserts a tab character, or its equivalent number of spaces.

void CodeEditorComponent::setTemporaryUnderlining ( const Array< Range< int > > &  underlinedRegions)
overridevirtual

Sets a number of temporarily underlined sections. This is needed by MS Windows input method UI.

Implements TextInputTarget.

bool CodeEditorComponent::undo ( )
void CodeEditorComponent::unindentSelection ( )

Friends And Related Function Documentation

friend struct ContainerDeletePolicy< GutterComponent >
friend
friend struct ContainerDeletePolicy< Pimpl >
friend
friend class GutterComponent
friend
friend class Pimpl
friend

The documentation for this class was generated from the following files: