Changeset 3483
- Timestamp:
- 04/22/10 05:14:39 (15 years ago)
- 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 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 using System.Threading;27 23 28 24 namespace HeuristicLab.Common { 29 25 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; 31 32 } 32 33 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; 36 41 } 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); 41 57 } 58 protected abstract IStorableContent LoadContent(string filename); 42 59 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; 45 64 } 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); 48 79 } 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); 90 81 } 91 82 } -
trunk/sources/HeuristicLab.Common/3.2/Content/IContent.cs
r3437 r3483 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 27 22 namespace HeuristicLab.Common { 28 public interface IContent : IDeepCloneable{ }23 public interface IContent { } 29 24 } -
trunk/sources/HeuristicLab.Common/3.2/Content/IStorableContent.cs
r3437 r3483 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 23 27 24 namespace HeuristicLab.Common { … … 29 26 string Filename { get; set; } 30 27 31 void Save();32 void Save(string filename);33 void SaveAsynchronous();34 void SaveAsynchronous(string filename);35 36 28 event EventHandler FilenameChanged; 37 event EventHandler SaveOperationStarted;38 event EventHandler<EventArgs<Exception>> SaveOperationFinished;39 29 } 40 30 } -
trunk/sources/HeuristicLab.Common/3.2/Content/StorableContent.cs
r3437 r3483 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 using System.Threading;27 using System.Reflection;28 23 29 24 namespace 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 { 40 26 private string filename; 41 27 public string Filename { 42 get { return this.filename; }28 get { return filename; } 43 29 set { 44 if ( this.filename != value) {45 this.filename = value;46 this.OnFilenameChanged();30 if (!filename.Equals(value)) { 31 filename = value; 32 OnFilenameChanged(); 47 33 } 48 34 } 49 35 } 50 36 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; 83 39 } 84 40 … … 88 44 if (handler != null) handler(this, EventArgs.Empty); 89 45 } 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 }100 46 } 101 47 } -
trunk/sources/HeuristicLab.Common/3.2/HeuristicLab.Common-3.2.csproj
r3437 r3483 89 89 <None Include="HeuristicLabCommonPlugin.cs.frame" /> 90 90 <Compile Include="Cloner.cs" /> 91 <Compile Include="Content\Content.cs" />92 91 <Compile Include="Content\ContentManager.cs" /> 93 92 <Compile Include="Content\IContent.cs" /> -
trunk/sources/HeuristicLab.Common/3.3/Content/ContentManager.cs
r3424 r3483 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 using System.Threading;27 23 28 24 namespace HeuristicLab.Common { 29 25 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; 31 32 } 32 33 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; 36 41 } 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); 41 57 } 58 protected abstract IStorableContent LoadContent(string filename); 42 59 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; 45 64 } 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); 48 79 } 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); 90 81 } 91 82 } -
trunk/sources/HeuristicLab.Common/3.3/Content/IContent.cs
r3431 r3483 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 27 22 namespace HeuristicLab.Common { 28 public interface IContent : IDeepCloneable{ }23 public interface IContent { } 29 24 } -
trunk/sources/HeuristicLab.Common/3.3/Content/IStorableContent.cs
r3412 r3483 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 23 27 24 namespace HeuristicLab.Common { … … 29 26 string Filename { get; set; } 30 27 31 void Save();32 void Save(string filename);33 void SaveAsynchronous();34 void SaveAsynchronous(string filename);35 36 28 event EventHandler FilenameChanged; 37 event EventHandler SaveOperationStarted;38 event EventHandler<EventArgs<Exception>> SaveOperationFinished;39 29 } 40 30 } -
trunk/sources/HeuristicLab.Common/3.3/Content/StorableContent.cs
r3412 r3483 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 using System.Threading;27 using System.Reflection;28 23 29 24 namespace 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 { 40 26 private string filename; 41 27 public string Filename { 42 get { return this.filename; }28 get { return filename; } 43 29 set { 44 if ( this.filename != value) {45 this.filename = value;46 this.OnFilenameChanged();30 if (!filename.Equals(value)) { 31 filename = value; 32 OnFilenameChanged(); 47 33 } 48 34 } 49 35 } 50 36 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; 83 39 } 84 40 … … 88 44 if (handler != null) handler(this, EventArgs.Empty); 89 45 } 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 }100 46 } 101 47 } -
trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj
r3462 r3483 89 89 <None Include="HeuristicLabCommonPlugin.cs.frame" /> 90 90 <Compile Include="Cloner.cs" /> 91 <Compile Include="Content\Content.cs" />92 91 <Compile Include="Content\ContentManager.cs" /> 93 92 <Compile Include="Content\IStorableContent.cs" /> -
trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.cs
r3456 r3483 35 35 [Content(typeof(ItemArray<>), true)] 36 36 [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 { 38 38 protected TypeSelectorDialog typeSelectorDialog; 39 39 -
trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs
r3456 r3483 32 32 [Content(typeof(ItemCollection<>), true)] 33 33 [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 { 35 35 protected TypeSelectorDialog typeSelectorDialog; 36 36 -
trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs
r3456 r3483 35 35 [Content(typeof(ItemList<>), true)] 36 36 [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 { 38 38 protected TypeSelectorDialog typeSelectorDialog; 39 39 -
trunk/sources/HeuristicLab.Core/3.3/Collections/ItemArray.cs
r3431 r3483 36 36 [Item("ItemArray<T>", "Represents an array of items.")] 37 37 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 38 49 public virtual string ItemName { 39 50 get { return ItemAttribute.GetName(this.GetType()); } … … 77 88 } 78 89 90 public event EventHandler FilenameChanged; 91 protected virtual void OnFilenameChanged() { 92 EventHandler handler = FilenameChanged; 93 if (handler != null) handler(this, EventArgs.Empty); 94 } 79 95 public event EventHandler ItemImageChanged; 80 96 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ItemCollection.cs
r3431 r3483 33 33 [Item("ItemCollection<T>", "Represents a collection of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 73 84 } 74 85 86 public event EventHandler FilenameChanged; 87 protected virtual void OnFilenameChanged() { 88 EventHandler handler = FilenameChanged; 89 if (handler != null) handler(this, EventArgs.Empty); 90 } 75 91 public event EventHandler ItemImageChanged; 76 92 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ItemDictionary.cs
r3431 r3483 33 33 [Item("ItemDictionary<TKey, TValue>", "Represents a dictionary of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 74 85 } 75 86 87 public event EventHandler FilenameChanged; 88 protected virtual void OnFilenameChanged() { 89 EventHandler handler = FilenameChanged; 90 if (handler != null) handler(this, EventArgs.Empty); 91 } 76 92 public event EventHandler ItemImageChanged; 77 93 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ItemList.cs
r3431 r3483 36 36 [Item("ItemList<T>", "Represents a list of items.")] 37 37 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 38 49 public virtual string ItemName { 39 50 get { return ItemAttribute.GetName(this.GetType()); } … … 76 87 } 77 88 89 public event EventHandler FilenameChanged; 90 protected virtual void OnFilenameChanged() { 91 EventHandler handler = FilenameChanged; 92 if (handler != null) handler(this, EventArgs.Empty); 93 } 78 94 public event EventHandler ItemImageChanged; 79 95 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ItemSet.cs
r3431 r3483 36 36 [Item("ItemSet<T>", "Represents a set of items.")] 37 37 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 38 49 public virtual string ItemName { 39 50 get { return ItemAttribute.GetName(this.GetType()); } … … 75 86 } 76 87 88 public event EventHandler FilenameChanged; 89 protected virtual void OnFilenameChanged() { 90 EventHandler handler = FilenameChanged; 91 if (handler != null) handler(this, EventArgs.Empty); 92 } 77 93 public event EventHandler ItemImageChanged; 78 94 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/KeyedItemCollection.cs
r3431 r3483 32 32 [StorableClass] 33 33 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 34 45 public virtual string ItemName { 35 46 get { return ItemAttribute.GetName(this.GetType()); } … … 75 86 } 76 87 88 public event EventHandler FilenameChanged; 89 protected virtual void OnFilenameChanged() { 90 EventHandler handler = FilenameChanged; 91 if (handler != null) handler(this, EventArgs.Empty); 92 } 77 93 public event EventHandler ItemImageChanged; 78 94 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemArray.cs
r3431 r3483 33 33 [Item("ReadOnlyItemArray<T>", "Represents a read-only array of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 74 85 } 75 86 87 public event EventHandler FilenameChanged; 88 protected virtual void OnFilenameChanged() { 89 EventHandler handler = FilenameChanged; 90 if (handler != null) handler(this, EventArgs.Empty); 91 } 76 92 public event EventHandler ItemImageChanged; 77 93 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemCollection.cs
r3431 r3483 33 33 [Item("ReadOnlyItemCollection<T>", "Represents a read-only collection of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 74 85 } 75 86 87 public event EventHandler FilenameChanged; 88 protected virtual void OnFilenameChanged() { 89 EventHandler handler = FilenameChanged; 90 if (handler != null) handler(this, EventArgs.Empty); 91 } 76 92 public event EventHandler ItemImageChanged; 77 93 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemDictionary.cs
r3431 r3483 33 33 [Item("ReadOnlyItemDictionary<TKey, TValue>", "Represents a read-only dictionary of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 74 85 } 75 86 87 public event EventHandler FilenameChanged; 88 protected virtual void OnFilenameChanged() { 89 EventHandler handler = FilenameChanged; 90 if (handler != null) handler(this, EventArgs.Empty); 91 } 76 92 public event EventHandler ItemImageChanged; 77 93 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemList.cs
r3431 r3483 33 33 [Item("ReadOnlyItemList<T>", "Represents a read-only list of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 74 85 } 75 86 87 public event EventHandler FilenameChanged; 88 protected virtual void OnFilenameChanged() { 89 EventHandler handler = FilenameChanged; 90 if (handler != null) handler(this, EventArgs.Empty); 91 } 76 92 public event EventHandler ItemImageChanged; 77 93 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyItemSet.cs
r3431 r3483 33 33 [Item("ReadOnlyItemSet<T>", "Represents a read-only set of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 74 85 } 75 86 87 public event EventHandler FilenameChanged; 88 protected virtual void OnFilenameChanged() { 89 EventHandler handler = FilenameChanged; 90 if (handler != null) handler(this, EventArgs.Empty); 91 } 76 92 public event EventHandler ItemImageChanged; 77 93 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/Collections/ReadOnlyKeyedItemCollection.cs
r3431 r3483 33 33 [Item("ReadOnlyKeyedItemCollection<TKey, TItem>", "Represents a read-only keyed collection of items.")] 34 34 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 35 46 public virtual string ItemName { 36 47 get { return ItemAttribute.GetName(this.GetType()); } … … 74 85 } 75 86 87 public event EventHandler FilenameChanged; 88 protected virtual void OnFilenameChanged() { 89 EventHandler handler = FilenameChanged; 90 if (handler != null) handler(this, EventArgs.Empty); 91 } 76 92 public event EventHandler ItemImageChanged; 77 93 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r3390 r3483 123 123 <Compile Include="Collections\ValueParameterCollection.cs" /> 124 124 <Compile Include="Collections\VariableCollection.cs" /> 125 <Compile Include="PersistenceContentManager.cs" /> 125 126 <Compile Include="Interfaces\IKeyedItemCollection.cs" /> 126 127 <Compile Include="Interfaces\IItemList.cs" /> -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IItem.cs
r3368 r3483 28 28 /// Interface to represent (almost) every HeuristicLab object (an object, an operator,...). 29 29 /// </summary> 30 public interface IItem : I Content, IDeepCloneable {30 public interface IItem : IStorableContent, IDeepCloneable { 31 31 string ItemName { get; } 32 32 string ItemDescription { get; } -
trunk/sources/HeuristicLab.Core/3.3/Item.cs
r3431 r3483 31 31 [StorableClass] 32 32 [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 34 45 public virtual string ItemName { 35 46 get { return ItemAttribute.GetName(this.GetType()); } … … 42 53 } 43 54 44 protected Item() : base() { } 55 protected Item() { 56 filename = string.Empty; 57 } 45 58 [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 } 47 71 48 72 /// <summary> … … 54 78 } 55 79 80 public event EventHandler FilenameChanged; 81 protected virtual void OnFilenameChanged() { 82 EventHandler handler = FilenameChanged; 83 if (handler != null) handler(this, EventArgs.Empty); 84 } 56 85 public event EventHandler ItemImageChanged; 57 86 protected virtual void OnItemImageChanged() { -
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Tests/TestRandom.cs
r3431 r3483 134 134 135 135 #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 136 149 } 137 150 } -
trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Tests/TestRandom.cs
r3431 r3483 134 134 135 135 #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 136 149 } 137 150 } -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Tests/Random.cs
r3431 r3483 134 134 135 135 #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 136 149 } 137 150 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/TestRandom.cs
r3431 r3483 134 134 135 135 #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 136 149 } 137 150 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ContentView.cs
r3416 r3483 47 47 if (this.content != null) this.RegisterContentEvents(); 48 48 this.OnContentChanged(); 49 this.OnChanged(); 49 50 } 50 51 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ContentView.cs
r3437 r3483 47 47 if (this.content != null) this.RegisterContentEvents(); 48 48 this.OnContentChanged(); 49 this.OnChanged(); 49 50 } 50 51 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs
r3456 r3483 34 34 [Content(typeof(RunCollection), true)] 35 35 [Content(typeof(IItemCollection<IRun>), false)] 36 public partial class RunCollectionView : AsynchronousContentView {36 public partial class RunCollectionView : ItemView { 37 37 public new IItemCollection<IRun> Content { 38 38 get { return (IItemCollection<IRun>)base.Content; } -
trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs
r3416 r3483 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.IO;25 23 using System.Linq; 26 using System.Threading;27 24 using System.Windows.Forms; 25 using HeuristicLab.Common; 28 26 using HeuristicLab.Core.Views; 29 27 using HeuristicLab.MainForm; 30 using HeuristicLab.MainForm.WindowsForms;31 using HeuristicLab.Persistence.Default.Xml;32 28 33 29 namespace HeuristicLab.Optimizer { 34 30 internal static class FileManager { 35 36 #region Private Class FileInfo37 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 #endregion53 54 private static Dictionary<IContentView, FileInfo> files;55 31 private static NewItemDialog newItemDialog; 56 32 private static OpenFileDialog openFileDialog; 57 33 private static SaveFileDialog saveFileDialog; 58 private static int waitingCursors;59 private static int newDocumentsCounter;60 34 61 35 static FileManager() { 62 files = new Dictionary<IContentView, FileInfo>();63 36 newItemDialog = null; 64 37 openFileDialog = null; 65 38 saveFileDialog = null; 66 waitingCursors = 0;67 newDocumentsCounter = 1;68 // NOTE: Events fired by the main form are registered in HeuristicLabOptimizerApplication.69 39 } 70 40 … … 73 43 if (newItemDialog.ShowDialog() == DialogResult.OK) { 74 44 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(); 84 47 } 85 48 } … … 96 59 97 60 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(); 100 81 } 101 82 } … … 108 89 } 109 90 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)) 112 94 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); 118 99 } 119 100 } 120 101 } 121 122 102 public static void SaveAs() { 123 103 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; … … 127 107 } 128 108 public static void SaveAs(IContentView view) { 129 if (!view.Locked) { 109 IStorableContent content = view.Content as IStorableContent; 110 if (!view.Locked && (content != null)) { 130 111 if (saveFileDialog == null) { 131 112 saveFileDialog = new SaveFileDialog(); … … 135 116 saveFileDialog.FilterIndex = 2; 136 117 } 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; 148 119 149 120 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 121 ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor(); 122 ((Form)MainFormManager.MainForm).Enabled = false; 150 123 if (saveFileDialog.FilterIndex == 1) { 151 SaveItemAsync(view, saveFileDialog.FileName, 0);124 ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted); 152 125 } else { 153 SaveItemAsync(view, saveFileDialog.FileName, 9);126 ContentManager.SaveAsync(content, saveFileDialog.FileName, true, SavingCompleted); 154 127 } 155 128 } 156 129 } 157 130 } 158 159 131 public static void SaveAll() { 160 132 foreach (IContentView view in MainFormManager.MainForm.Views.OfType<IContentView>()) 161 133 Save(view); 162 134 } 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 } 168 149 } 169 150 170 #region Asynchronous Save/Load Operations171 151 private static void Invoke(Action a) { 172 152 Form form = MainFormManager.MainForm as Form; … … 176 156 a.Invoke(); 177 157 } 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 #endregion257 158 } 258 159 } -
trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/CopyToClipboardMenuItem.cs
r3416 r3483 39 39 get { return 2100; } 40 40 } 41 public override Keys ShortCutKeys {42 get { return Keys.Control | Keys.C; }43 }44 41 45 42 protected override void OnToolStripItemSet(EventArgs e) { … … 48 45 protected override void OnActiveViewChanged(object sender, EventArgs e) { 49 46 ItemView activeView = MainFormManager.MainForm.ActiveView as ItemView; 50 ToolStripItem.Enabled = (activeView != null) && ( !activeView.Locked);47 ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) && !activeView.Locked; 51 48 } 52 49 53 50 public override void Execute() { 54 51 ItemView activeView = MainFormManager.MainForm.ActiveView as ItemView; 55 if ((activeView != null) && ( !activeView.Locked)) {52 if ((activeView != null) && (activeView.Content != null) && !activeView.Locked) { 56 53 Clipboard<IItem> clipboard = ((OptimizerMainForm)MainFormManager.MainForm).Clipboard; 57 54 clipboard.AddItem((IItem)activeView.Content.Clone()); -
trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAllMenuItem.cs
r3416 r3483 25 25 using System.Linq; 26 26 using System.Windows.Forms; 27 using HeuristicLab.Common; 27 28 using HeuristicLab.MainForm; 28 29 … … 47 48 protected override void OnActiveViewChanged(object sender, EventArgs e) { 48 49 var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>() 50 where v.Content != null 51 where v.Content is IStorableContent 49 52 where !v.Locked 50 53 select v; -
trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAsMenuItem.cs
r3416 r3483 23 23 using System.Collections.Generic; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.MainForm; 26 27 … … 45 46 protected override void OnActiveViewChanged(object sender, EventArgs e) { 46 47 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; 48 50 } 49 51 -
trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveMenuItem.cs
r3416 r3483 24 24 using System.Drawing; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.MainForm; 27 28 … … 49 50 protected override void OnActiveViewChanged(object sender, EventArgs e) { 50 51 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; 52 54 } 53 55 -
trunk/sources/HeuristicLab.Optimizer/3.3/OptimizerMainForm.cs
r3395 r3483 32 32 namespace HeuristicLab.Optimizer { 33 33 internal partial class OptimizerMainForm : DockingMainForm { 34 private string title; 35 private int appStartingCursors; 36 private int waitingCursors; 37 34 38 private Clipboard<IItem> clipboard; 35 39 public Clipboard<IItem> Clipboard { … … 40 44 : base() { 41 45 InitializeComponent(); 46 appStartingCursors = 0; 47 waitingCursors = 0; 42 48 } 43 49 public OptimizerMainForm(Type userInterfaceItemType) 44 50 : base(userInterfaceItemType) { 45 51 InitializeComponent(); 52 appStartingCursors = 0; 53 waitingCursors = 0; 46 54 } 47 55 public OptimizerMainForm(Type userInterfaceItemType, bool showViewsInViewHost) … … 54 62 AssemblyFileVersionAttribute version = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true). 55 63 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()); 59 69 60 70 clipboard = new Clipboard<IItem>(); … … 73 83 } 74 84 } 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 75 144 } 76 145 } -
trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveAllToolBarItem.cs
r3416 r3483 24 24 using System.Linq; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.MainForm; 27 28 … … 46 47 protected override void OnActiveViewChanged(object sender, EventArgs e) { 47 48 var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>() 49 where v.Content != null 50 where v.Content is IStorableContent 48 51 where !v.Locked 49 52 select v; -
trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveToolBarItem.cs
r3416 r3483 23 23 using System.Drawing; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.MainForm; 26 27 … … 45 46 protected override void OnActiveViewChanged(object sender, EventArgs e) { 46 47 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; 48 50 } 49 51
Note: See TracChangeset
for help on using the changeset viewer.