public void RecordInfo(string message) { if (AnalyzerBase.GetSettings().ExtendedOutputEnabled) { RxtOutputPane.Instance.Write(TimeStampMessage(message)); } }
private async void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { try { if (sender is OleMenuCommand menuCmd) { bool showCommandButton = false; var settings = AnalyzerBase.GetSettings(); if (settings.IsActiveProfileSet) { var profile = settings.GetActiveProfile(); var dte = await Instance.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var logic = new SetDataContextCommandLogic(profile, this.Logger, new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte)); showCommandButton = logic.ShouldEnableCommand(); } menuCmd.Visible = menuCmd.Enabled = showCommandButton; } } catch (Exception exc) { this.Logger.RecordException(exc); throw; // Remove for launch. see issue #90 } }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { try { if (sender is OleMenuCommand menuCmd) { menuCmd.Visible = menuCmd.Enabled = false; if (!this.IsSingleProjectItemSelection(out var hierarchy, out var itemid)) { this.SelectedFileName = null; return; } ((IVsProject)hierarchy).GetMkDocument(itemid, out var itemFullPath); var transformFileInfo = new FileInfo(itemFullPath); // Save the name of the selected file so we whave it when the command is executed this.SelectedFileName = transformFileInfo.FullName; if (transformFileInfo.Name.EndsWith(".cs") || transformFileInfo.Name.EndsWith(".vb")) { if (AnalyzerBase.GetSettings().IsActiveProfileSet) { menuCmd.Visible = menuCmd.Enabled = true; } } } } catch (Exception exc) { this.Logger.RecordException(exc); throw; } }
public void RecordInfo(string message) { ThreadHelper.ThrowIfNotOnUIThread(); if (AnalyzerBase.GetSettings().ExtendedOutputEnabled) { RxtOutputPane.Instance.Write(TimeStampMessage(message)); } }
public void RecordError(string message) { // Activate the pane (bring to front) so errors are obvious if (AnalyzerBase.GetSettings().ExtendedOutputEnabled) { RxtOutputPane.Instance.Write(TimeStampMessage(message)); RxtOutputPane.Instance.Activate(); } else { GeneralOutputPane.Instance.Write(TimeStampMessage(message)); GeneralOutputPane.Instance.Activate(); } }
private async void Execute(object sender, EventArgs e) { try { ThreadHelper.ThrowIfNotOnUIThread(); this.Logger?.RecordFeatureUsage(nameof(CreateViewCommand)); this.Logger?.RecordInfo(StringRes.Info_AttemptingToCreateView); var dte = await this.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var componentModel = await this.ServiceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel; var profile = AnalyzerBase.GetSettings().GetActiveProfile(); var logic = new CreateViewCommandLogic(profile, this.Logger, new VisualStudioAbstraction(dte, componentModel)); await logic.ExecuteAsync(this.SelectedFileName); if (logic.CreateView) { if (!Directory.Exists(logic.ViewFolder)) { Directory.CreateDirectory(logic.ViewFolder); } File.WriteAllText(logic.XamlFileName, logic.XamlFileContents, Encoding.UTF8); File.WriteAllText(logic.CodeFileName, logic.CodeFileContents, Encoding.UTF8); // add files to project (rely on VS to nest them) logic.ViewProject.Project.ProjectItems.AddFromFile(logic.XamlFileName); logic.ViewProject.Project.ProjectItems.AddFromFile(logic.CodeFileName); // Open the newly created view dte?.ItemOperations.OpenFile(logic.XamlFileName, EnvDTE.Constants.vsViewKindDesigner); this.Logger?.RecordInfo(StringRes.Info_CreatedView.WithParams(logic.XamlFileName)); } else { this.Logger?.RecordInfo(StringRes.Info_NoViewCreated); } } catch (Exception exc) { this.Logger?.RecordException(exc); throw; } }
public async Task <AnalyzerOutput> GetXamlAsync(IAsyncServiceProvider serviceProvider) { AnalyzerOutput result = null; if (AnalyzerBase.GetSettings().Profiles.Any()) { var dte = await serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE; var activeDocument = dte.ActiveDocument; var textView = await GetTextViewAsync(serviceProvider); var selection = textView.Selection; bool isSelection = selection.Start.Position != selection.End.Position; var caretPosition = textView.Caret.Position.BufferPosition; var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); var semanticModel = await document.GetSemanticModelAsync(); var vs = new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte); var xamlIndent = await vs.GetXamlIndentAsync(); IDocumentAnalyzer analyzer = null; if (activeDocument.Language == "CSharp") { analyzer = new CSharpAnalyzer(this.Logger); } else if (activeDocument.Language == "Basic") { analyzer = new VisualBasicAnalyzer(this.Logger); } result = isSelection ? analyzer?.GetSelectionOutput(await document.GetSyntaxRootAsync(), semanticModel, selection.Start.Position, selection.End.Position, xamlIndent) : analyzer?.GetSingleItemOutput(await document.GetSyntaxRootAsync(), semanticModel, caretPosition.Position, xamlIndent); } else { await ShowStatusBarMessageAsync(serviceProvider, StringRes.UI_NoXamlCopiedNoProfilesConfigured); } return(result); }
public AnalyzerOutput GetXaml(IAsyncServiceProvider serviceProvider) { AnalyzerOutput result = null; if (AnalyzerBase.GetSettings().Profiles.Any()) { var dte = (EnvDTE.DTE)serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)).Result; var activeDocument = dte.ActiveDocument; var textView = GetTextView(serviceProvider); var selection = textView.Selection; bool isSelection = selection.Start.Position != selection.End.Position; var caretPosition = textView.Caret.Position.BufferPosition; var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); var semanticModel = document.GetSemanticModelAsync().Result; IDocumentAnalyzer analyzer = null; if (activeDocument.Language == "CSharp") { analyzer = new CSharpAnalyzer(this.Logger); } else if (activeDocument.Language == "Basic") { analyzer = new VisualBasicAnalyzer(this.Logger); } result = isSelection ? analyzer?.GetSelectionOutput(document.GetSyntaxRootAsync().Result, semanticModel, selection.Start.Position, selection.End.Position) : analyzer?.GetSingleItemOutput(document.GetSyntaxRootAsync().Result, semanticModel, caretPosition.Position); } else { ShowStatusBarMessage(serviceProvider, "No XAML copied. No profiles configured."); } return(result); }
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { try { if (sender is OleMenuCommand menuCmd) { menuCmd.Visible = menuCmd.Enabled = false; if (!AnalyzerBase.GetSettings().IsActiveProfileSet) { menuCmd.Visible = menuCmd.Enabled = true; } } } catch (Exception exc) { this.Logger.RecordException(exc); throw; } }
public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo) { var position = dragDropInfo.VirtualBufferPosition.Position; var insertLineLength = this.view.GetTextViewLineContainingBufferPosition(position).Length; ThreadHelper.JoinableTaskFactory.Run(async() => { var profile = AnalyzerBase.GetSettings().GetActiveProfile(); var logic = new DropHandlerLogic(profile, this.logger, this.vs, this.fileSystem); var textOutput = await logic.ExecuteAsync(this.draggedFilename, insertLineLength); if (!string.IsNullOrEmpty(textOutput)) { this.view.TextBuffer.Insert(position.Position, textOutput); } }); return(DragDropPointerEffects.Copy); }
private async void Execute(object sender, EventArgs e) { try { ThreadHelper.ThrowIfNotOnUIThread(); this.Logger?.RecordFeatureUsage(nameof(SetDatacontextCommand)); var settings = AnalyzerBase.GetSettings(); var profile = settings.GetActiveProfile(); var dte = await Instance.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var logic = new SetDataContextCommandLogic(profile, this.Logger, new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte)); var inXamlDoc = dte.ActiveDocument.Name.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase); var(viewName, viewModelName, vmNamespace) = logic.InferViewModelNameFromFileName(dte.ActiveDocument.Name); if (inXamlDoc) { if (profile.Datacontext.SetsXamlPageAttribute) { var(add, lineNo, content) = logic.GetPageAttributeToAdd(viewModelName, vmNamespace); if (add) { if (dte.ActiveDocument.Object("TextDocument") is TextDocument objectDoc) { objectDoc.Selection.GotoLine(lineNo); objectDoc.Selection.EndOfLine(); objectDoc.Selection.Insert(content); } } } if (profile.Datacontext.SetsAnyCodeBehindContent) { if (profile.Datacontext.SetsCodeBehindPageContent) { // TODO: ISSUE#22 - set the DC in the CB file (C# or VB) may be open and unsaved } if (profile.Datacontext.SetsCodeBehindConstructorContent) { // TODO: ISSUE#22 - set the DC in the CB file (C# or VB) may be open and unsaved } } } else { if (profile.Datacontext.SetsXamlPageAttribute) { // TODO: ISSUE#22 - set the DC in the XAML file (C# or VB) may be open and unsaved } if (profile.Datacontext.SetsAnyCodeBehindContent) { if (dte.ActiveDocument.Object("TextDocument") is TextDocument objectDoc) { var textView = await GetTextViewAsync(Instance.ServiceProvider); var caretPosition = textView.Caret.Position.BufferPosition; var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); var documentTree = await document.GetSyntaxTreeAsync(); var documentRoot = documentTree.GetRoot(); var toAdd = logic.GetCodeBehindContentToAdd(viewName, viewModelName, vmNamespace, documentRoot); foreach (var(anything, lineNo, contentToAdd) in toAdd) { if (anything) { objectDoc.Selection.GotoLine(lineNo); objectDoc.Selection.EndOfLine(); objectDoc.Selection.Insert(contentToAdd); } } } } } this.SuppressAnyException(() => dte.FormatDocument(profile)); } catch (Exception exc) { this.Logger?.RecordException(exc); throw; // Remove for launch. see issue #90 } }