Beispiel #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            IAnkhSolutionSettings settings = Context.GetService <IAnkhSolutionSettings>();
            ISvnStatusCache       cache    = Context.GetService <ISvnStatusCache>();

            SvnItem        slnDirItem = cache[settings.SolutionFilename].Parent;
            SvnWorkingCopy wc         = slnDirItem.WorkingCopy;

            if (wc != null && slnDirItem.Uri != null)
            {
                SvnItem dirItem = slnDirItem;
                Uri     cur     = dirItem.Uri;
                Uri     setUri  = settings.ProjectRootUri;

                while (dirItem != null && dirItem.IsBelowPath(wc.FullPath))
                {
                    UriMap value = new UriMap(cur, dirItem.FullPath);
                    slnBindPath.Items.Add(value);

                    if (setUri == value.Uri)
                    {
                        slnBindPath.SelectedItem = value;
                    }
                    dirItem = dirItem.Parent;
                    cur     = new Uri(cur, "../");
                }
            }
        }
        /// <summary>
        /// Gets the "project root"
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private static SvnItem GetRoot(BaseCommandEventArgs e)
        {
            SvnItem item = null;

            switch (e.Command)
            {
            case AnkhCommand.SolutionIssueTrackerSetup:
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();
                if (ss == null)
                {
                    return(null);
                }

                string root = ss.ProjectRoot;

                if (string.IsNullOrEmpty(root))
                {
                    return(null);
                }

                item = e.GetService <ISvnStatusCache>()[root];
                break;
            }

            return(item);
        }
        void AddRoots(bool add)
        {
            if (add == _rootsPresent)
            {
                return;
            }

            if (!_rootsPresent)
            {
                IAnkhSolutionSettings slnSettings = Context.GetService <IAnkhSolutionSettings>();
                if (!string.IsNullOrEmpty(slnSettings.SolutionFilename))
                {
                    SvnItem slnItem = FileStatusCache[slnSettings.SolutionFilename];
                    folderTree.AddRoot(new WCSolutionNode(Context, slnItem));
                }
                folderTree.AddRoot(new WCMyComputerNode(Context));

                _rootsPresent = true;
            }
            else
            {
                folderTree.ClearRoots();
                _rootsPresent = false;
            }
        }
        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

            if (DesignMode)
            {
                return;
            }
            if (!_initialized && IsHandleCreated && Visible)
            {
                _initialized = true;
                if (SelectedUri != null)
                {
                    BrowseText();
                }

                if (Context != null)
                {
                    IAnkhSolutionSettings settings = Context.GetService <IAnkhSolutionSettings>();
                    if (settings != null)
                    {
                        foreach (Uri uri in settings.GetRepositoryUris(true))
                        {
                            if (!urlBox.Items.Contains(uri))
                            {
                                urlBox.Items.Add(uri);
                            }
                        }
                    }
                }
            }
        }
        public void Prepare()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_prepared)
            {
                return;
            }

            if (Context == null)
            {
                return;
            }

            _prepared = true;

            IAnkhSolutionSettings settings = Context.GetService <IAnkhSolutionSettings>();

            if (settings.SolutionFilename != null)
            {
                Text += " - " + Path.GetFileName(settings.SolutionFilename);
            }

            InitializeGrid();
        }
Beispiel #6
0
        public void OnExecute(CommandEventArgs e)
        {
            IAnkhSolutionSettings slnSettings = e.GetService <IAnkhSolutionSettings>();
            List <ISvnLogItem>    logItems    = new List <ISvnLogItem>(e.Selection.GetSelection <ISvnLogItem>());

            if (logItems.Count != 1)
            {
                return;
            }

            using (EditLogMessageDialog dialog = new EditLogMessageDialog())
            {
                dialog.Context    = e.Context;
                dialog.LogMessage = logItems[0].LogMessage;

                if (dialog.ShowDialog(e.Context) == DialogResult.OK)
                {
                    if (dialog.LogMessage == logItems[0].LogMessage)
                    {
                        return; // No changes
                    }
                    IAnkhConfigurationService config = e.GetService <IAnkhConfigurationService>();

                    if (config != null)
                    {
                        if (dialog.LogMessage != null && dialog.LogMessage.Trim().Length > 0)
                        {
                            config.GetRecentLogMessages().Add(dialog.LogMessage);
                        }
                    }

                    using (SvnClient client = e.GetService <ISvnClientPool>().GetClient())
                    {
                        SvnSetRevisionPropertyArgs sa = new SvnSetRevisionPropertyArgs();
                        sa.AddExpectedError(SvnErrorCode.SVN_ERR_REPOS_DISABLED_FEATURE);
                        client.SetRevisionProperty(logItems[0].RepositoryRoot, logItems[0].Revision, SvnPropertyNames.SvnLog, dialog.LogMessage, sa);

                        if (sa.LastException != null &&
                            sa.LastException.SvnErrorCode == SvnErrorCode.SVN_ERR_REPOS_DISABLED_FEATURE)
                        {
                            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                            mb.Show(sa.LastException.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            return;
                        }
                    }

                    ILogControl logWindow = e.Selection.GetActiveControl <ILogControl>();

                    if (logWindow != null)
                    {
                        // TODO: Somehow repair scroll position/number of items loaded
                        logWindow.Restart();
                    }
                }
            }
        }
Beispiel #7
0
        private void OnSvnItemChanged(SvnItem svnItem)
        {
            IAnkhSolutionSettings slnSettings = SolutionSettings;

            if (slnSettings != null && slnSettings.ProjectRoot == svnItem.FullPath)
            {
                MarkDirty();
            }
        }
Beispiel #8
0
        public override void OnExecute(CommandEventArgs e)
        {
            IPendingChangesManager pcm = e.GetService <IPendingChangesManager>();

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

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

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

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

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

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

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

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

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

                List <PendingChange> patchChanges = new List <PendingChange>(pcs.GetSelection());
                e.GetService <IPendingChangeHandler>().CreatePatch(patchChanges, pca);
            }
        }
Beispiel #9
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            if (!e.State.SolutionExists || e.State.SolutionBuilding || e.State.Debugging || e.State.SolutionOpening)
            {
                e.Enabled = false;
                return;
            }
            switch (e.Command)
            {
            case AnkhCommand.SolutionSwitchDialog:
                IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>();
                SvnItem solutionItem = solutionSettings.ProjectRootSvnItem;
                if (solutionItem == null || !solutionItem.IsVersioned || solutionItem.IsNewAddition)
                {
                    e.Enabled = false;
                    return;
                }
                break;

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

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

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

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

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

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

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

                if (oneItem == null || !oneItem.IsVersioned || oneItem.IsNewAddition)
                {
                    e.Enabled = false;
                }
                break;
            }
        }
Beispiel #10
0
        private static void AutoOpenCommand(CommandEventArgs e, SvnOrigin origin)
        {
            IAnkhCommandService   svc = e.GetService <IAnkhCommandService>();
            IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>();

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

            // Ok, we can assume we have a file
            string filename = origin.Target.FileName;
            string ext      = Path.GetExtension(filename);

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

            foreach (string projectExt in solutionSettings.AllProjectExtensionsFilter.Split(';'))
            {
                if (projectExt.TrimStart('*').Trim().Equals(ext, StringComparison.OrdinalIgnoreCase))
                {
                    // We found a project or solution, use Open from Subversion to create a checkout

                    svc.PostExecCommand(AnkhCommand.FileFileOpenFromSubversion, origin);
                    return;
                }
            }

            bool odd = false;

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

                foreach (string itemExt in block.Split(';'))
                {
                    if (itemExt.TrimStart('*').Trim().Equals(ext, StringComparison.OrdinalIgnoreCase))
                    {
                        svc.PostExecCommand(AnkhCommand.ViewInVsNet);
                        return;
                    }
                }
            }

            // Ultimate fallback: Just ask the user what to do (don't trust the repository!)
            svc.PostExecCommand(AnkhCommand.ViewInWindowsWith);
        }
Beispiel #11
0
        string GetSccBaseDirectory()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string projectDir = ProjectDirectory;

            if (projectDir == null)
            {
                return(null);
            }

            // TODO: Insert project local settings check

            IAnkhSolutionSettings settings = GetService <IAnkhSolutionSettings>();
            ISvnStatusCache       cache    = GetService <ISvnStatusCache>();

            SvnItem solutionRoot = settings.ProjectRootSvnItem;

            if (solutionRoot == null)
            {
                return(null); // Fix the solution before we try any SCC, thanks!
            }
            SvnItem projectDirItem = cache[projectDir];

            if (projectDirItem != null && projectDirItem.WorkingCopy != null)
            {
                // Project is below standard workingcopy
                if (projectDirItem.IsBelowPath(solutionRoot))
                {
                    if (solutionRoot.WorkingCopy == projectDirItem.WorkingCopy)
                    {
                        // Project is in the same working copy.. use the solution root
                        // to automatically handle in-between directory levels
                        return(solutionRoot.FullPath);
                    }

                    // Project has its own workingcopy below the solution root
                    // -> Use the complete workingcopy (might be shared with multiple projects)
                    return(projectDirItem.WorkingCopy.FullPath);
                }

                if (solutionRoot.WorkingCopy != projectDirItem.WorkingCopy)
                {
                    // Project is below a root of its own.. use its workingcopy
                    return(projectDirItem.WorkingCopy.FullPath);
                }

                // The user deliberately choose not to have the item in the solution root
                // -> Default to the project directory
            }

            return(ProjectDirectory);
        }
Beispiel #12
0
        string GetRelativePath(SvnItem item)
        {
            IAnkhSolutionSettings ss = Context.GetService <IAnkhSolutionSettings>();

            string path = ss.ProjectRoot;

            if (!string.IsNullOrEmpty(path) && item.IsBelowPath(path))
            {
                return(SvnItem.SubPath(item.FullPath, path));
            }

            return(item.FullPath);
        }
Beispiel #13
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();

            if (ss != null && !string.IsNullOrEmpty(ss.ProjectRoot) && ss.ProjectRootSvnItem.IsVersioned)
            {
                IAnkhConfigurationService cs = e.GetService <IAnkhConfigurationService>();

                if (!string.IsNullOrEmpty(cs.Instance.PatchExePath))
                {
                    return;
                }
            }

            e.Enabled = false;
        }
Beispiel #14
0
        private void okButton_Click(object sender, EventArgs e)
        {
            IAnkhSolutionSettings settings = Context.GetService <IAnkhSolutionSettings>();
            UriMap map = slnBindPath.SelectedItem as UriMap;

            if (map == null)
            {
                return;
            }

            if (settings.ProjectRootUri != null && map.Uri != settings.ProjectRootUri)
            {
                string dir = SvnTools.GetNormalizedDirectoryName(settings.SolutionFilename);
                settings.ProjectRoot = SvnTools.GetNormalizedFullPath(Path.Combine(dir, map.Value));
            }
        }
Beispiel #15
0
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            if (Context != null)
            {
                IAnkhSolutionSettings ss = Context.GetService <IAnkhSolutionSettings>();
                foreach (Uri u in ss.GetRepositoryUris(true))
                {
                    repositoryUrl.Items.Add(u);
                }
                _initialized = true;
            }
        }
Beispiel #16
0
        public override void OnExecute(CommandEventArgs e)
        {
            IAnkhPackage package = e.Context.GetService <IAnkhPackage>();

            AnkhToolWindow toolWindow;

            switch (e.Command)
            {
            case AnkhCommand.ShowPendingChanges:
                toolWindow = AnkhToolWindow.PendingChanges;
                break;

            case AnkhCommand.ShowWorkingCopyExplorer:
                toolWindow = AnkhToolWindow.WorkingCopyExplorer;
                break;

            case AnkhCommand.ShowRepositoryExplorer:
                toolWindow = AnkhToolWindow.RepositoryExplorer;
                break;

            case AnkhCommand.ShowSubversionInfo:
                toolWindow = AnkhToolWindow.SvnInfo;
                break;

            default:
                return;
            }

            package.ShowToolWindow(toolWindow);

            if (e.Command == AnkhCommand.ShowRepositoryExplorer)
            {
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();

                if (ss.ProjectRootUri != null)
                {
                    RepositoryExplorerControl ctrl = e.Selection.ActiveDialogOrFrameControl as RepositoryExplorerControl;

                    if (ctrl != null)
                    {
                        ctrl.AddRoot(ss.ProjectRootUri);
                    }
                }
            }
        }
Beispiel #17
0
        private static SvnItem GetRoot(BaseCommandEventArgs e)
        {
            SvnItem item = null;

            switch (e.Command)
            {
            case AnkhCommand.SolutionBranch:
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();
                if (ss == null)
                {
                    return(null);
                }

                string root = ss.ProjectRoot;

                if (string.IsNullOrEmpty(root))
                {
                    return(null);
                }

                item = e.GetService <ISvnStatusCache>()[root];
                break;

            case AnkhCommand.ProjectBranch:
                SccProject p = EnumTools.GetSingle(e.Selection.GetSelectedProjects(false));
                if (p == null)
                {
                    break;
                }

                ISccProjectInfo info = e.GetService <IProjectFileMapper>().GetProjectInfo(p);

                if (info == null || info.ProjectDirectory == null)
                {
                    break;
                }

                item = e.GetService <ISvnStatusCache>()[info.ProjectDirectory];
                break;
            }

            return(item);
        }
Beispiel #18
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            base.OnUpdate(e);


            if (e.Enabled && e.Command == AnkhCommand.ViewInVsNet)
            {
                ISvnRepositoryItem    single   = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());
                IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>();

                SvnOrigin origin = single.Origin; // Checked in parent

                string ext = Path.GetExtension(origin.Target.FileName);

                if (!string.IsNullOrEmpty(ext) && settings.OpenFileFilter.IndexOf("*" + ext, StringComparison.OrdinalIgnoreCase) < 0)
                {
                    e.Enabled = false;
                }
            }
        }
Beispiel #19
0
        protected override void ValidateAdd(object sender, CancelEventArgs e)
        {
            base.ValidateAdd(sender, e);

            if (e.Cancel)
            {
                return;
            }

            Debug.Assert(RepositoryAddUrl != null);

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

            // Error if the RepositoryAddUrl is below the url of the projectroot
            if (ss.ProjectRootUri.IsBaseOf(RepositoryAddUrl))
            {
                e.Cancel = true;

                errorProvider1.SetError(repositoryTree, "Please select a location that is not below the solution binding path, or move the project to a directory below the solution binding path on disk");
                return;
            }
        }
Beispiel #20
0
        public void DoCreatePatch(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            PendingChangeCreatePatchArgs a = new PendingChangeCreatePatchArgs();

            a.FileName = fileName;

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

            a.RelativeToPath      = ss.ProjectRoot;
            a.AddUnversionedFiles = true;

            List <PendingChange> changes = new List <PendingChange>(UI.CheckedItems);

            if (Context.GetService <IPendingChangeHandler>().CreatePatch(changes, a))
            {
            }
        }
Beispiel #21
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.RepositoryRoot = selected.Origin.RepositoryRoot;
                dlg.LocalPath      = System.IO.Path.Combine(ss.NewProjectLocation, name);

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

                e.GetService <IProgressRunner>().RunModal(CommandStrings.CheckingOut,
                                                          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               firstVersioned   = null;
            ISvnStatusCache       cache            = e.GetService <ISvnStatusCache>();
            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 #23
0
        public override void OnExecute(CommandEventArgs e)
        {
            IAnkhSolutionSettings ss   = e.GetService <IAnkhSolutionSettings>();
            IAnkhDiffHandler      diff = e.GetService <IAnkhDiffHandler>();

            AnkhPatchArgs args = new AnkhPatchArgs();

            args.ApplyTo = ss.ProjectRoot;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "Patch files( *.patch)|*.patch|Diff files (*.diff)|*.diff|" +
                             "Text files (*.txt)|*.txt|All files (*.*)|*";

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

                args.PatchFile = ofd.FileName;
            }

            diff.RunPatch(args);
        }
Beispiel #24
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <string>  toAdd = new List <string>();
            List <SvnItem> items = new List <SvnItem>();

            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
            {
                if (item.IsVersioned)
                {
                    items.Add(item);
                }
                else if (item.IsFile && item.IsVersionable && item.InSolution && !item.IsIgnored && !item.IsSccExcluded)
                {
                    toAdd.Add(item.FullPath); // Add new files  ### Alternative: Show them as added
                    items.Add(item);
                }
            }

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

            SvnRevision start = SvnRevision.Base;
            SvnRevision end   = SvnRevision.Working;

            // should we show the path selector?
            if (e.ShouldPrompt(true))
            {
                using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog())
                {
                    dlg.Text          = CommandStrings.UnifiedDiffTitle;
                    dlg.Items         = items;
                    dlg.RevisionStart = start;
                    dlg.RevisionEnd   = end;

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

                    items.Clear();
                    items.AddRange(dlg.GetCheckedItems());
                    start = dlg.RevisionStart;
                    end   = dlg.RevisionEnd;
                }
            }

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

            SvnRevisionRange revRange = new SvnRevisionRange(start, end);

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

            IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();
            string slndir            = ss.ProjectRoot;

            using (MemoryStream stream = new MemoryStream())
            {
                e.Context.GetService <IProgressRunner>().RunModal(CommandStrings.RunningDiff,
                                                                  delegate(object sender, ProgressWorkerArgs ee)
                {
                    SvnAddArgs aa   = new SvnAddArgs();
                    aa.ThrowOnError = false;
                    aa.AddParents   = false;
                    foreach (string item in toAdd)
                    {
                        ee.Client.Add(item, aa);
                    }

                    SvnDiffArgs diffArgs    = new SvnDiffArgs();
                    diffArgs.IgnoreAncestry = true;
                    diffArgs.NoDeleted      = false;
                    diffArgs.ThrowOnError   = false;

                    foreach (SvnItem item in items)
                    {
                        SvnWorkingCopy wc;
                        if (!string.IsNullOrEmpty(slndir) && item.IsBelowPath(slndir))
                        {
                            diffArgs.RelativeToPath = slndir;
                        }
                        else if ((wc = item.WorkingCopy) != null)
                        {
                            diffArgs.RelativeToPath = wc.FullPath;
                        }
                        else
                        {
                            diffArgs.RelativeToPath = null;
                        }

                        if (!ee.Client.Diff(item.FullPath, revRange, diffArgs, stream))
                        {
                            if (diffArgs.LastException != null)
                            {
                                StreamWriter sw = new StreamWriter(stream);
                                sw.WriteLine();
                                sw.WriteLine(string.Format("# {0}: {1}", item.FullPath, diffArgs.LastException.Message));
                                sw.Flush();
                                // Don't dispose the writer as that might close the stream
                            }

                            if (diffArgs.IsLastInvocationCanceled)
                            {
                                break;
                            }
                        }
                    }

                    stream.Flush();
                });

                stream.Position = 0;
                using (StreamReader sr = new StreamReader(stream))
                {
                    File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8);
                    VsShellUtilities.OpenDocument(e.Context, tempFile);
                }
            }
        }
        public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            _solutionLoaded = true;
            SccEvents.OnSolutionOpened(true);

            GetService <IAnkhServiceEvents>().OnSolutionOpened(EventArgs.Empty);

            if (!SccProvider.IsActive)
            {
                return(VSErr.S_OK);
            }
            try
            {
                VerifySolutionNaming();

                IAnkhSolutionSettings ss = GetService <IAnkhSolutionSettings>();

                if (ss != null && ss.ProjectRoot != null)
                {
                    string rootDir = Path.GetPathRoot(ss.ProjectRoot);
                    if (rootDir.Length == 3 && rootDir.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
                    {
                        DriveInfo di    = new DriveInfo(rootDir);
                        bool      oldFs = false;

                        switch ((di.DriveFormat ?? "").ToUpperInvariant())
                        {
                        case "FAT32":
                        case "FAT":
                            oldFs = true;
                            break;
                        }

                        if (oldFs)
                        {
                            IAnkhConfigurationService cs = GetService <IAnkhConfigurationService>();

                            if (!cs.GetWarningBool(AnkhWarningBool.FatFsFound))
                            {
                                using (SccFilesystemWarningDialog dlg = new SccFilesystemWarningDialog())
                                {
                                    dlg.Text = Path.GetFileName(ss.SolutionFilename);
                                    if (DialogResult.OK == dlg.ShowDialog(Context))
                                    {
                                        cs.SetWarningBool(AnkhWarningBool.FatFsFound, true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler handler = GetService <IAnkhErrorHandler>();

                if (handler.IsEnabled(ex))
                {
                    handler.OnError(ex);
                }
                else
                {
                    throw;
                }
            }

            return(VSErr.S_OK);
        }
Beispiel #26
0
        /// <see cref="Ankh.Commands.ICommandHandler.OnUpdate" />
        public void OnUpdate(CommandUpdateEventArgs e)
        {
            ISvnStatusCache statusCache;
            int             n = 0;

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

                    n++;

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

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

                    n++;

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

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

            default:
                throw new InvalidOperationException();
            }

            if (n != 1)
            {
                e.Enabled = false;
            }
        }
        public override void OnExecute(CommandEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Uri selectedUri = null;
            Uri rootUri     = null;

            bool addingProject = (e.Command == AnkhCommand.FileFileAddFromSubversion ||
                                  e.Command == AnkhCommand.FileSccAddFromSubversion);

            if (e.Argument is string && Uri.TryCreate((string)e.Argument, UriKind.Absolute, out selectedUri))
            {
            }
            else if (e.Argument is SvnOrigin)
            {
                SvnOrigin origin = (SvnOrigin)e.Argument;
                selectedUri = origin.Uri;
                rootUri     = origin.RepositoryRoot;
            }
            else if (e.Argument is Uri)
            {
                selectedUri = (Uri)e.Argument;
            }

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

            if (e.PromptUser || selectedUri == null)
            {
                using (RepositoryOpenDialog dlg = new RepositoryOpenDialog())
                {
                    if (addingProject)
                    {
                        dlg.Text = CommandStrings.AddProjectFromSubversion;
                    }

                    dlg.Filter = settings.OpenProjectFilterName + "|" + settings.AllProjectExtensionsFilter + "|All Files (*.*)|*";

                    if (selectedUri != null)
                    {
                        dlg.SelectedUri = selectedUri;
                    }

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

                    selectedUri = dlg.SelectedUri;
                    rootUri     = dlg.SelectedRepositoryRoot;
                }
            }
            else if (rootUri == null)
            {
                if (!e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingRepositoryRoot,
                                                               delegate(object sender, ProgressWorkerArgs a)
                {
                    rootUri = a.Client.GetRepositoryRoot(selectedUri);
                }).Succeeded)
                {
                    return;
                }
            }

            string defaultPath = settings.NewProjectLocation;

            if (addingProject)
            {
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();

                if (!string.IsNullOrEmpty(ss.ProjectRoot))
                {
                    defaultPath = ss.ProjectRoot;
                }
            }

            string name = Path.GetFileNameWithoutExtension(SvnTools.GetFileName(selectedUri));

            string newPath;
            int    n = 0;

            do
            {
                newPath = Path.Combine(defaultPath, name);
                if (n > 0)
                {
                    newPath += string.Format("({0})", n);
                }
                n++;
            }while (File.Exists(newPath) || Directory.Exists(newPath));

            using (CheckoutProject dlg = new CheckoutProject())
            {
                dlg.Context = e.Context;

                if (addingProject)
                {
                    dlg.Text = CommandStrings.AddProjectFromSubversion;
                }
                dlg.ProjectUri        = selectedUri;
                dlg.RepositoryRootUri = rootUri;
                dlg.SelectedPath      = newPath;
                dlg.SvnOrigin         = new SvnOrigin(selectedUri, rootUri);
                dlg.HandleCreated    += delegate
                {
                    FindRoot(e.Context, selectedUri, dlg);
                };

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

                if (!addingProject)
                {
                    OpenSolution(e, dlg);
                }
                else
                {
                    CheckOutAndOpenProject(e, dlg.ProjectTop, dlg.Revision, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri);
                }
            }
        }
        private static void AddProject(CommandEventArgs e, string projectFile)
        {
            IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();

            ss.AddProjectFile(projectFile);
        }
        private static void CheckOutAndOpenProject(CommandEventArgs e, SvnUriTarget checkoutLocation, SvnRevision revision, Uri projectTop, string localDir, Uri projectUri)
        {
            IProgressRunner runner = e.GetService <IProgressRunner>();

            runner.RunModal(CommandStrings.CheckingOutSolution,
                            delegate(object sender, ProgressWorkerArgs ee)
            {
                PerformCheckout(ee, checkoutLocation, revision, localDir);
            });

            Uri file = projectTop.MakeRelativeUri(projectUri);

            string projectFile = SvnTools.GetNormalizedFullPath(Path.Combine(localDir, SvnTools.UriPartToPath(file.ToString())));

            AddProject(e, projectFile);

            using (ProjectAddInfoDialog pai = new ProjectAddInfoDialog())
            {
                IAnkhSolutionSettings ss    = e.GetService <IAnkhSolutionSettings>();
                ISvnStatusCache       cache = e.GetService <ISvnStatusCache>();
                SvnItem rootItem;

                pai.EnableSlnConnection = false;

                if (ss == null || cache == null ||
                    string.IsNullOrEmpty(ss.ProjectRoot) ||
                    !SvnItem.IsBelowRoot(localDir, ss.ProjectRoot) ||
                    null == (rootItem = cache[localDir]))
                {
                    pai.EnableExternal = false;
                    pai.EnableCopy     = false;
                }
                else
                {
                    SvnItem dir = rootItem.Parent;

                    if (ss.ProjectRootSvnItem != null &&
                        ss.ProjectRootSvnItem.IsVersioned)
                    {
                        HybridCollection <string> dirs = new HybridCollection <string>();
                        SvnItem exDir = dir;

                        while (exDir != null && exDir.IsBelowPath(ss.ProjectRoot))
                        {
                            if (exDir.IsVersioned && exDir.WorkingCopy == ss.ProjectRootSvnItem.WorkingCopy)
                            {
                                dirs.Add(exDir.FullPath);
                            }

                            exDir = exDir.Parent;
                        }
                        pai.SetExternalDirs(dirs);
                        pai.EnableExternal = true;
                    }
                    else
                    {
                        pai.EnableExternal = false;
                    }

                    if (rootItem.WorkingCopy != null && dir.WorkingCopy != null)
                    {
                        pai.EnableCopy = (rootItem.WorkingCopy.RepositoryRoot == dir.WorkingCopy.RepositoryRoot) &&
                                         (rootItem.WorkingCopy.RepositoryId == dir.WorkingCopy.RepositoryId);
                    }
                    else
                    {
                        pai.EnableCopy = false;
                    }
                }

                if (pai.ShowDialog(e.Context) == DialogResult.OK)
                {
                    switch (pai.SelectedMode)
                    {
                    case ProjectAddMode.External:
                        if (pai.ExternalLocation != null)
                        {
                            using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient())
                            {
                                string externals;
                                if (!cl.TryGetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, out externals))
                                {
                                    externals = "";
                                }

                                SvnExternalItem sei;
                                if (pai.ExternalLocked)
                                {
                                    sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri, revision, revision);
                                }
                                else
                                {
                                    sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri);
                                }

                                externals = sei.ToString(true) + Environment.NewLine + externals;
                                cl.SetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, externals);
                            }
                        }
                        break;

                    case ProjectAddMode.Copy:
                        using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient())
                        {
                            string tmpDir = localDir + "-Src-copyTmp";
                            Directory.CreateDirectory(tmpDir);
                            Directory.Move(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), Path.Combine(tmpDir, SvnClient.AdministrativeDirectoryName));
                            SvnCopyArgs ma = new SvnCopyArgs();
                            ma.MetaDataOnly = true;
                            cl.Copy(tmpDir, localDir, ma);
                            SvnItem.DeleteDirectory(tmpDir, true);
                            cache.MarkDirtyRecursive(localDir);
                        }
                        break;

                    case ProjectAddMode.Unversioned:
                        cache.MarkDirtyRecursive(localDir);
                        SvnItem.DeleteDirectory(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), true);
                        e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(projectFile);    // And everything else in the project
                        break;
                    }
                }
            }
        }
Beispiel #30
0
        private void ShowErrorDialog(Exception ex, bool showStackTrace, bool internalError, ExceptionInfo info)
        {
            string stackTrace = ex.ToString();
            string message    = GetNestedMessages(ex);

            System.Collections.Specialized.StringDictionary additionalInfo =
                new System.Collections.Specialized.StringDictionary();

            IAnkhSolutionSettings ss = GetService <IAnkhSolutionSettings>();

            if (ss != null)
            {
                additionalInfo.Add("VS-Version", VSVersion.FullVersion.ToString());
            }

            if (info != null && info.CommandArgs != null)
            {
                additionalInfo.Add("Command", info.CommandArgs.Command.ToString());
            }

            IAnkhPackage pkg = GetService <IAnkhPackage>();

            if (pkg != null)
            {
                additionalInfo.Add("Ankh-Version", pkg.UIVersion.ToString());
            }

            additionalInfo.Add("SharpSvn-Version", SharpSvn.SvnClient.SharpSvnVersion.ToString());
            additionalInfo.Add("Svn-Version", SharpSvn.SvnClient.Version.ToString());
            additionalInfo.Add("OS-Version", Environment.OSVersion.Version.ToString());

            using (ErrorDialog dlg = new ErrorDialog())
            {
                dlg.ErrorMessage   = message;
                dlg.ShowStackTrace = showStackTrace;
                dlg.StackTrace     = stackTrace;
                dlg.InternalError  = internalError;

                if (dlg.ShowDialog(Context) == DialogResult.Retry)
                {
                    string subject = _errorReportSubject;

                    if (info != null && info.CommandArgs != null)
                    {
                        subject = string.Format("Error handling {0}", info.CommandArgs.Command);
                    }

                    SvnException sx = ex as SvnException;
                    SvnException ix;

                    while (sx != null &&
                           sx.SvnErrorCode == SvnErrorCode.SVN_ERR_BASE &&
                           (null != (ix = sx.InnerException as SvnException)))
                    {
                        sx = ix;
                    }

                    if (sx != null)
                    {
                        SvnException rc = sx.RootCause as SvnException;
                        if (rc == null || rc.SvnErrorCode == sx.SvnErrorCode)
                        {
                            subject += " (" + ErrorToString(sx) + ")";
                        }
                        else
                        {
                            subject += " (" + ErrorToString(sx) + "-" + ErrorToString(rc) + ")";
                        }
                    }

                    AnkhErrorMessage.SendByMail(_errorReportMailAddress,
                                                subject, ex, typeof(AnkhErrorHandler).Assembly, additionalInfo);
                }
            }
        }