config window base

This commit is contained in:
yuanxue.yang 2018-10-10 16:29:31 +08:00
parent d4e66b41f6
commit 725c5a32b7
6 changed files with 229 additions and 42 deletions

View File

@ -7,16 +7,17 @@
objects = {
/* Begin PBXBuildFile section */
6612ACC0216DB6DC00A8BF83 /* Config.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6612ACBF216DB6DC00A8BF83 /* Config.xib */; };
664EB375216C9A5E00B6AE0D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664EB374216C9A5E00B6AE0D /* AppDelegate.swift */; };
664EB377216C9A5F00B6AE0D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 664EB376216C9A5F00B6AE0D /* Assets.xcassets */; };
664EB37A216C9A5F00B6AE0D /* Menu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 664EB378216C9A5F00B6AE0D /* Menu.xib */; };
664EB392216CA9E800B6AE0D /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664EB390216CA9E800B6AE0D /* Config.swift */; };
664EB393216CA9E800B6AE0D /* Config.xib in Resources */ = {isa = PBXBuildFile; fileRef = 664EB391216CA9E800B6AE0D /* Config.xib */; };
664EB396216CB48400B6AE0D /* About.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664EB394216CB48400B6AE0D /* About.swift */; };
664EB397216CB48400B6AE0D /* About.xib in Resources */ = {isa = PBXBuildFile; fileRef = 664EB395216CB48400B6AE0D /* About.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
6612ACBF216DB6DC00A8BF83 /* Config.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Config.xib; sourceTree = "<group>"; };
664EB371216C9A5E00B6AE0D /* V2rayU.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = V2rayU.app; sourceTree = BUILT_PRODUCTS_DIR; };
664EB374216C9A5E00B6AE0D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
664EB376216C9A5F00B6AE0D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -24,7 +25,6 @@
664EB37B216C9A5F00B6AE0D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
664EB37C216C9A5F00B6AE0D /* V2rayU.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = V2rayU.entitlements; sourceTree = "<group>"; };
664EB390216CA9E800B6AE0D /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
664EB391216CA9E800B6AE0D /* Config.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Config.xib; sourceTree = "<group>"; };
664EB394216CB48400B6AE0D /* About.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = About.swift; sourceTree = "<group>"; };
664EB395216CB48400B6AE0D /* About.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = About.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -60,7 +60,7 @@
isa = PBXGroup;
children = (
664EB390216CA9E800B6AE0D /* Config.swift */,
664EB391216CA9E800B6AE0D /* Config.xib */,
6612ACBF216DB6DC00A8BF83 /* Config.xib */,
664EB374216C9A5E00B6AE0D /* AppDelegate.swift */,
664EB376216C9A5F00B6AE0D /* Assets.xcassets */,
664EB378216C9A5F00B6AE0D /* Menu.xib */,
@ -130,8 +130,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
664EB393216CA9E800B6AE0D /* Config.xib in Resources */,
664EB397216CB48400B6AE0D /* About.xib in Resources */,
6612ACC0216DB6DC00A8BF83 /* Config.xib in Resources */,
664EB377216C9A5F00B6AE0D /* Assets.xcassets in Resources */,
664EB37A216C9A5F00B6AE0D /* Menu.xib in Resources */,
);

View File

@ -14,7 +14,7 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="254" height="154"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
@ -35,7 +35,7 @@
<rect key="frame" x="51" y="14" width="152" height="14"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Copyright © 2018 yanue.net" allowsEditingTextAttributes="YES" id="6Ml-ub-v5q">
<font key="font" metaFont="system" size="11"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="systemBrownColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>

View File

@ -28,16 +28,31 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var myArray: Array<MyClass>!
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
let configWindow = ConfigWindow()
let aboutWindow = AboutWindow()
@IBAction func quickClicked(_ sender: NSMenuItem) {
@IBAction func quitClicked(_ sender: NSMenuItem) {
NSApplication.shared.terminate(self)
}
@IBAction func openHelp(_ sender: NSMenuItem) {
if let url = URL(string: "https://www.google.com"),NSWorkspace.shared.open(url) {
}
}
// switch server
@IBAction func switchServer(_ sender: NSMenuItem) {
if let obj = sender.representedObject {
if obj is MyClass {
let myItem = obj as! MyClass
NSLog("id: \(myItem.id), name: \(myItem.name)")
}
}
}
// open config window
@IBAction func openConfig(_ sender: NSMenuItem) {
configWindow.showWindow (nil)
// bring to front
@ -46,12 +61,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NSApp.setActivationPolicy(.regular)
}
// open about window
@IBAction func openAbout(_ sender: NSMenuItem) {
aboutWindow.showWindow (nil)
// bring to front
NSApp.activate(ignoringOtherApps: true)
}
// server list items
@IBOutlet weak var serverItems: NSMenuItem!
func applicationDidFinishLaunching(_ aNotification: Notification) {
@ -66,35 +83,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.myArray.append(MyClass(id: 1, name: "a"))
self.myArray.append(MyClass(id: 2, name: "b"))
self.myArray.append(MyClass(id: 3, name: "c"))
for myItem in self.myArray {
let menuItem = NSMenuItem.init(title: myItem.name, action: Selector(("menuItemClick")), keyEquivalent:"")
let menuItem : NSMenuItem = NSMenuItem()
menuItem.title = myItem.name
menuItem.action = #selector(AppDelegate.switchServer(_:))
menuItem.target = nil
menuItem.representedObject = myItem
menuItem.target = self
menuItem.isEnabled = true
serverItems.submenu?.addItem(menuItem)
}
// let newItem : NSMenuItem = NSMenuItem(title: "hk", action: Selector(("Test:")), keyEquivalent: "")
// stateMenu.addItem(newItem)
stateMenu.autoenablesItems = true
statusItem.menu = stateMenu
}
@IBAction func menuItemClick(sender: AnyObject) {
if let obj = sender.representedObject {
if obj is MyClass {
let myItem = obj as! MyClass
NSLog("id: \(myItem.id), name: \(myItem.name)")
}
}
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func Test(send: AnyObject?) {
NSLog("Exit")
}
}

View File

@ -13,42 +13,48 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="V2rayU" customModuleProvider="target">
<connections>
<outlet property="quickClicked" destination="eoI-of-kVd" id="1ym-HB-9cq"/>
<outlet property="serverItems" destination="cio-ej-HL5" id="VhP-6X-4cc"/>
<outlet property="stateMenu" destination="9n3-TW-9ur" id="Vkj-Ge-f59"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<menu title="load" id="9n3-TW-9ur" userLabel="StatusBarMenu">
<menu title="load" id="9n3-TW-9ur" userLabel="stateMenu">
<items>
<menuItem title="Start" state="on" id="SML-EF-rdT" userLabel="Start">
<menuItem title="Start" id="SML-EF-rdT" userLabel="Start">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="EF9-7H-2Xy"/>
<menuItem title="Config" id="GqB-HP-8ns">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="openConfig:" target="Voe-Tx-rLC" id="gIr-30-Wl6"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="qqG-Nh-BTg"/>
<menuItem title="Servers" id="cio-ej-HL5">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Servers" id="NCx-DY-Hm4"/>
</menuItem>
<menuItem title="Log" id="eLc-0G-7He">
<menuItem title="Logs" id="eLc-0G-7He">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="EF9-7H-2Xy"/>
<menuItem isSeparatorItem="YES" id="zsh-Mj-59b"/>
<menuItem title="Server" id="cio-ej-HL5">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Server" id="NCx-DY-Hm4"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="Zgj-uB-kMv"/>
<menuItem title="Help" id="YoX-II-o27" userLabel="Help">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="openHelp:" target="Voe-Tx-rLC" id="HHr-m6-jeV"/>
</connections>
</menuItem>
<menuItem title="About" id="mkZ-vI-Lc2">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="openAbout:" target="Voe-Tx-rLC" id="BXd-I1-Rc4"/>
</connections>
</menuItem>
<menuItem title="Quit" keyEquivalent="q" id="eoI-of-kVd">
<menuItem isSeparatorItem="YES" id="JSk-ds-GrJ"/>
<menuItem title="Quit" keyEquivalent="q" id="28U-8z-8lS" userLabel="Quit">
<connections>
<action selector="quickClicked:" target="Voe-Tx-rLC" id="FY0-C2-003"/>
<action selector="quitClicked:" target="Voe-Tx-rLC" id="XuU-xE-8GB"/>
</connections>
</menuItem>
</items>

View File

@ -1,5 +1,5 @@
//
// ConfigWindowController.swift
// Config.swift
// V2rayU
//
// Created by yanue on 2018/10/9.
@ -7,18 +7,79 @@
//
import Cocoa
import WebKit
class ConfigWindow: NSWindowController,NSWindowDelegate {
class ConfigWindow: NSWindowController {
override var windowNibName: String? {
return "Config" // no extension .xib here
}
var tableViewData = [["remark":"hk"],["remark":"us"]]
@IBOutlet weak var tableView: NSTableView!
@IBOutlet weak var addRemoveButton: NSSegmentedControl!
@IBAction func addRemoveServer(_ sender: NSSegmentedCell) {
// 0 add,1 remove
let seg = addRemoveButton.indexOfSelectedItem
override func windowDidLoad() {
super.windowDidLoad()
switch seg {
case 0:
// add server
tableViewData = [["remark":"hk"],["remark":"us"],["remark":"jp"]]
self.tableView.reloadData()
break
case 1:
tableViewData = [["remark":"hk"]]
self.tableView.reloadData()
// delete server
break
default :
return
}
}
@IBAction func openEdit(_ sender: NSTextFieldCell) {
NSLog("edit")
}
@IBAction func ok(_ sender: NSButton) {
// todo save
// self close
self.close()
// hide dock icon and close all opened windows
NSApp.setActivationPolicy(.accessory)
}
@IBAction func cancel(_ sender: NSButton) {
// self close
self.close()
// hide dock icon and close all opened windows
NSApp.setActivationPolicy(.accessory)
}
override func windowDidLoad() {
super.windowDidLoad()
self.tableView.delegate = self as? NSTableViewDelegate
self.tableView.dataSource = self
}
func windowWillClose(_ notification: Notification) {
// hide dock icon and close all opened windows
NSApp.setActivationPolicy(.accessory)
}
}
extension ConfigWindow: NSTableViewDataSource{
func numberOfRows(in tableView: NSTableView) -> Int {
return tableViewData.count
}
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
return tableViewData[row][(tableColumn?.identifier.rawValue)!]
}
}

114
V2rayU/Config1.xib Normal file
View File

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ConfigWindowController">
<connections>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView fixedFrame="YES" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="1" usesPredominantAxisScrolling="NO" verticalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="9QK-gu-U5O">
<rect key="frame" x="20" y="98" width="240" height="135"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" ambiguous="YES" id="XHq-jd-kGL">
<rect key="frame" x="1" y="0.0" width="238" height="134"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" headerView="XhP-GT-vKr" viewBased="YES" id="Zia-2z-nIT">
<rect key="frame" x="0.0" y="0.0" width="238" height="109"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn width="116" minWidth="40" maxWidth="1000" id="d0D-KH-sle">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="DCg-rN-yYv">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="JXV-SM-5da">
<rect key="frame" x="1" y="1" width="116" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="423-LS-9f2">
<rect key="frame" x="0.0" y="0.0" width="116" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="bb3-uY-cbU">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<connections>
<outlet property="textField" destination="423-LS-9f2" id="SJb-RF-mGo"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
<tableColumn width="116" minWidth="40" maxWidth="1000" id="cBv-b7-f88">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="6BT-HL-VH2">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="Som-DG-Xkh">
<rect key="frame" x="120" y="1" width="116" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</tableCellView>
</prototypeCellViews>
</tableColumn>
</tableColumns>
</tableView>
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="iZZ-4A-0LN">
<rect key="frame" x="1" y="119" width="223" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="yJl-3N-PK8">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<tableHeaderView key="headerView" id="XhP-GT-vKr">
<rect key="frame" x="0.0" y="0.0" width="238" height="25"/>
<autoresizingMask key="autoresizingMask"/>
</tableHeaderView>
</scrollView>
</subviews>
</view>
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
</window>
</objects>
</document>