From 81ff40486ef87b3b5072cea4033dae61b0ed1790 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Tue, 8 Dec 2015 21:04:15 +0200 Subject: [PATCH] autotools: Revive sorting action in automake/conf editor. Remove the sorting action from the MakefileContentOutlinePage because the action was changed in a way to be addable in init method instead of deprecated setActionBars. Hooked it properly in AutomakefileContentOutlinePage. Bonus point - hooked into AutoconfContentOutlinePage as it was just too easy to get it there too. Change-Id: I873864f3978ae7cb1d8aa4143edf604244c0a4bc Signed-off-by: Alexander Kurtakov --- .../outline/AutoconfContentOutlinePage.java | 16 +++++++++++- .../{automake => }/LexicalSortingAction.java | 25 ++++++++----------- .../AutomakefileContentOutlinePage.java | 13 ++++++++++ .../automake/MakefileContentOutlinePage.java | 11 -------- 4 files changed, 39 insertions(+), 26 deletions(-) rename build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/{automake => }/LexicalSortingAction.java (82%) diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/outline/AutoconfContentOutlinePage.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/outline/AutoconfContentOutlinePage.java index f29f416a2d2..e3ef7f3bdfa 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/outline/AutoconfContentOutlinePage.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/outline/AutoconfContentOutlinePage.java @@ -15,6 +15,8 @@ import java.util.Iterator; import org.eclipse.cdt.autotools.ui.editors.AutoconfEditor; import org.eclipse.cdt.autotools.ui.editors.parser.AutoconfElement; +import org.eclipse.cdt.internal.autotools.ui.editors.LexicalSortingAction; +import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; @@ -23,6 +25,7 @@ import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.part.IPageSite; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.views.contentoutline.ContentOutlinePage; @@ -31,6 +34,7 @@ public class AutoconfContentOutlinePage extends ContentOutlinePage { private ITextEditor editor; private IEditorInput input; + private LexicalSortingAction sortAction; public AutoconfContentOutlinePage(AutoconfEditor editor) { super(); @@ -89,8 +93,10 @@ public class AutoconfContentOutlinePage extends ContentOutlinePage { viewer.setLabelProvider(new AutoconfLabelProvider()); viewer.addSelectionChangedListener(this); - if (input != null) + if (input != null) { viewer.setInput(input); + } + sortAction.setTreeViewer(viewer); } /* @@ -120,4 +126,12 @@ public class AutoconfContentOutlinePage extends ContentOutlinePage { } } + @Override + public void init(IPageSite pageSite) { + super.init(pageSite); + IToolBarManager toolBarManager = pageSite.getActionBars().getToolBarManager(); + sortAction = new LexicalSortingAction(); + toolBarManager.add(sortAction); + } + } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/LexicalSortingAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/LexicalSortingAction.java similarity index 82% rename from build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/LexicalSortingAction.java rename to build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/LexicalSortingAction.java index a351186f2b5..c7dc4b746bb 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/LexicalSortingAction.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/LexicalSortingAction.java @@ -10,14 +10,14 @@ * QNX Software System * Red Hat Inc. - convert to use with Automake editor *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.editors.automake; +package org.eclipse.cdt.internal.autotools.ui.editors; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.internal.autotools.ui.MakeUIImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.jface.viewers.ViewerComparator; @@ -29,7 +29,7 @@ public class LexicalSortingAction extends Action { private LexicalCSorter fSorter; private TreeViewer fTreeViewer; - public LexicalSortingAction(TreeViewer treeViewer) { + public LexicalSortingAction() { super(CUIPlugin.getResourceString(ACTION_NAME + ".label")); //$NON-NLS-1$ setDescription(CUIPlugin.getResourceString(ACTION_NAME + ".description")); //$NON-NLS-1$ @@ -37,13 +37,15 @@ public class LexicalSortingAction extends Action { MakeUIImages.setImageDescriptors(this, MakeUIImages.T_TOOL, MakeUIImages.IMG_TOOLS_ALPHA_SORTING); - fTreeViewer= treeViewer; fSorter= new LexicalCSorter(); - - boolean checked= CUIPlugin.getDefault().getDialogSettings().getBoolean(DIALOG_STORE_KEY); - valueChanged(checked, false); } + public void setTreeViewer(TreeViewer treeViewer) { + fTreeViewer = treeViewer; + boolean checked = CUIPlugin.getDefault().getDialogSettings().getBoolean(DIALOG_STORE_KEY); + valueChanged(checked, false); + } + @Override public void run() { valueChanged(isChecked(), true); @@ -51,7 +53,7 @@ public class LexicalSortingAction extends Action { private void valueChanged(boolean on, boolean store) { setChecked(on); - fTreeViewer.setSorter(on ? fSorter : null); + fTreeViewer.setComparator(on ? fSorter : null); String key= ACTION_NAME + ".tooltip" + (on ? ".on" : ".off"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setToolTipText(CUIPlugin.getResourceString(key)); @@ -61,12 +63,7 @@ public class LexicalSortingAction extends Action { } } - private static class LexicalCSorter extends ViewerSorter { - @SuppressWarnings("unused") - public boolean isSorterProperty(Object element, Object property) { - return true; - } - + private static class LexicalCSorter extends ViewerComparator { @Override public int category(Object obj) { if (obj instanceof ICElement) { diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileContentOutlinePage.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileContentOutlinePage.java index 0f42a48e793..0365d4c1e1f 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileContentOutlinePage.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileContentOutlinePage.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.internal.autotools.ui.MakeUIImages; +import org.eclipse.cdt.internal.autotools.ui.editors.LexicalSortingAction; import org.eclipse.cdt.make.core.makefile.IBadDirective; import org.eclipse.cdt.make.core.makefile.ICommand; import org.eclipse.cdt.make.core.makefile.IComment; @@ -30,6 +31,7 @@ import org.eclipse.cdt.make.core.makefile.ITargetRule; import org.eclipse.cdt.make.core.makefile.gnu.IInclude; import org.eclipse.cdt.make.core.makefile.gnu.ITerminal; import org.eclipse.cdt.make.ui.IWorkingCopyManager; +import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TreeViewer; @@ -38,6 +40,7 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.part.IPageSite; import org.eclipse.ui.views.contentoutline.ContentOutlinePage; @@ -45,6 +48,7 @@ public class AutomakefileContentOutlinePage extends ContentOutlinePage { protected IMakefile makefile; protected IMakefile nullMakefile = new NullMakefile(); + private LexicalSortingAction sortAction; private class AutomakefileContentProvider implements ITreeContentProvider { @@ -251,6 +255,7 @@ public class AutomakefileContentOutlinePage extends ContentOutlinePage { if (fInput != null) { viewer.setInput(fInput); } + sortAction.setTreeViewer(viewer); } public void inputChanged(Object oldInput, Object newInput) { @@ -267,4 +272,12 @@ public class AutomakefileContentOutlinePage extends ContentOutlinePage { } } + @Override + public void init(IPageSite pageSite) { + super.init(pageSite); + IToolBarManager toolBarManager = pageSite.getActionBars().getToolBarManager(); + sortAction = new LexicalSortingAction(); + toolBarManager.add(sortAction); + } + } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileContentOutlinePage.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileContentOutlinePage.java index 1a848e8a0de..d8de33782f2 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileContentOutlinePage.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileContentOutlinePage.java @@ -31,7 +31,6 @@ import org.eclipse.cdt.make.core.makefile.gnu.IInclude; import org.eclipse.cdt.make.core.makefile.gnu.ITerminal; import org.eclipse.cdt.make.ui.IWorkingCopyManager; import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -42,7 +41,6 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.part.IPageSite; @@ -282,13 +280,4 @@ public class MakefileContentOutlinePage extends ContentOutlinePage { } } - @Override - public void setActionBars(IActionBars actionBars) { - super.setActionBars(actionBars); - IToolBarManager toolBarManager= actionBars.getToolBarManager(); - - LexicalSortingAction action= new LexicalSortingAction(getTreeViewer()); - toolBarManager.add(action); - } - }