private async void MenuItem_BeforeQueryStatus(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("MenuItem_BeforeQueryStatus"); try { if (sender is OleMenuCommand menuCmd) { var dte = await Instance.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var logic = new InsertGridRowDefinitionCommandLogic(this.Logger, new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte)); var showCommandButton = logic.ShouldEnableCommand(); // Changed text isn't shown until subsequent display and so wrong number may be shown ////if (showCommandButton) ////{ //// var rowNumber = logic.GetRowNumber(); //// menuCmd.Text = $"Insert new row {rowNumber} definition"; // Will need localizing if/when get this working ////} menuCmd.Visible = menuCmd.Enabled = showCommandButton; } } catch (Exception exc) { this.Logger.RecordException(exc); throw; } }
private async void Execute(object sender, EventArgs e) { try { ThreadHelper.ThrowIfNotOnUIThread(); this.Logger?.RecordFeatureUsage(nameof(InsertGridRowDefinitionCommand)); var dte = await Instance.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var vs = new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte); var activeDocText = vs.GetActiveDocumentText(); if (activeDocText.IsValidXml()) { var logic = new InsertGridRowDefinitionCommandLogic(this.Logger, vs); var replacements = logic.GetReplacements(); var(start, end, exclusions) = logic.GetGridBoundary(); var(newDefinition, newDefPos) = logic.GetDefinitionAtCursor(); vs.StartSingleUndoOperation(StringRes.Info_UndoContextIndertRowDef); try { vs.ReplaceInActiveDoc(replacements, start, end, exclusions); vs.InsertIntoActiveDocumentOnNextLine(newDefinition, newDefPos); } finally { vs.EndSingleUndoOperation(); } } else { this.Logger.RecordInfo(StringRes.Info_UnableToInsertRowDefinitionInvalidXaml); } } catch (Exception exc) { this.Logger?.RecordException(exc); throw; } }