forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttachFileSelectionDialog.java
More file actions
78 lines (64 loc) · 2.33 KB
/
Copy pathAttachFileSelectionDialog.java
File metadata and controls
78 lines (64 loc) · 2.33 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.chat;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
import com.microsoft.copilot.eclipse.core.Constants;
import com.microsoft.copilot.eclipse.core.utils.FileUtils;
import com.microsoft.copilot.eclipse.ui.utils.UiUtils;
class AttachFileSelectionDialog extends FilteredResourcesSelectionDialog {
private static final String OPENED_FILES = "${OPENED_FILES}";
private List<IFile> openedFiles;
public AttachFileSelectionDialog(Shell shell, boolean multi, IContainer container) {
super(shell, multi, container, IResource.FILE | IResource.FOLDER);
this.openedFiles = UiUtils.getOpenedFiles();
this.setInitialPattern(OPENED_FILES, NONE);
this.refresh();
}
@Override
protected ItemsFilter createFilter() {
return new AttachFileItemsFilter();
}
class AttachFileItemsFilter extends ResourceFilter {
private Set<String> uris;
public AttachFileItemsFilter() {
super();
this.uris = new HashSet<>();
}
@Override
public boolean matchItem(Object item) {
if (!(item instanceof IResource)) {
return false;
}
String uri = FileUtils.getResourceUri((IResource) item);
if (uri == null || this.uris.contains(uri)) {
return false;
}
this.uris.add(uri);
final String pattern = this.patternMatcher.getPattern();
if (item instanceof IFile file) {
final String extension = file.getFileExtension();
boolean isExcludedType = extension != null && Constants.EXCLUDED_REFERENCE_FILE_TYPE.contains(extension);
if (isExcludedType) {
return false;
}
if (StringUtils.equals(pattern, OPENED_FILES)) {
return AttachFileSelectionDialog.this.openedFiles.contains(item);
} else {
return super.matchItem(item);
}
} else if (item instanceof IFolder) {
return super.matchItem(item);
}
return false;
}
}
}