diff --git a/RockDevBooster/Views/GitHubVersions.xaml b/RockDevBooster/Views/GitHubVersions.xaml
index 6294b84..844ec6e 100644
--- a/RockDevBooster/Views/GitHubVersions.xaml
+++ b/RockDevBooster/Views/GitHubVersions.xaml
@@ -10,20 +10,40 @@
-
+
+
+
/// Interaction logic for GitHubVersions.xaml
///
- public partial class GitHubVersions : UserControl
+ public partial class GitHubVersions : UserControl, IViewDidShow
{
#region Protected Properties
@@ -23,6 +23,10 @@ public partial class GitHubVersions : UserControl
///
protected ReleaseBuilder ReleaseBuilder { get; set; }
+ protected List GitHubTags { get; set; }
+
+ protected List GitHubBranches { get; set; }
+
#endregion
#region Constructors
@@ -38,8 +42,6 @@ public GitHubVersions()
{
txtStatus.Text = "Loading...";
btnImport.IsEnabled = false;
-
- new Task( LoadData ).Start();
}
}
@@ -52,8 +54,39 @@ public GitHubVersions()
///
protected void UpdateState()
{
- var tags = cbTags.ItemsSource as List;
- btnImport.IsEnabled = cbTags.SelectedIndex != -1 && !string.IsNullOrEmpty( tags[cbTags.SelectedIndex].Name );
+ if ( cbSourceType.Text == "Release Version" )
+ {
+ var tags = cbSource.ItemsSource as List;
+ int index = cbSource.SelectedIndex;
+
+ btnImport.IsEnabled = index != -1 && !string.IsNullOrEmpty( tags[index].Name );
+ }
+ else if ( cbSourceType.Text == "Branch" )
+ {
+ var branches = cbSource.ItemsSource as List;
+ int index = cbSource.SelectedIndex;
+
+ btnImport.IsEnabled = index != -1 && !string.IsNullOrEmpty( branches[index].Name );
+ }
+ else if ( cbSourceType.Text == "SHA-1 Commit" )
+ {
+ btnImport.IsEnabled = !string.IsNullOrWhiteSpace( txtSource.Text );
+ }
+ }
+
+ #endregion
+
+ #region Methods
+
+ ///
+ /// The view has become visible on screen.
+ ///
+ public void ViewDidShow()
+ {
+ if ( GitHubTags == null )
+ {
+ new Task( LoadData ).Start();
+ }
}
#endregion
@@ -67,28 +100,38 @@ private async void LoadData()
{
var client = new GitHubClient( new ProductHeaderValue( "RockDevBooster" ) );
var tags = client.Repository.GetAllTags( "SparkDevNetwork", "Rock" );
+ var branches = client.Repository.Branch.GetAll( "SparkDevNetwork", "Rock" );
var minimumVersion = new Version( 1, 1, 0 );
- List list;
try
{
- list = ( await tags )
- .Select( t => new GitHubTag( t ) )
+ GitHubTags = ( await tags )
+ .Select( t => new GitHubItem( t ) )
.Where( t => t.Version >= minimumVersion )
.OrderByDescending( t => t.Version )
.ToList();
+
+ GitHubBranches = ( await branches )
+ .Select( b => new GitHubItem( b ) )
+ .OrderBy( b => b.Name )
+ .ToList();
}
catch
{
- list = new List();
+ GitHubTags = new List();
+ GitHubBranches = new List();
}
- list.Insert( 0, new GitHubTag() );
+ GitHubTags.Insert( 0, new GitHubItem() );
+ GitHubBranches.Insert( 0, new GitHubItem() );
Dispatcher.Invoke( () =>
{
- cbTags.ItemsSource = list;
- txtStatus.Text = string.Empty;
- cbTags.SelectedIndex = 0;
+ cbSourceType.Items.Add( "Release Version" );
+ cbSourceType.Items.Add( "Branch" );
+ cbSourceType.Items.Add( "SHA-1 Commit" );
+ cbSourceType.SelectedIndex = 0;
+
+ txtStatus.Text = "Ready";
} );
}
@@ -103,14 +146,27 @@ private async void LoadData()
/// The event arguments.
private void btnImport_Click( object sender, RoutedEventArgs e )
{
- var tags = cbTags.ItemsSource as List;
- var tag = tags[cbTags.SelectedIndex];
var vs = VisualStudioInstall.GetDefaultInstall();
+ GitHubItem item;
+
+ if ( cbSourceType.SelectedItem.ToString() == "Release Version" || cbSourceType.SelectedItem.ToString() == "Branch" )
+ {
+ var items = cbSource.ItemsSource as List;
+ item = items[cbSource.SelectedIndex];
+ }
+ else
+ {
+ item = new GitHubItem
+ {
+ Name = txtSource.Text.ToLowerInvariant(),
+ ZipballUrl = string.Format( "https://github.com/SparkDevNetwork/Rock/archive/{0}.zip", txtSource.Text.ToLowerInvariant() )
+ };
+ }
//
// Check if this template already exists.
//
- var templateName = "RockBase-" + tag.Name;
+ var templateName = "RockBase-" + item.Name;
if ( File.Exists( Path.Combine( Support.GetTemplatesPath(), templateName + ".zip" ) ) )
{
MessageBox.Show( "A template with the name " + templateName + " already exists.", "Cannot import", MessageBoxButton.OK, MessageBoxImage.Hand );
@@ -136,7 +192,7 @@ private void btnImport_Click( object sender, RoutedEventArgs e )
//
new Task( () =>
{
- ReleaseBuilder.DownloadRelease( tag.ZipballUrl, vs.GetExecutable(), "RockBase-" + tag.Name );
+ ReleaseBuilder.DownloadRelease( item.ZipballUrl, vs.GetExecutable(), "RockBase-" + item.Name );
} ).Start();
}
@@ -191,6 +247,41 @@ private void ReleaseBuilder_StatusTextChanged( object sender, string text )
} );
}
+ ///
+ /// Handles the SelectionChanged event of the cbSourceType control.
+ ///
+ /// The source of the event.
+ /// The instance containing the event data.
+ private void cbSourceType_SelectionChanged( object sender, SelectionChangedEventArgs e )
+ {
+ if ( cbSourceType.SelectedItem.ToString() == "Release Version" )
+ {
+ lSource.Content = "Version";
+ txtSource.Visibility = Visibility.Hidden;
+
+ cbSource.ItemsSource = GitHubTags;
+ cbSource.SelectedIndex = 0;
+ cbSource.Visibility = Visibility.Visible;
+ }
+ else if ( cbSourceType.SelectedItem.ToString() == "Branch" )
+ {
+ lSource.Content = "Branch";
+ txtSource.Visibility = Visibility.Hidden;
+
+ cbSource.ItemsSource = GitHubBranches;
+ cbSource.SelectedIndex = 0;
+ cbSource.Visibility = Visibility.Visible;
+ }
+ else if ( cbSourceType.SelectedItem.ToString() == "SHA-1 Commit" )
+ {
+ lSource.Content = "Commit";
+ txtSource.Visibility = Visibility.Visible;
+ cbSource.Visibility = Visibility.Hidden;
+ }
+
+ UpdateState();
+ }
+
#endregion
#region Classes
@@ -198,7 +289,7 @@ private void ReleaseBuilder_StatusTextChanged( object sender, string text )
///
/// Helper class to identify a GutHub Tag Release.
///
- protected class GitHubTag
+ protected class GitHubItem
{
public string Name { get; set; }
@@ -206,11 +297,11 @@ protected class GitHubTag
public Version Version { get; set; }
- public GitHubTag()
+ public GitHubItem()
{
}
- public GitHubTag( RepositoryTag tag )
+ public GitHubItem( RepositoryTag tag )
{
Name = tag.Name;
ZipballUrl = tag.ZipballUrl;
@@ -223,6 +314,13 @@ public GitHubTag( RepositoryTag tag )
Version = v;
}
+ public GitHubItem( Branch branch )
+ {
+ Name = branch.Name;
+ ZipballUrl = string.Format( "https://github.com/SparkDevNetwork/Rock/archive/{0}.zip", branch.Name );
+ Version = new Version();
+ }
+
public override string ToString()
{
return Name ?? string.Empty;