コード例 #1
0
ファイル: UnlockCommand.cs プロジェクト: windygu/AnkhSVN
        public override void OnExecute(CommandEventArgs e)
        {
            AnkhConfig            config = e.GetService <IAnkhConfigurationService>().Instance;
            ICollection <SvnItem> targets;

            if (!e.DontPrompt && (e.PromptUser || (!Shift && !config.SuppressLockingUI)))
            {
                using (PendingChangeSelector selector = new PendingChangeSelector())
                {
                    selector.Text = CommandStrings.UnlockTitle;
                    selector.PreserveWindowPlacement = true;

                    selector.LoadItems(new List <SvnItem>(e.Selection.GetSelectedSvnItems(true)),
                                       delegate(SvnItem i) { return(i.IsLocked); },
                                       delegate(SvnItem i) { return(i.IsLocked); });

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

                    targets = new List <SvnItem>(selector.GetSelectedItems());
                }
            }
            else
            {
                List <SvnItem> toUnlock = new List <SvnItem>();
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
                {
                    if (item.IsLocked)
                    {
                        toUnlock.Add(item);
                    }
                }
                targets = toUnlock;
            }

            if (targets.Count == 0)
            {
                return;
            }

            List <string> files = new List <string>(SvnItem.GetPaths(targets));

            if (files.Count == 0)
            {
                return;
            }

            e.GetService <IProgressRunner>().RunModal(
                CommandStrings.UnlockTitle,
                delegate(object sender, ProgressWorkerArgs ee)
            {
                SvnUnlockArgs ua = new SvnUnlockArgs();

                ee.Client.Unlock(files, ua);
            });
        }
コード例 #2
0
        public override void OnExecute(CommandEventArgs e)
        {
            IPendingChangesManager pcm = e.GetService <IPendingChangesManager>();

            PendingChange.RefreshContext       rc = new PendingChange.RefreshContext(e.Context);
            Dictionary <string, PendingChange> selectedChanges = new Dictionary <string, PendingChange>(StringComparer.OrdinalIgnoreCase);
            List <SvnItem> resources = new List <SvnItem>();

            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
            {
                PendingChange pc;

                if (PendingChange.CreateIfPending(rc, item, out pc))
                {
                    if (!pc.IsNoChangeForPatching())
                    {
                        selectedChanges.Add(pc.FullPath, pc);
                        resources.Add(pc.SvnItem);
                    }
                }
            }

            if (resources.Count == 0)
            {
                return;
            }

            using (PendingChangeSelector pcs = new PendingChangeSelector())
            {
                pcs.Text = CommandStrings.CreatePatchTitle;
                pcs.PreserveWindowPlacement = true;
                pcs.LoadItems(resources);

                DialogResult dr = pcs.ShowDialog(e.Context);

                if (dr != DialogResult.OK)
                {
                    return;
                }

                string fileName = GetFileName(e.Context.DialogOwner);
                if (string.IsNullOrEmpty(fileName))
                {
                    return;
                }

                PendingChangeCreatePatchArgs pca = new PendingChangeCreatePatchArgs();
                pca.FileName = fileName;
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();
                pca.RelativeToPath      = ss.ProjectRoot;
                pca.AddUnversionedFiles = true;

                List <PendingChange> patchChanges = new List <PendingChange>(pcs.GetSelection());
                e.GetService <IPendingChangeHandler>().CreatePatch(patchChanges, pca);
            }
        }
コード例 #3
0
        public override void OnExecute(CommandEventArgs e)
        {
            string         argumentFile = e.Argument as string;
            List <SvnItem> selection    = new List <SvnItem>();

            if (string.IsNullOrEmpty(argumentFile))
            {
                if (e.ShouldPrompt(true))
                {
                    selection.AddRange(e.Selection.GetSelectedSvnItems(true));

                    using (PendingChangeSelector pcs = new PendingChangeSelector())
                    {
                        pcs.Text = CommandStrings.AddDialogTitle;

                        pcs.PreserveWindowPlacement = true;

                        pcs.LoadItems(selection,
                                      delegate(SvnItem item) { return(!item.IsVersioned && item.IsVersionable); },
                                      delegate(SvnItem item)
                        {
                            if (item.IsIgnored)
                            {
                                return(false);
                            }
                            else if (item.IsSccExcluded)
                            {
                                return(false);
                            }
                            return(item.InSolution);
                        });

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

                        selection.Clear();
                        selection.AddRange(pcs.GetSelectedItems());
                    }
                }
                else
                {
                    foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
                    {
                        if (!item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution)
                        {
                            selection.Add(item);
                        }
                    }
                }
            }
            else
            {
                selection.Add(e.GetService <ISvnStatusCache>()[argumentFile]);
            }

            ICollection <string>     paths           = SvnItem.GetPaths(selection);
            IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>();

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

            using (DocumentLock lck = documentTracker.LockDocuments(paths, DocumentLockType.NoReload))
                using (lck.MonitorChangesForReload())
                    e.GetService <IProgressRunner>().RunModal(CommandStrings.AddTaskDialogTitle,
                                                              delegate(object sender, ProgressWorkerArgs ee)
                    {
                        SvnAddArgs args = new SvnAddArgs();
                        args.Depth      = SvnDepth.Empty;
                        args.AddParents = true;

                        foreach (SvnItem item in selection)
                        {
                            ee.Client.Add(item.FullPath, args);
                        }
                    });
        }
コード例 #4
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnItem>            toRevert     = new List <SvnItem>();
            HybridCollection <string> contained    = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
            HybridCollection <string> checkedItems = null;

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
            {
                if (contained.Contains(i.FullPath))
                {
                    continue;
                }

                contained.Add(i.FullPath);

                if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty) || i.IsConflicted)
                {
                    toRevert.Add(i);
                }
            }

            Predicate <SvnItem> initialCheckedFilter = null;

            if (toRevert.Count > 0)
            {
                checkedItems = new HybridCollection <string>(contained, StringComparer.OrdinalIgnoreCase);

                initialCheckedFilter = delegate(SvnItem item)
                {
                    return(checkedItems.Contains(item.FullPath));
                };
            }

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(true))
            {
                if (contained.Contains(i.FullPath))
                {
                    continue;
                }

                contained.Add(i.FullPath);

                if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty))
                {
                    toRevert.Add(i);
                }
            }

            if (e.PromptUser || (!e.DontPrompt && !Shift))
            {
                using (PendingChangeSelector pcs = new PendingChangeSelector())
                {
                    pcs.Text = CommandStrings.RevertDialogTitle;

                    pcs.PreserveWindowPlacement = true;

                    pcs.LoadItems(toRevert, null, initialCheckedFilter);

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

                    toRevert.Clear();
                    toRevert.AddRange(pcs.GetSelectedItems());
                }
            }


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

            ICollection <string> revertPaths = SvnItem.GetPaths(toRevert);

            documentTracker.SaveDocuments(revertPaths);

            // Revert items backwards to make sure we revert children before their ancestors
            toRevert.Sort(delegate(SvnItem i1, SvnItem i2)
            {
                bool add1 = i1.IsAdded || i1.IsReplaced;
                bool add2 = i2.IsAdded || i2.IsReplaced;

                if (add1 && !add2)
                {
                    return(-1);
                }
                else if (add2 && !add1)
                {
                    return(1);
                }
                else if (add1 && add2)
                {
                    return(-StringComparer.OrdinalIgnoreCase.Compare(i1.FullPath, i2.FullPath));
                }

                return(StringComparer.OrdinalIgnoreCase.Compare(i1.FullPath, i2.FullPath));
            });

            // perform the actual revert
            using (DocumentLock dl = documentTracker.LockDocuments(revertPaths, DocumentLockType.NoReload))
                using (dl.MonitorChangesForReload())
                {
                    e.GetService <IProgressRunner>().RunModal(CommandStrings.Reverting,
                                                              delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnRevertArgs ra = new SvnRevertArgs();
                        ra.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_DIRECTORY, SvnErrorCode.SVN_ERR_WC_INVALID_OPERATION_DEPTH); // Parent revert invalidated this change
                        ra.Depth = SvnDepth.Empty;
                        List <SvnItem> toRevertWithInfinity = new List <SvnItem>();

                        foreach (SvnItem item in toRevert)
                        {
                            if (!a.Client.Revert(item.FullPath, ra))
                            {
                                switch (ra.LastException.SvnErrorCode)
                                {
                                case SvnErrorCode.SVN_ERR_WC_INVALID_OPERATION_DEPTH:
                                    toRevertWithInfinity.Add(item);
                                    break;
                                }
                            }
                        }

                        ra = new SvnRevertArgs();
                        ra.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_DIRECTORY);
                        ra.Depth = SvnDepth.Infinity;
                        foreach (SvnItem item in toRevertWithInfinity)
                        {
                            SvnStatusArgs sa          = new SvnStatusArgs();
                            sa.RetrieveIgnoredEntries = false;
                            sa.IgnoreExternals        = true;
                            sa.ThrowOnError           = false;
                            bool modifications        = false;

                            using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0))
                            {
                                if (!a.Client.Status(item.FullPath, sa,
                                                     delegate(object ss, SvnStatusEventArgs ee)
                                {
                                    if (ee.FullPath == item.FullPath)
                                    {
                                        return;
                                    }

                                    if (ee.Conflicted ||
                                        (ee.LocalPropertyStatus != SvnStatus.Normal && ee.LocalPropertyStatus != SvnStatus.None))
                                    {
                                        ee.Cancel = modifications = true;
                                    }
                                    else
                                    {
                                        switch (ee.LocalNodeStatus)
                                        {
                                        case SvnStatus.None:
                                        case SvnStatus.Normal:
                                        case SvnStatus.Ignored:
                                        case SvnStatus.External:
                                        case SvnStatus.NotVersioned:
                                            break;

                                        default:
                                            ee.Cancel = modifications = true;
                                            break;
                                        }
                                    }
                                }))
                                {
                                    modifications = true;
                                }
                            }

                            if (!modifications)
                            {
                                a.Client.Revert(item.FullPath, ra);
                            }
                        }
                    });
                }
        }