|
@@ -24,6 +24,7 @@ package uk.org.ownage.dmdirc.actions;
|
24
|
24
|
|
25
|
25
|
import java.io.File;
|
26
|
26
|
import java.io.FileInputStream;
|
|
27
|
+import java.io.FileOutputStream;
|
27
|
28
|
import java.io.IOException;
|
28
|
29
|
import java.util.ArrayList;
|
29
|
30
|
import java.util.List;
|
|
@@ -168,7 +169,44 @@ public class Action {
|
168
|
169
|
|
169
|
170
|
/** Called to save the action. */
|
170
|
171
|
public void save() {
|
171
|
|
- //TODO: Please implement me.
|
|
172
|
+ final Properties properties = new Properties();
|
|
173
|
+ final StringBuffer triggerString = new StringBuffer();
|
|
174
|
+ final StringBuffer responseString = new StringBuffer();
|
|
175
|
+
|
|
176
|
+ for (ActionType trigger : triggers) {
|
|
177
|
+ triggerString.append('|');
|
|
178
|
+ triggerString.append(trigger.toString());
|
|
179
|
+ }
|
|
180
|
+
|
|
181
|
+ for (String line : response) {
|
|
182
|
+ responseString.append('\n');
|
|
183
|
+ responseString.append(line);
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+ properties.setProperty("trigger", triggerString.substring(1));
|
|
187
|
+ properties.setProperty("conditions", "" + conditions.size());
|
|
188
|
+ properties.setProperty("response", responseString.substring(1));
|
|
189
|
+
|
|
190
|
+ if (newFormat != null) {
|
|
191
|
+ properties.setProperty("formatter", newFormat);
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ int i = 0;
|
|
195
|
+ for (ActionCondition condition : conditions) {
|
|
196
|
+ properties.setProperty("condition" + i + "-arg", "" + condition.getArg());
|
|
197
|
+ properties.setProperty("condition" + i + "-component", condition.getComponent().toString());
|
|
198
|
+ properties.setProperty("condition" + i + "-comparison", condition.getComparison().toString());
|
|
199
|
+ properties.setProperty("condition" + i + "-target", condition.getTarget());
|
|
200
|
+ i++;
|
|
201
|
+ }
|
|
202
|
+
|
|
203
|
+ try {
|
|
204
|
+ final FileOutputStream outputStream = new FileOutputStream(file);
|
|
205
|
+ properties.store(outputStream, "Created by GUI actions editor");
|
|
206
|
+ outputStream.close();
|
|
207
|
+ } catch (IOException ex) {
|
|
208
|
+ Logger.error(ErrorLevel.ERROR, "Unable to save action: " + group + "/" + name, ex);
|
|
209
|
+ }
|
172
|
210
|
}
|
173
|
211
|
|
174
|
212
|
/**
|