Skip to content

Commit

Permalink
Optimized the loading of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
maikebing committed Mar 26, 2019
1 parent 2946842 commit 5675d94
Show file tree
Hide file tree
Showing 32 changed files with 263 additions and 253 deletions.
2 changes: 1 addition & 1 deletion GiteaApi
9 changes: 4 additions & 5 deletions src/Gitea.TeamFoundation.14/Colors.cs
Expand Up @@ -27,10 +27,9 @@ public static Color ToColor(this System.Drawing.Color color)
return Color.FromArgb(color.A, color.R, color.G, color.B);
}


static Color AccentMediumDarkTheme = Color.FromRgb(45, 45, 48);
static Color AccentMediumLightTheme = Color.FromRgb(238, 238, 242);
static Color AccentMediumBlueTheme = Color.FromRgb(255, 236, 181);
private static Color AccentMediumDarkTheme = Color.FromRgb(45, 45, 48);
private static Color AccentMediumLightTheme = Color.FromRgb(238, 238, 242);
private static Color AccentMediumBlueTheme = Color.FromRgb(255, 236, 181);

public static string DetectTheme()
{
Expand All @@ -55,4 +54,4 @@ public static string DetectTheme()
}
}
}
}
}
20 changes: 8 additions & 12 deletions src/Gitea.TeamFoundation.14/Connect/GiteaConnectSection.cs
Expand Up @@ -23,24 +23,23 @@ public class GiteaConnectSection : TeamExplorerSectionBase
private readonly ITeamExplorerServices _teamexplorer;
private readonly IViewFactory _viewFactory;
private readonly IWebService _web;

[ImportingConstructor]
public GiteaConnectSection(IMessenger messenger, IShellService shell, IStorage storage, ITeamExplorerServices teamexplorer, IViewFactory viewFactory, IWebService web)
public GiteaConnectSection(IMessenger messenger, IShellService shell, IStorage storage, ITeamExplorerServices teamexplorer, IViewFactory viewFactory, IWebService web)
{
_messenger = messenger;
_shell = shell;
_storage = storage;
_teamexplorer = teamexplorer;
_viewFactory = viewFactory;
_web = web;

messenger.Register("OnLoggedIn", OnLoggedIn);
messenger.Register("OnSignedOut", InLoggedOut);
messenger.Register<string, Repository>("OnClone", OnClone);
messenger.Register<string>("OnOpenSolution", OnOpenSolution);

}

protected override ITeamExplorerSection CreateViewModel(SectionInitializeEventArgs e)
{
var temp = new TeamExplorerSectionViewModelBase
Expand Down Expand Up @@ -75,6 +74,7 @@ protected override object CreateView(SectionInitializeEventArgs e)
{
return new ConnectSectionView();
}

protected override void InitializeView(SectionInitializeEventArgs e)
{
var view = this.SectionContent as FrameworkElement;
Expand Down Expand Up @@ -117,22 +117,18 @@ public void OnOpenSolution(string path)
return;
}
}

x.OpenSolutionViaDlg(path, 1);
}
}


public override void Refresh()
{

((View as ConnectSectionView).DataContext as ConnectSectionViewModel).Refresh();

base.Refresh();
}



public override void Dispose()
{
_messenger.UnRegister(this);
Expand All @@ -145,4 +141,4 @@ public override void Dispose()
GC.SuppressFinalize(this);
}
}
}
}
23 changes: 19 additions & 4 deletions src/Gitea.TeamFoundation.14/Connect/GiteaInvitationSection.cs
@@ -1,9 +1,11 @@
using Gitea.VisualStudio.Shared;
using Gitea.VisualStudio.Shared.Helpers;
using Microsoft.TeamFoundation.Controls;
using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer;
using System;
using System.ComponentModel.Composition;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
Expand Down Expand Up @@ -35,10 +37,10 @@ public GiteaInvitationSection(IMessenger messenger, IShellService shell, IStorag
ConnectLabel = Strings.Invitation_Connect;
SignUpLabel = Strings.Invitation_SignUp;
Name = Strings.Name;
Provider = Strings.Provider+ (storage.IsLogined?"(" +storage.Host+")": Strings.GiteaInvitationSection_GiteaInvitationSection_NoLogin);
Provider = Strings.Provider + (storage.IsLogined ? "(" + storage.Host + ")" : Strings.GiteaInvitationSection_GiteaInvitationSection_NoLogin);
Description = Strings.Description;
var assembly = Assembly.GetExecutingAssembly().GetName().Name;
var image = new BitmapImage(new Uri($"pack://application:,,,/{assembly};component/Resources/logo.png", UriKind.Absolute));;
var image = new BitmapImage(new Uri($"pack://application:,,,/{assembly};component/Resources/logo.png", UriKind.Absolute)); ;

var drawing = new DrawingGroup();
drawing.Children.Add(new GeometryDrawing
Expand All @@ -49,7 +51,20 @@ public GiteaInvitationSection(IMessenger messenger, IShellService shell, IStorag

Icon = new DrawingBrush(drawing);

IsVisible = !storage.IsLogined;
var gitExt = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService<Microsoft.VisualStudio.TeamFoundation.Git.Extensibility.IGitExt>();
gitExt.PropertyChanged += GitExt_PropertyChanged;
}

private void GitExt_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "ActiveRepositories")
{
Task.Run(async () =>
{
await ThreadingHelper.SwitchToMainThreadAsync();
IsVisible = !_storage.IsLogined;
});
}
}

public override void Connect()
Expand Down Expand Up @@ -81,4 +96,4 @@ public override void Dispose()
GC.SuppressFinalize(this);
}
}
}
}
3 changes: 1 addition & 2 deletions src/Gitea.TeamFoundation.14/Gitea.TeamFoundation.14.csproj
Expand Up @@ -69,8 +69,7 @@
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.TeamFoundation.Git.Provider">
<HintPath>..\..\lib\14.0\Microsoft.TeamFoundation.Git.Provider.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\Gitee.VisualStudio\lib\14.0\Microsoft.TeamFoundation.Git.Provider.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Imaging, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.VisualStudio.Imaging.14.3.25407\lib\net45\Microsoft.VisualStudio.Imaging.dll</HintPath>
Expand Down
3 changes: 1 addition & 2 deletions src/Gitea.TeamFoundation.14/Home/ActivityNavigationItem.cs
Expand Up @@ -32,5 +32,4 @@ public override void Execute()
OpenInBrowser("activity");
}
}
}

}
24 changes: 19 additions & 5 deletions src/Gitea.TeamFoundation.14/Home/GiteaHomeSection.cs
Expand Up @@ -4,6 +4,7 @@
using Microsoft.TeamFoundation.Controls;
using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

Expand All @@ -25,14 +26,29 @@ public override void Initialize(object sender, SectionInitializeEventArgs e)
{
IsVisible = false;
base.Initialize(sender, e);
var gitExt = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService<Microsoft.VisualStudio.TeamFoundation.Git.Extensibility.IGitExt>();
gitExt.PropertyChanged += GitExt_PropertyChanged;
}

private void GitExt_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "ActiveRepositories")
{
Task.Run(async () =>
{
await ThreadingHelper.SwitchToMainThreadAsync();
Refresh();
});
}
}

public override async void Refresh()
{
IsVisible = await _tes.IsGiteaRepoAsync() ;
IsVisible = await _tes.IsGiteaRepoAsync();
var view = (this.View as TextBlock);
if (view != null)
{
view.Text =( _tes.Project != null && !string.IsNullOrEmpty(_tes.Project.Description) )? _tes.Project.Description : Strings.Description;
view.Text = (_tes.Project != null && !string.IsNullOrEmpty(_tes.Project.Description)) ? _tes.Project.Description : Strings.Description;
}
base.Refresh();
}
Expand All @@ -41,18 +57,16 @@ protected override ITeamExplorerSection CreateViewModel(SectionInitializeEventAr
{
var temp = new TeamExplorerSectionViewModelBase();
temp.Title = Strings.Name;

return temp;
}

protected override object CreateView(SectionInitializeEventArgs e)
{
return new TextBlock
{
Text = (_tes.Project != null && !string.IsNullOrEmpty(_tes.Project.Description)) ? _tes.Project.Description : Strings.Description,
Text = (_tes.Project != null && !string.IsNullOrEmpty(_tes.Project.Description)) ? _tes.Project.Description : Strings.Description,
TextWrapping = System.Windows.TextWrapping.Wrap
};
}

}
}
31 changes: 26 additions & 5 deletions src/Gitea.TeamFoundation.14/Home/GiteaNavigationItem.cs
@@ -1,10 +1,13 @@
using Gitea.VisualStudio.Shared;
using Gitea.VisualStudio.Shared.Controls;
using Gitea.VisualStudio.Shared.Helpers;
using Microsoft.TeamFoundation.Controls;
using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer;
using Microsoft.VisualStudio.PlatformUI;
using System;
using System.Threading.Tasks;
using System.Windows.Media;

namespace Gitea.TeamFoundation.Home
{
public abstract class GiteaNavigationItem : TeamExplorerNavigationItemBase, ITeamExplorerNavigationItem2
Expand All @@ -18,6 +21,7 @@ public abstract class GiteaNavigationItem : TeamExplorerNavigationItemBase, ITea
private Project _project;
private string _branch;
private Octicon octicon;

public GiteaNavigationItem(Octicon icon, IGitService git, IShellService shell, IStorage storage, ITeamExplorerServices tes, IWebService web)
{
_git = git;
Expand All @@ -27,36 +31,53 @@ public GiteaNavigationItem(Octicon icon, IGitService git, IShellService shell, I
_web = web;
octicon = icon;
var brush = new SolidColorBrush(Color.FromRgb(66, 66, 66));

brush.Freeze();
OnThemeChanged();
VSColorTheme.ThemeChanged += _ =>
{
OnThemeChanged();
Invalidate();
};
var gitExt = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService<Microsoft.VisualStudio.TeamFoundation.Git.Extensibility.IGitExt>();
gitExt.PropertyChanged += GitExt_PropertyChanged;
}

private void GitExt_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "ActiveRepositories")
{
Task.Run(async () =>
{
await ThreadingHelper.SwitchToMainThreadAsync();
Invalidate();
});
}
}

public override async void Invalidate()
{
IsVisible = false;
IsVisible = await _tes.IsGiteaRepoAsync() && _tes.Project != null;
IsVisible = await _tes.IsGiteaRepoAsync() && _tes.Project != null;
}
void OnThemeChanged()

private void OnThemeChanged()
{
var theme = Colors.DetectTheme();
var dark = theme == "Dark";
m_defaultArgbColorBrush = new SolidColorBrush(dark ? Colors.DarkThemeNavigationItem : Colors.LightBlueNavigationItem);
m_defaultArgbColorBrush = new SolidColorBrush(dark ? Colors.DarkThemeNavigationItem : Colors.LightBlueNavigationItem);
m_icon = SharedResources.GetDrawingForIcon(octicon, dark ? Colors.DarkThemeNavigationItem : Colors.LightThemeNavigationItem, theme);
}

protected void OpenInBrowser(string endpoint)
{
var url = $"{_tes.Project.WebUrl}/{endpoint}";
_shell.OpenUrl(url);
}

protected void OpenHostUrlInBrowser(string endpoint)
{
var url = $"{_storage.Host}/{endpoint}";
_shell.OpenUrl(url);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Gitea.TeamFoundation.14/Home/IssuesNavigationItem.cs
Expand Up @@ -18,8 +18,8 @@ public IssuesNavigationItem(IGitService git, IShellService shell, IStorage stora
{
_tes = tes;
Text = Strings.Items_Issues;

}

public override void Invalidate()
{
base.Invalidate();
Expand All @@ -31,4 +31,4 @@ public override void Execute()
OpenInBrowser("issues");
}
}
}
}
Expand Up @@ -27,9 +27,10 @@ public override void Invalidate()

IsVisible = IsVisible && _tes.Project != null && _tes.Project.MergeRequestsEnabled;
}

public override void Execute()
{
OpenInBrowser("pulls");
}
}
}
}
5 changes: 2 additions & 3 deletions src/Gitea.TeamFoundation.14/Home/ReleasesNavigationItem.cs
Expand Up @@ -24,13 +24,12 @@ public ReleasesNavigationItem(IGitService git, IShellService shell, IStorage sto
public override void Invalidate()
{
base.Invalidate();
IsVisible = IsVisible && _tes.Project != null ;
IsVisible = IsVisible && _tes.Project != null;
}

public override void Execute()
{
OpenInBrowser("releases");
}
}
}

}
3 changes: 1 addition & 2 deletions src/Gitea.TeamFoundation.14/Home/WikiNavigationItem.cs
Expand Up @@ -32,5 +32,4 @@ public override void Execute()
OpenInBrowser("wiki");
}
}
}

}
1 change: 0 additions & 1 deletion src/Gitea.TeamFoundation.14/Properties/AssemblyInfo.cs
@@ -1,6 +1,5 @@
using System.Reflection;
using System.Runtime.InteropServices;


[assembly: AssemblyDescription("Gitea TeamFoundation")]
[assembly: Guid("b389adaf-62cc-486e-85b4-2d8b078df763")]
7 changes: 4 additions & 3 deletions src/Gitea.TeamFoundation.14/Services/Registry.cs
Expand Up @@ -7,9 +7,10 @@

namespace Gitea.TeamFoundation.Services
{
public partial class Registry
public partial class Registry
{
static string tfver = null;
private static string tfver = null;

private static RegistryKey OpenGitKey(string path)
{
if (tfver == null)
Expand Down Expand Up @@ -56,4 +57,4 @@ public static IReadOnlyList<Repository> GetKnownRepositories()
}
}
}
}
}

0 comments on commit 5675d94

Please sign in to comment.