Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/25/14 03:26:00 (10 years ago)
Author:
swagner
Message:

#2205: Merged changes r11062:11557 from trunk/sources into branches/OptimizationNetworks

Location:
branches/OptimizationNetworks
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks

  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs

    r10857 r11576  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj

    r10731 r11576  
    169169  </ItemGroup>
    170170  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    171   <PropertyGroup>
    172     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     171   <PropertyGroup>
     172    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    173173set ProjectDir=$(ProjectDir)
    174174set SolutionDir=$(SolutionDir)
    175175set Outdir=$(Outdir)
    176176
    177 call PreBuildEvent.cmd</PreBuildEvent>
     177call PreBuildEvent.cmd
     178</PreBuildEvent>
     179    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     180export ProjectDir=$(ProjectDir)
     181export SolutionDir=$(SolutionDir)
     182
     183$SolutionDir/PreBuildEvent.sh
     184</PreBuildEvent>
    178185  </PropertyGroup>
    179186  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/Plugin.cs.frame

    r10506 r11576  
    2323
    2424namespace HeuristicLab.Scripting.Views {
    25   [Plugin("HeuristicLab.Scripting.Views", "3.3.9.$WCREV$")]
     25  [Plugin("HeuristicLab.Scripting.Views", "3.3.10.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Scripting.Views-3.3.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.CodeEditor", "3.3")]
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/Properties/AssemblyInfo.cs.frame

    r10506 r11576  
    5555// [assembly: AssemblyVersion("1.0.*")]
    5656[assembly: AssemblyVersion("3.3.0.0")]
    57 [assembly: AssemblyFileVersion("3.3.9.$WCREV$")]
     57[assembly: AssemblyFileVersion("3.3.10.$WCREV$")]
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/ScriptView.cs

    r10865 r11576  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4545    }
    4646
     47    public override bool ReadOnly {
     48      get { return codeEditor.ReadOnly || base.ReadOnly; }
     49      set { base.ReadOnly = codeEditor.ReadOnly = value; }
     50    }
     51
     52    public override bool Locked {
     53      get { return codeEditor.ReadOnly || base.Locked; }
     54      set { base.Locked = codeEditor.ReadOnly = value; }
     55    }
     56
    4757    protected override void RegisterContentEvents() {
    4858      base.RegisterContentEvents();
     
    8393      base.SetEnabledStateOfControls();
    8494      compileButton.Enabled = Content != null && !Locked && !ReadOnly;
    85       codeEditor.Enabled = Content != null && !Locked && !ReadOnly;
     95      codeEditor.Enabled = Content != null;
    8696    }
    8797
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/VariableStoreView.Designer.cs

    r10506 r11576  
    6666      this.variableListView.LabelEdit = true;
    6767      this.variableListView.Location = new System.Drawing.Point(6, 49);
    68       this.variableListView.MultiSelect = false;
    6968      this.variableListView.Name = "variableListView";
    7069      this.variableListView.ShowItemToolTips = true;
  • branches/OptimizationNetworks/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs

    r11014 r11576  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Linq;
    2625using System.Text.RegularExpressions;
     
    4039  [Content(typeof(VariableStore), true)]
    4140  public partial class VariableStoreView : AsynchronousContentView {
    42     protected Dictionary<string, ListViewItem> itemListViewItemMapping;
     41    #region Image Names
     42    private const string ErrorImageName = "Error";
     43    private const string WarningImageName = "Warning";
     44    private const string HeuristicLabObjectImageName = "HeuristicLabObject";
     45    private const string ObjectImageName = "Object";
     46    private const string NothingImageName = "Nothing";
     47    #endregion
     48
     49    protected readonly Dictionary<string, ListViewItem> itemListViewItemMapping;
     50    protected readonly Dictionary<Type, bool> serializableLookup;
    4351    protected TypeSelectorDialog typeSelectorDialog;
    4452    protected bool validDragOperation;
     
    5664      InitializeComponent();
    5765      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       });
     66      serializableLookup = new Dictionary<Type, bool>();
     67
     68      var images = variableListView.SmallImageList.Images;
     69      images.Add(ErrorImageName, Common.Resources.VSImageLibrary.Error);
     70      images.Add(WarningImageName, Common.Resources.VSImageLibrary.Warning);
     71      images.Add(HeuristicLabObjectImageName, Common.Resources.HeuristicLab.Icon.ToBitmap());
     72      images.Add(ObjectImageName, Common.Resources.VSImageLibrary.Object);
     73      images.Add(NothingImageName, Common.Resources.VSImageLibrary.Nothing);
    6374    }
    6475
     
    90101      variableListView.Items.Clear();
    91102      itemListViewItemMapping.Clear();
    92       RebuildImageList();
    93103      if (Content != null) {
    94104        Caption += " (" + Content.GetType().Name + ")";
     
    109119        variableListView.Enabled = false;
    110120      } else {
    111         addButton.Enabled = !Locked && !ReadOnly;
     121        bool enabled = !Locked && !ReadOnly;
     122        addButton.Enabled = enabled;
    112123        sortAscendingButton.Enabled = variableListView.Items.Count > 1;
    113124        sortDescendingButton.Enabled = variableListView.Items.Count > 1;
    114         removeButton.Enabled = !Locked && !ReadOnly && variableListView.SelectedItems.Count > 0;
    115         variableListView.Enabled = true;
    116         variableListView.LabelEdit = !Locked && !ReadOnly;
     125        removeButton.Enabled = enabled && variableListView.SelectedItems.Count > 0;
     126        variableListView.Enabled = enabled;
     127        variableListView.LabelEdit = enabled;
    117128      }
    118129    }
     
    137148    protected virtual void AddVariable(KeyValuePair<string, object> variable) {
    138149      if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable");
    139       string value = (variable.Value ?? "null").ToString();
    140       string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();
    141150      bool serializable = IsSerializable(variable);
    142       var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { ToolTipText = GetToolTipText(variable, serializable), Tag = variable };
    143       if (serializable) {
    144         listViewItem.ImageIndex = variable.Value == null ? 2 : 1;
    145       } else listViewItem.ImageIndex = 0;
     151
     152      var listViewItem = new ListViewItem();
     153      AssignVariableToListViewItem(listViewItem, variable);
     154      SetImageKey(listViewItem, serializable);
     155      SetToolTipText(listViewItem, serializable);
    146156      variableListView.Items.Add(listViewItem);
     157
    147158      itemListViewItemMapping[variable.Key] = listViewItem;
    148159      sortAscendingButton.Enabled = variableListView.Items.Count > 1;
     
    154165    protected virtual void RemoveVariable(KeyValuePair<string, object> variable) {
    155166      if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable");
     167
    156168      ListViewItem listViewItem;
    157       if (itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem)) {
    158         itemListViewItemMapping.Remove(variable.Key);
    159         variableListView.Items.Remove(listViewItem);
    160         sortAscendingButton.Enabled = variableListView.Items.Count > 1;
    161         sortDescendingButton.Enabled = variableListView.Items.Count > 1;
    162         var item = variable.Value as IItem;
    163         if (item != null) item.ToStringChanged -= item_ToStringChanged;
    164       }
     169      if (!itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem)) return;
     170
     171      itemListViewItemMapping.Remove(variable.Key);
     172      variableListView.Items.Remove(listViewItem);
     173      sortAscendingButton.Enabled = variableListView.Items.Count > 1;
     174      sortDescendingButton.Enabled = variableListView.Items.Count > 1;
     175      var item = variable.Value as IItem;
     176      if (item != null) item.ToStringChanged -= item_ToStringChanged;
    165177    }
    166178
    167179    protected virtual void UpdateVariable(KeyValuePair<string, object> variable) {
    168180      if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable");
     181
    169182      ListViewItem listViewItem;
    170       if (itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem)) {
    171         string value = (variable.Value ?? "null").ToString();
    172         string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();
    173         bool serializable = IsSerializable(variable);
    174         if (serializable) {
    175           listViewItem.ImageIndex = variable.Value == null ? 2 : 1;
    176         } else listViewItem.ImageIndex = 0;
    177         listViewItem.SubItems[1].Text = value;
    178         listViewItem.SubItems[2].Text = type;
    179         listViewItem.ToolTipText = GetToolTipText(variable, serializable);
    180         listViewItem.Tag = variable;
    181       } else throw new ArgumentException("A variable with the specified name does not exist.", "variable");
     183      if (!itemListViewItemMapping.TryGetValue(variable.Key, out listViewItem))
     184        throw new ArgumentException("A variable with the specified name does not exist.", "variable");
     185
     186      bool serializable = IsSerializable(variable);
     187      AssignVariableToListViewItem(listViewItem, variable);
     188      SetImageKey(listViewItem, serializable);
     189      SetToolTipText(listViewItem, serializable);
     190
    182191    }
    183192
     
    188197    }
    189198    protected virtual void variableListView_KeyDown(object sender, KeyEventArgs e) {
    190       if (e.KeyCode == Keys.Delete) {
    191         if ((variableListView.SelectedItems.Count > 0) && !Locked && !ReadOnly) {
    192           foreach (ListViewItem item in variableListView.SelectedItems)
    193             Content.Remove(item.Text);
    194         }
     199      switch (e.KeyCode) {
     200        case Keys.Delete:
     201          if ((variableListView.SelectedItems.Count > 0) && !Locked && !ReadOnly) {
     202            foreach (ListViewItem item in variableListView.SelectedItems)
     203              Content.Remove(item.Text);
     204          }
     205          break;
     206        case Keys.F2:
     207          if (variableListView.SelectedItems.Count != 1) return;
     208          var selectedItem = variableListView.SelectedItems[0];
     209          if (variableListView.LabelEdit)
     210            selectedItem.BeginEdit();
     211          break;
     212        case Keys.A:
     213          if (e.Modifiers.HasFlag(Keys.Control)) {
     214            foreach (ListViewItem item in variableListView.Items)
     215              item.Selected = true;
     216          }
     217          break;
    195218      }
    196219    }
    197220    protected virtual void variableListView_DoubleClick(object sender, EventArgs e) {
    198       if (variableListView.SelectedItems.Count == 1) {
    199         var item = variableListView.SelectedItems[0].Tag as KeyValuePair<string, object>?;
    200         if (item != null) {
    201           var value = item.Value.Value as IContent;
    202           if (value != null) {
    203             IContentView view = MainFormManager.MainForm.ShowContent(value);
    204             if (view != null) {
    205               view.ReadOnly = ReadOnly;
    206               view.Locked = Locked;
    207             }
    208           }
    209         }
    210       }
     221      if (variableListView.SelectedItems.Count != 1) return;
     222      var item = variableListView.SelectedItems[0].Tag as KeyValuePair<string, object>?;
     223      if (item == null) return;
     224
     225      var value = item.Value.Value as IContent;
     226      if (value == null) return;
     227
     228      IContentView view = MainFormManager.MainForm.ShowContent(value);
     229      if (view == null) return;
     230
     231      view.ReadOnly = ReadOnly;
     232      view.Locked = Locked;
    211233    }
    212234    protected virtual void variableListView_ItemDrag(object sender, ItemDragEventArgs e) {
    213       if (!Locked) {
    214         var items = new List<object>();
    215         foreach (ListViewItem listViewItem in variableListView.SelectedItems) {
    216           var item = (KeyValuePair<string, object>)listViewItem.Tag as KeyValuePair<string, object>?;
    217           if (item != null) items.Add(item.Value.Value);
    218         }
    219 
    220         if (items.Count > 0) {
    221           var data = new DataObject();
    222           if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]);
    223           else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items);
    224           if (ReadOnly) {
    225             DoDragDrop(data, DragDropEffects.Copy);
    226           } else {
    227             var result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    228             if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
    229               foreach (string item in items) Content.Remove(item);
    230             }
    231           }
    232         }
    233       }
     235      if (Locked || variableListView.SelectedItems.Count != 1) return;
     236
     237      var listViewItem = variableListView.SelectedItems[0];
     238      var item = (KeyValuePair<string, object>)listViewItem.Tag;
     239      if (!(item.Value is IDeepCloneable)) return;
     240      var data = new DataObject(HeuristicLab.Common.Constants.DragDropDataFormat, item);
     241      DoDragDrop(data, DragDropEffects.Copy);
    234242    }
    235243    protected virtual void variableListView_DragEnter(object sender, DragEventArgs e) {
     
    239247      e.Effect = DragDropEffects.None;
    240248      if (validDragOperation) {
    241         if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    242         else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    243         else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
    244         else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
    245         else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
     249        if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
    246250      }
    247251    }
    248252    protected virtual void variableListView_DragDrop(object sender, DragEventArgs e) {
    249       if (e.Effect != DragDropEffects.None) {
    250         object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    251         if (e.Effect.HasFlag(DragDropEffects.Copy)) {
    252           var cloner = new Cloner();
    253           var dc = item as IDeepCloneable;
    254           if (dc != null) item = cloner.Clone(dc);
    255         }
    256         string name = GenerateNewVariableName();
    257         Content.Add(name, item);
    258         var listViewItem = variableListView.FindItemWithText(name);
    259         listViewItem.BeginEdit();
    260       }
     253      if (e.Effect != DragDropEffects.Copy) return;
     254      object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     255
     256      string variableName;
     257      bool editLabel;
     258
     259      if (item is KeyValuePair<string, object>) {
     260        var variable = (KeyValuePair<string, object>)item;
     261        variableName = GenerateNewVariableName(out editLabel, variable.Key, false);
     262        item = variable.Value;
     263      } else {
     264        var namedItem = item as INamedItem;
     265        if (namedItem != null)
     266          variableName = GenerateNewVariableName(out editLabel, namedItem.Name, false);
     267        else
     268          variableName = GenerateNewVariableName(out editLabel);
     269      }
     270
     271      var cloneable = item as IDeepCloneable;
     272      if (cloneable != null) item = cloneable.Clone();
     273
     274      Content.Add(variableName, item);
     275
     276      var listViewItem = variableListView.FindItemWithText(variableName);
     277      variableListView.SelectedItems.Clear();
     278      if (editLabel) listViewItem.BeginEdit();
    261279    }
    262280
    263281    private readonly Regex SafeVariableNameRegex = new Regex("^[@]?[_a-zA-Z][_a-zA-Z0-9]*$");
     282    private const string DefaultVariableName = "enter_name";
     283
    264284    private void variableListView_AfterLabelEdit(object sender, LabelEditEventArgs e) {
    265285      string name = e.Label;
    266       if (!string.IsNullOrEmpty(name) && SafeVariableNameRegex.IsMatch(name)) {
     286      if (!string.IsNullOrEmpty(name)) {
    267287        var variable = (KeyValuePair<string, object>)variableListView.Items[e.Item].Tag;
    268288        if (!Content.ContainsKey(name)) {
     
    277297    #region Button Events
    278298    protected virtual void addButton_Click(object sender, EventArgs e) {
    279       object newVar = CreateItem();
    280       if (newVar != null) {
    281         string name = GenerateNewVariableName();
    282         Content.Add(name, newVar);
    283         var item = variableListView.FindItemWithText(name);
    284         item.BeginEdit();
    285       }
     299      object variableValue = CreateItem();
     300      if (variableValue == null) return;
     301
     302      string variableName;
     303      var namedItem = variableValue as INamedItem;
     304      if (namedItem != null)
     305        variableName = GenerateNewVariableName(namedItem.Name, false);
     306      else
     307        variableName = GenerateNewVariableName();
     308
     309      Content.Add(variableName, variableValue);
     310
     311      var item = variableListView.FindItemWithText(variableName);
     312      variableListView.SelectedItems.Clear();
     313      item.BeginEdit();
    286314    }
    287315    protected virtual void sortAscendingButton_Click(object sender, EventArgs e) {
     
    327355        foreach (var item in e.Items)
    328356          RemoveVariable(item);
    329         RebuildImageList();
    330357        AdjustListViewColumnSizes();
    331358      }
     
    337364        foreach (var item in e.OldItems)
    338365          RemoveVariable(item);
    339         RebuildImageList();
    340366        foreach (var item in e.Items)
    341367          AddVariable(item);
     
    347373      foreach (ListViewItem item in variableListView.Items) {
    348374        var variable = item.Tag as KeyValuePair<string, object>?;
    349         if (variable != null && variable.Value.Value == sender) {
    350           string value = (variable.Value.Value ?? "null").ToString();
    351           item.SubItems[1].Text = value;
    352           item.SubItems[2].Text = variable.Value.Value.GetType().ToString();
    353           item.ToolTipText = GetToolTipText(variable.Value, item.ImageIndex != 0);
    354           return;
    355         }
     375        if (variable == null || variable.Value.Value != sender) continue;
     376
     377        string value = (variable.Value.Value ?? "null").ToString();
     378        item.SubItems[1].Text = value;
     379        item.SubItems[2].Text = variable.Value.Value.GetType().ToString();
     380        SetToolTipText(item, item.ImageIndex != 0);
    356381      }
    357382    }
     
    368393        ch.Width = -2;
    369394    }
    370     protected virtual void RebuildImageList() {
    371       variableListView.SmallImageList.Images.Clear();
    372       variableListView.SmallImageList.Images.AddRange(new Image[] {
    373         HeuristicLab.Common.Resources.VSImageLibrary.Error,
    374         HeuristicLab.Common.Resources.VSImageLibrary.Object,
    375         HeuristicLab.Common.Resources.VSImageLibrary.Nothing
    376       });
    377       foreach (ListViewItem listViewItem in variableListView.Items) {
    378         var variable = (KeyValuePair<string, object>)listViewItem.Tag;
    379         bool serializable = IsSerializable(variable);
    380         if (serializable) {
    381           listViewItem.ImageIndex = variable.Value == null ? 2 : 1;
    382         } else listViewItem.ImageIndex = 0;
    383       }
    384     }
    385 
    386     private string GetToolTipText(KeyValuePair<string, object> variable, bool serializable) {
    387       if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable");
     395
     396    protected virtual void AssignVariableToListViewItem(ListViewItem listViewItem, KeyValuePair<string, object> variable) {
    388397      string value = (variable.Value ?? "null").ToString();
    389398      string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();
     399
     400      listViewItem.Tag = variable;
     401
     402      var subItems = listViewItem.SubItems;
     403      subItems[0].Text = variable.Key;
     404      if (subItems.Count == 1) { // variable information is added; subitems do not exist yet
     405        subItems.AddRange(new[] { value, type });
     406      } else { // variable information is updated; subitems are changed
     407        subItems[1].Text = value;
     408        subItems[2].Text = type;
     409      }
     410    }
     411
     412    protected virtual void SetImageKey(ListViewItem listViewItem, bool serializable) {
     413      var variable = (KeyValuePair<string, object>)listViewItem.Tag;
     414      if (!serializable) listViewItem.ImageKey = ErrorImageName;
     415      else if (!SafeVariableNameRegex.IsMatch(variable.Key)) listViewItem.ImageKey = WarningImageName;
     416      else if (variable.Value is IItem) listViewItem.ImageKey = HeuristicLabObjectImageName;
     417      else if (variable.Value != null) listViewItem.ImageKey = ObjectImageName;
     418      else listViewItem.ImageKey = NothingImageName;
     419    }
     420
     421    protected virtual void SetToolTipText(ListViewItem listViewItem, bool serializable) {
     422      var variable = (KeyValuePair<string, object>)listViewItem.Tag;
     423      if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable");
     424      string value = listViewItem.SubItems[1].Text;
     425      string type = listViewItem.SubItems[2].Text;
     426
    390427      string[] lines = {
    391428        "Name: " + variable.Key,
     
    393430        "Type: " + type
    394431      };
     432
    395433      string toolTipText = string.Join(Environment.NewLine, lines);
     434      if (!SafeVariableNameRegex.IsMatch(variable.Key))
     435        toolTipText = "Caution: Identifier is no valid C# identifier!" + Environment.NewLine + toolTipText;
    396436      if (!serializable)
    397437        toolTipText = "Caution: Type is not serializable!" + Environment.NewLine + toolTipText;
    398       return toolTipText;
    399     }
    400 
    401     private string GenerateNewVariableName(string defaultName = "enter_name") {
     438      listViewItem.ToolTipText = toolTipText;
     439    }
     440
     441    private string GenerateNewVariableName(string defaultName = DefaultVariableName, bool generateValidIdentifier = true) {
     442      bool editLabel;
     443      return GenerateNewVariableName(out editLabel, defaultName, generateValidIdentifier);
     444    }
     445
     446    private string GenerateNewVariableName(out bool defaultNameExists, string defaultName = DefaultVariableName, bool generateValidIdentifier = true) {
     447      if (string.IsNullOrEmpty(defaultName) || generateValidIdentifier && !SafeVariableNameRegex.IsMatch(defaultName))
     448        defaultName = DefaultVariableName;
    402449      if (Content.ContainsKey(defaultName)) {
    403450        int i = 1;
     451        string formatString = generateValidIdentifier ? "{0}{1}" : "{0} ({1})";
    404452        string newName;
    405453        do {
    406           newName = defaultName + i++;
     454          newName = string.Format(formatString, defaultName, i++);
    407455        } while (Content.ContainsKey(newName));
     456        defaultNameExists = true;
    408457        return newName;
    409458      }
     459      defaultNameExists = false;
    410460      return defaultName;
    411461    }
    412462
    413463    private bool IsSerializable(KeyValuePair<string, object> variable) {
     464      Type type = null;
     465      bool serializable;
     466
     467      if (variable.Value != null) {
     468        type = variable.Value.GetType();
     469        if (serializableLookup.TryGetValue(type, out serializable))
     470          return serializable;
     471      }
     472
    414473      var ser = new Serializer(variable, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()), "ROOT", true);
    415474      try {
    416         return ser.Count() > 0;
     475        serializable = ser.Count() > 0; // try to create all serialization tokens
    417476      } catch (PersistenceException) {
    418         return false;
    419       }
     477        serializable = false;
     478      }
     479
     480      if (type != null)
     481        serializableLookup[type] = serializable;
     482      return serializable;
    420483    }
    421484    #endregion
Note: See TracChangeset for help on using the changeset viewer.