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
.binding
.application
.NSWindow
;
24 import ch
.cyberduck
.core
.Cache
;
25 import ch
.cyberduck
.core
.LocaleFactory
;
26 import ch
.cyberduck
.core
.Path
;
27 import ch
.cyberduck
.core
.UserDateFormatterFactory
;
28 import ch
.cyberduck
.core
.preferences
.PreferencesFactory
;
29 import ch
.cyberduck
.core
.resources
.IconCacheFactory
;
30 import ch
.cyberduck
.core
.threading
.DefaultMainAction
;
31 import ch
.cyberduck
.core
.transfer
.CopyTransfer
;
33 import org
.apache
.commons
.io
.FilenameUtils
;
34 import org
.apache
.commons
.lang3
.StringUtils
;
36 import java
.text
.MessageFormat
;
37 import java
.util
.ArrayList
;
38 import java
.util
.Collections
;
44 public class DuplicateFileController
extends FileController
{
46 public DuplicateFileController(final BrowserController parent
, final Cache
<Path
> cache
) {
47 super(parent
, cache
, NSAlert
.alert(
48 LocaleFactory
.localizedString("Duplicate File", "Duplicate"),
49 LocaleFactory
.localizedString("Enter the name for the new file:", "Duplicate"),
50 LocaleFactory
.localizedString("Duplicate", "Duplicate"),
52 LocaleFactory
.localizedString("Cancel", "Duplicate")
57 protected void beginSheet(final NSWindow window
) {
58 final Path selected
= this.getSelected();
59 alert
.setIcon(IconCacheFactory
.<NSImage
>get().fileIcon(selected
, 64));
60 String proposal
= MessageFormat
.format(PreferencesFactory
.get().getProperty("browser.duplicate.format"),
61 FilenameUtils
.getBaseName(selected
.getName()),
62 UserDateFormatterFactory
.get().getShortFormat(System
.currentTimeMillis(), false).replace(Path
.DELIMITER
, ':'),
63 StringUtils
.isNotEmpty(selected
.getExtension()) ?
"." + selected
.getExtension() : StringUtils
.EMPTY
);
64 inputField
.setStringValue(proposal
);
65 super.beginSheet(window
);
69 public void callback(final int returncode
) {
70 if(returncode
== DEFAULT_OPTION
) {
71 this.duplicate(this.getSelected(), inputField
.stringValue());
75 public void duplicate(final Path selected
, final String filename
) {
76 final Path duplicate
= new Path(selected
.getParent(), filename
, selected
.getType());
77 this.duplicate(selected
, duplicate
);
81 * @param source The original file to duplicate
82 * @param destination The destination of the duplicated file
84 public void duplicate(final Path source
, final Path destination
) {
85 this.duplicate(Collections
.singletonMap(source
, destination
));
89 * @param selected A map with the original files as the key and the destination
92 public void duplicate(final Map
<Path
, Path
> selected
) {
93 new OverwriteController(parent
).overwrite(new ArrayList
<Path
>(selected
.values()), new DefaultMainAction() {
96 parent
.transfer(new CopyTransfer(parent
.getSession().getHost(), parent
.getSession().getHost(), selected
),
97 new ArrayList
<Path
>(selected
.values()), true);