diff --git a/src/dlangui/core/editable.d b/src/dlangui/core/editable.d index ff032a62..56640c38 100644 --- a/src/dlangui/core/editable.d +++ b/src/dlangui/core/editable.d @@ -404,6 +404,18 @@ alias TokenPropString = ubyte[]; interface SyntaxHighlighter { /// categorize characters in content by token types void updateHighlight(dstring[] lines, TokenPropString[] props, int changeStartLine, int changeEndLine); + /// return true if toggle line comment is supported for file type + @property bool supportsToggleLineComment(); + /// return true if can toggle line comments for specified text range + bool canToggleLineComment(EditableContent content, TextRange range); + /// toggle line comments for specified text range + void toggleLineComment(EditableContent content, TextRange range, Object source); + /// return true if toggle block comment is supported for file type + @property bool supportsToggleBlockComment(); + /// return true if can toggle block comments for specified text range + bool canToggleBlockComment(EditableContent content, TextRange range); + /// toggle block comments for specified text range + void toggleBlockComment(EditableContent content, TextRange range, Object source); } /// editable plain text (singleline/multiline) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index e2baecab..684e5bf0 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -907,13 +907,27 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction /// override to handle specific actions state (e.g. change enabled state for supported actions) override bool handleActionStateRequest(const Action a) { switch (a.id) { + case EditorActions.ToggleBlockComment: + if (!_content.syntaxHighlighter || !_content.syntaxHighlighter.supportsToggleBlockComment) + a.state = ACTION_STATE_INVISIBLE; + else if (_content.syntaxHighlighter.canToggleBlockComment(_content, _selectionRange)) + a.state = ACTION_STATE_ENABLED; + else + a.state = ACTION_STATE_DISABLE; + return true; + case EditorActions.ToggleLineComment: + if (!_content.syntaxHighlighter || !_content.syntaxHighlighter.supportsToggleLineComment) + a.state = ACTION_STATE_INVISIBLE; + else if (_content.syntaxHighlighter.canToggleLineComment(_content, _selectionRange)) + a.state = ACTION_STATE_ENABLED; + else + a.state = ACTION_STATE_DISABLE; + return true; case EditorActions.Copy: case EditorActions.Cut: case EditorActions.Paste: case EditorActions.Undo: case EditorActions.Redo: - case EditorActions.ToggleBlockComment: - case EditorActions.ToggleLineComment: case EditorActions.Tab: case EditorActions.BackTab: case EditorActions.Indent: @@ -2024,12 +2038,14 @@ class EditBox : EditWidgetBase { } } return true; - case EditorActions.ToggleLineComment: - // TODO - return true; case EditorActions.ToggleBlockComment: - // TODO - return true; + if (_content.syntaxHighlighter && _content.syntaxHighlighter.supportsToggleBlockComment && _content.syntaxHighlighter.canToggleBlockComment(_content, _selectionRange)) + _content.syntaxHighlighter.toggleBlockComment(_content, _selectionRange, this); + return true; + case EditorActions.ToggleLineComment: + if (_content.syntaxHighlighter && _content.syntaxHighlighter.supportsToggleLineComment && _content.syntaxHighlighter.canToggleLineComment(_content, _selectionRange)) + _content.syntaxHighlighter.toggleLineComment(_content, _selectionRange, this); + return true; case EditorActions.InsertLine: { correctCaretPos();