示例#1
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            ISvnRepositoryItem reposItem = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (reposItem != null)
            {
                if (reposItem.Origin != null && reposItem.NodeKind != SharpSvn.SvnNodeKind.Directory &&
                    reposItem.Revision.RevisionType == SharpSvn.SvnRevisionType.Number)
                {
                    if (e.Command == AnkhCommand.RepositoryCompareWithWc)
                    {
                        if (!(reposItem.Origin.Target is SvnPathTarget))
                        {
                            e.Enabled = false;
                            return;
                        }
                    }

                    return;
                }
                else if (e.Command == AnkhCommand.RepositoryCompareWithWc &&
                         reposItem.Revision == SvnRevision.Working)
                {
                    return;
                }
            }

            e.Enabled = false;
        }
示例#2
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (item == null)
            {
                return;
            }

            string newName = item.Origin.Target.FileName;

            if (e.Argument != null)
            {
                string[] items = e.Argument as string[];

                if (items != null)
                {
                    if (items.Length == 1)
                    {
                        newName = items[0];
                    }
                    else if (items.Length > 1)
                    {
                        newName = items[1];
                    }
                }
            }

            string logMessage;

            using (RenameDialog dlg = new RenameDialog())
            {
                dlg.Context = e.Context;
                dlg.OldName = item.Origin.Target.FileName;
                dlg.NewName = newName;

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

            try
            {
                Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri);
                e.GetService <IProgressRunner>().RunModal(CommandStrings.RenamingNodes,
                                                          delegate(object sender, ProgressWorkerArgs we)
                {
                    SvnMoveArgs ma = new SvnMoveArgs();
                    ma.LogMessage  = logMessage;
                    we.Client.RemoteMove(itemUri, new Uri(itemUri, newName), ma);
                });
            }
            finally
            {
                item.RefreshItem(true);
            }
        }
示例#3
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            ISvnRepositoryItem single = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (single == null || single.NodeKind == SvnNodeKind.File || single.Origin == null)
            {
                e.Enabled = false;
            }
        }
示例#4
0
        public override void OnExecute(CommandEventArgs e)
        {
            IAnkhDiffHandler   diff      = e.GetService <IAnkhDiffHandler>();
            ISvnRepositoryItem reposItem = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (reposItem == null)
            {
                return;
            }

            SvnRevision from;
            SvnRevision to;

            if (reposItem.Revision == SvnRevision.Working)
            {
                from = SvnRevision.Base;
                to   = SvnRevision.Working;
            }
            else if (e.Command == AnkhCommand.RepositoryCompareWithWc)
            {
                from = reposItem.Revision;
                to   = SvnRevision.Working;
            }
            else
            {
                from = reposItem.Revision.Revision - 1;
                to   = reposItem.Revision;
            }
            AnkhDiffArgs da = new AnkhDiffArgs();

            if (to == SvnRevision.Working)
            {
                da.BaseFile = diff.GetTempFile(reposItem.Origin.Target, from, true);

                if (da.BaseFile == null)
                {
                    return; // User canceled
                }
                da.MineFile = ((SvnPathTarget)reposItem.Origin.Target).FullPath;
            }
            else
            {
                string[] files = diff.GetTempFiles(reposItem.Origin.Target, from, to, true);

                if (files == null)
                {
                    return; // User canceled
                }
                da.BaseFile = files[0];
                da.MineFile = files[1];
                System.IO.File.SetAttributes(da.MineFile, System.IO.FileAttributes.ReadOnly | System.IO.FileAttributes.Normal);
            }

            da.BaseTitle = diff.GetTitle(reposItem.Origin.Target, from);
            da.MineTitle = diff.GetTitle(reposItem.Origin.Target, to);
            diff.RunDiff(da);
        }
示例#5
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (item != null && item.Origin != null && !item.Origin.IsRepositoryRoot)
            {
                return;
            }

            e.Enabled = false;
        }
示例#6
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (item == null ||
                item.Origin == null ||
                item.Origin.Target.Revision != SvnRevision.Head ||
                item.NodeKind == SvnNodeKind.File)
            {
                e.Enabled = false;
            }
        }
示例#7
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            base.OnUpdate(e);

            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (item != null && item.Origin != null)
            {
                if (item.Origin.Target.Revision == SvnRevision.Head &&
                    !item.Origin.IsRepositoryRoot)
                {
                    return;
                }
            }

            e.Enabled = false;
        }
示例#8
0
        public override void OnUpdate(CommandUpdateEventArgs e)
        {
            switch (e.Command)
            {
            case AnkhCommand.SvnNodeAnnotate:
                ISvnRepositoryItem ri = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());
                if (ri != null && ri.Origin != null && ri.NodeKind != SvnNodeKind.Directory)
                {
                    return;
                }
                break;

            case AnkhCommand.ItemAnnotate:
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                {
                    if (item.IsFile && item.IsVersioned && item.HasCopyableHistory)
                    {
                        return;
                    }
                }
                break;

            case AnkhCommand.DocumentAnnotate:
                if (e.Selection.ActiveDocumentSvnItem != null && e.Selection.ActiveDocumentSvnItem.HasCopyableHistory)
                {
                    return;
                }
                break;

            case AnkhCommand.LogAnnotateRevision:
                ILogControl logControl = e.Selection.GetActiveControl <ILogControl>();
                if (logControl == null || logControl.Origins == null)
                {
                    e.Visible = e.Enabled = false;
                    return;
                }

                if (!EnumTools.IsEmpty(e.Selection.GetSelection <ISvnLogChangedPathItem>()))
                {
                    return;
                }
                break;
            }
            e.Enabled = false;
        }
        protected static bool SaveFile(CommandEventArgs e, ISvnRepositoryItem ri, string toFile)
        {
            ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal(
                "Saving File",
                delegate(object sender, ProgressWorkerArgs ee)
                {
                    using (FileStream fs = File.Create(toFile))
                    {
                        SvnWriteArgs args = new SvnWriteArgs();
                        if(ri.Revision != null)
                            args.Revision = ri.Revision;

                        ee.Client.Write(ri.Origin.Target, fs, args);
                    }
                });

            return r.Succeeded;
        }
        protected static bool SaveFile(CommandEventArgs e, ISvnRepositoryItem ri, string toFile)
        {
            ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingFileForComparison,
                                                                               delegate(object sender, ProgressWorkerArgs ee)
            {
                using (FileStream fs = File.Create(toFile))
                {
                    SvnWriteArgs args = new SvnWriteArgs();
                    if (ri.Revision != null)
                    {
                        args.Revision = ri.Revision;
                    }

                    ee.Client.Write(ri.Origin.Target, fs, args);
                }
            });

            return(r.Succeeded);
        }
示例#11
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;
                }
            }
        }
示例#12
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem selected = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            string directoryName = "";

            using (CreateDirectoryDialog dlg = new CreateDirectoryDialog())
            {
                DialogResult result = dlg.ShowDialog(e.Context);

                directoryName = dlg.NewDirectoryName;

                if (result != DialogResult.OK || string.IsNullOrEmpty(directoryName))
                {
                    return;
                }

                string log = dlg.LogMessage;

                // Handle special characters like on local path
                Uri uri = SvnTools.AppendPathSuffix(selected.Uri, directoryName);

                ProgressRunnerResult prResult =
                    e.GetService <IProgressRunner>().RunModal(
                        CommandStrings.CreatingDirectories,
                        delegate(object sender, ProgressWorkerArgs ee)
                {
                    SvnCreateDirectoryArgs args = new SvnCreateDirectoryArgs();
                    args.ThrowOnError           = false;
                    args.CreateParents          = true;
                    args.LogMessage             = log;
                    ee.Client.RemoteCreateDirectory(uri, args);
                }
                        );

                if (prResult.Succeeded)
                {
                    selected.RefreshItem(false);
                }
            }
        }
示例#13
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem ri = null;

            foreach (ISvnRepositoryItem i in e.Selection.GetSelection <ISvnRepositoryItem>())
            {
                ri = i;
                break;
            }
            if (ri == null)
            {
                return;
            }

            string toFile;

            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                string name = ri.Origin.Target.FileName;

                sfd.Filter = "All Files (*.*)|*";
                string ext = Path.GetExtension(name).Trim('.');

                if (!string.IsNullOrEmpty(ext))
                {
                    sfd.Filter = string.Format("{0} Files|*.{0}|{1}", ext, sfd.Filter);
                }

                sfd.FileName = name;

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

                toFile = sfd.FileName;
            }

            SaveFile(e, ri, toFile);
        }
示例#14
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);
                });
            }
        }
示例#15
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;
            ISvnStatusCache cache         = e.GetService <ISvnStatusCache>();

            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(CommandStrings.Copying,
                                                                      delegate(object sender, ProgressWorkerArgs a)
                            {
                                SvnDeleteArgs da = new SvnDeleteArgs();
                                da.Force         = true;
                                a.Client.Delete(copyTo, da);
                            });
                        }
                        else
                        {
                            SvnItem.DeleteNode(copyTo);
                        }
                    }

                    SvnItem dir = fileItem.Parent;

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

            if (!suggestExport)
            {
                e.GetService <IProgressRunner>().RunModal(CommandStrings.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(CommandStrings.NotInWorkingCopyExportInstead,
                                                CommandStrings.NotInWorkingCopyTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    e.GetService <IProgressRunner>().RunModal(CommandStrings.Exporting,
                                                              delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnExportArgs ea = new SvnExportArgs();
                        ea.Revision      = item.Revision;
                        ea.Overwrite     = true;

                        a.Client.Export(item.Origin.Target, copyTo, ea);
                    });
                }
            }
        }
示例#16
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem ri = null;

            foreach (ISvnRepositoryItem i in e.Selection.GetSelection <ISvnRepositoryItem>())
            {
                if (i.Origin == null)
                {
                    continue;
                }

                ri = i;
                break;
            }
            if (ri == null)
            {
                return;
            }

            string toFile = e.GetService <IAnkhTempFileManager>().GetTempFileNamed(ri.Origin.Target.FileName);
            string ext    = Path.GetExtension(toFile);

            if (!SaveFile(e, ri, toFile))
            {
                return;
            }

            if (e.Command == AnkhCommand.ViewInVsNet)
            {
                VsShellUtilities.OpenDocument(e.Context, toFile);
            }
            else if (e.Command == AnkhCommand.ViewInVsText)
            {
                IVsUIHierarchy hier;
                IVsWindowFrame frame;
                uint           id;
                VsShellUtilities.OpenDocument(e.Context, toFile, VSConstants.LOGVIEWID_TextView, out hier, out id, out frame);
            }
            else
            {
                Process process = new Process();
                process.StartInfo.UseShellExecute = true;

                if (e.Command == AnkhCommand.ViewInWindowsWith &&
                    !string.Equals(ext, ".zip", StringComparison.OrdinalIgnoreCase))
                {
                    // TODO: BH: I tested with adding quotes around {0} but got some error

                    // BH: Don't call this on .zip files in vista, as it will break the builtin
                    // zip file support in the Windows Explorer (as that isn't available in the list)

                    process.StartInfo.FileName  = "rundll32.exe";
                    process.StartInfo.Arguments = string.Format("Shell32,OpenAs_RunDLL {0}", toFile);
                }
                else
                {
                    process.StartInfo.FileName = toFile;
                }

                try
                {
                    process.Start();
                }
                catch (Win32Exception ex)
                {
                    // no application is associated with the file type
                    if (ex.NativeErrorCode == (int)SharpSvn.SvnWindowsErrorCode.ERROR_NO_ASSOCIATION)
                    {
                        e.GetService <IAnkhDialogOwner>()
                        .MessageBox.Show("Windows could not find an application associated with the file type",
                                         "No associated application", MessageBoxButtons.OK);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }