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
.NSAlert
;
22 import ch
.cyberduck
.binding
.application
.NSImage
;
23 import ch
.cyberduck
.core
.Cache
;
24 import ch
.cyberduck
.core
.LocaleFactory
;
25 import ch
.cyberduck
.core
.Path
;
26 import ch
.cyberduck
.core
.Session
;
27 import ch
.cyberduck
.core
.editor
.EditorFactory
;
28 import ch
.cyberduck
.core
.exception
.BackgroundException
;
29 import ch
.cyberduck
.core
.features
.Touch
;
30 import ch
.cyberduck
.core
.local
.Application
;
31 import ch
.cyberduck
.core
.resources
.IconCacheFactory
;
32 import ch
.cyberduck
.ui
.browser
.UploadTargetFinder
;
33 import ch
.cyberduck
.ui
.cocoa
.threading
.BrowserControllerBackgroundAction
;
35 import java
.text
.MessageFormat
;
36 import java
.util
.Collections
;
37 import java
.util
.EnumSet
;
42 public class CreateFileController
extends FileController
{
44 public CreateFileController(final WindowController parent
, final Cache
<Path
> cache
) {
45 super(parent
, cache
, NSAlert
.alert(
46 LocaleFactory
.localizedString("Create new file", "File"),
47 LocaleFactory
.localizedString("Enter the name for the new file:", "File"),
48 LocaleFactory
.localizedString("Create", "File"),
49 EditorFactory
.instance().getDefaultEditor() != Application
.notfound ? LocaleFactory
.localizedString("Edit", "File") : null,
50 LocaleFactory
.localizedString("Cancel", "File")
52 alert
.setIcon(IconCacheFactory
.<NSImage
>get().documentIcon(null, 64));
56 public void callback(final int returncode
) {
57 final Path parent
= new UploadTargetFinder(this.getWorkdir()).find(this.getSelected());
58 if(returncode
== DEFAULT_OPTION
) {
59 this.run(parent
, inputField
.stringValue(), false);
61 else if(returncode
== ALTERNATE_OPTION
) {
62 this.run(parent
, inputField
.stringValue(), true);
66 protected void run(final Path parent
, final String filename
, final boolean edit
) {
67 final BrowserController c
= (BrowserController
) this.parent
;
68 final Path file
= new Path(parent
, filename
, EnumSet
.of(Path
.Type
.file
));
69 c
.background(new BrowserControllerBackgroundAction
<Path
>(c
) {
71 public Path
run() throws BackgroundException
{
72 final Session
<?
> session
= c
.getSession();
73 final Touch feature
= session
.getFeature(Touch
.class);
76 file
.attributes().setSize(0L);
83 public String
getActivity() {
84 return MessageFormat
.format(LocaleFactory
.localizedString("Uploading {0}", "Status"),
89 public void cleanup() {
91 if(filename
.charAt(0) == '.') {
92 c
.setShowHiddenFiles(true);
94 c
.reload(Collections
.singletonList(file
), Collections
.singletonList(file
));