mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-11-24 16:04:48 +01:00
chore: moved modal messages to notification
This commit is contained in:
parent
f75b6191ea
commit
81529bb0b0
13 changed files with 75 additions and 53 deletions
|
@ -2,16 +2,19 @@ package com.codemp.intellij.actions;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.jni.CodeMPHandler;
|
import com.codemp.intellij.jni.CodeMPHandler;
|
||||||
|
import com.codemp.intellij.util.ActionUtil;
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ConnectAction extends AnAction {
|
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
|
CodeMP.loadLibrary(); //will only load it the first time
|
||||||
CodeMPHandler.connect(url);
|
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);
|
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",
|
String url = Messages.showInputDialog("URL to CodeMP instance:", "CodeMP Connect",
|
||||||
Messages.getQuestionIcon());
|
Messages.getQuestionIcon());
|
||||||
try {
|
try {
|
||||||
connect(url, false);
|
connect(e, url, false);
|
||||||
} catch(Exception ex) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class FastForwardAction extends AnAction {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||||
try {
|
try {
|
||||||
ConnectAction.connect("http://alemi.dev:50052", true);
|
ConnectAction.connect(e, "http://alemi.dev:50052", true);
|
||||||
WorkspaceJoinAction.join(e, "default", true);
|
WorkspaceJoinAction.join(e, "default", true);
|
||||||
BufferAttachAction.attach(e, "test", true);
|
BufferAttachAction.attach(e, "test", true);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
|
|
|
@ -14,8 +14,9 @@ import org.jetbrains.annotations.NotNull;
|
||||||
public class BufferAttachAction extends AnAction {
|
public class BufferAttachAction extends AnAction {
|
||||||
public static void attach(AnActionEvent e, String buffer, boolean silent) throws Exception {
|
public static void attach(AnActionEvent e, String buffer, boolean silent) throws Exception {
|
||||||
BufferHandler bufferHandler = CodeMPHandler.attach(buffer);
|
BufferHandler bufferHandler = CodeMPHandler.attach(buffer);
|
||||||
if(!silent) Messages.showInfoMessage(String.format("Attached to buffer to %s!", buffer),
|
if(!silent) ActionUtil.notify(e, "Success",
|
||||||
"CodeMP Buffer Attach");
|
String.format("Successfully attached to buffer to buffer to %s!", buffer)
|
||||||
|
);
|
||||||
CodeMP.LOGGER.debug("Attached to buffer to {}!", buffer);
|
CodeMP.LOGGER.debug("Attached to buffer to {}!", buffer);
|
||||||
|
|
||||||
//TODO "get" the Editor corresponding to buffer, for now use the current one
|
//TODO "get" the Editor corresponding to buffer, for now use the current one
|
||||||
|
@ -35,9 +36,9 @@ public class BufferAttachAction extends AnAction {
|
||||||
try {
|
try {
|
||||||
attach(e, buffer, false);
|
attach(e, buffer, false);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Messages.showErrorDialog(String.format(
|
ActionUtil.notifyError(e, String.format(
|
||||||
"Failed to attach to buffer %s: %s!",
|
"Failed to attach to buffer %s!",
|
||||||
buffer, ex.getMessage()), "Attach to CodeMP Buffer");
|
buffer), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,18 @@ package com.codemp.intellij.actions.buffer;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.jni.CodeMPHandler;
|
import com.codemp.intellij.jni.CodeMPHandler;
|
||||||
|
import com.codemp.intellij.util.ActionUtil;
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BufferCreateAction extends AnAction {
|
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);
|
CodeMPHandler.create(buffer);
|
||||||
if(!silent) Messages.showInfoMessage(String.format("Created buffer %s!", buffer),
|
if(!silent) ActionUtil.notify(e, "Success",
|
||||||
"Create CodeMP Buffer" );
|
String.format("Created buffer %s!", buffer)
|
||||||
|
);
|
||||||
CodeMP.LOGGER.debug("Created buffer {}!", buffer);
|
CodeMP.LOGGER.debug("Created buffer {}!", buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,11 +25,11 @@ public class BufferCreateAction extends AnAction {
|
||||||
Messages.getQuestionIcon());
|
Messages.getQuestionIcon());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
create(buffer, false);
|
create(e, buffer, false);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Messages.showErrorDialog(String.format(
|
ActionUtil.notifyError(e, String.format(
|
||||||
"Failed to create buffer with name %s: %s!",
|
"Failed to create buffer with name %s!",
|
||||||
buffer, ex.getMessage()), "Create CodeMP Buffer");
|
buffer), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,9 @@ public class BufferCreateWithContentAction extends AnAction {
|
||||||
public static void createWithContent(AnActionEvent event, String buffer, boolean silent) throws Exception {
|
public static void createWithContent(AnActionEvent event, String buffer, boolean silent) throws Exception {
|
||||||
String content = ActionUtil.getCurrentEditor(event).getDocument().getText();
|
String content = ActionUtil.getCurrentEditor(event).getDocument().getText();
|
||||||
CodeMPHandler.createWithContent(buffer, content);
|
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);
|
CodeMP.LOGGER.debug("Created buffer {} with content {}!", buffer, content);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,9 +28,9 @@ public class BufferCreateWithContentAction extends AnAction {
|
||||||
try {
|
try {
|
||||||
createWithContent(e, buffer, false);
|
createWithContent(e, buffer, false);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Messages.showErrorDialog(String.format(
|
ActionUtil.notifyError(e, String.format(
|
||||||
"Failed to create buffer with name %s: %s!",
|
"Failed to create buffer with name %s!",
|
||||||
buffer, ex.getMessage()), "Create CodeMP Buffer with Content");
|
buffer), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,14 @@ import com.codemp.intellij.exceptions.ide.BufferDetachException;
|
||||||
import com.codemp.intellij.jni.CodeMPHandler;
|
import com.codemp.intellij.jni.CodeMPHandler;
|
||||||
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
import com.codemp.intellij.task.BufferEventAwaiterTask;
|
||||||
import com.codemp.intellij.task.TaskManager;
|
import com.codemp.intellij.task.TaskManager;
|
||||||
|
import com.codemp.intellij.util.ActionUtil;
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class BufferDetachAction extends AnAction {
|
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);
|
boolean res = CodeMPHandler.detach(buffer);
|
||||||
if(!res) throw new BufferDetachException(buffer);
|
if(!res) throw new BufferDetachException(buffer);
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ public class BufferDetachAction extends AnAction {
|
||||||
BufferEventAwaiterTask task = TaskManager.getBufferTask();
|
BufferEventAwaiterTask task = TaskManager.getBufferTask();
|
||||||
if(task != null) {
|
if(task != null) {
|
||||||
task.unregisterListener(buffer);
|
task.unregisterListener(buffer);
|
||||||
if(!silent) Messages.showInfoMessage(String.format("Detached from buffer %s!", buffer),
|
if(!silent) ActionUtil.notify(e, "Success",
|
||||||
"Detach from CodeMP Buffer");
|
String.format("Detached from buffer %s!", buffer)
|
||||||
|
);
|
||||||
CodeMP.LOGGER.debug("Detached from buffer {}!", buffer);
|
CodeMP.LOGGER.debug("Detached from buffer {}!", buffer);
|
||||||
} else {
|
} else {
|
||||||
if(!silent) Messages.showErrorDialog(
|
if(!silent) ActionUtil.notifyError(e, String.format("Failed to detach from %s", buffer),
|
||||||
String.format("Failed to detach from %s: buffer event task was dead!", buffer),
|
"Buffer event task was dead!");
|
||||||
"Detach from CodeMP Buffer");
|
|
||||||
CodeMP.LOGGER.debug("Failed to detach from {}: buffer event task was dead!", buffer);
|
CodeMP.LOGGER.debug("Failed to detach from {}: buffer event task was dead!", buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,11 +39,11 @@ public class BufferDetachAction extends AnAction {
|
||||||
Messages.getQuestionIcon());
|
Messages.getQuestionIcon());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
detach(buffer, false);
|
detach(e, buffer, false);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Messages.showErrorDialog(String.format(
|
ActionUtil.notifyError(e, String.format(
|
||||||
"Failed to detach from buffer with name %s: %s!",
|
"Failed to detach from buffer with name %s!",
|
||||||
buffer, ex.getMessage()), "Detach from CodeMP Buffer");
|
buffer), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import com.codemp.intellij.util.ActionUtil;
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.editor.EditorFactory;
|
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 com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public static void join(AnActionEvent e, String workspace, boolean silent) throws Exception {
|
||||||
CursorHandler cursorHandler = CodeMPHandler.join(workspace);
|
CursorHandler cursorHandler = CodeMPHandler.join(workspace);
|
||||||
|
|
||||||
if(!silent) Messages.showInfoMessage(String.format("Joined workspace %s!", workspace), "CodeMP");
|
if(!silent) ActionUtil.notify(e,
|
||||||
else CodeMP.LOGGER.debug("Joined workspace {}!", workspace);
|
"Success", String.format("Joined workspace %s!", workspace));
|
||||||
|
CodeMP.LOGGER.debug("Joined workspace {}!", workspace);
|
||||||
|
|
||||||
CursorEventAwaiterTask task = TaskManager
|
CursorEventAwaiterTask task = TaskManager
|
||||||
.getOrCreateCursorTask(ActionUtil.getCurrentProject(e), cursorHandler);
|
.getOrCreateCursorTask(ActionUtil.getCurrentProject(e), cursorHandler);
|
||||||
|
@ -40,11 +39,9 @@ public class WorkspaceJoinAction extends AnAction {
|
||||||
try {
|
try {
|
||||||
join(e, session, false);
|
join(e, session, false);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Messages.showErrorDialog(String.format(
|
ActionUtil.notifyError(e, String.format(
|
||||||
"Failed to join session %s: %s!",
|
"Failed to join session %s!",
|
||||||
session,
|
session), ex);
|
||||||
ex.getMessage()),
|
|
||||||
"CodeMP Join");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,28 +2,26 @@ package com.codemp.intellij.actions.workspace;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.jni.CodeMPHandler;
|
import com.codemp.intellij.jni.CodeMPHandler;
|
||||||
|
import com.codemp.intellij.util.ActionUtil;
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class WorkspaceLeaveAction extends AnAction {
|
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();
|
CodeMPHandler.leaveWorkspace();
|
||||||
|
|
||||||
if(!silent) Messages.showInfoMessage("Left workspace!",
|
if(!silent) ActionUtil.notify(e, "Success", "Left workspace");
|
||||||
"Detach from CodeMP Buffer" );
|
|
||||||
CodeMP.LOGGER.debug("Left workspace!");
|
CodeMP.LOGGER.debug("Left workspace!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||||
try {
|
try {
|
||||||
leave(false);
|
leave(e, false);
|
||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
Messages.showErrorDialog(String.format(
|
ActionUtil.notifyError(e, "Failed to leave workspace!", ex);
|
||||||
"Failed to leave workspace: %s!",
|
|
||||||
ex.getMessage()), "Leave CodeMP Workspace");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.codemp.intellij.listeners;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.jni.BufferHandler;
|
import com.codemp.intellij.jni.BufferHandler;
|
||||||
import com.codemp.intellij.jni.CodeMPHandler;
|
|
||||||
import com.intellij.openapi.command.CommandProcessor;
|
import com.intellij.openapi.command.CommandProcessor;
|
||||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||||
import com.intellij.openapi.editor.event.DocumentListener;
|
import com.intellij.openapi.editor.event.DocumentListener;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.codemp.intellij.listeners;
|
package com.codemp.intellij.listeners;
|
||||||
|
|
||||||
import com.codemp.intellij.CodeMP;
|
import com.codemp.intellij.CodeMP;
|
||||||
import com.codemp.intellij.jni.CodeMPHandler;
|
|
||||||
import com.codemp.intellij.jni.CursorHandler;
|
import com.codemp.intellij.jni.CursorHandler;
|
||||||
import com.intellij.openapi.editor.Caret;
|
import com.intellij.openapi.editor.Caret;
|
||||||
import com.intellij.openapi.editor.VisualPosition;
|
import com.intellij.openapi.editor.VisualPosition;
|
||||||
|
|
|
@ -18,7 +18,6 @@ import com.intellij.openapi.util.Disposer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.codemp.intellij.util;
|
package com.codemp.intellij.util;
|
||||||
|
|
||||||
import com.codemp.intellij.exceptions.ide.BadActionEventStateException;
|
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.actionSystem.AnActionEvent;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||||
|
@ -21,4 +24,22 @@ public class ActionUtil {
|
||||||
throw new BadActionEventStateException("Editor was null!");
|
throw new BadActionEventStateException("Editor was null!");
|
||||||
return editor;
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@
|
||||||
</actions>
|
</actions>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
<!-- Extension points defined by the plugin.
|
<notificationGroup id="CodeMP" displayType="BALLOON"/>
|
||||||
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|
Loading…
Reference in a new issue