From 73469e79c735a941cdb140e6364d0257350bd39d Mon Sep 17 00:00:00 2001 From: Ville Hakulinen Date: Thu, 14 Apr 2016 14:29:38 +0300 Subject: [PATCH] Dialog to define the addr for neovim --- src/NeovimDialog.java | 33 +++++++++++++++++++++++++++++ src/NeovimIntellijComplete.java | 37 ++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 src/NeovimDialog.java diff --git a/src/NeovimDialog.java b/src/NeovimDialog.java new file mode 100644 index 0000000..4b32119 --- /dev/null +++ b/src/NeovimDialog.java @@ -0,0 +1,33 @@ +import com.intellij.openapi.ui.DialogWrapper; +import com.siyeh.ig.ui.TextField; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +/** + * Created by ville on 4/14/16. + */ +public class NeovimDialog extends DialogWrapper { + + private JTextField mComponent; + + public NeovimDialog(boolean canBeParent) { + super(canBeParent); + + this.setTitle("Connect to Neovim"); + mComponent = new JTextField(); + mComponent.setToolTipText("Neovim TCP address"); + + this.init(); + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + return mComponent; + } + + public String getAddr() { + return mComponent.getText(); + } +} diff --git a/src/NeovimIntellijComplete.java b/src/NeovimIntellijComplete.java index b44385e..e7bfaae 100644 --- a/src/NeovimIntellijComplete.java +++ b/src/NeovimIntellijComplete.java @@ -86,23 +86,30 @@ public NeovimIntellijComplete() { @Override public void actionPerformed(AnActionEvent e) { - MessagePackRPC.Connection conn; - HostAndPort hp = HostAndPort.fromParts("127.0.0.1", 7650); - try { - conn = new SocketNeovim(hp); - } catch (IOException ex) { - LOG.error("Failed to connect to neovim", ex); - return; - } - mNeovim = Neovim.connectTo(conn); - LOG.info("Connected to neovim"); + NeovimDialog dialog = new NeovimDialog(true); + dialog.show(); - long cid = mNeovim.getChannelId().join(); - mNeovim.commandOutput("let g:intellijID=" + cid); - mNeovim.register(new Updater(mNeovim)); + if (dialog.isOK()) { + LOG.warn(dialog.getAddr()); - mNeovim.sendVimCommand("echo 'Intellij connected.'"); - } + MessagePackRPC.Connection conn; + //HostAndPort hp = HostAndPort.fromParts("127.0.0.1", 7650); + try { + conn = new SocketNeovim(dialog.getAddr()); + } catch (IOException ex) { + LOG.error("Failed to connect to neovim", ex); + return; + } + mNeovim = Neovim.connectTo(conn); + LOG.info("Connected to neovim"); + + long cid = mNeovim.getChannelId().join(); + mNeovim.commandOutput("let g:intellijID=" + cid); + mNeovim.register(new Updater(mNeovim)); + mNeovim.sendVimCommand("echo 'Intellij connected.'"); + } + + } } \ No newline at end of file