mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-23 23:54:48 +01:00
feat: force sync buffer
This commit is contained in:
parent
878df9716f
commit
154e8c26b5
4 changed files with 52 additions and 2 deletions
|
@ -0,0 +1,45 @@
|
|||
package com.codemp.intellij.actions.buffer;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.jni.CodeMPHandler;
|
||||
import com.codemp.intellij.task.TaskManager;
|
||||
import com.codemp.intellij.util.ActionUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BufferSyncAction extends AnAction {
|
||||
public static void sync(AnActionEvent e, String bufferName, boolean silent) {
|
||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
||||
ApplicationManager.getApplication().runWriteAction(() ->
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
editor.getProject(),
|
||||
() -> editor.getDocument().setText(CodeMPHandler.getBuffer(bufferName).getContent()),
|
||||
"CodeMPBufferSync",
|
||||
"codemp-buffer-sync",
|
||||
editor.getDocument()
|
||||
));
|
||||
|
||||
if(!silent) ActionUtil.notify(e,
|
||||
String.format("Synced buffer %s", bufferName),
|
||||
"The buffer was synced successfully.");
|
||||
CodeMP.LOGGER.debug("The buffer {} was synced successfully.", bufferName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
Editor editor = ActionUtil.getCurrentEditor(e);
|
||||
String bufferName = CodeMP.ACTIVE_BUFFERS_REVERSE.get(editor);
|
||||
try {
|
||||
sync(e, bufferName, false);
|
||||
} catch(Exception ex) {
|
||||
ActionUtil.notifyError(e, String.format(
|
||||
"Failed to attach to buffer %s!",
|
||||
bufferName), ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,8 +22,9 @@ public class BufferEventListener implements DocumentListener {
|
|||
event.getOldFragment(), event.getNewFragment(), event.getOffset());
|
||||
|
||||
Object group = CommandProcessor.getInstance().getCurrentCommandGroupId();
|
||||
if(group instanceof String groupString && groupString.startsWith("codemp-buffer-receive"))
|
||||
return;
|
||||
if(group instanceof String groupString)
|
||||
if(groupString.startsWith("codemp-buffer-receive") || groupString.startsWith("codemp-buffer-sync"))
|
||||
return;
|
||||
|
||||
//TODO move actions break
|
||||
int changeOffset = event.getOffset();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.codemp.intellij.util;
|
||||
|
||||
import com.codemp.intellij.CodeMP;
|
||||
import com.codemp.intellij.exceptions.ide.BadActionEventStateException;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
|
@ -43,5 +44,6 @@ public class ActionUtil {
|
|||
String.format("%s: %s", t.getClass().getCanonicalName(), t.getMessage()),
|
||||
NotificationType.ERROR
|
||||
), event.getProject());
|
||||
CodeMP.LOGGER.error(title, t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
text="Create Buffer with Content"/>
|
||||
<action id="codemp.buffer.attach" class="com.codemp.intellij.actions.buffer.BufferAttachAction"
|
||||
text="Attach to Buffer"/>
|
||||
<action id="codemp.buffer.sync" class="com.codemp.intellij.actions.buffer.BufferSyncAction"
|
||||
text="Force Sync Buffer"/>
|
||||
<action id="codemp.buffer.detach" class="com.codemp.intellij.actions.buffer.BufferDetachAction"
|
||||
text="Detach from Buffer"/>
|
||||
</group>
|
||||
|
|
Loading…
Reference in a new issue