public override void OnExecute(CommandEventArgs e) { List<SvnItem> items = new List<SvnItem>(e.Selection.GetSelectedSvnItems(true)); e.GetService<IProgressRunner>().RunModal("Running Cleanup", delegate(object sender, ProgressWorkerArgs a) { HybridCollection<string> wcs = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); foreach (SvnItem item in items) { if (!item.IsVersioned) continue; SvnWorkingCopy wc = item.WorkingCopy; if (wc != null && !wcs.Contains(wc.FullPath)) wcs.Add(wc.FullPath); } SvnCleanUpArgs args = new SvnCleanUpArgs(); args.ThrowOnError = false; foreach (string path in wcs) a.Client.CleanUp(path, args); }); }
public override void OnExecute(CommandEventArgs e) { ISvnRepositoryItem selected = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>()); if (selected == null) return; Uri uri = selected.Uri; string name = selected.Origin.Target.FileName; IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>(); using (CheckoutDialog dlg = new CheckoutDialog()) { dlg.Context = e.Context; dlg.Uri = uri; dlg.LocalPath = System.IO.Path.Combine(ss.NewProjectLocation, name); if (dlg.ShowDialog(e.Context) != DialogResult.OK) return; e.GetService<IProgressRunner>().RunModal("Checking Out", delegate(object sender, ProgressWorkerArgs a) { SvnCheckOutArgs args = new SvnCheckOutArgs(); args.Revision = dlg.Revision; args.Depth = dlg.Recursive ? SvnDepth.Infinity : SvnDepth.Files; args.IgnoreExternals = dlg.IgnoreExternals; a.Client.CheckOut(dlg.Uri, dlg.LocalPath, args); }); } }
private static void OpenSolution(CommandEventArgs e, CheckoutProject dlg) { ThreadHelper.ThrowIfNotOnUIThread(); IVsSolution2 sol = e.GetService <IVsSolution2>(typeof(SVsSolution)); if (sol != null) { sol.CloseSolutionElement(VSItemId.Root, null, 0); // Closes the current solution } IAnkhSccService scc = e.GetService <IAnkhSccService>(); if (scc != null) { scc.RegisterAsPrimarySccProvider(); // Make us the current SCC provider! } CheckOutAndOpenSolution(e, dlg.ProjectTop, dlg.Revision, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri); sol = e.GetService <IVsSolution2>(typeof(SVsSolution)); if (sol != null) { string file, user, dir; if (VSErr.Succeeded(sol.GetSolutionInfo(out dir, out file, out user)) && !string.IsNullOrEmpty(file)) { scc.SetProjectManaged(null, true); } } }
public void OnExecute(CommandEventArgs e) { SvnItem firstVersioned = null; IFileStatusCache cache = e.GetService<IFileStatusCache>(); IAnkhSolutionSettings solutionSettings = e.GetService<IAnkhSolutionSettings>(); if (solutionSettings != null) { firstVersioned = cache[solutionSettings.ProjectRoot]; } if (firstVersioned == null) return; // exceptional case using (IssueTrackerConfigDialog dialog = new IssueTrackerConfigDialog(e.Context)) { if (dialog.ShowDialog(e.Context) == System.Windows.Forms.DialogResult.OK) { IIssueTrackerSettings currentSettings = e.GetService<IIssueTrackerSettings>(); IssueRepository newRepository = dialog.NewIssueRepository; if (newRepository == null || string.IsNullOrEmpty(newRepository.ConnectorName) || newRepository.RepositoryUri == null) { DeleteIssueRepositoryProperties(e.Context, firstVersioned); } else if (currentSettings == null || currentSettings.ShouldPersist(newRepository)) { SetIssueRepositoryProperties(e.Context, firstVersioned, newRepository); } } } }
public override void OnExecute(CommandEventArgs e) { ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); if (cache == null || e.Selection.SolutionFilename == null) { return; } if (!e.State.SccProviderActive) { // Ok, we should now enable ourselves as the SCC provider to get // our state loaded IAnkhSccService sccService = e.GetService <IAnkhSccService>(); sccService.RegisterAsPrimarySccProvider(); sccService.EnsureLoaded(); } SvnItem item = cache[e.Selection.SolutionFilename]; if (!HandleUnmanagedOrUnversionedSolution(e, item)) { return; } if (e.Command == AnkhCommand.FileSccAddSolutionToSubversion) { return; } SetProjectsManaged(e); }
static void Resolve(CommandEventArgs e, SvnAccept accept) { HybridCollection <string> paths = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (!item.IsConflicted) { continue; } if (!paths.Contains(item.FullPath)) { paths.Add(item.FullPath); } } IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); documentTracker.SaveDocuments(paths); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(paths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) using (SvnClient client = e.GetService <ISvnClientPool>().GetNoUIClient()) { SvnResolveArgs a = new SvnResolveArgs(); a.Depth = SvnDepth.Empty; foreach (string p in paths) { client.Resolve(p, accept, a); } } }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> toResolve = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.IsCasingConflicted) { toResolve.Add(item); } } try { foreach (SvnItem item in toResolve) { string svnPath = GetSvnCasing(item); string actualPath = SvnTools.GetTruePath(item.FullPath); if (svnPath == null || actualPath == null) { continue; // not found } if (!string.Equals(svnPath, actualPath, StringComparison.OrdinalIgnoreCase)) { continue; // More than casing rename } string svnName = Path.GetFileName(svnPath); string actualName = Path.GetFileName(actualPath); if (svnName == actualName) { continue; // Can't fix directories! } IAnkhOpenDocumentTracker odt = e.GetService <IAnkhOpenDocumentTracker>(); using (odt.LockDocument(svnPath, DocumentLockType.NoReload)) using (odt.LockDocument(actualPath, DocumentLockType.NoReload)) { try { // Try the actual rename File.Move(actualPath, svnPath); } catch { } try { // And try to fix the project+document system VsShellUtilities.RenameDocument(e.Context, actualPath, svnPath); } catch { } } } } finally { e.GetService <IFileStatusMonitor>().ScheduleSvnStatus(SvnItem.GetPaths(toResolve)); } }
public override void OnExecute(CommandEventArgs e) { AnkhConfig config = e.GetService <IAnkhConfigurationService>().Instance; ICollection <SvnItem> targets; if (!e.DontPrompt && (e.PromptUser || (!Shift && !config.SuppressLockingUI))) { using (PendingChangeSelector selector = new PendingChangeSelector()) { selector.Text = CommandStrings.UnlockTitle; selector.PreserveWindowPlacement = true; selector.LoadItems(new List <SvnItem>(e.Selection.GetSelectedSvnItems(true)), delegate(SvnItem i) { return(i.IsLocked); }, delegate(SvnItem i) { return(i.IsLocked); }); if (selector.ShowDialog(e.Context) != DialogResult.OK) { return; } targets = new List <SvnItem>(selector.GetSelectedItems()); } } else { List <SvnItem> toUnlock = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (item.IsLocked) { toUnlock.Add(item); } } targets = toUnlock; } if (targets.Count == 0) { return; } List <string> files = new List <string>(SvnItem.GetPaths(targets)); if (files.Count == 0) { return; } e.GetService <IProgressRunner>().RunModal( CommandStrings.UnlockTitle, delegate(object sender, ProgressWorkerArgs ee) { SvnUnlockArgs ua = new SvnUnlockArgs(); ee.Client.Unlock(files, ua); }); }
public override void OnExecute(CommandEventArgs e) { SvnItem node = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); IAnkhCommandService cmd = e.GetService<IAnkhCommandService>(); switch (e.Command) { case AnkhCommand.ItemSelectInRepositoryExplorer: if (node == null || node.Uri == null) return; if (cmd != null) cmd.DirectlyExecCommand(AnkhCommand.RepositoryBrowse, node.FullPath); break; case AnkhCommand.ItemSelectInWorkingCopyExplorer: if (node == null || !node.Exists) return; if (cmd != null) cmd.DirectlyExecCommand(AnkhCommand.WorkingCopyBrowse, node.FullPath); break; case AnkhCommand.ItemSelectInSolutionExplorer: if (node == null) return; IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer)); IVsProject project = VsShellUtilities.GetProject(e.Context, node.FullPath) as IVsProject; if (hierWindow != null) { int found; uint id; VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; if (project != null && ErrorHandler.Succeeded(project.IsDocumentInProject(node.FullPath, out found, prio, out id)) && found != 0) { hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem); } else if (string.Equals(node.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase)) hierWindow.ExpandItem(e.GetService<IVsUIHierarchy>(typeof(SVsSolution)), VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem); // Now try to activate the solution explorer IVsWindowFrame solutionExplorer; Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer); IVsUIShell shell = e.GetService<IVsUIShell>(typeof(SVsUIShell)); if (shell != null) { shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer); if (solutionExplorer != null) solutionExplorer.Show(); } } break; } }
public override void OnExecute(CommandEventArgs e) { IPendingChangesManager pcm = e.GetService <IPendingChangesManager>(); PendingChange.RefreshContext rc = new PendingChange.RefreshContext(e.Context); Dictionary <string, PendingChange> selectedChanges = new Dictionary <string, PendingChange>(StringComparer.OrdinalIgnoreCase); List <SvnItem> resources = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { PendingChange pc; if (PendingChange.CreateIfPending(rc, item, out pc)) { if (!pc.IsNoChangeForPatching()) { selectedChanges.Add(pc.FullPath, pc); resources.Add(pc.SvnItem); } } } if (resources.Count == 0) { return; } using (PendingChangeSelector pcs = new PendingChangeSelector()) { pcs.Text = CommandStrings.CreatePatchTitle; pcs.PreserveWindowPlacement = true; pcs.LoadItems(resources); DialogResult dr = pcs.ShowDialog(e.Context); if (dr != DialogResult.OK) { return; } string fileName = GetFileName(e.Context.DialogOwner); if (string.IsNullOrEmpty(fileName)) { return; } PendingChangeCreatePatchArgs pca = new PendingChangeCreatePatchArgs(); pca.FileName = fileName; IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); pca.RelativeToPath = ss.ProjectRoot; pca.AddUnversionedFiles = true; List <PendingChange> patchChanges = new List <PendingChange>(pcs.GetSelection()); e.GetService <IPendingChangeHandler>().CreatePatch(patchChanges, pca); } }
/// <see cref="Ankh.Commands.ICommandHandler.OnExecute" /> public void OnExecute(CommandEventArgs e) { List<SvnItem> svnItems = new List<SvnItem>(); IFileStatusCache cache = e.GetService<IFileStatusCache>(); switch (e.Command) { case AnkhCommand.ItemMerge: // TODO: Check for solution and/or project selection to use the folder instead of the file foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { svnItems.Add(item); } break; case AnkhCommand.ProjectMerge: foreach (SvnProject p in e.Selection.GetSelectedProjects(false)) { IProjectFileMapper pfm = e.GetService<IProjectFileMapper>(); ISvnProjectInfo info = pfm.GetProjectInfo(p); if (info != null && info.ProjectDirectory != null) { svnItems.Add(cache[info.ProjectDirectory]); } } break; case AnkhCommand.SolutionMerge: svnItems.Add(cache[e.GetService<IAnkhSolutionSettings>().ProjectRoot]); break; default: throw new InvalidOperationException(); } IEnumerable<string> selectedFiles = e.Selection.GetSelectedFiles(true); IAnkhOpenDocumentTracker tracker = e.GetService<IAnkhOpenDocumentTracker>(); using (DocumentLock lck = tracker.LockDocuments(selectedFiles, DocumentLockType.ReadOnly)) using (lck.MonitorChangesForReload()) using (MergeWizard dialog = new MergeWizard(e.Context, svnItems[0])) { DialogResult result = dialog.ShowDialog(e.Context); //result = uiService.ShowDialog(dialog); if (result == DialogResult.OK) { using (MergeResultsDialog mrd = new MergeResultsDialog()) { mrd.MergeActions = dialog.MergeActions; mrd.ResolvedMergeConflicts = dialog.ResolvedMergeConflicts; mrd.ShowDialog(e.Context); } } } }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IAnkhCommandService>(); if (_pendingChanges == null) _pendingChanges = e.GetService<PendingChangeManager>(typeof(IPendingChangesManager)); _commandService.TockCommand(e.Command); _pendingChanges.OnTickRefresh(); }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IAnkhCommandService>(); if (_projectNotifier == null) _projectNotifier = e.GetService<ProjectNotifier>(typeof(IFileStatusMonitor)); _commandService.TockCommand(e.Command); _projectNotifier.HandleEvent(e.Command); }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IAnkhCommandService>(); if (_fileCache == null) _fileCache = e.GetService<FileStatusCache>(typeof(IFileStatusCache)); _commandService.TockCommand(e.Command); if (e.Command == AnkhCommand.FileCacheFinishTasks) _fileCache.OnCleanup(); else _fileCache.BroadcastChanges(); }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IAnkhCommandService>(); if (_projectTracker == null) _projectTracker = e.GetService<ProjectTracker>(typeof(IAnkhProjectDocumentTracker)); if(_sccProvider == null) _sccProvider = e.GetService<AnkhSccProvider>(typeof(IAnkhSccService)); _commandService.TockCommand(e.Command); _projectTracker.OnSccCleanup(e); _sccProvider.OnSccCleanup(e); }
public override void OnExecute(CommandEventArgs e) { PathSelectorResult result = ShowDialog(e); if (!result.Succeeded) return; SvnRevisionRange revRange = new SvnRevisionRange(result.RevisionStart, result.RevisionEnd); IAnkhTempFileManager tempfiles = e.GetService<IAnkhTempFileManager>(); string tempFile = tempfiles.GetTempFile(".patch"); IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>(); string slndir = ss.ProjectRoot; string slndirP = slndir + "\\"; SvnDiffArgs args = new SvnDiffArgs(); args.IgnoreAncestry = true; args.NoDeleted = false; args.Depth = result.Depth; using (MemoryStream stream = new MemoryStream()) { e.Context.GetService<IProgressRunner>().RunModal("Diffing", delegate(object sender, ProgressWorkerArgs ee) { foreach (SvnItem item in result.Selection) { SvnWorkingCopy wc; if (!string.IsNullOrEmpty(slndir) && item.FullPath.StartsWith(slndirP, StringComparison.OrdinalIgnoreCase)) args.RelativeToPath = slndir; else if ((wc = item.WorkingCopy) != null) args.RelativeToPath = wc.FullPath; else args.RelativeToPath = null; ee.Client.Diff(item.FullPath, revRange, args, stream); } stream.Flush(); stream.Position = 0; }); using (StreamReader sr = new StreamReader(stream)) { File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8); VsShellUtilities.OpenDocument(e.Context, tempFile); } } }
public override void OnExecute(CommandEventArgs e) { using (ProjectCommitDialog dlg = new ProjectCommitDialog()) { dlg.Context = e.Context; dlg.PreserveWindowPlacement = true; dlg.LoadChanges(GetChanges(e)); dlg.LogMessageText = logMessage ?? ""; dlg.IssueNumberText = issueId ?? ""; DialogResult dr = dlg.ShowDialog(e.Context); logMessage = dlg.LogMessageText; issueId = dlg.IssueNumberText; if (dr == DialogResult.OK) { PendingChangeCommitArgs pca = new PendingChangeCommitArgs(); pca.StoreMessageOnError = true; // TODO: Commit it! List <PendingChange> toCommit = new List <PendingChange>(dlg.GetSelection()); dlg.FillArgs(pca); if (e.GetService <IPendingChangeHandler>().Commit(toCommit, pca)) { logMessage = issueId = null; } } } }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> items = new List <SvnItem>(e.Selection.GetSelectedSvnItems(true)); e.GetService <IProgressRunner>().RunModal(CommandStrings.CleaningWorkingCopy, delegate(object sender, ProgressWorkerArgs a) { HybridCollection <string> wcs = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); foreach (SvnItem item in items) { if (!item.IsVersioned) { continue; } SvnWorkingCopy wc = item.WorkingCopy; if (wc != null && !wcs.Contains(wc.FullPath)) { wcs.Add(wc.FullPath); } } SvnCleanUpArgs args = new SvnCleanUpArgs(); args.ThrowOnError = false; foreach (string path in wcs) { a.Client.CleanUp(path, args); } }); }
public override void OnExecute(CommandEventArgs e) { using (ProjectCommitDialog dlg = new ProjectCommitDialog()) { dlg.Context = e.Context; dlg.PreserveWindowPlacement = true; dlg.LoadChanges(GetChanges(e)); dlg.LogMessageText = logMessage ?? ""; dlg.IssueNumberText = issueId ?? ""; DialogResult dr = dlg.ShowDialog(e.Context); logMessage = dlg.LogMessageText; issueId = dlg.IssueNumberText; if (dr == DialogResult.OK) { PendingChangeCommitArgs pca = new PendingChangeCommitArgs(); pca.StoreMessageOnError = true; // TODO: Commit it! List<PendingChange> toCommit = new List<PendingChange>(dlg.GetSelection()); dlg.FillArgs(pca); if (e.GetService<IPendingChangeHandler>().Commit(toCommit, pca)) { logMessage = issueId = null; } } } }
private static IEnumerable <SvnItem> GetAllUpdateRoots(CommandEventArgs e) { // Duplicate handling is handled above this method! ISvnSolutionLayout pls = e.GetService <ISvnSolutionLayout>(); if (IsSolutionCommand(e.Command)) { foreach (SvnItem item in pls.GetUpdateRoots(null)) { yield return(item); } } else if (IsFolderCommand(e.Command)) { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { // Everything is checked in the OnUpdate yield return(item); } } else { foreach (SccProject project in GetSelectedProjects(e)) { foreach (SvnItem item in pls.GetUpdateRoots(project)) { yield return(item); } } } }
public override void OnExecute(CommandEventArgs e) { using (ProjectCommitDialog pcd = new ProjectCommitDialog()) { pcd.Context = e.Context; pcd.LogMessageText = storedLogMessage; pcd.IssueNumberText = storedIssueNumber; pcd.PreserveWindowPlacement = true; pcd.LoadItems(e.Selection.GetSelectedSvnItems(true)); DialogResult dr = pcd.ShowDialog(e.Context); storedLogMessage = pcd.LogMessageText; storedIssueNumber = pcd.IssueNumberText; if (dr != DialogResult.OK) return; PendingChangeCommitArgs pca = new PendingChangeCommitArgs(); pca.StoreMessageOnError = true; // TODO: Commit it! List<PendingChange> toCommit = new List<PendingChange>(pcd.GetSelection()); pcd.FillArgs(pca); e.GetService<IPendingChangeHandler>().Commit(toCommit, pca); } // not in the finally, because we want to preserve the message for a // non-successful commit storedLogMessage = null; storedIssueNumber = null; }
private static void ShowUpdate(CommandEventArgs e) { string[] args; try { args = (string[])e.Argument; } catch { return; } if (args == null || args.Length < 8) { return; } string title = args[0], header = args[1], description = args[2], url = args[3], urltext = args[4], version = args[5], newVersion = args[6], tag = args[7]; using (UpdateAvailableDialog uad = new UpdateAvailableDialog()) { try { uad.Text = string.Format(uad.Text, title); uad.headLabel.Text = header; uad.bodyLabel.Text = description; uad.linkLabel.Text = urltext; uad.linkLabel.Links.Add(0, urltext.Length).LinkData = url; if (!string.IsNullOrEmpty(version)) { uad.newVerLabel.Text = newVersion; uad.curVerLabel.Text = GetUIVersion(e.Context).ToString(3); uad.versionPanel.Enabled = uad.versionPanel.Visible = true; } if (string.IsNullOrEmpty(tag)) { uad.sameCheck.Enabled = uad.sameCheck.Visible = false; } } catch { return; // Don't throw a visible exception from a background check! } uad.ShowDialog(e.Context); if (uad.sameCheck.Checked) { IAnkhConfigurationService config = e.GetService <IAnkhConfigurationService>(); using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck")) { rk.SetValue("SkipTag", tag); } } } }
public override void OnExecute(CommandEventArgs e) { List<SvnItem> toResolve = new List<SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.IsCasingConflicted) { toResolve.Add(item); } } try { foreach (SvnItem item in toResolve) { string svnPath = GetSvnCasing(item); string actualPath = SvnTools.GetTruePath(item.FullPath); if (svnPath == null || actualPath == null) continue; // not found if (!string.Equals(svnPath, actualPath, StringComparison.OrdinalIgnoreCase)) continue; // More than casing rename string svnName = Path.GetFileName(svnPath); string actualName = Path.GetFileName(actualPath); if (svnName == actualName) continue; // Can't fix directories! IAnkhOpenDocumentTracker odt = e.GetService<IAnkhOpenDocumentTracker>(); using (odt.LockDocument(svnPath, DocumentLockType.NoReload)) using (odt.LockDocument(actualPath, DocumentLockType.NoReload)) { try { // Try the actual rename File.Move(actualPath, svnPath); } catch { } try { // And try to fix the project+document system VsShellUtilities.RenameDocument(e.Context, actualPath, svnPath); } catch { } } } } finally { e.GetService<IFileStatusMonitor>().ScheduleSvnStatus(SvnItem.GetPaths(toResolve)); } }
static void AddPathToSubversion(CommandEventArgs e, string path) { using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient()) { SvnAddArgs aa = new SvnAddArgs(); aa.AddParents = true; aa.AddExpectedError(SvnErrorCode.SVN_ERR_ENTRY_EXISTS); // Don't fail on already added nodes. (<= 1.7) aa.AddExpectedError(SvnErrorCode.SVN_ERR_WC_PATH_FOUND); // Don't fail on already added nodes. (1.8+?) cl.Add(path, aa); } }
static bool HandleUnmanagedOrUnversionedSolution(CommandEventArgs e, SvnItem solutionItem) { IAnkhSccService scc = e.GetService <IAnkhSccService>(); AnkhMessageBox mb = new AnkhMessageBox(e.Context); bool shouldActivate = false; if (!scc.IsActive) { if (e.State.OtherSccProviderActive) { return(false); // Can't switch in this case.. Nothing to do } // Ankh is not the active provider, we should register as active shouldActivate = true; } if (scc.IsSolutionManaged && solutionItem.IsVersioned) { return(true); // Projects should still be checked } bool confirmed = false; if (solutionItem.IsVersioned) { /* File is in subversion; just enable */ } else if (solutionItem.IsVersionable) { if (!AddVersionableSolution(e, solutionItem, ref confirmed)) { return(false); } } else { if (!CheckoutWorkingCopyForSolution(e, ref confirmed)) { return(false); } } if (!confirmed && !e.DontPrompt && !e.IsInAutomation && DialogResult.Yes != mb.Show(string.Format(CommandStrings.MarkXAsManaged, Path.GetFileName(e.Selection.SolutionFilename)), "", MessageBoxButtons.YesNo)) { return(false); } SetSolutionManaged(shouldActivate, solutionItem, scc); return(true); }
public override void OnExecute(CommandEventArgs e) { IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>(); IAnkhDiffHandler diff = e.GetService<IAnkhDiffHandler>(); AnkhPatchArgs args = new AnkhPatchArgs(); args.ApplyTo = ss.ProjectRoot; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "Patch files( *.patch)|*.patch|Diff files (*.diff)|*.diff|" + "Text files (*.txt)|*.txt|All files (*.*)|*"; if (ofd.ShowDialog(e.Context.DialogOwner) != DialogResult.OK) return; args.PatchFile = ofd.FileName; } diff.RunPatch(args); }
public void OnExecute(CommandEventArgs e) { IAnkhConfigurationService configSvc = e.GetService<IAnkhConfigurationService>(); if (configSvc != null) { AnkhConfig cfg = configSvc.Instance; using (ConfigureRecentChangesPageDialog dlg = new ConfigureRecentChangesPageDialog()) { int seconds = Math.Max(0, cfg.RecentChangesRefreshInterval); dlg.RefreshInterval = seconds / 60; if (dlg.ShowDialog(e.Context) == System.Windows.Forms.DialogResult.OK) { cfg.RecentChangesRefreshInterval = Math.Max(dlg.RefreshInterval * 60, 0); configSvc.SaveConfig(cfg); RecentChangesPage rcPage = e.GetService<RecentChangesPage>(); if (rcPage != null) rcPage.RefreshIntervalConfigModified(); } } } }
public override void OnExecute(CommandEventArgs e) { string info; if (e.Argument is string) { // Allow opening from info = (string)e.Argument; } else if (e.Command == AnkhCommand.WorkingCopyAdd) { using (AddWorkingCopyExplorerRootDialog dlg = new AddWorkingCopyExplorerRootDialog()) { DialogResult dr = dlg.ShowDialog(e.Context); if (dr != DialogResult.OK || string.IsNullOrEmpty(dlg.NewRoot)) return; info = dlg.NewRoot; } } else throw new InvalidOperationException("WorkingCopyBrowse was called without a path"); if (!string.IsNullOrEmpty(info)) { WorkingCopyExplorerControl ctrl = e.Selection.ActiveDialogOrFrameControl as WorkingCopyExplorerControl; if (ctrl == null) { IAnkhPackage pkg = e.GetService<IAnkhPackage>(); pkg.ShowToolWindow(AnkhToolWindow.WorkingCopyExplorer); } ctrl = e.Selection.ActiveDialogOrFrameControl as WorkingCopyExplorerControl; if (ctrl != null) { switch (e.Command) { case AnkhCommand.WorkingCopyAdd: ctrl.AddRoot(info); break; case AnkhCommand.WorkingCopyBrowse: ctrl.BrowsePath(e.Context, info); break; } } } }
public override void OnExecute(CommandEventArgs e) { IFileStatusMonitor fsm = e.GetService<IFileStatusMonitor>(); foreach (SvnItem i in GetSelection(e)) { if (i.InSolution) continue; if (e.Command == AnkhCommand.ItemAddToPending || e.Command == AnkhCommand.DocumentAddToPending) fsm.ScheduleMonitor(i.FullPath); else fsm.StopMonitoring(i.FullPath); } }
public override void OnExecute(CommandEventArgs e) { // Refresh all global states on the selected files // * File Status Cache // * Glyph cache (in VS Projects) // * Pending changes // * Editor dirty state // Don't handle individual windows here, they can just override the refresh handler // See WorkingCopyExplorerControl.OnFrameCreated() for some examples on how to do that IFileStatusMonitor monitor = e.GetService<IFileStatusMonitor>(); monitor.ScheduleSvnStatus(e.Selection.GetSelectedFiles(true)); IAnkhOpenDocumentTracker dt = e.GetService<IAnkhOpenDocumentTracker>(); dt.RefreshDirtyState(); IPendingChangesManager pm = e.GetService<IPendingChangesManager>(); pm.Refresh((string)null); // Perform a full incremental refresh on the PC window }
static void Resolved(CommandEventArgs e) { using (SvnClient client = e.GetService <ISvnClientPool>().GetNoUIClient()) { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (!item.IsConflicted) { continue; } client.Resolved(item.FullPath); } } }
public override void OnExecute(CommandEventArgs e) { IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); IAnkhDiffHandler diff = e.GetService <IAnkhDiffHandler>(); AnkhPatchArgs args = new AnkhPatchArgs(); args.ApplyTo = ss.ProjectRoot; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "Patch files( *.patch)|*.patch|Diff files (*.diff)|*.diff|" + "Text files (*.txt)|*.txt|All files (*.*)|*"; if (ofd.ShowDialog(e.Context.DialogOwner) != DialogResult.OK) { return; } args.PatchFile = ofd.FileName; } diff.RunPatch(args); }
private static void CheckOutAndOpenSolution(CommandEventArgs e, SvnUriTarget checkoutLocation, SvnRevision revision, Uri projectTop, string localDir, Uri projectUri) { IProgressRunner runner = e.GetService <IProgressRunner>(); runner.RunModal(CommandStrings.CheckingOutSolution, delegate(object sender, ProgressWorkerArgs ee) { PerformCheckout(ee, checkoutLocation, revision, localDir); }); Uri file = projectTop.MakeRelativeUri(projectUri); string projectFile = SvnTools.GetNormalizedFullPath(Path.Combine(localDir, SvnTools.UriPartToPath(file.ToString()))); OpenProject(e, projectFile); }
public override void OnExecute(CommandEventArgs e) { IFileStatusCache cache = e.GetService<IFileStatusCache>(); if (cache == null || e.Selection.SolutionFilename == null) return; SvnItem item = cache[e.Selection.SolutionFilename]; if (!HandleUnmanagedOrUnversionedSolution(e, item)) return; if (e.Command == AnkhCommand.FileSccAddSolutionToSubversion) return; SetProjectsManaged(e); }
protected static bool SaveFile(CommandEventArgs e, ISvnRepositoryItem ri, string toFile) { ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal( "Saving File", delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(toFile)) { SvnWriteArgs args = new SvnWriteArgs(); if(ri.Revision != null) args.Revision = ri.Revision; ee.Client.Write(ri.Origin.Target, fs, args); } }); return r.Succeeded; }
protected static bool SaveFile(CommandEventArgs e, ISvnRepositoryItem ri, string toFile) { ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingFileForComparison, delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(toFile)) { SvnWriteArgs args = new SvnWriteArgs(); if (ri.Revision != null) { args.Revision = ri.Revision; } ee.Client.Write(ri.Origin.Target, fs, args); } }); return(r.Succeeded); }
public override void OnExecute(CommandEventArgs e) { IFileStatusMonitor fsm = e.GetService <IFileStatusMonitor>(); foreach (SvnItem i in GetSelection(e)) { if (i.InSolution) { continue; } if (e.Command == AnkhCommand.ItemAddToPending || e.Command == AnkhCommand.DocumentAddToPending) { fsm.ScheduleMonitor(i.FullPath); } else { fsm.StopMonitoring(i.FullPath); } } }
public override void OnExecute(CommandEventArgs e) { using (ExportDialog dlg = new ExportDialog(e.Context)) { dlg.OriginPath = EnumTools.GetSingle(e.Selection.GetSelectedSvnItems(false)).FullPath; if (dlg.ShowDialog(e.Context) != DialogResult.OK) return; SvnDepth depth = dlg.NonRecursive ? SvnDepth.Empty : SvnDepth.Infinity; e.GetService<IProgressRunner>().RunModal(CommandStrings.Exporting, delegate(object sender, ProgressWorkerArgs wa) { SvnExportArgs args = new SvnExportArgs(); args.Depth = depth; args.Revision = dlg.Revision; wa.Client.Export(dlg.ExportSource, dlg.LocalPath, args); }); } }
public override void OnExecute(CommandEventArgs e) { IAnkhPackage package = e.Context.GetService<IAnkhPackage>(); AnkhToolWindow toolWindow; switch (e.Command) { case AnkhCommand.ShowPendingChanges: toolWindow = AnkhToolWindow.PendingChanges; break; case AnkhCommand.ShowWorkingCopyExplorer: toolWindow = AnkhToolWindow.WorkingCopyExplorer; break; case AnkhCommand.ShowRepositoryExplorer: toolWindow = AnkhToolWindow.RepositoryExplorer; break; case AnkhCommand.ShowSubversionInfo: toolWindow = AnkhToolWindow.SvnInfo; break; default: return; } package.ShowToolWindow(toolWindow); if (e.Command == AnkhCommand.ShowRepositoryExplorer) { IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>(); if (ss.ProjectRootUri != null) { RepositoryExplorerControl ctrl = e.Selection.ActiveDialogOrFrameControl as RepositoryExplorerControl; if (ctrl != null) ctrl.AddRoot(ss.ProjectRootUri); } } }
public override void OnExecute(CommandEventArgs e) { using (ProjectCommitDialog pcd = new ProjectCommitDialog()) { pcd.Context = e.Context; pcd.LogMessageText = storedLogMessage; pcd.IssueNumberText = storedIssueNumber; pcd.PreserveWindowPlacement = true; bool recursive = (e.Command != AnkhCommand.CommitProjectFile); pcd.LoadItems(e.Selection.GetSelectedSvnItems(recursive)); DialogResult dr = pcd.ShowDialog(e.Context); storedLogMessage = pcd.LogMessageText; storedIssueNumber = pcd.IssueNumberText; if (dr != DialogResult.OK) { return; } PendingChangeCommitArgs pca = new PendingChangeCommitArgs(); pca.StoreMessageOnError = true; List <PendingChange> toCommit = new List <PendingChange>(pcd.GetSelection()); pcd.FillArgs(pca); e.GetService <IPendingChangeHandler>().Commit(toCommit, pca); } // not in the finally, because we want to preserve the message for a // non-successful commit storedLogMessage = null; storedIssueNumber = null; }
public override void OnExecute(CommandEventArgs e) { SvnItem root = GetRoot(e); if (root == null) { return; } using (CreateBranchDialog dlg = new CreateBranchDialog()) { if (e.Command == AnkhCommand.ProjectBranch) { dlg.Text = CommandStrings.BranchProject; } dlg.SrcFolder = root.FullPath; dlg.SrcUri = root.Uri; dlg.EditSource = false; dlg.Revision = root.Status.Revision; RepositoryLayoutInfo info; if (RepositoryUrlUtils.TryGuessLayout(e.Context, root.Uri, out info)) { dlg.NewDirectoryName = new Uri(info.BranchesRoot, "."); } while (true) { if (DialogResult.OK != dlg.ShowDialog(e.Context)) { return; } string msg = dlg.LogMessage; bool retry = false; bool ok = false; ProgressRunnerResult rr = e.GetService <IProgressRunner>().RunModal(CommandStrings.CreatingBranch, delegate(object sender, ProgressWorkerArgs ee) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (ee.Client.Info(dlg.NewDirectoryName, ia, null)) { DialogResult dr = DialogResult.Cancel; ee.Synchronizer.Invoke((AnkhAction) delegate { AnkhMessageBox mb = new AnkhMessageBox(ee.Context); dr = mb.Show(string.Format("The Branch/Tag at Url '{0}' already exists.", dlg.NewDirectoryName), "Path Exists", MessageBoxButtons.RetryCancel); }, null); if (dr == DialogResult.Retry) { // show dialog again to let user modify the branch URL retry = true; } } else { SvnCopyArgs ca = new SvnCopyArgs(); ca.CreateParents = true; ca.LogMessage = msg; ok = dlg.CopyFromUri ? ee.Client.RemoteCopy(new SvnUriTarget(dlg.SrcUri, dlg.SelectedRevision), dlg.NewDirectoryName, ca) : ee.Client.RemoteCopy(dlg.SrcFolder, dlg.NewDirectoryName, ca); } }); if (rr.Succeeded && ok && dlg.SwitchToBranch) { e.GetService <IAnkhCommandService>().PostExecCommand(AnkhCommand.SolutionSwitchDialog, dlg.NewDirectoryName); } if (!retry) { break; } } } }
static void SetProjectsManaged(CommandEventArgs e) { IFileStatusCache cache = e.GetService<IFileStatusCache>(); IFileStatusMonitor monitor = e.GetService<IFileStatusMonitor>(); IAnkhSccService scc = e.GetService<IAnkhSccService>(); IProjectFileMapper mapper = e.GetService<IProjectFileMapper>(); AnkhMessageBox mb = new AnkhMessageBox(e.Context); if (mapper == null) return; List<SvnProject> projectsToBeManaged = new List<SvnProject>(); SvnItem slnItem = cache[e.Selection.SolutionFilename]; Uri solutionReposRoot = slnItem.WorkingCopy.RepositoryRoot; foreach (SvnProject project in GetSelection(e.Selection)) { ISvnProjectInfo projInfo = mapper.GetProjectInfo(project); if (projInfo == null || projInfo.ProjectDirectory == null || !projInfo.IsSccBindable) continue; // Some projects can't be managed SvnItem projectDir = cache[projInfo.ProjectDirectory]; if (projectDir.WorkingCopy == slnItem.WorkingCopy) { // This is a 'normal' project, part of the solution and in the same working copy projectsToBeManaged.Add(project); continue; } bool markAsManaged; bool writeReference; if (projectDir.IsVersioned) continue; // We don't have to add this one if (projectDir.IsVersionable) { SvnItem parentDir = GetVersionedParent(projectDir); Debug.Assert(parentDir != null); DialogResult rslt = mb.Show(string.Format(CommandResources.AddXToExistingWcY, Path.GetFileName(projInfo.ProjectName), parentDir.FullPath), AnkhId.PlkProduct, MessageBoxButtons.YesNoCancel); switch (rslt) { case DialogResult.Cancel: return; case DialogResult.No: if (CheckoutWorkingCopyForProject(e, projInfo, solutionReposRoot, out markAsManaged, out writeReference)) { if (markAsManaged) scc.SetProjectManaged(project, true); if (writeReference) scc.EnsureCheckOutReference(project); continue; } break; case DialogResult.Yes: projectsToBeManaged.Add(project); AddPathToSubversion(e, projInfo.ProjectFile ?? projInfo.ProjectDirectory); continue; } } else { // We have to checkout (and create repository location) if (CheckoutWorkingCopyForProject(e, projInfo, solutionReposRoot, out markAsManaged, out writeReference)) { if (markAsManaged) scc.SetProjectManaged(project, true); if (writeReference) scc.EnsureCheckOutReference(project); continue; } } } if (!AskSetManagedSelectionProjects(e, mapper, scc, projectsToBeManaged)) return; foreach (SvnProject project in projectsToBeManaged) { if (!scc.IsProjectManaged(project)) { scc.SetProjectManaged(project, true); monitor.ScheduleSvnStatus(mapper.GetAllFilesOf(project)); // Update for 'New' status } } }
static bool HandleUnmanagedOrUnversionedSolution(CommandEventArgs e, SvnItem solutionItem) { IAnkhSccService scc = e.GetService<IAnkhSccService>(); AnkhMessageBox mb = new AnkhMessageBox(e.Context); bool shouldActivate = false; if (!scc.IsActive) { if (e.State.OtherSccProviderActive) return false; // Can't switch in this case.. Nothing to do // Ankh is not the active provider, we should register as active shouldActivate = true; } if (scc.IsSolutionManaged && solutionItem.IsVersioned) return true; // Projects should still be checked bool confirmed = false; if (solutionItem.IsVersioned) { /* File is in subversion; just enable */ } else if (solutionItem.IsVersionable) { if (!AddVersionableSolution(e, solutionItem, ref confirmed)) return false; } else { if (!CheckoutWorkingCopyForSolution(e, ref confirmed)) return false; } if (!confirmed && !e.DontPrompt && !e.IsInAutomation && DialogResult.Yes != mb.Show(string.Format(CommandResources.MarkXAsManaged, Path.GetFileName(e.Selection.SolutionFilename)), "", MessageBoxButtons.YesNo)) { return false; } SetSolutionManaged(shouldActivate, solutionItem, scc); return true; }
/// <summary> /// Returns false if the AddToSubversionDialog has been cancelled, true otherwise /// </summary> /// <param name="e"></param> /// <param name="projectInfo"></param> /// <param name="solutionReposRoot"></param> /// <param name="shouldMarkAsManaged"></param> /// <param name="storeReference"></param> /// <returns></returns> static bool CheckoutWorkingCopyForProject(CommandEventArgs e, ISvnProjectInfo projectInfo, Uri solutionReposRoot, out bool shouldMarkAsManaged, out bool storeReference) { shouldMarkAsManaged = false; storeReference = false; using (SvnClient cl = e.GetService<ISvnClientPool>().GetClient()) using (AddProjectToSubversion dialog = new AddProjectToSubversion()) { dialog.Context = e.Context; dialog.PathToAdd = projectInfo.ProjectDirectory; dialog.RepositoryAddUrl = solutionReposRoot; if (dialog.ShowDialog(e.Context) != DialogResult.OK) return false; // User cancelled the "Add to subversion" dialog, don't set as managed by Ankh Collection<SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) return false; // Create failed; bail out } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); shouldMarkAsManaged = dialog.MarkAsManaged; storeReference = dialog.WriteCheckOutInformation; } return true; }
public override void OnExecute(CommandEventArgs e) { List <string> toAdd = new List <string>(); List <SvnItem> items = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (item.IsVersioned) { items.Add(item); } else if (item.IsFile && item.IsVersionable && item.InSolution && !item.IsIgnored && !item.IsSccExcluded) { toAdd.Add(item.FullPath); // Add new files ### Alternative: Show them as added items.Add(item); } } if (items.Count == 0) { return; } SvnRevision start = SvnRevision.Base; SvnRevision end = SvnRevision.Working; // should we show the path selector? if (e.ShouldPrompt(true)) { using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog()) { dlg.Text = CommandStrings.UnifiedDiffTitle; dlg.Items = items; dlg.RevisionStart = start; dlg.RevisionEnd = end; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } items.Clear(); items.AddRange(dlg.GetCheckedItems()); start = dlg.RevisionStart; end = dlg.RevisionEnd; } } if (items.Count == 0) { return; } SvnRevisionRange revRange = new SvnRevisionRange(start, end); IAnkhTempFileManager tempfiles = e.GetService <IAnkhTempFileManager>(); string tempFile = tempfiles.GetTempFile(".patch"); IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); string slndir = ss.ProjectRoot; using (MemoryStream stream = new MemoryStream()) { e.Context.GetService <IProgressRunner>().RunModal(CommandStrings.RunningDiff, delegate(object sender, ProgressWorkerArgs ee) { SvnAddArgs aa = new SvnAddArgs(); aa.ThrowOnError = false; aa.AddParents = false; foreach (string item in toAdd) { ee.Client.Add(item, aa); } SvnDiffArgs diffArgs = new SvnDiffArgs(); diffArgs.IgnoreAncestry = true; diffArgs.NoDeleted = false; diffArgs.ThrowOnError = false; foreach (SvnItem item in items) { SvnWorkingCopy wc; if (!string.IsNullOrEmpty(slndir) && item.IsBelowPath(slndir)) { diffArgs.RelativeToPath = slndir; } else if ((wc = item.WorkingCopy) != null) { diffArgs.RelativeToPath = wc.FullPath; } else { diffArgs.RelativeToPath = null; } if (!ee.Client.Diff(item.FullPath, revRange, diffArgs, stream)) { if (diffArgs.LastException != null) { StreamWriter sw = new StreamWriter(stream); sw.WriteLine(); sw.WriteLine(string.Format("# {0}: {1}", item.FullPath, diffArgs.LastException.Message)); sw.Flush(); // Don't dispose the writer as that might close the stream } if (diffArgs.IsLastInvocationCanceled) { break; } } } stream.Flush(); }); stream.Position = 0; using (StreamReader sr = new StreamReader(stream)) { File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8); VsShellUtilities.OpenDocument(e.Context, tempFile); } } }
public override void OnExecute(CommandEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); AnkhMessageBox mb = new AnkhMessageBox(e.Context); // Cache items to avoid problems when selection changes by opening editor List <SvnItem> items = new List <SvnItem>(e.Selection.GetSelectedSvnItems(false)); foreach (SvnItem item in items) { if (!item.Exists) { continue; } bool selectInSolutionExplorer = false; try { switch (e.Command) { case AnkhCommand.ItemOpenVisualStudio: IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); if (mapper.IsProjectFileOrSolution(item.FullPath)) { selectInSolutionExplorer = true; break; } if (item.IsDirectory) { goto case AnkhCommand.ItemOpenWindows; } VsShellUtilities.OpenDocument(e.Context, item.FullPath); break; case AnkhCommand.ItemOpenTextEditor: { IVsUIHierarchy hier; IVsWindowFrame frame; uint id; if (!item.IsFile) { continue; } VsShellUtilities.OpenDocument(e.Context, item.FullPath, VSConstants.LOGVIEWID_TextView, out hier, out id, out frame); } break; case AnkhCommand.ItemOpenWindows: System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(item.FullPath); psi.Verb = "open"; System.Diagnostics.Process.Start(psi); break; } } catch (IOException ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (COMException ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (InvalidOperationException ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (System.ComponentModel.Win32Exception ee) { mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (selectInSolutionExplorer) { IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer)); IVsProject project = VsShellUtilities.GetProject(e.Context, item.FullPath) as IVsProject; if (hierWindow != null) { int found; uint id; VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; if (project != null && VSErr.Succeeded(project.IsDocumentInProject(item.FullPath, out found, prio, out id)) && found != 0) { hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem); } else if (string.Equals(item.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase)) { hierWindow.ExpandItem(e.GetService <IVsUIHierarchy>(typeof(SVsSolution)), VSItemId.Root, EXPANDFLAGS.EXPF_SelectItem); } // Now try to activate the solution explorer IVsWindowFrame solutionExplorer; Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer); IVsUIShell shell = e.GetService <IVsUIShell>(typeof(SVsUIShell)); if (shell != null) { shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer); if (solutionExplorer != null) { solutionExplorer.Show(); } } } } } }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> toDelete = new List <SvnItem>(e.Selection.GetSelectedSvnItems(true)); AnkhMessageBox mb = new AnkhMessageBox(e.Context); string body; // We do as if we are Visual Studio here: Same texts, same behavior (same chance on data loss) if (toDelete.Count == 1) { body = string.Format(CommandStrings.XWillBeDeletedPermanently, toDelete[0].Name); } else { body = CommandStrings.TheSelectedItemsWillBeDeletedPermanently; } if (DialogResult.OK != mb.Show(body, "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)) { return; // No delete } int hr = VSErr.S_OK; foreach (SvnItem item in toDelete) { { IVsUIHierarchy hier; uint id; IVsWindowFrame frame; if (VsShellUtilities.IsDocumentOpen(e.Context, item.FullPath, Guid.Empty, out hier, out id, out frame)) { hr = frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); if (!VSErr.Succeeded(hr)) { break; // Show error and cancel further actions } } } try { if (item.IsVersioned) { using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient()) { SvnDeleteArgs da = new SvnDeleteArgs(); da.Force = true; cl.Delete(item.FullPath, da); } } else { SvnItem.DeleteNode(item.FullPath); } } finally { // TODO: Notify the working copy explorer here! // (Maybe via one of these methods below) e.GetService <ISvnStatusCache>().MarkDirtyRecursive(item.FullPath); e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath); } // Ok, now remove the file from projects IProjectFileMapper pfm = e.GetService <IProjectFileMapper>(); List <SccProject> projects = new List <SccProject>(pfm.GetAllProjectsContaining(item.FullPath)); foreach (SccProject p in projects) { IVsProject2 p2 = p.RawHandle as IVsProject2; if (p2 == null) { continue; } VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; int found; uint id; if (!VSErr.Succeeded(p2.IsDocumentInProject(item.FullPath, out found, prio, out id)) || found == 0) { continue; // Probably already removed (mapping out of synch?) } hr = p2.RemoveItem(0, id, out found); if (!VSErr.Succeeded(hr)) { break; } } } if (!VSErr.Succeeded(hr)) { mb.Show(Marshal.GetExceptionForHR(hr).Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public override void OnExecute(CommandEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); Uri selectedUri = null; Uri rootUri = null; bool addingProject = (e.Command == AnkhCommand.FileFileAddFromSubversion || e.Command == AnkhCommand.FileSccAddFromSubversion); if (e.Argument is string && Uri.TryCreate((string)e.Argument, UriKind.Absolute, out selectedUri)) { } else if (e.Argument is SvnOrigin) { SvnOrigin origin = (SvnOrigin)e.Argument; selectedUri = origin.Uri; rootUri = origin.RepositoryRoot; } else if (e.Argument is Uri) { selectedUri = (Uri)e.Argument; } IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>(); if (e.PromptUser || selectedUri == null) { using (RepositoryOpenDialog dlg = new RepositoryOpenDialog()) { if (addingProject) { dlg.Text = CommandStrings.AddProjectFromSubversion; } dlg.Filter = settings.OpenProjectFilterName + "|" + settings.AllProjectExtensionsFilter + "|All Files (*.*)|*"; if (selectedUri != null) { dlg.SelectedUri = selectedUri; } if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } selectedUri = dlg.SelectedUri; rootUri = dlg.SelectedRepositoryRoot; } } else if (rootUri == null) { if (!e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingRepositoryRoot, delegate(object sender, ProgressWorkerArgs a) { rootUri = a.Client.GetRepositoryRoot(selectedUri); }).Succeeded) { return; } } string defaultPath = settings.NewProjectLocation; if (addingProject) { IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); if (!string.IsNullOrEmpty(ss.ProjectRoot)) { defaultPath = ss.ProjectRoot; } } string name = Path.GetFileNameWithoutExtension(SvnTools.GetFileName(selectedUri)); string newPath; int n = 0; do { newPath = Path.Combine(defaultPath, name); if (n > 0) { newPath += string.Format("({0})", n); } n++; }while (File.Exists(newPath) || Directory.Exists(newPath)); using (CheckoutProject dlg = new CheckoutProject()) { dlg.Context = e.Context; if (addingProject) { dlg.Text = CommandStrings.AddProjectFromSubversion; } dlg.ProjectUri = selectedUri; dlg.RepositoryRootUri = rootUri; dlg.SelectedPath = newPath; dlg.SvnOrigin = new SvnOrigin(selectedUri, rootUri); dlg.HandleCreated += delegate { FindRoot(e.Context, selectedUri, dlg); }; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } if (!addingProject) { OpenSolution(e, dlg); } else { CheckOutAndOpenProject(e, dlg.ProjectTop, dlg.Revision, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri); } } }
private static void AddProject(CommandEventArgs e, string projectFile) { IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); ss.AddProjectFile(projectFile); }
public override void OnExecute(CommandEventArgs e) { string argumentFile = e.Argument as string; List <SvnItem> selection = new List <SvnItem>(); if (string.IsNullOrEmpty(argumentFile)) { if (e.ShouldPrompt(true)) { selection.AddRange(e.Selection.GetSelectedSvnItems(true)); using (PendingChangeSelector pcs = new PendingChangeSelector()) { pcs.Text = CommandStrings.AddDialogTitle; pcs.PreserveWindowPlacement = true; pcs.LoadItems(selection, delegate(SvnItem item) { return(!item.IsVersioned && item.IsVersionable); }, delegate(SvnItem item) { if (item.IsIgnored) { return(false); } else if (item.IsSccExcluded) { return(false); } return(item.InSolution); }); if (pcs.ShowDialog(e.Context) != DialogResult.OK) { return; } selection.Clear(); selection.AddRange(pcs.GetSelectedItems()); } } else { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (!item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution) { selection.Add(item); } } } } else { selection.Add(e.GetService <ISvnStatusCache>()[argumentFile]); } ICollection <string> paths = SvnItem.GetPaths(selection); IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); documentTracker.SaveDocuments(paths); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(paths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) e.GetService <IProgressRunner>().RunModal(CommandStrings.AddTaskDialogTitle, delegate(object sender, ProgressWorkerArgs ee) { SvnAddArgs args = new SvnAddArgs(); args.Depth = SvnDepth.Empty; args.AddParents = true; foreach (SvnItem item in selection) { ee.Client.Add(item.FullPath, args); } }); }
static void AddPathToSubversion(CommandEventArgs e, string path) { using (SvnClient cl = e.GetService<ISvnClientPool>().GetNoUIClient()) { SvnAddArgs aa = new SvnAddArgs(); aa.AddParents = true; cl.Add(path, aa); } }
public override void OnExecute(CommandEventArgs e) { // TODO: Choose which conflict to edit if we have more than one! SvnItem conflict = null; if (e.Command == AnkhCommand.DocumentConflictEdit) { conflict = e.Selection.ActiveDocumentSvnItem; if (conflict == null || !conflict.IsConflicted) { return; } } else { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.IsConflicted) { conflict = item; break; } } } if (conflict == null) { return; } conflict.MarkDirty(); if (conflict.Status.LocalTextStatus != SvnStatus.Conflicted) { AnkhMessageBox mb = new AnkhMessageBox(e.Context); mb.Show(string.Format(CommandStrings.TheConflictInXIsAlreadyResolved, conflict.FullPath), CommandStrings.EditConflictTitle, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); return; } SvnInfoEventArgs conflictInfo = null; bool ok = false; ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingConflictDetails, delegate(object sender, ProgressWorkerArgs a) { ok = a.Client.GetInfo(conflict.FullPath, out conflictInfo); }); if (!ok || !r.Succeeded || conflictInfo == null) { return; } AnkhMergeArgs da = new AnkhMergeArgs(); string dir = conflict.Directory; da.BaseFile = Path.Combine(dir, conflictInfo.ConflictOld ?? conflictInfo.ConflictNew); da.TheirsFile = Path.Combine(dir, conflictInfo.ConflictNew ?? conflictInfo.ConflictOld); if (!string.IsNullOrEmpty(conflictInfo.ConflictWork)) { da.MineFile = Path.Combine(dir, conflictInfo.ConflictWork); } else { da.MineFile = conflict.FullPath; } da.MergedFile = conflict.FullPath; da.BaseTitle = "Base"; da.TheirsTitle = "Theirs"; da.MineTitle = "Mine"; da.MergedTitle = conflict.Name; e.GetService <IAnkhDiffHandler>().RunMerge(da); }
static bool CheckoutWorkingCopyForSolution(CommandEventArgs e, ref bool confirmed) { using (SvnClient cl = e.GetService<ISvnClientPool>().GetClient()) using (AddToSubversion dialog = new AddToSubversion()) { dialog.PathToAdd = e.Selection.SolutionFilename; if (dialog.ShowDialog(e.Context) == DialogResult.OK) { confirmed = true; Collection<SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) return false; // Create failed; bail out } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); // Add solutionfile so we can set properties (set managed) AddPathToSubversion(e, e.Selection.SolutionFilename); IAnkhSolutionSettings settings = e.GetService<IAnkhSolutionSettings>(); IProjectFileMapper mapper = e.GetService<IProjectFileMapper>(); IFileStatusMonitor monitor = e.GetService<IFileStatusMonitor>(); settings.ProjectRoot = SvnTools.GetNormalizedFullPath(dialog.WorkingCopyDir); if (monitor != null && mapper != null) { // Make sure all visible glyphs are updated to reflect a new working copy monitor.ScheduleSvnStatus(mapper.GetAllFilesOfAllProjects()); } return true; } return false; // User cancelled the "Add to subversion" dialog, don't set as managed by Ankh } }
public override void OnExecute(CommandEventArgs e) { SvnItem theItem = null; string path; bool allowObstructions = false; string projectRoot = e.GetService <IAnkhSolutionSettings>().ProjectRoot; if (e.Command == AnkhCommand.SolutionSwitchDialog) { path = projectRoot; } else if (e.Command == AnkhCommand.SwitchProject) { IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); path = null; foreach (SccProject item in e.Selection.GetSelectedProjects(true)) { ISccProjectInfo pi = mapper.GetProjectInfo(item); if (pi == null) { continue; } path = pi.ProjectDirectory; break; } if (string.IsNullOrEmpty(path)) { return; } } else { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.IsVersioned) { theItem = item; break; } return; } path = theItem.FullPath; } ISvnStatusCache statusCache = e.GetService <ISvnStatusCache>(); SvnItem pathItem = statusCache[path]; Uri uri = pathItem.Uri; if (uri == null) { return; // Should never happen on a real workingcopy } SvnUriTarget target; SvnRevision revision = SvnRevision.None; if (e.Argument is string) { target = SvnUriTarget.FromString((string)e.Argument, true); revision = (target.Revision != SvnRevision.None) ? target.Revision : SvnRevision.Head; } else if (e.Argument is Uri) { target = (Uri)e.Argument; } else { using (SwitchDialog dlg = new SwitchDialog()) { dlg.Context = e.Context; dlg.LocalPath = path; dlg.RepositoryRoot = e.GetService <ISvnStatusCache>()[path].WorkingCopy.RepositoryRoot; dlg.SwitchToUri = uri; dlg.Revision = SvnRevision.Head; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } target = dlg.SwitchToUri; revision = dlg.Revision; allowObstructions = dlg.AllowUnversionedObstructions; } } // Get a list of all documents below the specified paths that are open in editors inside VS HybridCollection <string> lockPaths = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); foreach (string file in documentTracker.GetDocumentsBelow(path)) { if (!lockPaths.Contains(file)) { lockPaths.Add(file); } } documentTracker.SaveDocuments(lockPaths); // Make sure all files are saved before merging! using (DocumentLock lck = documentTracker.LockDocuments(lockPaths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { Uri newRepositoryRoot = null; e.GetService <IProgressRunner>().RunModal(CommandStrings.SwitchingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnSwitchArgs args = new SvnSwitchArgs(); args.AllowObstructions = allowObstructions; args.AddExpectedError(SvnErrorCode.SVN_ERR_WC_INVALID_SWITCH); if (revision != SvnRevision.None) { args.Revision = revision; } e.GetService <IConflictHandler>().RegisterConflictHandler(args, a.Synchronizer); if (!a.Client.Switch(path, target, args)) { if (args.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_INVALID_SWITCH) { return; } // source/target repository is different, check if we can fix this by relocating SvnInfoEventArgs iea; if (a.Client.GetInfo(target, out iea)) { if (pathItem.WorkingCopy.RepositoryId != iea.RepositoryId) { e.Context.GetService <IAnkhDialogOwner>() .MessageBox.Show("Cannot switch to different repository because the repository UUIDs are different", "Cannot switch", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (pathItem.WorkingCopy.RepositoryRoot != iea.RepositoryRoot) { newRepositoryRoot = iea.RepositoryRoot; } else if (pathItem.WorkingCopy.RepositoryId == Guid.Empty) { // No UUIDs and RepositoryRoot equal. Throw/show error? throw args.LastException; } } } }); if (newRepositoryRoot != null && DialogResult.Yes == e.Context.GetService <IAnkhDialogOwner>() .MessageBox.Show(string.Format("The repository root specified is different from the one in your " + "working copy. Would you like to relocate '{0}' from '{1}' to '{2}'?", pathItem.WorkingCopy.FullPath, pathItem.WorkingCopy.RepositoryRoot, newRepositoryRoot), "Relocate", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { // We can fix this by relocating string wcRoot = pathItem.WorkingCopy.FullPath; try { e.GetService <IProgressRunner>().RunModal( CommandStrings.RelocatingTitle, delegate(object sender, ProgressWorkerArgs a) { a.Client.Relocate(wcRoot, pathItem.WorkingCopy.RepositoryRoot, newRepositoryRoot); }); } finally { statusCache.MarkDirtyRecursive(wcRoot); e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(statusCache.GetCachedBelow(wcRoot)); } if (DialogResult.Yes == e.Context.GetService <IAnkhDialogOwner>() .MessageBox.Show(string.Format("Would you like to try to switch '{0}' to '{1}' again?", path, target), "Switch", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { // Try to switch again e.GetService <IProgressRunner>().RunModal( CommandStrings.SwitchingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnSwitchArgs args = new SvnSwitchArgs(); if (revision != SvnRevision.None) { args.Revision = revision; } args.AllowObstructions = allowObstructions; e.GetService <IConflictHandler>().RegisterConflictHandler(args, a.Synchronizer); a.Client.Switch(path, target, args); }); } } } }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> selectedFiles = new List <SvnItem>(); if (e.Command == AnkhCommand.DocumentShowChanges) { SvnItem item = e.Selection.ActiveDocumentSvnItem; if (item == null) { return; } selectedFiles.Add(item); } else { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (!item.IsVersioned || (item.Status.LocalNodeStatus == SvnStatus.Added && !item.Status.IsCopied)) { continue; } if (e.Command == AnkhCommand.ItemCompareBase || e.Command == AnkhCommand.ItemShowChanges) { if (!(item.IsModified || item.IsDocumentDirty) || !item.IsLocalDiffAvailable // exclude if local diff is not available ) { continue; } } if (e.Command == AnkhCommand.DiffLocalItem && !NotDeletedFilter(item)) { continue; } selectedFiles.Add(item); } } SvnRevisionRange revRange = null; switch (e.Command) { case AnkhCommand.DiffLocalItem: break; // revRange null -> show selector case AnkhCommand.ItemCompareBase: case AnkhCommand.ItemShowChanges: case AnkhCommand.DocumentShowChanges: revRange = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working); break; case AnkhCommand.ItemCompareCommitted: revRange = new SvnRevisionRange(SvnRevision.Committed, SvnRevision.Working); break; case AnkhCommand.ItemCompareLatest: revRange = new SvnRevisionRange(SvnRevision.Head, SvnRevision.Working); break; case AnkhCommand.ItemComparePrevious: revRange = new SvnRevisionRange(SvnRevision.Previous, SvnRevision.Working); break; } if (e.PromptUser || selectedFiles.Count > 1 || revRange == null) { SvnRevision start = revRange == null ? SvnRevision.Base : revRange.StartRevision; SvnRevision end = revRange == null ? SvnRevision.Working : revRange.EndRevision; // should we show the path selector? if (e.PromptUser || !Shift) { using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog()) { dlg.Text = CommandStrings.CompareFilesTitle; dlg.Items = selectedFiles; dlg.RevisionStart = start; dlg.RevisionEnd = end; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } selectedFiles.Clear(); selectedFiles.AddRange(dlg.GetCheckedItems()); start = dlg.RevisionStart; end = dlg.RevisionEnd; } } revRange = new SvnRevisionRange(start, end); } if (revRange.EndRevision.RevisionType == SvnRevisionType.Working || revRange.StartRevision.RevisionType == SvnRevisionType.Working) { // Save only the files needed IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); if (tracker != null) { tracker.SaveDocuments(SvnItem.GetPaths(selectedFiles)); } } IAnkhDiffHandler diff = e.GetService <IAnkhDiffHandler>(); foreach (SvnItem item in selectedFiles) { AnkhDiffArgs da = new AnkhDiffArgs(); if ((item.Status.IsCopied || item.IsReplaced) && (!revRange.StartRevision.RequiresWorkingCopy || !revRange.EndRevision.RequiresWorkingCopy)) { // The file is copied, use its origins history instead of that of the new file SvnUriTarget copiedFrom = diff.GetCopyOrigin(item); // TODO: Maybe handle Previous/Committed as history if (copiedFrom != null && !revRange.StartRevision.RequiresWorkingCopy) { if (null == (da.BaseFile = diff.GetTempFile(copiedFrom, revRange.StartRevision, true))) { return; // Canceled } da.BaseTitle = diff.GetTitle(copiedFrom, revRange.StartRevision); } if (copiedFrom != null && !revRange.EndRevision.RequiresWorkingCopy) { if (null == (da.MineFile = diff.GetTempFile(copiedFrom, revRange.EndRevision, true))) { return; // Canceled } da.MineTitle = diff.GetTitle(copiedFrom, revRange.EndRevision); } } if (da.BaseFile == null) { if (null == (da.BaseFile = (revRange.StartRevision == SvnRevision.Working) ? item.FullPath : diff.GetTempFile(item, revRange.StartRevision, true))) { return; // Canceled } da.BaseTitle = diff.GetTitle(item, revRange.StartRevision); } if (da.MineFile == null) { if (null == (da.MineFile = (revRange.EndRevision == SvnRevision.Working) ? item.FullPath : diff.GetTempFile(item, revRange.EndRevision, true))) { return; // Canceled } da.MineTitle = diff.GetTitle(item, revRange.EndRevision); } if (!String.Equals(da.MineFile, item.FullPath, StringComparison.OrdinalIgnoreCase)) { da.ReadOnly = true; } diff.RunDiff(da); } }
private static void CheckOutAndOpenSolution(CommandEventArgs e, SvnUriTarget checkoutLocation, SvnRevision revision, Uri projectTop, string localDir, Uri projectUri) { IProgressRunner runner = e.GetService<IProgressRunner>(); runner.RunModal("Checking Out Solution", delegate(object sender, ProgressWorkerArgs ee) { PerformCheckout(ee, checkoutLocation, revision, localDir); }); Uri file = projectTop.MakeRelativeUri(projectUri); string projectFile = SvnTools.GetNormalizedFullPath(Path.Combine(localDir, SvnTools.UriPartToPath(file.ToString()))); OpenProject(e, projectFile); }
private static void OpenProject(CommandEventArgs e, string projectFile) { IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>(); ss.OpenProjectFile(projectFile); }
public override void OnExecute(CommandEventArgs e) { Uri selectedUri = null; Uri rootUri = null; if (e.Argument is string && Uri.TryCreate((string)e.Argument, UriKind.Absolute, out selectedUri)) { } else if (e.Argument is SvnOrigin) { SvnOrigin origin = (SvnOrigin)e.Argument; selectedUri = origin.Uri; rootUri = origin.RepositoryRoot; } else if (e.Argument is Uri) selectedUri = (Uri)e.Argument; IAnkhSolutionSettings settings = e.GetService<IAnkhSolutionSettings>(); if (e.PromptUser || selectedUri == null) { using (RepositoryOpenDialog dlg = new RepositoryOpenDialog()) { dlg.Context = e.Context; dlg.Filter = settings.OpenProjectFilterName + "|" + settings.AllProjectExtensionsFilter + "|All Files (*.*)|*"; if (selectedUri != null) dlg.SelectedUri = selectedUri; if (e.Command != AnkhCommand.FileFileOpenFromSubversion && e.Command != AnkhCommand.FileSccOpenFromSubversion) { foreach (string ext in settings.SolutionFilter.Split(';')) { dlg.Filter = dlg.Filter.Replace(ext.Trim() + ';', ""); } } if (dlg.ShowDialog(e.Context) != DialogResult.OK) return; selectedUri = dlg.SelectedUri; rootUri = dlg.SelectedRepositoryRoot; } } else if (rootUri == null) { if (!e.GetService<IProgressRunner>().RunModal("Retrieving Repository Root", delegate(object sender, ProgressWorkerArgs a) { rootUri = a.Client.GetRepositoryRoot(selectedUri); }).Succeeded) { return; } } string path = settings.NewProjectLocation; string name = Path.GetFileNameWithoutExtension(SvnTools.GetFileName(selectedUri)); string newPath; int n = 0; do { newPath = Path.Combine(path, name); if (n > 0) newPath += string.Format("({0})", n); n++; } while (File.Exists(newPath) || Directory.Exists(newPath)); using (CheckoutProject dlg = new CheckoutProject()) { dlg.Context = e.Context; dlg.ProjectUri = selectedUri; dlg.RepositoryRootUri = rootUri; dlg.SelectedPath = newPath; dlg.SvnOrigin = new SvnOrigin(selectedUri, rootUri); dlg.HandleCreated += delegate { FindRoot(e.Context, selectedUri, dlg); }; if (dlg.ShowDialog(e.Context) != DialogResult.OK) return; IVsSolution2 sol = e.GetService<IVsSolution2>(typeof(SVsSolution)); if (sol != null) { sol.CloseSolutionElement(VSConstants.VSITEMID_ROOT, null, 0); // Closes the current solution } IAnkhSccService scc = e.GetService<IAnkhSccService>(); if (scc != null) scc.RegisterAsPrimarySccProvider(); // Make us the current SCC provider! CheckOutAndOpenSolution(e, dlg.ProjectTop, null, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri); sol = e.GetService<IVsSolution2>(typeof(SVsSolution)); if (sol != null) { string file, user, dir; if (ErrorHandler.Succeeded(sol.GetSolutionInfo(out dir, out file, out user)) && !string.IsNullOrEmpty(file)) { scc.SetProjectManaged(null, true); } } } }
public override void OnExecute(CommandEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); SvnItem node = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); IAnkhCommandService cmd = e.GetService <IAnkhCommandService>(); switch (e.Command) { case AnkhCommand.ItemSelectInRepositoryExplorer: if (node == null || node.Uri == null) { return; } if (cmd != null) { cmd.DirectlyExecCommand(AnkhCommand.RepositoryBrowse, node.FullPath); } break; case AnkhCommand.ItemSelectInWorkingCopyExplorer: if (node == null || !node.Exists) { return; } if (cmd != null) { cmd.DirectlyExecCommand(AnkhCommand.WorkingCopyBrowse, node.FullPath); } break; case AnkhCommand.ItemSelectInFileExplorer: if (node == null || !node.Exists) { return; } SelectInFileExplorer(node.FullPath); break; case AnkhCommand.ItemSelectInSolutionExplorer: if (node == null) { return; } IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer)); IVsProject project = VsShellUtilities.GetProject(e.Context, node.FullPath) as IVsProject; if (hierWindow != null) { int found; uint id; VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; if (project != null && VSErr.Succeeded(project.IsDocumentInProject(node.FullPath, out found, prio, out id)) && found != 0) { hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem); } else if (string.Equals(node.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase)) { hierWindow.ExpandItem(e.GetService <IVsUIHierarchy>(typeof(SVsSolution)), VSItemId.Root, EXPANDFLAGS.EXPF_SelectItem); } // Now try to activate the solution explorer IVsWindowFrame solutionExplorer; Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer); IVsUIShell shell = e.GetService <IVsUIShell>(typeof(SVsUIShell)); if (shell != null) { shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer); if (solutionExplorer != null) { solutionExplorer.Show(); } } } break; } }
private static void CheckOutAndOpenProject(CommandEventArgs e, SvnUriTarget checkoutLocation, SvnRevision revision, Uri projectTop, string localDir, Uri projectUri) { IProgressRunner runner = e.GetService <IProgressRunner>(); runner.RunModal(CommandStrings.CheckingOutSolution, delegate(object sender, ProgressWorkerArgs ee) { PerformCheckout(ee, checkoutLocation, revision, localDir); }); Uri file = projectTop.MakeRelativeUri(projectUri); string projectFile = SvnTools.GetNormalizedFullPath(Path.Combine(localDir, SvnTools.UriPartToPath(file.ToString()))); AddProject(e, projectFile); using (ProjectAddInfoDialog pai = new ProjectAddInfoDialog()) { IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); SvnItem rootItem; pai.EnableSlnConnection = false; if (ss == null || cache == null || string.IsNullOrEmpty(ss.ProjectRoot) || !SvnItem.IsBelowRoot(localDir, ss.ProjectRoot) || null == (rootItem = cache[localDir])) { pai.EnableExternal = false; pai.EnableCopy = false; } else { SvnItem dir = rootItem.Parent; if (ss.ProjectRootSvnItem != null && ss.ProjectRootSvnItem.IsVersioned) { HybridCollection <string> dirs = new HybridCollection <string>(); SvnItem exDir = dir; while (exDir != null && exDir.IsBelowPath(ss.ProjectRoot)) { if (exDir.IsVersioned && exDir.WorkingCopy == ss.ProjectRootSvnItem.WorkingCopy) { dirs.Add(exDir.FullPath); } exDir = exDir.Parent; } pai.SetExternalDirs(dirs); pai.EnableExternal = true; } else { pai.EnableExternal = false; } if (rootItem.WorkingCopy != null && dir.WorkingCopy != null) { pai.EnableCopy = (rootItem.WorkingCopy.RepositoryRoot == dir.WorkingCopy.RepositoryRoot) && (rootItem.WorkingCopy.RepositoryId == dir.WorkingCopy.RepositoryId); } else { pai.EnableCopy = false; } } if (pai.ShowDialog(e.Context) == DialogResult.OK) { switch (pai.SelectedMode) { case ProjectAddMode.External: if (pai.ExternalLocation != null) { using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient()) { string externals; if (!cl.TryGetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, out externals)) { externals = ""; } SvnExternalItem sei; if (pai.ExternalLocked) { sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri, revision, revision); } else { sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri); } externals = sei.ToString(true) + Environment.NewLine + externals; cl.SetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, externals); } } break; case ProjectAddMode.Copy: using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient()) { string tmpDir = localDir + "-Src-copyTmp"; Directory.CreateDirectory(tmpDir); Directory.Move(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), Path.Combine(tmpDir, SvnClient.AdministrativeDirectoryName)); SvnCopyArgs ma = new SvnCopyArgs(); ma.MetaDataOnly = true; cl.Copy(tmpDir, localDir, ma); SvnItem.DeleteDirectory(tmpDir, true); cache.MarkDirtyRecursive(localDir); } break; case ProjectAddMode.Unversioned: cache.MarkDirtyRecursive(localDir); SvnItem.DeleteDirectory(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), true); e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(projectFile); // And everything else in the project break; } } } }