Esempio n. 1
0
 PathSelectorResult IUIShell.ShowPathSelector(PathSelectorInfo info)
 {
     throw new NotImplementedException();
 }
Esempio n. 2
0
 public PathSelector(PathSelectorInfo info)
     : this()
 {
     _info = info;
 }
Esempio n. 3
0
        public override void OnExecute(CommandEventArgs e)
        {
            SvnRevision updateTo;
            SvnDepth depth;
            List<string> files = new List<string>();
            if (e.Command == AnkhCommand.UpdateItemSpecific)
            {
                IUIShell uiShell = e.GetService<IUIShell>();

                PathSelectorInfo info = new PathSelectorInfo("Select Items to Update",
                    e.Selection.GetSelectedSvnItems(true));

                info.CheckedFilter += delegate(SvnItem item) { return item.IsVersioned; };
                info.VisibleFilter += delegate(SvnItem item) { return item.IsVersioned; };
                info.EnableRecursive = true;
                info.RevisionStart = SvnRevision.Head;
                info.Depth = SvnDepth.Infinity;

                PathSelectorResult result = !Shift ? uiShell.ShowPathSelector(info) : info.DefaultResult;

                if (!result.Succeeded)
                    return;

                updateTo = result.RevisionStart;
                depth = result.Depth;
                List<SvnItem> dirs = new List<SvnItem>();

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

                    if (item.IsDirectory)
                    {
                        if (result.Depth < SvnDepth.Infinity)
                        {
                            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                            DialogResult dr = mb.Show(CommandStrings.CantUpdateDirectoriesNonRecursive, "", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning);

                            if (dr != DialogResult.Yes)
                                return;

                            depth = SvnDepth.Infinity;
                        }
                    }

                    bool found = false;
                    foreach (SvnItem dir in dirs)
                    {
                        if (item.IsBelowPath(dir))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                        continue;

                    files.Add(item.FullPath);

                    if (item.IsDirectory)
                        dirs.Add(item);
                }

            }
            else
            {
                updateTo = SvnRevision.Head;
                depth = SvnDepth.Infinity;
                List<SvnItem> dirs = new List<SvnItem>();

                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
                {
                    if (!item.IsVersioned)
                        continue;

                    bool found = false;
                    foreach (SvnItem p in dirs)
                    {
                        if (item.IsBelowPath(p) && p.WorkingCopy == item.WorkingCopy)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                        continue;

                    files.Add(item.FullPath);

                    if (item.IsDirectory)
                        dirs.Add(item);
                }
            }

            IAnkhOpenDocumentTracker tracker = e.GetService<IAnkhOpenDocumentTracker>();
            tracker.SaveDocuments(e.Selection.GetSelectedFiles(true));
            using (DocumentLock lck = tracker.LockDocuments(files, DocumentLockType.NoReload))
            using (lck.MonitorChangesForReload())
            {
                SvnUpdateResult ur;
                ProgressRunnerArgs pa = new ProgressRunnerArgs();
                pa.CreateLog = true;

                e.GetService<IProgressRunner>().RunModal(CommandStrings.UpdatingTitle, pa,
                                                         delegate(object sender, ProgressWorkerArgs ee)
                                                         {
                                                             SvnUpdateArgs ua = new SvnUpdateArgs();
                                                             ua.Depth = depth;
                                                             ua.Revision = updateTo;
                                                             e.GetService<IConflictHandler>().
                                                                 RegisterConflictHandler(ua, ee.Synchronizer);
                                                             ee.Client.Update(files, ua, out ur);
                                                         });
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Generates the diff from the current selection.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="selection"></param>
        /// <param name="revisions"></param>
        /// <param name="visibleFilter"></param>
        /// <returns>The diff as a string.</returns>
        protected virtual string GetDiff(IAnkhServiceProvider context, ISelectionContext selection, SvnRevisionRange revisions, Predicate<SvnItem> visibleFilter)
        {
            if (selection == null)
                throw new ArgumentNullException("selection");
            if (context == null)
                throw new ArgumentNullException("context");

            IUIShell uiShell = context.GetService<IUIShell>();

            bool foundModified = false;
            foreach (SvnItem item in selection.GetSelectedSvnItems(true))
            {
                if (item.IsModified || item.IsDocumentDirty)
                {
                    foundModified = true;
                    break; // no need (yet) to keep searching
                }
            }

            PathSelectorInfo info = new PathSelectorInfo("Select items for diffing", selection.GetSelectedSvnItems(true));
            info.VisibleFilter += visibleFilter;
            if (foundModified)
                info.CheckedFilter += delegate(SvnItem item) { return item.IsFile && (item.IsModified || item.IsDocumentDirty); };

            info.RevisionStart = revisions == null ? SvnRevision.Base : revisions.StartRevision;
            info.RevisionEnd = revisions == null ? SvnRevision.Working : revisions.EndRevision;

            PathSelectorResult result;
            // should we show the path selector?
            if (!Shift && (revisions == null || !foundModified))
            {
                result = uiShell.ShowPathSelector(info);
                if (!result.Succeeded)
                    return null;
            }
            else
                result = info.DefaultResult;

            if (!result.Succeeded)
                return null;

            SaveAllDirtyDocuments(selection, context);

            return DoExternalDiff(context, result);
        }
        static PathSelectorResult ShowDialog(CommandEventArgs e)
        {
            PathSelectorInfo info = new PathSelectorInfo("Select items for diffing", e.Selection.GetSelectedGitItems(true));
            IUIShell uiShell = e.GetService<IUIShell>();
            info.VisibleFilter += delegate { return true; };
            info.CheckedFilter += delegate(GitItem item) { return item.IsFile && (item.IsModified || item.IsDocumentDirty); };

            info.RevisionStart = GitRevision.Base;
            info.RevisionEnd = GitRevision.Working;

            // should we show the path selector?
            if (!Shift)
            {
                return uiShell.ShowPathSelector(info);
            }
            return info.DefaultResult;
        }
Esempio n. 6
0
 public override PathSelectorInfo ShowPathSelector(PathSelectorInfo info)
 {
     this.ShowPathSelectorCalled = true;
     return(info);
 }
Esempio n. 7
0
        public override void OnExecute(CommandEventArgs e)
        {
            List<GitItem> selectedFiles = new List<GitItem>();
            bool selectionHasDeleted = false;

            if (e.Command == VisualGitCommand.DocumentShowChanges)
            {
                GitItem item = e.Selection.ActiveDocumentItem;

                if(item == null)
                    return;
                selectedFiles.Add(item);
            }
            else
                foreach (GitItem item in e.Selection.GetSelectedGitItems(false))
                {
                    if (!item.IsVersioned || (item.Status.State == GitStatus.Added && !item.Status.IsCopied))
                        continue;

                    if ( e.Command == VisualGitCommand.ItemCompareBase
                         || e.Command == VisualGitCommand.ItemShowChanges)
                    {
                        if (!(item.IsModified || item.IsDocumentDirty)
                            || !item.IsLocalDiffAvailable // exclude if local diff is not available
                            )
                            continue;
                    }

                    if (e.Command == VisualGitCommand.DiffLocalItem)
                    {
                        selectionHasDeleted |= !NotDeletedFilter(item);
                    }

                    selectedFiles.Add(item);
                }

            GitRevisionRange revRange = null;
            switch (e.Command)
            {
                case VisualGitCommand.DiffLocalItem:
                    break; // revRange null -> show selector
                case VisualGitCommand.ItemCompareBase:
                case VisualGitCommand.ItemShowChanges:
                case VisualGitCommand.DocumentShowChanges:
                    revRange = new GitRevisionRange(GitRevision.Base, GitRevision.Working);
                    break;
                case VisualGitCommand.ItemCompareCommitted:
                    revRange = new GitRevisionRange(GitRevision.Committed, GitRevision.Working);
                    break;
                case VisualGitCommand.ItemCompareLatest:
                    revRange = new GitRevisionRange(GitRevision.Head, GitRevision.Working);
                    break;
                case VisualGitCommand.ItemComparePrevious:
                    revRange = new GitRevisionRange(GitRevision.Previous, GitRevision.Working);
                    break;
            }

            if (e.PromptUser || selectedFiles.Count > 1 || revRange == null)
            {
                PathSelectorInfo info = new PathSelectorInfo("Select item for Diff", selectedFiles);
                info.SingleSelection = false;
                info.RevisionStart = revRange == null ? GitRevision.Base : revRange.StartRevision;
                info.RevisionEnd = revRange == null ? GitRevision.Working : revRange.EndRevision;
                if (selectionHasDeleted)
                {
                    // do not allow selecting deleted items if the revision combination includes GitRevision.Working
                    info.CheckableFilter += new PathSelectorInfo.SelectableFilter(delegate(GitItem item, GitRevision from, GitRevision to)
                    {
                        if (item != null
                            && (from == GitRevision.Working
                                || to == GitRevision.Working
                                )
                            )
                        {
                            return NotDeletedFilter(item);
                        }
                        return true;
                    });
                }
                info.EnableRecursive = false;
                info.Depth = GitDepth.Infinity;

                PathSelectorResult result;
                // should we show the path selector?
                if (e.PromptUser || !Shift)
                {
                    IUIShell ui = e.GetService<IUIShell>();

                    result = ui.ShowPathSelector(info);
                    if (!result.Succeeded)
                        return;
                }
                else
                    result = info.DefaultResult;

                selectedFiles.Clear();
                selectedFiles.AddRange(result.Selection);
                revRange = new GitRevisionRange(result.RevisionStart, result.RevisionEnd);
            }

            if (revRange.EndRevision.RevisionType == GitRevisionType.Working ||
                revRange.StartRevision.RevisionType == GitRevisionType.Working)
            {
                // Save only the files needed

                IVisualGitOpenDocumentTracker tracker = e.GetService<IVisualGitOpenDocumentTracker>();
                if (tracker != null)
                    tracker.SaveDocuments(GitItem.GetPaths(selectedFiles));
            }

            IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>();
            foreach (GitItem item in selectedFiles)
            {
                VisualGitDiffArgs da = new VisualGitDiffArgs();

                if (item.Status.IsCopied &&
                    (!revRange.StartRevision.RequiresWorkingCopy || !revRange.EndRevision.RequiresWorkingCopy))
                {
                    // The file is copied, use its origins history instead of that of the new file
                    GitTarget copiedFrom = diff.GetCopyOrigin(item);

                    // TODO: Maybe handle Previous/Committed as history

                    if (copiedFrom != null && !revRange.StartRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.BaseFile = diff.GetTempFile(copiedFrom, revRange.StartRevision, true)))
                            return; // Canceled
                        da.BaseTitle = diff.GetTitle(copiedFrom, revRange.StartRevision);
                    }

                    if (copiedFrom != null && !revRange.EndRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.MineFile = diff.GetTempFile(copiedFrom, revRange.EndRevision, true)))
                            return; // Canceled
                        da.MineTitle = diff.GetTitle(copiedFrom, revRange.EndRevision);
                    }
                }

                if (da.BaseFile == null)
                {
                    if (null == (da.BaseFile = (revRange.StartRevision == GitRevision.Working) ? item.FullPath :
                        diff.GetTempFile(item, revRange.StartRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.BaseTitle = diff.GetTitle(item, revRange.StartRevision);
                }

                if (da.MineFile == null)
                {
                    if (null == (da.MineFile = (revRange.EndRevision == GitRevision.Working) ? item.FullPath :
                        diff.GetTempFile(item, revRange.EndRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.MineTitle = diff.GetTitle(item, revRange.EndRevision);
                }

                if (!String.Equals(da.MineFile, item.FullPath, StringComparison.OrdinalIgnoreCase))
                    da.ReadOnly = true;

                diff.RunDiff(da);
            }
        }
Esempio n. 8
0
 public override PathSelectorInfo ShowPathSelector(PathSelectorInfo info)
 {
     this.ShowPathSelectorCalled = true;
     return info;
 }
Esempio n. 9
0
        public override void OnExecute(CommandEventArgs e)
        {
            IEnumerable<SvnItem> items = e.Argument as IEnumerable<SvnItem>;

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

            PathSelectorInfo psi = new PathSelectorInfo("Select Files to Lock",
                                                        items ?? e.Selection.GetSelectedSvnItems(true));
            psi.VisibleFilter += delegate(SvnItem item)
                                     {
                                         return item.IsFile && item.IsVersioned && !item.IsLocked;
                                     };

            psi.CheckedFilter += delegate(SvnItem item)
                                     {
                                         return item.IsFile && item.IsVersioned && !item.IsLocked;
                                     };

            PathSelectorResult psr;
            bool stealLocks = false;
            string comment = "";

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

            IEnumerable<SvnItem> selectedItems = null;

            if (!config.SuppressLockingUI || e.PromptUser)
            {
                if (e.PromptUser || !(Shift || e.DontPrompt))
                {
                    using (LockDialog dlg = new LockDialog(psi))
                    {
                        bool succeeded = (dlg.ShowDialog(e.Context) == DialogResult.OK);
                        psr = new PathSelectorResult(succeeded, dlg.CheckedItems);
                        stealLocks = dlg.StealLocks;
                        comment = dlg.Message;
                    }

                }
                else
                {
                    psr = psi.DefaultResult;
                }
                if (!psr.Succeeded)
                {
                    return;
                }
                selectedItems = psr.Selection;
            }

            if (selectedItems == null)
                selectedItems = psi.DefaultResult.Selection;

            List<string> files = new List<string>();
            foreach (SvnItem item in selectedItems)
            {
                if (item.IsFile) // svn lock is only for files
                {
                    files.Add(item.FullPath);
                }
            }

            if (files.Count == 0)
                return;

            SortedList<string, string> alreadyLockedFiles = new SortedList<string, string>(StringComparer.OrdinalIgnoreCase);
            e.GetService<IProgressRunner>().RunModal(
                "Locking",
                 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)
                                          {
                                              alreadyLockedFiles.Add(notifyArgs.FullPath, GuessUserFromError(notifyArgs.Error.Message));
                                          }
                                      };
                     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);

            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);
                     });
            }
        }
Esempio n. 10
0
 public LockDialog(PathSelectorInfo info)
     : this()
 {
     this._info = info;
 }