Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/maddyhome/idea/vim/VimTypedActionHandler.java


1   package com.maddyhome.idea.vim;
2   
3   /*
4    * IdeaVim - A Vim emulator plugin for IntelliJ Idea
5    * Copyright (C) 2003 Rick Maddy
6    *
7    * This program is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation; either version 2
10   * of the License, or (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20   */
21  
22  import com.intellij.openapi.actionSystem.DataContext;
23  import com.intellij.openapi.diagnostic.Logger;
24  import com.intellij.openapi.editor.Editor;
25  import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
26  import javax.swing.KeyStroke;
27  
28  /**
29   * This handler accepts all regular keystrokes and passes them on to the Vim Key handler
30   */
31  public class VimTypedActionHandler implements TypedActionHandler
32  {
33      /**
34       * Creates an instance of the key handler
35       * @param origHandler The original key handler
36       */
37      public VimTypedActionHandler(TypedActionHandler origHandler)
38      {
39          this.origHandler = origHandler;
40          handler = KeyHandler.getInstance();
41          handler.setOriginalHandler(origHandler);
42      }
43  
44      /**
45       * Gives the original key handler
46       * @return The original key handler
47       */
48      public TypedActionHandler getOriginalTypedHandler()
49      {
50          return origHandler;
51      }
52  
53      /**
54       * All characters typed into an editor will get sent to this handler. Only letters, numbers, and punctuation
55       * are sent here. Keys like Tab, Enter, Home, Backspace, etc. and all Control-Letter etc. argType keys are not
56       * sent by Idea to this handler.
57       * @param editor The editor the character was typed into
58       * @param charTyped The character that was typed
59       * @param context The data context
60       */
61      public void execute(Editor editor, char charTyped, DataContext context)
62      {
63          // If the plugin is disabled we simply resend the character to the original handler
64          if (!VimPlugin.isEnabled())
65          {
66              origHandler.execute(editor, charTyped, context);
67              return;
68          }
69  
70          try
71          {
72              handler.handleKey(editor, KeyStroke.getKeyStroke(charTyped), context);
73          }
74          catch (Throwable e)
75          {
76              logger.error(e);
77          }
78      }
79  
80      private TypedActionHandler origHandler;
81      private KeyHandler handler;
82  
83      private static Logger logger = Logger.getInstance(VimTypedActionHandler.class.getName());
84  }