mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-02-28 11:45:59 +01:00
Convert macro group to kotlin
This commit is contained in:
parent
4bf5f6dcc1
commit
74dd307318
@ -5,71 +5,69 @@
|
||||
* license that can be found in the LICENSE.txt file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package com.maddyhome.idea.vim.group
|
||||
|
||||
package com.maddyhome.idea.vim.group;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.util.PotemkinProgress;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.maddyhome.idea.vim.KeyHandler;
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext;
|
||||
import com.maddyhome.idea.vim.api.VimEditor;
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper;
|
||||
import com.maddyhome.idea.vim.key.KeyStack;
|
||||
import com.maddyhome.idea.vim.macro.VimMacroBase;
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.progress.util.PotemkinProgress
|
||||
import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance
|
||||
import com.maddyhome.idea.vim.api.ExecutionContext
|
||||
import com.maddyhome.idea.vim.api.VimEditor
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper.message
|
||||
import com.maddyhome.idea.vim.macro.VimMacroBase
|
||||
import com.maddyhome.idea.vim.newapi.IjVimEditor
|
||||
|
||||
/**
|
||||
* Used to handle playback of macros
|
||||
*/
|
||||
public class MacroGroup extends VimMacroBase {
|
||||
private static final Logger logger = Logger.getInstance(MacroGroup.class.getName());
|
||||
|
||||
class MacroGroup : VimMacroBase() {
|
||||
/**
|
||||
* This puts a single keystroke at the end of the event queue for playback
|
||||
*/
|
||||
@Override
|
||||
public void playbackKeys(@NotNull final VimEditor editor,
|
||||
@NotNull final ExecutionContext context, final int cnt,
|
||||
final int total) {
|
||||
Project project = ((IjVimEditor)editor).getEditor().getProject();
|
||||
KeyStack keyStack = KeyHandler.getInstance().getKeyStack();
|
||||
override fun playbackKeys(
|
||||
editor: VimEditor,
|
||||
context: ExecutionContext,
|
||||
cnt: Int,
|
||||
total: Int,
|
||||
) {
|
||||
val project = (editor as IjVimEditor).editor.project
|
||||
val keyStack = getInstance().keyStack
|
||||
if (!keyStack.hasStroke() || cnt >= total) {
|
||||
logger.debug("done");
|
||||
keyStack.removeFirst();
|
||||
|
||||
return;
|
||||
logger.debug("done")
|
||||
keyStack.removeFirst()
|
||||
return
|
||||
}
|
||||
val potemkinProgress = PotemkinProgress(
|
||||
message("progress.title.macro.execution"), project, null,
|
||||
message("stop")
|
||||
)
|
||||
potemkinProgress.isIndeterminate = false
|
||||
potemkinProgress.fraction = 0.0
|
||||
potemkinProgress.runInSwingThread {
|
||||
|
||||
PotemkinProgress potemkinProgress =
|
||||
new PotemkinProgress(MessageHelper.message("progress.title.macro.execution"), project, null,
|
||||
MessageHelper.message("stop"));
|
||||
potemkinProgress.setIndeterminate(false);
|
||||
potemkinProgress.setFraction(0);
|
||||
potemkinProgress.runInSwingThread(() -> {
|
||||
// Handle one keystroke then queue up the next key
|
||||
for (int i = 0; i < total; ++i) {
|
||||
potemkinProgress.setFraction((double)(i + 1) / total);
|
||||
for (i in 0 until total) {
|
||||
potemkinProgress.fraction = (i + 1).toDouble() / total
|
||||
while (keyStack.hasStroke()) {
|
||||
KeyStroke key = keyStack.feedStroke();
|
||||
val key = keyStack.feedStroke()
|
||||
try {
|
||||
potemkinProgress.checkCanceled();
|
||||
potemkinProgress.checkCanceled()
|
||||
} catch (e: ProcessCanceledException) {
|
||||
return@runInSwingThread
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
return;
|
||||
}
|
||||
ProgressManager.getInstance().executeNonCancelableSection(() -> {
|
||||
KeyHandler.getInstance().handleKey(editor, key, context);
|
||||
});
|
||||
ProgressManager.getInstance()
|
||||
.executeNonCancelableSection { getInstance().handleKey(editor, key, context) }
|
||||
}
|
||||
keyStack.resetFirst();
|
||||
keyStack.resetFirst()
|
||||
}
|
||||
keyStack.removeFirst();
|
||||
});
|
||||
keyStack.removeFirst()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = Logger.getInstance(
|
||||
MacroGroup::class.java.name
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user