...
 
Commits (3)
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ScrollOffsetFeature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.FeatureNature</nature>
</natures>
</projectDescription>
bin.includes = feature.xml
This diff is collapsed.
......@@ -7,5 +7,14 @@
class="org.bonsaimind.scrolloffset.listeners.StartupListener">
</startup>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.ui.preferencePages.GeneralTextEditor"
class="org.bonsaimind.scrolloffset.preferences.PreferencePage"
id="org.bonsaimind.scrolloffset.preferencepage"
name="ScrollOffset">
</page>
</extension>
</plugin>
/*
* Copyright (c) 2017 Robert 'Bobby' Zenz
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.bonsaimind.scrolloffset.preferences;
import org.bonsaimind.scrolloffset.Activator;
import org.bonsaimind.scrolloffset.scrolling.Scroller;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class PreferencePage extends org.eclipse.jface.preference.PreferencePage implements IWorkbenchPreferencePage {
private Button btnEnableDuringMousedown = null;
private Button btnEnableScrolloffset = null;
private Preferences preferences = null;
private Text txtOffset = null;
public PreferencePage() {
super();
}
@Override
public void init(IWorkbench workbench) {
preferences = Activator.getDefault().getPreferences();
}
@Override
public boolean performOk() {
preferences.setEnabled(btnEnableScrolloffset.getSelection());
preferences.setEnabledDuringMousedown(btnEnableDuringMousedown.getSelection());
try {
preferences.setOffset(Integer.parseInt(txtOffset.getText()));
} catch (NumberFormatException e) {
// Ignore any exception.
}
updateValuesFromPreferences();
Scroller.updateFromPreferences();
return super.performOk();
}
@Override
protected Control createContents(Composite parent) {
parent.setLayout(new GridLayout(2, false));
btnEnableScrolloffset = new Button(parent, SWT.CHECK);
btnEnableScrolloffset.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
btnEnableScrolloffset.setText("Enable ScrollOffset");
Label lblOffset = new Label(parent, SWT.NONE);
lblOffset.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
lblOffset.setText("Offset");
txtOffset = new Text(parent, SWT.RIGHT);
txtOffset.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
btnEnableDuringMousedown = new Button(parent, SWT.CHECK);
btnEnableDuringMousedown.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
btnEnableDuringMousedown.setText("Enable during mousedown");
updateValuesFromPreferences();
return null;
}
@Override
protected void performDefaults() {
super.performDefaults();
btnEnableScrolloffset.setSelection(true);
btnEnableDuringMousedown.setSelection(false);
txtOffset.setText("10");
}
private void updateValuesFromPreferences() {
btnEnableScrolloffset.setSelection(preferences.isEnabled());
btnEnableDuringMousedown.setSelection(preferences.isEnabledDuringMousedown());
txtOffset.setText(Integer.toString(preferences.getOffset()));
}
}
......@@ -14,6 +14,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
public class Preferences {
private static final String PREFERENCE_NAME_ENABLED = Activator.PLUGIN_ID + ".enabled";
private static final String PREFERENCE_NAME_ENABLED_DURING_MOUSEDOWN = Activator.PLUGIN_ID + ".enabled_during_mousedown";
private static final String PREFERENCE_NAME_OFFSET = Activator.PLUGIN_ID + ".offset";
private IPreferenceStore preferenceStore = null;
......@@ -23,6 +24,7 @@ public class Preferences {
this.preferenceStore = preferenceStore;
preferenceStore.setDefault(PREFERENCE_NAME_ENABLED, true);
preferenceStore.setDefault(PREFERENCE_NAME_ENABLED_DURING_MOUSEDOWN, false);
preferenceStore.setDefault(PREFERENCE_NAME_OFFSET, 10);
}
......@@ -38,8 +40,13 @@ public class Preferences {
return preferenceStore.getBoolean(PREFERENCE_NAME_ENABLED);
}
public boolean isEnabledDuringMousedown() {
return preferenceStore.getBoolean(PREFERENCE_NAME_ENABLED_DURING_MOUSEDOWN);
}
public void restoreDefaults() {
preferenceStore.setToDefault(PREFERENCE_NAME_ENABLED);
preferenceStore.setToDefault(PREFERENCE_NAME_ENABLED_DURING_MOUSEDOWN);
preferenceStore.setToDefault(PREFERENCE_NAME_OFFSET);
}
......@@ -47,6 +54,10 @@ public class Preferences {
preferenceStore.setValue(PREFERENCE_NAME_ENABLED, enabled);
}
public void setEnabledDuringMousedown(boolean enabled) {
preferenceStore.setValue(PREFERENCE_NAME_ENABLED_DURING_MOUSEDOWN, enabled);
}
public void setOffset(int offset) {
preferenceStore.setValue(PREFERENCE_NAME_OFFSET, offset);
}
......
......@@ -20,6 +20,9 @@ public class Scroller {
/** If the scrolling offset is enabled. */
private static boolean enabled = true;
/** If the scrolling offset is enabled during mousedown. */
private static boolean enabledDuringMousedown = false;
/** The offset in lines. */
private static int offset = 10;
......@@ -45,7 +48,7 @@ public class Scroller {
return;
}
if (mouseDown) {
if (!enabledDuringMousedown && mouseDown) {
return;
}
......@@ -69,6 +72,7 @@ public class Scroller {
*/
public static void updateFromPreferences() {
enabled = Activator.getDefault().getPreferences().isEnabled();
enabledDuringMousedown = Activator.getDefault().getPreferences().isEnabledDuringMousedown();
offset = Activator.getDefault().getPreferences().getOffset();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ScrollOffsetUpdatesite</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.UpdateSiteBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.UpdateSiteNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature url="features/org.bonsaimind.scrolloffset_1.0.0.qualifier.jar" id="org.bonsaimind.scrolloffset" version="1.0.0.qualifier"/>
</site>