1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-01-12 22:42:44 +01:00

Fixed the display of the "more" panel for some ex commands.

This commit is contained in:
rmaddy 2004-05-24 02:00:19 +00:00
parent e2483c4146
commit cecf329832
9 changed files with 233 additions and 157 deletions

View File

@ -10,6 +10,8 @@ Bug Fixes
independent <word motion> commands.
- Fixed <count>cw on strings such as 1/2/3.
- Fixed <count>dw which could delete <count> lines instead.
- The results of the :registers, :marks, and :set commands are now displayed
properly. This "more" window hadn't been working for a while.
0.7.0 to 0.7.1

View File

@ -1,23 +1,22 @@
package com.maddyhome.idea.vim.ex;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003-2004 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.ex;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
@ -45,6 +44,8 @@ public abstract class CommandHandler
public static final int ARGUMENT_FORBIDDEN = 32;
/** Indicates that the command takes a count, not a range - effects default */
public static final int RANGE_IS_COUNT = 64;
/** Indicates that the editor should not get focus back after the command */
public static final int KEEP_FOCUS = 128;
/** Indicates that this is a command that modifies the editor */
public static final int WRITABLE = 256;

View File

@ -1,3 +1,21 @@
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003-2004 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.ex;
import com.intellij.openapi.actionSystem.DataContext;
@ -51,32 +69,17 @@ import com.maddyhome.idea.vim.group.CommandGroups;
import com.maddyhome.idea.vim.helper.MessageHelper;
import com.maddyhome.idea.vim.helper.Msg;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* Maintains a tree of Ex commands based on the required and optional parts of the command names. Parses and
* executes Ex commands entered by the user.
*/
public class CommandParser
{
public static final int RES_EMPTY = 1;
public static final int RES_ERROR = 1;
public static final int RES_READONLY = 1;
public static final int RES_MORE_PANEL = 2;
/**
* There is only one parser.
* @return The singleton instance
@ -171,14 +174,16 @@ public class CommandParser
* @param context The data context
* @param cmd The text entered by the user
* @param count The count entered before the colon
* @return A bitwise collection of flags, if any, from the result of running the command.
* @throws ExException if any part of the command is invalid or unknown
*/
public void processCommand(Editor editor, DataContext context, String cmd, int count) throws ExException
public int processCommand(Editor editor, DataContext context, String cmd, int count) throws ExException
{
// Nothing entered
int result = 0;
if (cmd.length() == 0)
{
return;
return result | RES_EMPTY;
}
// Parse the command
@ -219,7 +224,7 @@ public class CommandParser
if ((handler.getArgFlags() & CommandHandler.WRITABLE) > 0 && !editor.getDocument().isWritable())
{
VimPlugin.indicateError();
return;
return result | RES_READONLY;
}
// Run the command
@ -229,6 +234,13 @@ public class CommandParser
CommandGroups.getInstance().getRegister().storeTextInternal(editor, context, -1, -1, cmd,
Command.FLAG_MOT_CHARACTERWISE, ':', false, false);
}
if ((handler.getArgFlags() & CommandHandler.KEEP_FOCUS) != 0)
{
result |= RES_MORE_PANEL;
}
return result;
}
/**

View File

@ -1,23 +1,22 @@
package com.maddyhome.idea.vim.ex.handler;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003-2004 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.ex.handler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
@ -43,7 +42,7 @@ public class MarksHandler extends CommandHandler
{
super(new CommandName[] {
new CommandName("marks", "")
}, ARGUMENT_OPTIONAL);
}, ARGUMENT_OPTIONAL | KEEP_FOCUS);
}
public boolean execute(Editor editor, DataContext context, ExCommand cmd) throws ExException
@ -82,9 +81,9 @@ public class MarksHandler extends CommandHandler
text.append("\n");
}
MorePanel panel = new MorePanel(editor);
MorePanel panel = MorePanel.getInstance(editor);
panel.setText(text.toString());
panel.setVisible(true);
//panel.setVisible(true);
return true;
}

View File

@ -1,23 +1,22 @@
package com.maddyhome.idea.vim.ex.handler;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003-2004 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.ex.handler;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
@ -31,6 +30,7 @@ import com.maddyhome.idea.vim.helper.StringHelper;
import com.maddyhome.idea.vim.ui.MorePanel;
import java.util.Iterator;
import java.util.List;
import javax.swing.SwingUtilities;
/**
*
@ -42,10 +42,10 @@ public class RegistersHandler extends CommandHandler
super(new CommandName[] {
new CommandName("di", "splay"),
new CommandName("reg", "isters")
}, ARGUMENT_OPTIONAL);
}, ARGUMENT_OPTIONAL | KEEP_FOCUS);
}
public boolean execute(Editor editor, DataContext context, ExCommand cmd) throws ExException
public boolean execute(final Editor editor, DataContext context, ExCommand cmd) throws ExException
{
List registers = CommandGroups.getInstance().getRegister().getRegisters();
@ -62,9 +62,10 @@ public class RegistersHandler extends CommandHandler
text.append("\n");
}
MorePanel panel = new MorePanel(editor);
MorePanel panel = MorePanel.getInstance(editor);
panel.setText(text.toString());
panel.setVisible(true);
//panel.setVisible(true);
return true;
}

View File

@ -1,23 +1,22 @@
package com.maddyhome.idea.vim.group;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003-2004 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.group;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.DataConstants;
@ -28,12 +27,15 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.maddyhome.idea.vim.VimPlugin;
import com.maddyhome.idea.vim.helper.EditorData;
import com.maddyhome.idea.vim.helper.RunnableHelper;
import com.maddyhome.idea.vim.command.Command;
import com.maddyhome.idea.vim.command.CommandState;
import com.maddyhome.idea.vim.ex.CommandParser;
import com.maddyhome.idea.vim.ex.ExException;
import com.maddyhome.idea.vim.key.KeyParser;
import com.maddyhome.idea.vim.ui.ExEntryPanel;
import com.maddyhome.idea.vim.ui.MorePanel;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@ -105,9 +107,10 @@ public class ProcessGroup extends AbstractActionGroup
public boolean processExEntry(final Editor editor, final DataContext context)
{
final ExEntryPanel panel = ExEntryPanel.getInstance();
ExEntryPanel panel = ExEntryPanel.getInstance();
panel.deactivate(false);
boolean res = true;
int flags = 0;
try
{
CommandState.getInstance().popState();
@ -116,7 +119,8 @@ public class ProcessGroup extends AbstractActionGroup
logger.debug("swing=" + SwingUtilities.isEventDispatchThread());
if (panel.getLabel().equals(":"))
{
CommandParser.getInstance().processCommand(editor, context, text, 1);
flags = CommandParser.getInstance().processCommand(editor, context, text, 1);
logger.debug("flags=" + flags);
if (CommandState.getInstance().getMode() == CommandState.MODE_VISUAL)
{
CommandGroups.getInstance().getMotion().exitVisual(editor);
@ -147,14 +151,29 @@ public class ProcessGroup extends AbstractActionGroup
}
finally
{
final int flg = flags;
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
//editor.getContentComponent().requestFocus();
// Reopening the file was the only way I could solve the focus problem introduced in IDEA at
// version 1050.
FileEditorManager.getInstance((Project)context.getData(DataConstants.PROJECT)).openFile(
EditorData.getVirtualFile(editor), true);
// If the result of the ex command is to display the "more" panel, show it here.
if ((flg & CommandParser.RES_MORE_PANEL) != 0)
{
RunnableHelper.runReadCommand((Project)context.getData(DataConstants.PROJECT), new Runnable() {
public void run()
{
MorePanel.getInstance(editor).setVisible(true);
}
});
}
}
});
return res;
}
}

View File

@ -1,8 +1,6 @@
package com.maddyhome.idea.vim.helper;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
* Copyright (C) 2003-2004 Rick Maddy
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -18,6 +16,7 @@ package com.maddyhome.idea.vim.helper;
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.helper;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@ -151,6 +150,7 @@ public class EditorData
if (editors[e].equals(editor))
{
editor.putUserData(PROJECT, projs[p]);
proj = projs[p];
break;
}
}

View File

@ -1,23 +1,22 @@
package com.maddyhome.idea.vim.option;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003-2004 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.option;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@ -430,7 +429,7 @@ public class Options
Collections.sort(extra, new Option.NameSorter());
String pad = " ";
MorePanel panel = new MorePanel(editor);
MorePanel panel = MorePanel.getInstance(editor);
int width = panel.getDisplayWidth();
if (width < 20)
{

View File

@ -1,29 +1,31 @@
package com.maddyhome.idea.vim.ui;
/*
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
* Copyright (C) 2003-2004 Rick Maddy
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.maddyhome.idea.vim.ui;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerAdapter;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.maddyhome.idea.vim.helper.EditorData;
import com.maddyhome.idea.vim.option.Options;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
@ -48,14 +50,32 @@ import javax.swing.SwingUtilities;
*/
public class MorePanel extends JPanel
{
public static MorePanel getInstance(Editor editor)
{
if (instance == null)
{
instance = new MorePanel();
}
instance.setEditor(editor);
return instance;
}
/**
* Creates the panel
* @param editor The editor that this more panel will be displayed over
*/
public MorePanel(Editor editor)
public void setEditor(Editor editor)
{
this.editor = editor;
this.parent = editor.getContentComponent();
}
/**
* Creates the panel
*/
private MorePanel()
{
// Create a text editor for the text and a label for the prompt
BorderLayout layout = new BorderLayout(0, 0);
setLayout(layout);
@ -157,20 +177,22 @@ public class MorePanel extends JPanel
JPanel glass = (JPanel)SwingUtilities.getRootPane(parent).getGlassPane();
glass.setLayout(null);
glass.add(this);
positionPanel();
glass.addComponentListener(resizeListener);
glass.setVisible(true);
positionPanel();
}
super.setVisible(aFlag);
if (aFlag)
{
requestFocus();
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
requestFocus();
text.requestFocus();
focusListener.reset();
parent.addFocusListener(focusListener);
}
});
@ -290,8 +312,11 @@ public class MorePanel extends JPanel
public void run()
{
setVisible(false);
removeKeyListener(moreKeyListener);
//removeKeyListener(moreKeyListener);
parent.removeFocusListener(focusListener);
FileEditorManager.getInstance(EditorData.getProject(editor)).openFile(
EditorData.getVirtualFile(editor), true);
}
});
}
@ -363,12 +388,28 @@ public class MorePanel extends JPanel
this.parent = parent;
}
public void reset()
{
cnt = 0;
}
public void focusGained(FocusEvent e)
{
parent.close();
cnt++;
if (cnt > 1)
{
parent.close();
logger.debug("cnt="+cnt);
}
else
{
// This is a kludge to solve a focus problem I was unable to solve an other way.
parent.requestFocus();
}
}
private MorePanel parent;
private int cnt;
}
public static class MoreEditorChangeListener extends FileEditorManagerAdapter
@ -401,6 +442,7 @@ public class MorePanel extends JPanel
private MorePanel parent;
}
private Editor editor;
private Component parent;
private JLabel label = new JLabel("more");
private JTextArea text = new JTextArea();
@ -415,4 +457,5 @@ public class MorePanel extends JPanel
private static MorePanel currentPanel;
private static Logger logger = Logger.getInstance(MorePanel.class.getName());
private static MorePanel instance;
}