From 60326e10de9ff6557b8ced07c3813a7a0067e95a Mon Sep 17 00:00:00 2001 From: Andre Bossert Date: Fri, 21 Apr 2017 13:03:11 +0200 Subject: [PATCH] #136 [v2.0] possibility to change menu icons - dialog - set and reset handling - tooltips Signed-off-by: Andre Bossert --- .../easyshell/plugin/UIMessages.properties | 7 +- .../easyshell/plugin/misc/UtilsUI.java | 32 +- .../plugin/preferences/CommandData.java | 194 ++++----- .../plugin/preferences/CommandDataDialog.java | 66 +-- .../plugin/preferences/MainPage.java | 68 ++-- .../plugin/preferences/MenuData.java | 149 +++---- .../plugin/preferences/MenuDataDialog.java | 377 +++++++++--------- 7 files changed, 464 insertions(+), 429 deletions(-) diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/UIMessages.properties b/plugin/src/de/anbos/eclipse/easyshell/plugin/UIMessages.properties index 6c5f2490..3eaa42ed 100644 --- a/plugin/src/de/anbos/eclipse/easyshell/plugin/UIMessages.properties +++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/UIMessages.properties @@ -15,7 +15,7 @@ easyshell.main.page.dialog.defaults.title=Restore defaults easyshell.main.page.dialog.defaults.question=All your settings will be overwritten!\n\nYou can still use "Cancel" button afterwards for undo.\n\nDo you really want to restore default settings? easyshell.main.page.dialog.migration.title=Migration easyshell.main.page.dialog.migration.question=You have canceled the migration of settings from previous version.\n\nAll your settings will be written now and migration will be skipped completely!\n\nDo you really want to overwrite the migrated settings? -easyshell.main.page.error.title.incompletedata=Missing or wrong parameters +easyshell.error.title.incompletedata=Missing or wrong parameters easyshell.main.page.error.text.debug=Please choose a valid debug type easyshell.main.page.title.group1=General @@ -101,6 +101,10 @@ 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.button.tooltip.image=Select menu icon +easyshell.menu.editor.dialog.image.title=Menu icon selection +easyshell.menu.editor.dialog.image.text=Select the icon from the tree: +easyshell.menu.editor.dialog.image.none=reset to icon from command category 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: @@ -141,7 +145,6 @@ easyshell.command.editor.dialog.title.group2=Usable variables easyshell.command.editor.dialog.tooltip.group2=Double click at variable name copies it to clipboard easyshell.command.editor.dialog.title.group3=Usable converters easyshell.command.editor.dialog.tooltip.group3=Double click at converter name copies it to clipboard -easyshell.command.editor.dialog.error.title.incompletedata=Missing or wrong parameters easyshell.command.editor.dialog.error.text.resource=Please choose a valid resource type easyshell.command.editor.dialog.error.text.category=Please choose a valid category easyshell.command.editor.dialog.error.text.type=Please choose a valid command type diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/misc/UtilsUI.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/misc/UtilsUI.java index b2c8610f..0cddc780 100644 --- a/plugin/src/de/anbos/eclipse/easyshell/plugin/misc/UtilsUI.java +++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/misc/UtilsUI.java @@ -29,38 +29,40 @@ static public void createLabel(Composite parent, String name, String tooltip) { label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); label.setText(name); if (tooltip != null) { - label.setToolTipText(tooltip); + label.setToolTipText(tooltip); } } 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)); - if (text != null) { - label.setText(text); - label.setToolTipText(tooltip); - } + 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); + 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)); + Button button = new Button(parent, SWT.LEFT); + button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + if (text!=null) { + button.setText(text); + } + if (tooltip != null) { + 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 Button createImageButton(Composite parent, String imageId, String tooltip) { + return createButton(parent, imageId, null, tooltip); } static public void refreshWidget(Widget widget) { diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandData.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandData.java index 2ff33655..5c6d8296 100644 --- a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandData.java +++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandData.java @@ -140,15 +140,19 @@ public String getCommand() { } public String getImageId() { - if (!imageId.equals(Constants.IMAGE_NONE)) { - return imageId; - } else { - return getCategory().getImageId(); - } + if (imageId.equals(Constants.IMAGE_NONE)) { + return getCategoryImageId(); + } else { + return imageId; + } + } + + public String getCategoryImageId() { + return getCategory().getImageId(); } public String getImageIdOwn() { - return imageId; + return imageId; } public String getCommandAsComboName() { @@ -184,7 +188,7 @@ public void removeModifyData() { public void addOrRemoveModifyData(CommandDataBasic modifyData) { if (checkIfUserDataOverridesPreset(modifyData)) { - addModifyData(modifyData); + addModifyData(modifyData); } else { removeModifyData(); } @@ -203,37 +207,37 @@ public void setCategory(Category category) { } private void setImageId(String imageId) { - if (imageId != null) { - this.imageId = imageId; - } else { - this.imageId = Constants.IMAGE_NONE; - } - } + if (imageId == null || imageId.equals(Constants.IMAGE_NONE) || imageId.equals(getCategoryImageId())) { + this.imageId = Constants.IMAGE_NONE; + } else { + this.imageId = imageId; + } + } public void setCommandType(CommandType cmdType) { this.commandType = cmdType; } - public boolean equals(Object object) { - if(!(object instanceof CommandData)) { - return false; - } - CommandData data = (CommandData)object; - if(data.getId().equals(this.getId()) - /*data.getPosition() == this.getPosition() && - data.getBasicData().equals(this.getBasicData()) && - data.getPresetType() == this.getPresetType() && - data.getOS() == this.getOS() && - data.getCategory() == this.getCategory() && - data.getCommandType() == this.getCommandType() &&*/ - ) - { - return true; - } - return false; - } - - public boolean deserialize(Version version, String value, StringTokenizer tokenizer, String delimiter) { + public boolean equals(Object object) { + if(!(object instanceof CommandData)) { + return false; + } + CommandData data = (CommandData)object; + if(data.getId().equals(this.getId()) + /*data.getPosition() == this.getPosition() && + data.getBasicData().equals(this.getBasicData()) && + data.getPresetType() == this.getPresetType() && + data.getOS() == this.getOS() && + data.getCategory() == this.getCategory() && + data.getCommandType() == this.getCommandType() &&*/ + ) + { + return true; + } + return false; + } + + public boolean deserialize(Version version, String value, StringTokenizer tokenizer, String delimiter) { if((value == null || value.length() <= 0) && tokenizer == null) { return false; } @@ -242,11 +246,11 @@ public boolean deserialize(Version version, String value, StringTokenizer tokeni } // set internal members setPosition(Integer.parseInt(tokenizer.nextToken())); - setId(tokenizer.nextToken()); - // set command data members - String presetTypeStr = tokenizer.nextToken(); + setId(tokenizer.nextToken()); + // set command data members + String presetTypeStr = tokenizer.nextToken(); if (version.getId() < Version.v2_1_001.getId() && presetTypeStr.equals("presetPluginAndUser")) { - presetTypeStr = "presetPluginModify"; + presetTypeStr = "presetPluginModify"; } presetType = PresetType.getFromEnum(presetTypeStr); setOs(OS.getFromEnum(tokenizer.nextToken())); @@ -257,49 +261,49 @@ public boolean deserialize(Version version, String value, StringTokenizer tokeni resourceTypeStr = "resourceTypeDirectory"; } basicData.setResourceType(ResourceType.getFromEnum(resourceTypeStr)); - // handling of working directory, category and imageId + // handling of working directory, category and imageId String imageIdStr = Constants.IMAGE_NONE; - if (version.getId() >= Version.v2_0_003.getId()) { - basicData.setUseWorkingDirectory(Boolean.valueOf(tokenizer.nextToken()).booleanValue()); - basicData.setWorkingDirectory(tokenizer.nextToken()); - String categoryStr = tokenizer.nextToken(); - if (version.getId() < Version.v2_0_005.getId() && categoryStr.equals("categoryOther")) { - categoryStr = "categoryUser"; - } - setCategory(Category.getFromEnum(categoryStr)); - if (version.getId() >= Version.v2_1_005.getId()) { - imageIdStr = tokenizer.nextToken(); - } - setCommandType(CommandType.getFromEnum(tokenizer.nextToken())); - } else { - basicData.setUseWorkingDirectory(false); - basicData.setWorkingDirectory("${easyshell:container_loc}"); - String commandTypeStr = tokenizer.nextToken(); - setCategory(Category.getFromDeprecatedCommandTypeEnum(commandTypeStr)); - setCommandType(CommandType.getFromDeprecatedCommandTypeEnum(commandTypeStr)); - } - setImageId(imageIdStr); - // go on compatible - String commandTokenizer = CommandTokenizer.commandTokenizerSpaces.toString(); + if (version.getId() >= Version.v2_0_003.getId()) { + basicData.setUseWorkingDirectory(Boolean.valueOf(tokenizer.nextToken()).booleanValue()); + basicData.setWorkingDirectory(tokenizer.nextToken()); + String categoryStr = tokenizer.nextToken(); + if (version.getId() < Version.v2_0_005.getId() && categoryStr.equals("categoryOther")) { + categoryStr = "categoryUser"; + } + setCategory(Category.getFromEnum(categoryStr)); + if (version.getId() >= Version.v2_1_005.getId()) { + imageIdStr = tokenizer.nextToken(); + } + setCommandType(CommandType.getFromEnum(tokenizer.nextToken())); + } else { + basicData.setUseWorkingDirectory(false); + basicData.setWorkingDirectory("${easyshell:container_loc}"); + String commandTypeStr = tokenizer.nextToken(); + setCategory(Category.getFromDeprecatedCommandTypeEnum(commandTypeStr)); + setCommandType(CommandType.getFromDeprecatedCommandTypeEnum(commandTypeStr)); + } + setImageId(imageIdStr); + // go on compatible + String commandTokenizer = CommandTokenizer.commandTokenizerSpaces.toString(); if (version.getId() >= Version.v2_1_001.getId()) { - String oldCommandTokenizer = tokenizer.nextToken(); - if (version.getId() >= Version.v2_1_003.getId()) { - commandTokenizer = oldCommandTokenizer; - } + String oldCommandTokenizer = tokenizer.nextToken(); + if (version.getId() >= Version.v2_1_003.getId()) { + commandTokenizer = oldCommandTokenizer; + } } basicData.setCommandTokenizer(CommandTokenizer.getFromEnum(commandTokenizer)); - basicData.setCommand(tokenizer.nextToken()); - if (version.getId() >= Version.v2_0_005.getId()) { - if (version.getId() < Version.v2_1_001.getId()) { - // let read modifyData if there - if (getPresetType() == PresetType.presetPluginModify) { - setModifyData(new CommandDataBasic(getId())); - modifyData.deserialize(version, null, tokenizer, delimiter); - } - } - } - return true; - } + basicData.setCommand(tokenizer.nextToken()); + if (version.getId() >= Version.v2_0_005.getId()) { + if (version.getId() < Version.v2_1_001.getId()) { + // let read modifyData if there + if (getPresetType() == PresetType.presetPluginModify) { + setModifyData(new CommandDataBasic(getId())); + modifyData.deserialize(version, null, tokenizer, delimiter); + } + } + } + return true; + } public boolean deserialize(String value, StringTokenizer tokenizer, String delimiter) { return deserialize(Version.actual, value, tokenizer, delimiter); @@ -310,9 +314,9 @@ public String serialize(Version version, String delimiter) { ret += getId() + delimiter; PresetType presetTypeTemp = getPresetType(); if (version.getId() >= Version.v2_1_001.getId()) { - if (presetTypeTemp == PresetType.presetPluginModify) { - presetTypeTemp = PresetType.presetPlugin; - } + if (presetTypeTemp == PresetType.presetPluginModify) { + presetTypeTemp = PresetType.presetPlugin; + } } ret += presetTypeTemp.toString() + delimiter; ret += getOs().toString() + delimiter; @@ -323,20 +327,20 @@ public String serialize(Version version, String delimiter) { ret += basicData.getWorkingDirectory() + delimiter; ret += getCategory().toString() + delimiter; if (version.getId() >= Version.v2_1_005.getId()) { - ret += getImageIdOwn() + delimiter; + ret += getImageIdOwn() + delimiter; } } ret += getCommandType().toString() + delimiter; if (version.getId() >= Version.v2_1_001.getId()) { - ret += basicData.getCommandTokenizer().toString() + delimiter; + ret += basicData.getCommandTokenizer().toString() + delimiter; } ret += basicData.getCommand() + delimiter; if (version.getId() >= Version.v2_0_005.getId()) { - if (version.getId() < Version.v2_1_001.getId()) { - if (getPresetType() == PresetType.presetPluginModify) { - ret += modifyData.serialize(version, delimiter); - } - } + if (version.getId() < Version.v2_1_001.getId()) { + if (getPresetType() == PresetType.presetPluginModify) { + ret += modifyData.serialize(version, delimiter); + } + } } return ret; } @@ -345,17 +349,17 @@ public String serialize(String delimiter) { return serialize(Version.actual, delimiter); } - public void setSelected(boolean selected) { - this.selected = selected; - } + public void setSelected(boolean selected) { + this.selected = selected; + } - public boolean isSelected() { - return this.selected; - } + public boolean isSelected() { + return this.selected; + } @Override - public boolean verify() { - return super.verify() && basicData != null && basicData.verify(); - } + public boolean verify() { + return super.verify() && basicData != null && basicData.verify(); + } } diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandDataDialog.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandDataDialog.java index 473fe468..af142579 100644 --- a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandDataDialog.java +++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandDataDialog.java @@ -96,17 +96,17 @@ protected boolean isResizable() { } public Control createDialogArea(Composite parent) { - Composite pageComponent = createPageComponent(parent); + Composite pageComponent = createPageComponent(parent); createCommandControls(pageComponent); - if (showVariablesInfo) { - createVariablesOverview(pageComponent); - } + if (showVariablesInfo) { + createVariablesOverview(pageComponent); + } - if (showConvertersInfo) { - createConvertersOverview(pageComponent); - } + if (showConvertersInfo) { + createConvertersOverview(pageComponent); + } setHelpAvailable(showHelpButton); @@ -124,8 +124,8 @@ public Control createDialogArea(Composite parent) { } public Composite createPageComponent(Composite parent) { - Font font = parent.getFont(); - Composite pageComponent = new Composite(parent,SWT.NULL); + Font font = parent.getFont(); + Composite pageComponent = new Composite(parent,SWT.NULL); GridLayout layout0 = new GridLayout(); layout0.numColumns = 1; layout0.makeColumnsEqualWidth = false; @@ -140,10 +140,10 @@ public Composite createPageComponent(Composite parent) { } public Group createGroupCommand(Composite parent) { - Font font = parent.getFont(); - Group pageGroupCommand = new Group(parent, SWT.SHADOW_ETCHED_IN); - pageGroupCommand.setText(Activator.getResourceString("easyshell.command.editor.dialog.title.group1")); - pageGroupCommand.setToolTipText(Activator.getResourceString("easyshell.command.editor.dialog.tooltip.group1")); + Font font = parent.getFont(); + Group pageGroupCommand = new Group(parent, SWT.SHADOW_ETCHED_IN); + pageGroupCommand.setText(Activator.getResourceString("easyshell.command.editor.dialog.title.group1")); + pageGroupCommand.setToolTipText(Activator.getResourceString("easyshell.command.editor.dialog.tooltip.group1")); GridLayout layoutCommand = new GridLayout(); layoutCommand.numColumns = 3; layoutCommand.makeColumnsEqualWidth = false; @@ -157,7 +157,7 @@ public Group createGroupCommand(Composite parent) { } private void createCommandControls(Composite parent) { - Group pageGroupCommand = createGroupCommand(parent); + Group pageGroupCommand = createGroupCommand(parent); // create resource type combo createResourceTypeCombo(pageGroupCommand); // create category combo @@ -229,7 +229,7 @@ private ContentProposalAdapter addContentAssist(Text textControl) { } private void createVariablesOverview(Composite parent) { - Font font = parent.getFont(); + Font font = parent.getFont(); Group pageGroup2 = new Group(parent, SWT.SHADOW_ETCHED_IN); pageGroup2.setText(Activator.getResourceString("easyshell.command.editor.dialog.title.group2")); pageGroup2.setToolTipText(Activator.getResourceString("easyshell.command.editor.dialog.tooltip.group2")); @@ -252,7 +252,7 @@ private void createVariablesOverview(Composite parent) { } private void createConvertersOverview(Composite parent) { - Font font = parent.getFont(); + Font font = parent.getFont(); Group pageGroup3 = new Group(parent, SWT.SHADOW_ETCHED_IN); pageGroup3.setText(Activator.getResourceString("easyshell.command.editor.dialog.title.group3")); pageGroup3.setToolTipText(Activator.getResourceString("easyshell.command.editor.dialog.tooltip.group3")); @@ -345,7 +345,7 @@ protected void okPressed() { break; case presetPlugin: case presetPluginModify: - data.addOrRemoveModifyData(cmdDataBasic); + data.addOrRemoveModifyData(cmdDataBasic); break; default: break; @@ -355,7 +355,7 @@ protected void okPressed() { private boolean validateValues() { - final String title = Activator.getResourceString("easyshell.command.editor.dialog.error.title.incompletedata"); + final String title = Activator.getResourceString("easyshell.error.title.incompletedata"); // check resource if ( (resourceTypeCombo.getText() == null) || (resourceTypeCombo.getText().length() <= 0)) { @@ -369,13 +369,13 @@ private boolean validateValues() { return false; } - // check command type + // check command type if ( (commandTypeCombo.getText() == null) || (commandTypeCombo.getText().length() <= 0)) { - MessageDialog.openError(getShell(), title, Activator.getResourceString("easyshell.command.editor.dialog.error.text.type")); - return false; + MessageDialog.openError(getShell(), title, Activator.getResourceString("easyshell.command.editor.dialog.error.text.type")); + return false; } - boolean valid = true; + boolean valid = true; // check name String text = Activator.getResourceString("easyshell.command.editor.dialog.error.text.name"); @@ -393,9 +393,9 @@ private boolean validateValues() { // check value if (valid) { - text = Activator.getResourceString("easyshell.command.editor.dialog.error.text.value"); + text = Activator.getResourceString("easyshell.command.editor.dialog.error.text.value"); if ( (valueText.getText() == null) || (valueText.getText().length() <= 0)) { - valid = false; + valid = false; } } @@ -419,14 +419,14 @@ private void createResourceTypeCombo(Composite parent) { resourceTypeCombo.select(0); resourceTypeCombo.addSelectionListener(new SelectionListener() { @Override - public void widgetSelected(SelectionEvent e) { - //String text = resourceTypeCombo.getItem(resourceTypeCombo.getSelectionIndex()); - } + public void widgetSelected(SelectionEvent e) { + //String text = resourceTypeCombo.getItem(resourceTypeCombo.getSelectionIndex()); + } @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } - }); + }); String[] items = resourceTypeCombo.getItems(); for(int i = 0 ; i < items.length ; i++) { if(items[i].equals(this.data.getResourceType().getName())) { @@ -485,9 +485,9 @@ public void widgetSelected(SelectionEvent e) { String text = commandTypeCombo.getItem(commandTypeCombo.getSelectionIndex()); CommandType commandType = CommandType.getFromName(text); boolean enabledTokenizer = commandType == CommandType.commandTypeExecute; - tokenizerCombo.setEnabled(enabledTokenizer); - String tokenizerName = enabledTokenizer ? null : CommandTokenizer.commandTokenizerDisabled.getName(); - selectTokenizerCombo(tokenizerName); + tokenizerCombo.setEnabled(enabledTokenizer); + String tokenizerName = enabledTokenizer ? null : CommandTokenizer.commandTokenizerDisabled.getName(); + selectTokenizerCombo(tokenizerName); } @Override public void widgetDefaultSelected(SelectionEvent e) { @@ -532,9 +532,9 @@ public void widgetDefaultSelected(SelectionEvent e) { private void selectTokenizerCombo(String altName) { String[] items = tokenizerCombo.getItems(); for(int i = 0 ; i < items.length ; i++) { - String name = altName != null ? altName : this.data.getCommandTokenizer().getName(); + String name = altName != null ? altName : this.data.getCommandTokenizer().getName(); if(items[i].equals(name)) { - tokenizerCombo.select(i); + tokenizerCombo.select(i); break; } } diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MainPage.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MainPage.java index c8ea4977..5d604c32 100644 --- a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MainPage.java +++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MainPage.java @@ -39,7 +39,7 @@ public class MainPage extends PreferencePage implements IWorkbenchPreferencePage { private IWorkbench workbench; - + private Button debug; private Button toolTipAll; private Button toolTipClipboard; @@ -63,10 +63,10 @@ public void init(IWorkbench workbench) { @Override public boolean performOk() { - if (!validateValues()) { - return false; - } - boolean save = true; + if (!validateValues()) { + return false; + } + boolean save = true; if (!GeneralDataStore.instance().isMigrated()) { String title = Activator.getResourceString("easyshell.main.page.dialog.migration.title"); String question = Activator.getResourceString("easyshell.main.page.dialog.migration.question"); @@ -77,17 +77,17 @@ public boolean performOk() { 1); // no is the default int result = dialog.open(); if (result == 0) { - GeneralDataStore.instance().setMigrated(true); + GeneralDataStore.instance().setMigrated(true); } else { save = false; } } if (save) { - GeneralDataStore.instance().getData().setDebug(debug.getSelection() ? Debug.debugYes : Debug.debugNo); - GeneralDataStore.instance().getData().setToolTipAll(toolTipAll.getSelection() ? Tooltip.tooltipYes : Tooltip.tooltipNo); - GeneralDataStore.instance().getData().setToolTipClipboard(toolTipClipboard.getSelection() ? Tooltip.tooltipYes : Tooltip.tooltipNo); - GeneralDataStore.instance().getData().setToolTipError(toolTipError.getSelection() ? Tooltip.tooltipYes : Tooltip.tooltipNo); - GeneralDataStore.instance().save(); + GeneralDataStore.instance().getData().setDebug(debug.getSelection() ? Debug.debugYes : Debug.debugNo); + GeneralDataStore.instance().getData().setToolTipAll(toolTipAll.getSelection() ? Tooltip.tooltipYes : Tooltip.tooltipNo); + GeneralDataStore.instance().getData().setToolTipClipboard(toolTipClipboard.getSelection() ? Tooltip.tooltipYes : Tooltip.tooltipNo); + GeneralDataStore.instance().getData().setToolTipError(toolTipError.getSelection() ? Tooltip.tooltipYes : Tooltip.tooltipNo); + GeneralDataStore.instance().save(); } return save; } @@ -98,7 +98,7 @@ protected void performApply() { } private boolean validateValues() { - //final String title = Activator.getResourceString("easyshell.main.page.error.title.incompletedata"); + //final String title = Activator.getResourceString("easyshell.error.title.incompletedata"); // check resource /*if ( (debugCombo.getText() == null) || (debugCombo.getText().length() <= 0)) { MessageDialog.openError(getShell(), title, Activator.getResourceString("easyshell.main.page.error.text.debug")); @@ -125,16 +125,16 @@ protected void performDefaults() { @Override protected Control createContents(Composite parent) { - // forward to menu page + // forward to menu page Map params = new HashMap(); params.put("preferencePageId","de.anbos.eclipse.easyshell.plugin.preferences.MenuPage"); Utils.executeCommand(workbench, "org.eclipse.ui.window.preferences", params, true); - + // create own Composite pageComponent = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(3, false); pageComponent.setLayout(layout); - createGroup(pageComponent); + createGroup(pageComponent); return pageComponent; } @@ -144,10 +144,10 @@ private void createGroup(Composite pageComponent) { refreshWidgets(); } - private Group createGroup1(Composite pageComponent) { - Group pageGroup = new Group(pageComponent, SWT.SHADOW_ETCHED_IN); - pageGroup.setText(Activator.getResourceString("easyshell.main.page.title.group1")); - pageGroup.setToolTipText(Activator.getResourceString("easyshell.main.page.tooltip.group1")); + private Group createGroup1(Composite pageComponent) { + Group pageGroup = new Group(pageComponent, SWT.SHADOW_ETCHED_IN); + pageGroup.setText(Activator.getResourceString("easyshell.main.page.title.group1")); + pageGroup.setToolTipText(Activator.getResourceString("easyshell.main.page.tooltip.group1")); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.makeColumnsEqualWidth = false; @@ -157,12 +157,12 @@ private Group createGroup1(Composite pageComponent) { GridData data = new GridData(GridData.FILL_HORIZONTAL); pageGroup.setLayoutData(data); pageGroup.setFont(pageComponent.getFont()); - return pageGroup; - } + return pageGroup; + } - private Composite createGroup1_1(Composite pageComponent) { - // define group1 - Composite pageGroup = new Composite(pageComponent, SWT.NONE); + private Composite createGroup1_1(Composite pageComponent) { + // define group1 + Composite pageGroup = new Composite(pageComponent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = false; @@ -172,11 +172,11 @@ private Composite createGroup1_1(Composite pageComponent) { GridData data = new GridData(GridData.FILL_HORIZONTAL); pageGroup.setLayoutData(data); pageGroup.setFont(pageComponent.getFont()); - return pageGroup; - } + return pageGroup; + } private void createWidgets(Composite parent) { - createCheckBoxDebug(parent); + createCheckBoxDebug(parent); createCheckBoxToolTipAll(parent); Composite group1_1 = createGroup1_1(parent); createCheckBoxToolTipClipboard(group1_1); @@ -184,15 +184,15 @@ private void createWidgets(Composite parent) { } private void refreshWidgets() { - UtilsUI.refreshWidget(debug); - UtilsUI.refreshWidget(toolTipAll); + UtilsUI.refreshWidget(debug); + UtilsUI.refreshWidget(toolTipAll); UtilsUI.refreshWidget(toolTipClipboard); - UtilsUI.refreshWidget(toolTipError); + UtilsUI.refreshWidget(toolTipError); } private void createCheckBoxDebug(Composite parent) { // draw label - //UtilsUI.createLabel(parent, "", null); + //UtilsUI.createLabel(parent, "", null); // draw checkbox GeneralData data = GeneralDataStore.instance().getData(); debug = new Button(parent,SWT.CHECK); @@ -212,7 +212,7 @@ public void widgetDefaultSelected(SelectionEvent e) { private void createCheckBoxToolTipAll(Composite parent) { // draw label - //UtilsUI.createLabel(parent, "", null); + //UtilsUI.createLabel(parent, "", null); // draw checkbox GeneralData data = GeneralDataStore.instance().getData(); toolTipAll = new Button(parent,SWT.CHECK); @@ -236,7 +236,7 @@ public void widgetDefaultSelected(SelectionEvent e) { private void createCheckBoxToolTipClipboard(Composite parent) { // draw label - UtilsUI.createLabel(parent, "", null); + UtilsUI.createLabel(parent, "", null); // draw checkbox GeneralData data = GeneralDataStore.instance().getData(); toolTipClipboard = new Button(parent,SWT.CHECK); @@ -256,7 +256,7 @@ public void widgetDefaultSelected(SelectionEvent e) { private void createCheckBoxToolTipError(Composite parent) { // draw label - UtilsUI.createLabel(parent, "", null); + UtilsUI.createLabel(parent, "", null); // draw checkbox GeneralData data = GeneralDataStore.instance().getData(); toolTipError = new Button(parent,SWT.CHECK); diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuData.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuData.java index dfd1d2b6..fde5a041 100644 --- a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuData.java +++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuData.java @@ -40,7 +40,7 @@ public MenuData(String id, boolean enabled, MenuNameType nameType, String namePa setCommandId(commandId); } - public MenuData(String newId, String commandId) { + public MenuData(String newId, String commandId) { super(newId); setNameType(MenuNameType.menuNameTypeGeneric1); setCommandId(commandId); @@ -55,6 +55,7 @@ public MenuData(String newId, MenuData data) { this.enabled = data.isEnabled(); this.nameType = data.getNameType(); this.namePattern = data.getNamePattern(); + this.imageId = data.getImageIdOwn(); } public MenuData(MenuData data, boolean generateNewId) { @@ -64,9 +65,9 @@ public MenuData(MenuData data, boolean generateNewId) { public MenuData() { } - public boolean isEnabled() { - return enabled; - } + public boolean isEnabled() { + return enabled; + } public MenuNameType getNameType() { return nameType; @@ -80,11 +81,11 @@ public String getNameExpanded() { String expanded = namePattern; for (Variable variable : Variable.getInternalVariables()) { try { - expanded = expanded.replace(variable.getFullVariableName(), variable.getResolver().resolve(getCommandData(), null)); - } catch (UnknownCommandID e) { - e.logInternalError(); - break; - } + expanded = expanded.replace(variable.getFullVariableName(), variable.getResolver().resolve(getCommandData(), null)); + } catch (UnknownCommandID e) { + e.logInternalError(); + break; + } } return expanded; } @@ -94,39 +95,43 @@ public String toString() { } public String getImageId() { - if (!imageId.equals(Constants.IMAGE_NONE)) { - return imageId; - } else { - try { - return getCommandData().getImageId(); - } catch (UnknownCommandID e) { - return Constants.IMAGE_NONE; - } - } + if (imageId.equals(Constants.IMAGE_NONE)) { + return getCommandImageId(); + } else { + return imageId; + } + } + + public String getCommandImageId() { + try { + return getCommandData().getImageId(); + } catch (UnknownCommandID e) { + return Constants.IMAGE_NONE; + } } public String getImageIdOwn() { - return imageId; + return imageId; } public String getCommandId() { return commandId; } - public boolean equals(Object object) { - if(!(object instanceof MenuData)) { - return false; - } - MenuData data = (MenuData)object; - if( data.getId().equals(this.getId()) - /*data.getPosition() == this.getPosition() && - data.getName().equals(this.getName()) && - data.getCommandData().equals(this.getCommandData())*/ - ) - { - return true; - } - return false; + public boolean equals(Object object) { + if(!(object instanceof MenuData)) { + return false; + } + MenuData data = (MenuData)object; + if( data.getId().equals(this.getId()) + /*data.getPosition() == this.getPosition() && + data.getName().equals(this.getName()) && + data.getCommandData().equals(this.getCommandData())*/ + ) + { + return true; + } + return false; } public boolean deserialize(Version version, String value, StringTokenizer tokenizer, String delimiter) { @@ -151,9 +156,9 @@ public boolean deserialize(Version version, String value, StringTokenizer tokeni // ------------------------------------------------- // read new imageId and commandId if (version.getId() >= Version.v2_0_003.getId()) { - if (version.getId() >= Version.v2_1_005.getId()) { - imageIdStr = tokenizer.nextToken(); - } + if (version.getId() >= Version.v2_1_005.getId()) { + imageIdStr = tokenizer.nextToken(); + } // read the new one setCommandId(tokenizer.nextToken()); } else { @@ -201,15 +206,15 @@ public String serialize(Version version, String delimiter) { ret += getNamePattern() + delimiter; if (version.getId() >= Version.v2_0_003.getId()) { if (version.getId() >= Version.v2_1_005.getId()) { - ret += getImageIdOwn() + delimiter; + ret += getImageIdOwn() + delimiter; } ret += getCommandId() + delimiter; } else { try { - ret += getCommandData().serialize(version, delimiter); - } catch (UnknownCommandID e) { - e.logInternalError(); - } + ret += getCommandData().serialize(version, delimiter); + } catch (UnknownCommandID e) { + e.logInternalError(); + } } return ret; } @@ -236,42 +241,42 @@ public void setNamePattern(String namePattern) { } public void setImageId(String imageId) { - if (imageId != null) { - this.imageId = imageId; - } else { - this.imageId = Constants.IMAGE_NONE; - } - } + if (imageId == null || imageId.equals(Constants.IMAGE_NONE) || imageId.equals(getCommandImageId())) { + this.imageId = Constants.IMAGE_NONE; + } else { + this.imageId = imageId; + } + } public void setCommandId(String commandId) { this.commandId = commandId; } public CommandData getCommandData() throws UnknownCommandID { - String commandIdStr = getCommandId(); - CommandData data = CommandDataStore.instance().getById(commandIdStr); - if (data != null) { - return data; - } else { - throw new UnknownCommandID(commandIdStr, true); - } + String commandIdStr = getCommandId(); + CommandData data = CommandDataStore.instance().getById(commandIdStr); + if (data != null) { + return data; + } else { + throw new UnknownCommandID(commandIdStr, true); + } } public String getCommand() { - try { - return getCommandData().getCommand(); - } catch (UnknownCommandID e) { - e.logInternalError(); - return "Unknown ID: " + e.getID(); - } + try { + return getCommandData().getCommand(); + } catch (UnknownCommandID e) { + e.logInternalError(); + return "Unknown ID: " + e.getID(); + } } public void setNameTypeFromCategory() { - try { - setNameTypeFromCategory(getCommandData().getCategory()); - } catch (UnknownCommandID e) { - e.logInternalError(); - } + try { + setNameTypeFromCategory(getCommandData().getCategory()); + } catch (UnknownCommandID e) { + e.logInternalError(); + } } public void setNameTypeFromCategory(Category category) { @@ -304,12 +309,12 @@ public void setNameTypeFromCategory(Category category) { } @Override - public boolean verify() { - try { - return super.verify() && commandId != null && getCommandData() != null; - } catch (UnknownCommandID e) { - return false; - } - } + public boolean verify() { + try { + return super.verify() && commandId != null && getCommandData() != null; + } catch (UnknownCommandID e) { + return false; + } + } } diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuDataDialog.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuDataDialog.java index 067c3b1b..708f1053 100644 --- a/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuDataDialog.java +++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuDataDialog.java @@ -60,7 +60,7 @@ public class MenuDataDialog extends StatusDialog { - private MenuData menuData; + private MenuData menuData; private List cmdList; private Button enabledCheckBox; @@ -72,7 +72,7 @@ public class MenuDataDialog extends StatusDialog { private Combo nameTypeCombo; private Text namePatternText; ContentProposalAdapter namePatternTextAssist; - private Button categoryImageButton; + private Button menuImageButton; private Text menuNameText; private Text commandText; @@ -81,6 +81,8 @@ public class MenuDataDialog extends StatusDialog { private Button editButton; private Button removeButton; + private boolean firstRefresh = true; + public MenuDataDialog(Shell parent, MenuData menuData, List cmdList, boolean edit) { super(parent); this.menuData = menuData; @@ -115,12 +117,12 @@ protected void okPressed() { } @Override - protected void cancelPressed() { - super.cancelPressed(); - } + protected void cancelPressed() { + super.cancelPressed(); + } public Control createDialogArea(Composite parent) { - Composite pageComponent = createPageComponent(parent); + Composite pageComponent = createPageComponent(parent); Group pageGroupCommand = createGroupCommand(pageComponent); @@ -139,23 +141,23 @@ public Control createDialogArea(Composite parent) { } public Composite createPageComponent(Composite parent) { - Font font = parent.getFont(); - Composite pageComponent = new Composite(parent,SWT.NULL); - GridLayout layoutComponent = new GridLayout(); - layoutComponent.numColumns = 1; - layoutComponent.makeColumnsEqualWidth = false; - layoutComponent.marginWidth = 5; - layoutComponent.marginHeight = 4; - pageComponent.setLayout(layoutComponent); - GridData gridDataComponent = new GridData(GridData.FILL_HORIZONTAL); - gridDataComponent.widthHint = 640; - pageComponent.setLayoutData(gridDataComponent); - pageComponent.setFont(font); - return pageComponent; + Font font = parent.getFont(); + Composite pageComponent = new Composite(parent,SWT.NULL); + GridLayout layoutComponent = new GridLayout(); + layoutComponent.numColumns = 1; + layoutComponent.makeColumnsEqualWidth = false; + layoutComponent.marginWidth = 5; + layoutComponent.marginHeight = 4; + pageComponent.setLayout(layoutComponent); + GridData gridDataComponent = new GridData(GridData.FILL_HORIZONTAL); + gridDataComponent.widthHint = 640; + pageComponent.setLayoutData(gridDataComponent); + pageComponent.setFont(font); + return pageComponent; } public Group createGroupCommand(Composite parent) { - Font font = parent.getFont(); + Font font = parent.getFont(); Group pageGroupCommand = new Group(parent, SWT.SHADOW_ETCHED_IN); pageGroupCommand.setText(Activator.getResourceString("easyshell.menu.editor.dialog.title.group.command")); pageGroupCommand.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.title.group.tooltip.command")); @@ -168,29 +170,29 @@ public Group createGroupCommand(Composite parent) { GridData gridDataCommand = new GridData(GridData.FILL_HORIZONTAL); pageGroupCommand.setLayoutData(gridDataCommand); pageGroupCommand.setFont(font); - return pageGroupCommand; + return pageGroupCommand; } public Group createGroupMenu(Composite parent) { - Font font = parent.getFont(); - Group pageGroupMenu = new Group(parent, SWT.SHADOW_ETCHED_IN); - pageGroupMenu.setText(Activator.getResourceString("easyshell.menu.editor.dialog.title.group.menu")); - pageGroupMenu.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.title.group.tooltip.menu")); - GridLayout layoutMenu = new GridLayout(); - layoutMenu.numColumns = 3; - layoutMenu.makeColumnsEqualWidth = false; - layoutMenu.marginWidth = 5; - layoutMenu.marginHeight = 4; - pageGroupMenu.setLayout(layoutMenu); - GridData gridDataMenu = new GridData(GridData.FILL_HORIZONTAL); - pageGroupMenu.setLayoutData(gridDataMenu); - pageGroupMenu.setFont(font); - return pageGroupMenu; + Font font = parent.getFont(); + Group pageGroupMenu = new Group(parent, SWT.SHADOW_ETCHED_IN); + pageGroupMenu.setText(Activator.getResourceString("easyshell.menu.editor.dialog.title.group.menu")); + pageGroupMenu.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.title.group.tooltip.menu")); + GridLayout layoutMenu = new GridLayout(); + layoutMenu.numColumns = 3; + layoutMenu.makeColumnsEqualWidth = false; + layoutMenu.marginWidth = 5; + layoutMenu.marginHeight = 4; + pageGroupMenu.setLayout(layoutMenu); + GridData gridDataMenu = new GridData(GridData.FILL_HORIZONTAL); + pageGroupMenu.setLayoutData(gridDataMenu); + pageGroupMenu.setFont(font); + return pageGroupMenu; } public void createCommandControls(Composite parent) { - // enable checkbox - createEnabledCheckBox(parent); + // enable checkbox + createEnabledCheckBox(parent); // search createSearchField(parent); createNewButton(parent); @@ -200,7 +202,7 @@ public void createCommandControls(Composite parent) { // create input commandText field String commandStr; - commandStr = menuData.getCommand(); + commandStr = menuData.getCommand(); commandText = UtilsUI.createTextField(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.command"), Activator.getResourceString("easyshell.menu.editor.dialog.label.tooltip.command"), commandStr, false, false); //createLabel(parent, "");createLabel(parent, ""); @@ -229,23 +231,31 @@ public void modifyText(ModifyEvent e) { }); // create output menuNameText field UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.name"), Activator.getResourceString("easyshell.menu.editor.dialog.label.tooltip.name")); - //categoryImage = UtilsUI.createImageLabel(parent, Category.categoryDefault.getIcon()); - categoryImageButton = UtilsUI.createImageButton(parent, Category.categoryDefault.getImageId()); - categoryImageButton.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - imageDialog(); - } - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // TODO Auto-generated method stub - } - }); + //categoryImageButton = UtilsUI.createImageButton(parent, Category.categoryDefault.getImageId()); + menuImageButton = UtilsUI.createImageButton(parent, menuData.getImageId(), Activator.getResourceString("easyshell.menu.editor.dialog.button.tooltip.image")); + menuImageButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + String newImageId = imageDialog(); + if (newImageId != null) { + menuData.setImageId(newImageId); // may reset to command / category + refreshMenuImageButton(); + } + } + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + }); menuNameText = UtilsUI.createTextField(parent, null, null, menuData.getNameExpanded(), false, false); } + private void refreshMenuImageButton() { + menuImageButton.setImage(Activator.getImage(menuData.getImageId())); + } + private void createRemoveButton(Composite parent) { - Font font = parent.getFont(); + Font font = parent.getFont(); removeButton = new Button(parent, SWT.PUSH); removeButton.setText(Activator.getResourceString("easyshell.menu.editor.dialog.button.text.remove")); removeButton.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.button.tooltip.remove")); @@ -261,7 +271,7 @@ public void widgetSelected(SelectionEvent event) { } private void createEditButton(Composite parent) { - Font font = parent.getFont(); + Font font = parent.getFont(); editButton = new Button(parent, SWT.PUSH); editButton.setText(Activator.getResourceString("easyshell.menu.editor.dialog.button.text.edit")); editButton.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.button.tooltip.edit")); @@ -277,7 +287,7 @@ public void widgetSelected(SelectionEvent event) { } private void createCopyButton(Composite parent) { - Font font = parent.getFont(); + Font font = parent.getFont(); addCopyButton = new Button(parent, SWT.PUSH); addCopyButton.setText(Activator.getResourceString("easyshell.menu.editor.dialog.button.text.copy")); addCopyButton.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.button.tooltip.copy")); @@ -293,7 +303,7 @@ public void widgetSelected(SelectionEvent event) { } private void createNewButton(Composite parent) { - Font font = parent.getFont(); + Font font = parent.getFont(); addNewButton = new Button(parent, SWT.PUSH); addNewButton.setText(Activator.getResourceString("easyshell.menu.editor.dialog.button.text.new")); addNewButton.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.button.tooltip.new")); @@ -438,85 +448,93 @@ private void removeDialog() { } } - private void imageDialog() { - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new ILabelProvider() { - - @Override - public void removeListener(ILabelProviderListener listener) { - // TODO Auto-generated method stub - - } + private String imageDialog() { + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new ILabelProvider() { - @Override - public boolean isLabelProperty(Object element, String property) { - // TODO Auto-generated method stub - return false; - } + @Override + public void removeListener(ILabelProviderListener listener) { + // TODO Auto-generated method stub - @Override - public void dispose() { - // TODO Auto-generated method stub + } - } + @Override + public boolean isLabelProperty(Object element, String property) { + // TODO Auto-generated method stub + return false; + } - @Override - public void addListener(ILabelProviderListener listener) { - // TODO Auto-generated method stub + @Override + public void dispose() { + // TODO Auto-generated method stub - } + } - @Override - public String getText(Object element) { - return ""; - } + @Override + public void addListener(ILabelProviderListener listener) { + // TODO Auto-generated method stub - @Override - public Image getImage(Object element) { - return Activator.getImage((String)element); - } - }, new ITreeContentProvider() { + } - @Override - public boolean hasChildren(Object element) { - // TODO Auto-generated method stub - return false; - } + @Override + public String getText(Object element) { + String name = (String)element; + if (name.equals(menuData.getCommandImageId())) { + name = name + " (" + Activator.getResourceString("easyshell.menu.editor.dialog.image.none") +")"; + } + return name; + } - @Override - public Object getParent(Object element) { - // TODO Auto-generated method stub - return null; - } + @Override + public Image getImage(Object element) { + String name = (String)element; + return Activator.getImage(name); + } + }, new ITreeContentProvider() { - @Override - public Object[] getElements(Object inputElement) { - return ((List)inputElement).toArray(); - } + @Override + public boolean hasChildren(Object element) { + // TODO Auto-generated method stub + return false; + } - @Override - public Object[] getChildren(Object parentElement) { - // TODO Auto-generated method stub - return null; - } - }); - dialog.setTitle("Image Selection"); - dialog.setMessage("Select the image from the tree:"); - dialog.setInput(Activator.getImageNames()); - dialog.open(); - Object res[] = dialog.getResult(); - } + @Override + public Object getParent(Object element) { + // TODO Auto-generated method stub + return null; + } - private void imageDialog2() { + @Override + public Object[] getElements(Object inputElement) { + return ((List)inputElement).toArray(); + } - } + @Override + public Object[] getChildren(Object parentElement) { + // TODO Auto-generated method stub + return null; + } + }); + dialog.setTitle(Activator.getResourceString("easyshell.menu.editor.dialog.image.title")); + dialog.setMessage(Activator.getResourceString("easyshell.menu.editor.dialog.image.text")); + dialog.setInput(Activator.getImageNames()); + int ret = dialog.open(); + if (ret == OK) { + Object res[] = dialog.getResult(); + String imageNew = (String)res[0]; + if (imageNew != null && imageNew.length() > 0) { + return imageNew; + } + } + return null; + } private void refreshCommandCombo() { - try { - commandComboViewer.setSelection(this.menuData.getCommandData()); - } catch (UnknownCommandID e) { - e.logInternalError(); - commandComboViewer.selectFirstItem(); - } + try { + commandComboViewer.setSelection(this.menuData.getCommandData()); + } catch (UnknownCommandID e) { + e.logInternalError(); + commandComboViewer.selectFirstItem(); + } } private void refreshNameTypeCombo() { @@ -528,16 +546,16 @@ private void refreshNameTypeCombo() { private boolean validateValues() { - String title = Activator.getResourceString("easyshell.menu.editor.dialog.error.incompletedata.title"); + String title = Activator.getResourceString("easyshell.error.title.incompletedata"); - // check type - CommandData data = commandComboViewer.getSelection(); + // check type + CommandData data = commandComboViewer.getSelection(); if (data == null) { - MessageDialog.openError(getShell(), title, Activator.getResourceString("easyshell.menu.editor.dialog.error.type.text")); - return false; + MessageDialog.openError(getShell(), title, Activator.getResourceString("easyshell.menu.editor.dialog.error.type.text")); + return false; } - boolean valid = true; + boolean valid = true; // check name String text = Activator.getResourceString("easyshell.menu.editor.dialog.error.text.name"); @@ -577,7 +595,7 @@ private boolean validateValues() { private void createEnabledCheckBox(Composite parent) { // draw label - UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.active"), Activator.getResourceString("easyshell.menu.editor.dialog.label.tooltip.active")); + UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.active"), Activator.getResourceString("easyshell.menu.editor.dialog.label.tooltip.active")); // draw checkbox enabledCheckBox = new Button(parent,SWT.CHECK); enabledCheckBox.setSelection(this.menuData.isEnabled()); @@ -593,19 +611,19 @@ private MenuNameType[] getAllNameTypes() { } private CommandData getFirstSelected() { - CommandData retData = null; - for (Object object : (Object[])commandComboViewer.getViewer().getInput()) { - CommandData data = (CommandData)object; - if (data.isSelected()) { - retData = data; - break; - } - } - return retData; + CommandData retData = null; + for (Object object : (Object[])commandComboViewer.getViewer().getInput()) { + CommandData data = (CommandData)object; + if (data.isSelected()) { + retData = data; + break; + } + } + return retData; } private void createSearchField(Composite parent) { - UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.text.filter"), Activator.getResourceString("easyshell.menu.editor.dialog.label.tooltip.filter")); + UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.text.filter"), Activator.getResourceString("easyshell.menu.editor.dialog.label.tooltip.filter")); filter = new CommandDataFilter(); searchText = new Text(parent, SWT.BORDER | SWT.SEARCH); searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); @@ -622,7 +640,7 @@ public void keyReleased(KeyEvent ke) { private void createCommandCombo(Composite parent) { // draw label - UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.combo.preset"), Activator.getResourceString("easyshell.menu.editor.dialog.combo.tooltip.preset")); + UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.combo.preset"), Activator.getResourceString("easyshell.menu.editor.dialog.combo.tooltip.preset")); commandComboViewer = new TypedComboBox(parent); @@ -630,27 +648,30 @@ private void createCommandCombo(Composite parent) { @Override public void selectionChanged(TypedComboBox typedComboBox, CommandData newSelection) { - menuData.setCommandId(newSelection.getId()); - if (menuData.getNameType() != MenuNameType.menuNameTypeUser) { - menuData.setNameTypeFromCategory(newSelection.getCategory()); - } - String commandStr = null; - PresetType presetType = PresetType.presetPlugin; - Category category = Category.categoryUnknown; - try { - commandStr = menuData.getCommand(); - presetType = menuData.getCommandData().getPresetType(); - category = menuData.getCommandData().getCategory(); - } catch (UnknownCommandID e) { - e.logInternalError(); - } - categoryImageButton.setImage(Activator.getImage(category.getImageId())); - commandText.setText(commandStr); - boolean presetSelected = presetType == PresetType.presetPlugin; - removeButton.setEnabled(!presetSelected); - // updates & refreshes - updateTypeComboSelection(); - refreshNameTypeCombo(); + menuData.setCommandId(newSelection.getId()); + if (menuData.getNameType() != MenuNameType.menuNameTypeUser) { + menuData.setNameTypeFromCategory(newSelection.getCategory()); + } + String commandStr = null; + PresetType presetType = PresetType.presetPlugin; + try { + commandStr = menuData.getCommand(); + presetType = menuData.getCommandData().getPresetType(); + } catch (UnknownCommandID e) { + e.logInternalError(); + } + if (firstRefresh) { + firstRefresh = false; + } else { + menuData.setImageId(null); // reset to command / category + } + commandText.setText(commandStr); + boolean presetSelected = presetType == PresetType.presetPlugin; + removeButton.setEnabled(!presetSelected); + // updates & refreshes + updateTypeComboSelection(); + refreshNameTypeCombo(); + refreshMenuImageButton(); } }); @@ -675,37 +696,37 @@ public Image getImage(CommandData element) { }); if (filter != null) { - commandComboViewer.getViewer().addFilter(filter); + commandComboViewer.getViewer().addFilter(filter); } /*Combo combo = commandComboViewer.getViewer().getCombo(); combo.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - if (refreshing) { - refreshing = false; - return; - } - Combo combo = commandComboViewer.getViewer().getCombo(); - if (combo != null && filter != null) { - String text = combo.getText(); - CommandData data = commandComboViewer.getSelection(); - if (text != null && data != null && !data.getCommandAsComboName().equals(text)) { - filter.setSearchText(text); - refreshing = true; - //commandComboViewer.getViewer().refresh(); - } - } - } - });*/ + @Override + public void modifyText(ModifyEvent e) { + if (refreshing) { + refreshing = false; + return; + } + Combo combo = commandComboViewer.getViewer().getCombo(); + if (combo != null && filter != null) { + String text = combo.getText(); + CommandData data = commandComboViewer.getSelection(); + if (text != null && data != null && !data.getCommandAsComboName().equals(text)) { + filter.setSearchText(text); + refreshing = true; + //commandComboViewer.getViewer().refresh(); + } + } + } + });*/ commandComboViewer.getViewer().getCombo().setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.combo.tooltip.preset")); commandComboViewer.setContent(cmdList); } private void createNameTypeCombo(Composite parent) { - UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.combo.pattern"), Activator.getResourceString("easyshell.menu.editor.dialog.combo.tooltip.pattern")); - UtilsUI.createLabel(parent, "", null); + UtilsUI.createLabel(parent, Activator.getResourceString("easyshell.menu.editor.dialog.label.combo.pattern"), Activator.getResourceString("easyshell.menu.editor.dialog.combo.tooltip.pattern")); + UtilsUI.createLabel(parent, "", null); // draw combo nameTypeCombo = new Combo(parent,SWT.BORDER | SWT.READ_ONLY); nameTypeCombo.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.combo.tooltip.pattern"));