Beispiel #1
1
        public override void OnExecute(CommandEventArgs e)
        {
            List<SvnItem> items = new List<SvnItem>(e.Selection.GetSelectedSvnItems(true));

            e.GetService<IProgressRunner>().RunModal("Running Cleanup",
                delegate(object sender, ProgressWorkerArgs a)
                {
                    HybridCollection<string> wcs = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase);

                    foreach (SvnItem item in items)
                    {
                        if (!item.IsVersioned)
                            continue;

                        SvnWorkingCopy wc = item.WorkingCopy;

                        if (wc != null && !wcs.Contains(wc.FullPath))
                            wcs.Add(wc.FullPath);
                    }

                    SvnCleanUpArgs args = new SvnCleanUpArgs();
                    args.ThrowOnError = false;
                    foreach (string path in wcs)
                        a.Client.CleanUp(path, args);
                });
        }
Beispiel #2
0
        public void OnExecute(CommandEventArgs e)
        {
            PendingCommitsPage page = e.Context.GetService<PendingCommitsPage>();

            if (page != null)
                page.LogMessageVisible = !page.LogMessageVisible;
        }
        public void OnExecute(CommandEventArgs e)
        {
            SvnItem firstVersioned = null;
            IFileStatusCache cache = e.GetService<IFileStatusCache>();
            IAnkhSolutionSettings solutionSettings = e.GetService<IAnkhSolutionSettings>();
            if (solutionSettings != null)
            {
                firstVersioned = cache[solutionSettings.ProjectRoot];
            }

            if (firstVersioned == null)
                return; // exceptional case

            using (IssueTrackerConfigDialog dialog = new IssueTrackerConfigDialog(e.Context))
            {
                if (dialog.ShowDialog(e.Context) == System.Windows.Forms.DialogResult.OK)
                {
                    IIssueTrackerSettings currentSettings = e.GetService<IIssueTrackerSettings>();

                    IssueRepository newRepository = dialog.NewIssueRepository;
                    if (newRepository == null
                        || string.IsNullOrEmpty(newRepository.ConnectorName)
                        || newRepository.RepositoryUri == null)
                    {
                        DeleteIssueRepositoryProperties(e.Context, firstVersioned);
                    }
                    else if (currentSettings == null
                        || currentSettings.ShouldPersist(newRepository))
                    {
                        SetIssueRepositoryProperties(e.Context, firstVersioned, newRepository);
                    }
                }
            }
        }
Beispiel #4
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            CommandID cd = new CommandID(pguidCmdGroup, unchecked((int)nCmdID));

            List<CommandData> items;

            if (!_data.TryGetValue(cd, out items))
                return (int)Constants.OLECMDERR_E_NOTSUPPORTED;

            foreach (CommandData d in items)
            {
                if (!d.Control.ContainsFocus)
                    continue;

                CommandEventArgs ce = new CommandEventArgs((AnkhCommand)cd.ID, GetService<AnkhContext>());
                if (d.UpdateHandler != null)
                {
                    CommandUpdateEventArgs ud = new CommandUpdateEventArgs(ce.Command, ce.Context);

                    d.UpdateHandler(d.Control, ud);

                    if (!ud.Enabled)
                        return (int)Constants.OLECMDERR_E_DISABLED;
                }

                d.Handler(d.Control, ce);

                return VSConstants.S_OK;
            }

            return (int)Constants.OLECMDERR_E_NOTSUPPORTED;
        }
Beispiel #5
0
        public override void OnExecute(CommandEventArgs e)
        {
            if (!SmartListView.SupportsGrouping)
                return;

            base.OnExecute(e);
        }
Beispiel #6
0
 public override void OnExecute(CommandEventArgs e)
 {
     switch (e.Command)
     {
         case AnkhCommand.ItemResolveMerge:
             Resolved(e);
             break;
         case AnkhCommand.ItemResolveMergeTool:
             throw new NotImplementedException();
         case AnkhCommand.ItemResolveMineFull:
             Resolve(e, SvnAccept.MineFull);
             break;
         case AnkhCommand.ItemResolveTheirsFull:
             Resolve(e, SvnAccept.TheirsFull);
             break;
         case AnkhCommand.ItemResolveWorking:
             Resolve(e, SvnAccept.Merged);
             break;
         case AnkhCommand.ItemResolveBase:
             Resolve(e, SvnAccept.Base);
             break;
         case AnkhCommand.ItemResolveMineConflict:
             Resolve(e, SvnAccept.Mine);
             break;
         case AnkhCommand.ItemResolveTheirsConflict:
             Resolve(e, SvnAccept.Theirs);
             break;
         default:
             throw new NotImplementedException();
     }
 }
        public override void OnExecute(CommandEventArgs e)
        {
            using (ProjectCommitDialog dlg = new ProjectCommitDialog())
            {
                dlg.Context = e.Context;
                dlg.PreserveWindowPlacement = true;
                dlg.LoadChanges(GetChanges(e));

                dlg.LogMessageText = logMessage ?? "";
                dlg.IssueNumberText = issueId ?? "";

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

                logMessage = dlg.LogMessageText;
                issueId = dlg.IssueNumberText;

                if (dr == DialogResult.OK)
                {
                    PendingChangeCommitArgs pca = new PendingChangeCommitArgs();
                    pca.StoreMessageOnError = true;
                    // TODO: Commit it!
                    List<PendingChange> toCommit = new List<PendingChange>(dlg.GetSelection());
                    dlg.FillArgs(pca);

                    if (e.GetService<IPendingChangeHandler>().Commit(toCommit, pca))
                    {
                        logMessage = issueId = null;
                    }
                }
            }
        }
Beispiel #8
0
        public override void OnExecute(CommandEventArgs e)
        {
            using (ProjectCommitDialog pcd = new ProjectCommitDialog())
            {
                pcd.Context = e.Context;
                pcd.LogMessageText = storedLogMessage;
                pcd.IssueNumberText = storedIssueNumber;

                pcd.PreserveWindowPlacement = true;

                pcd.LoadItems(e.Selection.GetSelectedSvnItems(true));

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

                storedLogMessage = pcd.LogMessageText;
                storedIssueNumber = pcd.IssueNumberText;

                if (dr != DialogResult.OK)
                    return;

                PendingChangeCommitArgs pca = new PendingChangeCommitArgs();
                pca.StoreMessageOnError = true;
                // TODO: Commit it!
                List<PendingChange> toCommit = new List<PendingChange>(pcd.GetSelection());
                pcd.FillArgs(pca);

                e.GetService<IPendingChangeHandler>().Commit(toCommit, pca);
            }

            // not in the finally, because we want to preserve the message for a
            // non-successful commit
            storedLogMessage = null;
            storedIssueNumber = null;
        }
        public void OnExecute(CommandEventArgs e)
        {
            PendingChangesPage page = GetPage(e);

            if(page != null && page.CanRefreshList)
                page.RefreshList();
        }
Beispiel #10
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem selected = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            if (selected == null)
                return;

            Uri uri = selected.Uri;
            string name = selected.Origin.Target.FileName;

            IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>();

            using (CheckoutDialog dlg = new CheckoutDialog())
            {
                dlg.Context = e.Context;
                dlg.Uri = uri;
                dlg.LocalPath = System.IO.Path.Combine(ss.NewProjectLocation, name);

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

                e.GetService<IProgressRunner>().RunModal("Checking Out",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnCheckOutArgs args = new SvnCheckOutArgs();
                        args.Revision = dlg.Revision;
                        args.Depth = dlg.Recursive ? SvnDepth.Infinity : SvnDepth.Files;
                        args.IgnoreExternals = dlg.IgnoreExternals;

                        a.Client.CheckOut(dlg.Uri, dlg.LocalPath, args);
                    });
            }
        }
        public void OnExecute(CommandEventArgs e)
        {
            SvnItem item = e.Argument as SvnItem;
            if (item == null)
                return;

            using(EditReadOnlyFileDialog dialog = new EditReadOnlyFileDialog(item))
            {
                switch(dialog.ShowDialog(e.Context))
                {
                    case DialogResult.Yes:
                        // make writable and allow
                        FileAttributes attr = File.GetAttributes(item.FullPath);
                        File.SetAttributes(item.FullPath, attr & ~FileAttributes.ReadOnly);
                        e.Result = true;
                        break;
                    case DialogResult.No:
                        // Don't make writable but allow
                        e.Result = true;
                        break;
                    default:
                        // Don't make writeable and don't allow
                        e.Result = false;
                        break;
                }
            }
        }
Beispiel #12
0
        protected override void OnExecute(SmartListView list, CommandEventArgs e)
        {
            bool extend = ((Control.ModifierKeys & Keys.Shift) != 0);

            int n = (int)(e.Command - AnkhCommand.ListViewSort0);
            SmartColumn column = list.AllColumns[n];

            if (list.SortColumns.Contains(column))
            {
                list.SortColumns.Remove(column);

                list.UpdateSortGlyphs();

                if (list.SortColumns.Count > 0)
                    list.Sort();
            }
            else if (!extend)
            {
                list.SortColumns.Clear();
                list.SortColumns.Add(column);
                list.UpdateSortGlyphs();
                list.Sort();
            }
            else
            {
                list.SortColumns.Add(column);
                list.UpdateSortGlyphs();
                list.Sort();
            }
        }
        public override void OnExecute(CommandEventArgs e)
        {
            WorkingCopyExplorerControl ctrl = e.Selection.ActiveDialogOrFrameControl as WorkingCopyExplorerControl;

            if (ctrl != null)
                ctrl.RemoveRoot();
        }
Beispiel #14
0
        public override void OnExecute(CommandEventArgs e)
        {
            SvnItem node = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false));

            IAnkhCommandService cmd = e.GetService<IAnkhCommandService>();
            switch (e.Command)
            {
                case AnkhCommand.ItemSelectInRepositoryExplorer:
                    if (node == null || node.Uri == null)
                        return;

                    if (cmd != null)
                        cmd.DirectlyExecCommand(AnkhCommand.RepositoryBrowse, node.FullPath);
                    break;
                case AnkhCommand.ItemSelectInWorkingCopyExplorer:
                    if (node == null || !node.Exists)
                        return;

                    if (cmd != null)
                        cmd.DirectlyExecCommand(AnkhCommand.WorkingCopyBrowse, node.FullPath);
                    break;
                case AnkhCommand.ItemSelectInSolutionExplorer:
                    if (node == null)
                        return;

                    IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer));

                    IVsProject project = VsShellUtilities.GetProject(e.Context, node.FullPath) as IVsProject;

                    if (hierWindow != null)
                    {
                        int found;
                        uint id;
                        VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1];
                        if (project != null && ErrorHandler.Succeeded(project.IsDocumentInProject(node.FullPath, out found, prio, out id)) && found != 0)
                        {
                            hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem);
                        }
                        else if (string.Equals(node.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase))
                            hierWindow.ExpandItem(e.GetService<IVsUIHierarchy>(typeof(SVsSolution)), VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem);

                        // Now try to activate the solution explorer
                        IVsWindowFrame solutionExplorer;
                        Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer);
                        IVsUIShell shell = e.GetService<IVsUIShell>(typeof(SVsUIShell));

                        if (shell != null)
                        {
                            shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer);

                            if (solutionExplorer != null)
                                solutionExplorer.Show();
                        }

                    }
                    break;
            }
        }
Beispiel #15
0
        public void OnExecute(CommandEventArgs e)
        {
            if(_skip) // Only show this message once!
                return;

            _skip = true;
            AnkhMessageBox mb = new AnkhMessageBox(e.Context);
            mb.Show(string.Format(Resources.UnsupportedWorkingCopyFound, e.Argument));
        }
Beispiel #16
0
        public virtual void OnExecute(CommandEventArgs e)
        {
            SmartListView list = GetListView(e);

            if (list == null)
                return;

            OnExecute(list, e);
        }
Beispiel #17
0
        /// <see cref="Ankh.Commands.ICommandHandler.OnExecute" />
        public void OnExecute(CommandEventArgs e)
        {
            List<SvnItem> svnItems = new List<SvnItem>();
            IFileStatusCache cache = e.GetService<IFileStatusCache>();

            switch (e.Command)
            {
                case AnkhCommand.ItemMerge:
                    // TODO: Check for solution and/or project selection to use the folder instead of the file
                    foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                    {
                        svnItems.Add(item);
                    }
                    break;
                case AnkhCommand.ProjectMerge:
                    foreach (SvnProject p in e.Selection.GetSelectedProjects(false))
                    {
                        IProjectFileMapper pfm = e.GetService<IProjectFileMapper>();

                        ISvnProjectInfo info = pfm.GetProjectInfo(p);
                        if (info != null && info.ProjectDirectory != null)
                        {
                            svnItems.Add(cache[info.ProjectDirectory]);
                        }
                    }
                    break;
                case AnkhCommand.SolutionMerge:
                    svnItems.Add(cache[e.GetService<IAnkhSolutionSettings>().ProjectRoot]);
                    break;
                default:
                    throw new InvalidOperationException();
            }

            IEnumerable<string> selectedFiles = e.Selection.GetSelectedFiles(true);
            IAnkhOpenDocumentTracker tracker = e.GetService<IAnkhOpenDocumentTracker>();

            using (DocumentLock lck = tracker.LockDocuments(selectedFiles, DocumentLockType.ReadOnly))
            using (lck.MonitorChangesForReload())
            using (MergeWizard dialog = new MergeWizard(e.Context, svnItems[0]))
            {
                DialogResult result = dialog.ShowDialog(e.Context);
                //result = uiService.ShowDialog(dialog);

                if (result == DialogResult.OK)
                {
                    using (MergeResultsDialog mrd = new MergeResultsDialog())
                    {
                        mrd.MergeActions = dialog.MergeActions;
                        mrd.ResolvedMergeConflicts = dialog.ResolvedMergeConflicts;

                        mrd.ShowDialog(e.Context);
                    }
                }

            }
        }
Beispiel #18
0
        public override void OnExecute(CommandEventArgs e)
        {
            List<SvnItem> toResolve = new List<SvnItem>();

            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
            {
                if (item.IsCasingConflicted)
                {
                    toResolve.Add(item);
                }
            }
            try
            {
                foreach (SvnItem item in toResolve)
                {
                    string svnPath = GetSvnCasing(item);
                    string actualPath = SvnTools.GetTruePath(item.FullPath);

                    if (svnPath == null || actualPath == null)
                        continue; // not found
                    if (!string.Equals(svnPath, actualPath, StringComparison.OrdinalIgnoreCase))
                        continue; // More than casing rename

                    string svnName = Path.GetFileName(svnPath);
                    string actualName = Path.GetFileName(actualPath);

                    if (svnName == actualName)
                        continue; // Can't fix directories!

                    IAnkhOpenDocumentTracker odt = e.GetService<IAnkhOpenDocumentTracker>();
                    using (odt.LockDocument(svnPath, DocumentLockType.NoReload))
                    using (odt.LockDocument(actualPath, DocumentLockType.NoReload))
                    {
                        try
                        {
                            // Try the actual rename
                            File.Move(actualPath, svnPath);
                        }
                        catch { }

                        try
                        {
                            // And try to fix the project+document system
                            VsShellUtilities.RenameDocument(e.Context, actualPath, svnPath);
                        }
                        catch
                        { }
                    }
                }
            }
            finally
            {
                e.GetService<IFileStatusMonitor>().ScheduleSvnStatus(SvnItem.GetPaths(toResolve));
            }
        }
Beispiel #19
0
        public void OnExecute(CommandEventArgs e)
        {
            if (_commandService == null)
                _commandService = e.GetService<IAnkhCommandService>();
            if (_projectNotifier == null)
                _projectNotifier = e.GetService<ProjectNotifier>(typeof(IFileStatusMonitor));

            _commandService.TockCommand(e.Command);

            _projectNotifier.HandleEvent(e.Command);
        }
Beispiel #20
0
        public void OnExecute(CommandEventArgs e)
        {
            if (_commandService == null)
                _commandService = e.GetService<IAnkhCommandService>();
            if (_pendingChanges == null)
                _pendingChanges = e.GetService<PendingChangeManager>(typeof(IPendingChangesManager));

            _commandService.TockCommand(e.Command);

            _pendingChanges.OnTickRefresh();
        }
Beispiel #21
0
        protected override void OnExecute(SmartListView list, CommandEventArgs e)
        {
            bool value = (e.Command == AnkhCommand.ListViewSortDescending);

            foreach (SmartColumn sc in list.SortColumns)
            {
                sc.ReverseSort = value;
            }
            list.UpdateSortGlyphs();
            list.Sort();
        }
Beispiel #22
0
        void OnPasteList(CommandEventArgs e, LogMessageEditor lme)
        {
            StringBuilder sb = new StringBuilder();
            foreach (PendingChange pci in lme.PasteSource.PendingChanges)
            {
                sb.AppendFormat("* {0}", pci.RelativePath);
                sb.AppendLine();
            }

            lme.PasteText(sb.ToString());
        }
        public void OnExecute(CommandEventArgs e)
        {
            IAnkhServiceProvider context = e.Context;
            if (!EnsureAllProjectsLoaded(context))
                return;
            // TODO: Verify if all project files and the solution are open and saved

            using (ChangeSourceControl csc = new ChangeSourceControl())
            {
                csc.Context = e.Context;

                csc.ShowDialog(e.Context);
            }
        }
        public override void OnExecute(CommandEventArgs e)
        {
            string info;

            if (e.Argument is string)
            {
                // Allow opening from
                info = (string)e.Argument;
            }
            else if (e.Command == AnkhCommand.WorkingCopyAdd)
            {
                using (AddWorkingCopyExplorerRootDialog dlg = new AddWorkingCopyExplorerRootDialog())
                {
                    DialogResult dr = dlg.ShowDialog(e.Context);

                    if (dr != DialogResult.OK || string.IsNullOrEmpty(dlg.NewRoot))
                        return;

                    info = dlg.NewRoot;
                }
            }
            else
                throw new InvalidOperationException("WorkingCopyBrowse was called without a path");

            if (!string.IsNullOrEmpty(info))
            {
                WorkingCopyExplorerControl ctrl = e.Selection.ActiveDialogOrFrameControl as WorkingCopyExplorerControl;

                if (ctrl == null)
                {
                    IAnkhPackage pkg = e.GetService<IAnkhPackage>();
                    pkg.ShowToolWindow(AnkhToolWindow.WorkingCopyExplorer);
                }

                ctrl = e.Selection.ActiveDialogOrFrameControl as WorkingCopyExplorerControl;

                if (ctrl != null)
                {
                    switch (e.Command)
                    {
                        case AnkhCommand.WorkingCopyAdd:
                            ctrl.AddRoot(info);
                            break;
                        case AnkhCommand.WorkingCopyBrowse:
                            ctrl.BrowsePath(e.Context, info);
                            break;
                    }
                }
            }
        }
Beispiel #25
0
        public void OnExecute(CommandEventArgs e)
        {
            PendingCommitsPage page = e.Context.GetService<PendingCommitsPage>();

            if (page != null)
            {
                string fileName = GetFileName(e.Context.DialogOwner);

                if (!string.IsNullOrEmpty(fileName))
                {
                    page.DoCreatePatch(fileName);
                }
            }
        }
Beispiel #26
0
        public void OnExecute(CommandEventArgs e)
        {
            if (_commandService == null)
                _commandService = e.GetService<IAnkhCommandService>();
            if (_fileCache == null)
                _fileCache = e.GetService<FileStatusCache>(typeof(IFileStatusCache));

            _commandService.TockCommand(e.Command);

            if (e.Command == AnkhCommand.FileCacheFinishTasks)
                _fileCache.OnCleanup();
            else
                _fileCache.BroadcastChanges();
        }
Beispiel #27
0
        void OnPasteRecent(CommandEventArgs e, LogMessageEditor lme)
        {
            using (RecentMessageDialog rmd = new RecentMessageDialog())
            {
                rmd.Context = e.Context;

                if (DialogResult.OK != rmd.ShowDialog(e.Context))
                    return;

                string text = rmd.SelectedText;
                if (!string.IsNullOrEmpty(text))
                    lme.PasteText(text);
            }
        }
Beispiel #28
0
        internal void OnExecute(Ankh.Commands.CommandEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            switch (e.Command)
            {
            case AnkhCommand.PcLogEditorPasteRecentLog:
                break;
            }
            if (sb.Length > 0)
            {
                logMessageEditor.PasteText(sb.ToString());
            }
        }
Beispiel #29
0
        public void OnExecute(CommandEventArgs e)
        {
            if (_commandService == null)
                _commandService = e.GetService<IAnkhCommandService>();
            if (_projectTracker == null)
                _projectTracker = e.GetService<ProjectTracker>(typeof(IAnkhProjectDocumentTracker));
            if(_sccProvider == null)
                _sccProvider = e.GetService<AnkhSccProvider>(typeof(IAnkhSccService));

            _commandService.TockCommand(e.Command);

            _projectTracker.OnSccCleanup(e);
            _sccProvider.OnSccCleanup(e);
        }
        public override void OnExecute(CommandEventArgs e)
        {
            PathSelectorResult result = ShowDialog(e);
            if (!result.Succeeded)
                return;

            SvnRevisionRange revRange = new SvnRevisionRange(result.RevisionStart, result.RevisionEnd);

            IAnkhTempFileManager tempfiles = e.GetService<IAnkhTempFileManager>();
            string tempFile = tempfiles.GetTempFile(".patch");

            IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>();
            string slndir = ss.ProjectRoot;
            string slndirP = slndir + "\\";

            SvnDiffArgs args = new SvnDiffArgs();
            args.IgnoreAncestry = true;
            args.NoDeleted = false;
            args.Depth = result.Depth;

            using (MemoryStream stream = new MemoryStream())
            {
                e.Context.GetService<IProgressRunner>().RunModal("Diffing",
                    delegate(object sender, ProgressWorkerArgs ee)
                    {
                        foreach (SvnItem item in result.Selection)
                        {
                            SvnWorkingCopy wc;
                            if (!string.IsNullOrEmpty(slndir) &&
                                item.FullPath.StartsWith(slndirP, StringComparison.OrdinalIgnoreCase))
                                args.RelativeToPath = slndir;
                            else if ((wc = item.WorkingCopy) != null)
                                args.RelativeToPath = wc.FullPath;
                            else
                                args.RelativeToPath = null;

                            ee.Client.Diff(item.FullPath, revRange, args, stream);
                        }

                        stream.Flush();
                        stream.Position = 0;
                    });
                using (StreamReader sr = new StreamReader(stream))
                {
                    File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8);
                    VsShellUtilities.OpenDocument(e.Context, tempFile);
                }
            }
        }
Beispiel #31
0
        public override void OnExecute(CommandEventArgs e)
        {
            IFileStatusMonitor fsm = e.GetService<IFileStatusMonitor>();

            foreach (SvnItem i in GetSelection(e))
            {
                if (i.InSolution)
                    continue;

                if (e.Command == AnkhCommand.ItemAddToPending || e.Command == AnkhCommand.DocumentAddToPending)
                    fsm.ScheduleMonitor(i.FullPath);
                else
                    fsm.StopMonitoring(i.FullPath);
            }
        }
Beispiel #32
0
        public override void OnExecute(CommandEventArgs e)
        {
            IEnumerable <SvnItem> items = e.Argument as IEnumerable <SvnItem>;

            if (e.Command == AnkhCommand.SccLock && items == null)
            {
                return;
            }

            if (items == null)
            {
                List <SvnItem> choices = new List <SvnItem>();
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                {
                    if (item.IsFile && item.IsVersioned && !item.IsNewAddition && !item.IsLocked)
                    {
                        choices.Add(item);
                    }
                }

                items = choices;
            }

            if (EnumTools.IsEmpty(items))
            {
                return;
            }

            bool   stealLocks = false;
            string comment    = "";

            AnkhConfig config = e.GetService <IAnkhConfigurationService>().Instance;

            if (!e.DontPrompt && (e.PromptUser || !(Shift || config.SuppressLockingUI)))
            {
                using (LockDialog dlg = new LockDialog())
                {
                    dlg.Context = e.Context;
                    dlg.LoadItems(items);

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

                    items      = new List <SvnItem>(dlg.GetCheckedItems());
                    stealLocks = dlg.StealLocks;
                    comment    = dlg.Message;
                }
            }

            ICollection <string> files = SvnItem.GetPaths(items);

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

            SortedList <string, string> alreadyLockedFiles = new SortedList <string, string>(StringComparer.OrdinalIgnoreCase);

            e.GetService <IProgressRunner>().RunModal(
                CommandStrings.LockingTitle,
                delegate(object sender, ProgressWorkerArgs ee)
            {
                SvnLockArgs la = new SvnLockArgs();
                la.StealLock   = stealLocks;
                la.Comment     = comment;
                la.AddExpectedError(SvnErrorCode.SVN_ERR_FS_PATH_ALREADY_LOCKED);
                la.Notify += delegate(object nSender, SvnNotifyEventArgs notifyArgs)
                {
                    if (notifyArgs.Action == SvnNotifyAction.LockFailedLock)
                    {
                        string userName;

                        if (notifyArgs.Lock != null && !string.IsNullOrEmpty(notifyArgs.Lock.Owner))
                        {
                            userName = notifyArgs.Lock.Owner;
                        }
                        else
                        {
                            userName = GuessUserFromError(notifyArgs.Error.Message) ?? "?";
                        }


                        alreadyLockedFiles.Add(notifyArgs.FullPath, userName);
                    }
                };
                ee.Client.Lock(files, la);
            });

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

            StringBuilder msg = new StringBuilder();

            msg.AppendLine(CommandStrings.ItemsAlreadyLocked);
            msg.AppendLine();

            foreach (KeyValuePair <string, string> kv in alreadyLockedFiles)
            {
                if (!string.IsNullOrEmpty(kv.Value))
                {
                    msg.AppendFormat(CommandStrings.ItemFileLocked, kv.Key, kv.Value);
                }
                else
                {
                    msg.Append(kv.Key);
                }
                msg.AppendLine();
            }

            // TODO: Create a dialog where the user can select what locks to steal, and also what files are already locked.
            AnkhMessageBox box  = new AnkhMessageBox(e.Context);
            DialogResult   rslt = box.Show(
                msg.ToString().TrimEnd(),
                "",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);

            if (rslt == DialogResult.Yes)
            {
                e.GetService <IProgressRunner>().RunModal(
                    CommandStrings.LockingTitle,
                    delegate(object sender, ProgressWorkerArgs ee)
                {
                    SvnLockArgs la = new SvnLockArgs();
                    la.StealLock   = true;
                    la.Comment     = comment;
                    ee.Client.Lock(files, la);
                });
            }
        }