Skip to content

Commit f235bd1

Browse files
Moved selection into window
1 parent 9f33ce3 commit f235bd1

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

LocalizationEditor/AppDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Cocoa
1212
@NSApplicationMain
1313
class AppDelegate: NSObject, NSApplicationDelegate {
1414
@IBOutlet weak var openFolderMenuItem: NSMenuItem!
15-
@IBOutlet weak var selectMenuItem: NSMenuItem!
1615

1716
func applicationDidFinishLaunching(_: Notification) {
1817
setupLogging()

LocalizationEditor/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>1.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>1</string>
22+
<string>2</string>
2323
<key>LSMinimumSystemVersion</key>
2424
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2525
<key>NSHumanReadableCopyright</key>

LocalizationEditor/Providers/LocalizationProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class LocalizationProvider {
3333
let lang = String(parts[parts.count - 2]).replacingOccurrences(of: ".lproj", with: "")
3434
return Localization(language: lang, translations: getLocalizationStrings(path: file.path), path: file.path)
3535
}), path: path)
36-
})
36+
}).sorted(by: {$0.name < $1.name})
3737
}
3838

3939
private func getLocalizationStrings(path: String) -> [LocalizationString] {

LocalizationEditor/UI/Base.lproj/Main.storyboard

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@
6464
</menuItem>
6565
<menuItem title="Select" id="3lY-JD-VuH">
6666
<modifierMask key="keyEquivalentModifierMask"/>
67-
<menu key="submenu" title="Select" id="mcz-dt-iwt">
68-
<items>
69-
<menuItem title="Item" id="rhJ-Q3-oPZ">
70-
<modifierMask key="keyEquivalentModifierMask"/>
71-
</menuItem>
72-
</items>
73-
</menu>
7467
</menuItem>
7568
</items>
7669
</menu>
@@ -81,7 +74,6 @@
8174
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="LocalizationEditor" customModuleProvider="target">
8275
<connections>
8376
<outlet property="openFolderMenuItem" destination="pXV-BH-hD6" id="9EJ-PN-yBL"/>
84-
<outlet property="selectMenuItem" destination="3lY-JD-VuH" id="vyY-or-HeH"/>
8577
</connections>
8678
</customObject>
8779
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
@@ -119,13 +111,13 @@
119111
<autoresizingMask key="autoresizingMask"/>
120112
<subviews>
121113
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4ba-Nv-4Q4">
122-
<rect key="frame" x="0.0" y="0.0" width="658" height="416"/>
114+
<rect key="frame" x="0.0" y="0.0" width="658" height="392"/>
123115
<clipView key="contentView" id="xNj-vz-MO7">
124-
<rect key="frame" x="1" y="0.0" width="656" height="415"/>
116+
<rect key="frame" x="1" y="0.0" width="656" height="391"/>
125117
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
126118
<subviews>
127119
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" usesAutomaticRowHeights="YES" headerView="Bry-MY-OIY" id="ByO-mI-RPv">
128-
<rect key="frame" x="0.0" y="0.0" width="656" height="392"/>
120+
<rect key="frame" x="0.0" y="0.0" width="656" height="368"/>
129121
<autoresizingMask key="autoresizingMask"/>
130122
<size key="intercellSpacing" width="3" height="2"/>
131123
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -149,18 +141,46 @@
149141
<progressIndicator wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="orS-Om-jEF">
150142
<rect key="frame" x="321" y="200" width="16" height="16"/>
151143
</progressIndicator>
144+
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZFg-5m-6pC">
145+
<rect key="frame" x="84" y="390" width="577" height="26"/>
146+
<popUpButtonCell key="cell" type="push" title="Open folder first" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="border" inset="2" selectedItem="NVn-GV-ID4" id="4aK-eh-T5Y">
147+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
148+
<font key="font" metaFont="menu"/>
149+
<menu key="menu" id="5W8-5b-o7R">
150+
<items>
151+
<menuItem title="Open folder first" state="on" id="NVn-GV-ID4"/>
152+
</items>
153+
</menu>
154+
</popUpButtonCell>
155+
</popUpButton>
156+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="16j-oD-cAE">
157+
<rect key="frame" x="3" y="395" width="75" height="17"/>
158+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="String table" id="z8U-Ny-4JF">
159+
<font key="font" metaFont="system"/>
160+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
161+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
162+
</textFieldCell>
163+
</textField>
152164
</subviews>
153165
<constraints>
154-
<constraint firstItem="4ba-Nv-4Q4" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" id="Fcq-O0-4L6"/>
166+
<constraint firstItem="ZFg-5m-6pC" firstAttribute="leading" secondItem="16j-oD-cAE" secondAttribute="trailing" constant="10" id="D6G-Vj-vzc"/>
167+
<constraint firstItem="4ba-Nv-4Q4" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" constant="24" id="Fcq-O0-4L6"/>
168+
<constraint firstAttribute="trailing" secondItem="ZFg-5m-6pC" secondAttribute="trailing" id="I29-aq-1Lr"/>
169+
<constraint firstItem="ZFg-5m-6pC" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" constant="2" id="PJB-vg-X9o"/>
155170
<constraint firstAttribute="trailing" secondItem="4ba-Nv-4Q4" secondAttribute="trailing" id="U2K-bp-ktM"/>
156171
<constraint firstItem="4ba-Nv-4Q4" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" id="aFu-bj-BOT"/>
157172
<constraint firstItem="orS-Om-jEF" firstAttribute="centerY" secondItem="m2S-Jp-Qdl" secondAttribute="centerY" id="cdU-Z2-VjR"/>
173+
<constraint firstItem="4ba-Nv-4Q4" firstAttribute="top" secondItem="ZFg-5m-6pC" secondAttribute="bottom" constant="1" id="fUC-6L-ChH"/>
158174
<constraint firstAttribute="bottom" secondItem="4ba-Nv-4Q4" secondAttribute="bottom" id="m5c-j8-Z7f"/>
175+
<constraint firstItem="16j-oD-cAE" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" constant="5" id="osA-pP-jh6"/>
159176
<constraint firstItem="orS-Om-jEF" firstAttribute="centerX" secondItem="m2S-Jp-Qdl" secondAttribute="centerX" id="p93-Be-Z2I"/>
177+
<constraint firstItem="16j-oD-cAE" firstAttribute="centerY" secondItem="ZFg-5m-6pC" secondAttribute="centerY" id="rs9-h5-XO3"/>
160178
</constraints>
161179
</view>
162180
<connections>
181+
<outlet property="defaultSelectItem" destination="NVn-GV-ID4" id="Ibj-ZN-bm2"/>
163182
<outlet property="progressIndicator" destination="orS-Om-jEF" id="W9q-Ft-3Pn"/>
183+
<outlet property="selectButton" destination="ZFg-5m-6pC" id="uUm-fN-AZO"/>
164184
<outlet property="tableView" destination="ByO-mI-RPv" id="HZj-sq-2j6"/>
165185
</connections>
166186
</viewController>

LocalizationEditor/UI/ViewController.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class ViewController: NSViewController {
1313
// MARK: - Outlets
1414

1515
@IBOutlet private weak var tableView: NSTableView!
16+
@IBOutlet private weak var selectButton: NSPopUpButton!
1617
@IBOutlet private weak var progressIndicator: NSProgressIndicator!
18+
@IBOutlet private var defaultSelectItem: NSMenuItem!
1719

1820
// MARK: - Properties
1921

@@ -31,8 +33,8 @@ class ViewController: NSViewController {
3133
private func setupMenu() {
3234
let appDelegate = NSApplication.shared.delegate as! AppDelegate
3335
appDelegate.openFolderMenuItem.action = #selector(ViewController.openAction(sender:))
34-
appDelegate.selectMenuItem.isHidden = true
35-
appDelegate.selectMenuItem.submenu?.removeAllItems();
36+
selectButton.menu?.removeAllItems();
37+
selectButton.menu?.addItem(defaultSelectItem)
3638
}
3739

3840
private func setupData() {
@@ -46,11 +48,9 @@ class ViewController: NSViewController {
4648
tableView.dataSource = dataSource
4749
}
4850

49-
private func setupSetupLocalizsationSelectionMenu(files: [LocalizationGroup]){
50-
let appDelegate = NSApplication.shared.delegate as! AppDelegate
51-
appDelegate.selectMenuItem.isHidden = false
52-
53-
files.map({NSMenuItem(title: $0.name, action: #selector(ViewController.selectAction(sender:)), keyEquivalent: "")}).forEach({appDelegate.selectMenuItem.submenu?.addItem($0)})
51+
private func setupSetupLocalizationSelectionMenu(files: [LocalizationGroup]){
52+
selectButton.menu?.removeAllItems()
53+
files.map({NSMenuItem(title: $0.name, action: #selector(ViewController.selectAction(sender:)), keyEquivalent: "")}).forEach({selectButton.menu?.addItem($0)})
5454
}
5555

5656
private func reloadData(with languages: [String], title: String?) {
@@ -86,14 +86,14 @@ class ViewController: NSViewController {
8686
return string
8787
}
8888

89-
@objc func selectAction(sender: NSMenuItem) {
89+
@IBAction @objc func selectAction(sender: NSMenuItem) {
9090
let title = sender.title
9191
let languages = self.dataSource.select(name: title)
9292

9393
self.reloadData(with: languages, title:title)
9494
}
9595

96-
@objc func openAction(sender _: NSMenuItem) {
96+
@IBAction @objc func openAction(sender _: NSMenuItem) {
9797
let openPanel = NSOpenPanel()
9898
openPanel.allowsMultipleSelection = false
9999
openPanel.canChooseDirectories = true
@@ -106,8 +106,13 @@ class ViewController: NSViewController {
106106
self.dataSource.load(folder: url) { [unowned self] languages, title, localizationFiles in
107107
self.reloadData(with: languages, title:title)
108108
self.progressIndicator.stopAnimation(self)
109-
if(localizationFiles.count > 1){
110-
self.setupSetupLocalizsationSelectionMenu(files: localizationFiles)
109+
110+
if let title = title{
111+
self.setupSetupLocalizationSelectionMenu(files: localizationFiles)
112+
self.selectButton.selectItem(at: self.selectButton.indexOfItem(withTitle: title))
113+
}
114+
else {
115+
self.setupMenu()
111116
}
112117
}
113118
}

0 commit comments

Comments
 (0)