Skip to content

Commit df46935

Browse files
committed
Add bring to center action
1 parent 87be943 commit df46935

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

ChineseTime.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
CODE_SIGN_IDENTITY = "-";
303303
CODE_SIGN_STYLE = Automatic;
304304
COMBINE_HIDPI_IMAGES = YES;
305-
CURRENT_PROJECT_VERSION = 24;
305+
CURRENT_PROJECT_VERSION = 25;
306306
DEVELOPMENT_TEAM = 28HU5A7B46;
307307
ENABLE_HARDENED_RUNTIME = YES;
308308
INFOPLIST_FILE = ChineseTime/Info.plist;
@@ -327,7 +327,7 @@
327327
CODE_SIGN_IDENTITY = "-";
328328
CODE_SIGN_STYLE = Automatic;
329329
COMBINE_HIDPI_IMAGES = YES;
330-
CURRENT_PROJECT_VERSION = 24;
330+
CURRENT_PROJECT_VERSION = 25;
331331
DEVELOPMENT_TEAM = 28HU5A7B46;
332332
ENABLE_HARDENED_RUNTIME = YES;
333333
INFOPLIST_FILE = ChineseTime/Info.plist;

ChineseTime/AppDelegate.swift

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2525
keepTopMenuItem.state = watchFace.isTop ? .on : .off
2626
}
2727
}
28+
@IBAction func bringCenter(_ sender: Any) {
29+
WatchFace.currentInstance?.setCenter()
30+
}
2831

2932
@IBAction func showHelp(_ sender: Any) {
3033
NSWorkspace.shared.open(URL(string: "https://github.com/LEOYoon-Tsaw/ChineseTime")!)

ChineseTime/WatchFace.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,20 @@ class WatchFace: NSWindow {
847847
self.isMovableByWindowBackground = true
848848
}
849849
}
850-
851850
func setTop(_ on: Bool) {
852851
if on {
853852
self.level = NSWindow.Level.floating
854853
} else {
855-
self.level = NSWindow.Level.normal
854+
self.level = NSWindow.Level(rawValue: NSWindow.Level.normal.rawValue - 1)
856855
}
857856
}
857+
func setCenter() {
858+
let windowRect = self.getCurrentScreen()
859+
self.setFrame(NSMakeRect(
860+
windowRect.midX - _view.watchLayout.watchSize.width / 2,
861+
windowRect.midY - _view.watchLayout.watchSize.height / 2,
862+
_view.watchLayout.watchSize.width, _view.watchLayout.watchSize.height), display: true)
863+
}
858864

859865
func getCurrentScreen() -> NSRect {
860866
var screenRect = NSScreen.main!.frame
@@ -872,11 +878,7 @@ class WatchFace: NSWindow {
872878
func updateSize(with frame: NSRect?) {
873879
let watchDimension = _view.watchLayout.watchSize
874880
if frame == nil {
875-
let windowRect = self.getCurrentScreen()
876-
self.setFrame(NSMakeRect(
877-
windowRect.midX - watchDimension.width / 2,
878-
windowRect.midY - watchDimension.height / 2,
879-
watchDimension.width, watchDimension.height), display: true)
881+
setCenter()
880882
} else {
881883
self.setFrame(NSMakeRect(
882884
frame!.midX - watchDimension.width / 2,

ChineseTime/en.lproj/Main.storyboard

+9-3
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,12 @@
624624
<action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/>
625625
</connections>
626626
</menuItem>
627+
<menuItem title="Center" keyEquivalent="C" id="vN3-6a-37W">
628+
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
629+
<connections>
630+
<action selector="bringCenter:" target="Voe-Tx-rLC" id="8XF-tN-iOc"/>
631+
</connections>
632+
</menuItem>
627633
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
628634
<menuItem title="Lock" keyEquivalent="l" id="PEQ-kQ-g5U">
629635
<connections>
@@ -1211,8 +1217,8 @@
12111217
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
12121218
<datePickerCell key="cell" enabled="NO" borderStyle="bezel" alignment="left" drawsBackground="NO" useCurrentDate="YES" id="O3W-Rm-xGz">
12131219
<font key="font" metaFont="system"/>
1214-
<date key="date" timeIntervalSinceReferenceDate="657300683.91364801">
1215-
<!--2021-10-30 15:31:23 +0000-->
1220+
<date key="date" timeIntervalSinceReferenceDate="657311650.68938601">
1221+
<!--2021-10-30 18:34:10 +0000-->
12161222
</date>
12171223
<date key="minDate" timeIntervalSinceReferenceDate="-3124983600">
12181224
<!--1901-12-23 05:00:00 +0000-->
@@ -1330,7 +1336,7 @@
13301336
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
13311337
</colorWell>
13321338
<switch horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" baseWritingDirection="leftToRight" alignment="left" translatesAutoresizingMaskIntoConstraints="NO" id="LQj-E2-TaW">
1333-
<rect key="frame" x="214" y="1154" width="42" height="25"/>
1339+
<rect key="frame" x="213" y="1154" width="42" height="25"/>
13341340
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
13351341
</switch>
13361342
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UrE-IN-zsx">

0 commit comments

Comments
 (0)