1 package ch
.cyberduck
.ui
.cocoa
;
4 * Copyright (c) 2002-2009 David Kocher. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * Bug fixes, suggestions and comments should be sent to:
19 * dkocher@cyberduck.ch
22 import ch
.cyberduck
.binding
.application
.NSAlert
;
23 import ch
.cyberduck
.binding
.application
.NSButton
;
24 import ch
.cyberduck
.binding
.application
.NSPanel
;
25 import ch
.cyberduck
.binding
.application
.NSView
;
26 import ch
.cyberduck
.binding
.application
.SheetCallback
;
27 import ch
.cyberduck
.binding
.foundation
.NSEnumerator
;
28 import ch
.cyberduck
.binding
.foundation
.NSObject
;
29 import ch
.cyberduck
.core
.DefaultProviderHelpService
;
31 import org
.rococoa
.Foundation
;
32 import org
.rococoa
.ID
;
33 import org
.rococoa
.Rococoa
;
34 import org
.rococoa
.cocoa
.foundation
.NSRect
;
36 public abstract class AlertController
extends SheetController
{
39 * If using alert and no custom window
41 protected NSAlert alert
;
43 public AlertController(final WindowController parent
, final NSAlert alert
) {
44 this(parent
, alert
, NSAlert
.NSWarningAlertStyle
);
47 public AlertController(final WindowController parent
, final NSAlert alert
, final int style
) {
50 this.alert
.setAlertStyle(style
);
51 this.alert
.setDelegate(this.id());
52 this.setWindow(this.alert
.window());
55 public void setAccessoryView(final NSView view
) {
56 view
.setFrame(new NSRect(alert
.window().contentView().frame().size
.width
.floatValue(),
57 view
.frame().size
.height
.floatValue()));
58 alert
.setAccessoryView(view
);
62 public void beginSheet() {
68 protected void beginSheetImpl() {
69 parent
.window().makeKeyAndOrderFront(null);
71 NSEnumerator buttons
= alert
.buttons().objectEnumerator();
73 while(((button
= buttons
.nextObject()) != null)) {
74 final NSButton b
= Rococoa
.cast(button
, NSButton
.class);
75 b
.setTarget(this.id());
76 b
.setAction(Foundation
.selector("closeSheet:"));
78 alert
.beginSheet(parent
.window(), this.id(), Foundation
.selector("alertDidEnd:returnCode:contextInfo:"), null);
81 protected void focus() {
85 protected void setTitle(final String title
) {
86 alert
.setMessageText(title
);
89 protected void setMessage(final String message
) {
90 alert
.setInformativeText(message
);
94 * Message the alert sends to modalDelegate after the user responds but before the sheet is dismissed.
96 * @param alert Alert window
97 * @param returnCode Button code
98 * @param contextInfo Context
100 public void alertDidEnd_returnCode_contextInfo(final NSAlert alert
, final int returnCode
, final ID contextInfo
) {
101 this.sheetDidClose_returnCode_contextInfo(alert
.window(), returnCode
, contextInfo
);
105 protected int getCallbackOption(final NSButton selected
) {
106 if(selected
.tag() == NSPanel
.NSAlertDefaultReturn
) {
107 return SheetCallback
.DEFAULT_OPTION
;
109 else if(selected
.tag() == NSPanel
.NSAlertAlternateReturn
) {
110 return SheetCallback
.ALTERNATE_OPTION
;
112 else if(selected
.tag() == NSPanel
.NSAlertOtherReturn
) {
113 return SheetCallback
.CANCEL_OPTION
;
115 return SheetCallback
.DEFAULT_OPTION
;
121 protected void help() {
122 new DefaultProviderHelpService().help();
126 * When the help button is pressed, the alert delegate (delegate) is first sent a alertShowHelp: message.
128 * @param alert Alert window
129 * @return True if help request was handled.
131 public boolean alertShowHelp(final NSAlert alert
) {