diff options
author | Marc-Andre Laperle | 2013-12-20 22:06:33 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2014-01-06 15:48:58 +0000 |
commit | 5ea4867c5d798e7fd3cf9bb1c007623ec0e583eb (patch) | |
tree | 9cd498db8769f7b2bbc22dce1932b423171c45a3 | |
parent | 2be6e945d58670445e98026fea9047a77c497228 (diff) | |
download | org.eclipse.mylyn.docs-5ea4867c5d798e7fd3cf9bb1c007623ec0e583eb.tar.gz org.eclipse.mylyn.docs-5ea4867c5d798e7fd3cf9bb1c007623ec0e583eb.tar.xz org.eclipse.mylyn.docs-5ea4867c5d798e7fd3cf9bb1c007623ec0e583eb.zip |
424558: Add Collapse All button to Outline view
Bug: 424558
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=424558
Change-Id: I46972ef3297bdcb2f692cc9d46ab33708b03c031
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
4 files changed, 68 insertions, 5 deletions
diff --git a/org.eclipse.mylyn.wikitext.ui/icons/collapseall.gif b/org.eclipse.mylyn.wikitext.ui/icons/collapseall.gif Binary files differnew file mode 100644 index 000000000..a2d80a904 --- /dev/null +++ b/org.eclipse.mylyn.wikitext.ui/icons/collapseall.gif diff --git a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditorOutline.java b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditorOutline.java index ec166d0c7..18e506a7b 100644 --- a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditorOutline.java +++ b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditorOutline.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 David Green and others. + * Copyright (c) 2007, 2013 David Green and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,15 +7,19 @@ * * Contributors: * David Green - initial API and implementation + * Marc-Andre Laperle (Ericsson) - Add collapse all button (Bug 424558) *******************************************************************************/ package org.eclipse.mylyn.internal.wikitext.ui.editor; +import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; 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.commands.ActionHandler; import org.eclipse.jface.viewers.AbstractTreeViewer; import org.eclipse.jface.viewers.IOpenListener; import org.eclipse.jface.viewers.ISelection; @@ -25,6 +29,7 @@ import org.eclipse.jface.viewers.OpenEvent; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.window.ToolTip; +import org.eclipse.mylyn.internal.wikitext.ui.WikiTextUiPlugin; import org.eclipse.mylyn.internal.wikitext.ui.editor.dnd.DndConfigurationStrategy; import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineItem; import org.eclipse.swt.SWT; @@ -35,12 +40,17 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.handlers.CollapseAllHandler; +import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.model.BaseWorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.part.IPageSite; import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.IShowInTarget; import org.eclipse.ui.part.ShowInContext; +import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.IUpdate; import org.eclipse.ui.views.contentoutline.ContentOutlinePage; @@ -131,7 +141,9 @@ public class MarkupEditorOutline extends ContentOutlinePage implements IShowInSo } }; - getSite().setSelectionProvider(viewer); + IPageSite site = getSite(); + site.setSelectionProvider(viewer); + configureActionBars(site); MenuManager manager = new MenuManager("#PopUp"); //$NON-NLS-1$ manager.setRemoveAllWhenShown(true); @@ -142,12 +154,51 @@ public class MarkupEditorOutline extends ContentOutlinePage implements IShowInSo }); viewer.getTree().setMenu(manager.createContextMenu(viewer.getTree())); - getSite().registerContextMenu(MarkupEditor.ID + ".outlineContextMenu", manager, viewer); //$NON-NLS-1$ + site.registerContextMenu(MarkupEditor.ID + ".outlineContextMenu", manager, viewer); //$NON-NLS-1$ configureDnd(); configureActions(); } + /** + * Collapse all nodes. + */ + private static class CollapseAllAction extends Action { + + private final TreeViewer viewer; + + public CollapseAllAction(TreeViewer viewer) { + super(Messages.MarkupEditor_collapseAllAction_label); + setDescription(Messages.MarkupEditor_collapseAllAction_description); + setToolTipText(Messages.MarkupEditor_collapseAllAction_tooltip); + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(WikiTextUiPlugin.getDefault().getPluginId(), + "icons/collapseall.gif")); //$NON-NLS-1$ + this.viewer = viewer; + } + + @Override + public void run() { + try { + viewer.getControl().setRedraw(false); + viewer.collapseAll(); + } finally { + viewer.getControl().setRedraw(true); + } + } + } + + private void configureActionBars(IPageSite site) { + IActionBars actionBars = site.getActionBars(); + IToolBarManager toolBarManager = actionBars.getToolBarManager(); + IHandlerService handlerService = (IHandlerService) site.getService(IHandlerService.class); + + CollapseAllAction collapseAllAction = new CollapseAllAction(getTreeViewer()); + toolBarManager.add(collapseAllAction); + handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, new ActionHandler(collapseAllAction)); + + actionBars.updateActionBars(); + } + @Override public void dispose() { if (dndConfigurationStrategy != null) { diff --git a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/Messages.java b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/Messages.java index 05479e4f5..ee1c81d8a 100644 --- a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/Messages.java +++ b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 David Green and others. + * Copyright (c) 2007, 2013 David Green and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * David Green - initial API and implementation + * Marc-Andre Laperle (Ericsson) - Add collapse all button (Bug 424558) *******************************************************************************/ package org.eclipse.mylyn.internal.wikitext.ui.editor; @@ -39,6 +40,12 @@ class Messages extends NLS { public static String MarkupEditor_updateOutline; + public static String MarkupEditor_collapseAllAction_label; + + public static String MarkupEditor_collapseAllAction_tooltip; + + public static String MarkupEditor_collapseAllAction_description; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/messages.properties b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/messages.properties index 14789f9d2..b9709f5a0 100644 --- a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/messages.properties +++ b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2007, 2009 David Green and others. +# Copyright (c) 2007, 2013 David Green and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ # # Contributors: # David Green - initial API and implementation +# Marc-Andre Laperle (Ericsson) - Add collapse all button (Bug 424558) ############################################################################### MarkupEditor_markupLanguage=Markup Language MarkupEditor_markupPreferenceError=Cannot load markup language preference @@ -18,3 +19,7 @@ MarkupEditor_markupSource_tooltip_named=The markup source view, dislpaying {0} m MarkupEditor_preview=Preview MarkupEditor_preview_tooltip=The markup preview, which shows the markup source as it would be rendered to HTML MarkupEditor_updateOutline=Update outline + +MarkupEditor_collapseAllAction_label=Collapse All +MarkupEditor_collapseAllAction_tooltip=Collapse All +MarkupEditor_collapseAllAction_description=Collapse All |