-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Charp73 #173
base: master
Are you sure you want to change the base?
Charp73 #173
Changes from all commits
284493e
d75fc3b
712fa20
165872d
94ecf03
ec22983
1e6cea5
5980b7a
0a5b293
f42936b
f160567
6a3891e
32aec68
5b15edd
b5bd9ce
4a89715
dfaa74e
77f43c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using System.ComponentModel.Composition; | ||
using Microsoft.VisualStudio.Editor; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.TextManager.Interop; | ||
using Microsoft.VisualStudio.Utilities; | ||
using System.ComponentModel.Composition; | ||
using Microsoft.VisualStudio.Editor; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.TextManager.Interop; | ||
using Microsoft.VisualStudio.Utilities; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
[Export(typeof(IVsTextViewCreationListener))] | ||
[ContentType("text")] | ||
[TextViewRole(PredefinedTextViewRoles.Editable)] | ||
internal class CommandHandlerTextViewCreationListener : IVsTextViewCreationListener | ||
{ | ||
private readonly SVsServiceProvider _serviceProvider; | ||
private readonly IVsEditorAdaptersFactoryService _editorAdaptersFactoryService; | ||
private readonly SVsServiceProvider _serviceProvider; | ||
|
||
[ImportingConstructor] | ||
public CommandHandlerTextViewCreationListener(SVsServiceProvider serviceProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService) | ||
public CommandHandlerTextViewCreationListener(SVsServiceProvider serviceProvider, | ||
IVsEditorAdaptersFactoryService editorAdaptersFactoryService) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
_editorAdaptersFactoryService = editorAdaptersFactoryService; | ||
|
@@ -30,8 +31,8 @@ public void VsTextViewCreated(IVsTextView textViewAdapter) | |
|
||
// The new command handling approach does not require that the command filter be enabled. The command | ||
// implementations interact directly with the handler via its IOleCommandTarget interface. | ||
GitDiffMarginCommandHandler filter = new GitDiffMarginCommandHandler(textViewAdapter, _editorAdaptersFactoryService, textView); | ||
var filter = new GitDiffMarginCommandHandler(textViewAdapter, _editorAdaptersFactoryService, textView); | ||
textView.Properties.AddProperty(typeof(GitDiffMarginCommandHandler), filter); | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 I don't like how the missing newline at the end is presented by tools to look like an error. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
internal class CopyOldTextCommandArgs : EditorCommandArgs | ||
{ | ||
public CopyOldTextCommandArgs(ITextView textView, ITextBuffer subjectBuffer) | ||
: base(textView, subjectBuffer) | ||
{ | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,37 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using System.ComponentModel.Composition; | ||
using Microsoft.VisualStudio.Editor.Commanding; | ||
using System.ComponentModel.Composition; | ||
using Microsoft.VisualStudio.Editor.Commanding; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
internal class GitDiffMarginCommandBinding | ||
{ | ||
#pragma warning disable CS0649 // Field 'fieldName' is never assigned to, and will always have its default value null | ||
|
||
[Export] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.PreviousChange, typeof(PreviousChangeCommandArgs))] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.PreviousChange, | ||
typeof(PreviousChangeCommandArgs))] | ||
internal CommandBindingDefinition PreviousChangeCommandBinding; | ||
|
||
[Export] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.NextChange, typeof(NextChangeCommandArgs))] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.NextChange, | ||
typeof(NextChangeCommandArgs))] | ||
internal CommandBindingDefinition NextChangeCommandBinding; | ||
|
||
[Export] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.RollbackChange, typeof(RollbackChangeCommandArgs))] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.RollbackChange, | ||
typeof(RollbackChangeCommandArgs))] | ||
internal CommandBindingDefinition RollbackChangeCommandBinding; | ||
|
||
[Export] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.CopyOldText, typeof(CopyOldTextCommandArgs))] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.CopyOldText, | ||
typeof(CopyOldTextCommandArgs))] | ||
internal CommandBindingDefinition CopyOldTextCommandBinding; | ||
|
||
[Export] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.ShowPopup, typeof(ShowPopupCommandArgs))] | ||
[CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.ShowPopup, | ||
typeof(ShowPopupCommandArgs))] | ||
internal CommandBindingDefinition ShowPopupCommandBinding; | ||
|
||
#pragma warning restore CS0649 // Field 'fieldName' is never assigned to, and will always have its default value null | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using System; | ||
using Microsoft.VisualStudio.OLE.Interop; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
using System; | ||
using Microsoft.VisualStudio.OLE.Interop; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
internal abstract class GitDiffMarginCommandHandler<T> : ShimCommandHandler<T> | ||
where T : EditorCommandArgs | ||
{ | ||
protected GitDiffMarginCommandHandler(GitDiffMarginCommand commandId) | ||
: base(new Guid(GitDiffMarginCommandHandler.GitDiffMarginCommandSet), (uint)commandId) | ||
: base(new Guid(GitDiffMarginCommandHandler.GitDiffMarginCommandSet), (uint) commandId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Unexpected space after cast. If this is a style you want to use, you'll want to add it to a .editorconfig file because it's not the default behavior of Visual Studio. |
||
{ | ||
} | ||
|
||
protected override IOleCommandTarget GetCommandTarget(T args) | ||
=> args.TextView.Properties.GetProperty<GitDiffMarginCommandHandler>(typeof(GitDiffMarginCommandHandler)); | ||
{ | ||
return args.TextView.Properties.GetProperty<GitDiffMarginCommandHandler>( | ||
typeof(GitDiffMarginCommandHandler)); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
internal class NextChangeCommandArgs : EditorCommandArgs | ||
{ | ||
public NextChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer) | ||
: base(textView, subjectBuffer) | ||
{ | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
internal class PreviousChangeCommandArgs : EditorCommandArgs | ||
{ | ||
public PreviousChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer) | ||
: base(textView, subjectBuffer) | ||
{ | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Editor.Commanding; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
internal class RollbackChangeCommandArgs : EditorCommandArgs | ||
{ | ||
public RollbackChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer) | ||
: base(textView, subjectBuffer) | ||
{ | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,47 @@ | ||
namespace GitDiffMargin.Commands | ||
{ | ||
using System; | ||
using Microsoft.VisualStudio; | ||
using Microsoft.VisualStudio.Commanding; | ||
using Microsoft.VisualStudio.Shell; | ||
using IOleCommandTarget = Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget; | ||
using OLECMD = Microsoft.VisualStudio.OLE.Interop.OLECMD; | ||
using OLECMDEXECOPT = Microsoft.VisualStudio.OLE.Interop.OLECMDEXECOPT; | ||
using OLECMDF = Microsoft.VisualStudio.OLE.Interop.OLECMDF; | ||
using System; | ||
using Microsoft.VisualStudio; | ||
using Microsoft.VisualStudio.Commanding; | ||
using Microsoft.VisualStudio.OLE.Interop; | ||
using Microsoft.VisualStudio.Shell; | ||
|
||
namespace GitDiffMargin.Commands | ||
{ | ||
internal abstract class ShimCommandHandler<T> : ICommandHandler<T> | ||
where T : CommandArgs | ||
{ | ||
private readonly Guid _commandSet; | ||
private readonly uint _commandId; | ||
private readonly Guid _commandSet; | ||
|
||
protected ShimCommandHandler(Guid commandSet, uint commandId) | ||
{ | ||
_commandSet = commandSet; | ||
_commandId = commandId; | ||
} | ||
|
||
public abstract string DisplayName | ||
{ | ||
get; | ||
} | ||
public abstract string DisplayName { get; } | ||
|
||
public virtual CommandState GetCommandState(T args) | ||
{ | ||
ThreadHelper.ThrowIfNotOnUIThread(); | ||
|
||
OLECMD[] command = { new OLECMD { cmdID = _commandId } }; | ||
OLECMD[] command = {new OLECMD {cmdID = _commandId}}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Unexpected removal of spaces inside braces |
||
ErrorHandler.ThrowOnFailure(GetCommandTarget(args).QueryStatus(_commandSet, 1, command, IntPtr.Zero)); | ||
if ((command[0].cmdf & (uint)OLECMDF.OLECMDF_SUPPORTED) == 0) | ||
if ((command[0].cmdf & (uint) OLECMDF.OLECMDF_SUPPORTED) == 0) | ||
return CommandState.Unspecified; | ||
else if ((command[0].cmdf & (uint)OLECMDF.OLECMDF_ENABLED) == 0) | ||
return CommandState.Unavailable; | ||
else | ||
return CommandState.Available; | ||
|
||
return (command[0].cmdf & (uint) OLECMDF.OLECMDF_ENABLED) == 0 | ||
? CommandState.Unavailable | ||
: CommandState.Available; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 This is not wrong, but I don't like how some of this method uses an |
||
} | ||
|
||
public virtual bool ExecuteCommand(T args, CommandExecutionContext executionContext) | ||
{ | ||
ThreadHelper.ThrowIfNotOnUIThread(); | ||
|
||
return ErrorHandler.Succeeded(GetCommandTarget(args).Exec(_commandSet, _commandId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero)); | ||
return ErrorHandler.Succeeded(GetCommandTarget(args).Exec(_commandSet, _commandId, | ||
(uint) OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 I dislike how some tools seem to think code should read like a book. One of the smartest rules I've observed in StyleCop is the part of rules that says all arguments should be on one line, or each argument should be on a line of its own. |
||
} | ||
|
||
protected abstract IOleCommandTarget GetCommandTarget(T args); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ Why was this reordered? Previously the fields, the constructor parameters, and the assignments in the constructor all appeared in the same order. Now they are inconsistent.