diff --git a/BasicSccProvider.csproj b/BasicSccProvider.csproj index 820bef5..cffe108 100644 --- a/BasicSccProvider.csproj +++ b/BasicSccProvider.csproj @@ -85,9 +85,17 @@ + + Always + true + + + Always + true + diff --git a/GitFileStatusTracker.cs b/GitFileStatusTracker.cs index d1319fe..5475fc4 100644 --- a/GitFileStatusTracker.cs +++ b/GitFileStatusTracker.cs @@ -11,8 +11,6 @@ public class GitFileStatusTracker { private RepositoryStatus repositoryStatus; private Uri workingFolderUri; - //private FileSystemWatcher watcher; - //private IgnoreRules ignoreRules; public GitFileStatusTracker() { @@ -23,47 +21,18 @@ public void Open(string workingFolder) { Close(); - if (!string.IsNullOrEmpty(workingFolder)) + if (!string.IsNullOrEmpty(workingFolder) && Repository.IsValid(workingFolder)) { try { var repo = new Repository(workingFolder); this.repositoryStatus = repo.Status; this.workingFolderUri = new Uri(repo.WorkingDirectory+"\\"); - //this.ignoreRules = new IgnoreRules(Path.Combine(repo.WorkingDirectory, GitSharp.Core.Constants.GITIGNORE_FILENAME)); - - //this.watcher = new FileSystemWatcher(workingFolder + "\\" + GitSharp.Core.Constants.DOT_GIT); //? - ////this.watcher = new FileSystemWatcher(workingFolder); //? - - //this.watcher.NotifyFilter = NotifyFilters.LastWrite; - //this.watcher.EnableRaisingEvents = true; - //this.watcher.Changed += new FileSystemEventHandler(watcher_Changed); } catch { } } - - } - - private DateTime TimeFired; - public event EventHandler OnGitRepoChanged; - private object locker = new object(); - - void watcher_Changed(object sender, FileSystemEventArgs e) - { - lock (locker) - { - double delta = DateTime.Now.Subtract(TimeFired).TotalMilliseconds; - if (delta < 500) return; - - //if (IsIgnoredFile(e.FullPath)) return; - - this.repositoryStatus.Update(); - if (OnGitRepoChanged != null) OnGitRepoChanged(this, EventArgs.Empty); - - TimeFired = DateTime.Now; - } } public bool HasGitRepository @@ -76,39 +45,8 @@ public void Close() if (this.repositoryStatus != null) this.repositoryStatus.Repository.Close(); this.repositoryStatus = null; this.workingFolderUri = null; - //this.ignoreRules = null; - - //if (this.watcher != null) - //{ - // this.watcher.Changed -= new FileSystemEventHandler(watcher_Changed); - // this.watcher.Dispose(); - //} - } - //private bool IsIgnoredFile(string fileName) - //{ - // try - // { - // if (Directory.Exists(fileName)) - // { - // return this.ignoreRules.IgnoreDir(this.repositoryStatus.Repository.WorkingDirectory, fileName); - // } - // else if (File.Exists(fileName)) - // { - // return this.ignoreRules.IgnoreDir(this.repositoryStatus.Repository.WorkingDirectory, - // Path.GetDirectoryName(fileName)) || - // this.ignoreRules.IgnoreFile(this.repositoryStatus.Repository.WorkingDirectory, fileName); - // } - // else - // return true; - // } - // catch - // { - // return false; - // } - //} - public GitFileStatus GetFileStatus(string fileName) { if (!HasGitRepository || string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) @@ -137,6 +75,12 @@ public GitFileStatus GetFileStatus(string fileName) return GitFileStatus.Trackered; } } + + internal void Update() + { + if (this.repositoryStatus!=null) + this.repositoryStatus.Update(); + } } public static class HashSetExt diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..737c8d5 --- /dev/null +++ b/License.txt @@ -0,0 +1,31 @@ +Microsoft Public License (Ms-PL) + +This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. + +1. Definitions + +The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. + +A "contribution" is the original software, or any additions or changes to the software. + +A "contributor" is any person that distributes its contribution under this license. + +"Licensed patents" are a contributor's patent claims that read directly on its contribution. + +2. Grant of Rights + +(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. + +(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. + +3. Conditions and Limitations + +(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. + +(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. + +(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. + +(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. + +(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. \ No newline at end of file diff --git a/Overview.xml b/Overview.xml deleted file mode 100644 index 952a297..0000000 --- a/Overview.xml +++ /dev/null @@ -1,221 +0,0 @@ - - - - ../../../../Common - - true - true - true - true - true - false - true - true - false - true - true - - - - C# Example.BasicSccProvider - C# Basic Source Code Control Provider Sample - Implementing a source code control provider in Visual Studio using C#. - - - - This sample demonstrates how to create a source code control provider that registers - with Visual Studio and can be selected as active source control provider. - - Implement a source control provider package. - Expose an Options page visible only when the provider is active. - Expose a tool window visible only when the provider is active. - Display menu items only when the provider is active. - Example.BasicSccProvider.jpg - - - - - Example - 2 - Example.BasicSccProvider.jpg - Source Code Control - C# - VisualStudioIntegration\Samples\SourceControl\CSharp\Example.BasicSccProvider\ - BasicSccProvider.sln - VisualStudioIntegration\Samples\SourceControl\CSharp\Example.BasicSccProvider\TDD\ - UnitTests.sln - ms-help://MS.VSCC.v90/MS.VSIPCC.v90/MS.VSSDK.v90/dv_vsintegration/html/23a07da8-41b2-4d18-834b-60a71e7a5c54.htm - - SCC - Source - Code - Control - Tool window - provider - active - menu - items - Source Code Control - Source Code Control Provider - - - - - This sample has a package (BasicSccProvider) and the source control service (SccProviderService). - The sample exposes one tool window (SccProviderToolWindow) and one Options page (SccProviderOptions). - - - The source control provider can be selected on the Tools, Options, Source Control, Plug-In Selection page as "Managed Source Control Sample Basic Provider". Selecting it will make it the active source control provider. - - - When the provider is selected as the active source control provider, - the command "Scc Command" will be added to the Tools menu and the command "Source control provider toolwindow" will be added to the View menu, and the Tools, Options, Source Control, Sample Options Page will become visible. - When "View/Source control provider toolwindow" is clicked, the tool window will be created. - The visibility of menu commands, Options page, and tool window is controlled by the active state of the provider. - All of the UI elements will be hidden automatically when the provider is deactivated. - - - - - Visual Studio SDK Website - http://msdn.microsoft.com/vstudio/extend - - - - - Verify that the package can be created and sited and that it implements IVsPackage. - - - Verify that the source control provider service can be created, activated, and deactivated. - - - Test the "Scc Command" command on the Tools menu by toggling it twice. - - - Test the Options-page Activate, Deactivate, Apply, and Close events. - - - Test that the tool window can be displayed and that the toolbar command can be executed. - - - - Verify sample builds in all configurations. - Verify that the sample was registered. The About box should list the product as installed. - Verify that the provider is accessible in Tools, Options, SourceControl. - Verify that menu commands are visible when the provider is active. - Verify that the tool window is visible only when the provider is active, after it was displayed once. - Verify that the Options page is visible only when the provider is active. - - - - BasicSccProvider.cs - - This file contains the Package implementation. It also is responsible for - handling the enabling and execution of source control commands. - - - - SccProviderService.cs - - This file contains the source control service implementation. - The class implements the IVsSccProvider interface that enables source control - provider activation and switching. - - - - SccProviderOptions.cs - - This class derives from MsVsShell.DialogPage and provides the Options page. - It is responsible for handing the Option page events, such as activation, apply, and close. - It hosts the SccProviderOptionsControl. - - - - SccProviderOptionsControl.cs - - This class is a UserControl that will be hosted on the Options page. - It has a label to demonstrate display of controls in the page. - - - - SccProviderToolWindow.cs - - This class derives from ToolWindowPane, which provides the IVsWindowPane - implementation. It is responsible for defining the window frame properties - such as caption and bitmap. It hosts the SccProviderToolWindowControl. - - - - SccProviderToolWindowControl.cs - - This class is a UserControl that will be hosted in the tool window. It has - a label to demonstrate display of controls in the window. - - - - CommandId.cs - - This is a list of GUIDs specific to this sample, especially the package GUID - and the commands group GUID. It also includes GUIDs of other elements used by - the sample. - - - - Guids.cs - - This is the list of command IDs that the sample defines. - - - - PkgCmd.vsct - - This file describes the menu structure and commands for this sample. - - - - Resources (.cs/.resx/.Designer.cs) - These files are used to support localized strings. - - - Resources\Images_24bit.bmp - - This bitmap defines the icons that are used for tool windows. - - - - Resources\Images_32bit.bmp - - This bitmap defines the icons that are used for toolbars and menu commands. - - - - Resources\Product.ico - - This file defines the icon to be used for the product. - - - - ProvideSourceControlProvider.cs - - This file contains the implementation of a custom registration attribute - that registers a source control provider. It is used to make the source control - provider visible on the Tools, Options, SourceControl, Plugins page. - - - - ProvideToolsOptionsPageVisibility.cs - - This file contains the implementation of a custom registration attribute - that defines the visibility of a tool window. It is used to make the tool - window implemented by the provider visible only when the provider is active - (that is, when the provider context UI has been asserted). - - - - - - 2005-10-01 - Created this sample for the Visual Studio 2005 SDK. - - - \ No newline at end of file diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 5a469f2..8610a47 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -22,7 +22,7 @@ [assembly: AssemblyTitle("Git Source Control Provider")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("Yiyisun@hotmail.com")] [assembly: AssemblyProduct("Git Source Control Provider")] [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] [assembly: AssemblyTrademark("")] diff --git a/README.html b/README.html deleted file mode 100644 index 9813938..0000000 --- a/README.html +++ /dev/null @@ -1,21 +0,0 @@ - -Git Source Control Provider - - -

Introduction

-Visual Studio users are used to see file status in source code control system right inside the solution explorer, whether it is SourceSafe, Team Foundation Server, Subversionor or even Mercurial. This plug-in integrates Git with visual studio solution explorer.

solution explorer.png -

Features

- -

How to use

- -solution explorer - context menu.png -

What's coming

-
- \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..65ad765 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +Git Source Control Provider +=========================== + +Introduction +------------ +Visual Studio users are used to see file status of source control right inside the solution explorer, whether it is SourceSafe, Team Foundation Server, Subversion or even Mercurial. This plug-in integrates Git with Visual Studio solution explorer. + +![solution explorer] (http://gitscc.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=123874) + +Features +-------- +* Displays file status in solution explorer +* Enable/disable plug-in through visual studio's source control plug-in selection +* No source code control information stored in solution or project file. + +How to use +---------- +Download and install Git and [Git Source Control Provider]: http://gitscc.codeplex.com/releases +Open Visual Studio and go to Tools -> Options. +Select Source Control in the tree view +Select Git Source Control Provider from the drop down list, and click OK. +Open your solution controlled by Git to see the file's status. +If the file status is out of sync, right click solution explorer items and select "Refresh Git File Status" +![context menu](http://gitscc.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=123883) + +What's coming +----------------- +[Project Roadmap]: http://gitscc.codeplex.com/wikipage?title=Project%20Roadmap&referringTitle=Home diff --git a/SccProviderService.cs b/SccProviderService.cs index 9ce2861..28cd6fc 100644 --- a/SccProviderService.cs +++ b/SccProviderService.cs @@ -18,12 +18,13 @@ public class SccProviderService : IVsSccProvider, IVsSccManagerTooltip, IVsSolutionEvents, IVsSolutionEvents2, + IVsFileChangeEvents, IVsSccGlyphs, IDisposable { private bool _active = false; private BasicSccProvider _sccProvider = null; - private uint _vsSolutionEventsCookie; + private uint _vsSolutionEventsCookie, _vsIVsFileChangeEventsCookie; private GitFileStatusTracker _statusTracker = null; @@ -32,19 +33,15 @@ public SccProviderService(BasicSccProvider sccProvider) { _sccProvider = sccProvider; _statusTracker = new GitFileStatusTracker(); - _statusTracker.OnGitRepoChanged += new EventHandler(_statusTracker_OnGitRepoChanged); // Subscribe to solution events IVsSolution sol = (IVsSolution)_sccProvider.GetService(typeof(SVsSolution)); sol.AdviseSolutionEvents(this, out _vsSolutionEventsCookie); - Debug.Assert(VSConstants.VSCOOKIE_NIL != _vsSolutionEventsCookie); } public void Dispose() - { - _statusTracker.OnGitRepoChanged -= new EventHandler(_statusTracker_OnGitRepoChanged); - + { // Unregister from receiving solution events if (VSConstants.VSCOOKIE_NIL != _vsSolutionEventsCookie) { @@ -357,7 +354,12 @@ internal void OpenTracker() if (!string.IsNullOrEmpty(solutionFileName)) { - _statusTracker.Open(Path.GetDirectoryName(solutionFileName)); + + string pathGetsolution = Path.GetDirectoryName(solutionFileName); + _statusTracker.Open(pathGetsolution); + + IVsFileChangeEx fileChangeService = _sccProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; + fileChangeService.AdviseDirChange(pathGetsolution, 1, this, out _vsIVsFileChangeEventsCookie); } } @@ -365,6 +367,11 @@ internal void OpenTracker() private void CloseTracker() { _statusTracker.Close(); + if (VSConstants.VSCOOKIE_NIL != _vsIVsFileChangeEventsCookie) + { + IVsFileChangeEx fileChangeService = _sccProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; + fileChangeService.UnadviseDirChange(_vsIVsFileChangeEventsCookie); + } } private void _statusTracker_OnGitRepoChanged(object sender, EventArgs e) @@ -556,6 +563,30 @@ private IList GetNodeFiles(IVsSccProject2 pscp2, uint itemid) } + #endregion + + #region IVsFileChangeEvents + + private DateTime lastTimeDirChangeFired; + + public int DirectoryChanged(string pszDirectory) + { + double delta = DateTime.Now.Subtract(lastTimeDirChangeFired).TotalMilliseconds; + if (delta > 1000) + { + System.Threading.Thread.Sleep(100); + _statusTracker.Update(); + Refresh(); + } + lastTimeDirChangeFired = DateTime.Now; + return VSConstants.S_OK; + } + + public int FilesChanged(uint cChanges, string[] rgpszFile, uint[] rggrfChange) + { + return VSConstants.S_OK; + } + #endregion } } \ No newline at end of file diff --git a/solution explorer.png b/solution explorer.png new file mode 100644 index 0000000..6c72dbb Binary files /dev/null and b/solution explorer.png differ diff --git a/source.extension.vsixmanifest b/source.extension.vsixmanifest index 8718990..bc27fc3 100644 --- a/source.extension.vsixmanifest +++ b/source.extension.vsixmanifest @@ -3,9 +3,11 @@ Git Source Control Provider Yiyisun@hotmail.com - 0.2 + 0.3 Git Source Control Provider is a plug-in that integrates git with Visual Studio. 1033 + License.txt + solution explorer.png false