Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11474


Ignore:
Timestamp:
10/16/14 18:34:17 (10 years ago)
Author:
jkarder
Message:

#2262: applied some of the changes suggested by mkommend in comment:10:ticket:2262

  • renaming is now only possible if one variable is selected; the variable does not have to be focused
  • avoided manual creation of cloner
  • changed drag-and-drop logic; existing variable names are now taken into account when cloning INamedItems
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs

    r11472 r11474  
    202202          break;
    203203        case Keys.F2:
    204           var focusedItem = variableListView.FocusedItem;
    205           if (variableListView.LabelEdit && focusedItem.Selected)
    206             focusedItem.BeginEdit();
     204          if (variableListView.SelectedItems.Count != 1) return;
     205          var selectedItem = variableListView.SelectedItems[0];
     206          if (variableListView.LabelEdit)
     207            selectedItem.BeginEdit();
    207208          break;
    208209        case Keys.A:
     
    249250      if (e.Effect == DragDropEffects.Copy) {
    250251        object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    251         var cloner = new Cloner();
    252252        var dc = item as IDeepCloneable;
    253         if (dc != null) item = cloner.Clone(dc);
    254         var namedItem = item as INamedItem;
    255         bool nameValid = namedItem != null && !string.IsNullOrEmpty(namedItem.Name);
    256         string name = nameValid ? GenerateNewVariableName(namedItem.Name, false) : GenerateNewVariableName();
     253        if (dc != null) item = dc.Clone();
     254
     255        string name;
     256        bool editLabel;
     257        if (sender == variableListView) {
     258          name = GenerateNewVariableName(variableListView.FocusedItem.Text, false);
     259          editLabel = true;
     260        } else {
     261          var namedItem = item as INamedItem;
     262          editLabel = namedItem == null || string.IsNullOrEmpty(namedItem.Name);
     263          name = editLabel ? GenerateNewVariableName() : GenerateNewVariableName(namedItem.Name, false);
     264        }
     265
    257266        Content.Add(name, item);
    258267        var listViewItem = variableListView.FindItemWithText(name);
    259         if (!nameValid) listViewItem.BeginEdit();
     268        variableListView.SelectedItems.Clear();
     269        if (editLabel) listViewItem.BeginEdit();
    260270      }
    261271    }
     
    280290    protected virtual void addButton_Click(object sender, EventArgs e) {
    281291      object newVar = CreateItem();
    282       if (newVar != null) {
    283         string name = GenerateNewVariableName();
    284         Content.Add(name, newVar);
    285         var item = variableListView.FindItemWithText(name);
    286         item.BeginEdit();
    287       }
     292      if (newVar == null) return;
     293
     294      var namedItem = newVar as INamedItem;
     295      bool editLabel = namedItem == null || string.IsNullOrEmpty(namedItem.Name);
     296      string name = editLabel ? GenerateNewVariableName() : GenerateNewVariableName(namedItem.Name, false);
     297      Content.Add(name, newVar);
     298
     299      var item = variableListView.FindItemWithText(name);
     300      item.BeginEdit();
    288301    }
    289302    protected virtual void sortAscendingButton_Click(object sender, EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.