<NME> lib.js
<BEF> var pathLabel = nil
var topBottomGuides = nil

var measureWindowHeight = 70;
var measureWindowWidth = 440;



    var importViews = ViewInventory.createImportPanel()
    this.contentViewImport = importViews[0]
    this.pathLabel = importViews[1]
    this.selectionLabel = importViews[2]
    this.layersButton = importViews[3]
    this.statesButton = importViews[4]
    this.relativeButton = importViews[5]
    this.deviceAccessory = importViews[6]
    this.moreButtonImage = importViews[7]
    this.moreButton = importViews[8]
    this.emptySelectionView = importViews[9]
    this.expiredSelectionView = importViews[10]


    var sceneView = ViewInventory.createScenePanel()
    this.contentViewScene = sceneView[0]
    this.pathLabelScene = sceneView[1]
    this.selectionLabelScene = sceneView[2]
    this.deviceAccessoryScene = sceneView[3]
    this.sceneButton = sceneView[4]
    this.expiredSceneView = sceneView[5]

}




ToolbarInventory.prototype.returnPanel = function() {
    return this.panel
}


ToolbarInventory.setContentView = function() {
    var toolbar = ToolbarInventory.returnInstance()
    if (toolbar != nil) {
      var panel = toolbar.panel
      if (userDefaults.exportFramerFolder == "") {
        var view = toolbar.contentViewEmpty
        [panel setContentView:view]
      }
      else {
        if (panel.contentView() == toolbar.contentViewScene) {
          var view = toolbar.contentViewScene
          [panel setContentView:view]
        }
        else {
}


ToolbarInventory.updatePathLabel = function() {
    if (UIBar != nil) {
      if (userDefaults.exportFramerFolder == "") {
        UIBar.setContentView(ToolbarInventory.createEmptyContentView())
      }
      else {
        UIBar.setContentView(ToolbarInventory.createGeneralContentView())

        if (pathLabel != nil) {
          var pathComps = userDefaults.exportFramerFolder.split("/");
          var localLabel = pathComps.pop()
          [pathLabel setStringValue:localLabel];
        }

      }
    }
}



ToolbarInventory.getEmptyToolbarViews = function() {
      ToolbarInventory.updatePathLabelStringValue()
    }
}

ToolbarInventory.changeContentView = function() {
    if (userDefaults.exportFramerFolder == "") { return }

    var toolbar = ToolbarInventory.returnInstance()
    if (toolbar != nil) {
      var panel = toolbar.panel

      if (panel.contentView() == toolbar.contentViewScene) {
        var view = toolbar.contentViewImport
        [panel setContentView:view]
      }
      else {
        var view = toolbar.contentViewScene
        [panel setContentView:view]
      }
    [pathLabel setEditable:false];
    [pathLabel setBordered:false];
    [pathLabel setAlignment:NSCenterTextAlignment]
    [pathLabel setFont:[NSFont fontWithName:@"System" size:12]];
    [pathLabel setTextColor:[NSColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1]];
    [pathLabel setDrawsBackground:false];
    [pathLabel setStringValue:defaultPathLabel];
      if (toolbar != nil) {
          var panel = toolbar.panel
          if (panel.contentView() == toolbar.contentViewScene) { return Status.toolbarModeScene() }
          else if (panel.contentView() == toolbar.contentViewImport) { return Status.toolbarModeImport() }
          else { return Status.toolbarModeEmpty() }
      }
}


ToolbarInventory.removeInstance = function() {
    var threadIdentifier = "com.tilllur.framer-inventory"
    var threadDictionary = NSThread.mainThread().threadDictionary()
    threadDictionary.removeObjectForKey(threadIdentifier);
}

ToolbarInventory.returnInstance = function() {
    var threadIdentifier = "com.tilllur.framer-inventory"
    var threadDictionary = NSThread.mainThread().threadDictionary()
    return threadDictionary[threadIdentifier]
}

ToolbarInventory.updateClassInstance = function(toolbar) {
    if (toolbar != nil) { log(toolbar.returnPanel()) }
    var threadIdentifier = "com.tilllur.framer-inventory"
    var threadDictionary = NSThread.mainThread().threadDictionary()
    threadDictionary[threadIdentifier] = toolbar
}

// ToolbarInventory.setPathLabel = function(label) {
//   var toolbar = ToolbarInventory.returnInstance()
//   if (toolbar != nil) { toolbar.pathLabel = label }
    })


    // NSShadowlessSquareBezelStyle
    var accessoryFontSize = 10

    var relativeAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340-64-80, 16, 80, 28))
    [[relativeAccessory cell] setBezelStyle:NSTexturedRoundedBezelStyle];
    // [relativeAccessory setBordered:false];
    // [[relativeAccessory cell] setArrowPosition:NSPopUpNoArrow];
    var densityValues = ["Artboard", "Group"];
    relativeAccessory.addItemsWithTitles(densityValues)
    relativeAccessory.selectItemAtIndex(userDefaults.myRelativeGroup)
    [relativeAccessory setFont:[NSFont boldSystemFontOfSize:accessoryFontSize]];

    relativeAccessory.setCOSJSTargetFunction(function(sender){
        userDefaults.myRelativeGroup = relativeAccessory.indexOfSelectedItem()
        saveDefaults(userDefaults)
        log(userDefaults.myRelativeGroup)
    })

    var densityAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340-64, 16, 64, 28))
    [[densityAccessory cell] setBezelStyle:NSTexturedRoundedBezelStyle];
    // [densityAccessory setBordered:false];
    // [[densityAccessory cell] setArrowPosition:NSPopUpNoArrow];
    var densityValues = ["Pixels", "Points"];
    densityAccessory.addItemsWithTitles(densityValues)
    densityAccessory.selectItemAtIndex(userDefaults.myRetinaEnabled)
    [densityAccessory setFont:[NSFont boldSystemFontOfSize:accessoryFontSize]];

    densityAccessory.setCOSJSTargetFunction(function(sender){
        userDefaults.myRetinaEnabled = densityAccessory.indexOfSelectedItem()
        saveDefaults(userDefaults)
        log(userDefaults.myRetinaEnabled)
    })


    var deviceAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340, 16, 90, 28))
    [[deviceAccessory cell] setBezelStyle:NSTexturedRoundedBezelStyle];
    // [deviceAccessory setBordered:false];
    // [[deviceAccessory cell] setArrowPosition:NSPopUpNoArrow];
    var devices = [["Canvas", "Canvas @2x"], ["iPhone 5S", "iPhone 7", "iPhone 7 Plus"], ["Nexus 5P", "Nexus 6X"]]
    for (var i = 0; i < devices.length; i++) {
        deviceAccessory.addItemsWithTitles(devices[i])
        if (i != devices.length - 1) { [[deviceAccessory menu] addItem:[NSMenuItem separatorItem]] }
    }
    deviceAccessory.selectItemAtIndex(0)
    [deviceAccessory setFont:[NSFont boldSystemFontOfSize:accessoryFontSize]];

    deviceAccessory.setCOSJSTargetFunction(function(sender){
        log("REALLY")
        log(deviceAccessory.indexOfSelectedItem())
    })


      localDeviceDropdown.selectItemAtIndex(ScaleInventory.deviceToSelect(userDefaults.myDevice))

      var localDeviceSceneDropdown = toolbar.deviceAccessoryScene
      localDeviceSceneDropdown.selectItemAtIndex(ScaleInventory.deviceToSelect(userDefaults.myDevice))

  }
}


ToolbarInventory.updateImportButtons = function(adoptID) {
  var toolbar = ToolbarInventory.returnInstance()
  if (toolbar != nil) {
      if (adoptID == 0) { ViewInventory.adoptButtonsNone(toolbar.layersButton, toolbar.statesButton, toolbar.images) }
      else if (adoptID == 1) { ViewInventory.adaptButtonsBase(toolbar.layersButton, toolbar.statesButton, toolbar.images) }
      else if (adoptID == 3) { ViewInventory.adaptButtonsSeveral(toolbar.layersButton, toolbar.statesButton, toolbar.images) }
      else if (adoptID == 2) { ViewInventory.adaptButtonsSelected(toolbar.layersButton, toolbar.statesButton, toolbar.images) }
      else if (adoptID == 4) { ViewInventory.adaptButtonsSelectedSeveral(toolbar.layersButton, toolbar.statesButton, toolbar.images) }

      if (adoptID == 0) {
        ViewInventory.adoptMoreNone(toolbar.moreButtonImage, toolbar.moreButton)
        ViewInventory.adoptEmptySelection(toolbar.emptySelectionView)
}


ToolbarInventory.createContentView = function() {
    var view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, measureWindowWidth, measureWindowHeight)];
    return view
}


ToolbarInventory.createGeneralContentView = function() {
    var view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, measureWindowWidth, measureWindowHeight)];
      if (adoptID == 7) {
        ViewInventory.adoptMoreNone(toolbar.moreButtonImage, toolbar.moreButton)
        ViewInventory.adoptEmptySelectionNone(toolbar.emptySelectionView)
        ViewInventory.adoptExpiredSelection(toolbar.expiredSelectionView)
        ViewInventory.adoptButtonsNone(toolbar.layersButton, toolbar.statesButton, toolbar.images)
      }
      else {
        ViewInventory.adoptExpiredSelectionNone(toolbar.expiredSelectionView)
      }
  }
}

ToolbarInventory.updateSceneButtons = function(adoptID) {
    var toolbar = ToolbarInventory.returnInstance()
    if (toolbar != nil) {
        if (adoptID == 5) { ViewInventory.adoptSceneButtons(toolbar.sceneButton, toolbar.images) }
        else if (adoptID == 6) { ViewInventory.adoptSceneButtonsSelected(toolbar.sceneButton, toolbar.images) }

        if (adoptID == 7) {
          // log("adoptation")
          ViewInventory.adoptExpiredScene(toolbar.expiredSceneView)
          ToolbarInventory.updateSceneLabelStringValue("")
        }
        else {
          ViewInventory.adoptExpiredSceneNone(toolbar.expiredSceneView)
          ToolbarInventory.updateSceneLabelStringValue(ViewInventory.placeHolderScene())
        }
    }
}


ToolbarInventory.updateContext = function() {
    methodStartTime = [NSDate date]
    if (NSDocumentController.sharedDocumentController() != nil && NSDocumentController.sharedDocumentController().currentDocument() != nil) {
      currentDocument = NSDocumentController.sharedDocumentController().currentDocument();
      currentSelection = NSDocumentController.sharedDocumentController().currentDocument().selectedLayers().layers();
      scaleInstance = new ScaleInventory()
    }
}


        UIBar.setMovableByWindowBackground(true);
        UIBar.setHasShadow(true);
        UIBar.setLevel(NSFloatingWindowLevel);
        // var contentView = UIBar.contentView()








        // pathLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 48, measureWindowWidth, 20)];
        // [pathLabel setEditable:false];
        // [pathLabel setBordered:false];
        // [pathLabel setAlignment:NSCenterTextAlignment]
        // [pathLabel setFont:[NSFont fontWithName:@"System" size:12]];
        // [pathLabel setTextColor:[NSColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1]];
        // [pathLabel setDrawsBackground:false];
        // [pathLabel setStringValue:defaultPathLabel];
        //
        // contentView.addSubview(pathLabel);

        // var views = []
        if (userDefaults.exportFramerFolder == "") {
          UIBar.setContentView(ToolbarInventory.createEmptyContentView())
        }
        else { UIBar.setContentView(ToolbarInventory.createGeneralContentView()) }

        // for (var i = 0; i < views.length; i++) {
        //     contentView.addSubview(views[i])
        // }
        //
        // contentView.addSubview(settingsButton);
        // contentView.addSubview(closeButton);


        threadDictionary[threadIdentifier] = UIBar;
        UIBar.center();
    coscript.setShouldKeepAround(true);
    var toolbar = ToolbarInventory.returnInstance()

    if(!toolbar){

        var UIBar = NSPanel.alloc().init();
        UIBar.setStyleMask(NSTitledWindowMask + NSFullSizeContentViewWindowMask);
        UIBar.setBackgroundColor(ViewInventory.colorWindow())
        UIBar.setTitleVisibility(NSWindowTitleHidden);
        UIBar.setTitlebarAppearsTransparent(true);
        UIBar.setFrame_display(NSMakeRect(0, 0, ViewInventory.sizeWindowWidth(), ViewInventory.sizeWindowHeight()), false);
        UIBar.setMovableByWindowBackground(true);
        UIBar.setHasShadow(true);
        UIBar.setLevel(NSFloatingWindowLevel);


        toolbar = new ToolbarInventory(UIBar);
        ToolbarInventory.updateClassInstance(toolbar)
        ToolbarInventory.setContentView()

        UIBar.center()
        UIBar.makeKeyAndOrderFront(nil)

        ViewInventory.adoptButtonsNone(toolbar.layersButton, toolbar.statesButton, toolbar.images)
        SelectionInventory.asyncSelectionHandler(false)
    }
}
//       }
//   }
// }

<MSG> Added setters for Devices

– Added myDevice value in userDefaults
– Updating accessory items if settings are changed with UIBar running
– Added device magic to handle section breakers in UI (then
selectedItemIndex != place in the array)

<DFF> @@ -1,6 +1,10 @@
 var pathLabel = nil
 var topBottomGuides = nil
 
+var relativeAccessory = nil
+var densityAccessory = nil
+var deviceAccessory = nil
+
 var measureWindowHeight = 70;
 var measureWindowWidth = 440;
 
@@ -55,24 +59,6 @@ ToolbarInventory.addImage = function(rect, name) {
 }
 
 
-ToolbarInventory.updatePathLabel = function() {
-    if (UIBar != nil) {
-      if (userDefaults.exportFramerFolder == "") {
-        UIBar.setContentView(ToolbarInventory.createEmptyContentView())
-      }
-      else {
-        UIBar.setContentView(ToolbarInventory.createGeneralContentView())
-
-        if (pathLabel != nil) {
-          var pathComps = userDefaults.exportFramerFolder.split("/");
-          var localLabel = pathComps.pop()
-          [pathLabel setStringValue:localLabel];
-        }
-
-      }
-    }
-}
-
 
 
 ToolbarInventory.getEmptyToolbarViews = function() {
@@ -98,7 +84,7 @@ ToolbarInventory.getGeneralToolbarViews = function() {
     [pathLabel setEditable:false];
     [pathLabel setBordered:false];
     [pathLabel setAlignment:NSCenterTextAlignment]
-    [pathLabel setFont:[NSFont fontWithName:@"System" size:12]];
+    [pathLabel setFont:ViewInventory.fontCheckControls()];
     [pathLabel setTextColor:[NSColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1]];
     [pathLabel setDrawsBackground:false];
     [pathLabel setStringValue:defaultPathLabel];
@@ -136,55 +122,44 @@ ToolbarInventory.getGeneralToolbarViews = function() {
     })
 
 
-    // NSShadowlessSquareBezelStyle
-    var accessoryFontSize = 10
-
-    var relativeAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340-64-80, 16, 80, 28))
+    relativeAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340-64-80, 16, 80, 28))
     [[relativeAccessory cell] setBezelStyle:NSTexturedRoundedBezelStyle];
-    // [relativeAccessory setBordered:false];
-    // [[relativeAccessory cell] setArrowPosition:NSPopUpNoArrow];
     var densityValues = ["Artboard", "Group"];
     relativeAccessory.addItemsWithTitles(densityValues)
     relativeAccessory.selectItemAtIndex(userDefaults.myRelativeGroup)
-    [relativeAccessory setFont:[NSFont boldSystemFontOfSize:accessoryFontSize]];
+    [relativeAccessory setFont:ViewInventory.fontAccessory()];
 
     relativeAccessory.setCOSJSTargetFunction(function(sender){
         userDefaults.myRelativeGroup = relativeAccessory.indexOfSelectedItem()
         saveDefaults(userDefaults)
-        log(userDefaults.myRelativeGroup)
     })
 
-    var densityAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340-64, 16, 64, 28))
+    densityAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340-64, 16, 64, 28))
     [[densityAccessory cell] setBezelStyle:NSTexturedRoundedBezelStyle];
-    // [densityAccessory setBordered:false];
-    // [[densityAccessory cell] setArrowPosition:NSPopUpNoArrow];
     var densityValues = ["Pixels", "Points"];
     densityAccessory.addItemsWithTitles(densityValues)
     densityAccessory.selectItemAtIndex(userDefaults.myRetinaEnabled)
-    [densityAccessory setFont:[NSFont boldSystemFontOfSize:accessoryFontSize]];
+    [densityAccessory setFont:ViewInventory.fontAccessory()];
 
     densityAccessory.setCOSJSTargetFunction(function(sender){
         userDefaults.myRetinaEnabled = densityAccessory.indexOfSelectedItem()
         saveDefaults(userDefaults)
-        log(userDefaults.myRetinaEnabled)
     })
 
 
-    var deviceAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340, 16, 90, 28))
+    deviceAccessory = NSPopUpButton.alloc().initWithFrame(NSMakeRect(340, 16, 90, 28))
     [[deviceAccessory cell] setBezelStyle:NSTexturedRoundedBezelStyle];
-    // [deviceAccessory setBordered:false];
-    // [[deviceAccessory cell] setArrowPosition:NSPopUpNoArrow];
-    var devices = [["Canvas", "Canvas @2x"], ["iPhone 5S", "iPhone 7", "iPhone 7 Plus"], ["Nexus 5P", "Nexus 6X"]]
+    var devices = ViewInventory.returnDevices()
     for (var i = 0; i < devices.length; i++) {
         deviceAccessory.addItemsWithTitles(devices[i])
         if (i != devices.length - 1) { [[deviceAccessory menu] addItem:[NSMenuItem separatorItem]] }
     }
-    deviceAccessory.selectItemAtIndex(0)
-    [deviceAccessory setFont:[NSFont boldSystemFontOfSize:accessoryFontSize]];
+    deviceAccessory.selectItemAtIndex(ViewInventory.deviceToSelect(userDefaults.myDevice))
+    [deviceAccessory setFont:ViewInventory.fontAccessory()];
 
     deviceAccessory.setCOSJSTargetFunction(function(sender){
-        log("REALLY")
-        log(deviceAccessory.indexOfSelectedItem())
+        userDefaults.myDevice = ViewInventory.selectedDeviceIndex(deviceAccessory.indexOfSelectedItem())
+        saveDefaults(userDefaults)
     })
 
 
@@ -212,11 +187,6 @@ ToolbarInventory.getCloseToolbarViews = function() {
 }
 
 
-ToolbarInventory.createContentView = function() {
-    var view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, measureWindowWidth, measureWindowHeight)];
-    return view
-}
-
 
 ToolbarInventory.createGeneralContentView = function() {
     var view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, measureWindowWidth, measureWindowHeight)];
@@ -264,39 +234,11 @@ ToolbarInventory.createUIBar = function() {
         UIBar.setMovableByWindowBackground(true);
         UIBar.setHasShadow(true);
         UIBar.setLevel(NSFloatingWindowLevel);
-        // var contentView = UIBar.contentView()
-
-
-
-
-
 
 
-
-        // pathLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 48, measureWindowWidth, 20)];
-        // [pathLabel setEditable:false];
-        // [pathLabel setBordered:false];
-        // [pathLabel setAlignment:NSCenterTextAlignment]
-        // [pathLabel setFont:[NSFont fontWithName:@"System" size:12]];
-        // [pathLabel setTextColor:[NSColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1]];
-        // [pathLabel setDrawsBackground:false];
-        // [pathLabel setStringValue:defaultPathLabel];
-        //
-        // contentView.addSubview(pathLabel);
-
-        // var views = []
-        if (userDefaults.exportFramerFolder == "") {
-          UIBar.setContentView(ToolbarInventory.createEmptyContentView())
-        }
+        if (userDefaults.exportFramerFolder == "") { UIBar.setContentView(ToolbarInventory.createEmptyContentView()) }
         else { UIBar.setContentView(ToolbarInventory.createGeneralContentView()) }
 
-        // for (var i = 0; i < views.length; i++) {
-        //     contentView.addSubview(views[i])
-        // }
-        //
-        // contentView.addSubview(settingsButton);
-        // contentView.addSubview(closeButton);
-
 
         threadDictionary[threadIdentifier] = UIBar;
         UIBar.center();
@@ -363,3 +305,35 @@ ToolbarInventory.createUIBar = function() {
 //       }
 //   }
 // }
+
+
+ToolbarInventory.updateAccessoryControls = function() {
+    if (relativeAccessory != nil) {
+        relativeAccessory.selectItemAtIndex(userDefaults.myRelativeGroup)
+    }
+    if (densityAccessory != nil) {
+        densityAccessory.selectItemAtIndex(userDefaults.myRetinaEnabled)
+    }
+    if (deviceAccessory != nil) {
+        deviceAccessory.selectItemAtIndex(ViewInventory.deviceToSelect(userDefaults.myDevice))
+    }
+}
+
+
+ToolbarInventory.updatePathLabel = function() {
+    if (UIBar != nil) {
+      if (userDefaults.exportFramerFolder == "") {
+        UIBar.setContentView(ToolbarInventory.createEmptyContentView())
+      }
+      else {
+        UIBar.setContentView(ToolbarInventory.createGeneralContentView())
+
+        if (pathLabel != nil) {
+          var pathComps = userDefaults.exportFramerFolder.split("/");
+          var localLabel = pathComps.pop()
+          [pathLabel setStringValue:localLabel];
+        }
+
+      }
+    }
+}

Added setters for Devices