コード例 #1
0
            public ProjectListFilter(IAnkhServiceProvider context, IEnumerable <SccProject> projects)
            {
                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }
                if (projects == null)
                {
                    throw new ArgumentNullException("projects");
                }

                _mapper = context.GetService <IProjectFileMapper>();
                List <SccProject> projectList = new List <SccProject>(projects);

                files.AddRange(_mapper.GetAllFilesOf(projectList));

                foreach (SccProject p in projectList)
                {
                    ISccProjectInfo pi = _mapper.GetProjectInfo(p);

                    if (pi == null)
                    {
                        continue; // Ignore solution and non scc projects
                    }
                    string dir = pi.ProjectDirectory;

                    if (!string.IsNullOrEmpty(dir) && !folders.Contains(dir))
                    {
                        folders.Add(dir);
                    }
                }
            }
コード例 #2
0
        /// <summary>
        /// Defines a method to call after a project upgrade.
        /// </summary>
        /// <param name="pHierarchy">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsHierarchy"></see> interface of the project.</param>
        /// <param name="fUpgradeFlag">[in] Integer. Flag indicating the nature of the upgrade. Values taken from the <see cref="T:Microsoft.VisualStudio.Shell.Interop.__VSPPROJECTUPGRADEVIAFACTORYFLAGS"></see> enumeration. Will only be PUVFF_COPYUPGRADE, PUVFF_SXSBACKUP, or PUVFF_COPYBACKUP.</param>
        /// <param name="bstrCopyLocation">[in] String containing the location of the copy upgrade (PUVFF_COPYUPGRADE) or back up copy (PUVFF_COPYBACKUP).</param>
        /// <param name="stUpgradeTime">[in] A <see cref="T:Microsoft.VisualStudio.Shell.Interop.SYSTEMTIME"></see> value. The time the upgrade was done.</param>
        /// <param name="pLogger">[in] Pointer to an <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsUpgradeLogger"></see> interface to use for logging upgrade messages.</param>
        /// <returns>
        /// If the method succeeds, it returns <see cref="F:Microsoft.VisualStudio.VSErr.S_OK"></see>. If it fails, it returns an error code.
        /// </returns>
        public int OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger)
        {
            if (!SccProvider.IsActive)
            {
                return(VSErr.S_OK);
            }

            IProjectFileMapper mapper  = GetService <IProjectFileMapper>();
            IFileStatusMonitor monitor = GetService <IFileStatusMonitor>();

            if (monitor == null || mapper == null)
            {
                return(VSErr.S_OK);
            }

            if (SccProvider.IsSafeSccPath(bstrCopyLocation))
            {
                monitor.ScheduleSvnStatus(bstrCopyLocation);
            }

            IVsSccProject2 project = pHierarchy as IVsSccProject2;

            if (project != null)
            {
                ISccProjectInfo info = mapper.GetProjectInfo(new SccProject(null, project));

                if (info != null && !string.IsNullOrEmpty(info.ProjectFile))
                {
                    monitor.ScheduleSvnStatus(info.ProjectFile);
                }
            }

            return(VSErr.S_OK);
        }
コード例 #3
0
            public override void Reload(IEnumerable <string> paths)
            {
                if (paths == null)
                {
                    throw new ArgumentNullException("paths");
                }

                StopMonitor(); // Make sure we have no further locks while reloading!

                HybridCollection <string> changed = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);

                changed.AddRange(paths);

                IProjectFileMapper mapper = _tracker.GetService <IProjectFileMapper>();

                if (!string.IsNullOrEmpty(mapper.SolutionFilename) && changed.Contains(mapper.SolutionFilename))
                {
                    // Ok; we are going to reload the solution itself
                    _tracker.SaveAllDocumentsExcept(changed); // Make sure everything that is dirty is saved

                    // let's remove all documents that are in the solution from the changed list
                    foreach (string file in mapper.GetAllFilesOfAllProjects())
                    {
                        changed.Remove(file);
                    }

                    // The solution was just removed; add it back
                    changed.Add(mapper.SolutionFilename);
                }

                for (int i = 0; i < changed.Count; i++)
                {
                    string          ch = changed[i];
                    SccDocumentData dd;
                    if (_tracker._docMap.TryGetValue(ch, out dd))
                    {
                        if (!dd.Reload(true))
                        {
                            string parentDocument = _tracker.GetParentDocument(dd);

                            if (string.IsNullOrEmpty(parentDocument))
                            {
                                parentDocument = mapper.SolutionFilename;
                            }

                            if (!string.IsNullOrEmpty(parentDocument) && !changed.Contains(parentDocument))
                            {
                                if (!_locked.Contains(parentDocument))
                                {
                                    // The parent is not on our changed or locked list.. so make sure it is saved
                                    _tracker.SaveDocument(parentDocument);
                                }

                                changed.Add(parentDocument);
                            }
                        }
                    }
                }
            }
コード例 #4
0
ファイル: Merge.cs プロジェクト: windygu/AnkhSVN
        /// <see cref="Ankh.Commands.ICommandHandler.OnExecute" />
        public void OnExecute(CommandEventArgs e)
        {
            List <SvnItem>  svnItems = new List <SvnItem>();
            ISvnStatusCache cache    = e.GetService <ISvnStatusCache>();

            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 (SccProject p in e.Selection.GetSelectedProjects(false))
                {
                    IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();

                    ISccProjectInfo 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);
                            }
                        }
                    }
        }
コード例 #5
0
ファイル: SwitchItemCommand.cs プロジェクト: windygu/AnkhSVN
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            if (!e.State.SolutionExists || e.State.SolutionBuilding || e.State.Debugging || e.State.SolutionOpening)
            {
                e.Enabled = false;
                return;
            }
            switch (e.Command)
            {
            case AnkhCommand.SolutionSwitchDialog:
                IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>();
                SvnItem solutionItem = solutionSettings.ProjectRootSvnItem;
                if (solutionItem == null || !solutionItem.IsVersioned || solutionItem.IsNewAddition)
                {
                    e.Enabled = false;
                    return;
                }
                break;

            case AnkhCommand.SwitchProject:
                SccProject oneProject = EnumTools.GetSingle(e.Selection.GetSelectedProjects(false));

                if (oneProject == null)
                {
                    e.Enabled = false;
                    return;
                }

                IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();
                ISccProjectInfo    pi  = pfm.GetProjectInfo(oneProject);

                if (pi == null || pi.ProjectDirectory == null)
                {
                    e.Enabled = false;
                    return;
                }

                SvnItem projectItem = e.GetService <ISvnStatusCache>()[pi.ProjectDirectory];

                if (projectItem == null || !projectItem.IsVersioned || projectItem.IsNewAddition)
                {
                    e.Enabled = false;
                }
                break;

            case AnkhCommand.SwitchItem:
                SvnItem oneItem = EnumTools.GetSingle(e.Selection.GetSelectedSvnItems(false));

                if (oneItem == null || !oneItem.IsVersioned || oneItem.IsNewAddition)
                {
                    e.Enabled = false;
                }
                break;
            }
        }
コード例 #6
0
ファイル: FileIconMapper.cs プロジェクト: windygu/AnkhSVN
        int GetProjectIcon(string path)
        {
            EnsureSpecialImages();

            IProjectFileMapper map = GetService <IProjectFileMapper>();

            if (map == null)
            {
                return(-1);
            }

            ProjectIconReference handle = map.GetPathIconHandle(path);

            return(ResolveReference(handle));
        }
コード例 #7
0
ファイル: AddToSccCommands.cs プロジェクト: windygu/AnkhSVN
        /// <summary>
        /// Returns true if <see cref="succeededProjects"/> should be set managed, false otherwise
        /// </summary>
        /// <param name="e"></param>
        /// <param name="mapper"></param>
        /// <param name="scc"></param>
        /// <param name="succeededProjects"></param>
        /// <returns></returns>
        static bool AskSetManagedSelectionProjects(CommandEventArgs e, IProjectFileMapper mapper, IAnkhSccService scc, IEnumerable <SccProject> succeededProjects)
        {
            if (e.DontPrompt || e.IsInAutomation)
            {
                return(true);
            }

            AnkhMessageBox mb       = new AnkhMessageBox(e.Context);
            StringBuilder  sb       = new StringBuilder();
            bool           foundOne = false;

            foreach (SccProject project in succeededProjects)
            {
                ISccProjectInfo info;
                if (!scc.IsProjectManaged(project) && null != (info = mapper.GetProjectInfo(project)))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("', '");
                    }

                    sb.Append(info.ProjectName);
                }

                foundOne = true;
            }

            if (!foundOne)
            {
                return(false); // No need to add when there are no projects
            }
            string txt = sb.ToString();
            int    li  = txt.LastIndexOf("', '");

            if (li > 0)
            {
                txt = txt.Substring(0, li + 1) + CommandStrings.FileAnd + txt.Substring(li + 3);
            }

            return(DialogResult.Yes == mb.Show(string.Format(CommandStrings.MarkXAsManaged,
                                                             txt), AnkhId.PlkProduct, MessageBoxButtons.YesNo));
        }
コード例 #8
0
        void UpdateSolutionInfo()
        {
            IProjectFileMapper pfm = _context.GetService <IProjectFileMapper>();
            bool inSolution        = false;

            if (pfm != null)
            {
                inSolution   = pfm.ContainsPath(FullPath);
                _sccExcluded = pfm.IsSccExcluded(FullPath);
            }

            if (inSolution)
            {
                SetState(GitItemState.InSolution, GitItemState.None);
            }
            else
            {
                SetState(GitItemState.None, GitItemState.InSolution);
            }
        }
コード例 #9
0
            public ProjectListFilter(IVisualGitServiceProvider context, IEnumerable<GitProject> projects)
            {
                if (context == null)
                    throw new ArgumentNullException("context");
                if (projects == null)
                    throw new ArgumentNullException("projects");

                _mapper = context.GetService<IProjectFileMapper>();
                List<GitProject> projectList = new List<GitProject>(projects);

                files.AddRange(_mapper.GetAllFilesOf(projectList));

                foreach (GitProject p in projectList)
                {
                    IGitProjectInfo pi = _mapper.GetProjectInfo(p);

                    if (pi == null)
                        continue; // Ignore solution and non scc projects

                    string dir = pi.ProjectDirectory;

                    if (!string.IsNullOrEmpty(dir) && !folders.Contains(dir))
                        folders.Add(dir);
                }
            }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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();
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
ファイル: Merge.cs プロジェクト: windygu/AnkhSVN
        /// <see cref="Ankh.Commands.ICommandHandler.OnUpdate" />
        public void OnUpdate(CommandUpdateEventArgs e)
        {
            ISvnStatusCache statusCache;
            int             n = 0;

            switch (e.Command)
            {
            case AnkhCommand.ItemMerge:
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                {
                    if (!item.IsVersioned)
                    {
                        e.Enabled = false;
                        return;
                    }

                    n++;

                    if (n > 1)
                    {
                        break;
                    }
                }
                break;

            case AnkhCommand.ProjectMerge:
                statusCache = e.GetService <ISvnStatusCache>();
                IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();
                foreach (SccProject project in e.Selection.GetSelectedProjects(false))
                {
                    ISccProjectInfo projInfo = pfm.GetProjectInfo(project);
                    if (projInfo == null || string.IsNullOrEmpty(projInfo.ProjectDirectory))
                    {
                        e.Enabled = false;
                        return;
                    }
                    SvnItem projectDir = statusCache[projInfo.ProjectDirectory];
                    if (!projectDir.IsVersioned)
                    {
                        e.Enabled = false;
                        return;
                    }

                    n++;

                    if (n > 1)
                    {
                        break;
                    }
                }
                break;

            case AnkhCommand.SolutionMerge:
                statusCache = e.GetService <ISvnStatusCache>();
                IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>();
                if (solutionSettings == null || string.IsNullOrEmpty(solutionSettings.ProjectRoot))
                {
                    e.Enabled = false;
                    return;
                }
                SvnItem solutionItem = statusCache[solutionSettings.ProjectRoot];
                if (solutionItem.IsVersioned)
                {
                    n = 1;
                }
                break;

            default:
                throw new InvalidOperationException();
            }

            if (n != 1)
            {
                e.Enabled = false;
            }
        }
コード例 #13
0
ファイル: AddToSccCommands.cs プロジェクト: windygu/AnkhSVN
        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 (e.Argument is IAnkhSccService)
                    {
                        dialog.CommitAllVisible = false;
                        dialog.CommitAllFiles   = false;
                    }
                    else
                    {
                        dialog.CommitAllFiles = true;
                    }

                    if (dialog.ShowDialog(e.Context) != DialogResult.OK)
                    {
                        return(false); // Don't set as managed by AnkhSVN
                    }
                    confirmed = true;

                    if (dialog.CommitAllFiles)
                    {
                        HybridCollection <string> allFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);

                        string logMessage;
                        string wcPath   = dialog.WorkingCopyDir;
                        Uri    reposUrl = dialog.RepositoryAddUrl;

                        allFiles.UniqueAddRange(e.GetService <IProjectFileMapper>().GetAllFilesOfAllProjects(true));
                        using (CreateDirectoryDialog dlg = new CreateDirectoryDialog())
                        {
                            dlg.Text                 = CommandStrings.ImportingTitle;
                            dlg.NewDirectoryName     = dialog.RepositoryAddUrl.ToString();
                            dlg.NewDirectoryReadonly = true;

                            if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                            {
                                return(false);
                            }

                            logMessage = dlg.LogMessage;
                        }


                        IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>();

                        documentTracker.SaveDocuments(allFiles); // Make sure all files are saved before updating/merging!

                        using (DocumentLock lck = documentTracker.LockDocuments(allFiles, DocumentLockType.NoReload))
                            using (lck.MonitorChangesForReload())
                            {
                                e.GetService <IProgressRunner>().RunModal(CommandStrings.ImportingTitle,
                                                                          delegate(object sender, ProgressWorkerArgs a)
                                {
                                    SvnImportArgs importArgs = new SvnImportArgs();
                                    importArgs.LogMessage    = logMessage;
                                    importArgs.Filter       +=
                                        delegate(object ieSender, SvnImportFilterEventArgs ie)
                                    {
                                        if (ie.NodeKind != SvnNodeKind.Directory)
                                        {
                                            ie.Filter = !allFiles.Contains(ie.FullPath);
                                        }
                                        else
                                        {
                                            bool filter = true;
                                            foreach (string p in allFiles)
                                            {
                                                if (SvnItem.IsBelowRoot(p, ie.FullPath))
                                                {
                                                    filter = false;
                                                    break;
                                                }
                                            }
                                            if (filter)
                                            {
                                                ie.Filter = true;
                                            }
                                        }
                                    };
                                    a.Client.Import(wcPath, reposUrl, importArgs);
                                });
                            }
                    }
                    else
                    {
                        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);
                }
        }
コード例 #14
0
ファイル: AddToSccCommands.cs プロジェクト: windygu/AnkhSVN
        static void SetProjectsManaged(CommandEventArgs e)
        {
            ISvnStatusCache    cache   = e.GetService <ISvnStatusCache>();
            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 <SccProject> projectsToBeManaged = new List <SccProject>();
            SvnItem           slnItem             = cache[e.Selection.SolutionFilename];
            Uri solutionReposRoot = null;

            if (slnItem.WorkingCopy != null)
            {
                solutionReposRoot = slnItem.WorkingCopy.RepositoryRoot;

                foreach (SccProject project in GetSelection(e.Selection))
                {
                    ISccProjectInfo 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(CommandStrings.AddXToExistingWcY,
                                                                  projInfo.ProjectName,
                                                                  parentDir.FullPath), AnkhId.PlkProduct, MessageBoxButtons.YesNoCancel);

                        switch (rslt)
                        {
                        case DialogResult.Cancel:
                            return;

                        case DialogResult.No:
                            if (CheckoutWorkingCopyForProject(e, project, 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, project, 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 (SccProject project in projectsToBeManaged)
            {
                if (!scc.IsProjectManaged(project))
                {
                    scc.SetProjectManaged(project, true);

                    monitor.ScheduleSvnStatus(mapper.GetAllFilesOf(project)); // Update for 'New' status
                }
            }
        }
コード例 #15
0
ファイル: SwitchItemCommand.cs プロジェクト: windygu/AnkhSVN
        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);
                            });
                        }
                    }
                }
        }
コード例 #16
0
        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()));
                    }
                }
        }
コード例 #17
0
ファイル: LogCommand.cs プロジェクト: windygu/AnkhSVN
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnOrigin> selected = new List <SvnOrigin>();
            ISvnStatusCache  cache    = e.GetService <ISvnStatusCache>();

            switch (e.Command)
            {
            case AnkhCommand.Log:
                IAnkhDiffHandler diffHandler = e.GetService <IAnkhDiffHandler>();
                List <SvnOrigin> items       = new List <SvnOrigin>();
                foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
                {
                    Debug.Assert(i.IsVersioned);

                    if (i.IsReplaced || i.IsAdded)
                    {
                        if (!i.HasCopyableHistory)
                        {
                            continue;
                        }

                        items.Add(new SvnOrigin(diffHandler.GetCopyOrigin(i), i.WorkingCopy.RepositoryRoot));
                        continue;
                    }

                    items.Add(new SvnOrigin(i));
                }
                PerformLog(e.Context, items, null, null);
                break;

            case AnkhCommand.SolutionHistory:
                IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>();

                PerformLog(e.Context, new SvnOrigin[] { new SvnOrigin(cache[settings.ProjectRoot]) }, null, null);
                break;

            case AnkhCommand.ProjectHistory:
                IProjectFileMapper mapper = e.GetService <IProjectFileMapper>();
                foreach (SccProject p in e.Selection.GetSelectedProjects(false))
                {
                    ISccProjectInfo info = mapper.GetProjectInfo(p);

                    if (info != null)
                    {
                        selected.Add(new SvnOrigin(cache[info.ProjectDirectory]));
                    }
                }

                PerformLog(e.Context, selected, null, null);
                break;

            case AnkhCommand.DocumentHistory:
                SvnItem docItem = e.Selection.ActiveDocumentSvnItem;
                Debug.Assert(docItem != null);

                PerformLog(e.Context, new SvnOrigin[] { new SvnOrigin(docItem) }, null, null);
                break;

            case AnkhCommand.ReposExplorerLog:
                foreach (ISvnRepositoryItem i in e.Selection.GetSelection <ISvnRepositoryItem>())
                {
                    if (i != null && i.Origin != null)
                    {
                        selected.Add(i.Origin);
                    }
                }

                if (selected.Count > 0)
                {
                    PerformLog(e.Context, selected, null, null);
                }
                break;

            case AnkhCommand.AnnotateShowLog:
                IAnnotateSection section = EnumTools.GetSingle(e.Selection.GetSelection <IAnnotateSection>());

                if (section == null)
                {
                    return;
                }

                PerformLog(e.Context, new SvnOrigin[] { section.Origin }, section.Revision, null);

                break;
            }
        }
コード例 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e">The <see cref="Ankh.Commands.CommandUpdateEventArgs"/> instance containing the event data.</param>
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            ISvnStatusCache cache;

            int count = 0;

            switch (e.Command)
            {
            case AnkhCommand.ItemEditProperties:
            case AnkhCommand.ItemShowPropertyChanges:
                foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
                {
                    if (i.IsVersioned)
                    {
                        count++;

                        if (e.Command == AnkhCommand.ItemShowPropertyChanges &&
                            !i.IsPropertyModified)
                        {
                            e.Enabled = false;
                            return;
                        }

                        if (e.Selection.IsSingleNodeSelection)
                        {
                            break;
                        }
                        if (count > 1)
                        {
                            e.Enabled = false;
                            return;
                        }
                    }
                }
                break;

            case AnkhCommand.ProjectEditProperties:
                IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();
                cache = e.GetService <ISvnStatusCache>();
                foreach (SccProject project in e.Selection.GetSelectedProjects(false))
                {
                    ISccProjectInfo info = pfm.GetProjectInfo(project);
                    if (info == null || string.IsNullOrEmpty(info.ProjectDirectory))
                    {
                        e.Enabled = false;
                        return;
                    }
                    SvnItem projectFolder = cache[info.ProjectDirectory];

                    if (projectFolder.IsVersioned)
                    {
                        count++;
                    }

                    if (count > 1)
                    {
                        break;
                    }
                }
                break;

            case AnkhCommand.SolutionEditProperties:
                cache = e.GetService <ISvnStatusCache>();
                IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>();
                if (solutionSettings == null || string.IsNullOrEmpty(solutionSettings.ProjectRoot))
                {
                    e.Enabled = false;
                    return;
                }
                SvnItem solutionItem = cache[solutionSettings.ProjectRoot];
                if (solutionItem.IsVersioned)
                {
                    count = 1;
                }
                break;

            default:
                throw new InvalidOperationException();
            }
            if (count == 0 || (count > 1 && !e.Selection.IsSingleNodeSelection))
            {
                e.Enabled = false;
            }
        }
コード例 #19
0
        public override void OnExecute(CommandEventArgs e)
        {
            SvnItem         firstVersioned = null;
            ISvnStatusCache cache          = e.GetService <ISvnStatusCache>();

            switch (e.Command)
            {
            case AnkhCommand.ItemEditProperties:
            case AnkhCommand.ItemShowPropertyChanges:
                foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
                {
                    if (i.IsVersioned)
                    {
                        firstVersioned = i;
                        break;
                    }
                }
                break;

            case AnkhCommand.ProjectEditProperties:     // use project folder
                foreach (SccProject p in e.Selection.GetSelectedProjects(false))
                {
                    IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();
                    if (pfm != null)
                    {
                        ISccProjectInfo info = pfm.GetProjectInfo(p);
                        if (info != null && info.ProjectDirectory != null)
                        {
                            firstVersioned = cache[info.ProjectDirectory];
                        }
                        if (firstVersioned != null)
                        {
                            break;
                        }
                    }
                }
                break;

            case AnkhCommand.SolutionEditProperties:     // use solution folder
                IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>();
                if (solutionSettings != null)
                {
                    firstVersioned = cache[solutionSettings.ProjectRoot];
                }
                break;
            }
            if (firstVersioned == null)
            {
                return; // exceptional case
            }
            //using (SvnClient client = e.GetService<ISvnClientPool>().GetNoUIClient())
            using (PropertyEditorDialog dialog = new PropertyEditorDialog(firstVersioned))
            {
                dialog.Context = e.Context;

                SortedList <string, PropertyEditItem> editItems = new SortedList <string, PropertyEditItem>();
                if (!e.GetService <IProgressRunner>().RunModal(CommandStrings.ReadingProperties,
                                                               delegate(object Sender, ProgressWorkerArgs wa)
                {
                    // Retrieve base properties
                    wa.Client.PropertyList(new SvnPathTarget(firstVersioned.FullPath, SvnRevision.Base),
                                           delegate(object s, SvnPropertyListEventArgs la)
                    {
                        foreach (SvnPropertyValue pv in la.Properties)
                        {
                            PropertyEditItem ei;
                            if (!editItems.TryGetValue(pv.Key, out ei))
                            {
                                editItems.Add(pv.Key, ei = new PropertyEditItem(dialog.ListView, pv.Key));
                            }

                            ei.BaseValue = pv;
                        }
                    });
                    //

                    wa.Client.PropertyList(firstVersioned.FullPath,
                                           delegate(object s, SvnPropertyListEventArgs la)
                    {
                        foreach (SvnPropertyValue pv in la.Properties)
                        {
                            PropertyEditItem ei;
                            if (!editItems.TryGetValue(pv.Key, out ei))
                            {
                                editItems.Add(pv.Key, ei = new PropertyEditItem(dialog.ListView, pv.Key));
                            }

                            ei.OriginalValue = ei.Value = pv;
                        }
                    });
                }).Succeeded)
                {
                    return; // Canceled
                }

                PropertyEditItem[] items = new PropertyEditItem[editItems.Count];
                editItems.Values.CopyTo(items, 0);
                dialog.PropertyValues = items;

                if (dialog.ShowDialog(e.Context) == DialogResult.OK)
                {
                    // Hack: Currently we save all properties, not only the in memory changed ones

                    items = dialog.PropertyValues;

                    bool hasChanges = false;
                    foreach (PropertyEditItem i in items)
                    {
                        if (i.ShouldPersist)
                        {
                            hasChanges = true;
                            break;
                        }
                    }

                    if (!hasChanges)
                    {
                        return;
                    }

                    e.GetService <IProgressRunner>().RunModal(CommandStrings.StoringPropertyValues,
                                                              delegate(object sender, ProgressWorkerArgs wa)
                    {
                        foreach (PropertyEditItem ei in items)
                        {
                            if (!ei.ShouldPersist)
                            {
                                continue;
                            }

                            if (ei.Value == null)
                            {
                                if (ei.OriginalValue != null)
                                {
                                    wa.Client.DeleteProperty(firstVersioned.FullPath, ei.PropertyName);
                                }
                            }
                            else if (!ei.Value.ValueEquals(ei.OriginalValue))
                            {
                                if (ei.Value.StringValue != null)
                                {
                                    wa.Client.SetProperty(firstVersioned.FullPath, ei.PropertyName, ei.Value.StringValue);
                                }
                                else
                                {
                                    wa.Client.SetProperty(firstVersioned.FullPath, ei.PropertyName, ei.Value.RawValue);
                                }
                            }
                        }
                    });
                } // if
            }
        }
コード例 #20
0
        protected IEnumerable <SccProject> InternalGetOwnerProjects()
        {
            Hashtable          ht = new Hashtable();
            bool               searchedProjectMapper = false;
            IProjectFileMapper projectMapper         = null;

            foreach (SelectionItem si in GetSelectedItems(false))
            {
                if (ht.Contains(si.Hierarchy))
                {
                    continue;
                }

                ht.Add(si.Hierarchy, si);

                if (si.SccProject != null)
                {
                    yield return(new SccProject(null, si.SccProject));

                    continue;
                }
                else if (si.Hierarchy is IVsSccVirtualFolders)
                {
                    continue; // Skip URL WebApplications fast
                }
                string[] files;

                // No need to fetch special files as we only want projects!
                if (!SelectionUtils.GetSccFiles(si, out files, false, false, null) || files.Length == 0)
                {
                    continue; // No files selected
                }
                if (projectMapper == null && !searchedProjectMapper)
                {
                    searchedProjectMapper = true;
                    projectMapper         = GetService <IProjectFileMapper>();
                }

                if (projectMapper != null)
                {
                    foreach (string file in files)
                    {
                        foreach (SccProject project in projectMapper.GetAllProjectsContaining(file))
                        {
                            if (project.RawHandle != null)
                            {
                                if (ht.Contains(project.RawHandle))
                                {
                                    continue;
                                }

                                ht.Add(project.RawHandle, si);
                                yield return(project);
                            }
                            else if (!ht.Contains(project))
                            {
                                ht.Add(project, si);
                                yield return(project);
                            }
                        }
                    }
                }
            }
        }
コード例 #21
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            if (e.State.SolutionBuilding || e.State.Debugging || e.State.SolutionOpening)
            {
                e.Enabled = false;
                return;
            }

            if (IsSolutionCommand(e.Command))
            {
                IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>();
                if (settings == null || string.IsNullOrEmpty(settings.ProjectRoot))
                {
                    e.Enabled = false;
                    return;
                }

                if (!settings.ProjectRootSvnItem.IsVersioned)
                {
                    e.Enabled = false;
                }
            }
            else if (IsFolderCommand(e.Command))
            {
                bool forHead  = IsHeadCommand(e.Command);
                bool foundOne = false;
                Uri  root     = null;
                foreach (SvnItem dir in e.Selection.GetSelectedSvnItems(false))
                {
                    if (!dir.IsDirectory || !dir.IsVersioned)
                    {
                        e.Enabled = false;
                        break;
                    }

                    foundOne = true;

                    if (!forHead)
                    {
                        Uri reposRoot = dir.WorkingCopy.RepositoryRoot;

                        if (root != reposRoot)
                        {
                            if (root == null)
                            {
                                reposRoot = root;
                            }
                            else
                            {
                                e.Enabled = false;
                                break;
                            }
                        }
                    }
                }

                if (!foundOne)
                {
                    e.Enabled = false;
                }
            }
            else
            {
                IProjectFileMapper pfm = null;
                ISvnStatusCache    fsc = null;

                Uri rootUrl = null;
                foreach (SccProject p in GetSelectedProjects(e))
                {
                    if (pfm == null)
                    {
                        pfm = e.GetService <IProjectFileMapper>();
                    }

                    ISccProjectInfo pi = pfm.GetProjectInfo(p);

                    if (pi == null || pi.ProjectDirectory == null)
                    {
                        continue;
                    }

                    if (fsc == null)
                    {
                        fsc = e.GetService <ISvnStatusCache>();
                    }

                    SvnItem rootItem = fsc[pi.ProjectDirectory];

                    if (!rootItem.IsVersioned)
                    {
                        continue;
                    }

                    if (IsHeadCommand(e.Command))
                    {
                        return; // Ok, we can update
                    }
                    if (rootUrl == null)
                    {
                        rootUrl = rootItem.WorkingCopy.RepositoryRoot;
                    }
                    else if (rootUrl != rootItem.WorkingCopy.RepositoryRoot)
                    {
                        // Multiple repositories selected; can't choose uniform version
                        e.Enabled = false;
                        return;
                    }
                }

                if (rootUrl == null)
                {
                    e.Enabled = false;
                }
            }
        }
コード例 #22
0
ファイル: AddToSccCommands.cs プロジェクト: windygu/AnkhSVN
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            if (!e.State.SolutionExists || (e.Command == AnkhCommand.FileSccAddProjectToSubversion && e.State.EmptySolution))
            {
                e.Enabled = false;
                return;
            }

            if (e.State.OtherSccProviderActive)
            {
                e.Enabled = false;
                return; // Only one scc provider can be active at a time
            }

            IAnkhSccService scc   = e.GetService <IAnkhSccService>();
            ISvnStatusCache cache = e.GetService <ISvnStatusCache>();

            if (scc == null || cache == null)
            {
                e.Enabled = false;
                return;
            }

            string solutionFilename = e.Selection.SolutionFilename;

            if (string.IsNullOrEmpty(solutionFilename) || !SvnItem.IsValidPath(solutionFilename))
            {
                solutionFilename = null;
            }

            if (e.Command == AnkhCommand.FileSccAddSolutionToSubversion)
            {
                if (solutionFilename == null || scc.IsSolutionManaged)
                {
                    e.Enabled = false; // Already handled
                    return;
                }
                SvnItem item = cache[solutionFilename];

                if (!item.Exists || !item.IsFile || item.ParentDirectory.NeedsWorkingCopyUpgrade)
                {
                    // Decide where you store the .sln first
                    e.Enabled = false;
                    return;
                }

                if (!item.IsVersioned)
                {
                    // If the .sln is ignored hide it in the context menus
                    // but don't hide it on the node itself
                    e.HideOnContextMenu = item.IsIgnored && !e.Selection.IsSolutionSelected;
                }
                return;
            }

            IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();

            int  n        = 0;
            bool foundOne = false;

            foreach (IEnumerable <SccProject> projects in
                     new IEnumerable <SccProject>[]
            {
                e.Selection.GetSelectedProjects(true),
                e.Selection.GetSelectedProjects(false)
            })
            {
                foreach (SccProject p in projects)
                {
                    foundOne = true;

                    ISccProjectInfo pi = pfm.GetProjectInfo(p);

                    if (pi == null || !pi.IsSccBindable)
                    {
                        continue; // Not an SCC project
                    }
                    // A project is managed if the file says its managed
                    // and the project dir is managed
                    if (pi.ProjectDirectory != null && cache[pi.ProjectDirectory].IsVersioned &&
                        scc.IsProjectManaged(p))
                    {
                        continue; // Nothing to do here
                    }
                    string projectFile = pi.ProjectFile;

                    if (n > 1 && projectFile != null && cache[projectFile].IsIgnored)
                    {
                        e.HideOnContextMenu = true;
                    }

                    return;
                }
                n++;
                if (foundOne)
                {
                    break;
                }
            }

            e.Enabled = false;
        }
コード例 #23
0
ファイル: AddToSccCommands.cs プロジェクト: necora/ank_git
        /// <summary>
        /// Returns true if <see cref="succeededProjects"/> should be set managed, false otherwise
        /// </summary>
        /// <param name="e"></param>
        /// <param name="mapper"></param>
        /// <param name="scc"></param>
        /// <param name="succeededProjects"></param>
        /// <returns></returns>
        static bool AskSetManagedSelectionProjects(CommandEventArgs e, IProjectFileMapper mapper, IAnkhSccService scc, IEnumerable<SvnProject> succeededProjects)
        {
            if (e.DontPrompt || e.IsInAutomation)
                return true;

            AnkhMessageBox mb = new AnkhMessageBox(e.Context);
            StringBuilder sb = new StringBuilder();
            bool foundOne = false;
            foreach (SvnProject project in succeededProjects)
            {
                ISvnProjectInfo info;
                if (!scc.IsProjectManaged(project) && null != (info = mapper.GetProjectInfo(project)))
                {
                    if (sb.Length > 0)
                        sb.Append("', '");

                    sb.Append(info.ProjectName);
                }

                foundOne = true;
            }

            if (!foundOne)
                return false; // No need to add when there are no projects

            string txt = sb.ToString();
            int li = txt.LastIndexOf("', '");
            if (li > 0)
                txt = txt.Substring(0, li + 1) + CommandResources.FileAnd + txt.Substring(li + 3);

            return DialogResult.Yes == mb.Show(string.Format(CommandResources.MarkXAsManaged,
                txt), AnkhId.PlkProduct, MessageBoxButtons.YesNo);
        }
コード例 #24
0
        private static void AutoOpenCommand(CommandEventArgs e, SvnItem item)
        {
            IProjectFileMapper    pfm = e.GetService <IProjectFileMapper>();
            IAnkhCommandService   svc = e.GetService <IAnkhCommandService>();
            IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>();

            if (pfm == null || svc == null || solutionSettings == null)
            {
                return;
            }

            // We can assume we have a file

            if (pfm.IsProjectFileOrSolution(item.FullPath))
            {
                // Ok, the user selected the current solution file or an open project
                // Let's jump to it in the solution explorer

                svc.ExecCommand(AnkhCommand.ItemSelectInSolutionExplorer);
                return;
            }

            if (item.InSolution)
            {
                // The file is part of the solution, we can assume VS knows how to open it
                svc.ExecCommand(AnkhCommand.ItemOpenVisualStudio);
                return;
            }

            string filename = item.Name;
            string ext      = item.Extension;

            if (string.IsNullOrEmpty(ext))
            {
                // No extension -> Open as text
                svc.PostExecCommand(AnkhCommand.ItemOpenTextEditor);
                return;
            }

            foreach (string projectExt in solutionSettings.AllProjectExtensionsFilter.Split(';'))
            {
                if (projectExt.TrimStart('*').Trim().Equals(ext, StringComparison.OrdinalIgnoreCase))
                {
                    // We found a project or solution: Ask VS to open it

                    e.GetService <IAnkhSolutionSettings>().OpenProjectFile(item.FullPath);
                    return;
                }
            }

            bool odd = false;

            foreach (string block in solutionSettings.OpenFileFilter.Split('|'))
            {
                odd = !odd;
                if (odd)
                {
                    continue;
                }

                foreach (string itemExt in block.Split(';'))
                {
                    if (itemExt.TrimStart('*').Trim().Equals(ext, StringComparison.OrdinalIgnoreCase))
                    {
                        VsShellUtilities.OpenDocument(e.Context, item.FullPath);
                        return;
                    }
                }
            }

            // Ultimate fallback: Just open the file as windows would
            svc.PostExecCommand(AnkhCommand.ItemOpenWindows);
        }