1 package ch
.cyberduck
.ui
.cocoa
;
4 * Copyright (c) 2005 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * dkocher@cyberduck.ch
21 import ch
.cyberduck
.binding
.application
.NSButton
;
22 import ch
.cyberduck
.binding
.application
.NSImage
;
23 import ch
.cyberduck
.binding
.application
.NSImageView
;
24 import ch
.cyberduck
.binding
.application
.NSLayoutManager
;
25 import ch
.cyberduck
.binding
.application
.NSProgressIndicator
;
26 import ch
.cyberduck
.binding
.application
.NSTextField
;
27 import ch
.cyberduck
.binding
.application
.NSTextView
;
28 import ch
.cyberduck
.binding
.application
.NSWindow
;
29 import ch
.cyberduck
.binding
.foundation
.NSAttributedString
;
30 import ch
.cyberduck
.binding
.foundation
.NSObject
;
31 import ch
.cyberduck
.binding
.foundation
.NSRange
;
32 import ch
.cyberduck
.core
.PathCache
;
33 import ch
.cyberduck
.core
.Session
;
34 import ch
.cyberduck
.core
.TranscriptListener
;
35 import ch
.cyberduck
.core
.exception
.BackgroundException
;
36 import ch
.cyberduck
.core
.features
.Command
;
37 import ch
.cyberduck
.core
.local
.Application
;
38 import ch
.cyberduck
.core
.resources
.IconCacheFactory
;
39 import ch
.cyberduck
.core
.threading
.ControllerBackgroundAction
;
40 import ch
.cyberduck
.ui
.cocoa
.threading
.WindowMainAction
;
42 import org
.apache
.commons
.lang3
.StringUtils
;
43 import org
.rococoa
.cocoa
.foundation
.NSUInteger
;
48 public class CommandController
extends SheetController
implements TranscriptListener
, NSLayoutManager
.Delegate
{
51 private NSTextField inputField
;
53 private NSTextView responseField
;
55 private NSProgressIndicator progress
;
57 private NSImageView image
;
60 public void setWindow(final NSWindow window
) {
61 window
.setContentMinSize(window
.frame().size
);
62 super.setWindow(window
);
65 public void setInputField(NSTextField inputField
) {
66 this.inputField
= inputField
;
69 public void setResponseField(NSTextView responseField
) {
70 this.responseField
= responseField
;
71 this.responseField
.setEditable(false);
72 this.responseField
.setSelectable(true);
73 this.responseField
.setUsesFontPanel(false);
74 this.responseField
.setRichText(false);
75 this.responseField
.layoutManager().setDelegate(this.id());
78 public void setProgress(NSProgressIndicator progress
) {
79 this.progress
= progress
;
80 this.progress
.setDisplayedWhenStopped(false);
83 public void setImage(NSImageView image
) {
85 this.image
.setImage(IconCacheFactory
.<NSImage
>get().applicationIcon(new Application("com.apple.Terminal"), 128));
89 public void layoutManager_didCompleteLayoutForTextContainer_atEnd(NSLayoutManager layoutManager
,
90 NSObject textContainer
,
92 if(finished
&& this.responseField
.window().isVisible()) {
93 this.responseField
.scrollRangeToVisible(
94 NSRange
.NSMakeRange(this.responseField
.textStorage().length(), new NSUInteger(0))
99 private Session
<?
> session
;
101 public CommandController(final WindowController parent
, final Session session
) {
103 this.session
= session
;
107 protected String
getBundleName() {
112 public void sendButtonClicked(final NSButton sender
) {
113 final String command
= this.inputField
.stringValue();
114 if(StringUtils
.isNotBlank(command
)) {
115 progress
.startAnimation(null);
116 sender
.setEnabled(false);
117 parent
.background(new ControllerBackgroundAction
<Void
>(this, session
, PathCache
.empty()) {
119 public boolean alert() {
124 public Void
run() throws BackgroundException
{
125 final Command feature
= session
.getFeature(Command
.class);
126 feature
.send(command
, this, CommandController
.this);
131 public void cleanup() {
133 progress
.stopAnimation(null);
134 sender
.setEnabled(true);
138 public String
getActivity() {
146 public void log(boolean request
, final String message
) {
147 invoke(new WindowMainAction(this) {
150 responseField
.textStorage().replaceCharactersInRange_withAttributedString(
151 NSRange
.NSMakeRange(responseField
.textStorage().length(), new NSUInteger(0)),
152 NSAttributedString
.attributedStringWithAttributes(message
+ "\n", FIXED_WITH_FONT_ATTRIBUTES
));
158 protected boolean validateInput() {
163 public void callback(final int returncode
) {
168 public void invalidate() {
169 responseField
.layoutManager().setDelegate(null);