Skip to content

Commit

Permalink
move rootclass field to main window by [37](#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaow committed Jun 27, 2022
1 parent 3eb1dcc commit b2cce31
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 83 deletions.
14 changes: 14 additions & 0 deletions JSONConverter/Classes/Controller/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Cocoa
import Highlightr

class MainViewController: NSViewController {
@IBOutlet weak var rootClassField: NSTextField!

@IBOutlet weak var languagesPopup: NSPopUpButton!
@IBOutlet weak var structurePopup: NSPopUpButton!
@IBOutlet weak var themePopup: NSPopUpButton!
Expand Down Expand Up @@ -130,6 +132,7 @@ class MainViewController: NSViewController {

private func loadCacheConfig() {
let config = FileCacheManager.shared.configFile()
rootClassField.stringValue = config.rootName
languagesPopup.selectItem(at: config.langStruct.langType.rawValue)
structurePopup.selectItem(at: config.langStruct.structType.rawValue)
if let themeIndex = highlightr.availableThemes().firstIndex(where: { config.theme == $0 }) {
Expand Down Expand Up @@ -291,6 +294,8 @@ class MainViewController: NSViewController {
let transStruct = LangStruct(langType: langType, structType: structType)
config.langStruct = transStruct

config.rootName = rootClassField.stringValue

let theme = highlightr.availableThemes()[themePopup.indexOfSelectedItem]
config.theme = theme
FileCacheManager.shared.updateConfigWithFile(config)
Expand Down Expand Up @@ -361,6 +366,15 @@ extension MainViewController: NSTextViewDelegate {
}
}

extension MainViewController: NSTextFieldDelegate {
func controlTextDidEndEditing(_ obj: Notification) {
let config = FileCacheManager.shared.configFile()
config.rootName = rootClassField.stringValue
FileCacheManager.shared.updateConfigWithFile(config)
generateClasses()
}
}

extension MainViewController {
@objc private func verLineViewPanSplitViewAction(pan: NSPanGestureRecognizer) {
let moveX = pan.location(in: self.view).x
Expand Down
18 changes: 18 additions & 0 deletions JSONConverter/Classes/Controller/MainViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<outlet property="horSplitLineView" destination="pJl-yO-yNu" id="d5u-NS-nQH"/>
<outlet property="horSpliteLineViewHeightCons" destination="vPD-64-Bqo" id="qAL-Un-k5Q"/>
<outlet property="languagesPopup" destination="JNB-NE-r1E" id="3jm-tq-0SW"/>
<outlet property="rootClassField" destination="6TB-jR-Ead" id="pZp-9s-Fbc"/>
<outlet property="saveBtn" destination="zHm-8W-mp8" id="QTa-Vt-8ik"/>
<outlet property="statusLab" destination="N2j-s3-kwM" id="rfL-un-tza"/>
<outlet property="structurePopup" destination="d6h-R6-EFn" id="mmb-Cj-lLg"/>
Expand Down Expand Up @@ -235,13 +236,30 @@
<action selector="structureSelectedChanged:" target="-2" id="qAc-Uy-kLJ"/>
</connections>
</popUpButton>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6TB-jR-Ead">
<rect key="frame" x="289" y="13" width="150" height="25"/>
<constraints>
<constraint firstAttribute="height" constant="25" id="lko-yo-kfK"/>
<constraint firstAttribute="width" constant="150" id="oFm-wX-qT1"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Root Class" drawsBackground="YES" id="jAM-Lq-f09">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="96K-2m-nL3"/>
</connections>
</textField>
</subviews>
<constraints>
<constraint firstItem="6TB-jR-Ead" firstAttribute="centerY" secondItem="axb-Mu-38g" secondAttribute="centerY" id="0EB-Xe-sez"/>
<constraint firstAttribute="bottom" secondItem="zBe-Rp-cI7" secondAttribute="bottom" id="0p8-ZJ-jBr"/>
<constraint firstItem="N2j-s3-kwM" firstAttribute="centerY" secondItem="Rs5-vR-4VE" secondAttribute="centerY" id="6AU-2K-3Pi"/>
<constraint firstItem="N2j-s3-kwM" firstAttribute="leading" secondItem="zBe-Rp-cI7" secondAttribute="trailing" id="70Q-zi-LUf"/>
<constraint firstItem="d6h-R6-EFn" firstAttribute="centerY" secondItem="JNB-NE-r1E" secondAttribute="centerY" id="7i1-EW-VWM"/>
<constraint firstItem="d6h-R6-EFn" firstAttribute="leading" secondItem="axb-Mu-38g" secondAttribute="trailing" constant="25" id="F0b-mx-ycg"/>
<constraint firstItem="axb-Mu-38g" firstAttribute="leading" secondItem="6TB-jR-Ead" secondAttribute="trailing" constant="25" id="Qya-gL-2aW"/>
<constraint firstAttribute="height" constant="50" id="SAX-n5-KNq"/>
<constraint firstItem="zHm-8W-mp8" firstAttribute="leading" secondItem="JNB-NE-r1E" secondAttribute="trailing" constant="25" id="Yce-G1-5dc"/>
<constraint firstItem="zBe-Rp-cI7" firstAttribute="top" secondItem="Rs5-vR-4VE" secondAttribute="top" id="ZAf-f1-Ce1"/>
Expand Down
12 changes: 6 additions & 6 deletions JSONConverter/Classes/Controller/MainWindowController.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -13,12 +13,12 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="JSONConverter" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<window title="JSONConverter" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<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="140" y="58" width="1000" height="660"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
<value key="minSize" type="size" width="760" height="330"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
<value key="minSize" type="size" width="900" height="330"/>
<value key="maxSize" type="size" width="1500" height="990"/>
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="1000" height="660"/>
Expand All @@ -27,7 +27,7 @@
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="539" y="22"/>
<point key="canvasLocation" x="109" y="-69"/>
</window>
</objects>
</document>
8 changes: 1 addition & 7 deletions JSONConverter/Classes/Controller/SettingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import Cocoa
class SettingViewController: NSViewController {
@IBOutlet weak var prefixKeyLab: NSTextField!
@IBOutlet weak var prefixField: NSTextField!

@IBOutlet weak var rootClassKeyLab: NSTextField!
@IBOutlet weak var rootClassField: NSTextField!


@IBOutlet weak var parentClassKeyLab: NSTextField!
@IBOutlet weak var parentClassField: NSTextField!

Expand Down Expand Up @@ -45,7 +42,6 @@ class SettingViewController: NSViewController {
backgroundView.backgroundColor = NSColor(named: "LineColor")
title = "parameter_setting_title".localized
prefixKeyLab.stringValue = "parameter_classes_prefix".localized
rootClassKeyLab.stringValue = "parameter_root_class_title".localized
parentClassKeyLab.stringValue = "parameter_parent_class_title".localized
customHeaderKeyLab.stringValue = "parameter_custom_file_header_title".localized
autoHumpKeyLab.stringValue = "parameter_auto_case_underline_hump".localized
Expand All @@ -60,7 +56,6 @@ class SettingViewController: NSViewController {
private func updateCacheConfigUI() {
let configFile = FileCacheManager.shared.configFile()
prefixField.stringValue = configFile.prefix ?? ""
rootClassField.stringValue = configFile.rootName
parentClassField.stringValue = configFile.parentName ?? ""
autoHumpSwitch.state = configFile.autoCaseUnderline ? .on : .off
customHeaderSwitch.state = configFile.isCustomHeader ? .on : .off
Expand All @@ -72,7 +67,6 @@ class SettingViewController: NSViewController {
@IBAction func saveConfigAction(_ sender: NSButton) {
let configFile = FileCacheManager.shared.configFile()
configFile.prefix = prefixField.stringValue
configFile.rootName = rootClassField.stringValue
configFile.parentName = parentClassField.stringValue
configFile.header = headerField.stringValue
configFile.isCustomHeader = customHeaderSwitch.state.rawValue == 1
Expand Down
Loading

0 comments on commit b2cce31

Please sign in to comment.