提交 0e2b7637 编写于 作者: I Ivan Basov

more business logic

上级 c3b3e1f3
...@@ -42,15 +42,15 @@ ...@@ -42,15 +42,15 @@
<Label Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=dialog, Path=TypeNameLabel}" /> <Label Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=dialog, Path=TypeNameLabel}" />
<Border Grid.Row="0" Grid.Column="1" BorderThickness="1" Margin="6,0,0,0"> <ContentControl x:Name="TypeNameContentControl" Focusable="True" PreviewKeyDown="TypeNameContentControl_PreviewKeyDown" Margin="100,0,100,15" BorderBrush="{DynamicResource {x:Static SystemColors.InactiveBorderBrushKey}}" /> </Border> <Border Grid.Row="0" Grid.Column="1" BorderThickness="1" Margin="6,0,0,0"> <ContentControl x:Name="TypeNameContentControl" Focusable="True" PreviewKeyDown="TypeNameContentControl_PreviewKeyDown" Margin="100,0,100,15" BorderBrush="{DynamicResource {x:Static SystemColors.InactiveBorderBrushKey}}" /> </Border>
<Label Grid.Row="1" Grid.Column="0" Content="{Binding ElementName=dialog, Path=ParameterNameLabel}" /> <Label Grid.Row="1" Grid.Column="0" Content="{Binding ElementName=dialog, Path=ParameterNameLabel}" />
<TextBox Grid.Row="1" Grid.Column="1" Width="200" Text="{Binding ParameterName}" Margin="100,0,100,15" /> <TextBox Grid.Row="1" Grid.Column="1" Width="200" Text="{Binding ParameterName, Mode=TwoWay}" Margin="100,0,100,15" TextChanged="TextBox_ParameterNameChanged" />
<Label Grid.Row="2" Grid.Column="0" Content="{Binding ElementName=dialog, Path=CallsiteValueLabel}" /> <Label Grid.Row="2" Grid.Column="0" Content="{Binding ElementName=dialog, Path=CallsiteValueLabel}" />
<TextBox Grid.Row="2" Grid.Column="1" Width="200" Text="{Binding CallsiteValue}" Margin="100,0,100,15" /> <TextBox Grid.Row="2" Grid.Column="1" Width="200" Text="{Binding CallsiteValue, Mode=TwoWay}" Margin="100,0,100,15" />
</Grid> </Grid>
<StackPanel Grid.Row="1" <StackPanel Grid.Row="1"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0, 11, 0, 0" Margin="0, 11, 0, 0"
Orientation="Horizontal" Width="153"> Orientation="Horizontal" Width="153">
<vs:DialogButton x:Uid="OKButton" <vs:DialogButton x:Uid="OKButton" x:Name="OKButton"
Content="{Binding ElementName=dialog, Path=OK}" Content="{Binding ElementName=dialog, Path=OK}"
Margin="0, 0, 0, 0" Margin="0, 0, 0, 0"
Padding="{StaticResource ResourceKey=okCancelButtonPadding}" Padding="{StaticResource ResourceKey=okCancelButtonPadding}"
......
...@@ -14,9 +14,18 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ChangeSignature ...@@ -14,9 +14,18 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ChangeSignature
internal partial class AddParameterDialog : DialogWindow internal partial class AddParameterDialog : DialogWindow
{ {
public readonly AddParameterDialogViewModel ViewModel; public readonly AddParameterDialogViewModel ViewModel;
private readonly IVsTextLines _vsTextLines; private readonly IntellisenseTextBoxViewModel _intellisenseTextBoxView;
private readonly IVsTextView _textView; private bool _isValid;
private readonly IWpfTextView _wpfTextView;
private bool IsValid
{
get { return _isValid; }
set
{
this.OKButton.IsEnabled = value;
_isValid = value;
}
}
public string OK { get { return ServicesVSResources.OK; } } public string OK { get { return ServicesVSResources.OK; } }
public string Cancel { get { return ServicesVSResources.Cancel; } } public string Cancel { get { return ServicesVSResources.Cancel; } }
...@@ -29,16 +38,16 @@ internal partial class AddParameterDialog : DialogWindow ...@@ -29,16 +38,16 @@ internal partial class AddParameterDialog : DialogWindow
public string AddParameterDialogTitle { get { return ServicesVSResources.Add_Parameter; } } public string AddParameterDialogTitle { get { return ServicesVSResources.Add_Parameter; } }
public AddParameterDialog( public AddParameterDialog(IntellisenseTextBoxViewModel intellisenseTextBoxViewModel)
IVsTextLines vsTextLines,
IVsTextView vsTextView,
IWpfTextView wpfTextView)
{ {
// TODO this should be initlialized when called for Edit.
ViewModel = new AddParameterDialogViewModel(); ViewModel = new AddParameterDialogViewModel();
_vsTextLines = vsTextLines; _intellisenseTextBoxView = intellisenseTextBoxViewModel;
_textView = vsTextView;
_wpfTextView = wpfTextView;
this.Loaded += AddParameterDialog_Loaded; this.Loaded += AddParameterDialog_Loaded;
DataContext = ViewModel;
// This is for Add. For edit, it should be true by default.
IsValid = false;
InitializeComponent(); InitializeComponent();
} }
...@@ -46,7 +55,7 @@ internal partial class AddParameterDialog : DialogWindow ...@@ -46,7 +55,7 @@ internal partial class AddParameterDialog : DialogWindow
private void AddParameterDialog_Loaded(object sender, RoutedEventArgs e) private void AddParameterDialog_Loaded(object sender, RoutedEventArgs e)
{ {
IntellisenseTextBox typeNameTextBox = new IntellisenseTextBox( IntellisenseTextBox typeNameTextBox = new IntellisenseTextBox(
_vsTextLines, _textView, _wpfTextView, TypeNameContentControl); _intellisenseTextBoxView, TypeNameContentControl);
this.TypeNameContentControl.Content = typeNameTextBox; this.TypeNameContentControl.Content = typeNameTextBox;
} }
...@@ -54,7 +63,6 @@ private void OK_Click(object sender, RoutedEventArgs e) ...@@ -54,7 +63,6 @@ private void OK_Click(object sender, RoutedEventArgs e)
{ {
if (ViewModel.TrySubmit()) if (ViewModel.TrySubmit())
{ {
// TODO maybe we should try binding.
ViewModel.TypeName = ((IntellisenseTextBox)TypeNameContentControl.Content).Text; ViewModel.TypeName = ((IntellisenseTextBox)TypeNameContentControl.Content).Text;
DialogResult = true; DialogResult = true;
} }
...@@ -83,7 +91,6 @@ private void TypeNameContentControl_PreviewKeyDown(object sender, KeyEventArgs e ...@@ -83,7 +91,6 @@ private void TypeNameContentControl_PreviewKeyDown(object sender, KeyEventArgs e
{ {
// Do nothing. This case is handled in parent control KeyDown events. // Do nothing. This case is handled in parent control KeyDown events.
} }
else if (e.Key == Key.Tab && !typeNameTextBox.HasActiveIntellisenseSession) else if (e.Key == Key.Tab && !typeNameTextBox.HasActiveIntellisenseSession)
{ {
// Do nothing. This case is handled in parent control KeyDown events. // Do nothing. This case is handled in parent control KeyDown events.
...@@ -96,5 +103,15 @@ private void TypeNameContentControl_PreviewKeyDown(object sender, KeyEventArgs e ...@@ -96,5 +103,15 @@ private void TypeNameContentControl_PreviewKeyDown(object sender, KeyEventArgs e
} }
} }
} }
private void TextBox_ParameterNameChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
// check for empty
// check for starting with non-letter
// check for special symbols
// check for matching other parameter names
// if not valid and _isValid, then _isValid = false;
// if valid and !_isValid, then validate all controls
}
} }
} }
...@@ -27,11 +27,11 @@ public ITextViewModel CreateTextViewModel(ITextDataModel dataModel, ITextViewRol ...@@ -27,11 +27,11 @@ public ITextViewModel CreateTextViewModel(ITextDataModel dataModel, ITextViewRol
var span = projectionSnapshot.GetSourceSpans()[1]; var span = projectionSnapshot.GetSourceSpans()[1];
var mappedSpans = projectionSnapshot.MapFromSourceSnapshot(span); var mappedSpans = projectionSnapshot.MapFromSourceSnapshot(span);
var elisionBuffer = var elisionBuffer =
ProjectionBufferFactoryService.CreateElisionBuffer(/*resolver=*/null, ProjectionBufferFactoryService.CreateElisionBuffer(
new NormalizedSnapshotSpanCollection( projectionEditResolver: null,
new[]{ new SnapshotSpan(dataModel.DocumentBuffer.CurrentSnapshot, mappedSpans[0]) exposedSpans: new NormalizedSnapshotSpanCollection(
}), new[] { new SnapshotSpan(dataModel.DocumentBuffer.CurrentSnapshot, mappedSpans[0]) }),
ElisionBufferOptions.None); options: ElisionBufferOptions.None);
return new ElisionBufferTextViewModel(dataModel, elisionBuffer); return new ElisionBufferTextViewModel(dataModel, elisionBuffer);
} }
......
...@@ -24,7 +24,8 @@ public ChangeSignatureWorkspace(Solution solution, Project project) ...@@ -24,7 +24,8 @@ public ChangeSignatureWorkspace(Solution solution, Project project)
Options = Options.WithChangedOption(EditorCompletionOptions.UseSuggestionMode, true); Options = Options.WithChangedOption(EditorCompletionOptions.UseSuggestionMode, true);
} }
private string GetDocumentText() // TODO do we need to keep this?
private static string GetDocumentText()
{ {
return $@" return $@"
{{ {{
......
...@@ -170,14 +170,14 @@ public AddedParameterResult GetAddedParameter(Document document, int insertPosit ...@@ -170,14 +170,14 @@ public AddedParameterResult GetAddedParameter(Document document, int insertPosit
// Start getting the compilation so the PartialSolution will be ready when the user starts typing in the window // Start getting the compilation so the PartialSolution will be ready when the user starts typing in the window
await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var roleSet = _textEditorFactoryService.CreateTextViewRoleSet( ITextViewRoleSet roleSet = _textEditorFactoryService.CreateTextViewRoleSet(
PredefinedTextViewRoles.Editable, PredefinedTextViewRoles.Editable,
PredefinedTextViewRoles.Interactive, PredefinedTextViewRoles.Interactive,
AddParameterTextViewRole); AddParameterTextViewRole);
var vsTextView = _editorAdaptersFactoryService.CreateVsTextViewAdapter(_serviceProvider, roleSet); IVsTextView vsTextView = _editorAdaptersFactoryService.CreateVsTextViewAdapter(_serviceProvider, roleSet);
var initView = new[] { INITVIEW[] initView = new[] {
new INITVIEW() new INITVIEW()
{ {
fSelectionMargin = 0, fSelectionMargin = 0,
...@@ -198,7 +198,7 @@ public AddedParameterResult GetAddedParameter(Document document, int insertPosit ...@@ -198,7 +198,7 @@ public AddedParameterResult GetAddedParameter(Document document, int insertPosit
IWpfTextView wpfTextView = _editorAdaptersFactoryService.GetWpfTextView(vsTextView); IWpfTextView wpfTextView = _editorAdaptersFactoryService.GetWpfTextView(vsTextView);
wpfTextView.TextBuffer.ChangeContentType(_contentType, null); wpfTextView.TextBuffer.ChangeContentType(_contentType, null);
return new AddParameterDialog(vsTextLines, vsTextView, wpfTextView); return new AddParameterDialog(new IntellisenseTextBoxViewModel(vsTextView, wpfTextView));
} }
} }
} }
...@@ -27,11 +27,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation ...@@ -27,11 +27,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation
/// </summary> /// </summary>
internal class IntellisenseTextBox : FrameworkElement, IOleCommandTarget internal class IntellisenseTextBox : FrameworkElement, IOleCommandTarget
{ {
/// <summary>
/// Contains the text in the buffer
/// </summary>
private readonly IVsTextLines _vsTextLines;
/// <summary> /// <summary>
/// IWpfTextView container /// IWpfTextView container
/// </summary> /// </summary>
...@@ -55,11 +50,9 @@ internal class IntellisenseTextBox : FrameworkElement, IOleCommandTarget ...@@ -55,11 +50,9 @@ internal class IntellisenseTextBox : FrameworkElement, IOleCommandTarget
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IntellisenseTextBox"/> class. /// Initializes a new instance of the <see cref="IntellisenseTextBox"/> class.
/// </summary> /// </summary>
public IntellisenseTextBox( public IntellisenseTextBox(IntellisenseTextBoxViewModel viewModel, ContentControl container)
IVsTextLines vsTextLines, IVsTextView vsTextView, IWpfTextView wpfTextView, ContentControl container)
{ {
this._vsTextLines = vsTextLines; this.InitializeEditorControl(viewModel, container);
this.InitializeEditorControl(vsTextView, wpfTextView, container);
} }
/// <summary> /// <summary>
...@@ -91,15 +84,7 @@ public bool HasActiveIntellisenseSession ...@@ -91,15 +84,7 @@ public bool HasActiveIntellisenseSession
/// </summary> /// </summary>
public string Text public string Text
{ {
get get => this._textViewHost.TextView.TextSnapshot.GetText();
{
int length;
string text;
// TODO why 0?
this._vsTextLines.GetLengthOfLine(0, out length);
this._vsTextLines.GetLineText(0, 0, 0, length, out text);
return text;
}
} }
///// <summary> ///// <summary>
...@@ -107,10 +92,7 @@ public string Text ...@@ -107,10 +92,7 @@ public string Text
///// </summary> ///// </summary>
protected override int VisualChildrenCount protected override int VisualChildrenCount
{ {
get get => 1;
{
return 1;
}
} }
/// <summary> /// <summary>
...@@ -275,15 +257,12 @@ protected override void OnGotFocus(RoutedEventArgs e) ...@@ -275,15 +257,12 @@ protected override void OnGotFocus(RoutedEventArgs e)
/// <summary> /// <summary>
/// Initializes the editor control /// Initializes the editor control
/// </summary> /// </summary>
private void InitializeEditorControl(IVsTextView vsTextView, IWpfTextView wpfTextView, ContentControl container) private void InitializeEditorControl(IntellisenseTextBoxViewModel viewModel, ContentControl container)
{ {
IComponentModel componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel)); IComponentModel componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
// TODO Set text buffer initial contents
// ErrorHandler.ThrowOnFailure(vsTextBuffer.InitializeContent(initialContent, initialContent != null ? initialContent.Length : 0));
// Sets editor options that control its final look // Sets editor options that control its final look
IEditorOptions editorOptions = wpfTextView.Properties.GetProperty(typeof(IEditorOptions)) as IEditorOptions; IEditorOptions editorOptions = viewModel.WpfTextView.Properties.GetProperty(typeof(IEditorOptions)) as IEditorOptions;
editorOptions.SetOptionValue("TextViewHost/ZoomControl", false); editorOptions.SetOptionValue("TextViewHost/ZoomControl", false);
editorOptions.SetOptionValue(DefaultWpfViewOptions.AppearanceCategory, appearanceCategory); editorOptions.SetOptionValue(DefaultWpfViewOptions.AppearanceCategory, appearanceCategory);
...@@ -301,14 +280,14 @@ private void InitializeEditorControl(IVsTextView vsTextView, IWpfTextView wpfTex ...@@ -301,14 +280,14 @@ private void InitializeEditorControl(IVsTextView vsTextView, IWpfTextView wpfTex
IEditorOperationsFactoryService editorOperationsFactoryService = componentModel.GetService<IEditorOperationsFactoryService>(); IEditorOperationsFactoryService editorOperationsFactoryService = componentModel.GetService<IEditorOperationsFactoryService>();
if (editorOperationsFactoryService != null) if (editorOperationsFactoryService != null)
{ {
this._editorOperations = editorOperationsFactoryService.GetEditorOperations(wpfTextView); this._editorOperations = editorOperationsFactoryService.GetEditorOperations(viewModel.WpfTextView);
} }
ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out this._nextCommandTarget)); ErrorHandler.ThrowOnFailure(viewModel.VsTextView.AddCommandFilter(this, out this._nextCommandTarget));
// Get the host control to render the view // Get the host control to render the view
IVsEditorAdaptersFactoryService editorAdapterFactory = componentModel.GetService<IVsEditorAdaptersFactoryService>(); IVsEditorAdaptersFactoryService editorAdapterFactory = componentModel.GetService<IVsEditorAdaptersFactoryService>();
this._textViewHost = editorAdapterFactory.GetWpfTextViewHost(vsTextView); this._textViewHost = editorAdapterFactory.GetWpfTextViewHost(viewModel.VsTextView);
// For non-blurry text // For non-blurry text
TextOptions.SetTextFormattingMode(this._textViewHost.HostControl, TextFormattingMode.Display); TextOptions.SetTextFormattingMode(this._textViewHost.HostControl, TextFormattingMode.Display);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Implementation
{
internal readonly struct IntellisenseTextBoxViewModel
{
public readonly IVsTextView VsTextView;
public readonly IWpfTextView WpfTextView;
public IntellisenseTextBoxViewModel(IVsTextView vsTextView, IWpfTextView wpfTextView)
{
VsTextView = vsTextView;
WpfTextView = wpfTextView;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册