瀏覽代碼

Implemented Action.save()

Removed toString method on all action enums

git-svn-id: http://svn.dmdirc.com/trunk@1223 00569f92-eb28-0410-84fd-f71c24880f
tags/0.4
Chris Smith 17 年之前
父節點
當前提交
074e2942e0

+ 39
- 1
src/uk/org/ownage/dmdirc/actions/Action.java 查看文件

@@ -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
     /**

+ 1
- 6
src/uk/org/ownage/dmdirc/actions/CoreActionComparison.java 查看文件

@@ -138,10 +138,5 @@ public enum CoreActionComparison implements ActionComparison {
138 138
     
139 139
     /** {@inheritDoc} */
140 140
     public abstract String getName();
141
-    
142
-    /** {@inheritDoc} */
143
-    public String toString() {
144
-        return getName();
145
-    }
146
-    
141
+       
147 142
 }

+ 0
- 5
src/uk/org/ownage/dmdirc/actions/CoreActionComponent.java 查看文件

@@ -95,9 +95,4 @@ public enum CoreActionComponent implements ActionComponent {
95 95
     /** {@inheritDoc} */
96 96
     public abstract String getName();
97 97
     
98
-    /** {@inheritDoc} */
99
-    public String toString() {
100
-        return getName();
101
-    }
102
-    
103 98
 }

+ 0
- 5
src/uk/org/ownage/dmdirc/actions/CoreActionType.java 查看文件

@@ -97,9 +97,4 @@ public enum CoreActionType implements ActionType {
97 97
         return name;
98 98
     }
99 99
     
100
-    /** {@inheritDoc} */
101
-    public String toString() {
102
-        return getName();
103
-    }
104
-    
105 100
 }

+ 0
- 5
src/uk/org/ownage/dmdirc/plugins/plugins/timeplugin/TimeActionType.java 查看文件

@@ -55,9 +55,4 @@ public enum TimeActionType implements ActionType {
55 55
         return name;
56 56
     }
57 57
     
58
-    /** {@inheritDoc} */
59
-    public String toString() {
60
-        return getName();
61
-    }
62
-    
63 58
 }

Loading…
取消
儲存