Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now using a margin instead of a popup to alert about conflicting key …
…bindings
- Loading branch information
Showing
9 changed files
with
273 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Vim; | ||
using VsVim.UI; | ||
using System.Windows; | ||
using Microsoft.VisualStudio.Text.Classification; | ||
using System.Windows.Media; | ||
|
||
namespace VsVim.Implementation | ||
{ | ||
internal sealed class ConflictingKeyBindingMargin : IWpfTextViewMargin | ||
{ | ||
internal const string Name = "Vim Conflicting KeyBinding Margin"; | ||
|
||
private readonly IVimBuffer _buffer; | ||
private readonly IKeyBindingService _keyBindingService; | ||
private readonly ConflictingKeyBindingMarginControl _control; | ||
private bool _enabled = true; | ||
|
||
internal ConflictingKeyBindingMargin(IVimBuffer buffer, IKeyBindingService service, IEditorFormatMap formatMap) | ||
{ | ||
_buffer = buffer; | ||
_keyBindingService = service; | ||
_control = new ConflictingKeyBindingMarginControl(); | ||
_control.Background = GetBackgroundColor(formatMap); | ||
|
||
_control.RemoveClick += OnRemoveClick; | ||
_control.IgnoreClick += OnIgnoreClick; | ||
_keyBindingService.ConflictingKeyBindingStateChanged += OnStateChanged; | ||
|
||
OnStateChanged(this, EventArgs.Empty); | ||
} | ||
|
||
private static Brush GetBackgroundColor(IEditorFormatMap map) | ||
{ | ||
var properties = map.GetProperties(EditorFormatDefinitionNames.ConflictingKeyBindingMargin); | ||
var key = EditorFormatDefinition.BackgroundColorId; | ||
var color = ConflictingKeyBindingMarginFormatDefinition.DefaultColor; | ||
if (properties != null && properties.Contains(key)) | ||
{ | ||
color = (Color)properties[key]; | ||
} | ||
|
||
return new SolidColorBrush(color); | ||
} | ||
|
||
private void Unsubscribe() | ||
{ | ||
_control.RemoveClick -= OnRemoveClick; | ||
_control.IgnoreClick -= OnIgnoreClick; | ||
_keyBindingService.ConflictingKeyBindingStateChanged -= OnStateChanged; | ||
} | ||
|
||
private void OnRemoveClick(object sender, EventArgs e) | ||
{ | ||
_keyBindingService.ResolveAnyConflicts(); | ||
} | ||
|
||
private void OnIgnoreClick(object sender, EventArgs e) | ||
{ | ||
_keyBindingService.IgnoreAnyConflicts(); | ||
} | ||
|
||
private void OnStateChanged(object sender, EventArgs e) | ||
{ | ||
switch (_keyBindingService.ConflictingKeyBindingState) | ||
{ | ||
case ConflictingKeyBindingState.HasNotChecked: | ||
case ConflictingKeyBindingState.ConflictsIgnoredOrResolved: | ||
_control.Visibility = Visibility.Collapsed; | ||
_enabled = false; | ||
break; | ||
case ConflictingKeyBindingState.FoundConflicts: | ||
_control.Visibility = Visibility.Visible; | ||
_enabled = true; | ||
break; | ||
default: | ||
throw new Exception("Enum value unknown"); | ||
} | ||
} | ||
|
||
#region IWpfTextViewMargin | ||
|
||
public System.Windows.FrameworkElement VisualElement | ||
{ | ||
get { return _control; } | ||
} | ||
|
||
public bool Enabled | ||
{ | ||
get { return _enabled; } | ||
} | ||
|
||
public ITextViewMargin GetTextViewMargin(string marginName) | ||
{ | ||
return marginName == Name ? this : null; | ||
} | ||
|
||
public double MarginSize | ||
{ | ||
get { return 25d; } | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Unsubscribe(); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
VsVim/Implementation/ConflictingKeyBindingMarginProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using System.ComponentModel.Composition; | ||
using Vim; | ||
using Microsoft.VisualStudio.Utilities; | ||
using Microsoft.VisualStudio.Text.Classification; | ||
|
||
namespace VsVim.Implementation | ||
{ | ||
[Export(typeof(IWpfTextViewMarginProvider))] | ||
[MarginContainer(PredefinedMarginNames.Top)] | ||
[ContentType("code")] | ||
[Name(ConflictingKeyBindingMargin.Name)] | ||
[TextViewRole(PredefinedTextViewRoles.Document)] | ||
internal sealed class ConflictingKeyBindingMarginProvider : IWpfTextViewMarginProvider | ||
{ | ||
private readonly IVim _vim; | ||
private readonly IKeyBindingService _keyBindingService; | ||
private readonly IEditorFormatMapService _formatMapService; | ||
|
||
[ImportingConstructor] | ||
internal ConflictingKeyBindingMarginProvider(IVim vim, IKeyBindingService keyBindingService, IEditorFormatMapService formatMapService) | ||
{ | ||
_vim = vim; | ||
_keyBindingService = keyBindingService; | ||
_formatMapService = formatMapService; | ||
} | ||
|
||
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer) | ||
{ | ||
var buffer = _vim.GetOrCreateBuffer(wpfTextViewHost.TextView); | ||
var map = _formatMapService.GetEditorFormatMap(wpfTextViewHost.TextView); | ||
return new ConflictingKeyBindingMargin(buffer,_keyBindingService, map); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.VisualStudio.Text.Classification; | ||
using System.ComponentModel.Composition; | ||
using Microsoft.VisualStudio.Utilities; | ||
using System.Windows.Media; | ||
|
||
namespace VsVim.Implementation | ||
{ | ||
internal static class EditorFormatDefinitionNames | ||
{ | ||
internal const string ConflictingKeyBindingMargin = "vsvim_conflictingkeybindingmargin"; | ||
} | ||
|
||
[Export(typeof(EditorFormatDefinition))] | ||
[Name(EditorFormatDefinitionNames.ConflictingKeyBindingMargin)] | ||
[UserVisible(true)] | ||
internal sealed class ConflictingKeyBindingMarginFormatDefinition : EditorFormatDefinition | ||
{ | ||
internal static Color DefaultColor = Colors.Wheat; | ||
|
||
internal ConflictingKeyBindingMarginFormatDefinition() | ||
{ | ||
this.DisplayName = "VsVim Conflicting Key Binding Margin"; | ||
this.BackgroundColor = DefaultColor; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<UserControl x:Class="VsVim.UI.ConflictingKeyBindingMarginControl" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
mc:Ignorable="d" | ||
d:DesignHeight="25" d:DesignWidth="453"> | ||
<StackPanel Orientation="Horizontal"> | ||
|
||
<Label Margin="0,0,5,0">VsVim detected conflicting key bindings</Label> | ||
|
||
<Button | ||
Click="OnRemoveClick" | ||
Margin="0,0,5,0">Remove</Button> | ||
|
||
<Button | ||
Click="OnIgnoreClick" | ||
Margin="0,0,5,0">Ignore</Button> | ||
|
||
</StackPanel> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace VsVim.UI | ||
{ | ||
/// <summary> | ||
/// Interaction logic for ConflictingKeyBindingsMargin.xaml | ||
/// </summary> | ||
public partial class ConflictingKeyBindingMarginControl : UserControl | ||
{ | ||
/// <summary> | ||
/// Raised when the Remove button is clicked | ||
/// </summary> | ||
public event EventHandler RemoveClick; | ||
|
||
/// <summary> | ||
/// Raised when the Ignore button is clicked | ||
/// </summary> | ||
public event EventHandler IgnoreClick; | ||
|
||
public ConflictingKeyBindingMarginControl() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void OnRemoveClick(object sender, RoutedEventArgs e) | ||
{ | ||
var list = RemoveClick; | ||
if (list != null) | ||
{ | ||
list(this, RoutedEventArgs.Empty); | ||
} | ||
} | ||
|
||
private void OnIgnoreClick(object sender, RoutedEventArgs e) | ||
{ | ||
var list = IgnoreClick; | ||
if (list != null) | ||
{ | ||
list(this, RoutedEventArgs.Empty); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters