blob: d4ae6ad513e9aac2ba55cd84c25754e141a4a90a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*******************************************************************************
* Copyright (c) 2010 SAP AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Mathias Kinzler (SAP AG) - initial implementation
*******************************************************************************/
package org.eclipse.egit.ui.internal.repository.tree.command;
import java.io.File;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.util.FS;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
/**
* "Adds" a Repository upon pasting the clip-board contents.
* <p>
* This checks if the clip-board contents corresponds to a Git repository folder
* and adds that repository to the view if it doesn't already exists.
* <p>
* TODO we should extend this and open the "Add Repositories" dialog if the
* clip-board contents corresponds to an existing directory in the local file
* system. The "Directory" field of the dialog should be pre-filled with the
* directory from the clip-board.
*/
public class PasteCommand extends
RepositoriesViewCommandHandler<RepositoryTreeNode> {
public Object execute(ExecutionEvent event) throws ExecutionException {
// we check if the pasted content is a directory
// repository location and try to add this
String errorMessage = null;
Clipboard clip = null;
try {
clip = new Clipboard(getShell(event).getDisplay());
String content = (String) clip.getContents(TextTransfer
.getInstance());
if (content == null) {
errorMessage = UIText.RepositoriesView_NothingToPasteMessage;
return null;
}
File file = new File(content);
if (!file.exists() || !file.isDirectory()) {
errorMessage = UIText.RepositoriesView_ClipboardContentNotDirectoryMessage;
return null;
}
if (!RepositoryCache.FileKey.isGitRepository(file, FS.DETECTED)) {
errorMessage = NLS
.bind(
UIText.RepositoriesView_ClipboardContentNoGitRepoMessage,
content);
return null;
}
if (util.addConfiguredRepository(file)) {
// let's do the auto-refresh the rest
} else
errorMessage = NLS.bind(
UIText.RepositoriesView_PasteRepoAlreadyThere, content);
return null;
} finally {
if (clip != null)
// we must dispose ourselves
clip.dispose();
if (errorMessage != null)
Activator.handleError(errorMessage, null, true);
}
}
}
|