Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        bool EnsureAllProjectsLoaded(IAnkhServiceProvider context)
        {
            List<IVsHierarchy> unloaded = GetProjects(context, __VSENUMPROJFLAGS.EPF_UNLOADEDINSOLUTION);

            if(unloaded != null && unloaded.Count > 0)
            {
                AnkhMessageBox mb = new AnkhMessageBox(context);

                if(DialogResult.Yes != mb.Show("The solution contains unloaded projects. Any changes you make will not affect "+
                    "the unloaded projects.\n\nIt is strongly recommended that you reload all projects before continuing.\n\n" +
                    "Would you like to continue?", "Source Control", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation))
                    return false;
            }

            return true;
        }
Ejemplo n.º 3
0
        static void SetProjectsManaged(CommandEventArgs e)
        {
            IFileStatusCache cache = e.GetService<IFileStatusCache>();
            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<SvnProject> projectsToBeManaged = new List<SvnProject>();
            SvnItem slnItem = cache[e.Selection.SolutionFilename];
            Uri solutionReposRoot = slnItem.WorkingCopy.RepositoryRoot;

            foreach (SvnProject project in GetSelection(e.Selection))
            {
                ISvnProjectInfo 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(CommandResources.AddXToExistingWcY,
                                                              Path.GetFileName(projInfo.ProjectName),
                                                              parentDir.FullPath), AnkhId.PlkProduct, MessageBoxButtons.YesNoCancel);

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

                    monitor.ScheduleSvnStatus(mapper.GetAllFilesOf(project)); // Update for 'New' status
                }
            }
        }
Ejemplo n.º 4
0
        static bool HandleUnmanagedOrUnversionedSolution(CommandEventArgs e, SvnItem solutionItem)
        {
            IAnkhSccService scc = e.GetService<IAnkhSccService>();
            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

            bool shouldActivate = false;
            if (!scc.IsActive)
            {
                if (e.State.OtherSccProviderActive)
                    return false; // Can't switch in this case.. Nothing to do

                // Ankh is not the active provider, we should register as active
                shouldActivate = true;
            }

            if (scc.IsSolutionManaged && solutionItem.IsVersioned)
                return true; // Projects should still be checked

            bool confirmed = false;

            if (solutionItem.IsVersioned)
            { /* File is in subversion; just enable */ }
            else if (solutionItem.IsVersionable)
            {
                if (!AddVersionableSolution(e, solutionItem, ref confirmed))
                    return false;
            }
            else
            {
                if (!CheckoutWorkingCopyForSolution(e, ref confirmed))
                    return false;
            }

            if (!confirmed && !e.DontPrompt && !e.IsInAutomation &&
                DialogResult.Yes != mb.Show(string.Format(CommandResources.MarkXAsManaged,
                Path.GetFileName(e.Selection.SolutionFilename)), "", MessageBoxButtons.YesNo))
            {
                return false;
            }

            SetSolutionManaged(shouldActivate, solutionItem, scc);

            return true;
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        static bool AddVersionableSolution(CommandEventArgs e, SvnItem solutionItem, ref bool confirmed)
        {
            AnkhMessageBox mb = new AnkhMessageBox(e.Context);
            SvnItem parentDir = GetVersionedParent(solutionItem);

            // File is not versioned but is inside a versioned directory
            if (!e.DontPrompt && !e.IsInAutomation)
            {
                if (!solutionItem.Parent.IsVersioned)
                {
                    AddPathToSubversion(e, e.Selection.SolutionFilename);

                    return true;
                }

                DialogResult rslt = mb.Show(string.Format(CommandResources.AddXToExistingWcY,
                                                          Path.GetFileName(e.Selection.SolutionFilename),
                                                          parentDir.FullPath), AnkhId.PlkProduct, MessageBoxButtons.YesNoCancel);

                if (rslt == DialogResult.Cancel)
                    return false;
                if (rslt == DialogResult.No)
                {
                    // Checkout new working copy
                    return CheckoutWorkingCopyForSolution(e, ref confirmed);
                }
                if (rslt == DialogResult.Yes)
                {
                    // default case: Add to existing workingcopy
                    AddPathToSubversion(e, e.Selection.SolutionFilename);

                    return true;
                }
                return false;
            }

            confirmed = true;
            return true;
        }
Ejemplo n.º 7
0
        private void ReleaseExternalWrites()
        {
            Dictionary<string, DocumentLock> modified;
            lock (_externallyChanged)
            {
                if (_externallyChanged.Count == 0)
                    return;

                modified = new Dictionary<string, DocumentLock>(_externallyChanged, StringComparer.OrdinalIgnoreCase);
                _externallyChanged.Clear();
            }

            try
            {
                foreach (KeyValuePair<string, DocumentLock> file in modified)
                {
                    ScheduleSvnStatus(file.Key);
                    SvnItem item = Cache[file.Key];

                    if (item.IsConflicted)
                    {
                        AnkhMessageBox mb = new AnkhMessageBox(Context);

                        DialogResult dr = mb.Show(string.Format(Resources.YourMergeToolSavedXWouldYouLikeItMarkedAsResolved, file.Key),
                            Resources.MergeCompleted, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

                        switch (dr)
                        {
                            case DialogResult.Yes:
                                using (SvnClient c = Context.GetService<ISvnClientPool>().GetNoUIClient())
                                {
                                    SvnResolveArgs ra = new SvnResolveArgs();
                                    ra.ThrowOnError = false;

                                    c.Resolve(file.Key, SvnAccept.Merged, ra);
                                }
                                goto case DialogResult.No;
                            case DialogResult.No:
                                if (!item.IsModified)
                                {
                                    // Reload?
                                }
                                break;
                            default:
                                // Let VS handle the file
                                return; // No reload
                        }
                    }

                    if (!item.IsDocumentDirty)
                    {
                        if (file.Value != null)
                            file.Value.Reload(file.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService<IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                    eh.OnError(ex);
                else
                    throw;
            }
            finally
            {
                foreach (DocumentLock dl in modified.Values)
                {
                    if (dl != null)
                        dl.Dispose();
                }
            }
        }
Ejemplo n.º 8
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);
                                                         });
            }
        }
Ejemplo n.º 9
0
        public override void OnExecute(CommandEventArgs e)
        {
            Dictionary<string, List<string>> add = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
            List<string> refresh = new List<string>();

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
            {
                if (Skip(i))
                    continue;
                refresh.Add(i.FullPath);
                switch (e.Command)
                {
                    case AnkhCommand.ItemIgnoreFile:
                        AddIgnore(add, i.Parent, i.Name);
                        break;
                    case AnkhCommand.ItemIgnoreFileType:
                        AddIgnore(add, i.Parent, "*" + i.Extension);
                        break;
                    case AnkhCommand.ItemIgnoreFilesInFolder:
                        AddIgnore(add, i.Parent, "*");
                        break;
                    case AnkhCommand.ItemIgnoreFolder:
                        SvnItem p = i.Parent;
                        SvnItem pp = null;

                        while (null != p && null != (pp = p.Parent) && !pp.IsVersioned)
                            p = pp;

                        if (p != null && pp != null)
                            AddIgnore(add, pp, p.Name);
                        break;
                }
            }

            try
            {

                AnkhMessageBox mb = new AnkhMessageBox(e.Context);
                foreach (KeyValuePair<string, List<string>> k in add)
                {
                    if (k.Value.Count == 0)
                        continue;

                    string text;

                    if (k.Value.Count == 1)
                        text = "'" + k.Value[0] + "'";
                    else
                    {
                        StringBuilder sb = new StringBuilder();

                        for (int i = 0; i < k.Value.Count; i++)
                        {
                            if (i == 0)
                                sb.AppendFormat("'{0}'", k.Value[i]);
                            else if (i == k.Value.Count - 1)
                                sb.AppendFormat(" and '{0}'", k.Value[i]);
                            else
                                sb.AppendFormat(", '{0}'", k.Value[i]);
                        }
                        text = sb.ToString();
                    }

                    switch (mb.Show(string.Format(CommandStrings.WouldYouLikeToAddXToTheIgnorePropertyOnY,
                        text,
                        k.Key), CommandStrings.IgnoreCaption, System.Windows.Forms.MessageBoxButtons.YesNoCancel))
                    {
                        case System.Windows.Forms.DialogResult.Yes:
                            AddIgnores(e.Context, k.Key, k.Value);
                            break;
                        case System.Windows.Forms.DialogResult.No:
                            continue;
                        default:
                            return;
                    }
                }
            }
            finally
            {
                e.GetService<IFileStatusMonitor>().ScheduleSvnStatus(refresh);
            }
        }
Ejemplo n.º 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 = VSConstants.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 (!ErrorHandler.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 if (item.IsFile)
                        File.Delete(item.FullPath);
                    else if (item.IsDirectory)
                        Directory.Delete(item.FullPath, true); // Recursive delete!!
                }
                finally
                {
                    // TODO: Notify the working copy explorer here!
                    // (Maybe via one of these methods below)

                    e.GetService<IFileStatusCache>().MarkDirtyRecursive(item.FullPath);
                    e.GetService<IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath);
                }

                // Ok, now remove the file from projects

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

                List<SvnProject> projects = new List<SvnProject>(pfm.GetAllProjectsContaining(item.FullPath));

                foreach (SvnProject p in projects)
                {
                    IVsProject2 p2 = p.RawHandle as IVsProject2;

                    if (p2 == null)
                        continue;

                    VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1];
                    int found;
                    uint id;
                    if (!ErrorHandler.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 (!ErrorHandler.Succeeded(hr))
                        break;
                }
            }

            if (!ErrorHandler.Succeeded(hr))
                mb.Show(Marshal.GetExceptionForHR(hr).Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Ejemplo n.º 11
0
        public override void OnExecute(CommandEventArgs e)
        {
            SvnItem root = GetRoot(e);

            if (root == null)
                return;

            using (CreateBranchDialog dlg = new CreateBranchDialog())
            {
                if (e.Command == AnkhCommand.ProjectBranch)
                    dlg.Text = CommandStrings.BranchProject;

                dlg.SrcFolder = root.FullPath;
                dlg.SrcUri = root.Uri;
                dlg.EditSource = false;

                dlg.Revision = root.Status.Revision;

                RepositoryLayoutInfo info;
                if (RepositoryUrlUtils.TryGuessLayout(e.Context, root.Uri, out info))
                    dlg.NewDirectoryName = new Uri(info.BranchesRoot, ".");

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

                    string msg = dlg.LogMessage;

                    bool retry = false;
                    bool ok = false;
                    ProgressRunnerResult rr =
                        e.GetService<IProgressRunner>().RunModal("Creating Branch/Tag",
                        delegate(object sender, ProgressWorkerArgs ee)
                        {
                            SvnInfoArgs ia = new SvnInfoArgs();
                            ia.ThrowOnError = false;

                            if (ee.Client.Info(dlg.NewDirectoryName, ia, null))
                            {
                                DialogResult dr = DialogResult.Cancel;

                                ee.Synchronizer.Invoke((AnkhAction)
                                    delegate
                                    {
                                        AnkhMessageBox mb = new AnkhMessageBox(ee.Context);
                                        dr = mb.Show(string.Format("The Branch/Tag at Url '{0}' already exists.", dlg.NewDirectoryName),
                                            "Path Exists", MessageBoxButtons.RetryCancel);
                                    }, null);

                                if (dr == DialogResult.Retry)
                                {
                                    // show dialog again to let user modify the branch URL
                                    retry = true;
                                }
                            }
                            else
                            {
                                SvnCopyArgs ca = new SvnCopyArgs();
                                ca.CreateParents = true;
                                ca.LogMessage = msg;

                                ok = dlg.CopyFromUri ?
                                    ee.Client.RemoteCopy(new SvnUriTarget(dlg.SrcUri, dlg.SelectedRevision), dlg.NewDirectoryName, ca) :
                                    ee.Client.RemoteCopy(new SvnPathTarget(dlg.SrcFolder), dlg.NewDirectoryName, ca);
                            }
                        });

                    if (rr.Succeeded && ok && dlg.SwitchToBranch)
                    {
                        e.GetService<IAnkhCommandService>().PostExecCommand(AnkhCommand.SolutionSwitchDialog, dlg.NewDirectoryName);
                    }

                    if (!retry)
                        break;
                }
            }
        }
Ejemplo n.º 12
0
        public override void OnExecute(CommandEventArgs e)
        {
            AnkhMessageBox mb = new AnkhMessageBox(e.Context);
            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
            {
                if (!item.Exists)
                    continue;

                try
                {
                    switch (e.Command)
                    {
                        case AnkhCommand.ItemOpenVisualStudio:
                            IProjectFileMapper mapper = e.GetService<IProjectFileMapper>();

                            if (mapper.IsProjectFileOrSolution(item.FullPath))
                                goto case AnkhCommand.ItemOpenSolutionExplorer;
                            if (item.IsDirectory)
                                goto case AnkhCommand.ItemOpenFolder;

                            if (!item.IsFile || !item.Exists)
                                continue;

                            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.ItemOpenFolder:
                            if (!item.IsDirectory)
                                System.Diagnostics.Process.Start(Path.GetDirectoryName(item.FullPath));
                            else
                                System.Diagnostics.Process.Start(item.FullPath);
                            break;
                        case AnkhCommand.ItemOpenWindows:
                            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(item.FullPath);
                            psi.Verb = "open";
                            System.Diagnostics.Process.Start(psi);
                            break;

                        case AnkhCommand.ItemOpenSolutionExplorer:
                            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 && ErrorHandler.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)), 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;
                    }
                }
                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);
                }

            }
        }
Ejemplo n.º 13
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            if (item == null)
                return;

            string copyTo;
            bool copyBelow = false;
            bool suggestExport = false;
            IFileStatusCache cache = e.GetService<IFileStatusCache>();

            if (item.NodeKind == SharpSvn.SvnNodeKind.Directory)
            {
                using (FolderBrowserDialog fd = new FolderBrowserDialog())
                {
                    fd.ShowNewFolderButton = false;

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

                    copyTo = fd.SelectedPath;
                    copyBelow = true;

                    SvnItem dirItem = cache[copyTo];

                    if (dirItem == null || !dirItem.IsVersioned)
                        suggestExport = true;
                }
            }
            else
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.CheckPathExists = true;
                    sfd.OverwritePrompt = true;
                    string name = item.Origin.Target.FileName;
                    string ext = Path.GetExtension(item.Origin.Target.FileName);
                    sfd.Filter = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.'));
                    sfd.FileName = name;

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

                    copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName);

                    SvnItem fileItem = cache[copyTo];

                    if (File.Exists(copyTo))
                    {
                        // We prompted to confirm; remove the file!

                        if (fileItem.IsVersioned)
                            e.GetService<IProgressRunner>().RunModal("Copying",
                                delegate(object sender, ProgressWorkerArgs a)
                                {
                                    SvnDeleteArgs da = new SvnDeleteArgs();
                                    da.Force = true;
                                    a.Client.Delete(copyTo, da);
                                });
                        else
                            File.Delete(copyTo);
                    }

                    SvnItem dir = fileItem.Parent;

                    if (dir == null || !(dir.IsVersioned && dir.IsVersionable))
                        suggestExport = true;
                }
            }

            if (!suggestExport)
            {
                e.GetService<IProgressRunner>().RunModal("Copying",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnCopyArgs ca = new SvnCopyArgs();
                        ca.CreateParents = true;
                        if (copyBelow)
                            ca.AlwaysCopyAsChild = true;

                        a.Client.Copy(item.Origin.Target, copyTo, ca);
                    });
            }
            else
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                if (DialogResult.Yes == mb.Show("The specified path is not in a workingcopy; would you like to export the file instead?",
                    "No Working Copy", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    e.GetService<IProgressRunner>().RunModal("Exporting",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnExportArgs ea = new SvnExportArgs();
                        ea.Revision = item.Revision;

                        a.Client.Export(item.Origin.Target, copyTo, ea);
                    });
                }
            }
        }
Ejemplo n.º 14
0
        public override void OnExecute(CommandEventArgs e)
        {
            // TODO: Choose which conflict to edit if we have more than one!
            SvnItem conflict = null;

            if (e.Command == AnkhCommand.DocumentConflictEdit)
            {
                conflict = e.Selection.ActiveDocumentItem;

                if (conflict == null || !conflict.IsConflicted)
                    return;
            }
            else
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                {
                    if (item.IsConflicted)
                    {
                        conflict = item;
                        break;
                    }
                }

            if (conflict == null)
                return;

            conflict.MarkDirty();
            if (conflict.Status.LocalContentStatus != SvnStatus.Conflicted)
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                mb.Show(string.Format(CommandStrings.TheConflictInXIsAlreadyResolved, conflict.FullPath), CommandStrings.EditConflictTitle,
                    System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                return;
            }

            SvnInfoEventArgs conflictInfo = null;

            bool ok = false;
            ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal("Retrieving Conflict Information",
                delegate(object sender, ProgressWorkerArgs a)
                {
                    ok = a.Client.GetInfo(conflict.FullPath, out conflictInfo);
                });

            if (!ok || !r.Succeeded || conflictInfo == null)
                return;

            AnkhMergeArgs da = new AnkhMergeArgs();
            string dir = conflict.Directory;

            da.BaseFile = Path.Combine(dir, conflictInfo.ConflictOld ?? conflictInfo.ConflictNew);
            da.TheirsFile = Path.Combine(dir, conflictInfo.ConflictNew ?? conflictInfo.ConflictOld);

            if (!string.IsNullOrEmpty(conflictInfo.ConflictWork))
                da.MineFile = Path.Combine(dir, conflictInfo.ConflictWork);
            else
                da.MineFile = conflict.FullPath;

            da.MergedFile = conflict.FullPath;

            da.BaseTitle = "Base";
            da.TheirsTitle = "Theirs";
            da.MineTitle = "Mine";
            da.MergedTitle = conflict.Name;

            e.GetService<IAnkhDiffHandler>().RunMerge(da);
        }
Ejemplo n.º 15
0
        static void DoBlame(CommandEventArgs e, SvnOrigin item, SvnRevision revisionStart, SvnRevision revisionEnd, bool ignoreEols, SvnIgnoreSpacing ignoreSpacing, bool retrieveMergeInfo)
        {
            SvnWriteArgs wa = new SvnWriteArgs();
            wa.Revision = revisionEnd;

            SvnBlameArgs ba = new SvnBlameArgs();
            ba.Start = revisionStart;
            ba.End = revisionEnd;
            ba.IgnoreLineEndings = ignoreEols;
            ba.IgnoreSpacing = ignoreSpacing;
            ba.RetrieveMergedRevisions = retrieveMergeInfo;

            SvnTarget target = item.Target;

            IAnkhTempFileManager tempMgr = e.GetService<IAnkhTempFileManager>();
            string tempFile = tempMgr.GetTempFileNamed(target.FileName);

            Collection<SvnBlameEventArgs> blameResult = null;
            Dictionary<long, string> logMessages = new Dictionary<long, string>();

            ba.Notify += delegate(object sender, SvnNotifyEventArgs ee)
            {
                if (ee.Action == SvnNotifyAction.BlameRevision && ee.RevisionProperties != null)
                {
                    if (ee.RevisionProperties.Contains(SvnPropertyNames.SvnLog))
                        logMessages[ee.Revision] = ee.RevisionProperties[SvnPropertyNames.SvnLog].StringValue;
                }
            };

            bool retry = false;
            ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee)
            {
                using (FileStream fs = File.Create(tempFile))
                {
                    ee.Client.Write(target, fs, wa);
                }

                ba.SvnError +=
                    delegate(object errorSender, SvnErrorEventArgs errorEventArgs)
                    {
                        if (errorEventArgs.Exception is SvnClientBinaryFileException)
                        {
                            retry = true;
                            errorEventArgs.Cancel = true;
                        }
                    };
                ee.Client.GetBlame(target, ba, out blameResult);
            });

            if (retry)
            {
                using (AnkhMessageBox mb = new AnkhMessageBox(e.Context))
                {
                    if (DialogResult.Yes == mb.Show(
                                                CommandStrings.AnnotateBinaryFileContinueAnywayText,
                                                CommandStrings.AnnotateBinaryFileContinueAnywayTitle,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                    {
                        r = e.GetService<IProgressRunner>()
                            .RunModal(CommandStrings.Annotating,
                                      delegate(object sender, ProgressWorkerArgs ee)
                                      {
                                          ba.IgnoreMimeType = true;
                                          ee.Client.GetBlame(target, ba, out blameResult);
                                      });
                    }
                }
            }

            if (!r.Succeeded)
                return;

            AnnotateEditorControl annEditor = new AnnotateEditorControl();
            IAnkhEditorResolver er = e.GetService<IAnkhEditorResolver>();

            annEditor.Create(e.Context, tempFile);
            annEditor.LoadFile(tempFile);
            annEditor.AddLines(item, blameResult, logMessages);

            // Detect and set the language service
            Guid language;
            if (er.TryGetLanguageService(Path.GetExtension(target.FileName), out language))
            {
                // Extension is mapped -> user
                annEditor.SetLanguageService(language);
            }
            else if (blameResult != null && blameResult.Count > 0 && blameResult[0].Line != null)
            {
                // Extension is not mapped -> Check if this is xml (like project files)
                string line = blameResult[0].Line.Trim();

                if (line.StartsWith("<?xml")
                    || (line.StartsWith("<") && line.Contains("xmlns=\"http://schemas.microsoft.com/developer/msbuild/")))
                {
                    if (er.TryGetLanguageService(".xml", out language))
                    {
                        annEditor.SetLanguageService(language);
                    }
                }
            }
        }
Ejemplo n.º 16
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);
                     });
            }
        }