Skip to content

Commit

Permalink
Separated target from configuration selection to have a faster load
Browse files Browse the repository at this point in the history
  • Loading branch information
pfandrade committed Feb 10, 2020
1 parent 496519e commit b12618a
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 62 deletions.
8 changes: 4 additions & 4 deletions Build Settings.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
CODE_SIGN_ENTITLEMENTS = "Build Settings/Build_Settings.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 32HNEEH56A;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Build Settings/Info.plist";
Expand All @@ -297,7 +297,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.outercorner.Build-Settings";
PRODUCT_NAME = Xconfig;
SWIFT_OBJC_BRIDGING_HEADER = "Build Settings/Build Settings-Bridging-Header.h";
Expand All @@ -314,7 +314,7 @@
CODE_SIGN_ENTITLEMENTS = "Build Settings/Build_Settings.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 32HNEEH56A;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Build Settings/Info.plist";
Expand All @@ -323,7 +323,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.outercorner.Build-Settings";
PRODUCT_NAME = Xconfig;
SWIFT_OBJC_BRIDGING_HEADER = "Build Settings/Build Settings-Bridging-Header.h";
Expand Down
57 changes: 45 additions & 12 deletions Build Settings/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
<window key="window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" animationBehavior="default" titleVisibility="hidden" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="585" y="464" width="480" height="270"/>
<rect key="contentRect" x="585" y="464" width="689" height="389"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<toolbar key="toolbar" implicitIdentifier="6865DB01-8819-4434-979B-E2B3A02DF114" autosavesConfiguration="NO" allowsUserCustomization="NO" showsBaselineSeparator="NO" displayMode="iconOnly" sizeMode="regular" id="N92-AS-xSq">
<allowedToolbarItems>
Expand Down Expand Up @@ -419,7 +419,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="roundTextured" title="Item 1" bezelStyle="texturedRounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" selectedItem="bfX-bz-ixb" id="p1K-wt-HCV">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="EFX-wl-UR0">
<items>
<menuItem title="Item 1" state="on" id="bfX-bz-ixb"/>
Expand Down Expand Up @@ -460,24 +460,24 @@
</windowController>
<customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="82" y="322"/>
<point key="canvasLocation" x="146" y="305"/>
</scene>
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="Xconfig" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" misplaced="YES" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="482" height="232"/>
<rect key="frame" x="0.0" y="0.0" width="482" height="72"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView placeholderIntrinsicWidth="482" placeholderIntrinsicHeight="282" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AnM-mU-39b">
<rect key="frame" x="0.0" y="0.0" width="482" height="82"/>
<rect key="frame" x="0.0" y="0.0" width="482" height="257"/>
<clipView key="contentView" id="5gs-6P-xNO">
<rect key="frame" x="1" y="0.0" width="480" height="81"/>
<rect key="frame" x="1" y="0.0" width="480" height="256"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" autosaveColumns="NO" rowSizeStyle="automatic" headerView="X3E-i8-nLb" viewBased="YES" id="tMa-Rs-oip">
<rect key="frame" x="0.0" y="0.0" width="480" height="56"/>
<rect key="frame" x="0.0" y="0.0" width="480" height="231"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -486,7 +486,7 @@
<tableColumns>
<tableColumn editable="NO" width="118" minWidth="40" maxWidth="1000" id="tdK-xm-3qt">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Name">
<font key="font" metaFont="message" size="11"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
Expand Down Expand Up @@ -530,7 +530,7 @@
</tableColumn>
<tableColumn editable="NO" width="356" minWidth="40" maxWidth="1000" id="bIK-dc-Ugi">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Value">
<font key="font" metaFont="message" size="11"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
Expand Down Expand Up @@ -594,24 +594,57 @@
<autoresizingMask key="autoresizingMask"/>
</tableHeaderView>
</scrollView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="FnK-I4-ulL">
<rect key="frame" x="18" y="273" width="42" height="14"/>
<textFieldCell key="cell" controlSize="small" lineBreakMode="clipping" title="Config:" id="UAF-pQ-PRy">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SxZ-Ky-7nm">
<rect key="frame" x="63" y="268" width="70" height="22"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="smk-PW-k7b" id="jrb-sH-hTH">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
<menu key="menu" id="WH0-q8-pIa">
<items>
<menuItem title="Item 1" state="on" id="smk-PW-k7b"/>
<menuItem title="Item 2" id="Slc-SB-4CP"/>
<menuItem title="Item 3" id="2cT-9n-9zh"/>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="configurationSelectionDidChange:" target="XfG-lQ-9wD" id="ihE-hn-Y1q"/>
<binding destination="IDY-9v-NNo" name="content" keyPath="arrangedObjects" id="zZU-73-Vxp"/>
<binding destination="IDY-9v-NNo" name="selectedIndex" keyPath="selectionIndex" previousBinding="zZU-73-Vxp" id="xAB-kF-BEt"/>
</connections>
</popUpButton>
</subviews>
<constraints>
<constraint firstItem="FnK-I4-ulL" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" constant="20" id="0L2-40-HNY"/>
<constraint firstAttribute="bottom" secondItem="AnM-mU-39b" secondAttribute="bottom" id="1Iy-QS-UbM"/>
<constraint firstItem="FnK-I4-ulL" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" constant="10" id="DIz-nE-M0W"/>
<constraint firstItem="FnK-I4-ulL" firstAttribute="firstBaseline" secondItem="SxZ-Ky-7nm" secondAttribute="firstBaseline" id="KyS-0n-7Pu"/>
<constraint firstItem="AnM-mU-39b" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" id="Pyh-eG-wfy"/>
<constraint firstAttribute="trailing" secondItem="AnM-mU-39b" secondAttribute="trailing" id="jz1-k7-dFJ"/>
<constraint firstItem="AnM-mU-39b" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" id="uLF-Gn-zFX"/>
<constraint firstItem="AnM-mU-39b" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" constant="40" id="uLF-Gn-zFX"/>
<constraint firstItem="SxZ-Ky-7nm" firstAttribute="leading" secondItem="FnK-I4-ulL" secondAttribute="trailing" constant="8" id="xnO-t2-6MQ"/>
</constraints>
</view>
<connections>
<outlet property="selectionController" destination="meO-su-ZrT" id="7Xe-g0-gMD"/>
<outlet property="configurationsController" destination="IDY-9v-NNo" id="g9m-Qm-6TX"/>
<outlet property="settingsController" destination="cM6-wB-g7N" id="4Va-p3-thg"/>
<outlet property="targetSelectionController" destination="meO-su-ZrT" id="JTE-Tj-Rcw"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<arrayController id="cM6-wB-g7N"/>
<arrayController id="meO-su-ZrT" userLabel="Selection Controller"/>
<arrayController id="IDY-9v-NNo" userLabel="ConfigurationsController"/>
</objects>
<point key="canvasLocation" x="82" y="792"/>
<point key="canvasLocation" x="88.5" y="792"/>
</scene>
</scenes>
<resources>
Expand Down
80 changes: 63 additions & 17 deletions Build Settings/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class BuildSetting: NSObject {

class ViewController: NSViewController {

var projects: [XCDProject] = []

@IBOutlet var selectionController: NSArrayController!
@IBOutlet var settingsController: NSArrayController!
var configurationPopUp: NSPopUpButton!

var searchString: String? {
Expand All @@ -51,27 +47,32 @@ class ViewController: NSViewController {
setupPopUp()
}

override func viewDidAppear() {
super.viewDidAppear()
reload(self)
}

@objc func reload(_ sender: Any?) {
windowController?.busy = true
XcodeBridge.reloadBuildSettings { (results, error) in
XcodeBridge.reloadAvailableTargets { (results, error) in
self.windowController?.busy = false
guard let results = results else {
NSAlert(error: error!).runModal()
return
}
self.projects = results

let configurations = results.flatMap { $0.targets }.flatMap { $0.configurations }
self.selectionController.content = configurations.map { ItemWrapper(item: $0, includeProjects: results.count > 1) }
let targets = results.flatMap { $0.targets }
self.targetSelectionController.content = targets.map { ItemWrapper(item: $0, includeProjects: results.count > 1) }

if let selectedConfig = configurations.first {
self.selectionController.setSelectionIndex(0)
self.settingsController.content = selectedConfig.buildSettings.map { BuildSetting(name: $0.key, value: $0.value)
}
if let target = targets.first {
self.selectedTarget = target
self.targetSelectionController.setSelectionIndex(0)

}
}
}

// MARK: Actions
@objc func copy(_ sender: Any?) {
let text = self.settingsController.selectedObjects
.compactMap { $0 as? BuildSetting }
Expand All @@ -82,12 +83,14 @@ class ViewController: NSViewController {
NSPasteboard.general.setString(text, forType: .string)
}

// MARK: Configuration PopUp management
// MARK: Target selection

@IBOutlet var targetSelectionController: NSArrayController!
func setupPopUp() {
let toolbarPopUp = self.view.window?.toolbar?.items
.filter { $0.itemIdentifier == .init(rawValue: "ConfigurationPopUp")}
.first?.view as? NSPopUpButton
guard let popUp = toolbarPopUp, let controller = selectionController else {
guard let popUp = toolbarPopUp, let controller = targetSelectionController else {
return
}

Expand All @@ -99,13 +102,53 @@ class ViewController: NSViewController {
}

@objc func popUpDidChange(_ sender: Any?) {
guard let wrapper = selectionController.selectedObjects.first as? ItemWrapper,
let selectedConfig = wrapper.item as? XCDConfiguration else {
guard let wrapper = targetSelectionController.selectedObjects.first as? ItemWrapper else {
return
}
selectedTarget = wrapper.item as? XCDTarget
}

var selectedTarget: XCDTarget? {
didSet {
self.configurationsController.content = selectedTarget?.configurations ?? []
self.selectedConfiguration = (self.configurationsController.selectedObjects.first as? ItemWrapper)?.item as? XCDConfiguration
if let target = selectedTarget, target.configurations == nil {
target.updateConfigurations { (configs) in
if target == self.selectedTarget {
self.configurationsController.content = configs.map { ItemWrapper(item: $0, includeProjects: false) }
self.selectedConfiguration = (self.configurationsController.selectedObjects.first as? ItemWrapper)?.item as? XCDConfiguration
}
}
}
}
}

// MARK: Configuration selection
@IBOutlet var configurationsController: NSArrayController!
var selectedConfiguration: XCDConfiguration? {
didSet {
settingsController.content = (selectedConfiguration?.buildSettings ?? [:]).map { BuildSetting(name: $0.key, value: $0.value) }
if let config = selectedConfiguration, config.buildSettings == nil {
config.updateBuildSettings { (settings) in
if config == self.selectedConfiguration {
self.settingsController.content = settings.map { BuildSetting(name: $0.key, value: $0.value) }
}
}
}
}
}

self.settingsController.content = selectedConfig.buildSettings.map { BuildSetting(name: $0.key, value: $0.value) }
@IBAction func configurationSelectionDidChange(_ sender: Any) {
guard let wrapper = configurationsController.selectedObjects.first as? ItemWrapper else {
return
}
selectedConfiguration = wrapper.item as? XCDConfiguration
}

// MARK: Build Settings
@IBOutlet var settingsController: NSArrayController!


}


Expand Down Expand Up @@ -136,6 +179,9 @@ class ViewController: NSViewController {
return pathNames.reversed().joined(separator: " > ")
}

override var description: String {
return self.item.name
}
}

@objc protocol PopUpPathElement: NSObjectProtocol {
Expand Down
1 change: 1 addition & 0 deletions Build Settings/WindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Cocoa

class WindowController: NSWindowController, NSTextFieldDelegate {


var viewController: ViewController? {
return self.window?.contentViewController as? ViewController
}
Expand Down
Loading

0 comments on commit b12618a

Please sign in to comment.