Skip to content

Commit

Permalink
Add bring to center action
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Oct 30, 2021
1 parent 87be943 commit df46935
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ChineseTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 25;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = ChineseTime/Info.plist;
Expand All @@ -327,7 +327,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 25;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = ChineseTime/Info.plist;
Expand Down
3 changes: 3 additions & 0 deletions ChineseTime/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
keepTopMenuItem.state = watchFace.isTop ? .on : .off
}
}
@IBAction func bringCenter(_ sender: Any) {
WatchFace.currentInstance?.setCenter()
}

@IBAction func showHelp(_ sender: Any) {
NSWorkspace.shared.open(URL(string: "https://github.com/LEOYoon-Tsaw/ChineseTime")!)
Expand Down
16 changes: 9 additions & 7 deletions ChineseTime/WatchFace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -847,14 +847,20 @@ class WatchFace: NSWindow {
self.isMovableByWindowBackground = true
}
}

func setTop(_ on: Bool) {
if on {
self.level = NSWindow.Level.floating
} else {
self.level = NSWindow.Level.normal
self.level = NSWindow.Level(rawValue: NSWindow.Level.normal.rawValue - 1)
}
}
func setCenter() {
let windowRect = self.getCurrentScreen()
self.setFrame(NSMakeRect(
windowRect.midX - _view.watchLayout.watchSize.width / 2,
windowRect.midY - _view.watchLayout.watchSize.height / 2,
_view.watchLayout.watchSize.width, _view.watchLayout.watchSize.height), display: true)
}

func getCurrentScreen() -> NSRect {
var screenRect = NSScreen.main!.frame
Expand All @@ -872,11 +878,7 @@ class WatchFace: NSWindow {
func updateSize(with frame: NSRect?) {
let watchDimension = _view.watchLayout.watchSize
if frame == nil {
let windowRect = self.getCurrentScreen()
self.setFrame(NSMakeRect(
windowRect.midX - watchDimension.width / 2,
windowRect.midY - watchDimension.height / 2,
watchDimension.width, watchDimension.height), display: true)
setCenter()
} else {
self.setFrame(NSMakeRect(
frame!.midX - watchDimension.width / 2,
Expand Down
12 changes: 9 additions & 3 deletions ChineseTime/en.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,12 @@
<action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/>
</connections>
</menuItem>
<menuItem title="Center" keyEquivalent="C" id="vN3-6a-37W">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="bringCenter:" target="Voe-Tx-rLC" id="8XF-tN-iOc"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
<menuItem title="Lock" keyEquivalent="l" id="PEQ-kQ-g5U">
<connections>
Expand Down Expand Up @@ -1211,8 +1217,8 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<datePickerCell key="cell" enabled="NO" borderStyle="bezel" alignment="left" drawsBackground="NO" useCurrentDate="YES" id="O3W-Rm-xGz">
<font key="font" metaFont="system"/>
<date key="date" timeIntervalSinceReferenceDate="657300683.91364801">
<!--2021-10-30 15:31:23 +0000-->
<date key="date" timeIntervalSinceReferenceDate="657311650.68938601">
<!--2021-10-30 18:34:10 +0000-->
</date>
<date key="minDate" timeIntervalSinceReferenceDate="-3124983600">
<!--1901-12-23 05:00:00 +0000-->
Expand Down Expand Up @@ -1330,7 +1336,7 @@
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</colorWell>
<switch horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" baseWritingDirection="leftToRight" alignment="left" translatesAutoresizingMaskIntoConstraints="NO" id="LQj-E2-TaW">
<rect key="frame" x="214" y="1154" width="42" height="25"/>
<rect key="frame" x="213" y="1154" width="42" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
</switch>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UrE-IN-zsx">
Expand Down

0 comments on commit df46935

Please sign in to comment.