From 91625df1a362429ccc9c91a6b95de0b44c4da0a6 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 23 Jul 2010 00:50:40 +0100 Subject: [PATCH] Use a List instead of an Array for the repositories --- SparkleShare/SparkleStatusIcon.cs | 4 +-- SparkleShare/SparkleUI.cs | 42 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index e7849167..6e10534f 100644 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -97,8 +97,7 @@ namespace SparkleShare { }; Menu.Add (FolderAction.CreateMenuItem ()); - Gtk.Action [] FolderItems = - new Gtk.Action [SparkleUI.Repositories.Length]; + Gtk.Action [] FolderItems = new Gtk.Action [SparkleUI.Repositories.Count]; int i = 0; foreach (SparkleRepo SparkleRepo in SparkleUI.Repositories) { @@ -202,7 +201,6 @@ namespace SparkleShare { } // Changes the status icon to the syncing animation - // TODO: There are UI freezes when switching back and forth // bewteen syncing and idle state public void SetSyncingState () { diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index 76f6bd72..6382ff4e 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -19,6 +19,7 @@ using Mono.Unix; using Mono.Unix.Native; using SparkleShare; using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -27,7 +28,7 @@ namespace SparkleShare { public class SparkleUI { private Process Process; - public static SparkleRepo [] Repositories; + public static List Repositories; // Short alias for the translations public static string _(string s) @@ -40,6 +41,8 @@ namespace SparkleShare { public SparkleUI (bool HideUI) { + Repositories = new List (); + Process = new Process (); Process.EnableRaisingEvents = true; Process.StartInfo.RedirectStandardOutput = true; @@ -65,7 +68,7 @@ namespace SparkleShare { NotificationIcon = new SparkleStatusIcon (); // Show a notification if there are no folders yet - if (Repositories.Length == 0) { + if (Repositories.Count == 0) { SparkleBubble NoFoldersBubble; NoFoldersBubble = new SparkleBubble (_("Welcome to SparkleShare!"), @@ -240,7 +243,9 @@ namespace SparkleShare { public void ShowNewCommitBubble (object o, SparkleEventArgs args) { - Console.WriteLine ("AAAAAAAAAAAAAAAAAA"); + + // Show bubble + } @@ -259,37 +264,32 @@ namespace SparkleShare { } - // TODO: Make this a List instead of an array + // Updates the list of repositories with all the + // folders in the SparkleShare folder public void UpdateRepositories () { - string SparklePath = SparklePaths.SparklePath; - // Get all the repos in ~/SparkleShare - SparkleRepo [] TmpRepos = new SparkleRepo [Directory.GetDirectories (SparklePath).Length]; - - int FolderCount = 0; - foreach (string folder in Directory.GetDirectories (SparklePath)) { + Repositories = new List (); + + foreach (string folder in Directory.GetDirectories (SparklePaths.SparklePath)) { // Check if the folder is a git repo if (Directory.Exists (SparkleHelpers.CombineMore (folder, ".git"))) { - TmpRepos [FolderCount] = new SparkleRepo (folder); - TmpRepos [FolderCount].NewCommit += ShowNewCommitBubble; - TmpRepos [FolderCount].FetchingStarted += UpdateStatusIcon; - TmpRepos [FolderCount].FetchingFinished += UpdateStatusIcon; - FolderCount++; + SparkleRepo repo = new SparkleRepo (folder); + + repo.NewCommit += ShowNewCommitBubble; + repo.FetchingStarted += UpdateStatusIcon; + repo.FetchingFinished += UpdateStatusIcon; + + Repositories.Add (repo); } } - - Repositories = new SparkleRepo [FolderCount]; - Array.Copy (TmpRepos, Repositories, FolderCount); - + } } -} - }