system/src/sc/lang/ClientEditorContext.java
public void layerSelected(Layer l, boolean addToSelection) {
      if (currentLayers == null) {
         setCurrentLayer(l);
      }
      else if (!addToSelection) {
         if (currentLayers.get(0) == l) {
            List<Layer> newLayers = l.getSelectedLayers();
            if (!DynUtil.equalObjects(newLayers, currentLayers)) {
               currentLayers = newLayers;
               Bind.sendChangedEvent(this, "currentLayers");
            }
         }
         else {
            setCurrentLayer(l);
         }
      }
      else {
         boolean handled = false;
         int insertPos = -1;
         ArrayList<Layer> newCurrentLayers = new ArrayList<Layer>(currentLayers);
         for (int i = 0; i < currentLayers.size(); i++) {
            Layer current = currentLayers.get(i);
            if (current == l) {
               // Both addToSelection and normal should remove the element - or should one of them just ignore the selection?
               newCurrentLayers.remove(i);
               handled = true;
               break;
            }
            if (current.getLayerPosition() < l.getLayerPosition()) {
               insertPos = i;
               break;
            }
         }
         if (!handled) {
            if (insertPos != -1)
               newCurrentLayers.add(insertPos, l);
            else
               newCurrentLayers.add(l);
         }
         Layer newCurrentLayer = newCurrentLayers.size() == 0 ? null : newCurrentLayers.get(0);
         if (newCurrentLayer != currentLayer) {
            currentLayer = newCurrentLayer;
            updateLayerPrefix();
            Bind.sendChangedEvent(this, "currentLayer");
         }
         // Because we don't have access to sc.util.ArrayList which implements IChangeable and sends it's own events in add, set, etc.
         // we will just rebuild the list each time since it's pretty small.
         currentLayers = newCurrentLayers;
         Bind.sendChangedEvent(this, "currentLayers");
      }
   }
/** Toggles the state of the current layer - if it's current, remove it. Otherwise add it. */
Toggles the state of the current layer - if it's current, remove it. Otherwise add it.
Toggles the state of the current layer - if it ' s current remove it . Otherwise add it .
public void layerSelected(Layer l, boolean addToSelection) {
      if (currentLayers == null) {
         setCurrentLayer(l);
      }
      else if (!addToSelection) {
         if (currentLayers.get(0) == l) {
            List<Layer> newLayers = l.getSelectedLayers();
            if (!DynUtil.equalObjects(newLayers, currentLayers)) {
               currentLayers = newLayers;
               Bind.sendChangedEvent(this, "currentLayers");
            }
         }
         else {
            setCurrentLayer(l);
         }
      }
      else {
         boolean handled = false;
         int insertPos = -1;
         ArrayList<Layer> newCurrentLayers = new ArrayList<Layer>(currentLayers);
         for (int i = 0; i < currentLayers.size(); i++) {
            Layer current = currentLayers.get(i);
            if (current == l) {
               newCurrentLayers.remove(i);
               handled = true;
               break;
            }
            if (current.getLayerPosition() < l.getLayerPosition()) {
               insertPos = i;
               break;
            }
         }
         if (!handled) {
            if (insertPos != -1)
               newCurrentLayers.add(insertPos, l);
            else
               newCurrentLayers.add(l);
         }
         Layer newCurrentLayer = newCurrentLayers.size() == 0 ? null : newCurrentLayers.get(0);
         if (newCurrentLayer != currentLayer) {
            currentLayer = newCurrentLayer;
            updateLayerPrefix();
            Bind.sendChangedEvent(this, "currentLayer");
         }
         currentLayers = newCurrentLayers;
         Bind.sendChangedEvent(this, "currentLayers");
      }
   }
public void layerSelected ( Layer l , boolean addToSelection ) { if ( currentLayers == null ) { setCurrentLayer ( l ) ; } else if ( ! addToSelection ) { if ( currentLayers . get ( 0 ) == l ) { List < Layer > newLayers = l . getSelectedLayers ( ) ; if ( ! DynUtil . equalObjects ( newLayers , currentLayers ) ) { currentLayers = newLayers ; Bind . sendChangedEvent ( this , "currentLayers" ) ; } } else { setCurrentLayer ( l ) ; } } else { boolean handled = false ; int insertPos = - 1 ; ArrayList < Layer > newCurrentLayers = new ArrayList < Layer > ( currentLayers ) ; for ( int i = 0 ; i < currentLayers . size ( ) ; i ++ ) { Layer current = currentLayers . get ( i ) ; if ( current == l ) { newCurrentLayers . remove ( i ) ; handled = true ; break ; } if ( current . getLayerPosition ( ) < l . getLayerPosition ( ) ) { insertPos = i ; break ; } } if ( ! handled ) { if ( insertPos != - 1 ) newCurrentLayers . add ( insertPos , l ) ; else newCurrentLayers . add ( l ) ; } Layer newCurrentLayer = newCurrentLayers . size ( ) == 0 ? null : newCurrentLayers . get ( 0 ) ; if ( newCurrentLayer != currentLayer ) { currentLayer = newCurrentLayer ; updateLayerPrefix ( ) ; Bind . sendChangedEvent ( this , "currentLayer" ) ; } currentLayers = newCurrentLayers ; Bind . sendChangedEvent ( this , "currentLayers" ) ; } }
Toggles the state of the current layer - if it's current, remove it.
Toggles the state of the current layer - if it ' s current remove it .
// Both addToSelection and normal should remove the element - or should one of them just ignore the selection? // Because we don't have access to sc.util.ArrayList which implements IChangeable and sends it's own events in add, set, etc. // we will just rebuild the list each time since it's pretty small.