Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/14 17:33:22 (11 years ago)
Author:
jkarder
Message:

#2136:

  • refactored HLScriptGeneration to separate outputs from different running HL scripts.
  • added persistence support for HLScripts and fixed cloning
  • added code completion for all types in the currently loaded assemblies
  • merged trunk changes
Location:
branches/HLScript
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HLScript

  • branches/HLScript/HeuristicLab.HLScript.Views/3.3/VariableStoreView.cs

    r10332 r10358  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.Drawing;
    2526using System.Linq;
    2627using System.Windows.Forms;
     
    3132using HeuristicLab.MainForm;
    3233using HeuristicLab.MainForm.WindowsForms;
     34using HeuristicLab.Persistence.Core;
     35using HeuristicLab.Persistence.Default.Xml;
    3336using HeuristicLab.PluginInfrastructure;
    3437
     
    5356      InitializeComponent();
    5457      itemListViewItemMapping = new Dictionary<string, ListViewItem>();
     58      variableListView.SmallImageList.Images.AddRange(new Image[] {
     59        HeuristicLab.Common.Resources.VSImageLibrary.Error,
     60        HeuristicLab.Common.Resources.VSImageLibrary.Object,
     61        HeuristicLab.Common.Resources.VSImageLibrary.Nothing
     62      });
    5563    }
    5664
     
    101109        variableListView.Enabled = false;
    102110      } else {
    103         addButton.Enabled = /*!Content.IsReadOnly &&*/ !ReadOnly;
     111        addButton.Enabled = !Locked && !ReadOnly;
    104112        sortAscendingButton.Enabled = variableListView.Items.Count > 1;
    105113        sortDescendingButton.Enabled = variableListView.Items.Count > 1;
    106         removeButton.Enabled = /*!Content.IsReadOnly &&*/ !ReadOnly && variableListView.SelectedItems.Count > 0;
     114        removeButton.Enabled = !Locked && !ReadOnly && variableListView.SelectedItems.Count > 0;
    107115        variableListView.Enabled = true;
    108116      }
     
    130138      string value = (variable.Value ?? "null").ToString();
    131139      string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();
    132       var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { ToolTipText = GetToolTipText(variable), Tag = variable };
    133       variableListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Object);
    134       listViewItem.ImageIndex = variableListView.SmallImageList.Images.Count - 1;
     140      bool serializable = IsSerializable(variable);
     141      var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { ToolTipText = GetToolTipText(variable, serializable), Tag = variable };
     142      if (serializable) {
     143        listViewItem.ImageIndex = variable.Value == null ? 2 : 1;
     144      } else listViewItem.ImageIndex = 0;
    135145      variableListView.Items.Add(listViewItem);
    136146      itemListViewItemMapping[variable.Key] = listViewItem;
     
    160170        string value = (variable.Value ?? "null").ToString();
    161171        string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();
     172        bool serializable = IsSerializable(variable);
     173        if (serializable) {
     174          listViewItem.ImageIndex = variable.Value == null ? 2 : 1;
     175        } else listViewItem.ImageIndex = 0;
    162176        listViewItem.SubItems[1].Text = value;
    163177        listViewItem.SubItems[2].Text = type;
    164         listViewItem.ToolTipText = GetToolTipText(variable);
     178        listViewItem.ToolTipText = GetToolTipText(variable, serializable);
    165179        listViewItem.Tag = variable;
    166180      } else throw new ArgumentException("A variable with the specified name does not exist.", "variable");
     
    169183    #region ListView Events
    170184    protected virtual void variableListView_SelectedIndexChanged(object sender, EventArgs e) {
    171       removeButton.Enabled = (Content != null) /*&& !Content.IsReadOnly*/ && !ReadOnly && variableListView.SelectedItems.Count > 0;
     185      removeButton.Enabled = (Content != null) && !Locked && !ReadOnly && variableListView.SelectedItems.Count > 0;
    172186      AdjustListViewColumnSizes();
    173187    }
    174188    protected virtual void variableListView_KeyDown(object sender, KeyEventArgs e) {
    175189      if (e.KeyCode == Keys.Delete) {
    176         if ((variableListView.SelectedItems.Count > 0) /*&& !Content.IsReadOnly*/ && !ReadOnly) {
     190        if ((variableListView.SelectedItems.Count > 0) && !Locked && !ReadOnly) {
    177191          foreach (ListViewItem item in variableListView.SelectedItems)
    178192            Content.Remove(item.Text);
     
    207221          if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]);
    208222          else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items);
    209           if (/*Content.IsReadOnly ||*/ ReadOnly) {
     223          if (ReadOnly) {
    210224            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    211225          } else {
     
    220234    protected virtual void variableListView_DragEnter(object sender, DragEventArgs e) {
    221235      validDragOperation = false;
    222       if (/*!Content.IsReadOnly &&*/ !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is object)) {
     236      if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is object)) {
    223237        validDragOperation = true;
    224       } else if (/*!Content.IsReadOnly &&*/ !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {
     238      } else if (!Locked && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {
    225239        validDragOperation = true;
    226240        IEnumerable items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     
    361375          item.SubItems[1].Text = value;
    362376          item.SubItems[2].Text = variable.Value.Value.GetType().ToString();
    363           item.ToolTipText = GetToolTipText(variable.Value);
     377          item.ToolTipText = GetToolTipText(variable.Value, item.ImageIndex == 0);
    364378          return;
    365379        }
     
    382396    protected virtual void RebuildImageList() {
    383397      variableListView.SmallImageList.Images.Clear();
     398      variableListView.SmallImageList.Images.AddRange(new Image[] {
     399        HeuristicLab.Common.Resources.VSImageLibrary.Error,
     400        HeuristicLab.Common.Resources.VSImageLibrary.Object,
     401        HeuristicLab.Common.Resources.VSImageLibrary.Nothing
     402      });
    384403      foreach (ListViewItem listViewItem in variableListView.Items) {
    385         object item = listViewItem.Tag as object;
    386         variableListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : HeuristicLab.Common.Resources.VSImageLibrary.Object);//item.ItemImage);
    387         listViewItem.ImageIndex = variableListView.SmallImageList.Images.Count - 1;
    388       }
    389     }
    390 
    391     private string GetToolTipText(KeyValuePair<string, object> variable) {
     404        var variable = (KeyValuePair<string, object>)listViewItem.Tag;
     405        bool serializable = IsSerializable(variable);
     406        if (serializable) {
     407          listViewItem.ImageIndex = variable.Value == null ? 2 : 1;
     408        } else listViewItem.ImageIndex = 0;
     409      }
     410    }
     411
     412    private string GetToolTipText(KeyValuePair<string, object> variable, bool serializable) {
    392413      if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable");
    393414      string value = (variable.Value ?? "null").ToString();
     415      string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();
    394416      string[] lines = {
    395417        "Name: " + variable.Key,
    396418        "Value: " + value,
    397         "Type: " + variable.Value.GetType()
     419        "Type: " + type
    398420      };
    399       return string.Join(Environment.NewLine, lines);
     421      string toolTipText = string.Join(Environment.NewLine, lines);
     422      if (!serializable)
     423        toolTipText += Environment.NewLine + "CAUTION: Type is not serializable!";
     424      return toolTipText;
    400425    }
    401426
     
    411436      return defaultName;
    412437    }
     438
     439    private bool IsSerializable(KeyValuePair<string, object> variable) {
     440      var ser = new Serializer(variable, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()), "ROOT", true);
     441      try {
     442        return ser.Count() > 0;
     443      } catch (PersistenceException) {
     444        return false;
     445      }
     446    }
    413447    #endregion
    414448  }
Note: See TracChangeset for help on using the changeset viewer.