From dd4560b79e305772debf48cc76c9ba67af61f259 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 8 Jan 2018 19:00:50 +0200 Subject: Added code comments for: SharedUI. --- .../Controls/ScriptEditorControl.xaml.cs | 243 +++++++++++++++------ 1 file changed, 172 insertions(+), 71 deletions(-) (limited to 'Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs') diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs index 7e643ef4b..1ad568aed 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs @@ -26,60 +26,107 @@ using Tango.SharedUI.Helpers; namespace Tango.SharedUI.Controls { - #region Completion - - internal class CompletionData : ICompletionData + /// + /// Represents a C# script editor control. + /// + /// + /// + public partial class ScriptEditorControl : UserControl { - private String _description; - - public BitmapSource Source { get; set; } + #region Completion - public CompletionData(string text, String description) + /// + /// Represents an auto complete item. + /// + /// + internal class CompletionData : ICompletionData { - this.Text = text; - _description = description; - } + private String _description; + + /// + /// Gets or sets the icon source. + /// + public BitmapSource Source { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The text. + /// The description. + public CompletionData(string text, String description) + { + this.Text = text; + _description = description; + } - public System.Windows.Media.ImageSource Image - { - get { return Source; } - } + /// + /// Gets the image. + /// + public System.Windows.Media.ImageSource Image + { + get { return Source; } + } - public string Text { get; private set; } + /// + /// Gets the text. This property is used to filter the list of visible elements. + /// + public string Text { get; private set; } - // Use this property if you want to show a fancy UIElement in the drop down list. - public object Content - { - get { return this.Text; } - } + // Use this property if you want to show a fancy UIElement in the drop down list. + public object Content + { + get { return this.Text; } + } - public object Description - { - get { return _description; } - } + /// + /// Gets the description. + /// + public object Description + { + get { return _description; } + } - public double Priority { get { return 0; } } + /// + /// Gets the priority. This property is used in the selection logic. You can use it to prefer selecting those items + /// which the user is accessing most frequently. + /// + public double Priority { get { return 0; } } + + /// + /// Perform the completion. + /// + /// The text area on which completion is performed. + /// The text segment that was used by the completion window if + /// the user types (segment between CompletionWindow.StartOffset and CompletionWindow.EndOffset). + /// The EventArgs used for the insertion request. + /// These can be TextCompositionEventArgs, KeyEventArgs, MouseEventArgs, depending on how + /// the insertion was triggered. + public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) + { + textArea.Document.Replace(completionSegment, this.Text); + } - public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs) - { - textArea.Document.Replace(completionSegment, this.Text); + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return Text; + } } - public override string ToString() - { - return Text; - } - } + #endregion - #endregion + private CompletionWindow completionWindow; //Holds the auto-complete window instance. - /// - /// Interaction logic for ScriptEditorControl.xaml - /// - public partial class ScriptEditorControl : UserControl - { - private CompletionWindow completionWindow; + #region Constructors + /// + /// Initializes a new instance of the class. + /// public ScriptEditorControl() { InitializeComponent(); @@ -89,6 +136,15 @@ namespace Tango.SharedUI.Controls textEditor.TextArea.TextEntered += textEditor_TextArea_TextEntered; } + #endregion + + #region Event Handlers + + /// + /// Handles the TextEntered event of the textEditor_TextArea control. + /// + /// The source of the event. + /// The instance containing the event data. private void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e) { if (e.Text == ".") @@ -146,6 +202,11 @@ namespace Tango.SharedUI.Controls } } + /// + /// Handles the TextEntering event of the textEditor_TextArea control. + /// + /// The source of the event. + /// The instance containing the event data. private void textEditor_TextArea_TextEntering(object sender, TextCompositionEventArgs e) { if (e.Text.Length > 0 && completionWindow != null) @@ -159,6 +220,25 @@ namespace Tango.SharedUI.Controls } } + /// + /// Handles the TextChanged event of the textEditor control. + /// + /// The source of the event. + /// The instance containing the event data. + private void textEditor_TextChanged(object sender, EventArgs e) + { + Text = textEditor.Text; + } + + #endregion + + #region Private Methods + + /// + /// Fills the type. + /// + /// The type. + /// The data. private void FillType(Type type, IList data) { List items = new List(); @@ -189,6 +269,11 @@ namespace Tango.SharedUI.Controls } } + /// + /// Fills the assembly. + /// + /// The asm. + /// The data. private void FillAssembly(Assembly asm, IList data) { var q = from t in asm.GetTypes() @@ -201,10 +286,13 @@ namespace Tango.SharedUI.Controls } } - #region Properties - + #endregion + #region Properties + /// + /// Gets or sets the text. + /// public String Text { get { return (String)GetValue(TextProperty); } @@ -213,16 +301,9 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(String), typeof(ScriptEditorControl), new PropertyMetadata(null, (d, e) => (d as ScriptEditorControl).OnTextChanged())); - private void OnTextChanged() - { - if (textEditor.Text != Text) - { - textEditor.Text = Text; - } - } - - - + /// + /// Gets or sets the highlight types. + /// public ObservableCollection> HighlightTypes { get { return (ObservableCollection>)GetValue(HighlightTypesProperty); } @@ -231,12 +312,42 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty HighlightTypesProperty = DependencyProperty.Register("HighlightTypes", typeof(ObservableCollection>), typeof(ScriptEditorControl), new PropertyMetadata(null)); + #endregion + #region Virtual Methods + + /// + /// Called when the text has changed. + /// + protected virtual void OnTextChanged() + { + if (textEditor.Text != Text) + { + textEditor.Text = Text; + } + } + + /// + /// Called when the insert script command has changed. + /// + protected virtual void OnInsertScriptCommandChanged() + { + if (InsertSnippetCommand != null) + { + InsertSnippetCommand.Executed += (x, snippet) => + { + textEditor.Document.Insert(textEditor.TextArea.Caret.Offset, snippet); + }; + } + } #endregion #region Commands + /// + /// Gets or sets the run command. + /// public RelayCommand RunCommand { get { return (RelayCommand)GetValue(RunCommandProperty); } @@ -245,6 +356,9 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty RunCommandProperty = DependencyProperty.Register("RunCommand", typeof(RelayCommand), typeof(ScriptEditorControl), new PropertyMetadata(null)); + /// + /// Gets or sets the stop command. + /// public RelayCommand StopCommand { get { return (RelayCommand)GetValue(StopCommandProperty); } @@ -253,6 +367,9 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty StopCommandProperty = DependencyProperty.Register("StopCommand", typeof(RelayCommand), typeof(ScriptEditorControl), new PropertyMetadata(null)); + /// + /// Gets or sets the save command. + /// public RelayCommand SaveCommand { get { return (RelayCommand)GetValue(SaveCommandProperty); } @@ -261,8 +378,9 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty SaveCommandProperty = DependencyProperty.Register("SaveCommand", typeof(RelayCommand), typeof(ScriptEditorControl), new PropertyMetadata(null)); - - + /// + /// Gets or sets the insert snippet command. + /// public RelayCommand InsertSnippetCommand { get { return (RelayCommand)GetValue(InsertSnippetCommandProperty); } @@ -271,24 +389,7 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty InsertSnippetCommandProperty = DependencyProperty.Register("InsertSnippetCommand", typeof(RelayCommand), typeof(ScriptEditorControl), new PropertyMetadata(null,(d,e) => (d as ScriptEditorControl).OnInsertScriptCommandChanged())); - private void OnInsertScriptCommandChanged() - { - if (InsertSnippetCommand != null) - { - InsertSnippetCommand.Executed += (x, snippet) => - { - textEditor.Document.Insert(textEditor.TextArea.Caret.Offset, snippet); - }; - } - } - - #endregion - - private void textEditor_TextChanged(object sender, EventArgs e) - { - Text = textEditor.Text; - } } internal static class DocumentUtils -- cgit v1.3.1