Zonble: Swiftify // NonModalAlertWindowController
This commit is contained in:
parent
5b1d05564c
commit
a70e96a778
|
@ -37,7 +37,6 @@
|
|||
//
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import "OVNonModalAlertWindowController.h"
|
||||
#import "vChewing-Swift.h"
|
||||
#import "frmAboutWindow.h"
|
||||
|
||||
|
@ -51,7 +50,7 @@ static NSString *kUpdateInfoSiteKey = @"UpdateInfoSite";
|
|||
static const NSTimeInterval kNextCheckInterval = 86400.0;
|
||||
static const NSTimeInterval kTimeoutInterval = 60.0;
|
||||
|
||||
@interface AppDelegate () <NSURLConnectionDataDelegate, OVNonModalAlertWindowControllerDelegate>
|
||||
@interface AppDelegate () <NSURLConnectionDataDelegate, NonModalAlertWindowControllerDelegate>
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
|
@ -159,13 +158,13 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
|
|||
_currentUpdateCheckIsForced = NO;
|
||||
|
||||
if (isForcedCheck) {
|
||||
[[OVNonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"Update Check Failed", nil) content:[NSString stringWithFormat:NSLocalizedString(@"There may be no internet connection or the server failed to respond.\n\nError message: %@", nil), [error localizedDescription]] confirmButtonTitle:NSLocalizedString(@"Dismiss", nil) cancelButtonTitle:nil cancelAsDefault:NO delegate:nil];
|
||||
[[NonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"Update Check Failed", nil) content:[NSString stringWithFormat:NSLocalizedString(@"There may be no internet connection or the server failed to respond.\n\nError message: %@", nil), [error localizedDescription]] confirmButtonTitle:NSLocalizedString(@"Dismiss", nil) cancelButtonTitle:nil cancelAsDefault:NO delegate:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showNoUpdateAvailableAlert
|
||||
{
|
||||
[[OVNonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"Check for Update Completed", nil) content:NSLocalizedString(@"You are already using the latest version of vChewing.", nil) confirmButtonTitle:NSLocalizedString(@"OK", nil) cancelButtonTitle:nil cancelAsDefault:NO delegate:nil];
|
||||
[[NonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"Check for Update Completed", nil) content:NSLocalizedString(@"You are already using the latest version of vChewing.", nil) confirmButtonTitle:NSLocalizedString(@"OK", nil) cancelButtonTitle:nil cancelAsDefault:NO delegate:nil];
|
||||
}
|
||||
|
||||
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
|
||||
|
@ -255,7 +254,7 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
|
|||
|
||||
NSString *content = [NSString stringWithFormat:NSLocalizedString(@"You're currently using vChewing %@ (%@), a new version %@ (%@) is now available. Do you want to visit vChewing's website to download the version?%@", nil), [infoDict objectForKey:@"CFBundleShortVersionString"], currentVersion, [plist objectForKey:@"CFBundleShortVersionString"], remoteVersion, versionDescription];
|
||||
|
||||
[[OVNonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"New Version Available", nil) content:content confirmButtonTitle:NSLocalizedString(@"Visit Website", nil) cancelButtonTitle:NSLocalizedString(@"Not Now", nil) cancelAsDefault:NO delegate:self];
|
||||
[[NonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"New Version Available", nil) content:content confirmButtonTitle:NSLocalizedString(@"Visit Website", nil) cancelButtonTitle:NSLocalizedString(@"Not Now", nil) cancelAsDefault:NO delegate:self];
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
|
||||
|
@ -263,7 +262,7 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
|
|||
[_receivingData appendData:data];
|
||||
}
|
||||
|
||||
- (void)nonModalAlertWindowControllerDidConfirm:(OVNonModalAlertWindowController *)controller
|
||||
- (void)nonModalAlertWindowControllerDidConfirm:(NonModalAlertWindowController *)controller
|
||||
{
|
||||
if (_updateNextStepURL) {
|
||||
[[NSWorkspace sharedWorkspace] openURL:_updateNextStepURL];
|
||||
|
@ -272,7 +271,7 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
|
|||
_updateNextStepURL = nil;
|
||||
}
|
||||
|
||||
- (void)nonModalAlertWindowControllerDidCancel:(OVNonModalAlertWindowController *)controller
|
||||
- (void)nonModalAlertWindowControllerDidCancel:(NonModalAlertWindowController *)controller
|
||||
{
|
||||
_updateNextStepURL = nil;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#import "OVStringHelper.h"
|
||||
#import "OVUTF8Helper.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "OVNonModalAlertWindowController.h"
|
||||
#import "vChewing-Swift.h"
|
||||
|
||||
|
||||
|
@ -1563,7 +1562,7 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
|||
NSLog(@"openUserPhrases called");
|
||||
if (!LTCheckIfUserLanguageModelFileExists()) {
|
||||
NSString *content = [NSString stringWithFormat:NSLocalizedString(@"Please check the permission of at \"%@\".", @""), LTUserDataFolderPath()];
|
||||
[[OVNonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"Unable to create the user phrase file.", @"") content:content confirmButtonTitle:NSLocalizedString(@"OK", @"") cancelButtonTitle:nil cancelAsDefault:NO delegate:nil];
|
||||
[[NonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"Unable to create the user phrase file.", @"") content:content confirmButtonTitle:NSLocalizedString(@"OK", @"") cancelButtonTitle:nil cancelAsDefault:NO delegate:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
//
|
||||
// NonModalAlertWindowController.swift
|
||||
//
|
||||
// Copyright (c) 2011-2022 The OpenVanilla Project.
|
||||
//
|
||||
// Contributors:
|
||||
// Weizhong Yang (@zonble) @ OpenVanilla
|
||||
// Lukhnos Liu (@lukhnos) @ OpenVanilla
|
||||
//
|
||||
// Based on the Syrup Project and the Formosana Library
|
||||
// by Lukhnos Liu (@lukhnos).
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
@objc protocol NonModalAlertWindowControllerDelegate: AnyObject {
|
||||
func nonModalAlertWindowControllerDidConfirm(_ controller: NonModalAlertWindowController)
|
||||
func nonModalAlertWindowControllerDidCancel(_ controller: NonModalAlertWindowController)
|
||||
}
|
||||
|
||||
class NonModalAlertWindowController: NSWindowController {
|
||||
@objc (sharedInstance)
|
||||
|
||||
static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController")
|
||||
|
||||
@IBOutlet weak var titleTextField: NSTextField!
|
||||
@IBOutlet weak var contentTextField: NSTextField!
|
||||
@IBOutlet weak var confirmButton: NSButton!
|
||||
@IBOutlet weak var cancelButton: NSButton!
|
||||
weak var delegate: NonModalAlertWindowControllerDelegate?
|
||||
|
||||
@objc func show(title: String, content: String, confirmButtonTitle: String, cancelButtonTitle: String?, cancelAsDefault: Bool, delegate: NonModalAlertWindowControllerDelegate?) {
|
||||
if window?.isVisible == true {
|
||||
self.delegate?.nonModalAlertWindowControllerDidCancel(self)
|
||||
}
|
||||
|
||||
self.delegate = delegate
|
||||
|
||||
var oldFrame = confirmButton.frame
|
||||
confirmButton.title = confirmButtonTitle
|
||||
confirmButton.sizeToFit()
|
||||
|
||||
var newFrame = confirmButton.frame
|
||||
newFrame.size.width = max(90, newFrame.size.width + 10)
|
||||
newFrame.origin.x += oldFrame.size.width - newFrame.size.width
|
||||
self.confirmButton.frame = newFrame
|
||||
|
||||
if let cancelButtonTitle = cancelButtonTitle {
|
||||
cancelButton.title = cancelButtonTitle
|
||||
cancelButton.sizeToFit()
|
||||
var adjustFrame = cancelButton.frame
|
||||
adjustFrame.size.width = max(90, adjustFrame.size.width + 10)
|
||||
adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width
|
||||
confirmButton.frame = adjustFrame
|
||||
cancelButton.isHidden = false
|
||||
} else {
|
||||
cancelButton.isHidden = true
|
||||
}
|
||||
|
||||
cancelButton.nextKeyView = confirmButton
|
||||
confirmButton.nextKeyView = cancelButton
|
||||
|
||||
if cancelButtonTitle != nil {
|
||||
if cancelAsDefault {
|
||||
window?.defaultButtonCell = cancelButton.cell as? NSButtonCell
|
||||
} else {
|
||||
cancelButton.keyEquivalent = " "
|
||||
window?.defaultButtonCell = confirmButton.cell as? NSButtonCell
|
||||
}
|
||||
} else {
|
||||
window?.defaultButtonCell = confirmButton.cell as? NSButtonCell
|
||||
}
|
||||
|
||||
titleTextField.stringValue = title
|
||||
|
||||
oldFrame = contentTextField.frame
|
||||
contentTextField.stringValue = content
|
||||
|
||||
var infiniteHeightFrame = oldFrame
|
||||
infiniteHeightFrame.size.width -= 4.0
|
||||
infiniteHeightFrame.size.height = 10240
|
||||
newFrame = (content as NSString).boundingRect(with: infiniteHeightFrame.size, options: [.usesLineFragmentOrigin], attributes: [.font: contentTextField.font!])
|
||||
newFrame.size.width = max(newFrame.size.width, oldFrame.size.width)
|
||||
newFrame.size.height += 4.0
|
||||
newFrame.origin = oldFrame.origin
|
||||
newFrame.origin.y -= (newFrame.size.height - oldFrame.size.height)
|
||||
contentTextField.frame = newFrame
|
||||
|
||||
var windowFrame = window?.frame ?? NSRect.zero
|
||||
windowFrame.size.height += (newFrame.size.height - oldFrame.size.height)
|
||||
window?.level = NSWindow.Level(Int(CGShieldingWindowLevel()) + 1)
|
||||
window?.setFrame(windowFrame, display: true)
|
||||
window?.center()
|
||||
window?.makeKeyAndOrderFront(self)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
|
||||
@IBAction func confirmButtonAction(_ sender: Any) {
|
||||
delegate?.nonModalAlertWindowControllerDidConfirm(self)
|
||||
window?.orderOut(self)
|
||||
}
|
||||
|
||||
@IBAction func cancelButtonAction(_ sender: Any) {
|
||||
cancel(sender)
|
||||
}
|
||||
|
||||
func cancel(_ sender: Any) {
|
||||
delegate?.nonModalAlertWindowControllerDidCancel(self)
|
||||
delegate = nil
|
||||
window?.orderOut(self)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="OVNonModalAlertWindowController">
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NonModalAlertWindowController" customModule="vChewing" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="cancelButton" destination="71" id="83"/>
|
||||
<outlet property="confirmButton" destination="5" id="82"/>
|
||||
|
@ -17,18 +17,20 @@
|
|||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
|
||||
<windowStyleMask key="styleMask" titled="YES"/>
|
||||
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" visibleAtLaunch="NO" animationBehavior="default" titlebarAppearsTransparent="YES" id="1">
|
||||
<windowStyleMask key="styleMask" titled="YES" fullSizeContentView="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="196" y="240" width="420" height="130"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
|
||||
<view key="contentView" id="2">
|
||||
<rect key="frame" x="0.0" y="0.0" width="420" height="130"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5">
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5">
|
||||
<rect key="frame" x="314" y="13" width="92" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="78" id="izB-CQ-Vwa"/>
|
||||
</constraints>
|
||||
<buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
|
@ -37,9 +39,11 @@
|
|||
<action selector="confirmButtonAction:" target="-2" id="85"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="71">
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="71">
|
||||
<rect key="frame" x="222" y="13" width="92" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="78" id="kpO-UW-tVV"/>
|
||||
</constraints>
|
||||
<buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="73">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
|
@ -48,23 +52,26 @@
|
|||
<action selector="cancelButtonAction:" target="-2" id="86"/>
|
||||
</connections>
|
||||
</button>
|
||||
<imageView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="12">
|
||||
<imageView translatesAutoresizingMaskIntoConstraints="NO" id="12">
|
||||
<rect key="frame" x="24" y="50" width="64" height="64"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="64" id="A3W-eQ-z1A"/>
|
||||
</constraints>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="AlertIcon" id="13"/>
|
||||
</imageView>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="39">
|
||||
<rect key="frame" x="103" y="97" width="300" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="39">
|
||||
<rect key="frame" x="103" y="92" width="300" height="17"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="17" id="P7H-ef-iqw"/>
|
||||
</constraints>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Lorem ipsum" id="40">
|
||||
<font key="font" metaFont="systemBold"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" preferredMaxLayoutWidth="296" translatesAutoresizingMaskIntoConstraints="NO" id="59">
|
||||
<rect key="frame" x="103" y="72" width="300" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" preferredMaxLayoutWidth="296" translatesAutoresizingMaskIntoConstraints="NO" id="59">
|
||||
<rect key="frame" x="103" y="67" width="300" height="17"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Lorem ipsum" id="60">
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
|
@ -72,6 +79,23 @@
|
|||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="59" firstAttribute="top" secondItem="39" secondAttribute="bottom" constant="8" symbolic="YES" id="1wt-ne-dF2"/>
|
||||
<constraint firstItem="5" firstAttribute="baseline" secondItem="71" secondAttribute="firstBaseline" id="2Td-RT-EYA"/>
|
||||
<constraint firstAttribute="bottom" secondItem="12" secondAttribute="bottom" constant="50" id="8xn-Ib-OoE"/>
|
||||
<constraint firstItem="5" firstAttribute="leading" secondItem="71" secondAttribute="trailing" constant="14" id="AGi-0c-Byw"/>
|
||||
<constraint firstAttribute="bottom" secondItem="71" secondAttribute="bottom" constant="20" symbolic="YES" id="D2C-fc-uYy"/>
|
||||
<constraint firstItem="39" firstAttribute="leading" secondItem="12" secondAttribute="trailing" constant="17" id="Fby-g8-C6h"/>
|
||||
<constraint firstItem="71" firstAttribute="baseline" secondItem="5" secondAttribute="baseline" id="JpJ-pp-vm0"/>
|
||||
<constraint firstItem="71" firstAttribute="top" secondItem="59" secondAttribute="bottom" constant="27" id="KE1-B3-FrZ"/>
|
||||
<constraint firstAttribute="trailing" secondItem="39" secondAttribute="trailing" constant="19" id="MvK-Vm-t8m"/>
|
||||
<constraint firstItem="39" firstAttribute="top" secondItem="2" secondAttribute="top" constant="21" id="QZ0-fh-VbK"/>
|
||||
<constraint firstItem="39" firstAttribute="leading" secondItem="59" secondAttribute="leading" id="amF-fF-0aV"/>
|
||||
<constraint firstAttribute="trailing" secondItem="5" secondAttribute="trailing" constant="21" id="en7-0d-fBr"/>
|
||||
<constraint firstItem="39" firstAttribute="trailing" secondItem="59" secondAttribute="trailing" id="l6t-qJ-mLX"/>
|
||||
<constraint firstItem="12" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="24" id="oRs-Yb-Ysu"/>
|
||||
<constraint firstItem="12" firstAttribute="top" secondItem="2" secondAttribute="top" constant="16" id="reW-NP-Ec0"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="-2" id="4"/>
|
|
@ -1,31 +0,0 @@
|
|||
//
|
||||
// OVNonModalAlertWindowController.h
|
||||
// OpenVanilla
|
||||
//
|
||||
// Created by Lukhnos Liu on 10/17/12.
|
||||
// Copyright (c) 2012 The OpenVanilla Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class OVNonModalAlertWindowController;
|
||||
|
||||
@protocol OVNonModalAlertWindowControllerDelegate <NSObject>
|
||||
- (void)nonModalAlertWindowControllerDidConfirm:(OVNonModalAlertWindowController *)controller;
|
||||
|
||||
@optional
|
||||
- (void)nonModalAlertWindowControllerDidCancel:(OVNonModalAlertWindowController *)controller;
|
||||
@end
|
||||
|
||||
@interface OVNonModalAlertWindowController : NSWindowController
|
||||
|
||||
+ (OVNonModalAlertWindowController *)sharedInstance;
|
||||
- (void)showWithTitle:(NSString *)title content:(NSString *)content confirmButtonTitle:(NSString *)confirmTitle cancelButtonTitle:(NSString *)cancelButtonTitle cancelAsDefault:(BOOL)cancelAsDefault delegate:(id<OVNonModalAlertWindowControllerDelegate>)delegate;
|
||||
- (IBAction)confirmButtonAction:(id)sender;
|
||||
- (IBAction)cancelButtonAction:(id)sender;
|
||||
@property (assign, nonatomic) IBOutlet NSTextField *titleTextField;
|
||||
@property (assign, nonatomic) IBOutlet NSTextField *contentTextField;
|
||||
@property (assign, nonatomic) IBOutlet NSButton *confirmButton;
|
||||
@property (assign, nonatomic) IBOutlet NSButton *cancelButton;
|
||||
@property (assign, nonatomic) id<OVNonModalAlertWindowControllerDelegate> delegate;
|
||||
@end
|
|
@ -1,131 +0,0 @@
|
|||
//
|
||||
// OVNonModalAlertWindowController.m
|
||||
// OpenVanilla
|
||||
//
|
||||
// Created by Lukhnos Liu on 10/17/12.
|
||||
// Copyright (c) 2012 The OpenVanilla Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OVNonModalAlertWindowController.h"
|
||||
|
||||
@implementation OVNonModalAlertWindowController
|
||||
@synthesize titleTextField = _titleTextField;
|
||||
@synthesize contentTextField = _contentTextField;
|
||||
@synthesize confirmButton = _confirmButton;
|
||||
@synthesize cancelButton = _cancelButton;
|
||||
@synthesize delegate = _delegate;
|
||||
|
||||
+ (OVNonModalAlertWindowController *)sharedInstance
|
||||
{
|
||||
static OVNonModalAlertWindowController *instance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[OVNonModalAlertWindowController alloc] initWithWindowNibName:@"OVNonModalAlertWindowController"];
|
||||
[instance window];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Suppress the use of the MIN/MAX macros
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wgnu-statement-expression"
|
||||
|
||||
- (void)showWithTitle:(NSString *)title content:(NSString *)content confirmButtonTitle:(NSString *)confirmTitle cancelButtonTitle:(NSString *)cancelButtonTitle cancelAsDefault:(BOOL)cancelAsDefault delegate:(id <OVNonModalAlertWindowControllerDelegate>)delegate;
|
||||
{
|
||||
// cancel previous alert
|
||||
if (self.window.visible) {
|
||||
if ([_delegate respondsToSelector:@selector(nonModalAlertWindowControllerDidCancel:)]) {
|
||||
[_delegate nonModalAlertWindowControllerDidCancel:self];
|
||||
}
|
||||
}
|
||||
|
||||
_delegate = delegate;
|
||||
|
||||
NSRect oldFrame = self.confirmButton.frame;
|
||||
[self.confirmButton setTitle:confirmTitle];
|
||||
[self.confirmButton sizeToFit];
|
||||
|
||||
NSRect newFrame = self.confirmButton.frame;
|
||||
|
||||
newFrame.size.width = MAX(90.0, (newFrame.size.width + 10.0));
|
||||
newFrame.origin.x += (oldFrame.size.width - newFrame.size.width);
|
||||
[self.confirmButton setFrame:newFrame];
|
||||
|
||||
if (cancelButtonTitle) {
|
||||
[self.cancelButton setTitle:cancelButtonTitle];
|
||||
[self.cancelButton sizeToFit];
|
||||
NSRect adjustedFrame = self.cancelButton.frame;
|
||||
adjustedFrame.size.width = MAX(90.0, (adjustedFrame.size.width + 10.0));
|
||||
adjustedFrame.origin.x = newFrame.origin.x - adjustedFrame.size.width;
|
||||
self.cancelButton.frame = adjustedFrame;
|
||||
self.cancelButton.hidden = NO;
|
||||
}
|
||||
else {
|
||||
self.cancelButton.hidden = YES;
|
||||
}
|
||||
|
||||
self.cancelButton.nextKeyView = self.confirmButton;
|
||||
self.confirmButton.nextKeyView = self.cancelButton;
|
||||
|
||||
if (cancelButtonTitle) {
|
||||
if (cancelAsDefault) {
|
||||
[self.window setDefaultButtonCell:self.cancelButton.cell];
|
||||
}
|
||||
else {
|
||||
self.cancelButton.keyEquivalent = @" ";
|
||||
[self.window setDefaultButtonCell:self.confirmButton.cell];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[[self window] setDefaultButtonCell:self.confirmButton.cell];
|
||||
}
|
||||
|
||||
self.titleTextField.stringValue = title;
|
||||
|
||||
oldFrame = [self.contentTextField frame];
|
||||
self.contentTextField.stringValue = content;
|
||||
|
||||
NSRect infiniteHeightFrame = oldFrame;
|
||||
infiniteHeightFrame.size.width -= 4.0;
|
||||
infiniteHeightFrame.size.height = 10240;
|
||||
newFrame = [content boundingRectWithSize:infiniteHeightFrame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: self.contentTextField.font}];
|
||||
newFrame.size.width = MAX(newFrame.size.width, oldFrame.size.width);
|
||||
newFrame.size.height += 4.0;
|
||||
newFrame.origin = oldFrame.origin;
|
||||
newFrame.origin.y -= (newFrame.size.height - oldFrame.size.height);
|
||||
[self.contentTextField setFrame:newFrame];
|
||||
|
||||
NSRect windowFrame = [[self window] frame];
|
||||
windowFrame.size.height += (newFrame.size.height - oldFrame.size.height);
|
||||
|
||||
self.window.level = CGShieldingWindowLevel() + 1;
|
||||
[self.window setFrame:windowFrame display:YES];
|
||||
[self.window center];
|
||||
[self.window makeKeyAndOrderFront:self];
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
- (IBAction)confirmButtonAction:(id)sender
|
||||
{
|
||||
[_delegate nonModalAlertWindowControllerDidConfirm:self];
|
||||
[self.window orderOut:self];
|
||||
}
|
||||
|
||||
- (IBAction)cancelButtonAction:(id)sender
|
||||
{
|
||||
[self cancel:sender];
|
||||
}
|
||||
|
||||
- (void)cancel:(id)sender
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(nonModalAlertWindowControllerDidCancel:)]) {
|
||||
[_delegate nonModalAlertWindowControllerDidCancel:self];
|
||||
}
|
||||
|
||||
_delegate = nil;
|
||||
[self.window orderOut:self];
|
||||
}
|
||||
|
||||
@end
|
|
@ -19,6 +19,7 @@
|
|||
5BDF2CFE2791BE4400838ADB /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */; };
|
||||
5BDF2CFF2791BECC00838ADB /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */; };
|
||||
5BDF2D012791C03B00838ADB /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */; };
|
||||
5BDF2D032791C71200838ADB /* NonModalAlertWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2D022791C71200838ADB /* NonModalAlertWindowController.swift */; };
|
||||
5BF4A6FE27844738007DC6E7 /* frmAboutWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 5BF4A6FC27844738007DC6E7 /* frmAboutWindow.m */; };
|
||||
5BF4A70027844DC5007DC6E7 /* frmAboutWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5BF4A70227844DC5007DC6E7 /* frmAboutWindow.xib */; };
|
||||
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A0421A615FEF3F50061ED63 /* FastLM.cpp */; };
|
||||
|
@ -46,8 +47,7 @@
|
|||
6ACA41FD15FC1D9000935EF6 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41F015FC1D9000935EF6 /* MainMenu.xib */; };
|
||||
6ACA41FF15FC1D9000935EF6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ACA41F415FC1D9000935EF6 /* main.m */; };
|
||||
6ACA420215FC1E5200935EF6 /* vChewing.app in Resources */ = {isa = PBXBuildFile; fileRef = 6A0D4EA215FC0D2D00ABF4B3 /* vChewing.app */; };
|
||||
6AFF97F2253B299E007F1C49 /* OVNonModalAlertWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6AFF97F0253B299E007F1C49 /* OVNonModalAlertWindowController.xib */; };
|
||||
6AFF97F3253B299E007F1C49 /* OVNonModalAlertWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AFF97F1253B299E007F1C49 /* OVNonModalAlertWindowController.m */; };
|
||||
6AFF97F2253B299E007F1C49 /* NonModalAlertWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6AFF97F0253B299E007F1C49 /* NonModalAlertWindowController.xib */; };
|
||||
D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */; };
|
||||
D48550A325EBE689006A204C /* OpenCC in Frameworks */ = {isa = PBXBuildFile; productRef = D48550A225EBE689006A204C /* OpenCC */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
@ -95,6 +95,7 @@
|
|||
5BC3FB82278492DE0022E99A /* data-chs.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "data-chs.txt"; sourceTree = "<group>"; };
|
||||
5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceHelper.swift; sourceTree = "<group>"; };
|
||||
5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
|
||||
5BDF2D022791C71200838ADB /* NonModalAlertWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonModalAlertWindowController.swift; sourceTree = "<group>"; };
|
||||
5BF4A6FB27844738007DC6E7 /* frmAboutWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = frmAboutWindow.h; sourceTree = "<group>"; };
|
||||
5BF4A6FC27844738007DC6E7 /* frmAboutWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = frmAboutWindow.m; sourceTree = "<group>"; };
|
||||
5BF4A70327844DD0007DC6E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/frmAboutWindow.xib; sourceTree = "<group>"; };
|
||||
|
@ -202,9 +203,7 @@
|
|||
6ACA41F415FC1D9000935EF6 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Source/Installer/main.m; sourceTree = SOURCE_ROOT; };
|
||||
6ACA41F515FC1D9000935EF6 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
|
||||
6ACA41F715FC1D9000935EF6 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.strings"; sourceTree = "<group>"; };
|
||||
6AFF97EF253B299E007F1C49 /* OVNonModalAlertWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVNonModalAlertWindowController.h; sourceTree = "<group>"; };
|
||||
6AFF97F0253B299E007F1C49 /* OVNonModalAlertWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OVNonModalAlertWindowController.xib; sourceTree = "<group>"; };
|
||||
6AFF97F1253B299E007F1C49 /* OVNonModalAlertWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OVNonModalAlertWindowController.m; sourceTree = "<group>"; };
|
||||
6AFF97F0253B299E007F1C49 /* NonModalAlertWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NonModalAlertWindowController.xib; sourceTree = "<group>"; };
|
||||
D427A9BF25ED28CC005D43E0 /* vChewing-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "vChewing-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenCCBridge.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
@ -277,8 +276,7 @@
|
|||
6A0D4EC715FC0D6400ABF4B3 /* InputMethodController.mm */,
|
||||
6A0D4EC815FC0D6400ABF4B3 /* main.m */,
|
||||
6A0D4EF615FC0DA600ABF4B3 /* vChewing-Prefix.pch */,
|
||||
6AFF97EF253B299E007F1C49 /* OVNonModalAlertWindowController.h */,
|
||||
6AFF97F1253B299E007F1C49 /* OVNonModalAlertWindowController.m */,
|
||||
5BDF2D022791C71200838ADB /* NonModalAlertWindowController.swift */,
|
||||
5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */,
|
||||
D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */,
|
||||
5BDF2CFD2791BE4400838ADB /* InputSourceHelper.swift */,
|
||||
|
@ -394,7 +392,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
5BF4A70227844DC5007DC6E7 /* frmAboutWindow.xib */,
|
||||
6AFF97F0253B299E007F1C49 /* OVNonModalAlertWindowController.xib */,
|
||||
6AFF97F0253B299E007F1C49 /* NonModalAlertWindowController.xib */,
|
||||
6A0D4EEE15FC0DA600ABF4B3 /* Images */,
|
||||
6A0D4EF515FC0DA600ABF4B3 /* vChewing-Info.plist */,
|
||||
6A0D4F4815FC0EE100ABF4B3 /* InfoPlist.strings */,
|
||||
|
@ -571,7 +569,7 @@
|
|||
6A0D4F5815FC0EF900ABF4B3 /* Localizable.strings in Resources */,
|
||||
6A2E40F6253A69DA00D1AE1D /* Images.xcassets in Resources */,
|
||||
6A38BC1515FC117A00A8A51F /* data.txt in Resources */,
|
||||
6AFF97F2253B299E007F1C49 /* OVNonModalAlertWindowController.xib in Resources */,
|
||||
6AFF97F2253B299E007F1C49 /* NonModalAlertWindowController.xib in Resources */,
|
||||
5B58E87F278413E7003EA2AD /* MITLicense.txt in Resources */,
|
||||
6A187E2616004C5900466B2E /* MainMenu.xib in Resources */,
|
||||
5BF4A70027844DC5007DC6E7 /* frmAboutWindow.xib in Resources */,
|
||||
|
@ -628,12 +626,12 @@
|
|||
5BF4A6FE27844738007DC6E7 /* frmAboutWindow.m in Sources */,
|
||||
5BC3EE1B278FC48C00F5E44C /* VerticalCandidateController.swift in Sources */,
|
||||
5B42B64027876FDC00BB9B9F /* UserOverrideModel.cpp in Sources */,
|
||||
6AFF97F3253B299E007F1C49 /* OVNonModalAlertWindowController.m in Sources */,
|
||||
D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */,
|
||||
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */,
|
||||
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */,
|
||||
5BDF2D012791C03B00838ADB /* PreferencesWindowController.swift in Sources */,
|
||||
5BC3EE1C278FC48C00F5E44C /* VTCandidateController.swift in Sources */,
|
||||
5BDF2D032791C71200838ADB /* NonModalAlertWindowController.swift in Sources */,
|
||||
5BC3EE1D278FC48C00F5E44C /* HorizontalCandidateController.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
Loading…
Reference in New Issue