public EditReadOnlyFileDialog(GitItem item)
            : this()
        {
            if(item == null)
                throw new ArgumentNullException("item");

            label1.Text = string.Format(label1.Text, item.Name);
        }
Ejemplo n.º 2
0
        public GitItemData(IVisualGitServiceProvider context, GitItem item)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            else if (item == null)
                throw new ArgumentNullException("item");

            _context = context;
            _item = item;
        }
Ejemplo n.º 3
0
        public FileSystemTreeNode(WCTreeNode wcNode, GitItem item)
        {
            if (wcNode == null)
                throw new ArgumentNullException("wcNode");

            _wcNode = wcNode;
            Text = wcNode.Title;
            _item = item;

            wcNode.TreeNode = this;
        }
Ejemplo n.º 4
0
        public VisualGitGlyph GetStatusImageForGitItem(GitItem item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (item.IsConflicted || item.IsObstructed || item.IsTreeConflicted)
                return VisualGitGlyph.InConflict;
            else if (!item.IsVersioned)
            {
                if (!item.Exists)
                    return VisualGitGlyph.FileMissing;
                else if (item.IsIgnored)
                    return VisualGitGlyph.Ignored;
                else if (item.IsVersionable)
                    return item.InSolution ? VisualGitGlyph.ShouldBeAdded : VisualGitGlyph.Blank;
                else
                    return VisualGitGlyph.None;
            }

            switch (item.Status.State)
            {
                case GitStatus.Normal:
                    if (item.IsDocumentDirty)
                        return VisualGitGlyph.FileDirty;
                    else
                        return VisualGitGlyph.Normal;
                case GitStatus.Modified:
                    return VisualGitGlyph.Modified;
                case GitStatus.Added:
                    return item.Status.IsCopied ? VisualGitGlyph.CopiedOrMoved : VisualGitGlyph.Added;

                case GitStatus.Missing:
                    if (item.IsCasingConflicted)
                        return VisualGitGlyph.InConflict;
                    else
                        goto case GitStatus.Deleted;
                case GitStatus.Deleted:
                    return VisualGitGlyph.Deleted;

                case GitStatus.Conflicted: // Should have been handled above
                case GitStatus.Obstructed:
                    return VisualGitGlyph.InConflict;

                case GitStatus.Ignored: // Should have been handled above
                    return VisualGitGlyph.Ignored;

                case GitStatus.Incomplete:
                    return VisualGitGlyph.InConflict;

                case GitStatus.Zero:
                default:
                    return VisualGitGlyph.None;
            }
        }
Ejemplo n.º 5
0
        public FileSystemListViewItem(SmartListView view, GitItem item)
            : base(view)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            _gitItem = item;

            ImageIndex = View.IconMapper.GetIcon(item.FullPath);

            RefreshValues();
        }
Ejemplo n.º 6
0
        public WCSolutionNode(IVisualGitServiceProvider context, GitItem item)
            : base(context, null, item)
        {
            string file = Context.GetService<IVisualGitSolutionSettings>().SolutionFilename;

            IFileIconMapper iconMapper = context.GetService<IFileIconMapper>();

            if (string.IsNullOrEmpty(file))
                _imageIndex = iconMapper.GetIconForExtension(".sln");
            else
                _imageIndex = iconMapper.GetIcon(file);
        }
Ejemplo n.º 7
0
        public void LoadItemsInTreeView_should_not_add_icons_for_file_if_none_provided()
        {
            var items = new[] { new GitItem(0, GitObjectType.Blob, "", "file1.foo"), new GitItem(0, GitObjectType.Blob, "", "file2.txt") };
            var item  = new GitItem(0, GitObjectType.Tree, Guid.NewGuid().ToString("N"), "folder");

            _revisionInfoProvider.LoadChildren(item).Returns(items);

            _controller.LoadChildren(item, _rootNode.Nodes, _imageList.Images);

            _rootNode.Nodes.Count.Should().Be(items.Length);
            for (int i = 0; i < items.Length - 1; i++)
            {
                _rootNode.Nodes[i].Text.Should().Be(items[i].Name);
                _rootNode.Nodes[i].ImageKey.Should().BeEmpty();
                _rootNode.Nodes[i].SelectedImageKey.Should().BeEmpty();
                _rootNode.Nodes[i].Nodes.Count.Should().Be(0);
                _iconProvider.Received(1).Get(Arg.Any <string>(), items[i].Name);
            }

            _imageList.Images.Count.Should().Be(0);
        }
Ejemplo n.º 8
0
        public void LoadItemsInTreeView_should_not_load_icons_for_file_without_extension()
        {
            var items = new[] { new GitItem(0, GitObjectType.Blob, ObjectId.Random(), "file1."), new GitItem(0, GitObjectType.Blob, ObjectId.Random(), "file2") };
            var item  = new GitItem(0, GitObjectType.Tree, ObjectId.Random(), "folder");

            _revisionInfoProvider.LoadChildren(item).Returns(items);

            _controller.LoadChildren(item, _rootNode.Nodes, _imageList.Images);

            _rootNode.Nodes.Count.Should().Be(items.Length);
            for (int i = 0; i < items.Length - 1; i++)
            {
                _rootNode.Nodes[i].Text.Should().Be(items[i].Name);
                _rootNode.Nodes[i].ImageKey.Should().BeEmpty();
                _rootNode.Nodes[i].SelectedImageKey.Should().BeEmpty();
                _rootNode.Nodes[i].Nodes.Count.Should().Be(0);
            }

            _imageList.Images.Count.Should().Be(0);
            _iconProvider.DidNotReceive().Get(Arg.Any <string>(), Arg.Any <string>());
        }
Ejemplo n.º 9
0
        public void LoadItemsInTreeView_should_add_icon_for_file_extension_only_once()
        {
            var items = new[] { CreateGitItem("file1.txt", false, false, true), CreateGitItem("file2.txt", false, false, true) };
            var item  = new GitItem("", "", System.Guid.NewGuid().ToString("N"), "folder");

            _revisionInfoProvider.LoadChildren(item).Returns(items);
            var image = Resources.cow_head;

            _iconProvider.Get(Arg.Any <string>(), Arg.Is <string>(x => x.EndsWith(".txt"))).Returns(image);

            _controller.LoadChildren(item, _rootNode.Nodes, _imageList.Images);

            _rootNode.Nodes.Count.Should().Be(items.Length);
            for (int i = 0; i < items.Length - 1; i++)
            {
                _rootNode.Nodes[i].Text.Should().Be(items[i].Name);
                _rootNode.Nodes[i].ImageKey.Should().Be(".txt");
                _rootNode.Nodes[i].SelectedImageKey.Should().Be(".txt");
                _rootNode.Nodes[i].Nodes.Count.Should().Be(0);
                _iconProvider.Received(1).Get(Arg.Any <string>(), items[i].Name);
            }
            _imageList.Images.Count.Should().Be(1);
        }
Ejemplo n.º 10
0
        public void LoadItemsInTreeView_should_add_icon_for_file_extension_only_once()
        {
            var items = new[] { new GitItem(0, GitObjectType.Blob, ObjectId.Random(), "file1.txt"), new GitItem(0, GitObjectType.Blob, ObjectId.Random(), "file2.txt") };
            var item  = new GitItem(0, GitObjectType.Tree, ObjectId.Random(), "folder");

            _revisionInfoProvider.LoadChildren(item).Returns(items);
            using var bitmap = new Bitmap(1, 1);
            using var icon   = Icon.FromHandle(bitmap.GetHicon());
            _iconProvider.Get(Arg.Any <string>(), Arg.Is <string>(x => x.EndsWith(".txt"))).Returns(icon);

            _controller.LoadChildren(item, _rootNode.Nodes, _imageList.Images);

            _rootNode.Nodes.Count.Should().Be(items.Length);
            for (int i = 0; i < items.Length - 1; i++)
            {
                _rootNode.Nodes[i].Text.Should().Be(items[i].Name);
                _rootNode.Nodes[i].ImageKey.Should().Be(".txt");
                _rootNode.Nodes[i].SelectedImageKey.Should().Be(".txt");
                _rootNode.Nodes[i].Nodes.Count.Should().Be(0);
                _iconProvider.Received(1).Get(Arg.Any <string>(), items[i].Name);
            }

            _imageList.Images.Count.Should().Be(1);
        }
Ejemplo n.º 11
0
        public GitItem GetAlreadyNormalizedItem(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            lock (_lock)
            {
                GitItem item;

                if (!_map.TryGetValue(path, out item))
                {
                    string truePath = SvnTools.GetTruePath(path, true);

                    // Just create an item based on his name. Delay the Git calls as long as we can
                    StoreItem(item = new GitItem(this, truePath ?? path, NoSccStatus.Unknown, SvnNodeKind.Unknown));

                    //item.MarkDirty(); // Load status on first access
                }

                return(item);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the SvnItem of the document file and all subdocument files (SccSpecial files)
        /// </summary>
        /// <param name="documentName">The document.</param>
        /// <returns></returns>
        public override IEnumerable <string> GetAllDocumentFiles(string documentName)
        {
            if (string.IsNullOrEmpty(documentName))
            {
                throw new ArgumentNullException("document");
            }

            SccProjectFile pf;

            if (!ProjectMap.TryGetFile(documentName, out pf))
            {
                yield break;
            }

            foreach (string path in pf.GetAllFiles())
            {
                GitItem item = StatusCache[documentName];

                if (item != null)
                {
                    yield return(item.FullPath); // Use true path
                }
            }
        }
Ejemplo n.º 13
0
 private void SpawnCommitBrowser(GitItem item)
 {
     GitUICommands.LaunchBrowse(workingDir: _fullPathResolver.Resolve(item.FileName.EnsureTrailingPathSeparator()), selectedId: item.ObjectId);
 }
Ejemplo n.º 14
0
        public GitTarget GetCopyOrigin(GitItem item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            // TODO: We currently do not provide access to copied files.
            // VisualGitStatus.IsCopied/.IsReplaced will never be true, because
            // the copied information currently is only provided through the
            // changed paths interface. This method is only called when
            // .IsCopied/.IsReplaced is true.

            throw new NotSupportedException();
        }
Ejemplo n.º 15
0
        string SafeRepositoryPath(GitItem item)
        {
            if (item == null || String.IsNullOrEmpty(item.FullPath))
                return "";

            return GitTools.GetRepositoryPath(item.FullPath);
        }
Ejemplo n.º 16
0
        public AnkhGlyph GetStatusImageForGitItem(GitItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (item.IsConflicted)
            {
                return(AnkhGlyph.InConflict);
            }
            else if (!item.IsVersioned)
            {
                if (!item.Exists)
                {
                    return(AnkhGlyph.FileMissing);
                }
                else if (item.IsIgnored)
                {
                    return(AnkhGlyph.Ignored);
                }
                else if (item.IsVersionable)
                {
                    if (item.InSolution)
                    {
                        return(item.IsSccExcluded ? AnkhGlyph.Ignored : AnkhGlyph.ShouldBeAdded);
                    }
                    else
                    {
                        return(AnkhGlyph.None);
                    }
                }
                else
                {
                    return(AnkhGlyph.None);
                }
            }

            GitStatus status = item.Status.WorkingStatus;

            if (status == GitStatus.Normal || status == GitStatus.None)
            {
                status = item.Status.IndexStatus;
            }

            switch (status)
            {
            case GitStatus.Normal:
                if (item.IsDocumentDirty)
                {
                    return(AnkhGlyph.FileDirty);
                }
                else
                {
                    return(AnkhGlyph.Normal);
                }

            /*case GitStatus.Replaced:
             *  return AnkhGlyph.CopiedOrMoved;*/
            case GitStatus.New:
                return(false ? AnkhGlyph.CopiedOrMoved : AnkhGlyph.Added);

            case GitStatus.Renamed:
                return(AnkhGlyph.CopiedOrMoved);

            case GitStatus.Deleted:
                if (item.Exists && item.InSolution)
                {
                    return(item.IsSccExcluded ? AnkhGlyph.Ignored : AnkhGlyph.ShouldBeAdded);
                }
                return(AnkhGlyph.Deleted);

            /*case GitStatus.Conflicted: // Should have been handled above
             * case GitStatus.Obstructed:
             *  return AnkhGlyph.InConflict;*/

            case GitStatus.Unreadable:
                return(AnkhGlyph.InConflict);

            /*case GitStatus.External:
             * case GitStatus.Incomplete:
             *  return AnkhGlyph.InConflict;
             *
             * case GitStatus.Zero:*/
            default:
                return(AnkhGlyph.None);
            }
        }
Ejemplo n.º 17
0
        private static void AddIgnore(Dictionary<string, List<string>> add, GitItem item, string name)
        {
            if (item == null)
                return;
            if (!item.IsVersioned)
                return;
            List<string> toAdd;

            if (!add.TryGetValue(item.FullPath, out toAdd))
            {
                toAdd = new List<string>();
                add.Add(item.FullPath, toAdd);
            }

            if (!toAdd.Contains(name))
                toAdd.Add(name);
        }
Ejemplo n.º 18
0
        private PendingChange UpdatePendingChange(bool wasClean, GitItem item)
        {
            PendingChange pc;
            string file = item.FullPath;
            if (_pendingChanges.TryGetValue(file, out pc))
            {
                if (pc.Refresh(RefreshContext, item) && !wasClean)
                {
                    if (pc.IsClean)
                    {
                        _pendingChanges.Remove(file);
                        _extraFiles.Remove(file);

                        // No need to check wasClean
                        OnRemoved(new PendingChangeEventArgs(this, pc));
                    }
                    else if (!wasClean)
                        OnChanged(new PendingChangeEventArgs(this, pc));
                }
            }
            else if (PendingChange.CreateIfPending(RefreshContext, item, out pc))
            {
                Debug.Assert(!_pendingChanges.Contains(pc), "Insane race condition triggered");

                if (!_pendingChanges.Contains(pc))
                    _pendingChanges.Add(pc);

                if (!wasClean)
                    OnAdded(new PendingChangeEventArgs(this, pc));
            }

            return pc;
        }
            private bool AddItem(GitItem item, out uint parentId)
            {
                string itemDir = item.Directory;

                if (itemDir == null)
                {
                    parentId = VSConstants.VSITEMID_NIL;
                    return false;
                }
                else if (string.Equals(itemDir, ProjectDirectory, StringComparison.OrdinalIgnoreCase))
                    parentId = VSConstants.VSITEMID_ROOT;
                else
                {
                    parentId = GetId(itemDir, VSConstants.VSITEMID_ROOT);

                    if (parentId == VSConstants.VSITEMID_NIL)
                    {
                        if (!AddItem(item.Parent, out parentId))
                            return false;

                        parentId = GetId(itemDir, parentId);

                        if (parentId == VSConstants.VSITEMID_NIL)
                            return false;
                    }
                }
                VSADDRESULT[] result = new VSADDRESULT[1];

                return ErrorHandler.Succeeded(VsProject.AddItem(parentId, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, item.FullPath,
                    1, new string[] { item.FullPath }, IntPtr.Zero, result)) && result[0] == VSADDRESULT.ADDRESULT_Success;
            }
        tagVSQuerySaveResult QueryReadOnlyFile(GitItem item)
        {
            // Now we have to ask the user wether to overwrite, or to save as
            using (SccQuerySaveReadonlyDialog dlg = new SccQuerySaveReadonlyDialog())
            {
                dlg.File = item.Name;

                DialogResult result = dlg.ShowDialog(Context);
                switch (result)
                {
                    case DialogResult.Yes:
                        // Force the caller to show a save-as dialog for this file
                        return tagVSQuerySaveResult.QSR_ForceSaveAs;

                    case DialogResult.No:
                        // User wants to overwrite existing file
                        try
                        {
                            FileAttributes attrs = File.GetAttributes(item.FullPath);
                            File.SetAttributes(item.FullPath, attrs & ~FileAttributes.ReadOnly);
                        }
                        catch (IOException) // Includes PathTooLongException
                        { }
                        catch (SystemException) // Includes UnauthorizedAccessException
                        { }

                        // it's no longer read-only, so save is OK
                        return tagVSQuerySaveResult.QSR_SaveOK;

                    case DialogResult.Cancel:
                        return tagVSQuerySaveResult.QSR_NoSave_Cancel;
                    default:
                        throw new InvalidOperationException("Dialog returned unexpected DialogResult");
                } // switch(dialogResult)
            } // using dialog
        }
 public bool AddItem(GitItem item)
 {
     uint parentId;
     return AddItem(item, out parentId);
 }
 public void RemoveItem(GitItem item, uint id)
 {
     int found;
     VsProject.RemoveItem(0, id, out found);
     _map.Clear(); // Flush the cache to make sure ids stay valid
 }
 public RefreshState(IVisualGitServiceProvider context, IVsHierarchy hier, IVsProject project, string projectDir)
 {
     _hier = hier;
     _cache = context.GetService<IFileStatusCache>();
     _walker = context.GetService<ISccProjectWalker>();
     _project = project as IVsProject2;
     _projectDir = projectDir;
     if (projectDir != null)
         _projectDirItem = Cache[projectDir];
 }
        private IGitItem CreateGitItem(string name, bool isTree, bool isCommit, bool isBlol)
        {
            var item = new GitItem("", isTree ? "tree" : isBlol ? "blob" : isCommit ? "commit" : "", "", name);

            return(item);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Adds a node to the right place in the tree.
        /// </summary>
        /// <param name="nodeName"></param>
        private void AddNode(GitItem item)
        {
            TreeNodeCollection nodes = this.Nodes;

            string fullPath = item.FullPath;
            string[] components;

            int nStart = 0;
            if (Context != null)
            {
                IVisualGitSolutionSettings ss = Context.GetService<IVisualGitSolutionSettings>();

                if (ss != null)
                {
                    string root = ss.ProjectRootWithSeparator;

                    if (!string.IsNullOrEmpty(root) && fullPath.StartsWith(root))
                        nStart = root.Length - 1;
                }
            }

            if (nStart == 0)
                components = fullPath.Split(this.PathSeparator[0]);
            else
            {
                components = fullPath.Substring(nStart).Split(this.PathSeparator[0]);
                components[0] = fullPath.Substring(0, nStart) + components[0];
            }

            PathTreeNode node = null;
            foreach (string component in components)
            {
                node = this.GetNode(nodes, component);
                nodes = node.Nodes;
            }

            // leaf nodes should be black and enabled
            if (node != null)
            {
                node.Enabled = true;
                node.Tag = item;
                this.ResolveIcon(node);
            }
        }
Ejemplo n.º 26
0
 static DateTime GetCreated(GitItem item)
 {
     try
     {
         return File.GetCreationTimeUtc(item.FullPath);
     }
     catch
     {
         return DateTime.UtcNow;
     }
 }
Ejemplo n.º 27
0
 public WCFileNode(IVisualGitServiceProvider context, WCTreeNode parent, GitItem item)
     : base(context, parent, item)
 {
 }
        bool ShouldIgnore(GitItem item)
        {
            while (item != null)
            {
                GitStatus lc = item.Status.State;
                if (lc == GitStatus.Ignored)
                    return true;
                else if (lc != GitStatus.NotVersioned)
                    return false;

                item = item.Parent;
            }
            return false;
        }
Ejemplo n.º 29
0
        protected WCFileSystemNode(IVisualGitServiceProvider context, WCTreeNode parent, GitItem item)
            : base(context, parent)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            _item = item;
        }
Ejemplo n.º 30
0
        public void StartMergesMerged(IVisualGitServiceProvider context, GitItem target, string source)
        {
            if (target == null)
                throw new ArgumentNullException("target");

            GitOrigin origin = new GitOrigin(target);
            _origins = new GitOrigin[] { origin };
            UpdateTitle();
            logControl.StartMergesMerged(context, origin, source);
        }
Ejemplo n.º 31
0
        static bool NotDeletedFilter(GitItem item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            return !item.IsDeleteScheduled && item.Exists;
        }
Ejemplo n.º 32
0
 static bool Skip(GitItem item)
 {
     return (item.IsVersioned || item.IsIgnored || !item.IsVersionable || !item.Exists);
 }
Ejemplo n.º 33
0
        string GetGitCasing(GitItem item)
        {
            string name = null;
            // Find the correct casing
            using (GitClient client = Context.GetService<IGitClientPool>().GetNoUIClient())
            {
                GitStatusArgs args = new GitStatusArgs();

                args.Depth = GitDepth.Files;
                args.RetrieveAllEntries = false;
                args.RetrieveIgnoredEntries = false;
                args.ThrowOnCancel = false;
                args.ThrowOnError = false;

                client.Status(item.Directory, args,
                    delegate(object sender, GitStatusEventArgs ea)
                    {
                        if (string.Equals(ea.FullPath, item.FullPath, StringComparison.OrdinalIgnoreCase))
                        {
                            name = ea.FullPath;
                        }
                    });
            }

            return name;
        }
Ejemplo n.º 34
0
        private string GetStatus(GitItem dirItem, IGitProjectInfo projectInfo, string file)
        {
            if (dirItem == null || !dirItem.Exists || !dirItem.IsVersioned)
                return "<not found>";

            if (projectInfo == null)
            {
                if (Scc.IsSolutionManaged)
                    return "Connected"; // Solution itself + Connected
                else
                    return "Not Connected";
            }

            if (dirItem.IsBelowPath(SolutionSettings.ProjectRootGitItem)
                    && dirItem.WorkingCopy == SolutionSettings.ProjectRootGitItem.WorkingCopy)
            {
                // In master working copy
                if (Scc.IsSolutionManaged && Scc.IsProjectManaged(_project))
                    return "Connected";
                else
                    return "Valid"; // In master working copy
            }
            else if (Scc.IsSolutionManaged && Scc.IsProjectManaged(_project))
                return "Connected"; // Required information in solution
            else
                return "Detached"; // Separate working copy
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Called from RefreshPath's call to <see cref="GitClient::Status"/>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// All information we receive here is live from Git and Disk and is therefore propagated
        /// in all GitItems wishing information
        /// </remarks>
        void RefreshCallback(object sender, GitStatusEventArgs e)
        {
            // Note: There is a lock(_lock) around this in our caller

            GitStatusData status = new GitStatusData(e);
            string        path   = e.FullPath; // Fully normalized

            if (_root == null)
            {
                _root = new string[] { e.FullPath, e.RelativePath }
            }
            ;

            GitItem item;

            if (!_map.TryGetValue(path, out item) || !NewFullPathOk(item, path, status))
            {
                // We only create an item if we don't have an existing
                // with a valid path. (No casing changes allowed!)

                GitItem newItem = CreateItem(path, status);
                StoreItem(newItem);

                if (item != null)
                {
                    ((IGitItemUpdate)item).RefreshTo(newItem);
                    item.Dispose();
                }

                item = newItem;
            }
            else
            {
                ((IGitItemUpdate)item).RefreshTo(status);
            }

            // Note: There is a lock(_lock) around this in our caller
        }

        /// <summary>
        /// Marks the specified file dirty
        /// </summary>
        /// <param name="file"></param>
        void ISccStatusCache.MarkDirty(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            string normPath = SvnTools.GetNormalizedFullPath(path);

            lock (_lock)
            {
                GitItem item;

                if (_map.TryGetValue(normPath, out item))
                {
                    item.MarkDirty();
                }
            }
        }

        void ISccStatusCache.MarkDirtyRecursive(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            lock (_lock)
            {
                List <string> names = new List <string>();

                foreach (GitItem v in _map.Values)
                {
                    string name = v.FullPath;
                    if (v.IsBelowPath(path))
                    {
                        v.MarkDirty();
                    }
                }
            }
        }
Ejemplo n.º 36
0
        string SafeRepositoryRoot(GitItem item)
        {
            if (item == null || item.WorkingCopy == null)
                return "";

            return item.WorkingCopy.RepositoryRoot;
        }
Ejemplo n.º 37
0
        public string GetTempFile(GitItem target, GitRevision revision, bool withProgress)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            else if (revision == null)
                throw new ArgumentNullException("revision");

            string file = GetTempPath(target.Name, revision);

            if (target.NodeKind != GitNodeKind.File)
                throw new InvalidOperationException("Can't create a tempfile from a directory");

            ProgressRunnerResult r = GetService<IProgressRunner>().RunModal("Getting file",
                delegate(object sender, ProgressWorkerArgs aa)
                {
                    GitWriteArgs wa = new GitWriteArgs();
                    wa.Revision = revision;

                    using (Stream s = File.Create(file))
                        aa.Client.Write(new GitTarget(target.FullPath), s, wa);
                });

            if (!r.Succeeded)
                return null; // User canceled

            if (File.Exists(file))
                File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools

            return file;
        }
Ejemplo n.º 38
0
        private bool BelowAdminDir(GitItem item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (_adminDir == null)
            {
                // Caching in this instance should be safe
                _adminDir = '\\' + GitConstants.AdministrativeDirectoryName + '\\';
            }

            if (string.Equals(item.Name, GitConstants.AdministrativeDirectoryName))
                return true;

            return item.FullPath.IndexOf(_adminDir, StringComparison.OrdinalIgnoreCase) >= 0;
        }
Ejemplo n.º 39
0
 public static string GetFullPathFromGitItem(GitModule gitModule, GitItem gitItem)
 {
     return(GetFullPathFromFilename(gitModule, gitItem.FileName));
 }
        private static void AutoOpenCommand(CommandEventArgs e, GitItem item)
        {
            IProjectFileMapper pfm = e.GetService<IProjectFileMapper>();
            IVisualGitCommandService svc = e.GetService<IVisualGitCommandService>();
            IVisualGitSolutionSettings solutionSettings = e.GetService<IVisualGitSolutionSettings>();

            if (pfm == null || svc == null || solutionSettings == null)
                return;

            // We can assume we have a file

            if (pfm.IsProjectFileOrSolution(item.FullPath))
            {
                // Ok, the user selected the current solution file or an open project
                // Let's jump to it in the solution explorer

                svc.ExecCommand(VisualGitCommand.ItemOpenSolutionExplorer);
                return;
            }

            if (item.InSolution)
            {
                // The file is part of the solution, we can assume VS knows how to open it
                svc.ExecCommand(VisualGitCommand.ItemOpenVisualStudio);
                return;
            }

            string filename = item.Name;
            string ext = item.Extension;

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

            foreach (string projectExt in solutionSettings.AllProjectExtensionsFilter.Split(';'))
            {
                if (projectExt.TrimStart('*').Trim().Equals(ext, StringComparison.OrdinalIgnoreCase))
                {
                    // We found a project or solution: Ask VS to open it

                    e.GetService<IVisualGitSolutionSettings>().OpenProjectFile(item.FullPath);
                    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))
                    {
                        VsShellUtilities.OpenDocument(e.Context, item.FullPath);
                        return;
                    }
                }
            }

            // Ultimate fallback: Just open the file as windows would
            svc.PostExecCommand(VisualGitCommand.ItemOpenWindows);
        }
Ejemplo n.º 41
0
        public string GetTitle(GitItem target, GitRevision revision)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            if (revision == null)
                throw new ArgumentNullException("revision");

            return GetTitle(target.Name, revision);
        }