Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
andreycizov committed Feb 6, 2019
0 parents commit 432f98c
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
*.iml
out/
*.jar
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
35 changes: 35 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<idea-plugin>
<id>com.andreycizov.partialnav</id>
<name>Partial Navigation</name>
<version>1.0</version>
<vendor email="[email protected]" url="https://andreycizov.github.io/">Andrey Cizov</vendor>

<description><![CDATA[
Partial PageUp and PageDown navigation plugin
]]></description>

<change-notes><![CDATA[
1.0: build the plugin for the first time
]]>
</change-notes>

<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="173.0"/>

<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<!-- uncomment to enable plugin in all products
<depends>com.intellij.modules.lang</depends>
-->
<extensions defaultExtensionNs="com.intellij">
<applicationConfigurable instance="com.andreycizov.partialnav.PartialNavConfigurable"/>
</extensions>

<actions>
<action id="PartialPageNav.PageUp" class="com.andreycizov.partialnav.PartialPageUpAction"
text="Partial Page _Up" description="Navigate a part of the screen up"/>
<action id="PartialPageNav.PageDown" class="com.andreycizov.partialnav.PartialPageDownAction"
text="Partial Page _Down" description="Navigate a part of the screen down"/>
</actions>

</idea-plugin>
54 changes: 54 additions & 0 deletions src/com/andreycizov/partialnav/PartialNavConfigurable.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
88 changes: 88 additions & 0 deletions src/com/andreycizov/partialnav/PartialNavConfigurableForm.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.andreycizov.partialnav.PartialNavConfigurable">
<grid id="27dc6" binding="panelRoot" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="dd436" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="7b41" class="javax.swing.JComboBox" binding="comboPageDownMult">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="0.1"/>
<item value="0.15"/>
<item value="0.25"/>
<item value="0.5"/>
<item value="0.75"/>
<item value="1"/>
<item value="1.25"/>
<item value="1.5"/>
</model>
</properties>
</component>
<component id="9473a" class="javax.swing.JComboBox" binding="comboPageUpMult">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="0.1"/>
<item value="0.15"/>
<item value="0.25"/>
<item value="0.5"/>
<item value="0.75"/>
<item value="1"/>
<item value="1.25"/>
<item value="1.5"/>
</model>
</properties>
</component>
<component id="6f49d" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Page Up Multiplier:"/>
</properties>
</component>
<component id="98673" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Page Down Multiplier:"/>
</properties>
</component>
<hspacer id="faee8">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="4e73">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<vspacer id="12b41">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
38 changes: 38 additions & 0 deletions src/com/andreycizov/partialnav/PartialPageDownAction.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
37 changes: 37 additions & 0 deletions src/com/andreycizov/partialnav/PartialPageNavHelper.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
38 changes: 38 additions & 0 deletions src/com/andreycizov/partialnav/PartialPageUpAction.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 432f98c

Please sign in to comment.