Skip to content

Commit 68de840

Browse files
authored
Merge pull request #156 from jeddict/feature
Shortkeys to Submit Query
2 parents c0a8d97 + 906ae2a commit 68de840

6 files changed

Lines changed: 169 additions & 71 deletions

File tree

src/main/java/io/github/jeddict/ai/hints/AssistantChatManager.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@
7676
import java.awt.Dimension;
7777
import java.awt.EventQueue;
7878
import java.awt.FlowLayout;
79+
import java.awt.Toolkit;
7980
import java.awt.event.ActionEvent;
8081
import java.awt.event.ComponentAdapter;
8182
import java.awt.event.ComponentEvent;
83+
import java.awt.event.KeyAdapter;
84+
import java.awt.event.KeyEvent;
8285
import java.io.File;
8386
import java.io.FileWriter;
8487
import java.io.IOException;
@@ -107,6 +110,7 @@
107110
import javax.swing.JFrame;
108111
import javax.swing.JPanel;
109112
import javax.swing.JScrollPane;
113+
import javax.swing.KeyStroke;
110114
import javax.swing.ScrollPaneConstants;
111115
import javax.swing.SwingUtilities;
112116
import javax.swing.Timer;
@@ -153,7 +157,7 @@ public class AssistantChatManager extends JavaFix {
153157
private JScrollPane questionScrollPane;
154158
private final List<Response> responseHistory = new ArrayList<>();
155159
private int currentResponseIndex = -1;
156-
private String sourceCode = null;
160+
private String sourceCode;
157161
private Project projectContext;
158162
private Project project;
159163
private final Set<FileObject> threadContext = new HashSet<>();
@@ -781,15 +785,28 @@ public void actionPerformed(ActionEvent ae) {
781785
FileTransferHandler.register(questionPane, this::addFileTab);
782786

783787
//
784-
// intercept Ctrl+ENTER to submit the prompt
788+
// intercept shortkeys to submit the prompt
785789
//
786790
final String actionKey = "submit-prompt";
787-
final javax.swing.KeyStroke ctrlEnter = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, java.awt.event.KeyEvent.CTRL_DOWN_MASK);
791+
792+
String shortcut = pm.getSubmitShortcut(); // e.g. "Ctrl + Enter", "Enter", "Shift + Enter", "Alt + Enter"
793+
794+
javax.swing.KeyStroke submitKey;
795+
switch (shortcut) {
796+
case "Enter":
797+
submitKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
798+
break;
799+
case "Shift + Enter":
800+
submitKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK);
801+
break;
802+
default: // "Ctrl + Enter"
803+
submitKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK);
804+
}
788805

789806
final javax.swing.InputMap inputMap = questionPane.getInputMap(JComponent.WHEN_FOCUSED);
790807
final javax.swing.ActionMap actionMap = questionPane.getActionMap();
791808

792-
inputMap.put(ctrlEnter, actionKey);
809+
inputMap.put(submitKey, actionKey);
793810
actionMap.put(actionKey, submitButton.getAction());
794811

795812
// ---

src/main/java/io/github/jeddict/ai/lang/JeddictChatModelBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ private String generateInternal(Project project, String prompt, List<String> ima
294294
"Error in AI Assistance",
295295
JOptionPane.ERROR_MESSAGE);
296296
}
297+
handle.finish();
297298
}
298299
return null;
299300
}

src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form

Lines changed: 84 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
<Layout>
4242
<DimensionLayout dim="0">
4343
<Group type="103" groupAlignment="0" attributes="0">
44-
<Component id="jTabbedPane1" alignment="0" pref="558" max="32767" attributes="0"/>
44+
<Component id="jTabbedPane1" alignment="0" pref="600" max="32767" attributes="0"/>
4545
</Group>
4646
</DimensionLayout>
4747
<DimensionLayout dim="1">
4848
<Group type="103" groupAlignment="0" attributes="0">
4949
<Group type="102" alignment="0" attributes="0">
50-
<Component id="jTabbedPane1" pref="835" max="32767" attributes="0"/>
50+
<Component id="jTabbedPane1" pref="488" max="32767" attributes="0"/>
5151
<EmptySpace max="-2" attributes="0"/>
5252
</Group>
5353
</Group>
@@ -826,23 +826,23 @@
826826
<Layout>
827827
<DimensionLayout dim="0">
828828
<Group type="103" groupAlignment="0" attributes="0">
829-
<EmptySpace min="0" pref="558" max="32767" attributes="0"/>
829+
<EmptySpace min="0" pref="600" max="32767" attributes="0"/>
830830
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
831831
<Group type="102" alignment="0" attributes="0">
832832
<EmptySpace max="-2" attributes="0"/>
833-
<Component id="customHeadersScrollPane" pref="546" max="32767" attributes="0"/>
833+
<Component id="customHeadersScrollPane" pref="588" max="32767" attributes="0"/>
834834
<EmptySpace max="-2" attributes="0"/>
835835
</Group>
836836
</Group>
837837
</Group>
838838
</DimensionLayout>
839839
<DimensionLayout dim="1">
840840
<Group type="103" groupAlignment="0" attributes="0">
841-
<EmptySpace min="0" pref="385" max="32767" attributes="0"/>
841+
<EmptySpace min="0" pref="211" max="32767" attributes="0"/>
842842
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
843843
<Group type="102" alignment="1" attributes="0">
844844
<EmptySpace max="-2" attributes="0"/>
845-
<Component id="customHeadersScrollPane" pref="379" max="32767" attributes="0"/>
845+
<Component id="customHeadersScrollPane" pref="205" max="32767" attributes="0"/>
846846
</Group>
847847
</Group>
848848
</Group>
@@ -975,6 +975,83 @@
975975
<Property name="rows" type="int" value="1"/>
976976
</Layout>
977977
<SubComponents>
978+
<Container class="javax.swing.JLayeredPane" name="jLayeredPane3">
979+
980+
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
981+
<Property name="alignment" type="int" value="0"/>
982+
</Layout>
983+
<SubComponents>
984+
<Container class="javax.swing.JLayeredPane" name="jLayeredPane7">
985+
986+
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
987+
<Property name="alignment" type="int" value="0"/>
988+
</Layout>
989+
<SubComponents>
990+
<Component class="javax.swing.JLabel" name="submitShortcutLabel">
991+
<Properties>
992+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
993+
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.submitShortcutLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
994+
</Property>
995+
</Properties>
996+
</Component>
997+
<Component class="javax.swing.JComboBox" name="submitShortcut">
998+
<Properties>
999+
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
1000+
<Connection code="new javax.swing.DefaultComboBoxModel&lt;&gt;(new String[] { &quot;Ctrl + Enter&quot;, &quot;Enter&quot;, &quot;Shift + Enter&quot;})" type="code"/>
1001+
</Property>
1002+
</Properties>
1003+
<AuxValues>
1004+
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
1005+
</AuxValues>
1006+
</Component>
1007+
</SubComponents>
1008+
</Container>
1009+
<Container class="javax.swing.JLayeredPane" name="jLayeredPane4">
1010+
1011+
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
1012+
<Property name="alignment" type="int" value="0"/>
1013+
</Layout>
1014+
<SubComponents>
1015+
<Component class="javax.swing.JLabel" name="defaultAIAssistantPlacementLabel">
1016+
<Properties>
1017+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
1018+
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.defaultAIAssistantPlacementLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
1019+
</Property>
1020+
</Properties>
1021+
</Component>
1022+
<Component class="javax.swing.JComboBox" name="defaultAIAssistantPlacement">
1023+
<Properties>
1024+
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
1025+
<Connection code="new javax.swing.DefaultComboBoxModel&lt;&gt;(new String[] { &quot;Left&quot;, &quot;Center&quot;, &quot;Right&quot; })" type="code"/>
1026+
</Property>
1027+
</Properties>
1028+
<AuxValues>
1029+
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
1030+
</AuxValues>
1031+
</Component>
1032+
</SubComponents>
1033+
</Container>
1034+
<Container class="javax.swing.JLayeredPane" name="jLayeredPane5">
1035+
1036+
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
1037+
<SubComponents>
1038+
<Component class="javax.swing.JCheckBox" name="excludeJavadocCommentsCheckBox">
1039+
<Properties>
1040+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
1041+
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.excludeJavadocCommentsCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
1042+
</Property>
1043+
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
1044+
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.excludeJavadocCommentsCheckBox.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
1045+
</Property>
1046+
</Properties>
1047+
<Events>
1048+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="excludeJavadocCommentsCheckBoxActionPerformed"/>
1049+
</Events>
1050+
</Component>
1051+
</SubComponents>
1052+
</Container>
1053+
</SubComponents>
1054+
</Container>
9781055
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
9791056

9801057
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
@@ -990,45 +1067,6 @@
9901067
</Container>
9911068
</SubComponents>
9921069
</Container>
993-
<Container class="javax.swing.JLayeredPane" name="jLayeredPane1">
994-
995-
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
996-
<Property name="alignment" type="int" value="0"/>
997-
<Property name="horizontalGap" type="int" value="15"/>
998-
</Layout>
999-
<SubComponents>
1000-
<Component class="javax.swing.JLabel" name="defaultAIAssistantPlacementLabel">
1001-
<Properties>
1002-
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
1003-
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.defaultAIAssistantPlacementLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
1004-
</Property>
1005-
</Properties>
1006-
</Component>
1007-
<Component class="javax.swing.JComboBox" name="defaultAIAssistantPlacement">
1008-
<Properties>
1009-
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
1010-
<Connection code="new javax.swing.DefaultComboBoxModel&lt;&gt;(new String[] { &quot;Left&quot;, &quot;Center&quot;, &quot;Right&quot; })" type="code"/>
1011-
</Property>
1012-
</Properties>
1013-
<AuxValues>
1014-
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
1015-
</AuxValues>
1016-
</Component>
1017-
<Component class="javax.swing.JCheckBox" name="excludeJavadocCommentsCheckBox">
1018-
<Properties>
1019-
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
1020-
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.excludeJavadocCommentsCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
1021-
</Property>
1022-
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
1023-
<ResourceString bundle="io/github/jeddict/ai/settings/Bundle.properties" key="AIAssistancePanel.excludeJavadocCommentsCheckBox.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
1024-
</Property>
1025-
</Properties>
1026-
<Events>
1027-
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="excludeJavadocCommentsCheckBoxActionPerformed"/>
1028-
</Events>
1029-
</Component>
1030-
</SubComponents>
1031-
</Container>
10321070
</SubComponents>
10331071
</Container>
10341072
<Container class="javax.swing.JLayeredPane" name="inlineCompletionPane">
@@ -1487,7 +1525,7 @@
14871525
<Component id="importButton" alignment="3" min="-2" max="-2" attributes="0"/>
14881526
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
14891527
</Group>
1490-
<EmptySpace pref="684" max="32767" attributes="0"/>
1528+
<EmptySpace pref="337" max="32767" attributes="0"/>
14911529
</Group>
14921530
</Group>
14931531
</DimensionLayout>

0 commit comments

Comments
 (0)