History.cs

Description du code

History.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace be.gaudry.model
  5. {
  6. public class History<T>
  7. {
  8. #region constructor and declarations
  9. private Stack<T> items, redoItems;
  10. private int capacity;
  11.  
  12. public History()
  13. {
  14. setStacks(20);
  15. }
  16. public History(int capacity)
  17. {
  18. setStacks(capacity);
  19. }
  20. public History(T startItem, int capacity):this(capacity)
  21. {
  22. go(startItem, true);
  23. }
  24. private void setStacks(int capacity)
  25. {
  26. this.capacity = capacity;
  27. items = new Stack<T>(capacity);
  28. redoItems = new Stack<T>(capacity);
  29. }
  30. #endregion
  31.  
  32. #region misc properties and methods
  33. /// <summary>
  34. /// Capacity of the history.
  35. /// </summary>
  36. public int Capacity
  37. {
  38. get { return capacity; }
  39. }
  40. /// <summary>
  41. /// Number of items in the history.
  42. /// </summary>
  43. public int Count
  44. {
  45. get { return items.Count + redoItems.Count; }
  46. }
  47. /// <summary>
  48. /// Number of items in the redo history.
  49. /// </summary>
  50. public int RedoCount
  51. {
  52. get { return redoItems.Count; }
  53. }
  54. /// <summary>
  55. /// Number of items in the undo history.
  56. /// </summary>
  57. public int UndoCount
  58. {
  59. get { return items.Count; }
  60. }
  61. /// <summary>
  62. /// True if there is more than one item in the history
  63. /// </summary>
  64. public bool UndoEnabled
  65. {
  66. get { return items.Count>1; }
  67. }
  68. /// <summary>
  69. /// True if there is at least one item in the redo history
  70. /// </summary>
  71. public bool RedoEnabled
  72. {
  73. get { return redoItems.Count > 0; }
  74. }
  75. /// <summary>
  76. /// Free space in the history.
  77. /// </summary>
  78. public int FreeCount
  79. {
  80. get { return capacity - items.Count; }
  81. }
  82. /// <summary>
  83. /// Clear the history but keep the first item
  84. /// </summary>
  85. public void clear()
  86. {
  87. items.Clear();
  88. }
  89.  
  90.  
  91. #endregion
  92.  
  93. #region navigation properties and methods
  94. /// <summary>
  95. /// Current item in the navigation history.
  96. /// Returns default value if no item found
  97. /// </summary>
  98. public T Current
  99. {
  100. get
  101. {
  102. try
  103. {
  104. return items.Peek();
  105. }
  106. catch (Exception)
  107. {
  108. return default(T);
  109. }
  110. }
  111. }
  112. /// <summary>
  113. /// Add an item in the history.
  114. /// Reset redo.
  115. /// </summary>
  116. /// <param name="item">Item to put on the history</param>
  117. /// <param name="toClone">
  118. /// if ref type and set to true, do not clone the value.
  119. /// In this case, be carefull : referenced object is not maintained
  120. ///
  121. /// If val type, this parameter has no effect
  122. /// </param>
  123. /// <exception cref="NotSupportedException">Throwed if bypassClone is false, and item is a ref type not clonable</exception>
  124. public void go(T item, bool bypassClone)
  125. {
  126. if (!bypassClone && default(T) == null)
  127. {
  128. if (item is ICloneable)
  129. {
  130. item = (T)((ICloneable)item).Clone();
  131. }
  132. else
  133. throw new NotSupportedException(String.Format("{0} not cloneable",item.ToString()));
  134. }
  135. items.Push(item);
  136. if(redoItems.Count>0)
  137. redoItems.Clear();
  138. //System.Console.WriteLine(String.Format("Go : {0}/{1} [{2}]", items.Count, redoItems.Count, item));
  139. }
  140. /// <summary>
  141. /// Add an item in the history.
  142. /// Reset redo.
  143. /// </summary>
  144. /// <param name="item">Item to put on the history</param>
  145. /// <exception cref="NotSupportedException">Throwed if item is a ref type not clonable</exception>
  146. public void go(T item)
  147. {
  148. if (default(T) == null)
  149. {
  150. if (item is ICloneable)
  151. {
  152. item = (T)((ICloneable)item).Clone();
  153. }
  154. else
  155. throw new NotSupportedException(String.Format("{0} not cloneable", item.ToString()));
  156. }
  157. items.Push(item);
  158. if (redoItems.Count > 0)
  159. redoItems.Clear();
  160. //System.Console.WriteLine(String.Format("Go : {0}/{1} [{2}]", items.Count, redoItems.Count, item));
  161. }
  162. /// <summary>
  163. /// Previous item in the navigation history.
  164. /// </summary>
  165. /// <exception cref="System.InvalidOperationException">if no more items exists before current</exception>
  166. public T Undo
  167. {
  168. get
  169. {
  170. redoItems.Push(items.Pop());
  171. //System.Console.WriteLine(String.Format("Undo : {0}/{1}", items.Count, redoItems.Count));
  172. return items.Peek();
  173. }
  174. }
  175. /// <summary>
  176. /// Previous item in the navigation history.
  177. /// Return null (or default value) if no more items exists before current
  178. /// </summary>
  179. public T UndoSafe
  180. {
  181. get
  182. {
  183. try
  184. {
  185. redoItems.Push(items.Pop());
  186. return items.Peek();
  187. }
  188. catch (Exception)
  189. {
  190. return default(T);
  191. }
  192. }
  193. }
  194. /// <summary>
  195. /// Redo item in the navigation history.
  196. /// </summary>
  197. /// <exception cref="System.InvalidOperationException">if no more items exists after current</exception>
  198. public T Redo
  199. {
  200. get
  201. {
  202. items.Push(redoItems.Pop());
  203. //System.Console.WriteLine(String.Format("Redo : {0}/{1}", items.Count, redoItems.Count));
  204. return items.Peek();
  205. }
  206. }
  207. /// <summary>
  208. /// Redo item in the navigation history.
  209. /// Return null (or default value) if no more items exists after current
  210. /// </summary>
  211. public T RedoSafe
  212. {
  213. get
  214. {
  215. try
  216. {
  217. items.Push(redoItems.Pop());
  218. return items.Peek();
  219. }
  220. catch (Exception)
  221. {
  222. return default(T);
  223. }
  224. }
  225. }
  226. #endregion
  227. }
  228. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1711698921 29/03/2024 08:55:21
| _config0 octets1541007188 31/10/2018 18:33:08
| _enums0 octets1541007189 31/10/2018 18:33:09
| _exceptions0 octets1541007189 31/10/2018 18:33:09
| _drawing0 octets1541007188 31/10/2018 18:33:08
| _win320 octets1541007190 31/10/2018 18:33:10
| _file0 octets1541007190 31/10/2018 18:33:10
| _comparators0 octets1541007188 31/10/2018 18:33:08
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csWebHelper.cs841 octets31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csHistory.cs6.96 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csValueObject.cs664 octets31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csExport.cs13.3 Ko31/10/2018 18:32:47-refusé-
Afficher le fichier .cs|.csDisposableObject.cs883 octets31/10/2018 18:32:47-refusé-
Afficher le fichier .cs|.csStat.cs3.63 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csTextHelper.cs8.11 Ko31/10/2018 18:32:48-refusé-
Afficher le fichier .cs|.csUnits.cs2.07 Ko31/10/2018 18:32:48-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Document créé le 16/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-broldev-source-rf-model/History.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.