From 5efdc88762a80e59bf93a020573d5b567d57e686 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Tue, 25 Feb 2025 10:04:31 +0530 Subject: [PATCH] Add AI Inline Completion Shortcut Option --- .../completion/JeddictCompletionProvider.java | 3 +- .../ai/settings/AIAssistancePanel.form | 49 +++++++++++++++++++ .../ai/settings/AIAssistancePanel.java | 32 ++++++++++++ .../ai/settings/PreferencesManager.java | 8 +++ .../jeddict/ai/settings/Bundle.properties | 4 ++ 5 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/jeddict/ai/completion/JeddictCompletionProvider.java b/src/main/java/io/github/jeddict/ai/completion/JeddictCompletionProvider.java index 920c0f5..db04127 100644 --- a/src/main/java/io/github/jeddict/ai/completion/JeddictCompletionProvider.java +++ b/src/main/java/io/github/jeddict/ai/completion/JeddictCompletionProvider.java @@ -161,7 +161,8 @@ public CompletionTask createTask(int type, JTextComponent component) { if (!prefsManager.isSmartCodeEnabled()) { return null; } - if (type == COMPLETION_QUERY_TYPE) { + if ((prefsManager.isCompletionAllQueryType() && type == COMPLETION_ALL_QUERY_TYPE) + || (!prefsManager.isCompletionAllQueryType() && type == COMPLETION_QUERY_TYPE)) { return new AsyncCompletionTask(new JeddictCompletionQuery(type, component.getSelectionStart()), component); } return null; diff --git a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form index 26abd3e..419de32 100644 --- a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form +++ b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form @@ -22,6 +22,10 @@ -->
+ + + + @@ -1156,6 +1160,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java index 02ae2bd..b813b46 100644 --- a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java +++ b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java @@ -64,6 +64,7 @@ final class AIAssistancePanel extends javax.swing.JPanel { // //GEN-BEGIN:initComponents private void initComponents() { + aiInlineCompletionShortcutGroup = new javax.swing.ButtonGroup(); jTabbedPane1 = new javax.swing.JTabbedPane(); providersPane = new javax.swing.JLayeredPane(); providerParentPane = new javax.swing.JLayeredPane(); @@ -166,6 +167,10 @@ private void initComponents() { varContextLabel = new javax.swing.JLabel(); varContextHelp = new javax.swing.JLabel(); varContextComboBox = new javax.swing.JComboBox<>(); + snippetPane1 = new javax.swing.JLayeredPane(); + aiInlineCompletionShortcutLabel = new javax.swing.JLabel(); + ctrlSpaceRadioButton = new javax.swing.JRadioButton(); + ctrlAltSpaceRadioButton = new javax.swing.JRadioButton(); snippetPane = new javax.swing.JLayeredPane(); showDescriptionCheckBox = new javax.swing.JCheckBox(); cachePane = new javax.swing.JLayeredPane(); @@ -689,6 +694,25 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { inlineCompletionPane.add(varContextPane); + snippetPane1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); + + org.openide.awt.Mnemonics.setLocalizedText(aiInlineCompletionShortcutLabel, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcutLabel.text")); // NOI18N + aiInlineCompletionShortcutLabel.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcut.toolTipText")); // NOI18N + snippetPane1.add(aiInlineCompletionShortcutLabel); + + aiInlineCompletionShortcutGroup.add(ctrlSpaceRadioButton); + org.openide.awt.Mnemonics.setLocalizedText(ctrlSpaceRadioButton, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.ctrlSpaceRadioButton.text")); // NOI18N + ctrlSpaceRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcut.toolTipText")); // NOI18N + snippetPane1.add(ctrlSpaceRadioButton); + + aiInlineCompletionShortcutGroup.add(ctrlAltSpaceRadioButton); + ctrlAltSpaceRadioButton.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(ctrlAltSpaceRadioButton, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.ctrlAltSpaceRadioButton.text")); // NOI18N + ctrlAltSpaceRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.aiInlineCompletionShortcut.toolTipText")); // NOI18N + snippetPane1.add(ctrlAltSpaceRadioButton); + + inlineCompletionPane.add(snippetPane1); + snippetPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); org.openide.awt.Mnemonics.setLocalizedText(showDescriptionCheckBox, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.showDescriptionCheckBox.text")); // NOI18N @@ -1109,6 +1133,8 @@ void load() { providerComboBox.setSelectedItem(preferencesManager.getProvider()); modelComboBox.setSelectedItem(preferencesManager.getModel()); + ctrlSpaceRadioButton.setSelected(!preferencesManager.isCompletionAllQueryType()); + ctrlAltSpaceRadioButton.setSelected(preferencesManager.isCompletionAllQueryType()); showDescriptionCheckBox.setSelected(preferencesManager.isDescriptionEnabled()); fileExtField.setText(preferencesManager.getFileExtensionToInclude()); excludeJavadocCommentsCheckBox.setSelected(preferencesManager.isExcludeJavadocEnabled()); @@ -1144,6 +1170,7 @@ void store() { preferencesManager.setInlineHintEnabled(enableInlineHintCheckBox.isSelected()); preferencesManager.setHintsEnabled(enableHintsCheckBox.isSelected()); preferencesManager.setSmartCodeEnabled(enableSmartCodeCheckBox.isSelected()); + preferencesManager.setCompletionAllQueryType(ctrlAltSpaceRadioButton.isSelected()); preferencesManager.setDescriptionEnabled(showDescriptionCheckBox.isSelected()); preferencesManager.setFileExtensionToInclude(fileExtField.getText()); preferencesManager.setExcludeDirs(getCommaSeparatedValues(excludeTableModel)); @@ -1340,6 +1367,8 @@ boolean valid() { private javax.swing.JLayeredPane activationPane; private javax.swing.JLayeredPane activationParentPane; private javax.swing.JCheckBox aiAssistantActivationCheckBox; + private javax.swing.ButtonGroup aiInlineCompletionShortcutGroup; + private javax.swing.JLabel aiInlineCompletionShortcutLabel; private javax.swing.JCheckBox allowCodeExecution; private javax.swing.JPasswordField apiKeyField; private javax.swing.JLabel apiKeyInfo; @@ -1361,6 +1390,8 @@ boolean valid() { private javax.swing.JLayeredPane classContextPane; private javax.swing.JButton cleanDataButton; private javax.swing.JLayeredPane commonSettingsParentPane1; + private javax.swing.JRadioButton ctrlAltSpaceRadioButton; + private javax.swing.JRadioButton ctrlSpaceRadioButton; private javax.swing.JLayeredPane customHeadersPane; private javax.swing.JScrollPane customHeadersScrollPane; private javax.swing.JTable customHeadersTable; @@ -1433,6 +1464,7 @@ boolean valid() { private javax.swing.JLayeredPane seedPane; private javax.swing.JCheckBox showDescriptionCheckBox; private javax.swing.JLayeredPane snippetPane; + private javax.swing.JLayeredPane snippetPane1; private javax.swing.JCheckBox stream; private javax.swing.JTextField temperature; private javax.swing.JLabel temperatureLabel; diff --git a/src/main/java/io/github/jeddict/ai/settings/PreferencesManager.java b/src/main/java/io/github/jeddict/ai/settings/PreferencesManager.java index 4439fc9..72d72bb 100644 --- a/src/main/java/io/github/jeddict/ai/settings/PreferencesManager.java +++ b/src/main/java/io/github/jeddict/ai/settings/PreferencesManager.java @@ -346,6 +346,14 @@ public void setSmartCodeEnabled(boolean enabled) { preferences.putBoolean("enableSmartCode", enabled); } + public boolean isCompletionAllQueryType() { + return preferences.getBoolean("enableCompletionAllQueryType", true); + } + + public void setCompletionAllQueryType(boolean enabled) { + preferences.putBoolean("enableCompletionAllQueryType", enabled); + } + public boolean isDescriptionEnabled() { return preferences.getBoolean("showDecription", true); } diff --git a/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties b/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties index 1207c07..05160cb 100644 --- a/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties +++ b/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties @@ -112,3 +112,7 @@ AIAssistancePanel.maxRetries.toolTipText=Maximum number of retries for failed AP AIAssistancePanel.headerKey.text=Custom Header Key AIAssistancePanel.headerValue.text=Custom Header Value AIAssistancePanel.customHeadersTable.toolTipText=Custom headers can be to send specific metadata or authentication token +AIAssistancePanel.aiInlineCompletionShortcut.toolTipText=Select the keyboard shortcut to trigger AI-powered inline code completions. +AIAssistancePanel.aiInlineCompletionShortcutLabel.text=AI-Powered Inline Completion Shortcut: +AIAssistancePanel.ctrlSpaceRadioButton.text=CTRL+SPACE +AIAssistancePanel.ctrlAltSpaceRadioButton.text=CTRL+ALT+SPACE