Skip to content

Commit 8c58f96

Browse files
committed
Add settings to save templates
1 parent 8431f31 commit 8c58f96

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

src/main/java/com/junichi11/netbeans/modules/github/issues/GitHubIssuesConfig.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@
4848
import java.text.DateFormat;
4949
import java.text.ParseException;
5050
import java.text.SimpleDateFormat;
51+
import java.util.ArrayList;
52+
import java.util.Arrays;
5153
import java.util.Date;
5254
import java.util.prefs.BackingStoreException;
5355
import java.util.prefs.Preferences;
5456
import org.openide.util.Exceptions;
57+
import org.openide.util.NbBundle;
5558
import org.openide.util.NbPreferences;
5659

5760
/**
@@ -67,6 +70,8 @@ public final class GitHubIssuesConfig {
6770
private static final String SCHEDULE = "schedule"; // NOI18N
6871
private static final String SCHEDULE_DUE_DATE = "schedule.due"; // NOI18N
6972
private static final String SCHEDULE_INTERVAL = "schedule.interval"; // NOI18N
73+
private static final String TEMPLATE = "template"; // NOI18N
74+
private static final String DEFAULT_TEMPLATE_NAME = "default"; // NOI18N
7075

7176
private GitHubIssuesConfig() {
7277
}
@@ -192,6 +197,66 @@ public void removeSchedule(GitHubRepository repository, GitHubIssue issue) {
192197
}
193198
}
194199

200+
/**
201+
* Get the template for specified name.
202+
*
203+
* @param name the template name
204+
* @return the template
205+
*/
206+
@NbBundle.Messages("GitHubIssuesConfig.default.template=#### Overview description\n"
207+
+ "\n"
208+
+ "#### Steps to reproduce\n"
209+
+ "\n"
210+
+ "1. \n"
211+
+ "2. \n"
212+
+ "3. \n"
213+
+ "\n"
214+
+ "#### Actual results\n"
215+
+ "\n"
216+
+ "#### Expected results\n")
217+
public String getTemplate(String name) {
218+
return getPreferences().node(TEMPLATE).get(name, Bundle.GitHubIssuesConfig_default_template());
219+
}
220+
221+
/**
222+
* Set template.
223+
*
224+
* @param name the template name
225+
* @param template the template
226+
*/
227+
public void setTemplate(String name, String template) {
228+
getPreferences().node(TEMPLATE).put(name, template);
229+
}
230+
231+
/**
232+
* Remove a template. <b>NOTE:</b> Can't remove the default template. But
233+
* default template will be initialized.
234+
*
235+
* @param name the template name
236+
*/
237+
public void removeTemplate(String name) {
238+
getPreferences().node(TEMPLATE).remove(name);
239+
}
240+
241+
/**
242+
* Get all template names.
243+
*
244+
* @return all template names
245+
*/
246+
public String[] getTemplateNames() {
247+
ArrayList<String> names = new ArrayList<>();
248+
names.add(DEFAULT_TEMPLATE_NAME);
249+
Preferences preferences = getPreferences().node(TEMPLATE);
250+
try {
251+
String[] childrenNames = preferences.keys();
252+
names.addAll(Arrays.asList(childrenNames));
253+
return names.toArray(new String[childrenNames.length + 1]);
254+
} catch (BackingStoreException ex) {
255+
Exceptions.printStackTrace(ex);
256+
}
257+
return names.toArray(new String[1]);
258+
}
259+
195260
public void removeRepository(GitHubRepository repository) {
196261
Preferences preferences = getPreferences(repository);
197262
try {

0 commit comments

Comments
 (0)