diff options
author | Javier Suárez Ruiz <javiersuarezruiz@hotmail.com> | 2019-03-04 15:32:23 +0300 |
---|---|---|
committer | monojenkins <jo.shields+jenkins@xamarin.com> | 2019-03-08 11:21:13 +0300 |
commit | 177c098d4abe09abf043e3ec9a2bb380680e92f8 (patch) | |
tree | ffad581af72fab0048f73116ad179eb68727d73a /main | |
parent | 4c3e980b521eeb32e7bd03b32800600827846367 (diff) |
Add new VCS only if is not included and sorted
Diffstat (limited to 'main')
2 files changed, 52 insertions, 11 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlService.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlService.cs index 1b5c774e42..a6b82a5023 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlService.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlService.cs @@ -105,14 +105,20 @@ namespace MonoDevelop.VersionControl VersionControlSystem vcs; try { - vcs = (VersionControlSystem) args.ExtensionObject; + vcs = (VersionControlSystem)args.ExtensionObject; } catch (Exception e) { LoggingService.LogError ("Failed to initialize VersionControlSystem type.", e); return; } if (args.Change == ExtensionChange.Add) { - handlers.Add (vcs); + IComparer<VersionControlSystem> compare = new CompareVersionControlSystem (); + handlers.Sort (compare.Compare); + int search = handlers.BinarySearch (vcs, compare); + + if (search < 0) + handlers.Insert (~search, vcs); + try { // Include the repository type in the serialization context, so repositories // of this type can be deserialized from the configuration file. @@ -123,12 +129,9 @@ namespace MonoDevelop.VersionControl } catch (Exception e) { LoggingService.LogError ("Error while adding version control system.", e); } - } - else { + } else { handlers.Remove (vcs); } - - handlers = handlers.OrderBy (h => h.Name).ToList(); } public static Xwt.Drawing.Image LoadOverlayIconForStatus(VersionStatus status) diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlSystem.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlSystem.cs index feb396bcdf..5f46d8a233 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlSystem.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlSystem.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using MonoDevelop.Core; namespace MonoDevelop.VersionControl @@ -29,9 +30,9 @@ namespace MonoDevelop.VersionControl /// The default implementation returns the full name of the class. /// </remarks> public virtual string Id { - get { return GetType().ToString(); } + get { return GetType ().ToString (); } } - + /// <summary> /// Display name of the version control system /// </summary> @@ -55,12 +56,12 @@ namespace MonoDevelop.VersionControl public virtual bool IsInstalled { get { return false; } } - + /// <summary> /// Creates an instance of a repository for this version control system /// </summary> protected abstract Repository OnCreateRepositoryInstance (); - + /// <summary> /// Creates an editor object for a repository. /// </summary> @@ -70,7 +71,7 @@ namespace MonoDevelop.VersionControl /// <param name='repo'> /// A repository /// </param> - public abstract IRepositoryEditor CreateRepositoryEditor (Repository repo);
+ public abstract IRepositoryEditor CreateRepositoryEditor (Repository repo); /// <summary> /// Gets a repository for a given local path and identifier @@ -123,4 +124,41 @@ namespace MonoDevelop.VersionControl return remoteRelativePath.Replace ('/', System.IO.Path.DirectorySeparatorChar); } } + + public class CompareVersionControlSystem : IComparer<VersionControlSystem> + { + public int Compare (VersionControlSystem vcs1, VersionControlSystem vcs2) + { + int result; + + if (ReferenceEquals (vcs1, vcs2)) { + result = 0; + } else { + if (vcs1 == null) { + result = 1; + } else if (vcs2 == null) { + result = -1; + } else { + result = StringCompare (vcs1.Name, vcs2.Name); + } + } + + return result; + } + + int StringCompare (string strFirstString, string secondString) + { + int result; + if (strFirstString == null) { + if (secondString == null) { + result = 0; + } else { + result = 1; + } + } else { + result = string.Compare(strFirstString, secondString, StringComparison.InvariantCultureIgnoreCase); + } + return result; + } + } } |