Ejemplo n.º 1
0
 public ProjectNotifier(IVisualGitServiceProvider context)
     : base(context)
 {
     uint cookie;
     if (ErrorHandler.Succeeded(context.GetService<IVsShell>(typeof(SVsShell)).AdviseBroadcastMessages(this, out cookie)))
         _cookie = cookie;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves all dirty documents within the provided selection
        /// </summary>
        /// <param name="selection">The selection.</param>
        /// <param name="context">The context.</param>
        protected static void SaveAllDirtyDocuments(ISelectionContext selection, IVisualGitServiceProvider context)
        {
            if (selection == null)
                throw new ArgumentNullException("selection");
            if (context == null)
                throw new ArgumentNullException("context");

            IVisualGitOpenDocumentTracker tracker = context.GetService<IVisualGitOpenDocumentTracker>();
            if (tracker != null)
                tracker.SaveDocuments(selection.GetSelectedFiles(true));
        }
Ejemplo n.º 3
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.º 4
0
            public OutputPaneReporter(IVisualGitServiceProvider context, GitClient client)
            {
                if (context == null)
                    throw new ArgumentNullException("context");
                else if (client == null)
                    throw new ArgumentNullException("client");

                _mgr = context.GetService<IOutputPaneManager>();
                _sb = new StringBuilder();
            }
Ejemplo n.º 5
0
        private static void EnsureProjectItemPresent(IVisualGitServiceProvider context, string ignoreFilename)
        {
            var dte = context.GetService<IVisualGitServiceProvider>().GetService<EnvDTE.DTE>();

            foreach (EnvDTE.Project project in (IEnumerable)dte.ActiveSolutionProjects)
            {
                // FullName is the name of the project file; need to get the
                // containing directory.

                string projectPath = Path.GetDirectoryName(project.FullName);

                if (!projectPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    projectPath += Path.DirectorySeparatorChar;

                // We add the ignore file to all projects that have the ignore
                // file located under its root. If the file is already part
                // of the project, this is a no-op.

                if (ignoreFilename.StartsWith(projectPath, StringComparison.OrdinalIgnoreCase))
                    project.ProjectItems.AddFromFile(ignoreFilename);
            }
        }
Ejemplo n.º 6
0
        private static void AddIgnores(IVisualGitServiceProvider context, string ignoreFilename, string path, List<string> ignores)
        {
            try
            {
                context.GetService<IProgressRunner>().RunModal(CommandStrings.IgnoreCaption,
                    delegate(object sender, ProgressWorkerArgs e)
                    {
                        if (File.Exists(ignoreFilename))
                        {
                            int n = 0;
                            foreach (string oldItem in File.ReadAllText(ignoreFilename).Split('\n'))
                            {
                                string item = oldItem.TrimEnd('\r');

                                if (item.Trim().Length == 0)
                                    continue;

                                // Don't add duplicates
                                while (n < ignores.Count && ignores.IndexOf(item, n) >= 0)
                                    ignores.RemoveAt(ignores.IndexOf(item, n));

                                if (ignores.Contains(item))
                                    continue;

                                ignores.Insert(n++, item);
                            }
                        }

                        StringBuilder sb = new StringBuilder();
                        bool next = false;
                        foreach (string item in ignores)
                        {
                            if (next)
                                sb.Append('\n'); // Git wants only newlines
                            else
                                next = true;

                            sb.Append(item);
                        }

                        File.WriteAllText(ignoreFilename, sb.ToString());

                        // .gitignore files need to be in the project, otherwise
                        // they won't be committed.

                        EnsureProjectItemPresent(context, ignoreFilename);
                    });

                // Make sure a changed directory is visible in the PC Window
                context.GetService<IFileStatusMonitor>().ScheduleMonitor(path);
            }
            finally
            {
                // Ignore doesn't bubble
                context.GetService<IFileStatusCache>().MarkDirtyRecursive(path);
            }
        }
Ejemplo n.º 7
0
 public WCMyComputerNode(IVisualGitServiceProvider context)
     : base(context, null)
 {
     _imageIndex = context.GetService<IFileIconMapper>().GetSpecialFolderIcon(WindowsSpecialFolder.MyComputer);
 }
Ejemplo n.º 8
0
        public void RefreshText(IVisualGitServiceProvider context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            IFileStatusCache cache = context.GetService<IFileStatusCache>();

            ImageIndex = PendingChange.IconIndex;
            GitItem item = cache[FullPath];

            if (item == null)
                throw new InvalidOperationException(); // Item no longer valued

            PendingChangeStatus pcs = PendingChange.Change ?? new PendingChangeStatus(PendingChangeKind.None);

            SetValues(
                pcs.PendingCommitText,
                "", // Change list
                GetDirectory(item),
                PendingChange.FullPath,
                "", // Locked
                SafeDate(item.Modified), // Modified
                PendingChange.Name,
                PendingChange.RelativePath,
                PendingChange.Project,
                GetRevision(PendingChange),
                PendingChange.FileType,
                SafeWorkingCopy(item));

            if (!SystemInformation.HighContrast)
            {
                System.Drawing.Color clr = System.Drawing.Color.Black;

                if (item.IsConflicted || PendingChange.Kind == PendingChangeKind.WrongCasing)
                    clr = System.Drawing.Color.Red;
                else if (item.IsDeleteScheduled)
                    clr = System.Drawing.Color.DarkRed;
                else if (item.Status.IsCopied || item.Status.State == GitStatus.Added)
                    clr = System.Drawing.Color.FromArgb(100, 0, 100);
                else if (!item.IsVersioned)
                {
                    if (item.InSolution && !item.IsIgnored)
                        clr = System.Drawing.Color.FromArgb(100, 0, 100); // Same as added+copied
                    else
                        clr = System.Drawing.Color.Black;
                }
                else if (item.IsModified)
                    clr = System.Drawing.Color.DarkBlue;

                ForeColor = clr;
            }
        }
Ejemplo n.º 9
0
 public GitSccContext(IVisualGitServiceProvider context)
     : base(context)
 {
     _client = context.GetService<IGitClientPool>().GetNoUIClient();
     _statusCache = GetService<IFileStatusCache>();
 }
Ejemplo n.º 10
0
        static Version GetCurrentVersion(IVisualGitServiceProvider context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (_currentVersion != null)
                return _currentVersion;

            IVisualGitPackage pkg = context.GetService<IVisualGitPackage>();

            if (pkg != null)
                return _currentVersion = pkg.PackageVersion;
            return _currentVersion = typeof(CheckForUpdates).Assembly.GetName().Version;
        }
Ejemplo n.º 11
0
        public static void MaybePerformUpdateCheck(IVisualGitServiceProvider context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (_checkedOnce)
                return;

            _checkedOnce = true;

            IVisualGitConfigurationService config = context.GetService<IVisualGitConfigurationService>();
            using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck"))
            {
                int interval = 24 * 6; // 6 days
                object value = rk.GetValue("Interval");

                if (value is int)
                {
                    interval = (int)value;

                    if (interval <= 0)
                        return;
                }

                TimeSpan ts = TimeSpan.FromHours(interval);

                value = rk.GetValue("LastVersion");

                if (IsDevVersion() || (value is string && (string)value == GetCurrentVersion(context).ToString()))
                {
                    value = rk.GetValue("LastCheck");
                    long lv;
                    if (value is string && long.TryParse((string)value, out lv))
                    {
                        DateTime lc = new DateTime(lv, DateTimeKind.Utc);

                        if ((lc + ts) > DateTime.UtcNow)
                            return;

                        // TODO: Check the number of fails to increase the check interval
                    }
                }
            }

            context.GetService<IVisualGitScheduler>().Schedule(new TimeSpan(0, 0, 20), VisualGitCommand.CheckForUpdates);
        }
Ejemplo n.º 12
0
            public DiffToolMonitor(IVisualGitServiceProvider context, string monitor, bool monitorDir, VisualGitMergeArgs args)
                : base(context)
            {
                if (string.IsNullOrEmpty(monitor))
                    throw new ArgumentNullException("monitor");
                else if (!GitItem.IsValidPath(monitor))
                    throw new ArgumentOutOfRangeException("monitor");

                _monitorDir = monitorDir;
                _args = args;
                _toMonitor = monitor;

                IVsFileChangeEx fx = context.GetService<IVsFileChangeEx>(typeof(SVsFileChangeEx));

                _cookie = 0;
                if (fx == null)
                { }
                else if (!_monitorDir)
                {
                    if (!ErrorHandler.Succeeded(fx.AdviseFileChange(monitor,
                            (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size
                            | _VSFILECHANGEFLAGS.VSFILECHG_Add | _VSFILECHANGEFLAGS.VSFILECHG_Del
                            | _VSFILECHANGEFLAGS.VSFILECHG_Attr),
                            this,
                            out _cookie)))
                    {
                        _cookie = 0;
                    }
                }
                else
                {
                    if (!ErrorHandler.Succeeded(fx.AdviseDirChange(monitor, 1, this, out _cookie)))
                    {
                        _cookie = 0;
                    }
                }
            }
        internal void OpenItem(IVisualGitServiceProvider context, string p)
        {
            VisualGit.Commands.IVisualGitCommandService cmd = context.GetService<VisualGit.Commands.IVisualGitCommandService>();

            if (cmd != null)
                cmd.ExecCommand(VisualGitCommand.ItemOpenVisualStudio, true);
        }
        public void BrowsePath(IVisualGitServiceProvider context, string path)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            else if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("path");

            folderTree.BrowsePath(path);

            if (context.GetService<IFileStatusCache>()[path].IsFile)
            {
                fileList.SelectPath(path);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Installs a visual studio command handler for the specified control
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="control">The control.</param>
        /// <param name="command">The command.</param>
        /// <param name="handler">The handler.</param>
        /// <param name="updateHandler">The update handler.</param>
        public static void Install(IVisualGitServiceProvider context, Control control, CommandID command, EventHandler<CommandEventArgs> handler, EventHandler<CommandUpdateEventArgs> updateHandler)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            else if (control == null)
                throw new ArgumentNullException("control");
            else if (command == null)
                throw new ArgumentNullException("command");

            IVisualGitCommandHandlerInstallerService svc = context.GetService<IVisualGitCommandHandlerInstallerService>();

            if (svc != null)
                svc.Install(control, command, handler, updateHandler);
        }
Ejemplo n.º 16
0
        static void PerformLog(IVisualGitServiceProvider context, ICollection<GitOrigin> targets, GitRevision start, GitRevision end)
        {
            IVisualGitPackage package = context.GetService<IVisualGitPackage>();

            package.ShowToolWindow(VisualGitToolWindow.Log);

            LogToolWindowControl logToolControl = context.GetService<ISelectionContext>().ActiveFrameControl as LogToolWindowControl;
            if (logToolControl != null)
                logToolControl.StartLog(targets, start, end);
        }
Ejemplo n.º 17
0
            public ProjectListFilter(IVisualGitServiceProvider context, IEnumerable<GitProject> projects)
            {
                if (context == null)
                    throw new ArgumentNullException("context");
                if (projects == null)
                    throw new ArgumentNullException("projects");

                _mapper = context.GetService<IProjectFileMapper>();
                List<GitProject> projectList = new List<GitProject>(projects);

                files.AddRange(_mapper.GetAllFilesOf(projectList));

                foreach (GitProject p in projectList)
                {
                    IGitProjectInfo pi = _mapper.GetProjectInfo(p);

                    if (pi == null)
                        continue; // Ignore solution and non scc projects

                    string dir = pi.ProjectDirectory;

                    if (!string.IsNullOrEmpty(dir) && !folders.Contains(dir))
                        folders.Add(dir);
                }
            }
 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];
 }
Ejemplo n.º 19
0
        protected override IDisposable DialogRunContext(IVisualGitServiceProvider context)
        {
            IVisualGitDialogOwner owner = null;
            if (context != null)
                owner = context.GetService<IVisualGitDialogOwner>();

            if (owner != null)
                return owner.InstallFormRouting(this, EventArgs.Empty);
            else
                return base.DialogRunContext(context);
        }
Ejemplo n.º 20
0
        public CodeEditorWindow(IVisualGitServiceProvider context, Control container)
            : base(context)
        {
            if (container == null)
                throw new ArgumentNullException("container");

            _container = container;
            _serviceProvider = context.GetService<IOleServiceProvider>();
        }