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
Code c# (History.cs) (228 lignes)
using System; using System.Collections.Generic; namespace be.gaudry.model { public class History<T> { #region constructor and declarations private Stack<T> items, redoItems; private int capacity; public History() { setStacks(20); } public History(int capacity) { setStacks(capacity); } public History(T startItem, int capacity):this(capacity) { go(startItem, true); } private void setStacks(int capacity) { this.capacity = capacity; } #endregion #region misc properties and methods /// <summary> /// Capacity of the history. /// </summary> public int Capacity { get { return capacity; } } /// <summary> /// Number of items in the history. /// </summary> public int Count { get { return items.Count + redoItems.Count; } } /// <summary> /// Number of items in the redo history. /// </summary> public int RedoCount { get { return redoItems.Count; } } /// <summary> /// Number of items in the undo history. /// </summary> public int UndoCount { get { return items.Count; } } /// <summary> /// True if there is more than one item in the history /// </summary> public bool UndoEnabled { get { return items.Count>1; } } /// <summary> /// True if there is at least one item in the redo history /// </summary> public bool RedoEnabled { get { return redoItems.Count > 0; } } /// <summary> /// Free space in the history. /// </summary> public int FreeCount { get { return capacity - items.Count; } } /// <summary> /// Clear the history but keep the first item /// </summary> public void clear() { items.Clear(); } #endregion #region navigation properties and methods /// <summary> /// Current item in the navigation history. /// Returns default value if no item found /// </summary> public T Current { get { try { return items.Peek(); } catch (Exception) { return default(T); } } } /// <summary> /// Add an item in the history. /// Reset redo. /// </summary> /// <param name="item">Item to put on the history</param> /// <param name="toClone"> /// if ref type and set to true, do not clone the value. /// In this case, be carefull : referenced object is not maintained /// /// If val type, this parameter has no effect /// </param> /// <exception cref="NotSupportedException">Throwed if bypassClone is false, and item is a ref type not clonable</exception> public void go(T item, bool bypassClone) { if (!bypassClone && default(T) == null) { { item = (T)((ICloneable)item).Clone(); } else } items.Push(item); if(redoItems.Count>0) redoItems.Clear(); //System.Console.WriteLine(String.Format("Go : {0}/{1} [{2}]", items.Count, redoItems.Count, item)); } /// <summary> /// Add an item in the history. /// Reset redo. /// </summary> /// <param name="item">Item to put on the history</param> /// <exception cref="NotSupportedException">Throwed if item is a ref type not clonable</exception> public void go(T item) { if (default(T) == null) { { item = (T)((ICloneable)item).Clone(); } else } items.Push(item); if (redoItems.Count > 0) redoItems.Clear(); //System.Console.WriteLine(String.Format("Go : {0}/{1} [{2}]", items.Count, redoItems.Count, item)); } /// <summary> /// Previous item in the navigation history. /// </summary> /// <exception cref="System.InvalidOperationException">if no more items exists before current</exception> public T Undo { get { redoItems.Push(items.Pop()); //System.Console.WriteLine(String.Format("Undo : {0}/{1}", items.Count, redoItems.Count)); return items.Peek(); } } /// <summary> /// Previous item in the navigation history. /// Return null (or default value) if no more items exists before current /// </summary> public T UndoSafe { get { try { redoItems.Push(items.Pop()); return items.Peek(); } catch (Exception) { return default(T); } } } /// <summary> /// Redo item in the navigation history. /// </summary> /// <exception cref="System.InvalidOperationException">if no more items exists after current</exception> public T Redo { get { items.Push(redoItems.Pop()); //System.Console.WriteLine(String.Format("Redo : {0}/{1}", items.Count, redoItems.Count)); return items.Peek(); } } /// <summary> /// Redo item in the navigation history. /// Return null (or default value) if no more items exists after current /// </summary> public T RedoSafe { get { try { items.Push(redoItems.Pop()); return items.Peek(); } catch (Exception) { return default(T); } } } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732653766 26/11/2024 21:42:46 |
| _ | config | 0 octets | 1541007188 31/10/2018 18:33:08 |
| _ | enums | 0 octets | 1541007189 31/10/2018 18:33:09 |
| _ | exceptions | 0 octets | 1541007189 31/10/2018 18:33:09 |
| _ | drawing | 0 octets | 1541007188 31/10/2018 18:33:08 |
| _ | win32 | 0 octets | 1541007190 31/10/2018 18:33:10 |
| _ | file | 0 octets | 1541007190 31/10/2018 18:33:10 |
| _ | comparators | 0 octets | 1541007188 31/10/2018 18:33:08 |
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.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-broldev-source-rf-model//History.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.