Changeset 3483


Ignore:
Timestamp:
04/22/10 05:14:39 (12 years ago)
Author:
swagner
Message:

Worked on the refactoring of saving and loading items (#990)

Location:
trunk/sources
Files:
1 added
2 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.2/Content/ContentManager.cs

    r3437 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading;
    2723
    2824namespace HeuristicLab.Common {
    2925  public abstract class ContentManager {
    30     protected ContentManager() {
     26    private static ContentManager instance;
     27
     28    public static void Initialize(ContentManager manager) {
     29      if (manager == null) throw new ArgumentNullException();
     30      if (ContentManager.instance != null) throw new InvalidOperationException("ContentManager has already been initialized.");
     31      ContentManager.instance = manager;
    3132    }
    3233
    33     private static ContentManager instance;
    34     public static ContentManager Instance {
    35       get { return instance; }
     34    protected ContentManager() { }
     35
     36    public static IStorableContent Load(string filename) {
     37      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     38      IStorableContent content = instance.LoadContent(filename);
     39      content.Filename = filename;
     40      return content;
    3641    }
    37     public static void CreateInstance<T>() where T : ContentManager {
    38       if (instance != null)
    39         throw new InvalidOperationException("ContentManager was already created.");
    40       instance = Activator.CreateInstance<T>();
     42    public static void LoadAsync(string filename, Action<IStorableContent, Exception> loadingCompletedCallback) {
     43      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     44      var func = new Func<string, IStorableContent>(instance.LoadContent);
     45      func.BeginInvoke(filename, delegate(IAsyncResult result) {
     46        Exception error = null;
     47        IStorableContent content = null;
     48        try {
     49          content = func.EndInvoke(result);
     50          content.Filename = filename;
     51        }
     52        catch (Exception ex) {
     53          error = ex;
     54        }
     55        loadingCompletedCallback(content, error);
     56      }, null);
    4157    }
     58    protected abstract IStorableContent LoadContent(string filename);
    4259
    43     public static void Save(IStorableContent content) {
    44       content.Save();
     60    public static void Save(IStorableContent content, string filename, bool compressed) {
     61      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     62      instance.SaveContent(content, filename, compressed);
     63      content.Filename = filename;
    4564    }
    46     public static void Save(IStorableContent content, string filename) {
    47       content.Save(filename);
     65    public static void SaveAsync(IStorableContent content, string filename, bool compressed, Action<IStorableContent, Exception> savingCompletedCallback) {
     66      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     67      var action = new Action<IStorableContent, string, bool>(instance.SaveContent);
     68      action.BeginInvoke(content, filename, compressed, delegate(IAsyncResult result) {
     69        Exception error = null;
     70        try {
     71          action.EndInvoke(result);
     72          content.Filename = filename;
     73        }
     74        catch (Exception ex) {
     75          error = ex;
     76        }
     77        savingCompletedCallback(content, error);
     78      }, null);
    4879    }
    49 
    50     protected abstract void Load(string filename, bool flag);
    51     public static void Load(string filename) {
    52       if (instance == null)
    53         throw new InvalidOperationException("ContentManager must be created before access is allowed.");
    54 
    55       Exception ex = null;
    56       instance.OnLoadOperationStarted();
    57       try {
    58         instance.Load(filename, false);
    59       }
    60       catch (Exception e) {
    61         ex = e;
    62       }
    63       instance.OnLoadOperationFinished(ex);
    64     }
    65 
    66     public static void LoadAsynchronous(string filename) {
    67       if (instance == null)
    68         throw new InvalidOperationException("ContentManager must be created before access is allowed.");
    69 
    70       ThreadPool.QueueUserWorkItem(
    71         new WaitCallback(delegate(object arg) {
    72         Load(filename);
    73       })
    74       );
    75     }
    76    
    77 
    78     public event EventHandler LoadOperationStarted;
    79     protected virtual void OnLoadOperationStarted() {
    80       EventHandler handler = LoadOperationStarted;
    81       if (handler != null)
    82         handler(this, EventArgs.Empty);
    83     }
    84     public event EventHandler<EventArgs<Exception>> LoadOperationFinished;
    85     protected virtual void OnLoadOperationFinished(Exception e) {
    86       EventHandler<EventArgs<Exception>> handler = LoadOperationFinished;
    87       if (handler != null)
    88         handler(this, new EventArgs<Exception>(e));
    89     }
     80    protected abstract void SaveContent(IStorableContent content, string filename, bool compressed);
    9081  }
    9182}
  • trunk/sources/HeuristicLab.Common/3.2/Content/IContent.cs

    r3437 r3483  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 
    2722namespace HeuristicLab.Common {
    28   public interface IContent : IDeepCloneable { }
     23  public interface IContent { }
    2924}
  • trunk/sources/HeuristicLab.Common/3.2/Content/IStorableContent.cs

    r3437 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623
    2724namespace HeuristicLab.Common {
     
    2926    string Filename { get; set; }
    3027
    31     void Save();
    32     void Save(string filename);
    33     void SaveAsynchronous();
    34     void SaveAsynchronous(string filename);
    35 
    3628    event EventHandler FilenameChanged;
    37     event EventHandler SaveOperationStarted;
    38     event EventHandler<EventArgs<Exception>> SaveOperationFinished;
    3929  }
    4030}
  • trunk/sources/HeuristicLab.Common/3.2/Content/StorableContent.cs

    r3437 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading;
    27 using System.Reflection;
    2823
    2924namespace HeuristicLab.Common {
    30   public abstract class StorableContent : Content, IStorableContent {
    31     public StorableContent()
    32       : base() {
    33       this.filename = string.Empty;
    34     }
    35     public StorableContent(string filename)
    36       : base() {
    37       this.Filename = filename;
    38     }
    39 
     25  public class StorableContent : IStorableContent {
    4026    private string filename;
    4127    public string Filename {
    42       get { return this.filename; }
     28      get { return filename; }
    4329      set {
    44         if (this.filename != value) {
    45           this.filename = value;
    46           this.OnFilenameChanged();
     30        if (!filename.Equals(value)) {
     31          filename = value;
     32          OnFilenameChanged();
    4733        }
    4834      }
    4935    }
    5036
    51     protected abstract void Save();
    52     void IStorableContent.Save() {
    53       this.OnSaveOperationStarted();
    54       Exception ex = null;
    55       try {
    56         this.Save();
    57       }
    58       catch (Exception e) {
    59         ex = e;
    60       }
    61       this.OnSaveOperationFinished(ex);
    62     }
    63     public void Save(string filename) {
    64       this.Filename = filename;
    65       ((IStorableContent)this).Save();
    66     }
    67 
    68     protected virtual void SaveAsnychronous() {
    69       ThreadPool.QueueUserWorkItem(
    70         new WaitCallback(delegate(object arg) {
    71         this.Save();
    72       })
    73       );
    74     }
    75     void IStorableContent.SaveAsynchronous() {
    76       this.OnSaveOperationStarted();
    77       this.SaveAsnychronous();
    78       this.OnSaveOperationFinished(null);
    79     }
    80     public void SaveAsynchronous(string filename) {
    81       this.Filename = filename;
    82       ((IStorableContent)this).SaveAsynchronous();
     37    public StorableContent() {
     38      filename = string.Empty;
    8339    }
    8440
     
    8844      if (handler != null) handler(this, EventArgs.Empty);
    8945    }
    90     public event EventHandler SaveOperationStarted;
    91     protected virtual void OnSaveOperationStarted() {
    92       EventHandler handler = SaveOperationStarted;
    93       if (handler != null) handler(this, EventArgs.Empty);
    94     }
    95     public event EventHandler<EventArgs<Exception>> SaveOperationFinished;
    96     protected virtual void OnSaveOperationFinished(Exception ex) {
    97       EventHandler<EventArgs<Exception>> handler = SaveOperationFinished;
    98       if (handler != null) handler(this, new EventArgs<Exception>(ex));
    99     }
    10046  }
    10147}
  • trunk/sources/HeuristicLab.Common/3.2/HeuristicLab.Common-3.2.csproj

    r3437 r3483  
    8989    <None Include="HeuristicLabCommonPlugin.cs.frame" />
    9090    <Compile Include="Cloner.cs" />
    91     <Compile Include="Content\Content.cs" />
    9291    <Compile Include="Content\ContentManager.cs" />
    9392    <Compile Include="Content\IContent.cs" />
  • trunk/sources/HeuristicLab.Common/3.3/Content/ContentManager.cs

    r3424 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading;
    2723
    2824namespace HeuristicLab.Common {
    2925  public abstract class ContentManager {
    30     protected ContentManager() {
     26    private static ContentManager instance;
     27
     28    public static void Initialize(ContentManager manager) {
     29      if (manager == null) throw new ArgumentNullException();
     30      if (ContentManager.instance != null) throw new InvalidOperationException("ContentManager has already been initialized.");
     31      ContentManager.instance = manager;
    3132    }
    3233
    33     private static ContentManager instance;
    34     public static ContentManager Instance {
    35       get { return instance; }
     34    protected ContentManager() { }
     35
     36    public static IStorableContent Load(string filename) {
     37      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     38      IStorableContent content = instance.LoadContent(filename);
     39      content.Filename = filename;
     40      return content;
    3641    }
    37     public static void CreateInstance<T>() where T : ContentManager {
    38       if (instance != null)
    39         throw new InvalidOperationException("ContentManager was already created.");
    40       instance = Activator.CreateInstance<T>();
     42    public static void LoadAsync(string filename, Action<IStorableContent, Exception> loadingCompletedCallback) {
     43      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     44      var func = new Func<string, IStorableContent>(instance.LoadContent);
     45      func.BeginInvoke(filename, delegate(IAsyncResult result) {
     46        Exception error = null;
     47        IStorableContent content = null;
     48        try {
     49          content = func.EndInvoke(result);
     50          content.Filename = filename;
     51        }
     52        catch (Exception ex) {
     53          error = ex;
     54        }
     55        loadingCompletedCallback(content, error);
     56      }, null);
    4157    }
     58    protected abstract IStorableContent LoadContent(string filename);
    4259
    43     public static void Save(IStorableContent content) {
    44       content.Save();
     60    public static void Save(IStorableContent content, string filename, bool compressed) {
     61      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     62      instance.SaveContent(content, filename, compressed);
     63      content.Filename = filename;
    4564    }
    46     public static void Save(IStorableContent content, string filename) {
    47       content.Save(filename);
     65    public static void SaveAsync(IStorableContent content, string filename, bool compressed, Action<IStorableContent, Exception> savingCompletedCallback) {
     66      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
     67      var action = new Action<IStorableContent, string, bool>(instance.SaveContent);
     68      action.BeginInvoke(content, filename, compressed, delegate(IAsyncResult result) {
     69        Exception error = null;
     70        try {
     71          action.EndInvoke(result);
     72          content.Filename = filename;
     73        }
     74        catch (Exception ex) {
     75          error = ex;
     76        }
     77        savingCompletedCallback(content, error);
     78      }, null);
    4879    }
    49 
    50     protected abstract void Load(string filename, bool flag);
    51     public static void Load(string filename) {
    52       if (instance == null)
    53         throw new InvalidOperationException("ContentManager must be created before access is allowed.");
    54 
    55       Exception ex = null;
    56       instance.OnLoadOperationStarted();
    57       try {
    58         instance.Load(filename, false);
    59       }
    60       catch (Exception e) {
    61         ex = e;
    62       }
    63       instance.OnLoadOperationFinished(ex);
    64     }
    65 
    66     public static void LoadAsynchronous(string filename) {
    67       if (instance == null)
    68         throw new InvalidOperationException("ContentManager must be created before access is allowed.");
    69 
    70       ThreadPool.QueueUserWorkItem(
    71         new WaitCallback(delegate(object arg) {
    72         Load(filename);
    73       })
    74       );
    75     }
    76    
    77 
    78     public event EventHandler LoadOperationStarted;
    79     protected virtual void OnLoadOperationStarted() {
    80       EventHandler handler = LoadOperationStarted;
    81       if (handler != null)
    82         handler(this, EventArgs.Empty);
    83     }
    84     public event EventHandler<EventArgs<Exception>> LoadOperationFinished;
    85     protected virtual void OnLoadOperationFinished(Exception e) {
    86       EventHandler<EventArgs<Exception>> handler = LoadOperationFinished;
    87       if (handler != null)
    88         handler(this, new EventArgs<Exception>(e));
    89     }
     80    protected abstract void SaveContent(IStorableContent content, string filename, bool compressed);
    9081  }
    9182}
  • trunk/sources/HeuristicLab.Common/3.3/Content/IContent.cs

    r3431 r3483  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 
    2722namespace HeuristicLab.Common {
    28   public interface IContent : IDeepCloneable { }
     23  public interface IContent { }
    2924}
  • trunk/sources/HeuristicLab.Common/3.3/Content/IStorableContent.cs

    r3412 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623
    2724namespace HeuristicLab.Common {
     
    2926    string Filename { get; set; }
    3027
    31     void Save();
    32     void Save(string filename);
    33     void SaveAsynchronous();
    34     void SaveAsynchronous(string filename);
    35 
    3628    event EventHandler FilenameChanged;
    37     event EventHandler SaveOperationStarted;
    38     event EventHandler<EventArgs<Exception>> SaveOperationFinished;
    3929  }
    4030}
  • trunk/sources/HeuristicLab.Common/3.3/Content/StorableContent.cs

    r3412 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading;
    27 using System.Reflection;
    2823
    2924namespace HeuristicLab.Common {
    30   public abstract class StorableContent : Content, IStorableContent {
    31     public StorableContent()
    32       : base() {
    33       this.filename = string.Empty;
    34     }
    35     public StorableContent(string filename)
    36       : base() {
    37       this.Filename = filename;
    38     }
    39 
     25  public class StorableContent : IStorableContent {
    4026    private string filename;
    4127    public string Filename {
    42       get { return this.filename; }
     28      get { return filename; }
    4329      set {
    44         if (this.filename != value) {
    45           this.filename = value;
    46           this.OnFilenameChanged();
     30        if (!filename.Equals(value)) {
     31          filename = value;
     32          OnFilenameChanged();
    4733        }
    4834      }
    4935    }
    5036
    51     protected abstract void Save();
    52     void IStorableContent.Save() {
    53       this.OnSaveOperationStarted();
    54       Exception ex = null;
    55       try {
    56         this.Save();
    57       }
    58       catch (Exception e) {
    59         ex = e;
    60       }
    61       this.OnSaveOperationFinished(ex);
    62     }
    63     public void Save(string filename) {
    64       this.Filename = filename;
    65       ((IStorableContent)this).Save();
    66     }
    67 
    68     protected virtual void SaveAsnychronous() {
    69       ThreadPool.QueueUserWorkItem(
    70         new WaitCallback(delegate(object arg) {
    71         this.Save();
    72       })
    73       );
    74     }
    75     void IStorableContent.SaveAsynchronous() {
    76       this.OnSaveOperationStarted();
    77       this.SaveAsnychronous();
    78       this.OnSaveOperationFinished(null);
    79     }
    80     public void SaveAsynchronous(string filename) {
    81       this.Filename = filename;
    82       ((IStorableContent)this).SaveAsynchronous();
     37    public StorableContent() {
     38      filename = string.Empty;
    8339    }
    8440
     
    8844      if (handler != null) handler(this, EventArgs.Empty);
    8945    }
    90     public event EventHandler SaveOperationStarted;
    91     protected virtual void OnSaveOperationStarted() {
    92       EventHandler handler = SaveOperationStarted;
    93       if (handler != null) handler(this, EventArgs.Empty);
    94     }
    95     public event EventHandler<EventArgs<Exception>> SaveOperationFinished;
    96     protected virtual void OnSaveOperationFinished(Exception ex) {
    97       EventHandler<EventArgs<Exception>> handler = SaveOperationFinished;
    98       if (handler != null) handler(this, new EventArgs<Exception>(ex));
    99     }
    10046  }
    10147}
  • trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r3462 r3483  
    8989    <None Include="HeuristicLabCommonPlugin.cs.frame" />
    9090    <Compile Include="Cloner.cs" />
    91     <Compile Include="Content\Content.cs" />
    9291    <Compile Include="Content\ContentManager.cs" />
    9392    <Compile Include="Content\IStorableContent.cs" />
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.cs

    r3456 r3483  
    3535  [Content(typeof(ItemArray<>), true)]
    3636  [Content(typeof(IItemArray<>), false)]
    37   public partial class ItemArrayView<T> : AsynchronousContentView where T : class, IItem {
     37  public partial class ItemArrayView<T> : ItemView where T : class, IItem {
    3838    protected TypeSelectorDialog typeSelectorDialog;
    3939
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs

    r3456 r3483  
    3232  [Content(typeof(ItemCollection<>), true)]
    3333  [Content(typeof(IItemCollection<>), false)]
    34   public partial class ItemCollectionView<T> : AsynchronousContentView where T : class, IItem {
     34  public partial class ItemCollectionView<T> : ItemView where T : class, IItem {
    3535    protected TypeSelectorDialog typeSelectorDialog;
    3636
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs

    r3456 r3483  
    3535  [Content(typeof(ItemList<>), true)]
    3636  [Content(typeof(IItemList<>), false)]
    37   public partial class ItemListView<T> : AsynchronousContentView where T : class, IItem {
     37  public partial class ItemListView<T> : ItemView where T : class, IItem {
    3838    protected TypeSelectorDialog typeSelectorDialog;
    3939
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ItemArray.cs

    r3431 r3483  
    3636  [Item("ItemArray<T>", "Represents an array of items.")]
    3737  public class ItemArray<T> : ObservableArray<T>, IItemArray<T> where T : class, IItem {
     38    private string filename;
     39    public string Filename {
     40      get { return filename; }
     41      set {
     42        if (!filename.Equals(value)) {
     43          filename = value;
     44          OnFilenameChanged();
     45        }
     46      }
     47    }
     48
    3849    public virtual string ItemName {
    3950      get { return ItemAttribute.GetName(this.GetType()); }
     
    7788    }
    7889
     90    public event EventHandler FilenameChanged;
     91    protected virtual void OnFilenameChanged() {
     92      EventHandler handler = FilenameChanged;
     93      if (handler != null) handler(this, EventArgs.Empty);
     94    }
    7995    public event EventHandler ItemImageChanged;
    8096    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ItemCollection.cs

    r3431 r3483  
    3333  [Item("ItemCollection<T>", "Represents a collection of items.")]
    3434  public class ItemCollection<T> : ObservableCollection<T>, IItemCollection<T> where T : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7384    }
    7485
     86    public event EventHandler FilenameChanged;
     87    protected virtual void OnFilenameChanged() {
     88      EventHandler handler = FilenameChanged;
     89      if (handler != null) handler(this, EventArgs.Empty);
     90    }
    7591    public event EventHandler ItemImageChanged;
    7692    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ItemDictionary.cs

    r3431 r3483  
    3333  [Item("ItemDictionary<TKey, TValue>", "Represents a dictionary of items.")]
    3434  public class ItemDictionary<TKey, TValue> : ObservableDictionary<TKey, TValue>, IItemDictionary<TKey, TValue> where TKey : class, IItem where TValue : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7485    }
    7586
     87    public event EventHandler FilenameChanged;
     88    protected virtual void OnFilenameChanged() {
     89      EventHandler handler = FilenameChanged;
     90      if (handler != null) handler(this, EventArgs.Empty);
     91    }
    7692    public event EventHandler ItemImageChanged;
    7793    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ItemList.cs

    r3431 r3483  
    3636  [Item("ItemList<T>", "Represents a list of items.")]
    3737  public class ItemList<T> : ObservableList<T>, IItemList<T> where T : class, IItem {
     38    private string filename;
     39    public string Filename {
     40      get { return filename; }
     41      set {
     42        if (!filename.Equals(value)) {
     43          filename = value;
     44          OnFilenameChanged();
     45        }
     46      }
     47    }
     48
    3849    public virtual string ItemName {
    3950      get { return ItemAttribute.GetName(this.GetType()); }
     
    7687    }
    7788
     89    public event EventHandler FilenameChanged;
     90    protected virtual void OnFilenameChanged() {
     91      EventHandler handler = FilenameChanged;
     92      if (handler != null) handler(this, EventArgs.Empty);
     93    }
    7894    public event EventHandler ItemImageChanged;
    7995    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ItemSet.cs

    r3431 r3483  
    3636  [Item("ItemSet<T>", "Represents a set of items.")]
    3737  public class ItemSet<T> : ObservableSet<T>, IItemSet<T> where T : class, IItem {
     38    private string filename;
     39    public string Filename {
     40      get { return filename; }
     41      set {
     42        if (!filename.Equals(value)) {
     43          filename = value;
     44          OnFilenameChanged();
     45        }
     46      }
     47    }
     48
    3849    public virtual string ItemName {
    3950      get { return ItemAttribute.GetName(this.GetType()); }
     
    7586    }
    7687
     88    public event EventHandler FilenameChanged;
     89    protected virtual void OnFilenameChanged() {
     90      EventHandler handler = FilenameChanged;
     91      if (handler != null) handler(this, EventArgs.Empty);
     92    }
    7793    public event EventHandler ItemImageChanged;
    7894    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/KeyedItemCollection.cs

    r3431 r3483  
    3232  [StorableClass]
    3333  public abstract class KeyedItemCollection<TKey, TItem> : ObservableKeyedCollection<TKey, TItem>, IKeyedItemCollection<TKey, TItem> where TItem : class, IItem {
     34    private string filename;
     35    public string Filename {
     36      get { return filename; }
     37      set {
     38        if (!filename.Equals(value)) {
     39          filename = value;
     40          OnFilenameChanged();
     41        }
     42      }
     43    }
     44
    3445    public virtual string ItemName {
    3546      get { return ItemAttribute.GetName(this.GetType()); }
     
    7586    }
    7687
     88    public event EventHandler FilenameChanged;
     89    protected virtual void OnFilenameChanged() {
     90      EventHandler handler = FilenameChanged;
     91      if (handler != null) handler(this, EventArgs.Empty);
     92    }
    7793    public event EventHandler ItemImageChanged;
    7894    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemArray.cs

    r3431 r3483  
    3333  [Item("ReadOnlyItemArray<T>", "Represents a read-only array of items.")]
    3434  public class ReadOnlyItemArray<T> : ReadOnlyObservableArray<T>, IItemArray<T> where T : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7485    }
    7586
     87    public event EventHandler FilenameChanged;
     88    protected virtual void OnFilenameChanged() {
     89      EventHandler handler = FilenameChanged;
     90      if (handler != null) handler(this, EventArgs.Empty);
     91    }
    7692    public event EventHandler ItemImageChanged;
    7793    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemCollection.cs

    r3431 r3483  
    3333  [Item("ReadOnlyItemCollection<T>", "Represents a read-only collection of items.")]
    3434  public class ReadOnlyItemCollection<T> : ReadOnlyObservableCollection<T>, IItemCollection<T> where T : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7485    }
    7586
     87    public event EventHandler FilenameChanged;
     88    protected virtual void OnFilenameChanged() {
     89      EventHandler handler = FilenameChanged;
     90      if (handler != null) handler(this, EventArgs.Empty);
     91    }
    7692    public event EventHandler ItemImageChanged;
    7793    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemDictionary.cs

    r3431 r3483  
    3333  [Item("ReadOnlyItemDictionary<TKey, TValue>", "Represents a read-only dictionary of items.")]
    3434  public class ReadOnlyItemDictionary<TKey, TValue> : ReadOnlyObservableDictionary<TKey, TValue>, IItemDictionary<TKey, TValue> where TKey : class, IItem where TValue : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7485    }
    7586
     87    public event EventHandler FilenameChanged;
     88    protected virtual void OnFilenameChanged() {
     89      EventHandler handler = FilenameChanged;
     90      if (handler != null) handler(this, EventArgs.Empty);
     91    }
    7692    public event EventHandler ItemImageChanged;
    7793    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemList.cs

    r3431 r3483  
    3333  [Item("ReadOnlyItemList<T>", "Represents a read-only list of items.")]
    3434  public class ReadOnlyItemList<T> : ReadOnlyObservableList<T>, IItemList<T> where T : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7485    }
    7586
     87    public event EventHandler FilenameChanged;
     88    protected virtual void OnFilenameChanged() {
     89      EventHandler handler = FilenameChanged;
     90      if (handler != null) handler(this, EventArgs.Empty);
     91    }
    7692    public event EventHandler ItemImageChanged;
    7793    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemSet.cs

    r3431 r3483  
    3333  [Item("ReadOnlyItemSet<T>", "Represents a read-only set of items.")]
    3434  public class ReadOnlyItemSet<T> : ReadOnlyObservableSet<T>, IItemSet<T> where T : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7485    }
    7586
     87    public event EventHandler FilenameChanged;
     88    protected virtual void OnFilenameChanged() {
     89      EventHandler handler = FilenameChanged;
     90      if (handler != null) handler(this, EventArgs.Empty);
     91    }
    7692    public event EventHandler ItemImageChanged;
    7793    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyKeyedItemCollection.cs

    r3431 r3483  
    3333  [Item("ReadOnlyKeyedItemCollection<TKey, TItem>", "Represents a read-only keyed collection of items.")]
    3434  public class ReadOnlyKeyedItemCollection<TKey, TItem> : ReadOnlyObservableKeyedCollection<TKey, TItem>, IKeyedItemCollection<TKey, TItem> where TItem : class, IItem {
     35    private string filename;
     36    public string Filename {
     37      get { return filename; }
     38      set {
     39        if (!filename.Equals(value)) {
     40          filename = value;
     41          OnFilenameChanged();
     42        }
     43      }
     44    }
     45
    3546    public virtual string ItemName {
    3647      get { return ItemAttribute.GetName(this.GetType()); }
     
    7485    }
    7586
     87    public event EventHandler FilenameChanged;
     88    protected virtual void OnFilenameChanged() {
     89      EventHandler handler = FilenameChanged;
     90      if (handler != null) handler(this, EventArgs.Empty);
     91    }
    7692    public event EventHandler ItemImageChanged;
    7793    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r3390 r3483  
    123123    <Compile Include="Collections\ValueParameterCollection.cs" />
    124124    <Compile Include="Collections\VariableCollection.cs" />
     125    <Compile Include="PersistenceContentManager.cs" />
    125126    <Compile Include="Interfaces\IKeyedItemCollection.cs" />
    126127    <Compile Include="Interfaces\IItemList.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IItem.cs

    r3368 r3483  
    2828  /// Interface to represent (almost) every HeuristicLab object (an object, an operator,...).
    2929  /// </summary>
    30   public interface IItem : IContent, IDeepCloneable {
     30  public interface IItem : IStorableContent, IDeepCloneable {
    3131    string ItemName { get; }
    3232    string ItemDescription { get; }
  • trunk/sources/HeuristicLab.Core/3.3/Item.cs

    r3431 r3483  
    3131  [StorableClass]
    3232  [Item("Item", "Base class for all HeuristicLab items.")]
    33   public abstract class Item : DeepCloneable, IItem {
     33  public abstract class Item : IItem {
     34    private string filename;
     35    public string Filename {
     36      get { return filename; }
     37      set {
     38        if (!filename.Equals(value)) {
     39          filename = value;
     40          OnFilenameChanged();
     41        }
     42      }
     43    }
     44
    3445    public virtual string ItemName {
    3546      get { return ItemAttribute.GetName(this.GetType()); }
     
    4253    }
    4354
    44     protected Item() : base() { }
     55    protected Item() {
     56      filename = string.Empty;
     57    }
    4558    [StorableConstructor]
    46     protected Item(bool deserializing) { }
     59    protected Item(bool deserializing) {
     60      filename = string.Empty;
     61    }
     62
     63    public object Clone() {
     64      return Clone(new Cloner());
     65    }
     66    public virtual IDeepCloneable Clone(Cloner cloner) {
     67      Item clone = (Item)Activator.CreateInstance(this.GetType(), true);
     68      cloner.RegisterClonedObject(this, clone);
     69      return clone;
     70    }
    4771
    4872    /// <summary>
     
    5478    }
    5579
     80    public event EventHandler FilenameChanged;
     81    protected virtual void OnFilenameChanged() {
     82      EventHandler handler = FilenameChanged;
     83      if (handler != null) handler(this, EventArgs.Empty);
     84    }
    5685    public event EventHandler ItemImageChanged;
    5786    protected virtual void OnItemImageChanged() {
  • trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Tests/TestRandom.cs

    r3431 r3483  
    134134
    135135    #endregion
     136
     137    #region IStorableContent Members
     138
     139    public string Filename {
     140      get { throw new NotImplementedException(); }
     141      set { throw new NotImplementedException(); }
     142    }
     143
     144#pragma warning disable 67
     145    public event EventHandler FilenameChanged;
     146#pragma warning restore 67
     147
     148    #endregion
    136149  }
    137150}
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Tests/TestRandom.cs

    r3431 r3483  
    134134
    135135    #endregion
     136
     137    #region IStorableContent Members
     138
     139    public string Filename {
     140      get { throw new NotImplementedException(); }
     141      set { throw new NotImplementedException(); }
     142    }
     143
     144#pragma warning disable 67
     145    public event EventHandler FilenameChanged;
     146#pragma warning restore 67
     147
     148    #endregion
    136149  }
    137150}
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Tests/Random.cs

    r3431 r3483  
    134134
    135135    #endregion
     136
     137    #region IStorableContent Members
     138
     139    public string Filename {
     140      get { throw new NotImplementedException(); }
     141      set { throw new NotImplementedException(); }
     142    }
     143
     144#pragma warning disable 67
     145    public event EventHandler FilenameChanged;
     146#pragma warning restore 67
     147
     148    #endregion
    136149  }
    137150}
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/TestRandom.cs

    r3431 r3483  
    134134
    135135    #endregion
     136
     137    #region IStorableContent Members
     138
     139    public string Filename {
     140      get { throw new NotImplementedException(); }
     141      set { throw new NotImplementedException(); }
     142    }
     143
     144#pragma warning disable 67
     145    public event EventHandler FilenameChanged;
     146#pragma warning restore 67
     147
     148    #endregion
    136149  }
    137150}
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ContentView.cs

    r3416 r3483  
    4747            if (this.content != null) this.RegisterContentEvents();
    4848            this.OnContentChanged();
     49            this.OnChanged();
    4950          }
    5051        }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ContentView.cs

    r3437 r3483  
    4747            if (this.content != null) this.RegisterContentEvents();
    4848            this.OnContentChanged();
     49            this.OnChanged();
    4950          }
    5051        }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r3456 r3483  
    3434  [Content(typeof(RunCollection), true)]
    3535  [Content(typeof(IItemCollection<IRun>), false)]
    36   public partial class RunCollectionView : AsynchronousContentView {
     36  public partial class RunCollectionView : ItemView {
    3737    public new IItemCollection<IRun> Content {
    3838      get { return (IItemCollection<IRun>)base.Content; }
  • trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs

    r3416 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    2523using System.Linq;
    26 using System.Threading;
    2724using System.Windows.Forms;
     25using HeuristicLab.Common;
    2826using HeuristicLab.Core.Views;
    2927using HeuristicLab.MainForm;
    30 using HeuristicLab.MainForm.WindowsForms;
    31 using HeuristicLab.Persistence.Default.Xml;
    3228
    3329namespace HeuristicLab.Optimizer {
    3430  internal static class FileManager {
    35 
    36     #region Private Class FileInfo
    37     private class FileInfo {
    38       public string Filename { get; set; }
    39       public bool Compressed { get; set; }
    40 
    41       public FileInfo(string filename, bool compressed) {
    42         Filename = filename;
    43         Compressed = compressed;
    44       }
    45       public FileInfo(string filename)
    46         : this(filename, true) {
    47       }
    48       public FileInfo()
    49         : this(string.Empty, true) {
    50       }
    51     }
    52     #endregion
    53 
    54     private static Dictionary<IContentView, FileInfo> files;
    5531    private static NewItemDialog newItemDialog;
    5632    private static OpenFileDialog openFileDialog;
    5733    private static SaveFileDialog saveFileDialog;
    58     private static int waitingCursors;
    59     private static int newDocumentsCounter;
    6034
    6135    static FileManager() {
    62       files = new Dictionary<IContentView, FileInfo>();
    6336      newItemDialog = null;
    6437      openFileDialog = null;
    6538      saveFileDialog = null;
    66       waitingCursors = 0;
    67       newDocumentsCounter = 1;
    68       // NOTE: Events fired by the main form are registered in HeuristicLabOptimizerApplication.
    6939    }
    7040
     
    7343      if (newItemDialog.ShowDialog() == DialogResult.OK) {
    7444        IView view = MainFormManager.CreateDefaultView(newItemDialog.Item);
    75         if (view == null) {
    76           MessageBox.Show("There is no view for the new item. It cannot be displayed. ", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
    77         } else {
    78           if (view is IContentView) {
    79             view.Caption = "Item" + newDocumentsCounter.ToString() + ".hl";
    80             newDocumentsCounter++;
    81           }
    82           view.Show();
    83         }
     45        if (view == null) MessageBox.Show("There is no view for the new item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
     46        else view.Show();
    8447      }
    8548    }
     
    9659
    9760      if (openFileDialog.ShowDialog() == DialogResult.OK) {
    98         foreach (string filename in openFileDialog.FileNames)
    99           LoadItemAsync(filename);
     61        foreach (string filename in openFileDialog.FileNames) {
     62          ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor();
     63          ContentManager.LoadAsync(filename, LoadingCompleted);
     64        }
     65      }
     66    }
     67    private static void LoadingCompleted(IStorableContent content, Exception error) {
     68      try {
     69        if (error != null) throw error;
     70        Invoke(delegate() {
     71          IView view = MainFormManager.CreateDefaultView(content);
     72          if (view == null) MessageBox.Show("There is no view for the loaded item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
     73          else view.Show();
     74        });
     75      }
     76      catch (Exception ex) {
     77        Auxiliary.ShowErrorMessageBox(ex);
     78      }
     79      finally {
     80        ((OptimizerMainForm)MainFormManager.MainForm).ResetAppStartingCursor();
    10081      }
    10182    }
     
    10889    }
    10990    private static void Save(IContentView view) {
    110       if (!view.Locked) {
    111         if ((!files.ContainsKey(view)) || (!File.Exists(files[view].Filename))) {
     91      IStorableContent content = view.Content as IStorableContent;
     92      if (!view.Locked && (content != null)) {
     93        if (string.IsNullOrEmpty(content.Filename))
    11294          SaveAs(view);
    113         } else {
    114           if (files[view].Compressed)
    115             SaveItemAsync(view, files[view].Filename, 9);
    116           else
    117             SaveItemAsync(view, files[view].Filename, 0);
     95        else {
     96          ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor();
     97          ((Form)MainFormManager.MainForm).Enabled = false;
     98          ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted);
    11899        }
    119100      }
    120101    }
    121 
    122102    public static void SaveAs() {
    123103      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
     
    127107    }
    128108    public static void SaveAs(IContentView view) {
    129       if (!view.Locked) {
     109      IStorableContent content = view.Content as IStorableContent;
     110      if (!view.Locked && (content != null)) {
    130111        if (saveFileDialog == null) {
    131112          saveFileDialog = new SaveFileDialog();
     
    135116          saveFileDialog.FilterIndex = 2;
    136117        }
    137 
    138         if (!files.ContainsKey(view)) {
    139           files.Add(view, new FileInfo());
    140           saveFileDialog.FileName = view.Caption;
    141         } else {
    142           saveFileDialog.FileName = files[view].Filename;
    143         }
    144         if (!files[view].Compressed)
    145           saveFileDialog.FilterIndex = 1;
    146         else
    147           saveFileDialog.FilterIndex = 2;
     118        saveFileDialog.FileName = string.IsNullOrEmpty(content.Filename) ? "Item" : content.Filename;
    148119
    149120        if (saveFileDialog.ShowDialog() == DialogResult.OK) {
     121          ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor();
     122          ((Form)MainFormManager.MainForm).Enabled = false;
    150123          if (saveFileDialog.FilterIndex == 1) {
    151             SaveItemAsync(view, saveFileDialog.FileName, 0);
     124            ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted);
    152125          } else {
    153             SaveItemAsync(view, saveFileDialog.FileName, 9);
     126            ContentManager.SaveAsync(content, saveFileDialog.FileName, true, SavingCompleted);
    154127          }
    155128        }
    156129      }
    157130    }
    158 
    159131    public static void SaveAll() {
    160132      foreach (IContentView view in MainFormManager.MainForm.Views.OfType<IContentView>())
    161133        Save(view);
    162134    }
    163 
    164     // NOTE: This event is fired by the main form. It is registered in HeuristicLabOptimizerApplication.
    165     internal static void ViewClosed(object sender, ViewEventArgs e) {
    166       IContentView view = e.View as IContentView;
    167       if (view != null) files.Remove(view);
     135    private static void SavingCompleted(IStorableContent content, Exception error) {
     136      try {
     137        if (error != null) throw error;
     138        Invoke(delegate() {
     139          ((OptimizerMainForm)MainFormManager.MainForm).UpdateTitle();
     140          ((Form)MainFormManager.MainForm).Enabled = true;
     141        });
     142      }
     143      catch (Exception ex) {
     144        Auxiliary.ShowErrorMessageBox(ex);
     145      }
     146      finally {
     147        ((OptimizerMainForm)MainFormManager.MainForm).ResetAppStartingCursor();
     148      }
    168149    }
    169150
    170     #region Asynchronous Save/Load Operations
    171151    private static void Invoke(Action a) {
    172152      Form form = MainFormManager.MainForm as Form;
     
    176156        a.Invoke();
    177157    }
    178 
    179     private static void SaveItemAsync(IContentView view, string filename, int compression) {
    180       ThreadPool.QueueUserWorkItem(
    181         new WaitCallback(
    182           delegate(object arg) {
    183             try {
    184               DisableView(view);
    185               SetWaitingCursor();
    186               XmlGenerator.Serialize(view.Content, filename, compression);
    187               Invoke(delegate() {
    188                 view.Caption = Path.GetFileName(filename);
    189                 files[view].Filename = filename;
    190                 files[view].Compressed = compression > 0;
    191               });
    192             }
    193             catch (Exception ex) {
    194               Auxiliary.ShowErrorMessageBox(ex);
    195             } finally {
    196               ResetWaitingCursor();
    197               EnableView(view);
    198             }
    199           }
    200         )
    201       );
    202     }
    203     private static void LoadItemAsync(string filename) {
    204       ThreadPool.QueueUserWorkItem(
    205         new WaitCallback(
    206           delegate(object arg) {
    207             try {
    208               SetWaitingCursor();
    209               object content = XmlParser.Deserialize(filename);
    210               Invoke(delegate() {
    211                 IContentView view = MainFormManager.CreateDefaultView(content) as IContentView;
    212                 if (view == null) {
    213                   MessageBox.Show("There is no view for the loaded item. It cannot be displayed. ", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
    214                 } else {
    215                   view.Caption = Path.GetFileName(filename);
    216                   files.Add(view, new FileInfo(filename));
    217                   view.Show();
    218                 }
    219               });
    220             } catch (Exception ex) {
    221               Auxiliary.ShowErrorMessageBox(ex);
    222             } finally {
    223               ResetWaitingCursor();
    224             }
    225           }
    226         )
    227       );
    228     }
    229 
    230     private static void SetWaitingCursor() {
    231       Invoke(delegate() {
    232         waitingCursors++;
    233         ((Form)MainFormManager.MainForm).Cursor = Cursors.AppStarting;
    234       });
    235     }
    236     private static void ResetWaitingCursor() {
    237       Invoke(delegate() {
    238         waitingCursors--;
    239         if (waitingCursors == 0) ((Form)MainFormManager.MainForm).Cursor = Cursors.Default;
    240       });
    241     }
    242     private static void DisableView(IView view) {
    243       Invoke(delegate() {
    244         ((Control)view).SuspendRepaint();
    245         ((Control)view).Enabled = false;
    246         ((Control)view).ResumeRepaint(true);
    247       });
    248     }
    249     private static void EnableView(IView view) {
    250       Invoke(delegate() {
    251         ((Control)view).SuspendRepaint();
    252         ((Control)view).Enabled = true;
    253         ((Control)view).ResumeRepaint(true);
    254       });
    255     }
    256     #endregion
    257158  }
    258159}
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/CopyToClipboardMenuItem.cs

    r3416 r3483  
    3939      get { return 2100; }
    4040    }
    41     public override Keys ShortCutKeys {
    42       get { return Keys.Control | Keys.C; }
    43     }
    4441
    4542    protected override void OnToolStripItemSet(EventArgs e) {
     
    4845    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4946      ItemView activeView = MainFormManager.MainForm.ActiveView as ItemView;
    50       ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
     47      ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) && !activeView.Locked;
    5148    }
    5249
    5350    public override void Execute() {
    5451      ItemView activeView = MainFormManager.MainForm.ActiveView as ItemView;
    55       if ((activeView != null) && (!activeView.Locked)) {
     52      if ((activeView != null) && (activeView.Content != null) && !activeView.Locked) {
    5653        Clipboard<IItem> clipboard = ((OptimizerMainForm)MainFormManager.MainForm).Clipboard;
    5754        clipboard.AddItem((IItem)activeView.Content.Clone());
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAllMenuItem.cs

    r3416 r3483  
    2525using System.Linq;
    2626using System.Windows.Forms;
     27using HeuristicLab.Common;
    2728using HeuristicLab.MainForm;
    2829
     
    4748    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4849      var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>()
     50                  where v.Content != null
     51                  where v.Content is IStorableContent
    4952                  where !v.Locked
    5053                  select v;
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAsMenuItem.cs

    r3416 r3483  
    2323using System.Collections.Generic;
    2424using System.Windows.Forms;
     25using HeuristicLab.Common;
    2526using HeuristicLab.MainForm;
    2627
     
    4546    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4647      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    47       ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
     48      ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) &&
     49                              (activeView.Content is IStorableContent) && !activeView.Locked;
    4850    }
    4951
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveMenuItem.cs

    r3416 r3483  
    2424using System.Drawing;
    2525using System.Windows.Forms;
     26using HeuristicLab.Common;
    2627using HeuristicLab.MainForm;
    2728
     
    4950    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    5051      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    51       ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
     52      ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) &&
     53                              (activeView.Content is IStorableContent) && !activeView.Locked;
    5254    }
    5355
  • trunk/sources/HeuristicLab.Optimizer/3.3/OptimizerMainForm.cs

    r3395 r3483  
    3232namespace HeuristicLab.Optimizer {
    3333  internal partial class OptimizerMainForm : DockingMainForm {
     34    private string title;
     35    private int appStartingCursors;
     36    private int waitingCursors;
     37
    3438    private Clipboard<IItem> clipboard;
    3539    public Clipboard<IItem> Clipboard {
     
    4044      : base() {
    4145      InitializeComponent();
     46      appStartingCursors = 0;
     47      waitingCursors = 0;
    4248    }
    4349    public OptimizerMainForm(Type userInterfaceItemType)
    4450      : base(userInterfaceItemType) {
    4551      InitializeComponent();
     52      appStartingCursors = 0;
     53      waitingCursors = 0;
    4654    }
    4755    public OptimizerMainForm(Type userInterfaceItemType, bool showViewsInViewHost)
     
    5462      AssemblyFileVersionAttribute version = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
    5563                                             Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
    56       Title = "HeuristicLab Optimizer";
    57       if (version != null) Title += " " + version.Version;
    58       ViewClosed += new EventHandler<ViewEventArgs>(FileManager.ViewClosed);
     64      title = "HeuristicLab Optimizer";
     65      if (version != null) title += " " + version.Version;
     66      Title = title;
     67
     68      ContentManager.Initialize(new PersistenceContentManager());
    5969
    6070      clipboard = new Clipboard<IItem>();
     
    7383      }
    7484    }
     85
     86    protected override void OnActiveViewChanged() {
     87      base.OnActiveViewChanged();
     88      UpdateTitle();
     89    }
     90
     91    public void UpdateTitle() {
     92      if (InvokeRequired)
     93        Invoke(new Action(UpdateTitle));
     94      else {
     95        IContentView activeView = ActiveView as IContentView;
     96        if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IStorableContent)) {
     97          IStorableContent content = (IStorableContent)activeView.Content;
     98          Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
     99        } else {
     100          Title = title;
     101        }
     102      }
     103    }
     104
     105    #region Cursor Handling
     106    public void SetAppStartingCursor() {
     107      if (InvokeRequired)
     108        Invoke(new Action(SetAppStartingCursor));
     109      else {
     110        appStartingCursors++;
     111        SetCursor();
     112      }
     113    }
     114    public void ResetAppStartingCursor() {
     115      if (InvokeRequired)
     116        Invoke(new Action(ResetAppStartingCursor));
     117      else {
     118        appStartingCursors--;
     119        SetCursor();
     120      }
     121    }
     122    public void SetWaitCursor() {
     123      if (InvokeRequired)
     124        Invoke(new Action(SetWaitCursor));
     125      else {
     126        waitingCursors++;
     127        SetCursor();
     128      }
     129    }
     130    public void ResetWaitCursor() {
     131      if (InvokeRequired)
     132        Invoke(new Action(ResetWaitCursor));
     133      else {
     134        waitingCursors--;
     135        SetCursor();
     136      }
     137    }
     138    private void SetCursor() {
     139      if (waitingCursors > 0) Cursor = Cursors.WaitCursor;
     140      else if (appStartingCursors > 0) Cursor = Cursors.AppStarting;
     141      else Cursor = Cursors.Default;
     142    }
     143    #endregion
    75144  }
    76145}
  • trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveAllToolBarItem.cs

    r3416 r3483  
    2424using System.Linq;
    2525using System.Windows.Forms;
     26using HeuristicLab.Common;
    2627using HeuristicLab.MainForm;
    2728
     
    4647    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4748      var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>()
     49                  where v.Content != null
     50                  where v.Content is IStorableContent
    4851                  where !v.Locked
    4952                  select v;
  • trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveToolBarItem.cs

    r3416 r3483  
    2323using System.Drawing;
    2424using System.Windows.Forms;
     25using HeuristicLab.Common;
    2526using HeuristicLab.MainForm;
    2627
     
    4546    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4647      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    47       ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
     48      ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) &&
     49                              (activeView.Content is IStorableContent) && !activeView.Locked;
    4850    }
    4951
Note: See TracChangeset for help on using the changeset viewer.