Skip to content

Commit a361550

Browse files
committed
issue #53 - [v2.0] implement generic menu definition
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>
1 parent e224055 commit a361550

15 files changed

+635
-113
lines changed

plugin/src/de/anbos/eclipse/easyshell/plugin/Activator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,28 @@ public static void log(String title, String msg, Exception e) {
152152
public static void logSuccess(String title, String msg, Exception e, boolean tooltip) {
153153
log(Status.OK, title != null ? title + ": " + msg : msg, e);
154154
if (tooltip) {
155-
tooltipSuccess(getResourceString("easyshell.plugin.name") + ": " + title, msg);
155+
tooltipSuccess(title, msg);
156156
}
157157
}
158158

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

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

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

plugin/src/de/anbos/eclipse/easyshell/plugin/Constants.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ public interface Constants {
2626
public static final String IMAGE_OTHER = "editor.gif";
2727

2828
// Preferences
29-
// version with index = 0 is the used one
29+
// version with index = 0 is the actual one
30+
// do not delete old entries !!!
3031
public static final String[] PREF_VERSIONS = {
31-
"v2_0_001"
32+
"v2_0_002",
33+
"v2_0_001",
34+
"v1_4"
3235
};
33-
public static final String PREF_COMMANDS = "COMMANDS";
34-
public static final String PREF_MENU = "MENU";
36+
public static final String PREF_COMMANDS_PRESET = "COMMANDS_PRESET";
37+
public static final String PREF_COMMANDS = "COMMANDS";
38+
public static final String PREF_MENU = "MENU";
39+
public static final String PREF_MIGRATED = "MIGRATED";
3540

3641
// Actions
3742
public static final String ACTION_UNKNOWN = "de.anbos.eclipse.easyshell.plugin.commands.Unknown";

plugin/src/de/anbos/eclipse/easyshell/plugin/UIMessages.properties

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ easyshell.message.error.internal=Unable to open shell
88
easyshell.message.error.execution=Execution error
99
easyshell.message.error.validation=Validation error
1010

11+
easyshell.message.warning.migrated.yes=Migrated settings from previous version "{0}".\n\nPlease verify your settings!
12+
easyshell.message.warning.migrated.no=NOT migrated settings from previous version "{0}".\n\nPlease verify applied default settings!
13+
easyshell.message.warning.migrated.cancel=Migration was canceled and will be executed again during next Eclipse startup.\n\nTemporary applied default settings!
14+
easyshell.message.warning.migrated.default=First startup!\n\nPlease verify applied default settings!
15+
easyshell.question.migrate=Do you want to migrate your settings from previous version "{0}" ?
16+
1117
easyshell.page.table.header.title.column0=Name
1218
easyshell.page.table.header.title.column1=Command
1319
easyshell.page.table.button.text.new=Add...
@@ -24,15 +30,22 @@ easyshell.page.table.button.text.down=Down
2430
easyshell.page.table.button.tooltip.down=Move selected menu down
2531
easyshell.page.table.dialog.remove.title=Remove menu(s)
2632
easyshell.page.table.dialog.remove.question=Do you really want to remove selected menu(s) ?
33+
easyshell.page.table.dialog.defaults.title=Restore defaults
34+
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?
35+
easyshell.page.table.dialog.migration.title=Migration
36+
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?
2737

2838
easyshell.menu.editor.dialog.title.new=Create new menu
2939
easyshell.menu.editor.dialog.title.edit=Edit existing menu
3040
easyshell.menu.editor.dialog.title.group1=Menu definition
41+
easyshell.menu.editor.dialog.title.group2=Command definition
3142
easyshell.menu.editor.dialog.error.text.name=Please enter a valid name
3243
easyshell.menu.editor.dialog.error.type.text=Please choose a valid type
3344
easyshell.menu.editor.dialog.label.active=enabled:
34-
easyshell.menu.editor.dialog.label.name=menu name:
35-
easyshell.menu.editor.dialog.label.combo=preset:
45+
easyshell.menu.editor.dialog.label.name=name:
46+
easyshell.menu.editor.dialog.label.pattern=
47+
easyshell.menu.editor.dialog.label.combo.preset=select:
48+
easyshell.menu.editor.dialog.label.combo.pattern=name pattern:
3649
easyshell.menu.editor.dialog.label.command=command:
3750
easyshell.menu.editor.dialog.button.text.new=New...
3851
easyshell.menu.editor.dialog.button.tooltip.new=Add new user command
@@ -43,11 +56,11 @@ easyshell.menu.editor.dialog.button.tooltip.edit=Edit selected user command
4356
easyshell.menu.editor.dialog.button.text.remove=Remove...
4457
easyshell.menu.editor.dialog.button.tooltip.remove=Remove selected user command
4558
easyshell.menu.editor.dialog.title.remove=Remove user command
46-
easyshell.menu.editor.dialog.question.remove=Do you really want to remove user command "{0}" ?
59+
easyshell.menu.editor.dialog.question.remove=Do you really want to remove user command\n"{0}" ?
4760

4861
easyshell.command.editor.dialog.title.new=Create new command
4962
easyshell.command.editor.dialog.title.edit=Edit existing command
50-
easyshell.command.editor.dialog.title.group1=Command definition
63+
easyshell.command.editor.dialog.title.group1=Command
5164
easyshell.command.editor.dialog.tooltip.group1=Add your command here
5265
easyshell.command.editor.dialog.title.group2=Usable variables
5366
easyshell.command.editor.dialog.tooltip.group2=Double click at variable copies it to clipboard

plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void createContributionItems(IServiceLocator serviceLocator,
4141
List<MenuData> items = store.getEnabledCommandMenuDataList();
4242
for (MenuData item : items) {
4343
addItem(serviceLocator, additions,
44-
item.getName(),
44+
item.getNameExpanded(),
4545
"de.anbos.eclipse.easyshell.plugin.commands.execute",
4646
"de.anbos.eclipse.easyshell.plugin.commands.parameter.type",
4747
item.getCommandData().getTypeAction(),

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandData.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ public boolean deserialize(String value, StringTokenizer tokenizer, String delim
167167
return true;
168168
}
169169

170+
public boolean deserialize_v2_0_001(String value, StringTokenizer tokenizer, String delimiter) {
171+
return deserialize(value, tokenizer, delimiter);
172+
}
173+
170174
public String serialize(String delimiter) {
171175
return Integer.toString(getPosition()) + delimiter + getId() + delimiter + getPresetType().toString() + delimiter + getOS().toString() + delimiter + getName() + delimiter + getResourceType().toString() + delimiter + getCommandType().toString() + delimiter + getCommand() + delimiter;
172176
}

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandDataDefaultCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static List<MenuData> getCommandsNativeAsMenu(boolean sorted) {
4141
List<MenuData> ret = new ArrayList<MenuData>();
4242
for (int i=0;i<list.size();i++) {
4343
CommandData cmdData = list.get(i);
44-
MenuData newData = new MenuData(cmdData.getId(), cmdData, true); // use the same id like the default command to have same defaults
44+
MenuData newData = new MenuData(cmdData.getId(), cmdData); // use the same id like the default command to have same defaults
4545
if (sorted) {
4646
newData.setPosition(i);
4747
}

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandDataStore.java

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.jface.preference.IPreferenceStore;
2020

2121
import de.anbos.eclipse.easyshell.plugin.Constants;
22+
import de.anbos.eclipse.easyshell.plugin.types.PresetType;
2223

2324
public class CommandDataStore {
2425

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

3435
public List<CommandData> getAllCommands() {
35-
return items;
36+
return items;
37+
}
38+
39+
private List<CommandData> getUserCommands() {
40+
List<CommandData> userItems = new ArrayList<CommandData>();
41+
for (CommandData data : items) {
42+
if (data.getPresetType() == PresetType.presetUser) {
43+
userItems.add(data);
44+
}
45+
}
46+
return userItems;
47+
}
48+
49+
private List<CommandData> getPresetCommands() {
50+
List<CommandData> presetItems = new ArrayList<CommandData>();
51+
for (CommandData data : items) {
52+
if (data.getPresetType() == PresetType.presetPlugin) {
53+
presetItems.add(data);
54+
}
55+
}
56+
return presetItems;
3657
}
3758

3859
public CommandData[] getAllCommandsArray() {
@@ -48,7 +69,7 @@ public CommandData[] getAllCommandsArray() {
4869
}
4970

5071
public CommandData getPreviousElement(CommandData data) {
51-
sort();
72+
sort(items);
5273
for(int i = 0 ; i < items.size() ; i++) {
5374
CommandData item = (CommandData)items.get(i);
5475
if(item.equals(data)) {
@@ -63,7 +84,7 @@ public CommandData getPreviousElement(CommandData data) {
6384
}
6485

6586
public CommandData getNextElement(CommandData data) {
66-
sort();
87+
sort(items);
6788
for(int i = 0 ; i < items.size() ; i++) {
6889
CommandData item = (CommandData)items.get(i);
6990
if(item.equals(data)) {
@@ -78,7 +99,7 @@ public CommandData getNextElement(CommandData data) {
7899
}
79100

80101
public CommandData getLastElement() {
81-
sort();
102+
sort(items);
82103
int index = items.size() - 1;
83104
if(index < 0) {
84105
return null;
@@ -94,34 +115,40 @@ public void add(CommandData data) {
94115
}
95116
data.setPosition(position);
96117
items.add(data);
97-
sort();
118+
sort(items);
98119
}
99120

100121
public void delete(CommandData data) {
101122
items.remove(data);
102-
sort();
123+
sort(items);
103124
}
104125

105126
public void save() {
106-
store.setValue(Constants.PREF_COMMANDS,PreferenceValueConverter.asCommandDataString(getAllCommands()));
127+
store.setValue(Constants.PREF_COMMANDS_PRESET,PreferenceValueConverter.asCommandDataString(getPresetCommands()));
128+
store.setValue(Constants.PREF_COMMANDS,PreferenceValueConverter.asCommandDataString(getUserCommands()));
107129
}
108130

109131
public void loadDefaults() {
132+
store.setToDefault(Constants.PREF_COMMANDS_PRESET);
110133
store.setToDefault(Constants.PREF_COMMANDS);
111134
load();
112135
}
113136

114137
public void load() {
115-
CommandData[] items = PreferenceValueConverter.asCommandDataArray(store.getString(Constants.PREF_COMMANDS));
138+
CommandData[] arrayPreset = PreferenceValueConverter.asCommandDataArray(store.getString(Constants.PREF_COMMANDS_PRESET));
139+
CommandData[] arrayUser = PreferenceValueConverter.asCommandDataArray(store.getString(Constants.PREF_COMMANDS));
116140
this.items.clear();
117-
for(int i = 0 ; i < items.length ; i++) {
118-
this.items.add(items[i]);
141+
for(int i = 0 ; i < arrayPreset.length ; i++) {
142+
this.items.add(arrayPreset[i]);
143+
}
144+
for(int i = 0 ; i < arrayUser.length ; i++) {
145+
this.items.add(arrayUser[i]);
119146
}
120-
sort();
147+
sort(items);
121148
}
122149

123150
public void removeAll() {
124-
items.clear();
151+
items.clear();
125152
}
126153

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

140-
private void sort() {
167+
private void sort(List<CommandData> items) {
141168
if(comparator == null) {
142169
comparator = new DataObjectComparator();
143170
}
144-
Collections.sort(items,comparator);
171+
Collections.sort(items, comparator);
145172
for (int i=0;i<items.size();i++) {
146173
((CommandData)items.get(i)).setPosition(i);
147174
}

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandsPage.java

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,44 @@ public void init(IWorkbench workbench) {
7171

7272
@Override
7373
public boolean performOk() {
74-
menuStore.save();
75-
return true;
74+
boolean save = true;
75+
if (!menuStore.isMigrated()) {
76+
String title = Activator.getResourceString("easyshell.page.table.dialog.migration.title");
77+
String question = Activator.getResourceString("easyshell.page.table.dialog.migration.question");
78+
MessageDialog dialog = new MessageDialog(
79+
null, title, null, question,
80+
MessageDialog.WARNING,
81+
new String[] {"Yes", "No"},
82+
1); // no is the default
83+
int result = dialog.open();
84+
if (result == 0) {
85+
menuStore.setMigrated(true);
86+
} else {
87+
save = false;
88+
}
89+
}
90+
if (save) {
91+
menuStore.save();
92+
}
93+
return save;
7694
}
7795

7896
@Override
7997
protected void performDefaults() {
80-
menuStore.loadDefaults();
81-
tableViewer.refresh();
82-
for (MenuData item : menuStore.getCommandMenuDataList()) {
83-
tableViewer.setChecked(item, true);
98+
String title = Activator.getResourceString("easyshell.page.table.dialog.defaults.title");
99+
String question = Activator.getResourceString("easyshell.page.table.dialog.defaults.question");
100+
MessageDialog dialog = new MessageDialog(
101+
null, title, null, question,
102+
MessageDialog.WARNING,
103+
new String[] {"Yes", "No"},
104+
1); // no is the default
105+
int result = dialog.open();
106+
if (result == 0) {
107+
menuStore.loadDefaults();
108+
tableViewer.refresh();
109+
for (MenuData item : menuStore.getCommandMenuDataList()) {
110+
tableViewer.setChecked(item, true);
111+
}
84112
}
85113
}
86114

@@ -416,31 +444,42 @@ public void controlResized(ControlEvent e) {
416444
}
417445

418446
private void addNewDialog() {
419-
MenuData data = new MenuData(cmdList.get(0), true, true);
420-
MenuDataDialog dialog = new MenuDataDialog(getShell(), data, cmdStore, cmdList, false);
447+
MenuData dataNew = new MenuData(cmdList.get(0), true);
448+
MenuDataDialog dialog = new MenuDataDialog(getShell(), dataNew, cmdStore, cmdList, false);
421449
if (dialog.open() == Window.OK) {
422-
menuStore.add(data);
423-
refreshTableViewer(data);
450+
menuStore.add(dataNew);
451+
refreshTableViewer(dataNew);
452+
} else {
453+
dataNew = null;
424454
}
425455
}
426456

427457
private void addCopyDialog() {
428458
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
429-
MenuData data = new MenuData((MenuData)selection.getFirstElement(), true);
430-
MenuDataDialog dialog = new MenuDataDialog(getShell(), data, cmdStore, cmdList, false);
459+
MenuData dataSelected = (MenuData)selection.getFirstElement();
460+
MenuData dataNew = new MenuData(dataSelected, true);
461+
MenuDataDialog dialog = new MenuDataDialog(getShell(), dataNew, cmdStore, cmdList, false);
431462
if (dialog.open() == Window.OK) {
432-
menuStore.add(data);
433-
refreshTableViewer(data);
463+
menuStore.add(dataNew);
464+
refreshTableViewer(dataNew);
465+
} else {
466+
dataNew = null;
434467
}
435468
}
436469

437470
private void editDialog() {
438471
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
439-
MenuData data = (MenuData) selection.getFirstElement();
440-
MenuDataDialog dialog = new MenuDataDialog(getShell(), data, cmdStore, cmdList, true);
472+
MenuData dataSelected = (MenuData)selection.getFirstElement();
473+
MenuData dataNew = new MenuData(dataSelected, false);
474+
dataNew.setPosition(dataSelected.getPosition());
475+
MenuDataDialog dialog = new MenuDataDialog(getShell(), dataNew, cmdStore, cmdList, true);
441476
if (dialog.open() == Window.OK) {
442-
refreshTableViewer(data);
477+
menuStore.replace(dataNew);
478+
refreshTableViewer(dataNew);
479+
} else {
480+
dataNew = null;
443481
}
482+
444483
}
445484

446485
private void removeDialog() {

0 commit comments

Comments
 (0)