chore: moved modal messages to notification

This commit is contained in:
zaaarf 2023-11-17 21:14:01 +01:00
parent f75b6191ea
commit 81529bb0b0
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
13 changed files with 75 additions and 53 deletions

View file

@ -2,16 +2,19 @@ package com.codemp.intellij.actions;
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 ConnectAction extends AnAction {
public static void connect(String url, boolean silent) throws Exception {
public static void connect(AnActionEvent e, String url, boolean silent) throws Exception {
CodeMP.loadLibrary(); //will only load it the first time
CodeMPHandler.connect(url);
if(!silent) Messages.showInfoMessage(String.format("Connected to %s!", url), "CodeMP");
if(!silent) ActionUtil.notify(e,
"Success", String.format("Connected to %s!", url));
CodeMP.LOGGER.debug("Connected to {}!", url);
}
@ -20,9 +23,11 @@ public class ConnectAction extends AnAction {
String url = Messages.showInputDialog("URL to CodeMP instance:", "CodeMP Connect",
Messages.getQuestionIcon());
try {
connect(url, false);
connect(e, url, false);
} catch(Exception ex) {
Messages.showErrorDialog(String.format("Failed to connect to %s: %s!", url, ex.getMessage()), "CodeMP");
ActionUtil.notifyError(e, String.format(
"Failed to connect to %s!",
url), ex);
}
}
}

View file

@ -13,7 +13,7 @@ public class FastForwardAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
try {
ConnectAction.connect("http://alemi.dev:50052", true);
ConnectAction.connect(e, "http://alemi.dev:50052", true);
WorkspaceJoinAction.join(e, "default", true);
BufferAttachAction.attach(e, "test", true);
} catch(Exception ex) {

View file

@ -14,8 +14,9 @@ import org.jetbrains.annotations.NotNull;
public class BufferAttachAction extends AnAction {
public static void attach(AnActionEvent e, String buffer, boolean silent) throws Exception {
BufferHandler bufferHandler = CodeMPHandler.attach(buffer);
if(!silent) Messages.showInfoMessage(String.format("Attached to buffer to %s!", buffer),
"CodeMP Buffer Attach");
if(!silent) ActionUtil.notify(e, "Success",
String.format("Successfully attached to buffer to buffer to %s!", buffer)
);
CodeMP.LOGGER.debug("Attached to buffer to {}!", buffer);
//TODO "get" the Editor corresponding to buffer, for now use the current one
@ -35,9 +36,9 @@ public class BufferAttachAction extends AnAction {
try {
attach(e, buffer, false);
} catch(Exception ex) {
Messages.showErrorDialog(String.format(
"Failed to attach to buffer %s: %s!",
buffer, ex.getMessage()), "Attach to CodeMP Buffer");
ActionUtil.notifyError(e, String.format(
"Failed to attach to buffer %s!",
buffer), ex);
}
}
}

View file

@ -2,16 +2,18 @@ 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 BufferCreateAction extends AnAction {
public static void create(String buffer, boolean silent) throws Exception {
public static void create(AnActionEvent e, String buffer, boolean silent) throws Exception {
CodeMPHandler.create(buffer);
if(!silent) Messages.showInfoMessage(String.format("Created buffer %s!", buffer),
"Create CodeMP Buffer" );
if(!silent) ActionUtil.notify(e, "Success",
String.format("Created buffer %s!", buffer)
);
CodeMP.LOGGER.debug("Created buffer {}!", buffer);
}
@ -23,11 +25,11 @@ public class BufferCreateAction extends AnAction {
Messages.getQuestionIcon());
try {
create(buffer, false);
create(e, buffer, false);
} catch(Exception ex) {
Messages.showErrorDialog(String.format(
"Failed to create buffer with name %s: %s!",
buffer, ex.getMessage()), "Create CodeMP Buffer");
ActionUtil.notifyError(e, String.format(
"Failed to create buffer with name %s!",
buffer), ex);
}
}
}

View file

@ -13,8 +13,9 @@ 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" );
if(!silent) ActionUtil.notify(event, "Success", String.format(
"Created buffer %s with content %s!", buffer, content));
CodeMP.LOGGER.debug("Created buffer {} with content {}!", buffer, content);
}
@Override
@ -27,9 +28,9 @@ public class BufferCreateWithContentAction extends AnAction {
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");
ActionUtil.notifyError(e, String.format(
"Failed to create buffer with name %s!",
buffer), ex);
}
}
}

View file

@ -5,13 +5,14 @@ import com.codemp.intellij.exceptions.ide.BufferDetachException;
import com.codemp.intellij.jni.CodeMPHandler;
import com.codemp.intellij.task.BufferEventAwaiterTask;
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.ui.Messages;
import org.jetbrains.annotations.NotNull;
public class BufferDetachAction extends AnAction {
public static void detach(String buffer, boolean silent) throws Exception {
public static void detach(AnActionEvent e, String buffer, boolean silent) throws Exception {
boolean res = CodeMPHandler.detach(buffer);
if(!res) throw new BufferDetachException(buffer);
@ -19,13 +20,13 @@ public class BufferDetachAction extends AnAction {
BufferEventAwaiterTask task = TaskManager.getBufferTask();
if(task != null) {
task.unregisterListener(buffer);
if(!silent) Messages.showInfoMessage(String.format("Detached from buffer %s!", buffer),
"Detach from CodeMP Buffer");
if(!silent) ActionUtil.notify(e, "Success",
String.format("Detached from buffer %s!", buffer)
);
CodeMP.LOGGER.debug("Detached from buffer {}!", buffer);
} else {
if(!silent) Messages.showErrorDialog(
String.format("Failed to detach from %s: buffer event task was dead!", buffer),
"Detach from CodeMP Buffer");
if(!silent) ActionUtil.notifyError(e, String.format("Failed to detach from %s", buffer),
"Buffer event task was dead!");
CodeMP.LOGGER.debug("Failed to detach from {}: buffer event task was dead!", buffer);
}
}
@ -38,11 +39,11 @@ public class BufferDetachAction extends AnAction {
Messages.getQuestionIcon());
try {
detach(buffer, false);
detach(e, buffer, false);
} catch(Exception ex) {
Messages.showErrorDialog(String.format(
"Failed to detach from buffer with name %s: %s!",
buffer, ex.getMessage()), "Detach from CodeMP Buffer");
ActionUtil.notifyError(e, String.format(
"Failed to detach from buffer with name %s!",
buffer), ex);
}
}
}

View file

@ -10,8 +10,6 @@ import com.codemp.intellij.util.ActionUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
@ -19,8 +17,9 @@ public class WorkspaceJoinAction extends AnAction {
public static void join(AnActionEvent e, String workspace, boolean silent) throws Exception {
CursorHandler cursorHandler = CodeMPHandler.join(workspace);
if(!silent) Messages.showInfoMessage(String.format("Joined workspace %s!", workspace), "CodeMP");
else CodeMP.LOGGER.debug("Joined workspace {}!", workspace);
if(!silent) ActionUtil.notify(e,
"Success", String.format("Joined workspace %s!", workspace));
CodeMP.LOGGER.debug("Joined workspace {}!", workspace);
CursorEventAwaiterTask task = TaskManager
.getOrCreateCursorTask(ActionUtil.getCurrentProject(e), cursorHandler);
@ -40,11 +39,9 @@ public class WorkspaceJoinAction extends AnAction {
try {
join(e, session, false);
} catch(Exception ex) {
Messages.showErrorDialog(String.format(
"Failed to join session %s: %s!",
session,
ex.getMessage()),
"CodeMP Join");
ActionUtil.notifyError(e, String.format(
"Failed to join session %s!",
session), ex);
}
}
}

View file

@ -2,28 +2,26 @@ package com.codemp.intellij.actions.workspace;
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 WorkspaceLeaveAction extends AnAction {
public static void leave(boolean silent) throws Exception {
public static void leave(AnActionEvent e, boolean silent) throws Exception {
CodeMPHandler.leaveWorkspace();
if(!silent) Messages.showInfoMessage("Left workspace!",
"Detach from CodeMP Buffer" );
if(!silent) ActionUtil.notify(e, "Success", "Left workspace");
CodeMP.LOGGER.debug("Left workspace!");
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
try {
leave(false);
leave(e, false);
} catch(Exception ex) {
Messages.showErrorDialog(String.format(
"Failed to leave workspace: %s!",
ex.getMessage()), "Leave CodeMP Workspace");
ActionUtil.notifyError(e, "Failed to leave workspace!", ex);
}
}
}

View file

@ -2,7 +2,6 @@ package com.codemp.intellij.listeners;
import com.codemp.intellij.CodeMP;
import com.codemp.intellij.jni.BufferHandler;
import com.codemp.intellij.jni.CodeMPHandler;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;

View file

@ -1,7 +1,6 @@
package com.codemp.intellij.listeners;
import com.codemp.intellij.CodeMP;
import com.codemp.intellij.jni.CodeMPHandler;
import com.codemp.intellij.jni.CursorHandler;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.VisualPosition;

View file

@ -18,7 +18,6 @@ import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

View file

@ -1,6 +1,9 @@
package com.codemp.intellij.util;
import com.codemp.intellij.exceptions.ide.BadActionEventStateException;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditorManager;
@ -21,4 +24,22 @@ public class ActionUtil {
throw new BadActionEventStateException("Editor was null!");
return editor;
}
public static void notify(AnActionEvent event, String title, String msg) {
Notifications.Bus.notify(new Notification(
"CodeMP", title, msg, NotificationType.INFORMATION
), event.getProject());
}
public static void notifyError(AnActionEvent event, String title, String msg) {
Notifications.Bus.notify(new Notification(
"CodeMP", title, msg, NotificationType.ERROR
), event.getProject());
}
public static void notifyError(AnActionEvent event, String title, Throwable t) {
Notifications.Bus.notify(new Notification(
"CodeMP", title, t.getMessage(), NotificationType.ERROR
), event.getProject());
}
}

View file

@ -49,7 +49,6 @@
</actions>
<extensions defaultExtensionNs="com.intellij">
<!-- Extension points defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<notificationGroup id="CodeMP" displayType="BALLOON"/>
</extensions>
</idea-plugin>