Changeset 2961 for trunk/sources/HeuristicLab.Optimizer
- Timestamp:
- 03/08/10 00:20:29 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimizer/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs
r2960 r2961 26 26 using System.Threading; 27 27 using System.Windows.Forms; 28 using HeuristicLab.Core;29 28 using HeuristicLab.Core.Views; 30 29 using HeuristicLab.MainForm; … … 108 107 } 109 108 private static void Save(IContentView view) { 110 if ((!files.ContainsKey(view)) || (!File.Exists(files[view].Filename))) { 111 SaveAs(view); 112 } else { 113 if (files[view].Compressed) 114 SaveItemAsync(view, files[view].Filename, 9); 115 else 116 SaveItemAsync(view, files[view].Filename, 0); 109 if (view.SaveEnabled) { 110 if ((!files.ContainsKey(view)) || (!File.Exists(files[view].Filename))) { 111 SaveAs(view); 112 } else { 113 if (files[view].Compressed) 114 SaveItemAsync(view, files[view].Filename, 9); 115 else 116 SaveItemAsync(view, files[view].Filename, 0); 117 } 117 118 } 118 119 } … … 125 126 } 126 127 public static void SaveAs(IContentView view) { 127 if (saveFileDialog == null) { 128 saveFileDialog = new SaveFileDialog(); 129 saveFileDialog.Title = "Save Item"; 130 saveFileDialog.DefaultExt = "hl"; 131 saveFileDialog.Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*"; 132 saveFileDialog.FilterIndex = 2; 133 } 134 135 if (!files.ContainsKey(view)) { 136 files.Add(view, new FileInfo()); 137 saveFileDialog.FileName = view.Caption; 138 } else { 139 saveFileDialog.FileName = files[view].Filename; 140 } 141 if (! files[view].Compressed) 142 saveFileDialog.FilterIndex = 1; 143 else 144 saveFileDialog.FilterIndex = 2; 145 146 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 147 if (saveFileDialog.FilterIndex == 1) { 148 SaveItemAsync(view, saveFileDialog.FileName, 0); 128 if (view.SaveEnabled) { 129 if (saveFileDialog == null) { 130 saveFileDialog = new SaveFileDialog(); 131 saveFileDialog.Title = "Save Item"; 132 saveFileDialog.DefaultExt = "hl"; 133 saveFileDialog.Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*"; 134 saveFileDialog.FilterIndex = 2; 135 } 136 137 if (!files.ContainsKey(view)) { 138 files.Add(view, new FileInfo()); 139 saveFileDialog.FileName = view.Caption; 149 140 } else { 150 SaveItemAsync(view, saveFileDialog.FileName, 9); 141 saveFileDialog.FileName = files[view].Filename; 142 } 143 if (!files[view].Compressed) 144 saveFileDialog.FilterIndex = 1; 145 else 146 saveFileDialog.FilterIndex = 2; 147 148 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 149 if (saveFileDialog.FilterIndex == 1) { 150 SaveItemAsync(view, saveFileDialog.FileName, 0); 151 } else { 152 SaveItemAsync(view, saveFileDialog.FileName, 9); 153 } 151 154 } 152 155 } … … 154 157 155 158 public static void SaveAll() { 156 var views = from v in MainFormManager.MainForm.Views 157 where v is IContentView 158 select v as IContentView; 159 160 foreach (IContentView view in views) { 161 ItemView itemView = view as ItemView; 162 if ((itemView == null) || (itemView.EnableFileOperations)) { 163 Save(view); 164 } 165 } 159 foreach (IContentView view in MainFormManager.MainForm.Views.OfType<IContentView>()) 160 Save(view); 166 161 } 167 162 … … 211 206 try { 212 207 SetWaitingCursor(); 213 IItem item = (IItem)XmlParser.Deserialize(filename);208 object content = XmlParser.Deserialize(filename); 214 209 Invoke(delegate() { 215 IContentView view = MainFormManager.CreateDefaultView( item) as IContentView;210 IContentView view = MainFormManager.CreateDefaultView(content) as IContentView; 216 211 if (view == null) { 217 212 MessageBox.Show("There is no view for the loaded item. It cannot be displayed. ", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error); -
trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAllMenuItem.cs
r2960 r2961 25 25 using System.Linq; 26 26 using System.Windows.Forms; 27 using HeuristicLab.Core;28 using HeuristicLab.Core.Views;29 27 using HeuristicLab.MainForm; 30 28 … … 48 46 } 49 47 protected override void OnActiveViewChanged(object sender, EventArgs e) { 50 var views = from v in MainFormManager.MainForm.Views 51 where v is IContentView 52 where ((v is ItemView) && ((ItemView)v).EnableFileOperations) || (!(v is ItemView)) 48 var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>() 49 where v.SaveEnabled 53 50 select v; 54 51 ToolStripItem.Enabled = views.FirstOrDefault() != null; -
trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAsMenuItem.cs
r2960 r2961 23 23 using System.Collections.Generic; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Core;26 using HeuristicLab.Core.Views;27 25 using HeuristicLab.MainForm; 28 26 … … 47 45 protected override void OnActiveViewChanged(object sender, EventArgs e) { 48 46 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 49 bool enable = activeView != null; 50 ItemView itemView = MainFormManager.MainForm.ActiveView as ItemView; 51 if ((enable) && (itemView != null)) enable = itemView.EnableFileOperations; 52 ToolStripItem.Enabled = enable; 47 ToolStripItem.Enabled = (activeView != null) && (activeView.SaveEnabled); 53 48 } 54 49 -
trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveMenuItem.cs
r2960 r2961 24 24 using System.Drawing; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Core;27 using HeuristicLab.Core.Views;28 26 using HeuristicLab.MainForm; 29 27 … … 51 49 protected override void OnActiveViewChanged(object sender, EventArgs e) { 52 50 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 53 bool enable = activeView != null; 54 ItemView itemView = MainFormManager.MainForm.ActiveView as ItemView; 55 if ((enable) && (itemView != null)) enable = itemView.EnableFileOperations; 56 ToolStripItem.Enabled = enable; 51 ToolStripItem.Enabled = (activeView != null) && (activeView.SaveEnabled); 57 52 } 58 53 -
trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveAllToolBarItem.cs
r2960 r2961 24 24 using System.Linq; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Core;27 using HeuristicLab.Core.Views;28 26 using HeuristicLab.MainForm; 29 27 … … 47 45 } 48 46 protected override void OnActiveViewChanged(object sender, EventArgs e) { 49 var views = from v in MainFormManager.MainForm.Views 50 where v is IContentView 51 where ((v is ItemView) && ((ItemView)v).EnableFileOperations) || (!(v is ItemView)) 47 var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>() 48 where v.SaveEnabled 52 49 select v; 53 50 ToolStripItem.Enabled = views.FirstOrDefault() != null; -
trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveToolBarItem.cs
r2960 r2961 23 23 using System.Drawing; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Core;26 using HeuristicLab.Core.Views;27 25 using HeuristicLab.MainForm; 28 26 … … 47 45 protected override void OnActiveViewChanged(object sender, EventArgs e) { 48 46 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 49 bool enable = activeView != null; 50 ItemView itemView = MainFormManager.MainForm.ActiveView as ItemView; 51 if ((enable) && (itemView != null)) enable = itemView.EnableFileOperations; 52 ToolStripItem.Enabled = enable; 47 ToolStripItem.Enabled = (activeView != null) && (activeView.SaveEnabled); 53 48 } 54 49
Note: See TracChangeset
for help on using the changeset viewer.