Changeset 1050


Ignore:
Timestamp:
Jun 10, 2011, 11:02:52 PM (6 years ago)
Author:
joerg
Message:
 
Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/JLatexEditorJFrame.java

    r1048 r1050  
    6464  public static final File CHANGELOG = new File("CHANGELOG");
    6565
     66  private static final String RECEIVER_PANE_UI = "PaneUI <= ";
     67
    6668  /** Logger. */
    6769  private static Logger logger = Logger.getLogger(JLatexEditorJFrame.class.getName());
     
    273275    editMenu.add(createMenuItem("Paste", "paste", null));
    274276    editMenu.addSeparator();
     277    editMenu.add(createMenuItem("Select All", "select all", null));
     278    editMenu.add(createMenuItem("Select None", "select none", null));
     279    editMenu.addSeparator();
    275280    editMenu.add(createMenuItem("Comment", "comment", 'o'));
    276281    editMenu.add(createMenuItem("Uncomment", "uncomment", 'u'));
     
    352357    helpMenu.add(createMenuItem("About", "about", 'A'));
    353358    helpMenu.add(createMenuItem("Acknowledgements", "acknowledgements", 'K'));
     359
     360    // misc keyboard actions
     361    createShortcut(this, RECEIVER_PANE_UI, "jump left", true);
     362    createShortcut(this, RECEIVER_PANE_UI, "jump right", true);
     363    createShortcut(this, RECEIVER_PANE_UI, "jump to front", true);
     364    createShortcut(this, RECEIVER_PANE_UI, "jump to end", true);
     365    createShortcut(this, RECEIVER_PANE_UI, "move view up", true);
     366    createShortcut(this, RECEIVER_PANE_UI, "move view down", true);
     367    createShortcut(this, RECEIVER_PANE_UI, "remove line", false);
     368    createShortcut(this, RECEIVER_PANE_UI, "remove line before caret", false);
     369    createShortcut(this, RECEIVER_PANE_UI, "remove line behind caret", false);
     370    createShortcut(this, RECEIVER_PANE_UI, "remove word before caret", false);
     371    createShortcut(this, RECEIVER_PANE_UI, "remove word behind caret", false);
     372
     373    // prevent that TabbledPane consumes the "control UP"
     374    Object ancestorMap = UIManager.get("TabbedPane.ancestorInputMap");
     375    if(ancestorMap instanceof InputMap) {
     376      InputMap map = (InputMap) ancestorMap;
     377      map.remove(KeyStroke.getKeyStroke("control UP"));
     378    }
     379
     380    // focus traversal keys
     381    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
     382    focusManager.setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
     383            new HashSet(Arrays.asList(KeyStroke.getKeyStroke(GProperties.getString("shortcut.focus traversal forward")))));
     384    focusManager.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
     385            new HashSet(Arrays.asList(KeyStroke.getKeyStroke(GProperties.getString("shortcut.focus traversal backward")))));
    354386
    355387    // error messages
     
    526558
    527559    return menuItem;
     560  }
     561
     562  /**
     563   * Creates a keyboard shortcut without a menu item.
     564   */
     565  private void createShortcut(ActionListener listener, String receiver, String command, boolean withAndWithoutShift) {
     566    String shorcutString = GProperties.getString("shortcut." + command);
     567    if (shorcutString != null && !shorcutString.equals("")) {
     568      KeyStroke keyStroke = KeyStroke.getKeyStroke(shorcutString);
     569      menuBar.registerKeyboardAction(listener, receiver + command, keyStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
     570
     571      if(withAndWithoutShift) {
     572        keyStroke = KeyStroke.getKeyStroke("shift " + shorcutString);
     573        menuBar.registerKeyboardAction(listener, receiver + command, keyStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
     574      }
     575    }
    528576  }
    529577
     
    11281176    String action = e.getActionCommand();
    11291177
     1178    // forward to paneUI ?
     1179    if (action.startsWith(RECEIVER_PANE_UI)) {
     1180      SourceCodeEditor editor = getActiveEditor();
     1181      editor.getTextPane().getPaneUI().handleCommand(
     1182              action.substring(RECEIVER_PANE_UI.length()),
     1183              (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0);
     1184      return;
     1185    }
     1186
    11301187    // timer
    11311188    if (action.equals("timer")) {
     
    12251282      getActiveEditor().paste();
    12261283    } else
     1284    // select all
     1285    if (action.equals("select all")) {
     1286      SCEPane pane = getActiveEditor().getTextPane();
     1287      SCEDocument document = pane.getDocument();
     1288      document.setSelectionRange(document.createDocumentPosition(0,0), document.createDocumentPosition(document.getRowsCount()-1, 0));
     1289      pane.repaint();
     1290    } else
     1291    if (action.equals("select none")) {
     1292      SCEPane pane = getActiveEditor().getTextPane();
     1293      SCEDocument document = pane.getDocument();
     1294      document.setSelectionRange(null, null);
     1295      pane.getCaret().setSelectionMark();
     1296      pane.repaint();
     1297    } else
    12271298
    12281299    // lineComment
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r1025 r1050  
    164164    properties.addEntry(new Def("shortcut.copy", SHORTCUT, "control C"));
    165165    properties.addEntry(new Def("shortcut.paste", SHORTCUT, "control V"));
     166    properties.addEntry(new Def("shortcut.select all", SHORTCUT, "control A"));
     167    properties.addEntry(new Def("shortcut.select none", SHORTCUT, "control shift A"));
    166168    properties.addEntry(new Def("shortcut.comment", SHORTCUT, "control D"));
    167169    properties.addEntry(new Def("shortcut.uncomment", SHORTCUT, "control shift D"));
     
    201203    properties.addEntry(new Def("shortcut.about", SHORTCUT, ""));
    202204
     205    properties.addEntry(new Comment(" Editor"));
     206    properties.addEntry(new Def("shortcut.jump left", SHORTCUT, "control LEFT"));
     207    properties.addEntry(new Def("shortcut.jump right", SHORTCUT, "control RIGHT"));
     208    properties.addEntry(new Def("shortcut.jump to front", SHORTCUT, "control BEGIN"));
     209    properties.addEntry(new Def("shortcut.jump to end", SHORTCUT, "control END"));
     210    properties.addEntry(new Def("shortcut.move view up", SHORTCUT, "alt UP"));
     211    properties.addEntry(new Def("shortcut.move view down", SHORTCUT, "alt DOWN"));
     212    properties.addEntry(new Def("shortcut.remove line", SHORTCUT, "control Y"));
     213    properties.addEntry(new Def("shortcut.remove line before caret", SHORTCUT, "control U"));
     214    properties.addEntry(new Def("shortcut.remove line behind caret", SHORTCUT, "control K"));
     215    properties.addEntry(new Def("shortcut.remove word before caret", SHORTCUT, "control BACKSPACE"));
     216    properties.addEntry(new Def("shortcut.remove word behind caret", SHORTCUT, "control DELETE"));
     217
     218    properties.addEntry(new Comment(" Focus Traversal"));
     219    properties.addEntry(new Def("shortcut.focus traversal forward", SHORTCUT, "TAB"));
     220    properties.addEntry(new Def("shortcut.focus traversal backward", SHORTCUT, "shift TAB"));
     221
    203222    properties.addEntry(new Comment("\n## Compiler settings"));
    204223    properties.addEntry(new Comment(" pdflatex"));
  • trunk/src/sce/codehelper/CodeHelperPane.java

    r1048 r1050  
    11package sce.codehelper;
    22
     3import de.endrullis.utils.KeyUtils;
    34import sce.component.*;
    45import util.Tuple;
     
    537538
    538539    // hide code helper on escape or close template
    539     if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
     540    if (KeyUtils.isStopKey(e)) {
    540541      if (isVisible()) {
    541542        // hide code helper
  • trunk/src/sce/codehelper/SCEPopup.java

    r744 r1050  
    11package sce.codehelper;
    22
     3import de.endrullis.utils.KeyUtils;
    34import sce.component.SCEDocument;
    45import sce.component.SCEPane;
     
    162163
    163164    // hide on escape
    164     if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
     165    if (KeyUtils.isStopKey(e)) {
    165166      // hide popup
    166167      setVisible(false);
  • trunk/src/sce/component/SCEPaneUI.java

    r1049 r1050  
    155155    // is control down?
    156156    if (e.isControlDown() && !e.isAltDown()) {
    157       keyControlDown(e);
    158157      if (!isModifierKey(keyCode)) return;
    159158    }
     
    361360  }
    362361
    363   private void keyControlDown(KeyEvent e) {
     362  public void handleCommand(String command, boolean isShiftDown) {
    364363    // caret movement
    365     if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN) {
    366       int jump = e.getKeyCode() == KeyEvent.VK_UP ? -1 : 1;
     364    boolean viewUp = command.equals("move view up");
     365    boolean viewDown = command.equals("move view down");
     366    if (viewUp || viewDown) {
     367      int jump = viewUp ? -1 : 1;
    367368      Rectangle visibleRect = scrollVisibleRect(jump);
    368369
     
    370371      int maxRow = (visibleRect.y + visibleRect.height) / pane.getLineHeight();
    371372
    372       if (caret.getRow() < minRow + 2) caret.move(SCECaret.DIRECTION_DOWN, e.isShiftDown());
    373       if (caret.getRow() > maxRow - 2) caret.move(SCECaret.DIRECTION_UP, e.isShiftDown());
    374       e.consume();
    375     }
    376     if (e.getKeyCode() == KeyEvent.VK_LEFT) {
    377       caret.moveTo(pane.findSplitterPosition(caret.getRow(), caret.getColumn(), -1), e.isShiftDown());
    378       e.consume();
    379     }
    380     if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
    381       caret.moveTo(pane.findSplitterPosition(caret.getRow(), caret.getColumn(), 1), e.isShiftDown());
    382       e.consume();
    383     }
    384     if (e.getKeyCode() == KeyEvent.VK_HOME) {
    385       caret.moveTo(0, 0, e.isShiftDown());
    386       e.consume();
    387     }
    388     if (e.getKeyCode() == KeyEvent.VK_END) {
     373      if (caret.getRow() < minRow + 2) caret.move(SCECaret.DIRECTION_DOWN, isShiftDown);
     374      if (caret.getRow() > maxRow - 2) caret.move(SCECaret.DIRECTION_UP, isShiftDown);
     375    }
     376
     377    if (command.equals("jump left")) {
     378      caret.moveTo(pane.findSplitterPosition(caret.getRow(), caret.getColumn(), -1), isShiftDown);
     379    }
     380    if (command.equals("jump right")) {
     381      caret.moveTo(pane.findSplitterPosition(caret.getRow(), caret.getColumn(), 1), isShiftDown);
     382    }
     383    if (command.equals("jump to front")) {
     384      caret.moveTo(0, 0, isShiftDown);
     385    }
     386    if (command.equals("jump to end")) {
    389387      int row = document.getRowsCount() - 1;
    390388      int column = document.getRowLength(row);
    391       caret.moveTo(row, column, e.isShiftDown());
    392       e.consume();
    393     }
    394 
    395     if (!e.isShiftDown()) {
    396       // control+Y
    397       if (e.getKeyCode() == KeyEvent.VK_Y) {
    398         if (caret.getRow() < document.getRowsCount() - 1) {
    399           document.remove(caret.getRow(), 0, caret.getRow() + 1, 0);
    400         } else if (caret.getRow() > 0) {
    401           document.remove(caret.getRow() - 1, document.getRowLength(caret.getRow() - 1), caret.getRow(), document.getRowLength(caret.getRow()));
    402           caret.moveTo(caret.getRow() - 1, caret.getColumn(), false);
    403         } else {
    404           document.remove(0, 0, 0, document.getRowLength(0));
    405           caret.moveTo(0, 0, false);
    406         }
    407         e.consume();
    408       }
    409 
    410       // control+U
    411       if (e.getKeyCode() == KeyEvent.VK_U) {
    412         document.remove(caret.getRow(), 0, caret.getRow(), caret.getColumn());
    413         e.consume();
    414       }
    415       // control+K
    416       if (e.getKeyCode() == KeyEvent.VK_K) {
    417         document.remove(caret.getRow(), caret.getColumn(), caret.getRow(), document.getRowLength(caret.getRow()));
    418         e.consume();
    419       }
    420       // control+backspace
    421       if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
    422         document.remove(pane.findSplitterPosition(caret.getRow(), caret.getColumn(), -1), caret);
    423         clearSelection();
    424         e.consume();
    425       }
    426       // control+delete
    427       if (e.getKeyCode() == KeyEvent.VK_DELETE) {
    428         document.remove(caret, pane.findSplitterPosition(caret.getRow(), caret.getColumn(), 1));
    429         clearSelection();
    430         e.consume();
    431       }
    432     }
     389      caret.moveTo(row, column, isShiftDown);
     390    }
     391
     392    if (command.equals("remove line")) { // control+Y
     393      if (caret.getRow() < document.getRowsCount() - 1) {
     394        document.remove(caret.getRow(), 0, caret.getRow() + 1, 0);
     395      } else if (caret.getRow() > 0) {
     396        document.remove(caret.getRow() - 1, document.getRowLength(caret.getRow() - 1), caret.getRow(), document.getRowLength(caret.getRow()));
     397        caret.moveTo(caret.getRow() - 1, caret.getColumn(), false);
     398      } else {
     399        document.remove(0, 0, 0, document.getRowLength(0));
     400        caret.moveTo(0, 0, false);
     401      }
     402    }
     403
     404    if (command.equals("remove line before caret")) { // control+U
     405      document.remove(caret.getRow(), 0, caret.getRow(), caret.getColumn());
     406    }
     407    if (command.equals("remove line behind caret")) { // control+K
     408      document.remove(caret.getRow(), caret.getColumn(), caret.getRow(), document.getRowLength(caret.getRow()));
     409    }
     410    if (command.equals("remove word before caret")) { // control+backspace
     411      document.remove(pane.findSplitterPosition(caret.getRow(), caret.getColumn(), -1), caret);
     412      clearSelection();
     413    }
     414    if (command.equals("remove word behind caret")) { // control+delete
     415      document.remove(caret, pane.findSplitterPosition(caret.getRow(), caret.getColumn(), 1));
     416      clearSelection();
     417    }
    433418  }
    434419
  • trunk/src/sce/component/SCESearch.java

    r1048 r1050  
    11package sce.component;
    22
     3import de.endrullis.utils.KeyUtils;
    34import jlatexeditor.gproperties.GProperties;
    45
     
    384385  public void keyPressed(KeyEvent e) {
    385386    if (isVisible()) {
    386       if (e.getKeyCode() == KeyEvent.VK_ESCAPE && e.getModifiers() == 0) {
     387      if (KeyUtils.isStopKey(e)) {
    387388        setVisible(false);
    388389        e.consume();
  • trunk/src/sce/quickhelp/QuickHelpPane.java

    r744 r1050  
    11package sce.quickhelp;
    22
     3import de.endrullis.utils.KeyUtils;
    34import sce.component.SCECaret;
    45import sce.component.SCEDocument;
     
    139140
    140141    // hide on escape
    141     if (popup.isVisible() && e.getKeyCode() == KeyEvent.VK_ESCAPE) {
     142    if (popup.isVisible() && KeyUtils.isStopKey(e)) {
    142143      setVisible(false);
    143144      getParent().requestFocus();
  • trunk/src/util/filechooser/SCEFileChooser.java

    r1047 r1050  
    11package util.filechooser;
    22
     3import de.endrullis.utils.KeyUtils;
    34import util.GraphicsUtil;
    45
     
    1415import java.awt.event.*;
    1516import java.io.File;
    16 import java.nio.charset.Charset;
    1717import java.text.SimpleDateFormat;
    1818import java.util.*;
     
    467467                    || keyEvent.getKeyChar() == KeyEvent.VK_DELETE;
    468468
    469     boolean stop =
    470             keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE;
     469    boolean stop = KeyUtils.isStopKey(keyEvent);
    471470
    472471    if(stop && filePrefix.length() == 0 && (time - filePrefixReset) > 1000) {
Note: See TracChangeset for help on using the changeset viewer.