public override void OnUpdate(CommandUpdateEventArgs e) { if (null == EnumTools.GetFirst(e.Selection.GetSelectedFiles(true))) { e.Enabled = false; } }
private void okButton_Click(object sender, EventArgs e) { string path = directory.Text; if (!SvnItem.IsValidPath(path) || File.Exists(path)) { MessageBox.Show(this, "Path is not valid", "Open Project from Subversion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } directory.Text = path = SvnTools.GetNormalizedFullPath(path); if (Directory.Exists(path)) { DirectoryInfo di = new DirectoryInfo(path); if (EnumTools.GetFirst(di.GetFileSystemInfos()) != null) { if (MessageBox.Show(this, string.Format("{0} already contains files or directories.\nWould you like to continue?", path) , "Open Project from Subversion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes) { return; } } } else { Directory.CreateDirectory(path); } DialogResult = DialogResult.OK; }
public UnifiedDiffDropDownBar(UnifiedDiffLanguage language, AnkhCodeWindowManager manager) : base(language, manager) { IVsTextView view = EnumTools.GetFirst(manager.GetViews()); if (VSErr.Succeeded(view.GetBuffer(out _buffer))) { if (!TryHookConnectionPoint <IVsTextLinesEvents>(_buffer, this, out _linesCookie)) { _linesCookie = 0; } } }
internal void BroadcastChanges() { IGitItemStateUpdate update; if (_map.Count > 0) { update = EnumTools.GetFirst(_map.Values); } else { update = this["C:\\"]; // Just give me a GitItem instance to access the interface } IList <GitItem> updates = update.GetUpdateQueueAndClearScheduled(); if (updates != null) { OnGitItemsChanged(new GitItemsEventArgs(updates)); } }
public override void OnUpdate(CommandUpdateEventArgs e) { SvnItem node = EnumTools.GetSingle(e.Selection.GetSelectedSvnItems(false)); if (node == null && e.Selection.IsSingleNodeSelection) { node = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); } bool enable = true; if (node == null) { enable = false; } else if (e.Command == AnkhCommand.ItemSelectInRepositoryExplorer) { enable = node.Uri != null; } else if (e.Command == AnkhCommand.ItemSelectInWorkingCopyExplorer || e.Command == AnkhCommand.ItemSelectInFileExplorer) { enable = node.Exists; } else if (e.Command == AnkhCommand.ItemSelectInSolutionExplorer) { if (e.State.SolutionExplorerActive) { enable = false; } else if (!node.InSolution) { enable = false; } } if (!enable) { e.Enabled = false; } }
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; } }
public void PerformMerge() { MergeType mergeType = GetPage <MergeTypePage>().SelectedMergeType; ProgressRunnerArgs runnerArgs = new ProgressRunnerArgs(); runnerArgs.CreateLog = !PerformDryRun; // Perform merge using IProgressRunner Context.GetService <IProgressRunner>().RunModal(MergeStrings.MergingTitle, runnerArgs, delegate(object sender, ProgressWorkerArgs ee) { _mergeActions = new List <SvnNotifyEventArgs>(); _resolvedMergeConflicts = new Dictionary <string, List <SvnConflictType> >(); MergeConflictHandler mergeConflictHandler = CreateMergeConflictHandler(); Handler conflictHandler = new Handler(Context, ee.Synchronizer, mergeConflictHandler); try { if (!PerformDryRun) { // Attach the conflict handler ee.Client.Conflict += new EventHandler <SvnConflictEventArgs>(conflictHandler.OnConflict); } // Attach the cancel handler ee.Client.Cancel += new EventHandler <SvnCancelEventArgs>(this.OnCancel); // Attach the notify handler ee.Client.Notify += new EventHandler <SvnNotifyEventArgs>(this.OnNotify); if (mergeType == MergeType.TwoDifferentTrees) { MergeSourceTwoDifferentTreesPage page = ((MergeSourceTwoDifferentTreesPage)mergeSourceTwoDifferentTreesPage); SvnDiffMergeArgs dArgs = new SvnDiffMergeArgs(); Uri fromUri; Uri toUri; // Set the proper depth dArgs.Depth = ((MergeOptionsPage)mergeOptionsPage).Depth; // Set whether or not unversioned obstructions should be allowed dArgs.Force = ((MergeOptionsPage)mergeOptionsPage).AllowUnversionedObstructions; // Set whether or not to ignore ancestry dArgs.IgnoreAncestry = ((MergeOptionsPage)mergeOptionsPage).IgnoreAncestry; // Set whether or not this is a dry run dArgs.DryRun = PerformDryRun; // Create 'From' uri Uri.TryCreate(page.MergeSourceOne, UriKind.Absolute, out fromUri); // Create 'To' uri if necessary if (page.HasSecondMergeSourceUrl) { Uri.TryCreate(page.MergeSourceTwo, UriKind.Absolute, out toUri); } else { toUri = fromUri; } ee.Client.DiffMerge(MergeTarget.FullPath, new SvnUriTarget(fromUri, (page.MergeFromRevision > -1 ? new SvnRevision(page.MergeFromRevision - 1) : SvnRevision.Head)), new SvnUriTarget(toUri, (page.MergeToRevision > -1 ? new SvnRevision(page.MergeToRevision) : SvnRevision.Head)), dArgs); } else if (mergeType == MergeType.Reintegrate) { SvnReintegrationMergeArgs args = new SvnReintegrationMergeArgs(); // Set whether or not this is a dry run args.DryRun = PerformDryRun; ee.Client.ReintegrationMerge(MergeTarget.FullPath, MergeSource.Target, args); } else { SvnMergeArgs args = new SvnMergeArgs(); // Set the proper depth args.Depth = mergeOptionsPage.Depth; // Set whether or not unversioned obstructions should be allowed args.Force = mergeOptionsPage.AllowUnversionedObstructions; // Set whether or not to ignore ancestry args.IgnoreAncestry = mergeOptionsPage.IgnoreAncestry; // Set whether or not this merge should just record the merge information args.RecordOnly = (mergeType == MergeType.ManuallyRecord || mergeType == MergeType.ManuallyRemove); // Set whether or not this is a dry run args.DryRun = PerformDryRun; //no need to continue with the merge operation since there are no revisions to merge if (MergeRevisions != null && EnumTools.GetFirst(MergeRevisions) == null) { throw new Exception(MergeStrings.NoLogItems); } if (MergeRevisions == null) { // Merge all eligible ee.Client.Merge( MergeTarget.FullPath, MergeSource.Target, new SvnRevisionRange(SvnRevision.Zero, SvnRevision.Head), args); } else { // Cherrypicking ee.Client.Merge( MergeTarget.FullPath, MergeSource.Target, new List <SvnRevisionRange>(MergeRevisions), args); } } } finally { if (!PerformDryRun) { // Detach the conflict handler ee.Client.Conflict -= new EventHandler <SvnConflictEventArgs>(conflictHandler.OnConflict); } // Detach the notify handler ee.Client.Notify -= new EventHandler <SvnNotifyEventArgs>(OnNotify); // Detach the cancel handler ee.Client.Cancel -= new EventHandler <SvnCancelEventArgs>(this.OnCancel); if (mergeConflictHandler != null) { _resolvedMergeConflicts = mergeConflictHandler.ResolvedMergedConflicts; mergeConflictHandler = null; } } }); }
public override void OnExecute(CommandEventArgs e) { IAnkhServiceEvents ci = e.GetService <IAnkhServiceEvents>(); if (ci != null) { ci.OnLastChanged(new LastChangedEventArgs(null, null)); } SvnRevision rev; bool allowUnversionedObstructions = false; bool updateExternals = true; bool setDepthInfinity = true; IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>(); ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); Uri reposRoot = null; if (IsHeadCommand(e.Command) || e.DontPrompt) { rev = SvnRevision.Head; } else if (IsSolutionCommand(e.Command)) { SvnItem projectItem = settings.ProjectRootSvnItem; Debug.Assert(projectItem != null, "Has item"); using (UpdateDialog ud = new UpdateDialog()) { ud.ItemToUpdate = projectItem; ud.Revision = SvnRevision.Head; if (ud.ShowDialog(e.Context) != DialogResult.OK) { return; } rev = ud.Revision; allowUnversionedObstructions = ud.AllowUnversionedObstructions; updateExternals = ud.UpdateExternals; setDepthInfinity = ud.SetDepthInfinty; } } else if (IsFolderCommand(e.Command)) { SvnItem dirItem = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); Debug.Assert(dirItem != null && dirItem.IsDirectory && dirItem.IsVersioned); using (UpdateDialog ud = new UpdateDialog()) { ud.Text = CommandStrings.UpdateFolder; ud.FolderLabelText = CommandStrings.UpdateFolderLabel; ud.ItemToUpdate = dirItem; ud.Revision = SvnRevision.Head; if (ud.ShowDialog(e.Context) != DialogResult.OK) { return; } rev = ud.Revision; allowUnversionedObstructions = ud.AllowUnversionedObstructions; updateExternals = ud.UpdateExternals; setDepthInfinity = ud.SetDepthInfinty; } } else { // We checked there was only a single repository to select a revision // from in OnUpdate, so we can suffice with only calculate the path SvnItem si = null; SvnOrigin origin = null; foreach (SccProject p in GetSelectedProjects(e)) { ISccProjectInfo pi = mapper.GetProjectInfo(p); if (pi == null || pi.ProjectDirectory == null) { continue; } SvnItem item = cache[pi.ProjectDirectory]; if (!item.IsVersioned) { continue; } if (si == null && origin == null) { si = item; origin = new SvnOrigin(item); reposRoot = item.WorkingCopy.RepositoryRoot; } else { si = null; string urlPath1 = origin.Uri.AbsolutePath; string urlPath2 = item.Uri.AbsolutePath; int i = 0; while (i < urlPath1.Length && i < urlPath2.Length && urlPath1[i] == urlPath2[i]) { i++; } while (i > 0 && urlPath1[i - 1] != '/') { i--; } origin = new SvnOrigin(new Uri(origin.Uri, urlPath1.Substring(0, i)), origin.RepositoryRoot); } } Debug.Assert(origin != null); using (UpdateDialog ud = new UpdateDialog()) { ud.Text = CommandStrings.UpdateProject; if (si != null) { ud.ItemToUpdate = si; } else { ud.SvnOrigin = origin; ud.SetMultiple(true); } ud.Revision = SvnRevision.Head; if (ud.ShowDialog(e.Context) != DialogResult.OK) { return; } rev = ud.Revision; allowUnversionedObstructions = ud.AllowUnversionedObstructions; updateExternals = ud.UpdateExternals; setDepthInfinity = ud.SetDepthInfinty; } } Dictionary <string, SvnItem> itemsToUpdate = new Dictionary <string, SvnItem>(StringComparer.OrdinalIgnoreCase); SortedList <string, UpdateGroup> groups = new SortedList <string, UpdateGroup>(StringComparer.OrdinalIgnoreCase); // 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 (SvnItem item in GetAllUpdateRoots(e)) { // GetAllUpdateRoots can (and probably will) return duplicates! if (itemsToUpdate.ContainsKey(item.FullPath) || !item.IsVersioned) { continue; } SvnWorkingCopy wc = item.WorkingCopy; if (!IsHeadCommand(e.Command) && reposRoot != null) { // Specific revisions are only valid on a single repository! if (wc != null && wc.RepositoryRoot != reposRoot) { continue; } } UpdateGroup group; if (!groups.TryGetValue(wc.FullPath, out group)) { group = new UpdateGroup(wc.FullPath); groups.Add(wc.FullPath, group); } group.Nodes.Add(item.FullPath); itemsToUpdate.Add(item.FullPath, item); foreach (string file in documentTracker.GetDocumentsBelow(item.FullPath)) { if (!lockPaths.Contains(file)) { lockPaths.Add(file); } } } documentTracker.SaveDocuments(lockPaths); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(lockPaths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { SvnUpdateResult updateResult = null; ProgressRunnerArgs pa = new ProgressRunnerArgs(); pa.CreateLog = true; string title; if (IsSolutionCommand(e.Command)) { title = CommandStrings.UpdatingSolution; } else if (IsFolderCommand(e.Command)) { title = CommandStrings.UpdatingFolder; } else { title = CommandStrings.UpdatingProject; } e.GetService <IProgressRunner>().RunModal(title, pa, delegate(object sender, ProgressWorkerArgs a) { PerformUpdate(e, a, rev, allowUnversionedObstructions, updateExternals, setDepthInfinity, groups.Values, out updateResult); }); if (ci != null && updateResult != null && IsSolutionCommand(e.Command)) { ci.OnLastChanged(new LastChangedEventArgs(CommandStrings.UpdatedToTitle, updateResult.Revision.ToString())); } } }
public override void OnExecute(CommandEventArgs e) { List <SvnOrigin> targets = new List <SvnOrigin>(); SvnRevision startRev = SvnRevision.Zero; SvnRevision endRev = null; switch (e.Command) { case AnkhCommand.ItemAnnotate: endRev = SvnRevision.Working; foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false)) { if (i.IsFile && i.IsVersioned && i.HasCopyableHistory) { targets.Add(new SvnOrigin(i)); } } break; case AnkhCommand.LogAnnotateRevision: foreach (ISvnLogChangedPathItem logItem in e.Selection.GetSelection <ISvnLogChangedPathItem>()) { targets.Add(logItem.Origin); endRev = logItem.Revision; } break; case AnkhCommand.SvnNodeAnnotate: foreach (ISvnRepositoryItem item in e.Selection.GetSelection <ISvnRepositoryItem>()) { targets.Add(item.Origin); endRev = item.Revision; } break; case AnkhCommand.DocumentAnnotate: //TryObtainBlock(e); targets.Add(new SvnOrigin(e.GetService <ISvnStatusCache>()[e.Selection.ActiveDocumentFilename])); endRev = SvnRevision.Working; break; } if (targets.Count == 0) { return; } bool ignoreEols = true; SvnIgnoreSpacing ignoreSpacing = SvnIgnoreSpacing.IgnoreSpace; bool retrieveMergeInfo = false; SvnOrigin target; if ((!e.DontPrompt && !Shift) || e.PromptUser) { using (AnnotateDialog dlg = new AnnotateDialog()) { dlg.SetTargets(targets); dlg.StartRevision = startRev; dlg.EndRevision = endRev; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } target = dlg.SelectedTarget; startRev = dlg.StartRevision; endRev = dlg.EndRevision; ignoreEols = dlg.IgnoreEols; ignoreSpacing = dlg.IgnoreSpacing; retrieveMergeInfo = dlg.RetrieveMergeInfo; } } else { SvnItem one = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); if (one == null) { return; } target = new SvnOrigin(one); } if (startRev == SvnRevision.Working || endRev == SvnRevision.Working && target.Target is SvnPathTarget) { IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); if (tracker != null) { tracker.SaveDocument(((SvnPathTarget)target.Target).FullPath); } } DoBlame(e, target, startRev, endRev, ignoreEols, ignoreSpacing, retrieveMergeInfo); }
public override void OnUpdate(CommandUpdateEventArgs e) { int i; switch (e.Command) { case AnkhCommand.ProjectHistory: SccProject p = EnumTools.GetFirst(e.Selection.GetSelectedProjects(false)); if (p == null) { break; } ISccProjectInfo pi = e.GetService <IProjectFileMapper>().GetProjectInfo(p); if (pi == null || string.IsNullOrEmpty(pi.ProjectDirectory)) { break; // No project location } if (e.GetService <ISvnStatusCache>()[pi.ProjectDirectory].HasCopyableHistory) { return; // Ok, we have history! } break; // No history case AnkhCommand.SolutionHistory: IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); if (ss == null || string.IsNullOrEmpty(ss.ProjectRoot)) { break; } if (e.GetService <ISvnStatusCache>()[ss.ProjectRoot].HasCopyableHistory) { return; // Ok, we have history! } break; // No history case AnkhCommand.DocumentHistory: SvnItem docitem = e.Selection.ActiveDocumentSvnItem; if (docitem != null && docitem.HasCopyableHistory) { return; } break; // No history case AnkhCommand.Log: int itemCount = 0; int needsRemoteCount = 0; foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (!item.IsVersioned) { e.Enabled = false; return; } if (item.IsReplaced || item.IsAdded) { if (item.HasCopyableHistory) { needsRemoteCount++; } else { e.Enabled = false; return; } } itemCount++; } if (itemCount == 0 || (needsRemoteCount != 0 && itemCount > 1)) { e.Enabled = false; return; } if (needsRemoteCount >= 1) { // One remote log Debug.Assert(needsRemoteCount == 1); return; } // Local log only return; case AnkhCommand.ReposExplorerLog: i = 0; foreach (ISvnRepositoryItem item in e.Selection.GetSelection <ISvnRepositoryItem>()) { if (item == null || item.Origin == null) { continue; } i++; break; } if (i >= 1) { return; } break; case AnkhCommand.AnnotateShowLog: IAnnotateSection section = EnumTools.GetSingle(e.Selection.GetSelection <IAnnotateSection>()); if (section != null && section.Revision >= 0) { return; } break; } e.Enabled = false; }