Skip to content
This repository
Browse code

fix 15114 (status not refresh when switching providers), 14539 (typo)…

…, 14484 (only solution items, no project)
  • Loading branch information...
commit 6fd2eb1e92fe29c8d9773ec50af87d0930b69f92 1 parent 6568518
Yiyi Sun authored
2  BasicSccProvider.Tests/GitFileStatusTrackerTest.cs
@@ -178,7 +178,7 @@ public void GetFileStatusTest()
178 178
179 179 tracker.Commit("test");
180 180 tracker.Refresh();
181   - Assert.AreEqual(GitFileStatus.Trackered, tracker.GetFileStatus(tempFile));
  181 + Assert.AreEqual(GitFileStatus.Tracked, tracker.GetFileStatus(tempFile));
182 182
183 183 File.WriteAllText(tempFile, "changed text");
184 184 tracker.Refresh();
11 BasicSccProvider.cs
@@ -50,6 +50,8 @@ namespace GitScc
50 50 [Guid("C4128D99-2000-41D1-A6C3-704E6C1A3DE2")]
51 51 public class BasicSccProvider : MsVsShell.Package, IOleCommandTarget
52 52 {
  53 + private SccOnIdleEvent _OnIdleEvent = new SccOnIdleEvent();
  54 +
53 55 private List<GitFileStatusTracker> projects;
54 56 private SccProviderService sccService = null;
55 57
@@ -110,12 +112,21 @@ protected override void Initialize()
110 112 // If the package is to become active, this will also callback on OnActiveStateChange and the menu commands will be enabled
111 113 IVsRegisterScciProvider rscp = (IVsRegisterScciProvider)GetService(typeof(IVsRegisterScciProvider));
112 114 rscp.RegisterSourceControlProvider(GuidList.guidSccProvider);
  115 +
  116 + _OnIdleEvent.RegisterForIdleTimeCallbacks(GetGlobalService(typeof(SOleComponentManager)) as IOleComponentManager);
  117 + _OnIdleEvent.OnIdleEvent += new OnIdleEvent(sccService.UpdateNodesGlyphs);
  118 +
113 119 }
114 120
115 121 protected override void Dispose(bool disposing)
116 122 {
117 123 Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering Dispose() of: {0}", this.ToString()));
118 124
  125 + _OnIdleEvent.OnIdleEvent -= new OnIdleEvent(sccService.UpdateNodesGlyphs);
  126 + _OnIdleEvent.UnRegisterForIdleTimeCallbacks();
  127 +
  128 + sccService.Dispose();
  129 +
119 130 base.Dispose(disposing);
120 131 }
121 132
1  BasicSccProvider.csproj
@@ -89,6 +89,7 @@
89 89 <DesignTime>True</DesignTime>
90 90 <DependentUpon>Resources.resx</DependentUpon>
91 91 </Compile>
  92 + <Compile Include="SccOnIdleEvent.cs" />
92 93 <Compile Include="SccProviderOptions.cs">
93 94 <SubType>Component</SubType>
94 95 </Compile>
2  GitFileStatus.cs
@@ -8,7 +8,7 @@ public enum GitFileStatus
8 8 {
9 9 NotControlled,
10 10 New,
11   - Trackered,
  11 + Tracked,
12 12 Modified,
13 13 Staged,
14 14 Removed,
2  GitFileStatusTracker.cs
@@ -124,7 +124,7 @@ private GitFileStatus GetFileStatusNoCache(string fileName)
124 124 }
125 125 if (treeEntry != null && treeEntry.Id.Equals(indexEntry.ObjectId))
126 126 {
127   - return GitFileStatus.Trackered;
  127 + return GitFileStatus.Tracked;
128 128 }
129 129 }
130 130 else // <-- index entry == null
77 SccOnIdleEvent.cs
... ... @@ -0,0 +1,77 @@
  1 +using System;
  2 +using Microsoft.VisualStudio.OLE.Interop;
  3 +using System.Runtime.InteropServices;
  4 +
  5 +namespace GitScc
  6 +{
  7 + // ------------------------------------------------------------------------
  8 + // IOleComponent OnIdle trigger
  9 + // ------------------------------------------------------------------------
  10 + public delegate void OnIdleEvent();
  11 +
  12 + class SccOnIdleEvent : IOleComponent
  13 + {
  14 + uint _wComponentID = 0;
  15 + IOleComponentManager _cmService = null;
  16 +
  17 + public event OnIdleEvent OnIdleEvent;
  18 +
  19 + public void RegisterForIdleTimeCallbacks(IOleComponentManager cmService)
  20 + {
  21 + _cmService = cmService;
  22 +
  23 + if (_cmService != null)
  24 + {
  25 + OLECRINFO[] pcrinfo = new OLECRINFO[1];
  26 + pcrinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
  27 + pcrinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime |
  28 + (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
  29 + pcrinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal |
  30 + (uint)_OLECADVF.olecadvfRedrawOff |
  31 + (uint)_OLECADVF.olecadvfWarningsOff;
  32 + pcrinfo[0].uIdleTimeInterval = 100;
  33 +
  34 + _cmService.FRegisterComponent(this, pcrinfo, out _wComponentID);
  35 + }
  36 + }
  37 +
  38 + public void UnRegisterForIdleTimeCallbacks()
  39 + {
  40 + if (_cmService != null)
  41 + _cmService.FRevokeComponent(_wComponentID);
  42 + }
  43 +
  44 + public virtual int FContinueMessageLoop(uint uReason, IntPtr pvLoopData, MSG[] pMsgPeeked)
  45 + { return 1; }
  46 +
  47 + /// <summary>
  48 + /// Idle processing trigger method
  49 + /// </summary>
  50 + public virtual int FDoIdle(uint grfidlef)
  51 + {
  52 + if (OnIdleEvent != null)
  53 + OnIdleEvent();
  54 +
  55 + return 0;
  56 + }
  57 +
  58 + public virtual int FPreTranslateMessage(MSG[] pMsg)
  59 + { return 0; }
  60 + public virtual int FQueryTerminate(int fPromptUser)
  61 + { return 1; }
  62 + public virtual int FReserved1(uint dwReserved, uint message, IntPtr wParam, IntPtr lParam)
  63 + { return 0; }
  64 + public virtual IntPtr HwndGetWindow(uint dwWhich, uint dwReserved)
  65 + { return IntPtr.Zero; }
  66 + public virtual void OnActivationChange(IOleComponent pic, int fSameComponent, OLECRINFO[] pcrinfo, int fHostIsActivating, OLECHOSTINFO[] pchostinfo, uint dwReserved)
  67 + { ; }
  68 + public virtual void OnAppActivate(int fActive, uint dwOtherThreadID)
  69 + { ; }
  70 + public virtual void OnEnterState(uint uStateID, int fEnter)
  71 + { ; }
  72 + public virtual void OnLoseActivation()
  73 + { ; }
  74 + public virtual void Terminate()
  75 + { ; }
  76 + }
  77 +}
80 SccProviderService.cs
@@ -149,7 +149,7 @@ public int GetSccGlyph([InAttribute] int cFiles, [InAttribute] string[] rgpszFul
149 149
150 150 switch (status)
151 151 {
152   - case GitFileStatus.Trackered:
  152 + case GitFileStatus.Tracked:
153 153 rgsiGlyphs[0] = VsStateIcon.STATEICON_CHECKEDIN;
154 154 break;
155 155
@@ -619,11 +619,6 @@ internal void OpenTracker()
619 619 {
620 620 monitorFolder = Path.GetDirectoryName(solutionFileName);
621 621
622   - //IVsHierarchy sol = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution));
623   - //EnumHierarchyItems(sol, VSConstants.VSITEMID_ROOT, 0,
624   - // (h, id) => {if(id==VSConstants.VSITEMID_ROOT) AddProject(h);} //only add project nodes
625   - //);
626   -
627 622 GetLoadedControllableProjects().ForEach(h => AddProject(h as IVsHierarchy));
628 623
629 624 if (monitorFolder != lastMinotorFolder)
@@ -667,39 +662,24 @@ private void RemoveFolderMonitor()
667 662
668 663 #region IVsFileChangeEvents
669 664
670   - internal void Refresh()
671   - {
672   - Debug.WriteLine("==== Refresh Nodes");
673   -
674   - noRefresh = true;
675   - OpenTracker();
676   -
677   - //IVsHierarchy sol = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution));
678   - //EnumHierarchyItems(sol as IVsHierarchy, VSConstants.VSITEMID_ROOT, 0,
679   - // (h, id) => processNodeFunc(h, id)
680   - //);
681   -
682   - RefreshNodesGlyphs();
683   -
684   - noRefresh = false;
685   - }
686   -
687   - private DateTime lastTimeDirChangeFired = DateTime.Now;
  665 + //private DateTime lastTimeDirChangeFired = DateTime.Now;
688 666
689 667 public int DirectoryChanged(string pszDirectory)
690 668 {
691 669 if (noRefresh) return VSConstants.S_OK;
692 670
693   - double delta = DateTime.Now.Subtract(lastTimeDirChangeFired).TotalMilliseconds;
694   - lastTimeDirChangeFired = DateTime.Now;
  671 + //double delta = DateTime.Now.Subtract(lastTimeDirChangeFired).TotalMilliseconds;
  672 + //lastTimeDirChangeFired = DateTime.Now;
695 673
696 674 //Debug.WriteLine("==== dir changed: " + Math.Floor(delta).ToString());
697   - if (delta > 1000)
698   - {
699   - System.Threading.Thread.Sleep(200);
700   - Debug.WriteLine("==== dir changed REFRESH: " + Math.Floor(delta).ToString());
701   - Refresh();
702   - }
  675 + //if (delta > 1000)
  676 + //{
  677 + // System.Threading.Thread.Sleep(200);
  678 + // Debug.WriteLine("==== dir changed REFRESH: " + Math.Floor(delta).ToString());
  679 + // Refresh();
  680 + //}
  681 +
  682 + NodesGlyphsDirty = true;
703 683 return VSConstants.S_OK;
704 684 }
705 685
@@ -762,8 +742,6 @@ internal void UndoSelectedFile()
762 742
763 743 #region IVsUpdateSolutionEvents2 Members
764 744
765   - bool noRefresh = false;
766   -
767 745 public int OnActiveProjectCfgChange(IVsHierarchy pIVsHierarchy)
768 746 {
769 747 return VSConstants.S_OK;
@@ -912,6 +890,28 @@ private void SaveFileFromRepository(string fileName, string tempFile)
912 890 #endregion
913 891
914 892 #region new Refresh methods
  893 +
  894 + bool noRefresh = false;
  895 + bool NodesGlyphsDirty = false;
  896 +
  897 + internal void Refresh()
  898 + {
  899 + Debug.WriteLine("==== Refresh Nodes");
  900 + NodesGlyphsDirty = true;
  901 + }
  902 +
  903 + public void UpdateNodesGlyphs()
  904 + {
  905 + if (NodesGlyphsDirty)
  906 + {
  907 + noRefresh = true;
  908 + OpenTracker();
  909 + RefreshNodesGlyphs();
  910 + noRefresh = false;
  911 + }
  912 + NodesGlyphsDirty = false;
  913 + }
  914 +
915 915 public void RefreshNodesGlyphs()
916 916 {
917 917 var solHier = (IVsHierarchy)_sccProvider.GetService(typeof(SVsSolution));
@@ -921,14 +921,6 @@ public void RefreshNodesGlyphs()
921 921 // to reflect the controlled state
922 922 IList<VSITEMSELECTION> nodes = new List<VSITEMSELECTION>();
923 923
924   - {
925   - // add solution root item
926   - VSITEMSELECTION vsItem;
927   - vsItem.itemid = VSConstants.VSITEMID_ROOT;
928   - vsItem.pHier = solHier;// pHierarchy;
929   - nodes.Add(vsItem);
930   - }
931   -
932 924 // add project node items
933 925 foreach (IVsHierarchy hr in projectList)
934 926 {
@@ -955,9 +947,10 @@ public void RefreshNodesGlyphs()
955 947 public List<IVsSccProject2> GetLoadedControllableProjects()
956 948 {
957 949 var list = new List<IVsSccProject2>();
958   - // Hashtable mapHierarchies = new Hashtable();
959 950
960 951 IVsSolution sol = (IVsSolution) _sccProvider.GetService(typeof(SVsSolution));
  952 + list.Add(sol as IVsSccProject2);
  953 +
961 954 Guid rguidEnumOnlyThisType = new Guid();
962 955 IEnumHierarchies ppenum = null;
963 956 ErrorHandler.ThrowOnFailure(sol.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref rguidEnumOnlyThisType, out ppenum));
@@ -1077,5 +1070,6 @@ internal void InitRepo()
1077 1070 [Tt]est[Rr]esult*"
1078 1071 );
1079 1072 }
  1073 +
1080 1074 }
1081 1075 }
2  source.extension.vsixmanifest
@@ -3,7 +3,7 @@
3 3 <Identifier Id="C4128D99-2000-41D1-A6C3-704E6C1A3DE2">
4 4 <Name>Git Source Control Provider</Name>
5 5 <Author>Yiyisun@hotmail.com</Author>
6   - <Version>0.6.0</Version>
  6 + <Version>0.6.1</Version>
7 7 <Description xml:space="preserve">Git Source Control Provider is a plug-in that integrates git with Visual Studio.</Description>
8 8 <Locale>1033</Locale>
9 9 <License>License.txt</License>

0 comments on commit 6fd2eb1

Please sign in to comment.
Something went wrong with that request. Please try again.