internal static UndoScope Create(DTE dte, string renameOperationName) { var undo = new UndoScope(renameOperationName, dte); undo.StartUndo(); return(undo); }
public void Stack(Drawing.Axis axis, double space) { if (!this.Client.HasSelectedShapes(2)) { return; } if (space < 0.0) { throw new System.ArgumentOutOfRangeException("space", "must be non-negative"); } var application = this.Client.VisioApplication; using (var undoscope = new UndoScope(application, "Stack")) { if (axis == VA.Drawing.Axis.YAxis) { Align(null, VA.Drawing.AlignmentHorizontal.Center); } else { Align(null, VA.Drawing.AlignmentVertical.Center); } Distribute(axis, space); } }
public void AddScope(UndoScope scope) { if (scope == null) return; if (!scope.HasChanges) return; RedoStack.Clear(); UndoStack.Push(scope); if (UndoStack.Count == 1) OnPropertyChanged(nameof(CanUndo)); }
public void UndoToScope(UndoScope scopeTo) { UndoScope scope; do { scope = UndoStack.Peek(); Undo(); } while (!scopeTo.Equals(scope)); }
internal static async Task <UndoScope> CreateAsync(IVsService <DTE> dte, IProjectThreadingService threadingService, string renameOperationName, CancellationToken token = default) { var undo = new UndoScope(renameOperationName, dte, threadingService); await undo.StartUndoAsync(token); return(undo); }
public void Distribute(VA.Drawing.Axis axis, double d) { if (!this.Client.HasActiveDocument) { return; } var application = this.Client.VisioApplication; var selection = this.Client.Selection.Get(); var shapeids = selection.GetIDs(); using (var undoscope = new UndoScope(application, "Distribute")) { ArrangeHelper.DistributeWithSpacing(application.ActivePage, shapeids, axis, d); } }
private Task <bool> RenameAsync(string oldFilePath, string newFilePath, bool isCaseSensitive, string oldName, string newName, ISymbol?symbol, string renameOperationName, CancellationToken token) { token.ThrowIfCancellationRequested(); return(_unconfiguredProjectTasksService.LoadedProjectAsync(async() => { // Perform the rename operation Solution?renamedSolution = await GetRenamedSolutionAsync(oldName, oldFilePath, newFilePath, isCaseSensitive, GetCurrentProject, token); if (renamedSolution is null) { return false; } string rqName = RQName.From(symbol); Solution?solution = GetCurrentProject()?.Solution; if (solution is null) { return false; } IEnumerable <ProjectChanges> changes = renamedSolution.GetChanges(solution).GetProjectChanges(); DTE?dte = _dte.Value; Assumes.NotNull(dte); using var undo = UndoScope.Create(dte, renameOperationName); // Notify other VS features that symbol is about to be renamed NotifyBeforeRename(newName, rqName, changes); // Try and apply the changes to the current solution token.ThrowIfCancellationRequested(); if (!_roslynServices.ApplyChangesToSolution(renamedSolution.Workspace, renamedSolution)) { return false; } // Notify other VS features that symbol has been renamed NotifyAfterRename(newName, rqName, changes); return true; })); }
internal async Task HandleRenameAsync(string oldFilePath, string newFilePath) { // Do not offer to rename types if the user changes the file extensions if (!oldFilePath.EndsWith(Path.GetExtension(newFilePath), StringComparison.OrdinalIgnoreCase)) { return; } if (GetCurrentProject() is null) { return; } // see if the current project contains a compilation (bool success, bool isCaseSensitive) = await TryDetermineIfCompilationIsCaseSensitiveAsync(GetCurrentProject()); if (!success) { return; } // Check that the new name is a valid identifier in the current programming language string oldName = Path.GetFileNameWithoutExtension(oldFilePath); string newName = Path.GetFileNameWithoutExtension(newFilePath); if (!CanHandleRename(oldName, newName, isCaseSensitive)) { return; } // Check if there are any symbols that need to be renamed ISymbol?symbol = await TryGetSymbolToRename(oldName, oldFilePath, newFilePath, isCaseSensitive, GetCurrentProject); if (symbol is null) { return; } // Ask if the user wants to rename the symbol bool userConfirmed = await CheckUserConfirmation(oldName); if (!userConfirmed) { return; } // Try and apply the changes to the current solution await _projectVsServices.ThreadingService.SwitchToUIThread(); string renameOperationName = string.Format(CultureInfo.CurrentCulture, VSResources.Renaming_Type_from_0_to_1, oldName, newName); (WaitIndicatorResult result, bool renamedSolutionApplied) = _waitService.WaitForAsyncFunctionWithResult( title: VSResources.Renaming_Type, message: renameOperationName, allowCancel: true, async token => { token.ThrowIfCancellationRequested(); return(await _unconfiguredProjectTasksService.LoadedProjectAsync(async() => { // Perform the rename operation Solution?renamedSolution = await GetRenamedSolutionAsync(oldName, oldFilePath, newFilePath, isCaseSensitive, GetCurrentProject, token); if (renamedSolution is null) { return false; } string rqName = RQName.From(symbol); Solution?solution = GetCurrentProject()?.Solution; if (solution is null) { return false; } IEnumerable <ProjectChanges> changes = renamedSolution.GetChanges(solution).GetProjectChanges(); using UndoScope undo = await UndoScope.CreateAsync(_dte, _projectVsServices.ThreadingService, renameOperationName, token); // Notify other VS features that symbol is about to be renamed await NotifyBeforeRename(newName, rqName, changes); // Try and apply the changes to the current solution token.ThrowIfCancellationRequested(); bool applyChangesSucceeded = _roslynServices.ApplyChangesToSolution(renamedSolution.Workspace, renamedSolution); if (applyChangesSucceeded) { // Notify other VS features that symbol has been renamed await NotifyAfterRename(newName, rqName, changes); } return applyChangesSucceeded; })); }); // Do not warn the user if the rename was cancelled by the user if (result.WasCanceled()) { return; } // Notify the user if the rename could not be performed if (!renamedSolutionApplied) { string failureMessage = string.Format(CultureInfo.CurrentCulture, VSResources.RenameSymbolFailed, oldName); _userNotificationServices.ShowWarning(failureMessage); } Project?GetCurrentProject() { foreach (Project proj in _workspace.CurrentSolution.Projects) { if (StringComparers.Paths.Equals(proj.FilePath, _projectVsServices.Project.FullPath)) { return(proj); } } return(null); } }