Skip to content

Commit

Permalink
Model and Tree share same filter (#132)
Browse files Browse the repository at this point in the history
Make sure that generated files (e.g. build/) are not displayed in the package.properties editor.
  • Loading branch information
prrvchr authored Jan 16, 2025
1 parent 541e80d commit ac105cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,11 @@ private void addFilter(PackagePropertiesModel model) {

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
/*
* Files to exclude: .* Folders to exclude: build, bin
*/
boolean selected = true;
if (element instanceof IAdaptable) {
IResource res = ((IAdaptable) element).getAdapter(IResource.class);
if (res != null) {
// FIXME: If we want to be able to see soft link pointing outside
// FIXME: the Package we need to accept resource not contained in package
if (model.isHidden(res) ||
res.getName().equals("build") || //$NON-NLS-1$
res.getName().equals("bin")) { //$NON-NLS-1$
selected = false;
} else if (model.getBasicLibraries().contains(res) ||
model.getDialogLibraries().contains(res) ||
model.getDescriptionFiles().containsValue(res)) {
selected = false;
}
selected = !model.isFilteredResource(res);
}
}
return selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,26 @@ public boolean isModified() {
}

/**
* Get whether the resource is hidden or not.
* Get whether the resource is filtered or not.
* Files to exclude: .* Folders to exclude: build, bin
*
* @param res
* the resource to check.
*
* @return <code>true</code> if resource is hidden, <code>false</code> otherwise.
* @return <code>true</code> if resource is filtered, <code>false</code> otherwise.
*/
public boolean isHidden(IResource res) {
return res.getName().startsWith("."); //$NON-NLS-1$
public boolean isFilteredResource(IResource res) {
boolean filtered = false;
if (res.getName().startsWith(".") || //$NON-NLS-1$
res.getName().equals("bin") || //$NON-NLS-1$
res.getName().equals("build")) { //$NON-NLS-1$
filtered = true;
} else if (getBasicLibraries().contains(res) ||
getDialogLibraries().contains(res) ||
getDescriptionFiles().containsValue(res)) {
filtered = true;
}
return filtered;
}

/**
Expand Down Expand Up @@ -661,14 +672,13 @@ private void addFolderResource(IResource folder) throws CoreException {
mFolders.put(folder, false);
IResource[] members = ((IContainer) folder).members();
for (IResource res : members) {
if (isFilteredResource(res)) {
continue;
}
if (res.getType() == IResource.FOLDER) {
if (!isHidden(res)) {
addFolderResource(res);
}
addFolderResource(res);
} else if (!mFiles.contains(res)) {
if (!isHidden(res)) {
mFiles.add(res);
}
mFiles.add(res);
}
}
}
Expand Down Expand Up @@ -752,7 +762,7 @@ private int serializeFolder(List<String> results, Entry<IResource, Boolean> entr
// Only empty folder will be saved if checked
int nbFolders = 0;
IResource folder = entry.getKey();
if (folder.getType() == IResource.FOLDER && folder.exists() && !isHidden(folder)) {
if (folder.getType() == IResource.FOLDER && folder.exists() && !isFilteredResource(folder)) {
if (!entry.getValue() && !hasVisibleMembers(folder)) {
results.add(folder.getProjectRelativePath().toString());
nbFolders++;
Expand Down Expand Up @@ -850,7 +860,7 @@ private void setFolderCheckState(Map<IResource, Boolean> folders, IContainer par
boolean any = false;
for (IResource res : members) {
// We need to consider only non-hidden resource
if (isHidden(res)) {
if (isFilteredResource(res)) {
continue;
}
if (res.getType() == IResource.FILE) {
Expand Down Expand Up @@ -901,7 +911,7 @@ private void setParentCheckState(IContainer parent) throws CoreException {
boolean any = false;
for (IResource res : members) {
// We need to consider only non-hidden resource
if (isHidden(res)) {
if (isFilteredResource(res)) {
continue;
}
if (res.getType() == IResource.FILE) {
Expand All @@ -928,7 +938,7 @@ private boolean hasVisibleMembers(IResource folder) throws CoreException {
boolean hasMembers = false;
IResource[] members = ((IContainer) folder).members();
for (IResource res : members) {
if (!isHidden(res)) {
if (!isFilteredResource(res)) {
hasMembers = true;
break;
}
Expand Down

0 comments on commit ac105cd

Please sign in to comment.