-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include version and GitHub project link in Settings panel
- Loading branch information
Showing
8 changed files
with
145 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/devoxx/genie/service/PropertiesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.devoxx.genie.service; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
public class PropertiesService { | ||
|
||
private final Properties properties = new Properties(); | ||
|
||
public PropertiesService() { | ||
loadProperties(); | ||
} | ||
|
||
@NotNull | ||
public static PropertiesService getInstance() { | ||
return ApplicationManager.getApplication().getService(PropertiesService.class); | ||
} | ||
|
||
private void loadProperties() { | ||
try (InputStream input = getClass().getClassLoader().getResourceAsStream("application.properties")) { | ||
if (input == null) { | ||
System.out.println("Sorry, unable to find application.properties"); | ||
return; | ||
} | ||
properties.load(input); | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
public String getVersion() { | ||
return properties.getProperty("version"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/com/devoxx/genie/ui/util/CodeSnippetAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.devoxx.genie.ui.util; | ||
|
||
import com.devoxx.genie.model.request.ChatMessageContext; | ||
import com.devoxx.genie.ui.component.JHoverButton; | ||
import com.intellij.openapi.command.WriteCommandAction; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.editor.CaretModel; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.openapi.fileEditor.FileEditorManager; | ||
import org.commonmark.node.FencedCodeBlock; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.datatransfer.StringSelection; | ||
import java.awt.datatransfer.Clipboard; | ||
import java.awt.Toolkit; | ||
|
||
import static com.devoxx.genie.ui.util.DevoxxGenieIcons.CopyIcon; | ||
import static com.devoxx.genie.ui.util.DevoxxGenieIcons.InsertCodeIcon; | ||
|
||
public class CodeSnippetAction { | ||
|
||
private final ChatMessageContext chatMessageContext; | ||
|
||
public CodeSnippetAction(ChatMessageContext chatMessageContext) { | ||
this.chatMessageContext = chatMessageContext; | ||
} | ||
|
||
public JPanel createClipBoardButtonPanel(FencedCodeBlock fencedCodeBlock) { | ||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 4, 2)); | ||
buttonPanel.setOpaque(true); | ||
|
||
JHoverButton copyButton = new JHoverButton(CopyIcon, true); | ||
copyButton.setToolTipText("Copy to clipboard"); | ||
copyButton.addActionListener(e -> copyToClipboard(fencedCodeBlock.getLiteral())); | ||
buttonPanel.add(copyButton); | ||
|
||
JHoverButton insertButton = new JHoverButton(InsertCodeIcon, true); | ||
insertButton.setToolTipText("Insert code"); | ||
insertButton.addActionListener(e -> insertCode(fencedCodeBlock.getLiteral())); | ||
buttonPanel.add(insertButton); | ||
|
||
return buttonPanel; | ||
} | ||
|
||
private void copyToClipboard(String codeSnippet) { | ||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
clipboard.setContents(new StringSelection(codeSnippet), null); | ||
NotificationUtil.sendNotification(chatMessageContext.getProject(), "Code copied to clipboard"); | ||
} | ||
|
||
private void insertCode(String codeSnippet) { | ||
FileEditorManager fileEditorManager = FileEditorManager.getInstance(chatMessageContext.getProject()); | ||
Editor editor = fileEditorManager.getSelectedTextEditor(); | ||
if (editor != null) { | ||
Document document = editor.getDocument(); | ||
CaretModel caretModel = editor.getCaretModel(); | ||
WriteCommandAction.runWriteCommandAction(chatMessageContext.getProject(), () -> { | ||
try { | ||
document.insertString(caretModel.getOffset(), codeSnippet); | ||
} catch (Exception e) { | ||
Logger.getInstance(getClass()).error(e.getMessage()); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#Tue Jun 25 13:55:28 CEST 2024 | ||
version=0.1.20 |