From 432f98cb3f2270a92400fe2cce31063d0fdafa0b Mon Sep 17 00:00:00 2001 From: Andrey Cizov Date: Wed, 6 Feb 2019 23:33:31 +0000 Subject: [PATCH] initial --- .gitignore | 4 + README.md | 20 +++++ resources/META-INF/plugin.xml | 35 ++++++++ .../partialnav/PartialNavConfigurable.java | 54 ++++++++++++ .../PartialNavConfigurableForm.form | 88 +++++++++++++++++++ .../partialnav/PartialPageDownAction.java | 38 ++++++++ .../partialnav/PartialPageNavHelper.java | 37 ++++++++ .../partialnav/PartialPageUpAction.java | 38 ++++++++ 8 files changed, 314 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 resources/META-INF/plugin.xml create mode 100644 src/com/andreycizov/partialnav/PartialNavConfigurable.java create mode 100644 src/com/andreycizov/partialnav/PartialNavConfigurableForm.form create mode 100644 src/com/andreycizov/partialnav/PartialPageDownAction.java create mode 100644 src/com/andreycizov/partialnav/PartialPageNavHelper.java create mode 100644 src/com/andreycizov/partialnav/PartialPageUpAction.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..12caeb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +*.iml +out/ +*.jar diff --git a/README.md b/README.md new file mode 100644 index 0000000..2c172bf --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# Partial Navigation + +A plugin that allows one to set how many multiples of the screen each PageDown/PageUp button push scrolls. + +Idea stolen from here: https://stackoverflow.com/questions/27610249/intellij-idea-control-page-up-page-down-scroll-size + +## License + +`Partial Navigation` is licensed under either of + + * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in Partial Navigation by you, as defined in the Apache-2.0 license, shall be +dual licensed as above, without any additional terms or conditions. \ No newline at end of file diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml new file mode 100644 index 0000000..1e87a1c --- /dev/null +++ b/resources/META-INF/plugin.xml @@ -0,0 +1,35 @@ + + com.andreycizov.partialnav + Partial Navigation + 1.0 + Andrey Cizov + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/andreycizov/partialnav/PartialNavConfigurable.java b/src/com/andreycizov/partialnav/PartialNavConfigurable.java new file mode 100644 index 0000000..5257857 --- /dev/null +++ b/src/com/andreycizov/partialnav/PartialNavConfigurable.java @@ -0,0 +1,54 @@ +package com.andreycizov.partialnav; + +import com.intellij.ide.util.PropertiesComponent; +import com.intellij.openapi.options.Configurable; +import com.intellij.openapi.options.ConfigurationException; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class PartialNavConfigurable implements Configurable { + private JPanel panelRoot; + private JComboBox comboPageUpMult; + private JComboBox comboPageDownMult; + + @Nls(capitalization = Nls.Capitalization.Title) + @Override + public String getDisplayName() { + return "Partial Navigation"; + } + + public boolean isModified() { + return true; + } + + @Nullable + @Override + public JComponent createComponent() { + float a = PropertiesComponent.getInstance().getFloat(PartialPageUpAction.propertyName, PartialPageUpAction.propertyDefault); + float b = PropertiesComponent.getInstance().getFloat(PartialPageDownAction.propertyName, PartialPageDownAction.propertyDefault); + comboPageUpMult.setSelectedItem(Float.toString(a)); + comboPageDownMult.setSelectedItem(Float.toString(b)); + + return panelRoot; + } + + @Nullable + @Override + public String getHelpTopic() { + return "com.andreycizov.partianav"; + } + + @Override + public void apply() throws ConfigurationException { + String pageUpMult = (String) comboPageUpMult.getSelectedItem(); + String pageDownMult = (String) comboPageDownMult.getSelectedItem(); + + float fPageUpMult = Float.parseFloat(pageUpMult); + float fPageDownMult = Float.parseFloat(pageDownMult); + + PropertiesComponent.getInstance().setValue(PartialPageUpAction.propertyName, fPageUpMult, PartialPageUpAction.propertyDefault); + PropertiesComponent.getInstance().setValue(PartialPageDownAction.propertyName, fPageDownMult, PartialPageDownAction.propertyDefault); + } +} diff --git a/src/com/andreycizov/partialnav/PartialNavConfigurableForm.form b/src/com/andreycizov/partialnav/PartialNavConfigurableForm.form new file mode 100644 index 0000000..3fc2489 --- /dev/null +++ b/src/com/andreycizov/partialnav/PartialNavConfigurableForm.form @@ -0,0 +1,88 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/andreycizov/partialnav/PartialPageDownAction.java b/src/com/andreycizov/partialnav/PartialPageDownAction.java new file mode 100644 index 0000000..f8ba3c7 --- /dev/null +++ b/src/com/andreycizov/partialnav/PartialPageDownAction.java @@ -0,0 +1,38 @@ +package com.andreycizov.partialnav; + +import com.intellij.ide.util.PropertiesComponent; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.actionSystem.EditorAction; +import com.intellij.openapi.editor.actionSystem.EditorActionHandler; +import org.jetbrains.annotations.NotNull; + + +public class PartialPageDownAction extends EditorAction { + static String propertyName = "com.andreycizov.partialpagenav.mult.down"; + static float propertyDefault = (float) 1.0; + + public static class Handler extends EditorActionHandler { + public Handler() { + super(true); + } + + @Override + public void execute(@NotNull Editor editor, DataContext dataContext) { + PartialPageNavHelper.moveCaretPageDown( + editor, + false, + PropertiesComponent.getInstance().getFloat(propertyName, propertyDefault) + ); + } + + @Override + public boolean isEnabled(Editor editor, DataContext dataContext) { + return !editor.isOneLineMode(); + } + } + + public PartialPageDownAction() { + super(new Handler()); + } +} \ No newline at end of file diff --git a/src/com/andreycizov/partialnav/PartialPageNavHelper.java b/src/com/andreycizov/partialnav/PartialPageNavHelper.java new file mode 100644 index 0000000..6fe8f8d --- /dev/null +++ b/src/com/andreycizov/partialnav/PartialPageNavHelper.java @@ -0,0 +1,37 @@ +package com.andreycizov.partialnav; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.util.SystemProperties; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +public class PartialPageNavHelper { + // https://github.com/JetBrains/intellij-community/blob/5107d68347f99578759f406fb128bb0907b820ea/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java#L791 + static Rectangle getVisibleArea(@NotNull Editor editor) { + return SystemProperties.isTrueSmoothScrollingEnabled() ? editor.getScrollingModel().getVisibleAreaOnScrollingFinished() + : editor.getScrollingModel().getVisibleArea(); + } + + // https://github.com/JetBrains/intellij-community/blob/5107d68347f99578759f406fb128bb0907b820ea/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java#L743 + public static void moveCaretPageUp(@NotNull Editor editor, boolean isWithSelection, float mult) { + int lineHeight = editor.getLineHeight(); + Rectangle visibleArea = getVisibleArea(editor); + int linesIncrement = (int) (visibleArea.height / lineHeight * mult); + editor.getScrollingModel().scrollVertically(visibleArea.y - visibleArea.y % lineHeight - linesIncrement * lineHeight); + int lineShift = -linesIncrement; + editor.getCaretModel().moveCaretRelatively(0, lineShift, isWithSelection, editor.isColumnMode(), true); + } + + // https://github.com/JetBrains/intellij-community/blob/5107d68347f99578759f406fb128bb0907b820ea/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java#L752 + public static void moveCaretPageDown(@NotNull Editor editor, boolean isWithSelection, float mult) { + int lineHeight = editor.getLineHeight(); + Rectangle visibleArea = getVisibleArea(editor); + int linesIncrement = (int) (visibleArea.height / lineHeight * mult); + int allowedBottom = ((EditorEx) editor).getContentSize().height - visibleArea.height; + editor.getScrollingModel().scrollVertically( + Math.min(allowedBottom, visibleArea.y - visibleArea.y % lineHeight + linesIncrement * lineHeight)); + editor.getCaretModel().moveCaretRelatively(0, linesIncrement, isWithSelection, editor.isColumnMode(), true); + } +} diff --git a/src/com/andreycizov/partialnav/PartialPageUpAction.java b/src/com/andreycizov/partialnav/PartialPageUpAction.java new file mode 100644 index 0000000..2c298be --- /dev/null +++ b/src/com/andreycizov/partialnav/PartialPageUpAction.java @@ -0,0 +1,38 @@ +package com.andreycizov.partialnav; + +import com.intellij.ide.util.PropertiesComponent; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.actionSystem.EditorAction; +import com.intellij.openapi.editor.actionSystem.EditorActionHandler; +import org.jetbrains.annotations.NotNull; + + +public class PartialPageUpAction extends EditorAction { + static String propertyName = "com.andreycizov.partialpagenav.mult.up"; + static float propertyDefault = (float) 1.0; + + public static class Handler extends EditorActionHandler { + public Handler() { + super(true); + } + + @Override + public void execute(@NotNull Editor editor, DataContext dataContext) { + PartialPageNavHelper.moveCaretPageUp( + editor, + false, + PropertiesComponent.getInstance().getFloat(propertyName, propertyDefault) + ); + } + + @Override + public boolean isEnabled(Editor editor, DataContext dataContext) { + return !editor.isOneLineMode(); + } + } + + public PartialPageUpAction() { + super(new Handler()); + } +} \ No newline at end of file