Skip to content

Commit

Permalink
Make overlay scrolling configurable via the palette settings
Browse files Browse the repository at this point in the history
This adds a new checkbox to the settings dialog that allows the user to
replace the overlay scrollbar with the native scrollbar. Linux only, as
the overlay is not available on any other platforms.

Resolves eclipse#569
  • Loading branch information
ptziegler committed Oct 15, 2024
1 parent 7181ef2 commit 15a7eea
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 3 deletions.
8 changes: 8 additions & 0 deletions org.eclipse.gef/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/gef/ui/palette/DefaultPaletteViewerPreferences.java" type="org.eclipse.gef.ui.palette.DefaultPaletteViewerPreferences">
<filter id="576725006">
<message_arguments>
<message_argument value="PaletteViewerPreferences"/>
<message_argument value="DefaultPaletteViewerPreferences"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/gef/ui/palette/PinDrawerAction.java" type="org.eclipse.gef.ui.palette.PinDrawerAction">
<filter id="643850349">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -15,6 +15,7 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;

import org.eclipse.jface.preference.IPreferenceStore;
Expand Down Expand Up @@ -76,6 +77,7 @@ public DefaultPaletteViewerPreferences(final IPreferenceStore store) {
store.setDefault(PREFERENCE_LAYOUT, LAYOUT_LIST);
store.setDefault(PREFERENCE_AUTO_COLLAPSE, COLLAPSE_AS_NEEDED);
store.setDefault(PREFERENCE_FONT, DEFAULT_FONT);
store.setDefault(PREFERENCE_SCROLLBARS_MODE, SWT.SCROLLBAR_OVERLAY);

listener = new PreferenceStoreListener();
store.addPropertyChangeListener(listener);
Expand Down Expand Up @@ -231,6 +233,8 @@ protected void handlePreferenceStorePropertyChanged(String property) {
firePropertyChanged(property, Integer.valueOf(getAutoCollapseSetting()));
} else if (property.equals(PREFERENCE_FONT)) {
firePropertyChanged(property, getFontData());
} else if (property.equals(PREFERENCE_SCROLLBARS_MODE)) {
firePropertyChanged(property, getScrollbarsMode());
} else {
firePropertyChanged(property, Boolean.valueOf(useLargeIcons(convertPreferenceNameToLayout(property))));
}
Expand Down Expand Up @@ -356,4 +360,18 @@ public void propertyChange(PropertyChangeEvent evt) {
}
}

@Override
public void setScrollbarsMode(int mode) {
if (mode != SWT.SCROLLBAR_OVERLAY && mode != SWT.NONE) {
throw new IllegalArgumentException(
"Scrollbar mode must be either SWT.SCROLLBAR_OVERLAY or SWT.NONE, but %d was given!" //$NON-NLS-1$
.formatted(mode));
}
getPreferenceStore().setValue(PREFERENCE_SCROLLBARS_MODE, mode);
}

@Override
public int getScrollbarsMode() {
return getPreferenceStore().getInt(PREFERENCE_SCROLLBARS_MODE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ public class PaletteMessages extends NLS {
* The String "<Using Workbench Dialog Font>"
*/
public static String SETTINGS_WORKBENCH_FONT_LABEL;
/**
* The String "Enable Overlay Scrolling"
*
* @since 3.20
*/
public static String SETTINGS_OVERLAY_SCROLLING;
/**
* The String "-"
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -71,6 +71,11 @@ public void propertyChange(PropertyChangeEvent evt) {
|| property.equals(DefaultPaletteViewerPreferences
.convertLayoutToPreferenceName(getPaletteViewerPreferences().getLayoutSetting()))) {
refreshAllEditParts(root);
} else if (property.equals(PaletteViewerPreferences.PREFERENCE_SCROLLBARS_MODE)) {
FigureCanvas canvas = getFigureCanvas();
if (canvas != null) {
canvas.setScrollbarsMode((int) evt.getNewValue());
}
}
}

Expand Down Expand Up @@ -271,6 +276,7 @@ protected void hookControl() {
canvas.setHorizontalScrollBarVisibility(FigureCanvas.NEVER);
canvas.setVerticalScrollBarVisibility(globalScrollbar ? FigureCanvas.ALWAYS : FigureCanvas.AUTOMATIC);
if (prefs != null) {
canvas.setScrollbarsMode(prefs.getScrollbarsMode());
prefs.addPropertyChangeListener(prefListener);
}
updateFont();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -14,6 +14,7 @@

import java.beans.PropertyChangeListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;

/**
Expand All @@ -26,6 +27,7 @@
* future.
*
* @author Pratik Shah
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface PaletteViewerPreferences {

Expand Down Expand Up @@ -129,6 +131,14 @@ public interface PaletteViewerPreferences {
*/
String PREFERENCE_FONT = "Palette Font"; //$NON-NLS-1$

/**
* <b>Linux Only</b> Property name for enabling or disabling the scrollbars
* overlay.
*
* @since 3.20
*/
String PREFERENCE_SCROLLBARS_MODE = "Scrollbars Mode"; //$NON-NLS-1$

/**
* @param listener the PropertyChangeListener to be notified of changes
* @see java.beans.PropertyChangeSupport#addPropertyChangeListener(java.beans.PropertyChangeListener)
Expand Down Expand Up @@ -298,4 +308,25 @@ public interface PaletteViewerPreferences {
*/
boolean useLargeIcons();

/**
* Enables or disables overlay scrolling for the palette viewer. Supported
* values are:
* <ul>
* <li>{@link SWT#NONE}</li>
* <li>{@link SWT#SCROLLBAR_OVERLAY}</li>
* </ul>
* Overlay scrollbars are only supported on {@code Linux}.
*
* @since 3.20
*/
void setScrollbarsMode(int mode);

/**
* Returns whether overlay scrolling is enabled for the palette viewer . Overlay
* scrollbars are only supported on {@code Linux}.
*
* @return One of {@link SWT#SCROLLBAR_OVERLAY} or {@link SWT#NONE}.
* @since 3.20
*/
int getScrollbarsMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
Expand All @@ -31,6 +32,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
Expand Down Expand Up @@ -70,6 +72,10 @@ public class PaletteSettingsDialog extends Dialog {
protected static final String CACHE_DETAILS_ICON_SIZE = "details - use large icons"; //$NON-NLS-1$
protected static final String CACHE_FONT = "font"; //$NON-NLS-1$
protected static final String CACHE_COLLAPSE = "auto-collapse setting"; //$NON-NLS-1$
/**
* @since 3.20
*/
protected static final String CACHE_SCROLLBARS_MODE = "scrollbars mode"; //$NON-NLS-1$

/**
* The unique IDs for the various widgets. These IDs can be used to retrieve
Expand All @@ -90,6 +96,10 @@ public class PaletteSettingsDialog extends Dialog {
protected static final int LAYOUT_DETAILS_VIEW_ID = IDialogConstants.CLIENT_ID + 12;
protected static final int FONT_CHANGE_ID = IDialogConstants.CLIENT_ID + 13;
protected static final int DEFAULT_FONT_ID = IDialogConstants.CLIENT_ID + 14;
/**
* @since 3.20
*/
protected static final int SCROLLBARS_MODE_ID = IDialogConstants.CLIENT_ID + 15;

/**
* Sub - classes that need to create their own unique IDs should do so by adding
Expand Down Expand Up @@ -163,6 +173,9 @@ protected void buttonPressed(int buttonId) {
case DEFAULT_FONT_ID:
handleDefaultFontRequested();
break;
case SCROLLBARS_MODE_ID:
handleScrollbarsModeChanged(b.getSelection());
break;
default:
super.buttonPressed(buttonId);
break;
Expand All @@ -186,6 +199,7 @@ protected void cacheSettings() {
settings.put(CACHE_COLUMNS_ICON_SIZE,
Boolean.valueOf(prefs.useLargeIcons(PaletteViewerPreferences.LAYOUT_COLUMNS)));
settings.put(CACHE_LIST_ICON_SIZE, Boolean.valueOf(prefs.useLargeIcons(PaletteViewerPreferences.LAYOUT_LIST)));
settings.put(CACHE_SCROLLBARS_MODE, prefs.getScrollbarsMode());
}

/**
Expand Down Expand Up @@ -348,6 +362,11 @@ protected Control createDialogArea(Composite parent) {
data.horizontalIndent = 5;
child.setLayoutData(data);

if (Platform.getOS().equals(Platform.OS_LINUX)) {
child = createScrollbarsSettings(composite);
child.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
}

Label label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
data.horizontalSpan = 2;
Expand Down Expand Up @@ -436,6 +455,23 @@ protected Control createColumnsOptions(Composite parent) {
return contents;
}

/**
* Creates and initializes the part of the dialog that displays the options for
* overlay scrolling. This method should only be called on Linux. *
*
* @param parent the parent composite
* @return the newly created control
*
* @since 3.20
*/
protected Control createScrollbarsSettings(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FillLayout());
Button button = createButton(composite, SCROLLBARS_MODE_ID, "Enable overlay scrollbar", SWT.CHECK, null);
button.setSelection(prefs.getScrollbarsMode() == SWT.SCROLLBAR_OVERLAY);
return composite;
}

/**
* Creates and initializes (i.e. loads the current settings from
* PaletteViewerPreferences) the part of the dialog that displays the font
Expand Down Expand Up @@ -734,6 +770,17 @@ protected void handleLayoutSettingChanged(int newSetting) {
}
}

/**
* This method is called whenever the "Enable Overlay Scrolling" checkbox is
* selected/deselected. The method argument is the new state of the button.
*
* @param checked If {@code true}, overlay scrolling will be enabled.
* @since 3.20
*/
protected void handleScrollbarsModeChanged(boolean checked) {
prefs.setScrollbarsMode(checked ? SWT.SCROLLBAR_OVERLAY : SWT.NONE);
}

/**
* Restores the cached settings, thus undoing any changes made since the last
* caching of settings.
Expand All @@ -752,6 +799,7 @@ protected void restoreSettings() {
((Boolean) settings.get(CACHE_LIST_ICON_SIZE)).booleanValue());
prefs.setUseLargeIcons(PaletteViewerPreferences.LAYOUT_COLUMNS,
((Boolean) settings.get(CACHE_COLUMNS_ICON_SIZE)).booleanValue());
prefs.setScrollbarsMode((int) settings.get(CACHE_SCROLLBARS_MODE));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SETTINGS_LIST_VIEW_LABEL=&List
SETTINGS_USE_LARGE_ICONS_LABEL=&Use large icons
SETTINGS_USE_LARGE_ICONS_LABEL_CAPS=&Use Large Icons
SETTINGS_ICONS_VIEW_LABEL=&Icons only
SETTINGS_OVERLAY_SCROLLING=Enable Overlay Scrolling
COLLAPSE_NEVER_LABEL=&Never close
COLLAPSE_ALWAYS_LABEL=&Always close when opening another drawer
COLLAPSE_AS_NEEDED_LABEL=Close automatically &when there is not enough room
Expand Down

0 comments on commit 15a7eea

Please sign in to comment.