Datei: NDOPackage/Commands/AddAccessor.cs
Last Commit (33e9857)
| 1 | using System.Diagnostics; |
| 2 | using EnvDTE; |
| 3 | using MessageBox = System.Windows.Forms.MessageBox; |
| 4 | |
| 5 | namespace NDOVsPackage.Commands |
| 6 | { |
| 7 | ····[Command(PackageGuids.guidNDOPackageCmdSetString, PackageIds.cmdidAddAccessor)] |
| 8 | ····internal sealed class AddAccessor : BaseCommand<AddAccessor> |
| 9 | ····{ |
| 10 | ········protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) |
| 11 | ········{ |
| 12 | ············try |
| 13 | ············{ |
| 14 | ················Document document; |
| 15 | ················TextDocument textDoc; |
| 16 | |
| 17 | ················await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
| 18 | |
| 19 | ················document = ApplicationObject.VisualStudioApplication.ActiveDocument; |
| 20 | ················if (document == null) |
| 21 | ····················return; |
| 22 | |
| 23 | ················textDoc = (TextDocument) document.Object( "TextDocument" ); |
| 24 | ················if (textDoc == null) |
| 25 | ····················return; |
| 26 | |
| 27 | ················string fileName = document.FullName.ToLower(); |
| 28 | ················if (fileName.EndsWith( ".cs" )) |
| 29 | ····················new AddAccessorCs( textDoc, document ).DoIt(); |
| 30 | ················else if (fileName.EndsWith( ".vb" )) |
| 31 | ····················new AddAccessorVb( textDoc, document ).DoIt(); |
| 32 | ············} |
| 33 | ············catch (Exception ex) |
| 34 | ············{ |
| 35 | ················Debug.WriteLine( ex.ToString() ); |
| 36 | ················MessageBox.Show( ex.Message, "Configure" ); |
| 37 | ············} |
| 38 | ········} |
| 39 | ········protected override void BeforeQueryStatus(EventArgs e) |
| 40 | ········{ |
| 41 | ············ThreadHelper.JoinableTaskFactory.Run(async () => |
| 42 | ············{ |
| 43 | ················var active = await VS.Documents.GetActiveDocumentViewAsync(); |
| 44 | ················var enabled = active.FilePath.EndsWith(".cs") || active.FilePath.EndsWith(".vb"); |
| 45 | ················await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
| 46 | ················Command.Enabled = enabled; |
| 47 | ············}); |
| 48 | ········} |
| 49 | ····} |
| 50 | } |
| 51 |
New Commit (aa458ff)
| 1 | // |
| 2 | // Copyright (c) 2002-2022 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | |
| 23 | using System.Diagnostics; |
| 24 | using EnvDTE; |
| 25 | using MessageBox = System.Windows.Forms.MessageBox; |
| 26 | |
| 27 | #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread |
| 28 | |
| 29 | namespace NDOVsPackage.Commands |
| 30 | { |
| 31 | ····[Command(PackageGuids.guidNDOPackageCmdSetString, PackageIds.cmdidAddAccessor)] |
| 32 | ····internal sealed class AddAccessor : BaseCommand<AddAccessor> |
| 33 | ····{ |
| 34 | ········protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) |
| 35 | ········{ |
| 36 | ············try |
| 37 | ············{ |
| 38 | ················Document document; |
| 39 | ················TextDocument textDoc; |
| 40 | |
| 41 | ················await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
| 42 | |
| 43 | ················document = ApplicationObject.VisualStudioApplication.ActiveDocument; |
| 44 | ················if (document == null) |
| 45 | ····················return; |
| 46 | |
| 47 | ················textDoc = (TextDocument) document.Object( "TextDocument" ); |
| 48 | ················if (textDoc == null) |
| 49 | ····················return; |
| 50 | |
| 51 | ················string fileName = document.FullName.ToLower(); |
| 52 | ················if (fileName.EndsWith( ".cs" )) |
| 53 | ····················new AddAccessorCs( textDoc, document ).DoIt(); |
| 54 | ················else if (fileName.EndsWith( ".vb" )) |
| 55 | ····················new AddAccessorVb( textDoc, document ).DoIt(); |
| 56 | ············} |
| 57 | ············catch (Exception ex) |
| 58 | ············{ |
| 59 | ················Debug.WriteLine( ex.ToString() ); |
| 60 | ················MessageBox.Show( ex.Message, "Configure" ); |
| 61 | ············} |
| 62 | ········} |
| 63 | ········protected override void BeforeQueryStatus(EventArgs e) |
| 64 | ········{ |
| 65 | ············ThreadHelper.JoinableTaskFactory.Run(async () => |
| 66 | ············{ |
| 67 | ················var active = await VS.Documents.GetActiveDocumentViewAsync(); |
| 68 | ················var enabled = active.FilePath.EndsWith(".cs") || active.FilePath.EndsWith(".vb"); |
| 69 | ················await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
| 70 | ················Command.Enabled = enabled; |
| 71 | ············}); |
| 72 | ········} |
| 73 | ····} |
| 74 | } |
| 75 | |
| 76 | #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread |
| 77 |