Index: /trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs
===================================================================
--- /trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs	(revision 11478)
+++ /trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs	(revision 11479)
@@ -22,5 +22,4 @@
 using System;
 using System.Collections.Generic;
-using System.Drawing;
 using System.Linq;
 using System.Text.RegularExpressions;
@@ -40,4 +39,12 @@
   [Content(typeof(VariableStore), true)]
   public partial class VariableStoreView : AsynchronousContentView {
+    #region Image Names
+    private const string ErrorImageName = "Error";
+    private const string WarningImageName = "Warning";
+    private const string HeuristicLabObjectImageName = "HeuristicLabObject";
+    private const string ObjectImageName = "Object";
+    private const string NothingImageName = "Nothing";
+    #endregion
+
     protected readonly Dictionary<string, ListViewItem> itemListViewItemMapping;
     protected readonly Dictionary<Type, bool> serializableLookup;
@@ -58,10 +65,11 @@
       itemListViewItemMapping = new Dictionary<string, ListViewItem>();
       serializableLookup = new Dictionary<Type, bool>();
-      variableListView.SmallImageList.Images.AddRange(new Image[] {
-        HeuristicLab.Common.Resources.VSImageLibrary.Error,
-        HeuristicLab.Common.Resources.VSImageLibrary.Warning,
-        HeuristicLab.Common.Resources.VSImageLibrary.Object,
-        HeuristicLab.Common.Resources.VSImageLibrary.Nothing
-      });
+
+      var images = variableListView.SmallImageList.Images;
+      images.Add(ErrorImageName, Common.Resources.VSImageLibrary.Error);
+      images.Add(WarningImageName, Common.Resources.VSImageLibrary.Warning);
+      images.Add(HeuristicLabObjectImageName, Common.Resources.HeuristicLab.Icon.ToBitmap());
+      images.Add(ObjectImageName, Common.Resources.VSImageLibrary.Object);
+      images.Add(NothingImageName, Common.Resources.VSImageLibrary.Nothing);
     }
 
@@ -142,11 +150,10 @@
       string type = variable.Value == null ? "null" : variable.Value.GetType().ToString();
       bool serializable = IsSerializable(variable);
-      var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { ToolTipText = GetToolTipText(variable, serializable), Tag = variable };
-      bool validIdentifier = SafeVariableNameRegex.IsMatch(variable.Key);
-      if (!serializable) listViewItem.ImageIndex = 0;
-      else if (!validIdentifier) listViewItem.ImageIndex = 1;
-      else if (variable.Value != null) listViewItem.ImageIndex = 2;
-      else listViewItem.ImageIndex = 3;
+
+      var listViewItem = new ListViewItem(new[] { variable.Key, value, type }) { Tag = variable };
+      SetImageKey(listViewItem, serializable);
+      SetToolTipText(listViewItem, serializable);
       variableListView.Items.Add(listViewItem);
+
       itemListViewItemMapping[variable.Key] = listViewItem;
       sortAscendingButton.Enabled = variableListView.Items.Count > 1;
@@ -177,12 +184,10 @@
         bool serializable = IsSerializable(variable);
         bool validIdentifier = SafeVariableNameRegex.IsMatch(variable.Key);
-        if (!serializable) listViewItem.ImageIndex = 0;
-        else if (!validIdentifier) listViewItem.ImageIndex = 1;
-        else if (variable.Value != null) listViewItem.ImageIndex = 2;
-        else listViewItem.ImageIndex = 3;
+
+        listViewItem.Tag = variable;
         listViewItem.SubItems[1].Text = value;
         listViewItem.SubItems[2].Text = type;
-        listViewItem.ToolTipText = GetToolTipText(variable, serializable);
-        listViewItem.Tag = variable;
+        SetImageKey(listViewItem, serializable);
+        SetToolTipText(listViewItem, serializable);
       } else throw new ArgumentException("A variable with the specified name does not exist.", "variable");
     }
@@ -234,5 +239,6 @@
         var listViewItem = variableListView.SelectedItems[0];
         var item = (KeyValuePair<string, object>)listViewItem.Tag;
-        var data = new DataObject(HeuristicLab.Common.Constants.DragDropDataFormat, item.Value);
+        if (!(item.Value is IDeepCloneable)) return;
+        var data = new DataObject(HeuristicLab.Common.Constants.DragDropDataFormat, item);
         DoDragDrop(data, DragDropEffects.Copy);
       }
@@ -250,20 +256,26 @@
       if (e.Effect == DragDropEffects.Copy) {
         object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
-        var dc = item as IDeepCloneable;
-        if (dc != null) item = dc.Clone();
-
-        string name;
+
+        string variableName;
+        object variableValue;
         bool editLabel;
-        if (sender == variableListView) {
-          name = GenerateNewVariableName(variableListView.FocusedItem.Text, false);
-          editLabel = true;
+        if (item is KeyValuePair<string, object>) {
+          var variable = (KeyValuePair<string, object>)item;
+          variableName = GenerateNewVariableName(out editLabel, variable.Key, false);
+          variableValue = variable.Value;
         } else {
+          var cloneable = item as IDeepCloneable;
+          variableValue = cloneable != null ? cloneable.Clone() : item;
+
           var namedItem = item as INamedItem;
-          editLabel = namedItem == null || string.IsNullOrEmpty(namedItem.Name);
-          name = editLabel ? GenerateNewVariableName() : GenerateNewVariableName(namedItem.Name, false);
+          if (namedItem != null)
+            variableName = GenerateNewVariableName(out editLabel, namedItem.Name, false);
+          else
+            variableName = GenerateNewVariableName(out editLabel);
         }
 
-        Content.Add(name, item);
-        var listViewItem = variableListView.FindItemWithText(name);
+        Content.Add(variableName, variableValue);
+
+        var listViewItem = variableListView.FindItemWithText(variableName);
         variableListView.SelectedItems.Clear();
         if (editLabel) listViewItem.BeginEdit();
@@ -289,13 +301,18 @@
     #region Button Events
     protected virtual void addButton_Click(object sender, EventArgs e) {
-      object newVar = CreateItem();
-      if (newVar == null) return;
-
-      var namedItem = newVar as INamedItem;
-      bool editLabel = namedItem == null || string.IsNullOrEmpty(namedItem.Name);
-      string name = editLabel ? GenerateNewVariableName() : GenerateNewVariableName(namedItem.Name, false);
-      Content.Add(name, newVar);
-
-      var item = variableListView.FindItemWithText(name);
+      object variableValue = CreateItem();
+      if (variableValue == null) return;
+
+      string variableName;
+      var namedItem = variableValue as INamedItem;
+      if (namedItem != null)
+        variableName = GenerateNewVariableName(namedItem.Name, false);
+      else
+        variableName = GenerateNewVariableName();
+
+      Content.Add(variableName, variableValue);
+
+      var item = variableListView.FindItemWithText(variableName);
+      variableListView.SelectedItems.Clear();
       item.BeginEdit();
     }
@@ -364,5 +381,5 @@
           item.SubItems[1].Text = value;
           item.SubItems[2].Text = variable.Value.Value.GetType().ToString();
-          item.ToolTipText = GetToolTipText(variable.Value, item.ImageIndex != 0);
+          SetToolTipText(item, item.ImageIndex != 0);
         }
       }
@@ -381,5 +398,15 @@
     }
 
-    private string GetToolTipText(KeyValuePair<string, object> variable, bool serializable) {
+    protected virtual void SetImageKey(ListViewItem listViewItem, bool serializable) {
+      var variable = (KeyValuePair<string, object>)listViewItem.Tag;
+      if (!serializable) listViewItem.ImageKey = ErrorImageName;
+      else if (!SafeVariableNameRegex.IsMatch(variable.Key)) listViewItem.ImageKey = WarningImageName;
+      else if (variable.Value is IItem) listViewItem.ImageKey = HeuristicLabObjectImageName;
+      else if (variable.Value != null) listViewItem.ImageKey = ObjectImageName;
+      else listViewItem.ImageKey = NothingImageName;
+    }
+
+    protected virtual void SetToolTipText(ListViewItem listViewItem, bool serializable) {
+      var variable = (KeyValuePair<string, object>)listViewItem.Tag;
       if (string.IsNullOrEmpty(variable.Key)) throw new ArgumentException("The variable must have a name.", "variable");
       string value = (variable.Value ?? "null").ToString();
@@ -395,9 +422,14 @@
       if (!serializable)
         toolTipText = "Caution: Type is not serializable!" + Environment.NewLine + toolTipText;
-      return toolTipText;
+      listViewItem.ToolTipText = toolTipText;
     }
 
     private string GenerateNewVariableName(string defaultName = DefaultVariableName, bool generateValidIdentifier = true) {
-      if (generateValidIdentifier && !SafeVariableNameRegex.IsMatch(defaultName))
+      bool editLabel;
+      return GenerateNewVariableName(out editLabel, defaultName, generateValidIdentifier);
+    }
+
+    private string GenerateNewVariableName(out bool defaultNameExists, string defaultName = DefaultVariableName, bool generateValidIdentifier = true) {
+      if (string.IsNullOrEmpty(defaultName) || generateValidIdentifier && !SafeVariableNameRegex.IsMatch(defaultName))
         defaultName = DefaultVariableName;
       if (Content.ContainsKey(defaultName)) {
@@ -408,6 +440,8 @@
           newName = string.Format(formatString, defaultName, i++);
         } while (Content.ContainsKey(newName));
+        defaultNameExists = true;
         return newName;
       }
+      defaultNameExists = false;
       return defaultName;
     }
