1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-07-31 03:59:07 +02:00

Convert RegistersHandler to kotlin

This commit is contained in:
Alex Plate 2019-02-22 16:26:37 +03:00
parent 0f835fd3ba
commit a1236d855b
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
2 changed files with 41 additions and 60 deletions
src/com/maddyhome/idea/vim/ex/handler

View File

@ -1,60 +0,0 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2019 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.ex.handler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.common.Register;
import com.maddyhome.idea.vim.ex.*;
import com.maddyhome.idea.vim.helper.StringHelper;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
*
*/
public class RegistersHandler extends CommandHandler {
public RegistersHandler() {
super(new CommandName[]{
new CommandName("di", "splay"),
new CommandName("reg", "isters")
}, ARGUMENT_OPTIONAL);
}
public boolean execute(@NotNull final Editor editor, @NotNull DataContext context, @NotNull ExCommand cmd) throws ExException {
List<Register> registers = VimPlugin.getRegister().getRegisters();
StringBuilder text = new StringBuilder();
text.append("--- Registers ---\n");
for (Register reg : registers) {
text.append("\"");
text.append(reg.getName());
text.append(" ");
text.append(StringHelper.toKeyNotation(reg.getKeys()));
text.append("\n");
}
ExOutputModel.getInstance(editor).output(text.toString());
return true;
}
}

View File

@ -0,0 +1,41 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2019 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.ex.handler
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.ex.*
import com.maddyhome.idea.vim.ex.CommandHandler.ARGUMENT_OPTIONAL
import com.maddyhome.idea.vim.helper.StringHelper
class RegistersHandler : CommandHandler(
commands("di[splay]", "reg[isters]"),
ARGUMENT_OPTIONAL
) {
override fun execute(editor: Editor, context: DataContext, cmd: ExCommand): Boolean {
val regs = VimPlugin.getRegister().registers.joinToString("\n", prefix = "--- Registers ---\n") { reg ->
""""${reg.name} ${StringHelper.toKeyNotation(reg.keys)}"""
}
ExOutputModel.getInstance(editor).output(regs)
return true
}
}