feat: create buffer with content

This commit is contained in:
zaaarf 2023-11-16 16:36:41 +01:00
parent cebcad7327
commit 4e28c9a65a
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C

View file

@ -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");
}
}
}