X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTEditorWindow.java;h=d78185c32f3096cd615f345d9731751d285fc3b6;hb=12b90437b5f22c2ae6e9b9b14c3b62b60f6143e5;hp=4a638fc8d0c2b3a3b293f787bca18f224d4aed38;hpb=615a0d99fd0aa4437116dd083147f9150d5e6527;p=fanfix.git diff --git a/src/jexer/TEditorWindow.java b/src/jexer/TEditorWindow.java index 4a638fc..d78185c 100644 --- a/src/jexer/TEditorWindow.java +++ b/src/jexer/TEditorWindow.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -73,6 +73,17 @@ public class TEditorWindow extends TScrollableWindow { */ private String filename = ""; + /** + * If true, hide the mouse after typing a keystroke. + */ + private boolean hideMouseWhenTyping = true; + + /** + * If true, the mouse should not be displayed because a keystroke was + * typed. + */ + private boolean typingHidMouse = false; + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -86,7 +97,7 @@ public class TEditorWindow extends TScrollableWindow { public TEditorWindow(final TApplication parent, final String title) { super(parent, title, 0, 0, parent.getScreen().getWidth(), - parent.getScreen().getHeight() - 2, RESIZABLE); + parent.getDesktopBottom() - parent.getDesktopTop(), RESIZABLE); editField = addEditor("", 0, 0, getWidth() - 2, getHeight() - 2); setupAfterEditor(); @@ -103,7 +114,7 @@ public class TEditorWindow extends TScrollableWindow { final String contents) { super(parent, title, 0, 0, parent.getScreen().getWidth(), - parent.getScreen().getHeight() - 2, RESIZABLE); + parent.getDesktopBottom() - parent.getDesktopTop(), RESIZABLE); filename = title; editField = addEditor(contents, 0, 0, getWidth() - 2, getHeight() - 2); @@ -121,7 +132,7 @@ public class TEditorWindow extends TScrollableWindow { final File file) throws IOException { super(parent, file.getName(), 0, 0, parent.getScreen().getWidth(), - parent.getScreen().getHeight() - 2, RESIZABLE); + parent.getDesktopBottom() - parent.getDesktopTop(), RESIZABLE); filename = file.getName(); String contents = readFileData(file); @@ -173,6 +184,10 @@ public class TEditorWindow extends TScrollableWindow { // Use TWidget's code to pass the event to the children. super.onMouseDown(mouse); + if (hideMouseWhenTyping) { + typingHidMouse = false; + } + if (mouseOnEditor(mouse)) { // The editor might have changed, update the scollbars. setBottomValue(editField.getMaximumRowNumber()); @@ -197,12 +212,19 @@ public class TEditorWindow extends TScrollableWindow { // Use TWidget's code to pass the event to the children. super.onMouseUp(mouse); + if (hideMouseWhenTyping) { + typingHidMouse = false; + } + if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) { // Clicked on vertical scrollbar editField.setVisibleRowNumber(getVerticalValue()); } - - // TODO: horizontal scrolling + if (mouse.isMouse1() && mouseOnHorizontalScroller(mouse)) { + // Clicked on horizontal scrollbar + editField.setVisibleColumnNumber(getHorizontalValue()); + setHorizontalValue(editField.getVisibleColumnNumber()); + } } /** @@ -215,6 +237,10 @@ public class TEditorWindow extends TScrollableWindow { // Use TWidget's code to pass the event to the children. super.onMouseMotion(mouse); + if (hideMouseWhenTyping) { + typingHidMouse = false; + } + if (mouseOnEditor(mouse) && mouse.isMouse1()) { // The editor might have changed, update the scollbars. setBottomValue(editField.getMaximumRowNumber()); @@ -226,8 +252,11 @@ public class TEditorWindow extends TScrollableWindow { // Clicked/dragged on vertical scrollbar editField.setVisibleRowNumber(getVerticalValue()); } - - // TODO: horizontal scrolling + if (mouse.isMouse1() && mouseOnHorizontalScroller(mouse)) { + // Clicked/dragged on horizontal scrollbar + editField.setVisibleColumnNumber(getHorizontalValue()); + setHorizontalValue(editField.getVisibleColumnNumber()); + } } } @@ -239,6 +268,10 @@ public class TEditorWindow extends TScrollableWindow { */ @Override public void onKeypress(final TKeypressEvent keypress) { + if (hideMouseWhenTyping) { + typingHidMouse = true; + } + // Use TWidget's code to pass the event to the children. super.onKeypress(keypress); @@ -318,6 +351,18 @@ public class TEditorWindow extends TScrollableWindow { super.onCommand(command); } + /** + * Returns true if this window does not want the application-wide mouse + * cursor drawn over it. + * + * @return true if this window does not want the application-wide mouse + * cursor drawn over it + */ + @Override + public boolean hasHiddenMouse() { + return (super.hasHiddenMouse() || typingHidMouse); + } + // ------------------------------------------------------------------------ // TEditorWindow ---------------------------------------------------------- // ------------------------------------------------------------------------ @@ -344,6 +389,13 @@ public class TEditorWindow extends TScrollableWindow { i18n.getString("statusBarOpen")); statusBar.addShortcutKeypress(kbF10, cmMenu, i18n.getString("statusBarMenu")); + + // Hide mouse when typing option + if (System.getProperty("jexer.TEditor.hideMouseWhenTyping", + "true").equals("false")) { + + hideMouseWhenTyping = false; + } } /** @@ -386,7 +438,7 @@ public class TEditorWindow extends TScrollableWindow { * @param mouse a mouse-based event * @return whether or not the mouse is on the editor */ - private final boolean mouseOnEditor(final TMouseEvent mouse) { + private boolean mouseOnEditor(final TMouseEvent mouse) { if ((mouse.getAbsoluteX() >= getAbsoluteX() + 1) && (mouse.getAbsoluteX() < getAbsoluteX() + getWidth() - 1) && (mouse.getAbsoluteY() >= getAbsoluteY() + 1)