-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide syntax highlighting in the compare editor #684
This enables syntax highlighting for build scripts (Groovy and Kotlin DSL) in these areas: * Compare editor * Dialog: Restore from Local History * Opening an old file revision from history
- Loading branch information
1 parent
06828cf
commit 9ba95e9
Showing
11 changed files
with
256 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ildship.ui/src/main/java/org/eclipse/buildship/ui/internal/compare/GradleMergeViewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Gradle Inc. 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 https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
******************************************************************************/ | ||
package org.eclipse.buildship.ui.internal.compare; | ||
|
||
import org.eclipse.compare.CompareConfiguration; | ||
import org.eclipse.compare.contentmergeviewer.TextMergeViewer; | ||
import org.eclipse.jface.text.IDocumentPartitioner; | ||
import org.eclipse.jface.text.TextViewer; | ||
import org.eclipse.jface.text.rules.FastPartitioner; | ||
import org.eclipse.jface.text.source.ISourceViewer; | ||
import org.eclipse.swt.widgets.Composite; | ||
|
||
import org.eclipse.buildship.ui.internal.editor.GradleEditorConstants; | ||
import org.eclipse.buildship.ui.internal.editor.GradlePartitionScanner; | ||
import org.eclipse.buildship.ui.internal.editor.GradleTextViewerConfiguration; | ||
import org.eclipse.buildship.ui.internal.i18n.UiMessages; | ||
|
||
public final class GradleMergeViewer extends TextMergeViewer { | ||
|
||
public GradleMergeViewer(Composite parent, CompareConfiguration configuration) { | ||
super(parent, configuration); | ||
} | ||
|
||
@Override | ||
public String getTitle() { | ||
return UiMessages.Title_Gradle_Build_Script_Compare; | ||
} | ||
|
||
@Override | ||
protected void configureTextViewer(TextViewer textViewer) { | ||
if (textViewer instanceof ISourceViewer) { | ||
((ISourceViewer) textViewer).configure(new GradleTextViewerConfiguration()); | ||
} | ||
} | ||
|
||
@Override | ||
protected IDocumentPartitioner getDocumentPartitioner() { | ||
return new FastPartitioner(new GradlePartitionScanner(), GradleEditorConstants.PARTITIONS); | ||
} | ||
|
||
@Override | ||
protected String getDocumentPartitioning() { | ||
return GradleEditorConstants.PARTITIONING; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
....ui/src/main/java/org/eclipse/buildship/ui/internal/compare/GradleMergeViewerCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Gradle Inc. 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 https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
******************************************************************************/ | ||
package org.eclipse.buildship.ui.internal.compare; | ||
|
||
import org.eclipse.compare.CompareConfiguration; | ||
import org.eclipse.compare.IViewerCreator; | ||
import org.eclipse.jface.viewers.Viewer; | ||
import org.eclipse.swt.widgets.Composite; | ||
|
||
public final class GradleMergeViewerCreator implements IViewerCreator { | ||
|
||
@Override | ||
public Viewer createViewer(Composite parent, CompareConfiguration config) { | ||
return new GradleMergeViewer(parent, config); | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
...se.buildship.ui/src/main/java/org/eclipse/buildship/ui/internal/compare/GradleViewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Gradle Inc. 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 https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
******************************************************************************/ | ||
package org.eclipse.buildship.ui.internal.compare; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.eclipse.compare.IEncodedStreamContentAccessor; | ||
import org.eclipse.compare.IStreamContentAccessor; | ||
import org.eclipse.compare.contentmergeviewer.TextMergeViewer; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jface.resource.JFaceResources; | ||
import org.eclipse.jface.text.Document; | ||
import org.eclipse.jface.text.source.SourceViewer; | ||
import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.jface.viewers.StructuredSelection; | ||
import org.eclipse.jface.viewers.Viewer; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Control; | ||
|
||
import org.eclipse.buildship.ui.internal.UiPlugin; | ||
import org.eclipse.buildship.ui.internal.editor.GradleDocumentSetupParticipant; | ||
import org.eclipse.buildship.ui.internal.editor.GradleTextViewerConfiguration; | ||
|
||
public final class GradleViewer extends Viewer { | ||
|
||
private final SourceViewer sourceViewer; | ||
|
||
private Object input; | ||
|
||
public GradleViewer(Composite parent) { | ||
this.sourceViewer = new SourceViewer(parent, null, SWT.H_SCROLL | SWT.V_SCROLL); | ||
this.sourceViewer.setEditable(false); | ||
this.sourceViewer.configure(new GradleTextViewerConfiguration()); | ||
|
||
// use the same font as the TextMergeViewer | ||
this.sourceViewer.getTextWidget().setFont(JFaceResources.getFont(TextMergeViewer.class.getName())); | ||
} | ||
|
||
@Override | ||
public Control getControl() { | ||
return this.sourceViewer.getControl(); | ||
} | ||
|
||
@Override | ||
public Object getInput() { | ||
return this.input; | ||
} | ||
|
||
@Override | ||
public ISelection getSelection() { | ||
return StructuredSelection.EMPTY; | ||
} | ||
|
||
@Override | ||
public void refresh() { | ||
// empty implementation | ||
} | ||
|
||
@Override | ||
public void setInput(Object input) { | ||
this.input = input; | ||
|
||
if (!(input instanceof IStreamContentAccessor && input instanceof IEncodedStreamContentAccessor)) { | ||
return; | ||
} | ||
|
||
IEncodedStreamContentAccessor contentAccessor = (IEncodedStreamContentAccessor) input; | ||
try (InputStream contents = contentAccessor.getContents()) { | ||
if (contents == null) { | ||
return; | ||
} | ||
|
||
String charset = contentAccessor.getCharset(); | ||
if (charset == null) { | ||
charset = ResourcesPlugin.getEncoding(); | ||
} | ||
|
||
Document document = new Document(new String(contents.readAllBytes(), charset)); | ||
new GradleDocumentSetupParticipant().setup(document); | ||
this.sourceViewer.setDocument(document); | ||
} catch (CoreException | IOException e) { | ||
UiPlugin.logger().error("Failed to set up input document.", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void setSelection(ISelection selection, boolean reveal) { | ||
// empty implementation | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...dship.ui/src/main/java/org/eclipse/buildship/ui/internal/compare/GradleViewerCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Gradle Inc. 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 https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
******************************************************************************/ | ||
package org.eclipse.buildship.ui.internal.compare; | ||
|
||
import org.eclipse.compare.CompareConfiguration; | ||
import org.eclipse.compare.IViewerCreator; | ||
import org.eclipse.jface.viewers.Viewer; | ||
import org.eclipse.swt.widgets.Composite; | ||
|
||
public final class GradleViewerCreator implements IViewerCreator { | ||
|
||
@Override | ||
public Viewer createViewer(Composite parent, CompareConfiguration config) { | ||
return new GradleViewer(parent); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters