Skip to content

Commit

Permalink
issue #53 - [v2.0] implement generic menu definition
Browse files Browse the repository at this point in the history
fixed: issues described in #52 - [v2.0] issues found in beta 1
- Opening the edition window for an existing entry changes its name back
to the original one.
- Adding a new entry sometimes changes the name of the other existing
entries back to their original one.
- I wouldn't automatically prefix the "menu name" with the "type" when
exiting the "Edit existing command".

fixed: other
- menu data is changed also in case of cancel
- issue #56 - [v2.0] migration support from older EasyShell v2.x (also
beta releases)

added:
- MenuTypeName: predefined and user defined name patterns (#53)
- implemented migration of store

Signed-off-by: Andre Bossert <anb0s@anbos.de>
  • Loading branch information
anb0s committed Jul 19, 2016
1 parent e224055 commit a361550
Show file tree
Hide file tree
Showing 15 changed files with 635 additions and 113 deletions.
8 changes: 4 additions & 4 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,28 @@ public static void log(String title, String msg, Exception e) {
public static void logSuccess(String title, String msg, Exception e, boolean tooltip) {
log(Status.OK, title != null ? title + ": " + msg : msg, e);
if (tooltip) {
tooltipSuccess(getResourceString("easyshell.plugin.name") + ": " + title, msg);
tooltipSuccess(title, msg);
}
}

public static void logInfo(String title, String msg, Exception e, boolean tooltip) {
log(Status.INFO, title != null ? title + ": " + msg : msg, e);
if (tooltip) {
tooltipInfo(getResourceString("easyshell.plugin.name") + ": " + title, msg);
tooltipInfo(title, msg);
}
}

public static void logWarning(String title, String msg, Exception e, boolean tooltip) {
log(Status.WARNING, title != null ? title + ": " + msg : msg, e);
if (tooltip) {
tooltipWarning(getResourceString("easyshell.plugin.name") + ": " + title, msg);
tooltipWarning(title, msg);
}
}

public static void logError(String title, String msg, Exception e, boolean tooltip) {
log(Status.ERROR, title != null ? title + ": " + msg : msg, e);
if (tooltip) {
tooltipError(getResourceString("easyshell.plugin.name") + ": " + title, msg);
tooltipError(title, msg);
}
}

Expand Down
13 changes: 9 additions & 4 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ public interface Constants {
public static final String IMAGE_OTHER = "editor.gif";

// Preferences
// version with index = 0 is the used one
// version with index = 0 is the actual one
// do not delete old entries !!!
public static final String[] PREF_VERSIONS = {
"v2_0_001"
"v2_0_002",
"v2_0_001",
"v1_4"
};
public static final String PREF_COMMANDS = "COMMANDS";
public static final String PREF_MENU = "MENU";
public static final String PREF_COMMANDS_PRESET = "COMMANDS_PRESET";
public static final String PREF_COMMANDS = "COMMANDS";
public static final String PREF_MENU = "MENU";
public static final String PREF_MIGRATED = "MIGRATED";

// Actions
public static final String ACTION_UNKNOWN = "de.anbos.eclipse.easyshell.plugin.commands.Unknown";
Expand Down
21 changes: 17 additions & 4 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/UIMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ easyshell.message.error.internal=Unable to open shell
easyshell.message.error.execution=Execution error
easyshell.message.error.validation=Validation error

easyshell.message.warning.migrated.yes=Migrated settings from previous version "{0}".\n\nPlease verify your settings!
easyshell.message.warning.migrated.no=NOT migrated settings from previous version "{0}".\n\nPlease verify applied default settings!
easyshell.message.warning.migrated.cancel=Migration was canceled and will be executed again during next Eclipse startup.\n\nTemporary applied default settings!
easyshell.message.warning.migrated.default=First startup!\n\nPlease verify applied default settings!
easyshell.question.migrate=Do you want to migrate your settings from previous version "{0}" ?

easyshell.page.table.header.title.column0=Name
easyshell.page.table.header.title.column1=Command
easyshell.page.table.button.text.new=Add...
Expand All @@ -24,15 +30,22 @@ easyshell.page.table.button.text.down=Down
easyshell.page.table.button.tooltip.down=Move selected menu down
easyshell.page.table.dialog.remove.title=Remove menu(s)
easyshell.page.table.dialog.remove.question=Do you really want to remove selected menu(s) ?
easyshell.page.table.dialog.defaults.title=Restore defaults
easyshell.page.table.dialog.defaults.question=All your menu definitions will be overwritten!\n\nYou can still use "Cancel" button afterwards for undo.\n\nDo you really want to restore default settings?
easyshell.page.table.dialog.migration.title=Migration
easyshell.page.table.dialog.migration.question=You have canceled the migration of settings from previous version.\n\nAll your menu definitions will be written now and migration will be skipped completely!\n\nDo you really want to overwrite the migrated settings?

easyshell.menu.editor.dialog.title.new=Create new menu
easyshell.menu.editor.dialog.title.edit=Edit existing menu
easyshell.menu.editor.dialog.title.group1=Menu definition
easyshell.menu.editor.dialog.title.group2=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.name=menu name:
easyshell.menu.editor.dialog.label.combo=preset:
easyshell.menu.editor.dialog.label.name=name:
easyshell.menu.editor.dialog.label.pattern=
easyshell.menu.editor.dialog.label.combo.preset=select:
easyshell.menu.editor.dialog.label.combo.pattern=name pattern:
easyshell.menu.editor.dialog.label.command=command:
easyshell.menu.editor.dialog.button.text.new=New...
easyshell.menu.editor.dialog.button.tooltip.new=Add new user command
Expand All @@ -43,11 +56,11 @@ easyshell.menu.editor.dialog.button.tooltip.edit=Edit selected user command
easyshell.menu.editor.dialog.button.text.remove=Remove...
easyshell.menu.editor.dialog.button.tooltip.remove=Remove selected user command
easyshell.menu.editor.dialog.title.remove=Remove user command
easyshell.menu.editor.dialog.question.remove=Do you really want to remove user command "{0}" ?
easyshell.menu.editor.dialog.question.remove=Do you really want to remove user command\n"{0}" ?

easyshell.command.editor.dialog.title.new=Create new command
easyshell.command.editor.dialog.title.edit=Edit existing command
easyshell.command.editor.dialog.title.group1=Command definition
easyshell.command.editor.dialog.title.group1=Command
easyshell.command.editor.dialog.tooltip.group1=Add your command here
easyshell.command.editor.dialog.title.group2=Usable variables
easyshell.command.editor.dialog.tooltip.group2=Double click at variable copies it to clipboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void createContributionItems(IServiceLocator serviceLocator,
List<MenuData> items = store.getEnabledCommandMenuDataList();
for (MenuData item : items) {
addItem(serviceLocator, additions,
item.getName(),
item.getNameExpanded(),
"de.anbos.eclipse.easyshell.plugin.commands.execute",
"de.anbos.eclipse.easyshell.plugin.commands.parameter.type",
item.getCommandData().getTypeAction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ public boolean deserialize(String value, StringTokenizer tokenizer, String delim
return true;
}

public boolean deserialize_v2_0_001(String value, StringTokenizer tokenizer, String delimiter) {
return deserialize(value, tokenizer, delimiter);
}

public String serialize(String delimiter) {
return Integer.toString(getPosition()) + delimiter + getId() + delimiter + getPresetType().toString() + delimiter + getOS().toString() + delimiter + getName() + delimiter + getResourceType().toString() + delimiter + getCommandType().toString() + delimiter + getCommand() + delimiter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static List<MenuData> getCommandsNativeAsMenu(boolean sorted) {
List<MenuData> ret = new ArrayList<MenuData>();
for (int i=0;i<list.size();i++) {
CommandData cmdData = list.get(i);
MenuData newData = new MenuData(cmdData.getId(), cmdData, true); // use the same id like the default command to have same defaults
MenuData newData = new MenuData(cmdData.getId(), cmdData); // use the same id like the default command to have same defaults
if (sorted) {
newData.setPosition(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.jface.preference.IPreferenceStore;

import de.anbos.eclipse.easyshell.plugin.Constants;
import de.anbos.eclipse.easyshell.plugin.types.PresetType;

public class CommandDataStore {

Expand All @@ -32,7 +33,27 @@ public CommandDataStore(IPreferenceStore store) {
}

public List<CommandData> getAllCommands() {
return items;
return items;
}

private List<CommandData> getUserCommands() {
List<CommandData> userItems = new ArrayList<CommandData>();
for (CommandData data : items) {
if (data.getPresetType() == PresetType.presetUser) {
userItems.add(data);
}
}
return userItems;
}

private List<CommandData> getPresetCommands() {
List<CommandData> presetItems = new ArrayList<CommandData>();
for (CommandData data : items) {
if (data.getPresetType() == PresetType.presetPlugin) {
presetItems.add(data);
}
}
return presetItems;
}

public CommandData[] getAllCommandsArray() {
Expand All @@ -48,7 +69,7 @@ public CommandData[] getAllCommandsArray() {
}

public CommandData getPreviousElement(CommandData data) {
sort();
sort(items);
for(int i = 0 ; i < items.size() ; i++) {
CommandData item = (CommandData)items.get(i);
if(item.equals(data)) {
Expand All @@ -63,7 +84,7 @@ public CommandData getPreviousElement(CommandData data) {
}

public CommandData getNextElement(CommandData data) {
sort();
sort(items);
for(int i = 0 ; i < items.size() ; i++) {
CommandData item = (CommandData)items.get(i);
if(item.equals(data)) {
Expand All @@ -78,7 +99,7 @@ public CommandData getNextElement(CommandData data) {
}

public CommandData getLastElement() {
sort();
sort(items);
int index = items.size() - 1;
if(index < 0) {
return null;
Expand All @@ -94,34 +115,40 @@ public void add(CommandData data) {
}
data.setPosition(position);
items.add(data);
sort();
sort(items);
}

public void delete(CommandData data) {
items.remove(data);
sort();
sort(items);
}

public void save() {
store.setValue(Constants.PREF_COMMANDS,PreferenceValueConverter.asCommandDataString(getAllCommands()));
store.setValue(Constants.PREF_COMMANDS_PRESET,PreferenceValueConverter.asCommandDataString(getPresetCommands()));
store.setValue(Constants.PREF_COMMANDS,PreferenceValueConverter.asCommandDataString(getUserCommands()));
}

public void loadDefaults() {
store.setToDefault(Constants.PREF_COMMANDS_PRESET);
store.setToDefault(Constants.PREF_COMMANDS);
load();
}

public void load() {
CommandData[] items = PreferenceValueConverter.asCommandDataArray(store.getString(Constants.PREF_COMMANDS));
CommandData[] arrayPreset = PreferenceValueConverter.asCommandDataArray(store.getString(Constants.PREF_COMMANDS_PRESET));
CommandData[] arrayUser = PreferenceValueConverter.asCommandDataArray(store.getString(Constants.PREF_COMMANDS));
this.items.clear();
for(int i = 0 ; i < items.length ; i++) {
this.items.add(items[i]);
for(int i = 0 ; i < arrayPreset.length ; i++) {
this.items.add(arrayPreset[i]);
}
for(int i = 0 ; i < arrayUser.length ; i++) {
this.items.add(arrayUser[i]);
}
sort();
sort(items);
}

public void removeAll() {
items.clear();
items.clear();
}

public CommandData getCommandDataByName(String name) {
Expand All @@ -137,11 +164,11 @@ public CommandData getCommandDataByPosition(int position) {
return items.get(position);
}

private void sort() {
private void sort(List<CommandData> items) {
if(comparator == null) {
comparator = new DataObjectComparator();
}
Collections.sort(items,comparator);
Collections.sort(items, comparator);
for (int i=0;i<items.size();i++) {
((CommandData)items.get(i)).setPosition(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,44 @@ public void init(IWorkbench workbench) {

@Override
public boolean performOk() {
menuStore.save();
return true;
boolean save = true;
if (!menuStore.isMigrated()) {
String title = Activator.getResourceString("easyshell.page.table.dialog.migration.title");
String question = Activator.getResourceString("easyshell.page.table.dialog.migration.question");
MessageDialog dialog = new MessageDialog(
null, title, null, question,
MessageDialog.WARNING,
new String[] {"Yes", "No"},
1); // no is the default
int result = dialog.open();
if (result == 0) {
menuStore.setMigrated(true);
} else {
save = false;
}
}
if (save) {
menuStore.save();
}
return save;
}

@Override
protected void performDefaults() {
menuStore.loadDefaults();
tableViewer.refresh();
for (MenuData item : menuStore.getCommandMenuDataList()) {
tableViewer.setChecked(item, true);
String title = Activator.getResourceString("easyshell.page.table.dialog.defaults.title");
String question = Activator.getResourceString("easyshell.page.table.dialog.defaults.question");
MessageDialog dialog = new MessageDialog(
null, title, null, question,
MessageDialog.WARNING,
new String[] {"Yes", "No"},
1); // no is the default
int result = dialog.open();
if (result == 0) {
menuStore.loadDefaults();
tableViewer.refresh();
for (MenuData item : menuStore.getCommandMenuDataList()) {
tableViewer.setChecked(item, true);
}
}
}

Expand Down Expand Up @@ -416,31 +444,42 @@ public void controlResized(ControlEvent e) {
}

private void addNewDialog() {
MenuData data = new MenuData(cmdList.get(0), true, true);
MenuDataDialog dialog = new MenuDataDialog(getShell(), data, cmdStore, cmdList, false);
MenuData dataNew = new MenuData(cmdList.get(0), true);
MenuDataDialog dialog = new MenuDataDialog(getShell(), dataNew, cmdStore, cmdList, false);
if (dialog.open() == Window.OK) {
menuStore.add(data);
refreshTableViewer(data);
menuStore.add(dataNew);
refreshTableViewer(dataNew);
} else {
dataNew = null;
}
}

private void addCopyDialog() {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
MenuData data = new MenuData((MenuData)selection.getFirstElement(), true);
MenuDataDialog dialog = new MenuDataDialog(getShell(), data, cmdStore, cmdList, false);
MenuData dataSelected = (MenuData)selection.getFirstElement();
MenuData dataNew = new MenuData(dataSelected, true);
MenuDataDialog dialog = new MenuDataDialog(getShell(), dataNew, cmdStore, cmdList, false);
if (dialog.open() == Window.OK) {
menuStore.add(data);
refreshTableViewer(data);
menuStore.add(dataNew);
refreshTableViewer(dataNew);
} else {
dataNew = null;
}
}

private void editDialog() {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
MenuData data = (MenuData) selection.getFirstElement();
MenuDataDialog dialog = new MenuDataDialog(getShell(), data, cmdStore, cmdList, true);
MenuData dataSelected = (MenuData)selection.getFirstElement();
MenuData dataNew = new MenuData(dataSelected, false);
dataNew.setPosition(dataSelected.getPosition());
MenuDataDialog dialog = new MenuDataDialog(getShell(), dataNew, cmdStore, cmdList, true);
if (dialog.open() == Window.OK) {
refreshTableViewer(data);
menuStore.replace(dataNew);
refreshTableViewer(dataNew);
} else {
dataNew = null;
}

}

private void removeDialog() {
Expand Down
Loading

0 comments on commit a361550

Please sign in to comment.