Skip to content

Commit

Permalink
Complete preference page refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbr committed Feb 20, 2023
1 parent efe131c commit ca98961
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 256 deletions.
4 changes: 2 additions & 2 deletions net.certiv.tools.indentguide.plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.ui.preferencePages.GeneralTextEditor"
class="net.certiv.tools.indentguide.preferences.SettingsPage"
id="net.certiv.tools.indentguide.preferences.SettingsPage"
class="net.certiv.tools.indentguide.preferences.GuidePage"
id="net.certiv.tools.indentguide.preferences.GuidePage"
name="Indent Guide">
</page>
</extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.ui.themes.ColorUtil;
import org.osgi.framework.BundleContext;

import net.certiv.tools.indentguide.preferences.Settings;
import net.certiv.tools.indentguide.preferences.Pref;

public class Activator extends AbstractUIPlugin {

Expand All @@ -36,7 +36,9 @@ public class Activator extends AbstractUIPlugin {
private static Activator plugin;

private final IEclipsePreferences[] editorScopes = new IEclipsePreferences[] {
InstanceScope.INSTANCE.getNode(EditorsID), DefaultScope.INSTANCE.getNode(EditorsID) };
InstanceScope.INSTANCE.getNode(EditorsID), //
DefaultScope.INSTANCE.getNode(EditorsID) //
};

private final IPropertyChangeListener themeChange = event -> {
disposeLineColor();
Expand Down Expand Up @@ -74,9 +76,9 @@ public void stop(BundleContext context) throws Exception {

public Color getColor() {
if (color == null) {
String key = Settings.LINE_COLOR;
String key = Pref.LINE_COLOR;
if (isDarkTheme()) {
key += Settings.DARK;
key += Pref.DARK;
}
String spec = getPreferenceStore().getString(key);
color = new Color(PlatformUI.getWorkbench().getDisplay(), ColorUtil.getColorValue(spec));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.eclipse.swt.graphics.LineAttributes;
import org.eclipse.swt.graphics.Point;

import net.certiv.tools.indentguide.preferences.Settings;
import net.certiv.tools.indentguide.preferences.Pref;

/**
* A painter for drawing visible indent guide lines.
Expand Down Expand Up @@ -57,10 +57,10 @@ public class IndentGuidePainter implements IPainter, PaintListener {
private int lineShift;
private boolean drawLeftEnd;
private boolean drawBlankLine;
private boolean skipCommentBlock;
private boolean drawCommentBlock;

private final IPropertyChangeListener propertyWatcher = event -> {
if (event.getProperty().startsWith(Settings.KEY)) {
if (event.getProperty().startsWith(Pref.KEY)) {
update();
redrawAll();
}
Expand Down Expand Up @@ -117,8 +117,7 @@ public void paint(int reason) {
if (widgetOffset >= 0 && redrawLength > 0) {
widget.redrawRange(widgetOffset, redrawLength, true);
}
}
catch (BadLocationException e) {}
} catch (BadLocationException e) {}
}
}

Expand All @@ -142,13 +141,13 @@ public void paintControl(PaintEvent event) {
}

private void update() {
lineAlpha = store.getInt(Settings.LINE_ALPHA);
lineStyle = store.getInt(Settings.LINE_STYLE);
lineWidth = store.getInt(Settings.LINE_WIDTH);
lineShift = store.getInt(Settings.LINE_SHIFT);
drawLeftEnd = store.getBoolean(Settings.DRAW_LEFT_END);
drawBlankLine = store.getBoolean(Settings.DRAW_BLANK_LINE);
skipCommentBlock = store.getBoolean(Settings.SKIP_COMMENT_BLOCK);
lineAlpha = store.getInt(Pref.LINE_ALPHA);
lineStyle = store.getInt(Pref.LINE_STYLE);
lineWidth = store.getInt(Pref.LINE_WIDTH);
lineShift = store.getInt(Pref.LINE_SHIFT);
drawLeftEnd = store.getBoolean(Pref.DRAW_LEFT_EDGE);
drawBlankLine = store.getBoolean(Pref.DRAW_BLANK_LINE);
drawCommentBlock = store.getBoolean(Pref.DRAW_COMMENT_BLOCK);
}

// Draw characters in view range.
Expand Down Expand Up @@ -195,7 +194,7 @@ private void drawLineRange(GC gc, int begLine, int endLine, int x, int w) {
if (!isFoldedLine(content.getLineAtOffset(offset))) {
String text = widget.getLine(line);
int extend = 0;
if (skipCommentBlock && assumeCommentBlock(text, tabWidth)) {
if (!drawCommentBlock && assumeCommentBlock(text, tabWidth)) {
extend -= tabWidth;
}
if (drawBlankLine && text.trim().length() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@

import net.certiv.tools.indentguide.adaptors.PartAdaptor;
import net.certiv.tools.indentguide.adaptors.WindowAdaptor;
import net.certiv.tools.indentguide.preferences.Settings;
import net.certiv.tools.indentguide.util.Prefs;
import net.certiv.tools.indentguide.preferences.Pref;
import net.certiv.tools.indentguide.util.Utils;
import net.certiv.tools.indentguide.util.Utils.Delta;

public class Starter implements IStartup {

Expand All @@ -58,7 +58,8 @@ public class Starter implements IStartup {
private static final String SOURCE_VIEWER = "getSourceViewer"; // $NON-NLS-1$

private IPreferenceStore store;
private Set<String> contentTypes;
// excluded content types
private Set<String> excludedTypeIds;

// row=window; col=page/editor; val=painter
private HashMap<IWorkbenchPart, HashMap<ISourceViewer, IndentGuidePainter>> paintMap = new HashMap<>();
Expand Down Expand Up @@ -92,7 +93,7 @@ private void initWorkbenchWindow(IWorkbenchWindow window) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IWorkbenchPart part = page.getActivePart();
Activator.log("workbench page '%s'", name(part));
Activator.log("workbench page [%s]", name(part));

if (part instanceof MultiPageEditorPart) {
IEditorPart editor = activeEditor((MultiPageEditorPart) part);
Expand All @@ -108,8 +109,8 @@ private void initWorkbenchWindow(IWorkbenchWindow window) {
}

private void installPainter(IEditorPart part, IWorkbenchPart window) {
if (!store.getBoolean(Settings.ENABLED)) return;
Activator.log("inspecting editor '%s'", name(part));
if (!store.getBoolean(Pref.ENABLED)) return;
Activator.log("inspecting editor [%s]", name(part));

if (part instanceof AbstractTextEditor) {
AbstractTextEditor editor = (AbstractTextEditor) part;
Expand Down Expand Up @@ -175,7 +176,7 @@ private boolean validType(AbstractTextEditor editor) {
Activator.log("painter disallowed for '%s' [%s]", srcname, UNKNOWN);
return false;
}
if (contentTypes.contains(type.getId())) {
if (!excludedTypeIds.contains(type.getId())) {
Activator.log("installing painter on '%s' [%s]", srcname, type.getName());
return true;
}
Expand All @@ -185,7 +186,7 @@ private boolean validType(AbstractTextEditor editor) {
}

private void updateContentTypes() {
contentTypes = Prefs.asLinkedSet(store.getString(Settings.CONTENT_TYPES));
excludedTypeIds = Utils.undelimit(store.getString(Pref.CONTENT_TYPES));
}

private String name(IWorkbenchPart part) {
Expand Down Expand Up @@ -249,19 +250,16 @@ private class StoreWatcher implements IPropertyChangeListener {

@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getProperty().startsWith(Settings.KEY)) {
if (evt.getProperty().startsWith(Pref.KEY)) {
String property = evt.getProperty();
Object old = evt.getOldValue();
Object now = evt.getNewValue();
if (property.equals(Settings.CONTENT_TYPES)) {
if (property.equals(Pref.CONTENT_TYPES)) {
updateContentTypes();

Set<String> prev = Prefs.asLinkedSet((String) old);
Set<String> pres = Prefs.asLinkedSet((String) now);
Set<String> rmved = Utils.subtract(prev, pres);
Set<String> added = Utils.subtract(pres, prev);
if (!rmved.isEmpty()) Activator.log("property change '%s' removed %s", property, rmved);
if (!added.isEmpty()) Activator.log("property change '%s' added %s", property, added);
Delta<String> delta = Utils.delta(Utils.undelimit((String) old), Utils.undelimit((String) now));
if (!delta.rmved.isEmpty()) Activator.log("property change '%s' removed %s", property, delta.rmved);
if (!delta.added.isEmpty()) Activator.log("property change '%s' added %s", property, delta.added);

} else {
Activator.log("property change '%s' [%s] => [%s]", property, old, now);
Expand Down
Loading

0 comments on commit ca98961

Please sign in to comment.