Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/17/10 16:42:58 (14 years ago)
Author:
mkommend
Message:

Removed cloning of saved contents and refactored FileManager (ticket #1143).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs

    r4068 r4245  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Windows.Forms;
    2425using HeuristicLab.Common;
     
    4243      if (newItemDialog.ShowDialog() == DialogResult.OK) {
    4344        IView view = MainFormManager.MainForm.ShowContent(newItemDialog.Item);
    44         if (view == null) MessageBox.Show("There is no view for the new item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
     45        if (view == null)
     46          ErrorHandling.ShowErrorDialog("There is no view for the new item. It cannot be displayed.", new InvalidOperationException("No View Available"));
    4547      }
    4648    }
     
    6668      try {
    6769        if (error != null) throw error;
    68         Invoke(delegate() {
    69           IView view = MainFormManager.MainForm.ShowContent(content);
    70           if (view == null) MessageBox.Show("There is no view for the loaded item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
    71         });
     70        IView view = MainFormManager.MainForm.ShowContent(content);
     71        if (view == null)
     72          ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
    7273      }
    7374      catch (Exception ex) {
     
    8788    private static void Save(IContentView view) {
    8889      IStorableContent content = view.Content as IStorableContent;
    89       if (!view.Locked && (content != null)) {
     90      if (!view.Locked && content != null) {
    9091        if (string.IsNullOrEmpty(content.Filename))
    9192          SaveAs(view);
    9293        else {
    9394          ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor();
     95          var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList();
     96          views.ForEach(v => v.ReadOnly = true);
     97          views.ForEach(v => v.Locked = true);
    9498          ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted);
    9599        }
     
    104108    public static void SaveAs(IContentView view) {
    105109      IStorableContent content = view.Content as IStorableContent;
    106       if (!view.Locked && (content != null)) {
     110      if (!view.Locked && content != null) {
    107111        if (saveFileDialog == null) {
    108112          saveFileDialog = new SaveFileDialog();
     
    116120        if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    117121          ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor();
     122          var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList();
     123          views.ForEach(v => v.ReadOnly = true);
     124          views.ForEach(v => v.Locked = true);
    118125          if (saveFileDialog.FilterIndex == 1) {
    119126            ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted);
     
    126133    private static void SavingCompleted(IStorableContent content, Exception error) {
    127134      try {
     135        var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList();
     136        views.ForEach(v => v.ReadOnly = false);
     137        views.ForEach(v => v.Locked = false);
    128138        if (error != null) throw error;
    129         Invoke(delegate() {
    130           ((OptimizerMainForm)MainFormManager.MainForm).UpdateTitle();
    131         });
     139        MainFormManager.GetMainForm<OptimizerMainForm>().UpdateTitle();
    132140      }
    133141      catch (Exception ex) {
     
    138146      }
    139147    }
    140 
    141     private static void Invoke(Action a) {
    142       Form form = MainFormManager.MainForm as Form;
    143       if (form.InvokeRequired)
    144         form.Invoke(a);
    145       else
    146         a.Invoke();
    147     }
    148148  }
    149149}
Note: See TracChangeset for help on using the changeset viewer.