From a1af30c079fb0d43cdc0fa0cf287d008ca3ea92c Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 31 Jul 2018 15:14:01 +0200 Subject: [PATCH] Activate existing windows for About/Preferences (fixes #72) (#73) --- syncthing/STApplication.m | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/syncthing/STApplication.m b/syncthing/STApplication.m index 67aaa7a..52f0aed 100644 --- a/syncthing/STApplication.m +++ b/syncthing/STApplication.m @@ -214,6 +214,12 @@ // TODO: need a more generic approach for opening windows - (IBAction)clickedPreferences:(NSMenuItem *)sender { + if (_preferencesWindow != nil) { + [NSApp activateIgnoringOtherApps:YES]; + [_preferencesWindow.window makeKeyAndOrderFront:self]; + return; + } + _preferencesWindow = [[STPreferencesWindowController alloc] init]; [_preferencesWindow showWindow:nil]; [[NSNotificationCenter defaultCenter] addObserver:self @@ -223,12 +229,18 @@ } - (IBAction)clickedAbout:(NSMenuItem *)sender { - _aboutWindow = [[STAboutWindowController alloc] init]; - [_aboutWindow showWindow:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(aboutWillClose:) - name:NSWindowWillCloseNotification - object:[_aboutWindow window]]; + if (_aboutWindow != nil) { + [NSApp activateIgnoringOtherApps:YES]; + [_aboutWindow.window makeKeyAndOrderFront:self]; + return; + } + + _aboutWindow = [[STAboutWindowController alloc] init]; + [_aboutWindow showWindow:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(aboutWillClose:) + name:NSWindowWillCloseNotification + object:[_aboutWindow window]]; } // TODO: need a more generic approach for closing windows