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
.UserDateFormatterFactory
;
27 import ch
.cyberduck
.core
.preferences
.PreferencesFactory
;
28 import ch
.cyberduck
.core
.resources
.IconCacheFactory
;
30 import org
.apache
.commons
.io
.FilenameUtils
;
31 import org
.apache
.commons
.lang3
.StringUtils
;
33 import java
.text
.MessageFormat
;
38 public class DuplicateFileController
extends FileController
{
40 public DuplicateFileController(final WindowController parent
, final Cache
<Path
> cache
) {
41 super(parent
, cache
, NSAlert
.alert(
42 LocaleFactory
.localizedString("Duplicate File", "Duplicate"),
43 LocaleFactory
.localizedString("Enter the name for the new file:", "Duplicate"),
44 LocaleFactory
.localizedString("Duplicate", "Duplicate"),
46 LocaleFactory
.localizedString("Cancel", "Duplicate")
48 alert
.setIcon(IconCacheFactory
.<NSImage
>get().fileIcon(this.getSelected(), 64));
49 final Path selected
= this.getSelected();
50 String proposal
= MessageFormat
.format(PreferencesFactory
.get().getProperty("browser.duplicate.format"),
51 FilenameUtils
.getBaseName(selected
.getName()),
52 UserDateFormatterFactory
.get().getShortFormat(System
.currentTimeMillis(), false).replace(Path
.DELIMITER
, ':'),
53 StringUtils
.isNotEmpty(selected
.getExtension()) ?
"." + selected
.getExtension() : StringUtils
.EMPTY
);
54 inputField
.setStringValue(proposal
);
58 public void callback(final int returncode
) {
59 if(returncode
== DEFAULT_OPTION
) {
60 this.run(this.getSelected(), inputField
.stringValue());
64 private void run(final Path selected
, final String filename
) {
65 final Path duplicate
= new Path(selected
.getParent(), filename
, selected
.getType());
66 ((BrowserController
) parent
).duplicatePath(selected
, duplicate
);