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

more business logic

上级 c3b3e1f3
......@@ -42,15 +42,15 @@
<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>
<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}" />
<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>
<StackPanel Grid.Row="1"
HorizontalAlignment="Right"
Margin="0, 11, 0, 0"
Orientation="Horizontal" Width="153">
<vs:DialogButton x:Uid="OKButton"
<vs:DialogButton x:Uid="OKButton" x:Name="OKButton"
Content="{Binding ElementName=dialog, Path=OK}"
Margin="0, 0, 0, 0"
Padding="{StaticResource ResourceKey=okCancelButtonPadding}"
......
......@@ -14,9 +14,18 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ChangeSignature
internal partial class AddParameterDialog : DialogWindow
{
public readonly AddParameterDialogViewModel ViewModel;
private readonly IVsTextLines _vsTextLines;
private readonly IVsTextView _textView;
private readonly IWpfTextView _wpfTextView;
private readonly IntellisenseTextBoxViewModel _intellisenseTextBoxView;
private bool _isValid;
private bool IsValid
{
get { return _isValid; }
set
{
this.OKButton.IsEnabled = value;
_isValid = value;
}
}
public string OK { get { return ServicesVSResources.OK; } }
public string Cancel { get { return ServicesVSResources.Cancel; } }
......@@ -29,16 +38,16 @@ internal partial class AddParameterDialog : DialogWindow
public string AddParameterDialogTitle { get { return ServicesVSResources.Add_Parameter; } }
public AddParameterDialog(
IVsTextLines vsTextLines,
IVsTextView vsTextView,
IWpfTextView wpfTextView)
public AddParameterDialog(IntellisenseTextBoxViewModel intellisenseTextBoxViewModel)
{
// TODO this should be initlialized when called for Edit.
ViewModel = new AddParameterDialogViewModel();
_vsTextLines = vsTextLines;
_textView = vsTextView;
_wpfTextView = wpfTextView;
_intellisenseTextBoxView = intellisenseTextBoxViewModel;
this.Loaded += AddParameterDialog_Loaded;
DataContext = ViewModel;
// This is for Add. For edit, it should be true by default.
IsValid = false;
InitializeComponent();
}
......@@ -46,7 +55,7 @@ internal partial class AddParameterDialog : DialogWindow
private void AddParameterDialog_Loaded(object sender, RoutedEventArgs e)
{
IntellisenseTextBox typeNameTextBox = new IntellisenseTextBox(
_vsTextLines, _textView, _wpfTextView, TypeNameContentControl);
_intellisenseTextBoxView, TypeNameContentControl);
this.TypeNameContentControl.Content = typeNameTextBox;
}
......@@ -54,7 +63,6 @@ private void OK_Click(object sender, RoutedEventArgs e)
{
if (ViewModel.TrySubmit())
{
// TODO maybe we should try binding.
ViewModel.TypeName = ((IntellisenseTextBox)TypeNameContentControl.Content).Text;
DialogResult = true;
}
......@@ -83,7 +91,6 @@ private void TypeNameContentControl_PreviewKeyDown(object sender, KeyEventArgs e
{
// Do nothing. This case is handled in parent control KeyDown events.
}
else if (e.Key == Key.Tab && !typeNameTextBox.HasActiveIntellisenseSession)
{
// Do nothing. This case is handled in parent control KeyDown events.
......@@ -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
var span = projectionSnapshot.GetSourceSpans()[1];
var mappedSpans = projectionSnapshot.MapFromSourceSnapshot(span);
var elisionBuffer =
ProjectionBufferFactoryService.CreateElisionBuffer(/*resolver=*/null,
new NormalizedSnapshotSpanCollection(
new[]{ new SnapshotSpan(dataModel.DocumentBuffer.CurrentSnapshot, mappedSpans[0])
}),
ElisionBufferOptions.None);
ProjectionBufferFactoryService.CreateElisionBuffer(
projectionEditResolver: null,
exposedSpans: new NormalizedSnapshotSpanCollection(
new[] { new SnapshotSpan(dataModel.DocumentBuffer.CurrentSnapshot, mappedSpans[0]) }),
options: ElisionBufferOptions.None);
return new ElisionBufferTextViewModel(dataModel, elisionBuffer);
}
......
......@@ -24,7 +24,8 @@ public ChangeSignatureWorkspace(Solution solution, Project project)
Options = Options.WithChangedOption(EditorCompletionOptions.UseSuggestionMode, true);
}
private string GetDocumentText()
// TODO do we need to keep this?
private static string GetDocumentText()
{
return $@"
{{
......
......@@ -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
await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var roleSet = _textEditorFactoryService.CreateTextViewRoleSet(
ITextViewRoleSet roleSet = _textEditorFactoryService.CreateTextViewRoleSet(
PredefinedTextViewRoles.Editable,
PredefinedTextViewRoles.Interactive,
AddParameterTextViewRole);
var vsTextView = _editorAdaptersFactoryService.CreateVsTextViewAdapter(_serviceProvider, roleSet);
IVsTextView vsTextView = _editorAdaptersFactoryService.CreateVsTextViewAdapter(_serviceProvider, roleSet);
var initView = new[] {
INITVIEW[] initView = new[] {
new INITVIEW()
{
fSelectionMargin = 0,
......@@ -198,7 +198,7 @@ public AddedParameterResult GetAddedParameter(Document document, int insertPosit
IWpfTextView wpfTextView = _editorAdaptersFactoryService.GetWpfTextView(vsTextView);
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
/// </summary>
internal class IntellisenseTextBox : FrameworkElement, IOleCommandTarget
{
/// <summary>
/// Contains the text in the buffer
/// </summary>
private readonly IVsTextLines _vsTextLines;
/// <summary>
/// IWpfTextView container
/// </summary>
......@@ -55,11 +50,9 @@ internal class IntellisenseTextBox : FrameworkElement, IOleCommandTarget
/// <summary>
/// Initializes a new instance of the <see cref="IntellisenseTextBox"/> class.
/// </summary>
public IntellisenseTextBox(
IVsTextLines vsTextLines, IVsTextView vsTextView, IWpfTextView wpfTextView, ContentControl container)
public IntellisenseTextBox(IntellisenseTextBoxViewModel viewModel, ContentControl container)
{
this._vsTextLines = vsTextLines;
this.InitializeEditorControl(vsTextView, wpfTextView, container);
this.InitializeEditorControl(viewModel, container);
}
/// <summary>
......@@ -91,15 +84,7 @@ public bool HasActiveIntellisenseSession
/// </summary>
public string Text
{
get
{
int length;
string text;
// TODO why 0?
this._vsTextLines.GetLengthOfLine(0, out length);
this._vsTextLines.GetLineText(0, 0, 0, length, out text);
return text;
}
get => this._textViewHost.TextView.TextSnapshot.GetText();
}
///// <summary>
......@@ -107,10 +92,7 @@ public string Text
///// </summary>
protected override int VisualChildrenCount
{
get
{
return 1;
}
get => 1;
}
/// <summary>
......@@ -275,15 +257,12 @@ protected override void OnGotFocus(RoutedEventArgs e)
/// <summary>
/// Initializes the editor control
/// </summary>
private void InitializeEditorControl(IVsTextView vsTextView, IWpfTextView wpfTextView, ContentControl container)
private void InitializeEditorControl(IntellisenseTextBoxViewModel viewModel, ContentControl container)
{
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
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(DefaultWpfViewOptions.AppearanceCategory, appearanceCategory);
......@@ -301,14 +280,14 @@ private void InitializeEditorControl(IVsTextView vsTextView, IWpfTextView wpfTex
IEditorOperationsFactoryService editorOperationsFactoryService = componentModel.GetService<IEditorOperationsFactoryService>();
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
IVsEditorAdaptersFactoryService editorAdapterFactory = componentModel.GetService<IVsEditorAdaptersFactoryService>();
this._textViewHost = editorAdapterFactory.GetWpfTextViewHost(vsTextView);
this._textViewHost = editorAdapterFactory.GetWpfTextViewHost(viewModel.VsTextView);
// For non-blurry text
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.
先完成此消息的编辑!
想要评论请 注册