feat(macos): toggle transfers window and support close shortcut
This commit is contained in:
1 parent
02c4a1cf39
commit
9bcdcd7a77
5 files changed
+79
-8
No files matched your search
@@ -7897,6 +7897,29 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"Close Transfers" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"ja" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "転送を閉じる"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "关闭传输"
|
||||
}
|
||||
},
|
||||
"zh-Hant" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "關閉傳輸"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Close Window" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
|
||||
@@ -111,6 +111,10 @@ extension AppStrings {
|
||||
"Open Transfers"
|
||||
}
|
||||
|
||||
public static var closeTransfers: LocalizedStringResource {
|
||||
"Close Transfers"
|
||||
}
|
||||
|
||||
public static var octalPermissions: LocalizedStringResource {
|
||||
"Octal permissions"
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ struct TermindCommands: Commands {
|
||||
@FocusedValue(\.window) private var window
|
||||
|
||||
private var closeShortcuts: WindowCloseShortcuts {
|
||||
WindowCloseShortcuts(hasWorkspace: window?.selectedWorkspace != nil)
|
||||
WindowCloseShortcuts(
|
||||
hasWorkspace: !app.mainWindows.isTransfersWindowKey && window?.selectedWorkspace != nil)
|
||||
}
|
||||
|
||||
var body: some Commands {
|
||||
@@ -164,21 +165,26 @@ struct TermindCommands: Commands {
|
||||
Divider()
|
||||
|
||||
Button(AppStrings.Workspace.closeWindow.swiftUIKey, systemImage: MenuSymbol.closeWorkspace) {
|
||||
if app.mainWindows.isTransfersWindowKey {
|
||||
app.mainWindows.closeTransfers()
|
||||
return
|
||||
}
|
||||
guard let window else { return }
|
||||
app.mainWindows.closeWindow(in: window)
|
||||
}
|
||||
.termindShortcut(closeShortcuts.closeWindow)
|
||||
.disabled(window == nil)
|
||||
.disabled(window == nil && !app.mainWindows.isTransfersWindowKey)
|
||||
Button(AppStrings.Workspace.closeAllWindows.swiftUIKey) {
|
||||
app.mainWindows.closeAllWindows()
|
||||
}
|
||||
.termindShortcut(closeShortcuts.closeAllWindows)
|
||||
.disabled(window == nil)
|
||||
Button(AppStrings.Workspace.closeWorkspace.swiftUIKey) {
|
||||
guard !app.mainWindows.isTransfersWindowKey else { return }
|
||||
window?.closeSelected()
|
||||
}
|
||||
.termindShortcut(closeShortcuts.closeWorkspace)
|
||||
.disabled(window?.selectedWorkspace == nil)
|
||||
.disabled(app.mainWindows.isTransfersWindowKey || window?.selectedWorkspace == nil)
|
||||
|
||||
}
|
||||
|
||||
@@ -206,8 +212,12 @@ struct TermindCommands: Commands {
|
||||
showsStatusBar.toggle()
|
||||
}
|
||||
|
||||
Button(AppStrings.SFTP.openTransfers.swiftUIKey, systemImage: "arrow.up.arrow.down") {
|
||||
app.mainWindows.showTransfers()
|
||||
Button(
|
||||
(app.mainWindows.isTransfersWindowOpen
|
||||
? AppStrings.SFTP.closeTransfers : AppStrings.SFTP.openTransfers).swiftUIKey,
|
||||
systemImage: "arrow.up.arrow.down"
|
||||
) {
|
||||
app.mainWindows.toggleTransfers()
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
@@ -522,8 +522,12 @@ struct SFTPBrowserView: View {
|
||||
}
|
||||
}
|
||||
.disabled(!window.canOpenCompanionSession(from: sftpChannel.id))
|
||||
Button(AppStrings.SFTP.openTransfers.swiftUIKey, systemImage: "arrow.up.arrow.down") {
|
||||
app.mainWindows.showTransfers()
|
||||
Button(
|
||||
(app.mainWindows.isTransfersWindowOpen
|
||||
? AppStrings.SFTP.closeTransfers : AppStrings.SFTP.openTransfers).swiftUIKey,
|
||||
systemImage: "arrow.up.arrow.down"
|
||||
) {
|
||||
app.mainWindows.toggleTransfers()
|
||||
}
|
||||
Divider()
|
||||
if sftpChannel.showsHiddenFiles {
|
||||
|
||||
@@ -76,9 +76,23 @@ final class MainWindowCoordinator {
|
||||
@ObservationIgnored var createScene: ((UUID) -> Void)?
|
||||
@ObservationIgnored private var isTerminating = false
|
||||
@ObservationIgnored private var transfersWindow: NSWindow?
|
||||
private(set) var isTransfersWindowOpen = false
|
||||
private(set) var isTransfersWindowKey = false
|
||||
private(set) var paywallOwnerID: ObjectIdentifier?
|
||||
private var fullScreenWindows: Set<ObjectIdentifier> = []
|
||||
|
||||
func toggleTransfers() {
|
||||
if isTransfersWindowOpen {
|
||||
closeTransfers()
|
||||
} else {
|
||||
showTransfers()
|
||||
}
|
||||
}
|
||||
|
||||
func closeTransfers() {
|
||||
transfersWindow?.performClose(nil)
|
||||
}
|
||||
|
||||
func showTransfers() {
|
||||
guard !isTerminating, let app else { return }
|
||||
if let transfersWindow {
|
||||
@@ -98,6 +112,8 @@ final class MainWindowCoordinator {
|
||||
window.center()
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
isTransfersWindowOpen = true
|
||||
isTransfersWindowKey = transfersWindow?.isKeyWindow == true
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
|
||||
@@ -116,7 +132,7 @@ final class MainWindowCoordinator {
|
||||
}
|
||||
})
|
||||
for name in [
|
||||
NSWindow.willCloseNotification, NSWindow.didBecomeKeyNotification,
|
||||
NSWindow.willCloseNotification, NSWindow.didBecomeKeyNotification, NSWindow.didResignKeyNotification,
|
||||
NSWindow.didResizeNotification, NSWindow.didEndLiveResizeNotification,
|
||||
NSWindow.willEnterFullScreenNotification, NSWindow.didEnterFullScreenNotification,
|
||||
NSWindow.willExitFullScreenNotification, NSWindow.didExitFullScreenNotification,
|
||||
@@ -133,6 +149,20 @@ final class MainWindowCoordinator {
|
||||
}
|
||||
|
||||
private func handle(_ notification: Notification.Name, for native: NSWindow) {
|
||||
if native === transfersWindow {
|
||||
switch notification {
|
||||
case NSWindow.willCloseNotification:
|
||||
isTransfersWindowOpen = false
|
||||
isTransfersWindowKey = false
|
||||
case NSWindow.didBecomeKeyNotification:
|
||||
isTransfersWindowKey = true
|
||||
case NSWindow.didResignKeyNotification:
|
||||
isTransfersWindowKey = false
|
||||
default:
|
||||
break
|
||||
}
|
||||
return
|
||||
}
|
||||
guard let entry = entries.first(where: { $0.window === native }), let model = entry.model else { return }
|
||||
switch notification {
|
||||
case NSWindow.willCloseNotification:
|
||||
|
||||
Reference in new issue
Block a user