mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-12-23 04:54:52 +01:00
feat: create buffer with content
This commit is contained in:
parent
cebcad7327
commit
4e28c9a65a
1 changed files with 35 additions and 0 deletions
|
@ -0,0 +1,35 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferCreateWithContentAction extends AnAction {
|
||||
|
||||
public static void createWithContent(AnActionEvent event, String buffer, boolean silent) throws Exception {
|
||||
String content = ActionUtil.getCurrentEditor(event).getDocument().getText();
|
||||
CodeMPHandler.createWithContent(buffer, content);
|
||||
if(!silent) Messages.showInfoMessage(String.format("Created buffer %s with content %s!", buffer, content),
|
||||
"Create CodeMP Buffer" );
|
||||
CodeMP.LOGGER.debug("Created buffer {} with content {}!", buffer, content);
|
||||
}
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
String buffer = Messages.showInputDialog(
|
||||
"Buffer name:",
|
||||
"Create CodeMP Buffer with Content",
|
||||
Messages.getQuestionIcon());
|
||||
|
||||
try {
|
||||
createWithContent(e, buffer, false);
|
||||
} catch(Exception ex) {
|
||||
Messages.showErrorDialog(String.format(
|
||||
"Failed to create buffer with name %s: %s!",
|
||||
buffer, ex.getMessage()), "Create CodeMP Buffer with Content");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue