History.cs (1805B)
1 using System.Collections.Specialized; 2 using System.Linq; 3 4 namespace SilkypixFileMover.Objects 5 { 6 internal class History 7 { 8 // speichert die Einträge 9 private string[] history; 10 11 // max. Länge des 12 private int size; 13 14 /// <summary> 15 /// Liefert die History-Einträge als SpecializedStringCollection für die Settings 16 /// </summary> 17 public StringCollection EntrysAsSpecializedStringCollection 18 { 19 get 20 { 21 StringCollection collection = new StringCollection(); 22 collection.AddRange( history ); 23 24 return collection; 25 } 26 27 set 28 { 29 history = value.Cast<string>().ToArray(); 30 } 31 } 32 33 // Die Einträge 34 internal string[] Entrys 35 { 36 get 37 { 38 return history; 39 } 40 } 41 42 internal History( int MaxSize ) 43 { 44 history = new string[ MaxSize ]; 45 size = MaxSize; 46 } 47 48 internal History( int MaxSize, string[] HistoryEntrys ) 49 { 50 history = new string[ MaxSize ]; 51 size = MaxSize; 52 53 HistoryEntrys.CopyTo( history, 0 ); 54 } 55 56 internal void Add( string entry ) 57 { 58 if ( string.IsNullOrEmpty( entry ) ) 59 { 60 return; 61 } 62 63 if ( history.Contains( entry ) ) 64 { 65 return; 66 } 67 68 // Objekte eins nach hinten schieben 69 for ( int i = ( size - 1 ); i > 0; i-- ) 70 { 71 history[ i ] = history[ i - 1 ]; 72 } 73 74 // aktuelles Objekt einfügen 75 history[ 0 ] = entry; 76 } 77 } 78 }