Skip to content

Commit

Permalink
autotools: Revive sorting action in automake/conf editor.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
akurtakov committed Dec 8, 2015
1 parent 6ba6157 commit 81ff404
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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;
Expand All @@ -23,6 +25,7 @@
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;

Expand All @@ -31,6 +34,7 @@ public class AutoconfContentOutlinePage extends ContentOutlinePage {

private ITextEditor editor;
private IEditorInput input;
private LexicalSortingAction sortAction;

public AutoconfContentOutlinePage(AutoconfEditor editor) {
super();
Expand Down Expand Up @@ -89,8 +93,10 @@ public void createControl(Composite parent) {
viewer.setLabelProvider(new AutoconfLabelProvider());
viewer.addSelectionChangedListener(this);

if (input != null)
if (input != null) {
viewer.setInput(input);
}
sortAction.setTreeViewer(viewer);
}

/*
Expand Down Expand Up @@ -120,4 +126,12 @@ public void selectionChanged(SelectionChangedEvent event)
}
}

@Override
public void init(IPageSite pageSite) {
super.init(pageSite);
IToolBarManager toolBarManager = pageSite.getActionBars().getToolBarManager();
sortAction = new LexicalSortingAction();
toolBarManager.add(sortAction);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;



Expand All @@ -29,29 +29,31 @@ 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$
setToolTipText(CUIPlugin.getResourceString(ACTION_NAME + ".tooltip")); //$NON-NLS-1$

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);
}

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));
Expand All @@ -61,12 +63,7 @@ private void valueChanged(boolean on, boolean store) {
}
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand All @@ -30,6 +31,7 @@
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;
Expand All @@ -38,13 +40,15 @@
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;


public class AutomakefileContentOutlinePage extends ContentOutlinePage {

protected IMakefile makefile;
protected IMakefile nullMakefile = new NullMakefile();
private LexicalSortingAction sortAction;

private class AutomakefileContentProvider implements ITreeContentProvider {

Expand Down Expand Up @@ -251,6 +255,7 @@ public void createControl(Composite parent) {
if (fInput != null) {
viewer.setInput(fInput);
}
sortAction.setTreeViewer(viewer);
}

public void inputChanged(Object oldInput, Object newInput) {
Expand All @@ -267,4 +272,12 @@ public void inputChanged(Object oldInput, Object newInput) {
}
}

@Override
public void init(IPageSite pageSite) {
super.init(pageSite);
IToolBarManager toolBarManager = pageSite.getActionBars().getToolBarManager();
sortAction = new LexicalSortingAction();
toolBarManager.add(sortAction);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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;
Expand All @@ -42,7 +41,6 @@
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;
Expand Down Expand Up @@ -282,13 +280,4 @@ public void update() {
}
}

@Override
public void setActionBars(IActionBars actionBars) {
super.setActionBars(actionBars);
IToolBarManager toolBarManager= actionBars.getToolBarManager();

LexicalSortingAction action= new LexicalSortingAction(getTreeViewer());
toolBarManager.add(action);
}

}

0 comments on commit 81ff404

Please sign in to comment.