mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
images: filter icons by theme (internal)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<idea-plugin>
|
||||
|
||||
<vendor>JetBrains</vendor>
|
||||
<extensionPoints>
|
||||
<extensionPoint name="images.themeFilter" interface="org.intellij.images.thumbnail.actions.ThemeFilter"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<search.topHitProvider implementation="org.intellij.images.options.impl.ImagesOptionsTopHitProvider"/>
|
||||
@@ -123,6 +126,12 @@
|
||||
icon="AllIcons.Actions.ShowImportStatements">
|
||||
</action>
|
||||
<separator/>
|
||||
|
||||
<action class="org.intellij.images.thumbnail.actions.FilterByThemeComboBoxAction"
|
||||
internal="true"
|
||||
id="Images.Thumbnails.FilterByTheme"
|
||||
description="Filter images by theme"/>
|
||||
|
||||
<action class="org.intellij.images.thumbnail.actions.HideThumbnailsAction"
|
||||
id="Images.Thumbnails.Hide"
|
||||
text="Hide"
|
||||
|
||||
@@ -20,8 +20,10 @@ import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.intellij.images.ImagesBundle;
|
||||
import org.intellij.images.thumbnail.actions.ThemeFilter;
|
||||
import org.intellij.images.ui.ImageComponentDecorator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Thumbnail thumbnail is a component with thumbnails for a set of {@link com.intellij.openapi.vfs.VirtualFile}.
|
||||
@@ -72,4 +74,12 @@ public interface ThumbnailView extends Disposable, ImageComponentDecorator {
|
||||
boolean isVisible();
|
||||
|
||||
void activate();
|
||||
|
||||
void setFilter(ThemeFilter filter);
|
||||
|
||||
/**
|
||||
* null means all files accepted
|
||||
*/
|
||||
@Nullable
|
||||
ThemeFilter getFilter();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.intellij.images.thumbnail.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import org.intellij.images.thumbnail.ThumbnailView;
|
||||
import org.intellij.images.thumbnail.actionSystem.ThumbnailViewActionUtil;
|
||||
|
||||
public class FilterByThemeAction extends AnAction {
|
||||
private final ThemeFilter myFilter;
|
||||
|
||||
public FilterByThemeAction(ThemeFilter filter) {
|
||||
myFilter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setText(myFilter.getDisplayName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
ThumbnailView view = ThumbnailViewActionUtil.getVisibleThumbnailView(e);
|
||||
|
||||
if (view != null) {
|
||||
view.setFilter(myFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/** $Id$ */
|
||||
|
||||
package org.intellij.images.thumbnail.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.intellij.images.thumbnail.ThumbnailView;
|
||||
import org.intellij.images.thumbnail.actionSystem.ThumbnailViewActionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public final class FilterByThemeComboBoxAction extends ComboBoxAction {
|
||||
|
||||
public void update(final AnActionEvent e) {
|
||||
ThumbnailView view = ThumbnailViewActionUtil.getVisibleThumbnailView(e);
|
||||
ThemeFilter[] extensions = ThemeFilter.EP_NAME.getExtensions();
|
||||
e.getPresentation().setVisible(view != null && extensions.length > 0);
|
||||
if (view != null) {
|
||||
ThemeFilter filter = view.getFilter();
|
||||
e.getPresentation().setText(filter == null ? "All" : filter.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new FilterByThemeAction(new ThemeFilter() {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "All";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(VirtualFile file) {
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
for (ThemeFilter filter : ThemeFilter.EP_NAME.getExtensions()) {
|
||||
group.add(new FilterByThemeAction(filter));
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.intellij.images.thumbnail.actions;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
public interface ThemeFilter {
|
||||
ExtensionPointName<ThemeFilter> EP_NAME = ExtensionPointName.create("com.intellij.images.themeFilter");
|
||||
|
||||
String getDisplayName();
|
||||
boolean accepts(VirtualFile file);
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import icons.ImagesIcons;
|
||||
import org.intellij.images.editor.ImageZoomModel;
|
||||
import org.intellij.images.editor.actionSystem.ImageEditorActions;
|
||||
import org.intellij.images.thumbnail.ThumbnailView;
|
||||
import org.intellij.images.thumbnail.actions.ThemeFilter;
|
||||
import org.intellij.images.vfs.IfsUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -46,6 +47,7 @@ final class ThumbnailViewImpl implements ThumbnailView {
|
||||
private boolean recursive = false;
|
||||
private VirtualFile root = null;
|
||||
private final ThumbnailViewUI myThubmnailViewUi;
|
||||
private ThemeFilter myFilter;
|
||||
|
||||
public ThumbnailViewImpl(Project project) {
|
||||
this.project = project;
|
||||
@@ -118,6 +120,17 @@ final class ThumbnailViewImpl implements ThumbnailView {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFilter(ThemeFilter filter) {
|
||||
myFilter = filter;
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThemeFilter getFilter() {
|
||||
return myFilter;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
toolWindow.setAvailable(visible, null);
|
||||
if (visible) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.intellij.images.fileTypes.ImageFileTypeManager;
|
||||
import org.intellij.images.options.*;
|
||||
import org.intellij.images.thumbnail.ThumbnailView;
|
||||
import org.intellij.images.thumbnail.actionSystem.ThumbnailViewActions;
|
||||
import org.intellij.images.thumbnail.actions.ThemeFilter;
|
||||
import org.intellij.images.ui.ImageComponent;
|
||||
import org.intellij.images.ui.ImageComponentDecorator;
|
||||
import org.intellij.images.ui.ThumbnailComponent;
|
||||
@@ -171,8 +172,11 @@ final class ThumbnailViewUI extends JPanel implements DataProvider, Disposable {
|
||||
Arrays.sort(virtualFiles, VIRTUAL_FILE_COMPARATOR);
|
||||
|
||||
model.ensureCapacity(model.size() + virtualFiles.length + 1);
|
||||
ThemeFilter filter = thumbnailView.getFilter();
|
||||
for (VirtualFile virtualFile : virtualFiles) {
|
||||
model.addElement(virtualFile);
|
||||
if (filter == null || filter.accepts(virtualFile)) {
|
||||
model.addElement(virtualFile);
|
||||
}
|
||||
}
|
||||
if (model.size() > 0) {
|
||||
list.setSelectedIndex(0);
|
||||
|
||||
@@ -38,5 +38,6 @@
|
||||
<orderEntry type="module" module-name="testFramework" />
|
||||
<orderEntry type="module" module-name="dom-impl" />
|
||||
<orderEntry type="module" module-name="devkit-jps-plugin" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="images" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -180,6 +180,11 @@
|
||||
|
||||
<annotator language="Properties" implementationClass="org.jetbrains.idea.devkit.inspections.RegistryPropertiesAnnotator"/>
|
||||
|
||||
<images.themeFilter implementation="org.jetbrains.idea.devkit.icons.DefaultThemeFilter"/>
|
||||
<images.themeFilter implementation="org.jetbrains.idea.devkit.icons.DefaultHiDPIThemeFilter"/>
|
||||
<images.themeFilter implementation="org.jetbrains.idea.devkit.icons.DarculaThemeFilter"/>
|
||||
<images.themeFilter implementation="org.jetbrains.idea.devkit.icons.DarculaHiDPIThemeFilter"/>
|
||||
|
||||
<moduleService serviceImplementation="org.jetbrains.idea.devkit.build.PluginBuildConfiguration"/>
|
||||
<generatedSourcesFilter implementation="org.jetbrains.idea.devkit.internal.IconsGeneratedSourcesFilter"/>
|
||||
|
||||
|
||||
37
plugins/devkit/src/icons/AbstractThemeFilter.java
Normal file
37
plugins/devkit/src/icons/AbstractThemeFilter.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.icons;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.intellij.images.thumbnail.actions.ThemeFilter;
|
||||
|
||||
public abstract class AbstractThemeFilter implements ThemeFilter {
|
||||
private final Theme myTheme;
|
||||
|
||||
protected AbstractThemeFilter(Theme theme) {
|
||||
myTheme = theme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return myTheme.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(VirtualFile file) {
|
||||
return myTheme.accepts(file);
|
||||
}
|
||||
}
|
||||
23
plugins/devkit/src/icons/DarculaHiDPIThemeFilter.java
Normal file
23
plugins/devkit/src/icons/DarculaHiDPIThemeFilter.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.icons;
|
||||
|
||||
public class DarculaHiDPIThemeFilter extends AbstractThemeFilter {
|
||||
|
||||
protected DarculaHiDPIThemeFilter() {
|
||||
super(Theme.HIGH_DPI_DARK);
|
||||
}
|
||||
}
|
||||
23
plugins/devkit/src/icons/DarculaThemeFilter.java
Normal file
23
plugins/devkit/src/icons/DarculaThemeFilter.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.icons;
|
||||
|
||||
public class DarculaThemeFilter extends AbstractThemeFilter {
|
||||
|
||||
protected DarculaThemeFilter() {
|
||||
super(Theme.DARK);
|
||||
}
|
||||
}
|
||||
23
plugins/devkit/src/icons/DefaultHiDPIThemeFilter.java
Normal file
23
plugins/devkit/src/icons/DefaultHiDPIThemeFilter.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.icons;
|
||||
|
||||
public class DefaultHiDPIThemeFilter extends AbstractThemeFilter {
|
||||
|
||||
protected DefaultHiDPIThemeFilter() {
|
||||
super(Theme.HIGH_DPI_WHITE);
|
||||
}
|
||||
}
|
||||
23
plugins/devkit/src/icons/DefaultThemeFilter.java
Normal file
23
plugins/devkit/src/icons/DefaultThemeFilter.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.icons;
|
||||
|
||||
public class DefaultThemeFilter extends AbstractThemeFilter {
|
||||
|
||||
protected DefaultThemeFilter() {
|
||||
super(Theme.WHITE);
|
||||
}
|
||||
}
|
||||
66
plugins/devkit/src/icons/Theme.java
Normal file
66
plugins/devkit/src/icons/Theme.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.icons;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
public enum Theme {
|
||||
WHITE(null, "Default"),
|
||||
HIGH_DPI_WHITE("@2x", "Default HiDPI"),
|
||||
DARK("dark", "Darcula"),
|
||||
HIGH_DPI_DARK("@2x_dark", "Darcula HiDPI");
|
||||
private final String myExtension;
|
||||
private final String myDisplayName;
|
||||
|
||||
Theme(String extension, String displayName) {
|
||||
myExtension = extension;
|
||||
myDisplayName = displayName;
|
||||
}
|
||||
|
||||
public String getExtension() {
|
||||
return myExtension;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return myDisplayName;
|
||||
}
|
||||
|
||||
public boolean accepts(VirtualFile fileName) {
|
||||
String nameWithoutExtension = FileUtil.getNameWithoutExtension(fileName.getName());
|
||||
if (myExtension != null) {
|
||||
if (nameWithoutExtension.endsWith(myExtension)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
VirtualFile parent = fileName.getParent();
|
||||
if (parent != null && parent.findChild(nameWithoutExtension + myExtension + ".png") != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (Theme theme : values()) {
|
||||
String extension = theme.getExtension();
|
||||
if (extension != null && nameWithoutExtension.endsWith(extension)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user