aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-02-17 01:49:14 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-02-17 01:49:14 +0200
commite2a5664b9425953e33b39c21dab8d5c24adfa78f (patch)
treefd2ba7df2f8f52706aaa8183e5cf1c5dc5c8cc03 /Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion
parent497c38292a1dda9b873f12336b5bbbe4a33c74d6 (diff)
downloadTango-e2a5664b9425953e33b39c21dab8d5c24adfa78f.tar.gz
Tango-e2a5664b9425953e33b39c21dab8d5c24adfa78f.zip
Some work on scripting engine...
Diffstat (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion')
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionList.cs2
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBox.cs11
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs59
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs87
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs96
5 files changed, 159 insertions, 96 deletions
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionList.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionList.cs
index a50b82463..ea6e1856f 100644
--- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionList.cs
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionList.cs
@@ -218,7 +218,7 @@ namespace Tango.Scripting.Editors.CodeCompletion
/// <summary>
/// Filters CompletionList items to show only those matching given query, and selects the best match.
/// </summary>
- void SelectItemFiltering(string query)
+ public void SelectItemFiltering(string query)
{
// if the user just typed one more character, don't filter all data but just filter what we are already displaying
var listToFilter = (this.currentList != null && (!string.IsNullOrEmpty(this.currentText)) && (!string.IsNullOrEmpty(query)) &&
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBox.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBox.cs
index f515c955c..235c07304 100644
--- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBox.cs
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBox.cs
@@ -26,7 +26,9 @@ namespace Tango.Scripting.Editors.CodeCompletion
Border border = this.GetVisualChild(0) as Border;
if (border != null)
scrollViewer = border.Child as ScrollViewer;
- }
+ scrollViewer.BorderThickness = new Thickness(0);
+
+ }
}
/// <summary>
@@ -92,5 +94,10 @@ namespace Tango.Scripting.Editors.CodeCompletion
{
this.FirstVisibleItem = index - VisibleItemCount / 2;
}
- }
+
+ protected override DependencyObject GetContainerForItemOverride()
+ {
+ return new CompletionListBoxItem();
+ }
+ }
}
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs
new file mode 100644
index 000000000..bb6acf69e
--- /dev/null
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionListBoxItem.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace Tango.Scripting.Editors.CodeCompletion
+{
+ public class CompletionListBoxItem : ListBoxItem
+ {
+ public ToolTip toolTip;
+
+ public DataTemplate ToolTipContentTemplate
+ {
+ get { return (DataTemplate)GetValue(ToolTipContentTemplateProperty); }
+ set { SetValue(ToolTipContentTemplateProperty, value); }
+ }
+ public static readonly DependencyProperty ToolTipContentTemplateProperty =
+ DependencyProperty.Register("ToolTipContentTemplate", typeof(DataTemplate), typeof(CompletionListBoxItem), new PropertyMetadata(null));
+
+ public CompletionListBoxItem()
+ {
+ toolTip = new ToolTip();
+ toolTip.PlacementTarget = this;
+ toolTip.HorizontalOffset = 15;
+ toolTip.Background = Brushes.Transparent;
+ toolTip.BorderThickness = new Thickness(0);
+ toolTip.Opacity = 1;
+ toolTip.HasDropShadow = true;
+ toolTip.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
+ this.Unloaded += CompletionListBoxItem_Unloaded;
+ }
+
+ private void CompletionListBoxItem_Unloaded(object sender, RoutedEventArgs e)
+ {
+ toolTip.StaysOpen = false;
+ toolTip.IsOpen = false;
+ }
+
+ protected override void OnSelected(RoutedEventArgs e)
+ {
+ base.OnSelected(e);
+ toolTip.Content = DataContext;
+ toolTip.ContentTemplate = ToolTipContentTemplate;
+ toolTip.StaysOpen = true;
+ toolTip.IsOpen = true;
+ }
+
+ protected override void OnUnselected(RoutedEventArgs e)
+ {
+ base.OnUnselected(e);
+ toolTip.StaysOpen = false;
+ toolTip.IsOpen = false;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs
index 44621df72..0e8cd781d 100644
--- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindow.cs
@@ -21,7 +21,8 @@ namespace Tango.Scripting.Editors.CodeCompletion
public class CompletionWindow : CompletionWindowBase
{
readonly CompletionList completionList = new CompletionList();
- ToolTip toolTip = new ToolTip();
+
+ public event Action<ICompletionData> InsertionRequest;
/// <summary>
/// Gets the completion list used in this completion window.
@@ -36,79 +37,58 @@ namespace Tango.Scripting.Editors.CodeCompletion
/// </summary>
public CompletionWindow(TextArea textArea) : base(textArea)
{
+
// keep height automatic
this.CloseAutomatically = true;
- this.SizeToContent = SizeToContent.Height;
- this.MaxHeight = 300;
- this.Width = 175;
+ this.SizeToContent = SizeToContent.WidthAndHeight;
+ this.WindowStyle = WindowStyle.None;
+ this.ResizeMode = ResizeMode.NoResize;
this.Content = completionList;
// prevent user from resizing window to 0x0
this.MinHeight = 15;
this.MinWidth = 30;
//this.Background = new SolidColorBrush(Color.FromRgb(15, 15, 15));
this.Foreground = Brushes.Gainsboro;
-
- toolTip.PlacementTarget = this;
- toolTip.Placement = PlacementMode.Right;
- toolTip.Closed += toolTip_Closed;
-
- AttachEvents();
}
- #region ToolTip handling
- void toolTip_Closed(object sender, RoutedEventArgs e)
+ public override void ShowCompletion()
{
- // Clear content after tooltip is closed.
- // We cannot clear is immediately when setting IsOpen=false
- // because the tooltip uses an animation for closing.
- if (toolTip != null)
- toolTip.Content = null;
+ base.ShowCompletion();
+ AttachEvents();
}
- void completionList_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ public override void HideCompletion()
{
- var item = completionList.SelectedItem;
- if (item == null)
- return;
- object description = item.Description;
- if (description != null)
+ base.HideCompletion();
+
+ foreach (var item in completionList.ListBox.Items)
{
- string descriptionText = description as string;
- if (descriptionText != null)
+ var box = completionList.ListBox.ItemContainerGenerator.ContainerFromItem(item) as CompletionListBoxItem;
+ if (box != null && box.IsSelected)
{
- toolTip.Content = new TextBlock
- {
- Text = descriptionText,
- TextWrapping = TextWrapping.Wrap
- };
+ box.toolTip.IsOpen = false;
}
- else
- {
- toolTip.Content = description;
- }
- toolTip.IsOpen = true;
- }
- else
- {
- toolTip.IsOpen = false;
}
}
- #endregion
void completionList_InsertionRequested(object sender, EventArgs e)
{
- Close();
+ HideCompletion();
// The window must close before Complete() is called.
// If the Complete callback pushes stacked input handlers, we don't want to pop those when the CC window closes.
var item = completionList.SelectedItem;
+ //if (item != null)
+ // item.Complete(this.TextArea, new AnchorSegment(this.TextArea.Document, this.StartOffset, this.EndOffset - this.StartOffset), e);
+
if (item != null)
- item.Complete(this.TextArea, new AnchorSegment(this.TextArea.Document, this.StartOffset, this.EndOffset - this.StartOffset), e);
+ {
+ InsertionRequest?.Invoke(item);
+ }
}
void AttachEvents()
{
this.completionList.InsertionRequested += completionList_InsertionRequested;
- this.completionList.SelectionChanged += completionList_SelectionChanged;
this.TextArea.Caret.PositionChanged += CaretPositionChanged;
this.TextArea.MouseWheel += textArea_MouseWheel;
this.TextArea.PreviewTextInput += textArea_PreviewTextInput;
@@ -118,7 +98,6 @@ namespace Tango.Scripting.Editors.CodeCompletion
protected override void DetachEvents()
{
this.completionList.InsertionRequested -= completionList_InsertionRequested;
- this.completionList.SelectionChanged -= completionList_SelectionChanged;
this.TextArea.Caret.PositionChanged -= CaretPositionChanged;
this.TextArea.MouseWheel -= textArea_MouseWheel;
this.TextArea.PreviewTextInput -= textArea_PreviewTextInput;
@@ -126,17 +105,6 @@ namespace Tango.Scripting.Editors.CodeCompletion
}
/// <inheritdoc/>
- protected override void OnClosed(EventArgs e)
- {
- base.OnClosed(e);
- if (toolTip != null)
- {
- toolTip.IsOpen = false;
- toolTip = null;
- }
- }
-
- /// <inheritdoc/>
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
@@ -150,6 +118,11 @@ namespace Tango.Scripting.Editors.CodeCompletion
{
e.Handled = RaiseEventPair(this, PreviewTextInputEvent, TextInputEvent,
new TextCompositionEventArgs(e.Device, e.TextComposition));
+
+ if (e.Text == " ")
+ {
+ HideCompletion();
+ }
}
void textArea_MouseWheel(object sender, MouseWheelEventArgs e)
@@ -193,7 +166,7 @@ namespace Tango.Scripting.Editors.CodeCompletion
{
if (CloseAutomatically && CloseWhenCaretAtBeginning)
{
- Close();
+ HideCompletion();
}
else
{
@@ -205,7 +178,7 @@ namespace Tango.Scripting.Editors.CodeCompletion
{
if (CloseAutomatically)
{
- Close();
+ HideCompletion();
}
}
else
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs
index 40c611843..b5bab3f97 100644
--- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/CodeCompletion/CompletionWindowBase.cs
@@ -12,6 +12,7 @@ using Tango.Scripting.Editors.Document;
using Tango.Scripting.Editors.Editing;
using Tango.Scripting.Editors.Rendering;
using Tango.Scripting.Editors.Utils;
+using System.ComponentModel;
namespace Tango.Scripting.Editors.CodeCompletion
{
@@ -60,17 +61,31 @@ namespace Tango.Scripting.Editors.CodeCompletion
if (textArea == null)
throw new ArgumentNullException("textArea");
this.TextArea = textArea;
- parentWindow = Window.GetWindow(textArea);
- this.Owner = parentWindow;
- this.AddHandler(MouseUpEvent, new MouseButtonEventHandler(OnMouseUp), true);
-
- StartOffset = EndOffset = this.TextArea.Caret.Offset;
-
- AttachEvents();
- }
-
- #region Event Handlers
- void AttachEvents()
+
+ parentWindow = Window.GetWindow(TextArea);
+ this.Owner = parentWindow;
+ this.AddHandler(MouseUpEvent, new MouseButtonEventHandler(OnMouseUp), true);
+ }
+
+ public virtual void ShowCompletion()
+ {
+ StartOffset = EndOffset = this.TextArea.Caret.Offset;
+
+ AttachEvents();
+ SetPosition();
+ UpdatePosition();
+ Show();
+ }
+
+ public virtual void HideCompletion()
+ {
+ DetachEvents();
+ Hide();
+ }
+
+ #region Event Handlers
+
+ void AttachEvents()
{
document = this.TextArea.Document;
if (document != null) {
@@ -133,7 +148,7 @@ namespace Tango.Scripting.Editors.CodeCompletion
public override void Detach()
{
base.Detach();
- window.Close();
+ window.HideCompletion();
}
const Key KeyDeadCharProcessed = (Key)0xac; // Key.DeadCharProcessed; // new in .NET 4
@@ -166,17 +181,18 @@ namespace Tango.Scripting.Editors.CodeCompletion
IScrollInfo scrollInfo = this.TextArea.TextView;
Rect visibleRect = new Rect(scrollInfo.HorizontalOffset, scrollInfo.VerticalOffset, scrollInfo.ViewportWidth, scrollInfo.ViewportHeight);
- // close completion window when the user scrolls so far that the anchor position is leaving the visible area
- if (visibleRect.Contains(visualLocation) || visibleRect.Contains(visualLocationTop))
- UpdatePosition();
- else
- Close();
- }
+ // close completion window when the user scrolls so far that the anchor position is leaving the visible area
+ if (visibleRect.Contains(visualLocation) || visibleRect.Contains(visualLocationTop))
+ UpdatePosition();
+ else
+ HideCompletion();
+
+ }
void TextAreaDocumentChanged(object sender, EventArgs e)
{
- Close();
- }
+ HideCompletion();
+ }
void TextAreaLostFocus(object sender, RoutedEventArgs e)
{
@@ -242,8 +258,8 @@ namespace Tango.Scripting.Editors.CodeCompletion
if (CloseOnFocusLost) {
Debug.WriteLine("CloseIfFocusLost: this.IsActive=" + this.IsActive + " IsTextAreaFocused=" + IsTextAreaFocused);
if (!this.IsActive && !IsTextAreaFocused) {
- Close();
- }
+ HideCompletion();
+ }
}
}
@@ -268,21 +284,29 @@ namespace Tango.Scripting.Editors.CodeCompletion
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
+ SetPosition();
- if (document != null && this.StartOffset != this.TextArea.Caret.Offset) {
- SetPosition(new TextViewPosition(document.GetLocation(this.StartOffset)));
- } else {
- SetPosition(this.TextArea.Caret.Position);
- }
- sourceIsInitialized = true;
+ //sourceIsInitialized = true;
}
+
+ private void SetPosition()
+ {
+ if (document != null && this.StartOffset != this.TextArea.Caret.Offset)
+ {
+ SetPosition(new TextViewPosition(document.GetLocation(this.StartOffset)));
+ }
+ else
+ {
+ SetPosition(this.TextArea.Caret.Position);
+ }
+ }
/// <inheritdoc/>
protected override void OnClosed(EventArgs e)
{
- base.OnClosed(e);
- DetachEvents();
- }
+ DetachEvents();
+ HideCompletion();
+ }
/// <inheritdoc/>
protected override void OnKeyDown(KeyEventArgs e)
@@ -290,8 +314,8 @@ namespace Tango.Scripting.Editors.CodeCompletion
base.OnKeyDown(e);
if (!e.Handled && e.Key == Key.Escape) {
e.Handled = true;
- Close();
- }
+ HideCompletion();
+ }
}
Point visualLocation, visualLocationTop;
@@ -365,9 +389,9 @@ namespace Tango.Scripting.Editors.CodeCompletion
void textArea_Document_Changing(object sender, DocumentChangeEventArgs e)
{
if (e.Offset + e.RemovalLength == this.StartOffset && e.RemovalLength > 0) {
- Close(); // removal immediately in front of completion segment: close the window
- // this is necessary when pressing backspace after dot-completion
- }
+ HideCompletion(); // removal immediately in front of completion segment: close the window
+ // this is necessary when pressing backspace after dot-completion
+ }
if (e.Offset == StartOffset && e.RemovalLength == 0 && ExpectInsertionBeforeStart) {
StartOffset = e.GetNewOffset(StartOffset, AnchorMovementType.AfterInsertion);
this.ExpectInsertionBeforeStart = false;