Skip to content

Commit a5eb522

Browse files
committed
Merge pull request #29 from junichi11/feature-templates
Add features to insert and manage templates
2 parents 8431f31 + 47751ad commit a5eb522

13 files changed

Lines changed: 1046 additions & 6 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This plugin provides support for GitHub Issue Tracker.
1313
- Create a new label
1414
- Create a new milestone
1515
- Add issues to schedule categories
16+
- Insert and manage templates
1617

1718
## Usage
1819

@@ -29,6 +30,14 @@ This plugin provides support for GitHub Issue Tracker.
2930

3031
If an issue has a milestone and it has a due date, the issue is added to schedule category.
3132

33+
### Insert and manage templates
34+
35+
You can insert a template and manage templates using buttons below the description.
36+
All templates are used globally. (i.e. It isn't templates per repository.)
37+
38+
**NOTE:**You cannot remove the default template. If you remove it, it will be initilized.
39+
You cannot edit a template name. So, if you want to change it, just remove it, then add a new template.
40+
3241
## Default queries
3342

3443
1. Open

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 {

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/GitHubIssuePanel.form

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,13 @@
272272
<Group type="103" groupAlignment="0" attributes="0">
273273
<Component id="descriptionLabel" min="-2" max="-2" attributes="0"/>
274274
<Component id="titleLabel" alignment="0" min="-2" max="-2" attributes="0"/>
275+
<Group type="102" alignment="0" attributes="0">
276+
<Component id="insertTemplateButton" min="-2" max="-2" attributes="0"/>
277+
<EmptySpace max="-2" attributes="0"/>
278+
<Component id="manageTemplatesButton" min="-2" max="-2" attributes="0"/>
279+
</Group>
275280
</Group>
276-
<EmptySpace min="-2" pref="37" max="-2" attributes="0"/>
281+
<EmptySpace type="separate" max="-2" attributes="0"/>
277282
<Group type="103" groupAlignment="0" attributes="0">
278283
<Component id="descriptionTabbedPanel" max="32767" attributes="0"/>
279284
<Component id="titleTextField" max="32767" attributes="0"/>
@@ -340,7 +345,12 @@
340345
</Group>
341346
<Group type="102" attributes="0">
342347
<Component id="descriptionLabel" min="-2" max="-2" attributes="0"/>
343-
<EmptySpace min="-2" pref="271" max="-2" attributes="0"/>
348+
<EmptySpace max="-2" attributes="0"/>
349+
<Group type="103" groupAlignment="0" attributes="0">
350+
<Component id="insertTemplateButton" min="-2" max="-2" attributes="0"/>
351+
<Component id="manageTemplatesButton" min="-2" max="-2" attributes="0"/>
352+
</Group>
353+
<EmptySpace min="-2" pref="237" max="-2" attributes="0"/>
344354
</Group>
345355
<Component id="descriptionTabbedPanel" min="-2" max="-2" attributes="0"/>
346356
</Group>
@@ -492,6 +502,38 @@
492502
</Property>
493503
</Properties>
494504
</Component>
505+
<Component class="javax.swing.JButton" name="insertTemplateButton">
506+
<Properties>
507+
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
508+
<Image iconType="2" name="/home/junichi11/NetBeansProjects/netbeans-github-issues/src/main/resources/com/junichi11/netbeans/modules/github/issues/resources/template_16.png"/>
509+
</Property>
510+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
511+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="GitHubIssuePanel.insertTemplateButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
512+
</Property>
513+
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
514+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="GitHubIssuePanel.insertTemplateButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
515+
</Property>
516+
</Properties>
517+
<Events>
518+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="insertTemplateButtonActionPerformed"/>
519+
</Events>
520+
</Component>
521+
<Component class="javax.swing.JButton" name="manageTemplatesButton">
522+
<Properties>
523+
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
524+
<Image iconType="2" name="/home/junichi11/NetBeansProjects/netbeans-github-issues/src/main/resources/com/junichi11/netbeans/modules/github/issues/resources/template_settings_16.png"/>
525+
</Property>
526+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
527+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="GitHubIssuePanel.manageTemplatesButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
528+
</Property>
529+
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
530+
<ResourceString bundle="com/junichi11/netbeans/modules/github/issues/issue/ui/Bundle.properties" key="GitHubIssuePanel.manageTemplatesButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
531+
</Property>
532+
</Properties>
533+
<Events>
534+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="manageTemplatesButtonActionPerformed"/>
535+
</Events>
536+
</Component>
495537
</SubComponents>
496538
</Container>
497539
</SubComponents>

0 commit comments

Comments
 (0)