Skip to content

Commit

Permalink
#97 Possibility to use custom icons
Browse files Browse the repository at this point in the history
added internal handling and override of images / icons

Signed-off-by: Andre Bossert <[email protected]>
  • Loading branch information
anb0s committed Dec 27, 2016
1 parent 367128c commit 523ba7a
Show file tree
Hide file tree
Showing 119 changed files with 208 additions and 177 deletions.
4 changes: 2 additions & 2 deletions plugin/build.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
bin.includes = icons/,\
bin.includes = images/,\
plugin.xml,\
META-INF/,\
target/easyshell-library.jar,\
src/de/anbos/eclipse/easyshell/plugin/UIMessages.properties,\
releases/,\
scripts/
src.includes = icons/,\
src.includes = images/,\
manpages/,\
releases/CHANGES.TXT,\
releases/README.TXT,\
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
6 changes: 3 additions & 3 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=group.open">
<menu
icon="icons/easyshell.png"
icon="images/easyshell.png"
id="de.anbos.eclipse.easyshell.plugin.menu"
label="EasyShell">
<visibleWhen
Expand All @@ -145,7 +145,7 @@
</visibleWhen>
</menu>
<menu
icon="icons/easyshell.png"
icon="images/easyshell.png"
id="de.anbos.eclipse.easyshell.plugin.menu.file"
label="EasyShell">
<visibleWhen
Expand All @@ -162,7 +162,7 @@
</visibleWhen>
</menu>
<menu
icon="icons/easyshell.png"
icon="images/easyshell.png"
id="de.anbos.eclipse.easyshell.plugin.menu.directory"
label="EasyShell">
<visibleWhen
Expand Down
19 changes: 12 additions & 7 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.Bundle;
Expand Down Expand Up @@ -110,19 +111,23 @@ public static ImageDescriptor getImageDescriptor(String id) {
return getDefault().getImageRegistry().getDescriptor(id);
}

public static Image getImage(String id) {
return getDefault().getImageRegistry().get(id);
}

protected void initializeImageRegistry(ImageRegistry registry) {
Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID);
OS os = Utils.getOS();
for (String iconName : Category.getIconsAsList()) {
String iconPath = Constants.IMAGE_PATH + os.getId() + "/" + iconName;
URL url = bundle.getEntry(iconPath);
for (String imageId : Category.getImageIdsAsList()) {
String imagePath = Constants.IMAGE_PATH + os.getId() + "/" + imageId + Constants.IMAGE_EXT;
URL url = bundle.getEntry(imagePath);
if (url == null) {
iconPath = Constants.IMAGE_PATH + iconName;
imagePath = Constants.IMAGE_PATH + imageId + Constants.IMAGE_EXT;
}
addImageToRegistry(registry, bundle, iconPath, iconName);
addImageToRegistry(registry, bundle, imagePath, imageId);
}
addImageToRegistry(registry, bundle, Constants.IMAGE_PATH + Constants.IMAGE_EASYSHELL, Constants.IMAGE_EASYSHELL);
addImageToRegistry(registry, bundle, Constants.IMAGE_PATH + Constants.IMAGE_ECLIPSE, Constants.IMAGE_ECLIPSE);
addImageToRegistry(registry, bundle, Constants.IMAGE_PATH + Constants.IMAGE_EASYSHELL + Constants.IMAGE_EXT, Constants.IMAGE_EASYSHELL);
addImageToRegistry(registry, bundle, Constants.IMAGE_PATH + Constants.IMAGE_ECLIPSE + Constants.IMAGE_EXT, Constants.IMAGE_ECLIPSE);
}

protected void addImageToRegistry(ImageRegistry registry, Bundle bundle, String imagePath, String image_id) {
Expand Down
25 changes: 12 additions & 13 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ public interface Constants {
// Plugin
public static final String PLUGIN_ID = "de.anbos.eclipse.easyshell.plugin";

// Images
//public static final String IMAGE_EXT = "gif";
public static final String IMAGE_EXT = "png";
public static final String IMAGE_PATH = "icons/";
// Icons
public static final String IMAGE_EXT = ".png";
public static final String IMAGE_PATH = "images/";
// categories
public static final String IMAGE_UNKNOWN = "unknown." + IMAGE_EXT;
public static final String IMAGE_DEFAULT = "default." + IMAGE_EXT;
public static final String IMAGE_OPEN = "open." + IMAGE_EXT;
public static final String IMAGE_RUN = "run." + IMAGE_EXT;
public static final String IMAGE_EXPLORE = "explore." + IMAGE_EXT;
public static final String IMAGE_CLIPBOARD = "clipboard." + IMAGE_EXT;
public static final String IMAGE_USER = "user." + IMAGE_EXT;
public static final String IMAGE_NONE = "none";
public static final String IMAGE_DEFAULT = "default";
public static final String IMAGE_OPEN = "open";
public static final String IMAGE_RUN = "run";
public static final String IMAGE_EXPLORE = "explore";
public static final String IMAGE_CLIPBOARD = "clipboard";
public static final String IMAGE_USER = "user";
// other
public static final String IMAGE_EASYSHELL = "easyshell." + IMAGE_EXT;
public static final String IMAGE_ECLIPSE = "eclipse." + IMAGE_EXT;
public static final String IMAGE_EASYSHELL = "easyshell";
public static final String IMAGE_ECLIPSE = "eclipse";

// Preferences
public static final String PREF_COMMANDS_PRESET = "COMMANDS_PRESET";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,27 @@ easyshell.command.page.dialog.migration.question=You have canceled the migration
easyshell.menu.editor.dialog.title.new=Create new menu
easyshell.menu.editor.dialog.title.edit=Edit existing menu
easyshell.menu.editor.dialog.title.group.menu=Menu
easyshell.menu.editor.dialog.title.group.tooltip.menu=Menu definition
easyshell.menu.editor.dialog.title.group.tooltip.menu=Menu item definition
easyshell.menu.editor.dialog.title.group.command=Command
easyshell.menu.editor.dialog.title.group.tooltip.command=Command definition
easyshell.menu.editor.dialog.error.text.name=Please enter a valid name
easyshell.menu.editor.dialog.error.type.text=Please choose a valid type

easyshell.menu.editor.dialog.label.active=Enabled:
easyshell.menu.editor.dialog.label.tooltip.active=Enabled = show menu\nDisabled = hide menu
easyshell.menu.editor.dialog.label.name=Name:
easyshell.menu.editor.dialog.label.tooltip.name=Menu name
easyshell.menu.editor.dialog.label.pattern=
easyshell.menu.editor.dialog.label.tooltip.pattern=The selected or user entered pattern
easyshell.menu.editor.dialog.label.tooltip.active=Enabled = show menu item\nDisabled = hide menu item
easyshell.menu.editor.dialog.label.combo.pattern=Pattern:
easyshell.menu.editor.dialog.combo.tooltip.pattern=Select the name pattern for menu item
easyshell.menu.editor.dialog.label.name=Preview:
easyshell.menu.editor.dialog.label.tooltip.name=Preview of menu item
easyshell.menu.editor.dialog.label.pattern=Name:
easyshell.menu.editor.dialog.label.tooltip.pattern=The selected or entered name pattern
easyshell.menu.editor.dialog.label.text.filter=Filter:
easyshell.menu.editor.dialog.label.tooltip.filter=Enter search string
easyshell.menu.editor.dialog.label.command=Command:
easyshell.menu.editor.dialog.label.tooltip.command=The command

easyshell.menu.editor.dialog.label.combo.preset=Select:
easyshell.menu.editor.dialog.combo.tooltip.preset=Select the used command for menu
easyshell.menu.editor.dialog.label.combo.pattern=Pattern:
easyshell.menu.editor.dialog.combo.tooltip.pattern=Select the name pattern for menu

easyshell.menu.editor.dialog.button.text.new=New...
easyshell.menu.editor.dialog.button.tooltip.new=Add new command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void createContributionItems(IServiceLocator serviceLocator, IContributio
|| (resTypeSupported == resTypeWanted)) {
addItem(serviceLocator, additions, item.getNameExpanded(),
"de.anbos.eclipse.easyshell.plugin.commands.execute",
Utils.getParameterMapFromMenuData(item), item.getCommandData().getCategory().getIcon(),
Utils.getParameterMapFromMenuData(item), item.getImageId(),
true);
}
} catch (UnknownCommandID e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
Expand All @@ -38,7 +37,7 @@ public ExecuteCommandDialog(Shell parent, IWorkbench workbench, MenuDataList men
setImage(getDefaultImage());
setMatchEmptyString(true);
setMultipleSelection(true);
setImage(new Image(null, Activator.getImageDescriptor(Constants.IMAGE_EASYSHELL).getImageData()));
setImage(Activator.getImage(Constants.IMAGE_EASYSHELL));
init(workbench, menuDataList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.eclipse.swt.graphics.Image;

import de.anbos.eclipse.easyshell.plugin.Activator;
import de.anbos.eclipse.easyshell.plugin.exceptions.UnknownCommandID;
import de.anbos.eclipse.easyshell.plugin.preferences.MenuData;

public class ExecuteCommandLabelProvider extends LabelProvider {
Expand All @@ -26,12 +25,7 @@ public Image getImage(Object element) {
return null;
}
MenuData data = (MenuData)element;
try {
return new Image(null, Activator.getImageDescriptor(data.getCommandData().getCategory().getIcon()).getImageData());
} catch (UnknownCommandID e) {
e.logInternalError();
return null;
}
return Activator.getImage(data.getImageId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
String openCmd = store.getString(PreferenceEntry.preferenceTargetOpen.getString());
CommandData cmdDataOpen = new CommandData(null, PresetType.presetUser, os, command.getConsole(), ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryOpen, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpaces, migrateCommandVariables(openCmd));
cmdDataList.add(cmdDataOpen);
MenuData menuDataOpen = new MenuData(cmdDataOpen.getId(), true, MenuNameType.menuNameTypeOpenHere, null, cmdDataOpen.getId());
MenuData menuDataOpen = new MenuData(cmdDataOpen.getId(), true, MenuNameType.menuNameTypeOpenHere, null, null, cmdDataOpen.getId());
menuDataOpen.setPosition(position++);
menuDataOpen.setNamePattern(menuDataOpen.getNamePattern() + postfix);
menuDataOpen.setNameType(MenuNameType.menuNameTypeUser);
Expand All @@ -245,7 +245,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
String runCmd = store.getString(PreferenceEntry.preferenceTargetRun.getString());
CommandData cmdDataRun = new CommandData(null, PresetType.presetUser, os, command.getConsole(), ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryRun, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpaces, migrateCommandVariables(runCmd));
cmdDataList.add(cmdDataRun);
MenuData menuDataRun = new MenuData(cmdDataRun.getId(), true, MenuNameType.menuNameTypeRunWith, null, cmdDataRun.getId());
MenuData menuDataRun = new MenuData(cmdDataRun.getId(), true, MenuNameType.menuNameTypeRunWith, null, null, cmdDataRun.getId());
menuDataRun.setPosition(position++);
menuDataRun.setNamePattern(menuDataRun.getNamePattern() + postfix);
menuDataRun.setNameType(MenuNameType.menuNameTypeUser);
Expand All @@ -254,7 +254,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
String exploreCmd = store.getString(PreferenceEntry.preferenceTargetExplore.getString());
CommandData cmdDataExplore = new CommandData(null, PresetType.presetUser, os, command.getExplorer(), ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryExplore, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpaces, migrateCommandVariables(exploreCmd));
cmdDataList.add(cmdDataExplore);
MenuData menuDataExplore = new MenuData(cmdDataExplore.getId(), true, MenuNameType.menuNameTypeShowIn, null, cmdDataExplore.getId());
MenuData menuDataExplore = new MenuData(cmdDataExplore.getId(), true, MenuNameType.menuNameTypeShowIn, null, null, cmdDataExplore.getId());
menuDataExplore.setPosition(position++);
menuDataExplore.setNamePattern(menuDataExplore.getNamePattern() + postfix);
menuDataExplore.setNameType(MenuNameType.menuNameTypeUser);
Expand All @@ -263,7 +263,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
String copyPathCmd = store.getString(PreferenceEntry.preferenceTargetCopyPath.getString());
CommandData cmdDataCopyPath = new CommandData(null, PresetType.presetUser, os, "Full Path", ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpaces, migrateCommandVariables(copyPathCmd));
cmdDataList.add(cmdDataCopyPath);
MenuData menuDataCopyPath = new MenuData(cmdDataCopyPath.getId(), true, MenuNameType.menuNameTypeCopyToClipboard, null, cmdDataCopyPath.getId());
MenuData menuDataCopyPath = new MenuData(cmdDataCopyPath.getId(), true, MenuNameType.menuNameTypeCopyToClipboard, null, null, cmdDataCopyPath.getId());
menuDataCopyPath.setPosition(position++);
menuDataCopyPath.setNamePattern(menuDataCopyPath.getNamePattern() + postfix);
menuDataCopyPath.setNameType(MenuNameType.menuNameTypeUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
openCmdList.add(openCmd);
CommandData cmdDataOpen = new CommandData(null, PresetType.presetUser, os, command.getConsole(), ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryOpen, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpaces, PrefsV1_4.migrateCommandVariables(openCmd));
cmdDataList.add(cmdDataOpen);
MenuData menuDataOpen = new MenuData(cmdDataOpen.getId(), true, MenuNameType.menuNameTypeOpenHere, null, cmdDataOpen.getId());
MenuData menuDataOpen = new MenuData(cmdDataOpen.getId(), true, MenuNameType.menuNameTypeOpenHere, null, null, cmdDataOpen.getId());
menuDataOpen.setPosition(position++);
menuDataOpen.setNamePattern(menuDataOpen.getNamePattern() + postfix);
menuDataOpen.setNameType(MenuNameType.menuNameTypeUser);
Expand All @@ -314,7 +314,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
runCmdList.add(runCmd);
CommandData cmdDataRun = new CommandData(null, PresetType.presetUser, os, command.getConsole(), ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryRun, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpaces, PrefsV1_4.migrateCommandVariables(runCmd));
cmdDataList.add(cmdDataRun);
MenuData menuDataRun = new MenuData(cmdDataRun.getId(), true, MenuNameType.menuNameTypeRunWith, null, cmdDataRun.getId());
MenuData menuDataRun = new MenuData(cmdDataRun.getId(), true, MenuNameType.menuNameTypeRunWith, null, null, cmdDataRun.getId());
menuDataRun.setPosition(position++);
menuDataRun.setNamePattern(menuDataRun.getNamePattern() + postfix);
menuDataRun.setNameType(MenuNameType.menuNameTypeUser);
Expand All @@ -326,7 +326,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
exploreCmdList.add(exploreCmd);
CommandData cmdDataExplore = new CommandData(null, PresetType.presetUser, os, command.getExplorer(), ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryExplore, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpaces, PrefsV1_4.migrateCommandVariables(exploreCmd));
cmdDataList.add(cmdDataExplore);
MenuData menuDataExplore = new MenuData(cmdDataExplore.getId(), true, MenuNameType.menuNameTypeShowIn, null, cmdDataExplore.getId());
MenuData menuDataExplore = new MenuData(cmdDataExplore.getId(), true, MenuNameType.menuNameTypeShowIn, null, null, cmdDataExplore.getId());
menuDataExplore.setPosition(position++);
menuDataExplore.setNamePattern(menuDataExplore.getNamePattern() + postfix);
menuDataExplore.setNameType(MenuNameType.menuNameTypeUser);
Expand All @@ -338,7 +338,7 @@ public static boolean loadStore(IPreferenceStore store, OS os, CommandDataList c
copyPathList.add(copyPathCmd);
CommandData cmdDataCopyPath = new CommandData(null, PresetType.presetUser, os, "Full Path", ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpaces, PrefsV1_4.migrateCommandVariables(copyPathCmd));
cmdDataList.add(cmdDataCopyPath);
MenuData menuDataCopyPath = new MenuData(cmdDataCopyPath.getId(), true, MenuNameType.menuNameTypeCopyToClipboard, null, cmdDataCopyPath.getId());
MenuData menuDataCopyPath = new MenuData(cmdDataCopyPath.getId(), true, MenuNameType.menuNameTypeCopyToClipboard, null, null, cmdDataCopyPath.getId());
menuDataCopyPath.setPosition(position++);
menuDataCopyPath.setNamePattern(menuDataCopyPath.getNamePattern() + postfix);
menuDataCopyPath.setNameType(MenuNameType.menuNameTypeUser);
Expand Down
29 changes: 26 additions & 3 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/misc/UtilsUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
package de.anbos.eclipse.easyshell.plugin.misc;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
Expand All @@ -33,13 +33,36 @@ static public void createLabel(Composite parent, String name, String tooltip) {
}
}

static public Label createImageLabel(Composite parent, String image) {
static public Label createLabel(Composite parent, String imageId, String text, String tooltip) {
Label label = new Label(parent, SWT.LEFT);
label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
label.setImage(new Image(null, Activator.getImageDescriptor(image).getImageData()));
if (text != null) {
label.setText(text);
label.setToolTipText(tooltip);
}
label.setImage(Activator.getImage(imageId));
return label;
}

static public Label createImageLabel(Composite parent, String imageId) {
return createLabel(parent, imageId, null, null);
}

static public Button createButton(Composite parent, String imageId, String text, String tooltip) {
Button button = new Button(parent, SWT.LEFT);
button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
if (text!=null) {
button.setText(text);
button.setToolTipText(tooltip);
}
button.setImage(Activator.getImage(imageId));
return button;
}

static public Button createImageButton(Composite parent, String imageId) {
return createButton(parent, imageId, null, null);
}

static public void refreshWidget(Widget widget) {
// send event to refresh
Event event = new Event();
Expand Down
Loading

0 comments on commit 523ba7a

Please sign in to comment.