Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-05-20 07:26:00 +0000
committerAlexander Kurtakov2017-05-20 08:42:15 +0000
commitd3835ba6ad609079642923c7d2162a804c0f61b1 (patch)
tree5e437b4dbad8dac43dbb569b09531122477ce75e
parentbf10b404d3e38a1d3fefbc7ae17f088cfc23d1aa (diff)
downloadorg.eclipse.linuxtools-d3835ba6ad609079642923c7d2162a804c0f61b1.tar.gz
org.eclipse.linuxtools-d3835ba6ad609079642923c7d2162a804c0f61b1.tar.xz
org.eclipse.linuxtools-d3835ba6ad609079642923c7d2162a804c0f61b1.zip
rpm: Make toggle commend and show outline work with generic editor.
Change-Id: I6efbb724d8039a0b1271d433fb2fda4d4add31d3 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com> Reviewed-on: https://git.eclipse.org/r/97611 Tested-by: Hudson CI
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml11
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileFoldingStructureProvider.java200
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java233
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorShowOutlineActionDelegate.java11
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorToggleCommentActionDelegate.java14
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileQuickOutlineDialog.java6
6 files changed, 230 insertions, 245 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml b/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml
index a85bdce997..51079f94c0 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/plugin.xml
@@ -439,12 +439,11 @@
point="org.eclipse.core.expressions.definitions">
<definition
id="org.eclipse.linuxtools.rpm.ui.editor.specEditorActive">
- <with
- variable="activePart">
- <instanceof
- value="org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor">
- </instanceof>
- </with>
+ <with variable="activeEditorInput">
+ <adapt type="org.eclipse.core.resources.IFile">
+ <test property="org.eclipse.core.resources.contentTypeId" value="org.eclipse.linuxtools.rpm.editor.content-type" />
+ </adapt>
+ </with>
</definition>
</extension>
<extension
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileFoldingStructureProvider.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileFoldingStructureProvider.java
index 8b136dd42f..2cb78556c4 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileFoldingStructureProvider.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/SpecfileFoldingStructureProvider.java
@@ -32,106 +32,104 @@ import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement;
public class SpecfileFoldingStructureProvider {
-
- private static class ElementByLineNbrComparator implements Comparator<SpecfileElement> {
- @Override
- public int compare(SpecfileElement element1, SpecfileElement element2) {
- Integer lineNbr1 = element1.getLineNumber();
- Integer lineNbr2 = element2.getLineNumber();
- return lineNbr1.compareTo(lineNbr2);
- }
- }
-
- private static final Annotation[] EMPTY = new Annotation[] {};
- private SpecfileEditor sEditor;
- private IDocument sDocument;
- private IProgressMonitor sProgressMonitor;
-
- public SpecfileFoldingStructureProvider(SpecfileEditor editor) {
- sEditor = editor;
- }
-
- public void setProgressMonitor(IProgressMonitor progressMonitor) {
- sProgressMonitor = progressMonitor;
- }
-
- public void setDocument(IDocument document) {
- sDocument = document;
- }
-
- public void updateFoldingRegions() {
+ private static class ElementByLineNbrComparator implements Comparator<SpecfileElement> {
+ @Override
+ public int compare(SpecfileElement element1, SpecfileElement element2) {
+ Integer lineNbr1 = element1.getLineNumber();
+ Integer lineNbr2 = element2.getLineNumber();
+ return lineNbr1.compareTo(lineNbr2);
+ }
+ }
+
+ private static final Annotation[] EMPTY = new Annotation[] {};
+ private SpecfileEditor sEditor;
+ private IDocument sDocument;
+ private IProgressMonitor sProgressMonitor;
+
+ public SpecfileFoldingStructureProvider(SpecfileEditor editor) {
+ sEditor = editor;
+ }
+
+ public void setProgressMonitor(IProgressMonitor progressMonitor) {
+ sProgressMonitor = progressMonitor;
+ }
+
+ public void setDocument(IDocument document) {
+ sDocument = document;
+ }
+
+ public void updateFoldingRegions() {
ProjectionAnnotationModel model = sEditor.getAdapter(ProjectionAnnotationModel.class);
- if (model != null) {
- updateFoldingRegions(model);
- }
- }
-
- void updateFoldingRegions(ProjectionAnnotationModel model) {
- Set<Position> structure = createFoldingStructure(sEditor.getSpecfile());
- Annotation[] deletions = computeDifferences(model, structure);
- Map<Annotation,Position> additions = computeAdditions(structure);
- if ((deletions.length != 0 || !additions.isEmpty())
- && (sProgressMonitor == null || !sProgressMonitor.isCanceled())) {
- model.modifyAnnotations(deletions, additions, EMPTY);
- }
- }
-
- private Map<Annotation,Position> computeAdditions(Set<Position> currentRegions) {
- Map<Annotation,Position> additionsMap = new HashMap<>();
- for (Position position: currentRegions) {
- additionsMap.put(new ProjectionAnnotation(), position);
- }
- return additionsMap;
- }
-
- private Annotation[] computeDifferences(ProjectionAnnotationModel model,
- Set<Position> current) {
- List<Annotation> deletions = new ArrayList<>();
- for (Iterator<Annotation> iter = model.getAnnotationIterator(); iter.hasNext();) {
- Annotation annotation = iter.next();
- if (annotation instanceof ProjectionAnnotation) {
- Position position = model.getPosition(annotation);
- if (current.contains(position)) {
- current.remove(position);
- } else {
- deletions.add(annotation);
- }
- }
- }
- return deletions.toArray(new Annotation[deletions.size()]);
- }
-
- private Set<Position> createFoldingStructure(Specfile specfile) {
- List<SpecfileElement> elements = new ArrayList<>();
- elements.addAll(specfile.getSections());
- elements.addAll(specfile.getComplexSections());
- Collections.sort(elements, new ElementByLineNbrComparator());
- return addFoldingRegions(elements);
- }
-
- private Set<Position> addFoldingRegions(List<SpecfileElement> elements) {
- Set<Position> regions = new HashSet<>();
- // add folding on the preamble section
- Position position;
- if (elements.size() > 0) {
- SpecfileElement element = elements.get(0);
- position = new Position(0, element.getLineStartPosition() - 1);
- regions.add(position);
- }
-
- for (int i = 0; i < elements.size(); i++) {
- SpecfileElement startElement = elements.get(i);
- int offsetPos = startElement.getLineStartPosition();
- int lenghtPos;
- if (i < elements.size() -1) {
- SpecfileElement endElement = elements.get(i+1);
- lenghtPos = endElement.getLineStartPosition() - startElement.getLineStartPosition() - 1;
- } else {
- lenghtPos = sDocument.getLength() - startElement.getLineStartPosition();
- }
- position = new Position(offsetPos, lenghtPos);
- regions.add(position);
- }
- return regions;
- }
+ if (model != null) {
+ updateFoldingRegions(model);
+ }
+ }
+
+ void updateFoldingRegions(ProjectionAnnotationModel model) {
+ Set<Position> structure = createFoldingStructure(sEditor.getSpecfile());
+ Annotation[] deletions = computeDifferences(model, structure);
+ Map<Annotation, Position> additions = computeAdditions(structure);
+ if ((deletions.length != 0 || !additions.isEmpty())
+ && (sProgressMonitor == null || !sProgressMonitor.isCanceled())) {
+ model.modifyAnnotations(deletions, additions, EMPTY);
+ }
+ }
+
+ private Map<Annotation, Position> computeAdditions(Set<Position> currentRegions) {
+ Map<Annotation, Position> additionsMap = new HashMap<>();
+ for (Position position : currentRegions) {
+ additionsMap.put(new ProjectionAnnotation(), position);
+ }
+ return additionsMap;
+ }
+
+ private Annotation[] computeDifferences(ProjectionAnnotationModel model, Set<Position> current) {
+ List<Annotation> deletions = new ArrayList<>();
+ for (Iterator<Annotation> iter = model.getAnnotationIterator(); iter.hasNext();) {
+ Annotation annotation = iter.next();
+ if (annotation instanceof ProjectionAnnotation) {
+ Position position = model.getPosition(annotation);
+ if (current.contains(position)) {
+ current.remove(position);
+ } else {
+ deletions.add(annotation);
+ }
+ }
+ }
+ return deletions.toArray(new Annotation[deletions.size()]);
+ }
+
+ private Set<Position> createFoldingStructure(Specfile specfile) {
+ List<SpecfileElement> elements = new ArrayList<>();
+ elements.addAll(specfile.getSections());
+ elements.addAll(specfile.getComplexSections());
+ Collections.sort(elements, new ElementByLineNbrComparator());
+ return addFoldingRegions(elements);
+ }
+
+ private Set<Position> addFoldingRegions(List<SpecfileElement> elements) {
+ Set<Position> regions = new HashSet<>();
+ // add folding on the preamble section
+ Position position;
+ if (elements.size() > 0) {
+ SpecfileElement element = elements.get(0);
+ position = new Position(0, element.getLineStartPosition() - 1);
+ regions.add(position);
+ }
+
+ for (int i = 0; i < elements.size(); i++) {
+ SpecfileElement startElement = elements.get(i);
+ int offsetPos = startElement.getLineStartPosition();
+ int lenghtPos;
+ if (i < elements.size() - 1) {
+ SpecfileElement endElement = elements.get(i + 1);
+ lenghtPos = endElement.getLineStartPosition() - startElement.getLineStartPosition() - 1;
+ } else {
+ lenghtPos = sDocument.getLength() - startElement.getLineStartPosition();
+ }
+ position = new Position(offsetPos, lenghtPos);
+ regions.add(position);
+ }
+ return regions;
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java
index 01533909c7..88806cd213 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorPrepareSourcesActionDelegate.java
@@ -49,135 +49,126 @@ import org.eclipse.ui.handlers.HandlerUtil;
public class SpecfileEditorPrepareSourcesActionDelegate extends AbstractHandler {
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- final Shell shell = HandlerUtil.getActiveShellChecked(event);
- final SpecfileParser specparser = new SpecfileParser();
- final IResource resource = RPMHandlerUtils.getResource(event);
- final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource);
- final IFile workFile = (IFile) rpj.getSpecFile();
- final Specfile specfile = specparser.parse(workFile);
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final Shell shell = HandlerUtil.getActiveShellChecked(event);
+ final SpecfileParser specparser = new SpecfileParser();
+ final IResource resource = RPMHandlerUtils.getResource(event);
+ final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource);
+ final IFile workFile = (IFile) rpj.getSpecFile();
+ final Specfile specfile = specparser.parse(workFile);
- if (!downloadFile(shell, rpj, specfile)) {
- return null;
- }
+ if (!downloadFile(shell, rpj, specfile)) {
+ return null;
+ }
- Job job = new Job("Preparing sources") { //$NON-NLS-1$
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(
- NLS.bind(Messages.PrepareSources_prepareSources, rpj.getSpecFile().getName()), IProgressMonitor.UNKNOWN);
- int offset = rpj.getSpecFile().getName().lastIndexOf("."); //$NON-NLS-1$
- MessageConsoleStream out = getConsole(
- rpj.getSpecFile().getName().substring(0, offset))
- .newMessageStream();
- IStatus is = null;
- try {
- is = rpj.buildPrep(out);
- } catch (CoreException e) {
- SpecfileLog.logError(Messages.PrepareSources_coreException,
- e);
- RPMUtils.showErrorDialog(shell,
- Messages.PrepareSources_error,
- Messages.PrepareSources_coreException);
- return is;
- } finally {
- monitor.done();
- }
- return is;
- }
- };
- job.setUser(true); // suppress UI. That's done in encapsulated
- job.schedule();
- return null;
- }
+ Job job = new Job("Preparing sources") { //$NON-NLS-1$
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask(NLS.bind(Messages.PrepareSources_prepareSources, rpj.getSpecFile().getName()),
+ IProgressMonitor.UNKNOWN);
+ int offset = rpj.getSpecFile().getName().lastIndexOf("."); //$NON-NLS-1$
+ MessageConsoleStream out = getConsole(rpj.getSpecFile().getName().substring(0, offset))
+ .newMessageStream();
+ IStatus is = null;
+ try {
+ is = rpj.buildPrep(out);
+ } catch (CoreException e) {
+ SpecfileLog.logError(Messages.PrepareSources_coreException, e);
+ RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error,
+ Messages.PrepareSources_coreException);
+ return is;
+ } finally {
+ monitor.done();
+ }
+ return is;
+ }
+ };
+ job.setUser(true); // suppress UI. That's done in encapsulated
+ job.schedule();
+ return null;
+ }
- public boolean downloadFile(Shell shell, RPMProject rpj, Specfile specfile) {
- // retrieve source(s) from specfile
+ public boolean downloadFile(Shell shell, RPMProject rpj, Specfile specfile) {
+ // retrieve source(s) from specfile
final List<SpecfileSource> sourceURLList = specfile != null ? specfile.getSources() : null;
- for (final SpecfileSource sourceurls : sourceURLList) {
- try {
- String resolvedURL = UiUtils.resolveDefines(specfile, sourceurls.getFileName());
- URL url = null;
- try {
- url = new URL(resolvedURL);
- } catch (MalformedURLException e) {
- SpecfileLog.logError(
- NLS.bind(Messages.PrepareSources_downloadSourcesMalformedURL, resolvedURL), e);
- RPMUtils.showErrorDialog(shell,
- Messages.PrepareSources_error,
- NLS.bind(Messages.PrepareSources_downloadSourcesMalformedURL, resolvedURL));
- return false;
- }
+ for (final SpecfileSource sourceurls : sourceURLList) {
+ try {
+ String resolvedURL = UiUtils.resolveDefines(specfile, sourceurls.getFileName());
+ URL url = null;
+ try {
+ url = new URL(resolvedURL);
+ } catch (MalformedURLException e) {
+ SpecfileLog.logError(NLS.bind(Messages.PrepareSources_downloadSourcesMalformedURL, resolvedURL), e);
+ RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error,
+ NLS.bind(Messages.PrepareSources_downloadSourcesMalformedURL, resolvedURL));
+ return false;
+ }
- URLConnection connection = url.openConnection();
+ URLConnection connection = url.openConnection();
- if (!(connection instanceof HttpURLConnection) ||
- ((HttpURLConnection) connection).getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) {
- connection.connect();
- // grab the name of the file from the URL
- int offset = url.toString().lastIndexOf("/"); //$NON-NLS-1$
- String filename = url.toString().substring(offset + 1);
+ if (!(connection instanceof HttpURLConnection)
+ || ((HttpURLConnection) connection).getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND) {
+ connection.connect();
+ // grab the name of the file from the URL
+ int offset = url.toString().lastIndexOf("/"); //$NON-NLS-1$
+ String filename = url.toString().substring(offset + 1);
- // create the path to the "to be downloaded" file
- IFile file = rpj.getConfiguration().getSourcesFolder()
- .getFile(new Path(filename));
+ // create the path to the "to be downloaded" file
+ IFile file = rpj.getConfiguration().getSourcesFolder().getFile(new Path(filename));
- Job downloadJob = new DownloadJob(file, connection);
- downloadJob.setUser(true);
- downloadJob.schedule();
- try {
- downloadJob.join();
- } catch (InterruptedException e1) {
- return false;
- }
- if (!downloadJob.getResult().isOK()) {
- return false;
- }
- }
- } catch (OperationCanceledException e) {
- SpecfileLog.logError(Messages.PrepareSources_downloadCancelled,
- e);
- RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error,
- Messages.PrepareSources_downloadCancelled);
- return false;
- } catch (IOException e) {
- SpecfileLog.logError(
- Messages.PrepareSources_downloadConnectionFail, e);
- RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error,
- Messages.PrepareSources_downloadConnectionFail);
- return false;
- }
- }
- return true;
- }
+ Job downloadJob = new DownloadJob(file, connection);
+ downloadJob.setUser(true);
+ downloadJob.schedule();
+ try {
+ downloadJob.join();
+ } catch (InterruptedException e1) {
+ return false;
+ }
+ if (!downloadJob.getResult().isOK()) {
+ return false;
+ }
+ }
+ } catch (OperationCanceledException e) {
+ SpecfileLog.logError(Messages.PrepareSources_downloadCancelled, e);
+ RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error,
+ Messages.PrepareSources_downloadCancelled);
+ return false;
+ } catch (IOException e) {
+ SpecfileLog.logError(Messages.PrepareSources_downloadConnectionFail, e);
+ RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error,
+ Messages.PrepareSources_downloadConnectionFail);
+ return false;
+ }
+ }
+ return true;
+ }
- /**
- * Get the console.
- *
- * @param packageName
- * The name of the package(RPM) this console will be for.
- * @return A console instance.
- */
- public MessageConsole getConsole(String packageName) {
- ConsolePlugin plugin = ConsolePlugin.getDefault();
- IConsoleManager conMan = plugin.getConsoleManager();
- String projectConsoleName = NLS.bind(Messages.PrepareSources_consoleName, packageName);
- MessageConsole ret = null;
- for (IConsole cons : ConsolePlugin.getDefault().getConsoleManager()
- .getConsoles()) {
- if (cons.getName().equals(projectConsoleName)) {
- ret = (MessageConsole) cons;
- }
- }
- // no existing console, create new one
- if (ret == null) {
- ret = new MessageConsole(projectConsoleName, null, null, true);
- }
- conMan.addConsoles(new IConsole[] { ret });
- ret.clearConsole();
- ret.activate();
- return ret;
- }
+ /**
+ * Get the console.
+ *
+ * @param packageName
+ * The name of the package(RPM) this console will be for.
+ * @return A console instance.
+ */
+ public MessageConsole getConsole(String packageName) {
+ ConsolePlugin plugin = ConsolePlugin.getDefault();
+ IConsoleManager conMan = plugin.getConsoleManager();
+ String projectConsoleName = NLS.bind(Messages.PrepareSources_consoleName, packageName);
+ MessageConsole ret = null;
+ for (IConsole cons : ConsolePlugin.getDefault().getConsoleManager().getConsoles()) {
+ if (cons.getName().equals(projectConsoleName)) {
+ ret = (MessageConsole) cons;
+ }
+ }
+ // no existing console, create new one
+ if (ret == null) {
+ ret = new MessageConsole(projectConsoleName, null, null, true);
+ }
+ conMan.addConsoles(new IConsole[] { ret });
+ ret.clearConsole();
+ ret.activate();
+ return ret;
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorShowOutlineActionDelegate.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorShowOutlineActionDelegate.java
index 7aab057a60..d70720aae5 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorShowOutlineActionDelegate.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorShowOutlineActionDelegate.java
@@ -12,22 +12,21 @@ package org.eclipse.linuxtools.internal.rpm.ui.editor.actions;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor;
import org.eclipse.linuxtools.internal.rpm.ui.editor.outline.SpecfileQuickOutlineDialog;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.texteditor.ITextEditor;
public class SpecfileEditorShowOutlineActionDelegate extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
- if (editor instanceof SpecfileEditor) {
- SpecfileQuickOutlineDialog quickOutlinePopupDialog = new SpecfileQuickOutlineDialog(
- editor.getSite().getShell(), SWT.NONE, (SpecfileEditor) editor);
- quickOutlinePopupDialog.setVisible(true);
- }
+ ITextEditor textEditor = editor.getAdapter(ITextEditor.class);
+ SpecfileQuickOutlineDialog quickOutlinePopupDialog = new SpecfileQuickOutlineDialog(editor.getSite().getShell(),
+ SWT.NONE, textEditor);
+ quickOutlinePopupDialog.setVisible(true);
return null;
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorToggleCommentActionDelegate.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorToggleCommentActionDelegate.java
index 3b0b32d9b7..2365b42a1f 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorToggleCommentActionDelegate.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/actions/SpecfileEditorToggleCommentActionDelegate.java
@@ -22,23 +22,21 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.linuxtools.internal.rpm.ui.editor.ISpecfileSpecialSymbols;
-import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor;
import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileLog;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
public class SpecfileEditorToggleCommentActionDelegate extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
- if (!(editor instanceof SpecfileEditor)) {
- return null;
- }
-
- SpecfileEditor specfileEditor = (SpecfileEditor) editor;
- IDocument document = specfileEditor.getAdapter(IDocument.class);
- ISelection currentSelection = specfileEditor.getSpecfileSourceViewer().getSelection();
+ ITextEditor specfileEditor = editor.getAdapter(ITextEditor.class);
+ IDocumentProvider dp = specfileEditor.getDocumentProvider();
+ IDocument document = dp.getDocument(specfileEditor.getEditorInput());
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof ITextSelection) {
ITextSelection selection = (ITextSelection) currentSelection;
String selectedContent = ""; //$NON-NLS-1$
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileQuickOutlineDialog.java b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileQuickOutlineDialog.java
index 9e7acaef8d..56ce296083 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileQuickOutlineDialog.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui.editor/src/org/eclipse/linuxtools/internal/rpm/ui/editor/outline/SpecfileQuickOutlineDialog.java
@@ -16,7 +16,6 @@ import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor;
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyListener;
@@ -29,15 +28,16 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.texteditor.ITextEditor;
public class SpecfileQuickOutlineDialog extends PopupDialog {
TreeViewer treeViewer;
private Text filterText;
- private SpecfileEditor editor;
+ private ITextEditor editor;
private ContainsFilter treeViewerFilter;
- public SpecfileQuickOutlineDialog(Shell parent, int shellStyle, SpecfileEditor editor) {
+ public SpecfileQuickOutlineDialog(Shell parent, int shellStyle, ITextEditor editor) {
super(parent, shellStyle, true, true, true, true, true, null, null);
this.editor = editor;
create();

Back to the top