1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 461770: Allow to copy and remove items from Include Browser view

Change-Id: I8bac95acfd2d72e258890974bf949e8c220f54a2
Signed-off-by: Andrew Gvozdev <angvoz.dev@gmail.com>
This commit is contained in:
Andrew Gvozdev 2015-03-09 22:33:39 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent ff5a55388c
commit c87badb420
6 changed files with 112 additions and 16 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2012 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2015 Wind River Systems, Inc. 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
@ -25,8 +25,6 @@ import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.util.CoreUtility;
public class IBFile {
final public ITranslationUnit fTU;
final public IIndexFileLocation fLocation;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2015 Wind River Systems, Inc. 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
@ -21,6 +21,7 @@ public class IBMessages extends NLS {
public static String IBHistoryListAction_HistoryList_label;
public static String IBHistoryListAction_label;
public static String IBHistoryListAction_Remove_label;
public static String IBViewPart_CopyIncludeHierarchy_label;
public static String IBViewPart_falseInputMessage;
public static String IBViewPart_FocusOn_label;
public static String IBViewPart_hideInactive_label;
@ -38,6 +39,7 @@ public class IBMessages extends NLS {
public static String IBViewPart_previousMatch_tooltip;
public static String IBViewPart_refresh_label;
public static String IBViewPart_refresh_tooltip;
public static String IBViewPart_RemoveFromView_label;
public static String IBViewPart_showFolders_label;
public static String IBViewPart_showFolders_tooltip;
public static String IBViewPart_showInclude_label;

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2006, 2008 Wind River Systems, Inc and others.
# Copyright (c) 2006, 2015 Wind River Systems, Inc 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
@ -35,6 +35,8 @@ IBViewPart_nextMatch_label=Next Include
IBViewPart_refresh_tooltip=Refresh View Content
IBViewPart_falseInputMessage=Include Hierarchies can be shown for C or C++ files, only. They have to be part of the workspace.
IBViewPart_nextMatch_tooltip=Show Next Include
IBViewPart_CopyIncludeHierarchy_label=Copy E&xpanded Hierarchy
IBViewPart_RemoveFromView_label=Remove From View
IBHistoryListAction_HistoryDialog_title=Include Browser History
IBHistoryDropDownAction_ClearHistory_label=Clear History
IBHistoryListAction_Remove_label=Remove

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2015 Wind River Systems, Inc. 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
@ -21,8 +21,6 @@ import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.util.CoreUtility;
/**
* Represents a node in the include browser
*/

View file

@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2015, 2015 Andrew Gvozdev 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Gvozdev - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.includebrowser;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
/**
* Action to remove items from the C++ Include Browser View.
*/
public class IBRemoveFromView extends Action {
private IBViewPart fView;
/**
* Constructs a Remove From View action.
*
* @param view the Include Browser view
*/
public IBRemoveFromView(IBViewPart view) {
super(IBMessages.IBViewPart_RemoveFromView_label);
fView= view;
ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE));
setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
}
@Override
public void run() {
TreeViewer tree = fView.getTreeViewer();
ITreeSelection selection = (ITreeSelection) tree.getSelection();
tree.setSelection(null); // should stay before removal
tree.remove(selection.toArray());
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2013 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2015 Wind River Systems, Inc. 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
@ -31,6 +31,8 @@ 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.bindings.BindingManagerEvent;
import org.eclipse.jface.bindings.IBindingManagerListener;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
@ -61,6 +63,7 @@ import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;
@ -68,8 +71,11 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ContributionItemFactory;
import org.eclipse.ui.actions.OpenFileAction;
import org.eclipse.ui.actions.TextActionHandler;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.keys.IBindingService;
import org.eclipse.ui.navigator.ICommonMenuConstants;
import org.eclipse.ui.navigator.resources.ProjectExplorer;
import org.eclipse.ui.part.IShowInSource;
import org.eclipse.ui.part.IShowInTarget;
@ -95,6 +101,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.actions.CopyTreeAction;
import org.eclipse.cdt.internal.ui.navigator.OpenCElementAction;
import org.eclipse.cdt.internal.ui.util.Messages;
import org.eclipse.cdt.internal.ui.viewsupport.EditorOpener;
@ -149,11 +156,15 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
private Action fPreviousAction;
private Action fRefreshAction;
private Action fHistoryAction;
private Action fRemoveFromViewAction;
private CopyTreeAction fCopyAction;
private IContextActivation fContextActivation;
private WorkingSetFilterUI fWorkingSetFilterUI;
private IBSetInputJob fSetInputJob;
private IBindingService bindingService;
private IBindingManagerListener bindingManagerListener;
@Override
public void setFocus() {
fPagebook.setFocus();
@ -280,6 +291,22 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
createActions();
createContextMenu();
bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
if (bindingService != null) {
bindingManagerListener = new IBindingManagerListener() {
@Override
public void bindingManagerChanged(BindingManagerEvent event) {
if (event.isActiveBindingsChanged()) {
String keyBinding = bindingService.getBestActiveBindingFormattedFor(IWorkbenchCommandConstants.EDIT_DELETE);
if (keyBinding != null) {
fRemoveFromViewAction.setText(IBMessages.IBViewPart_RemoveFromView_label + '\t'+ keyBinding);
}
}
}
};
bindingService.addBindingManagerListener(bindingManagerListener);
}
getSite().setSelectionProvider(fTreeViewer);
setMessage(IBMessages.IBViewPart_instructionMessage);
@ -300,10 +327,16 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
putDialogSettings();
if (fContextActivation != null) {
IContextService ctxService = (IContextService)getSite().getService(IContextService.class);
if (ctxService != null) {
ctxService.deactivateContext(fContextActivation);
}
if (ctxService != null) {
ctxService.deactivateContext(fContextActivation);
}
}
if (bindingService != null) {
bindingService.removeBindingManagerListener(bindingManagerListener);
bindingService = null;
}
if (fWorkingSetFilterUI != null) {
fWorkingSetFilterUI.dispose();
}
@ -594,7 +627,10 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
CPluginImages.setImageDescriptors(fRefreshAction, CPluginImages.T_LCL, CPluginImages.IMG_REFRESH);
fHistoryAction= new IBHistoryDropDownAction(this);
fCopyAction= new CopyCallHierarchyAction(this, fTreeViewer);
fRemoveFromViewAction= new IBRemoveFromView(this);
// setup action bar
// global action hooks
IActionBars actionBars = getViewSite().getActionBars();
@ -602,7 +638,10 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPreviousAction);
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fRefreshAction);
actionBars.updateActionBars();
TextActionHandler textActionHandler = new TextActionHandler(actionBars);
textActionHandler.setDeleteAction(fRemoveFromViewAction);
// local toolbar
IToolBarManager tm = actionBars.getToolBarManager();
tm.add(fNextAction);
@ -763,7 +802,6 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
submenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getSite().getWorkbenchWindow()));
m.add(submenu);
if (node.getParent() != null) {
m.add(new Separator());
m.add(new Action(Messages.format(IBMessages.IBViewPart_FocusOn_label, tu.getPath().lastSegment())) {
@Override
public void run() {
@ -772,6 +810,13 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
});
}
}
m.add(new Separator(IContextMenuConstants.GROUP_EDIT));
if (fCopyAction.canActionBeAdded()) {
m.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fCopyAction);
}
m.appendToGroup(ICommonMenuConstants.GROUP_EDIT, fRemoveFromViewAction);
}
m.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
}
@ -846,6 +891,12 @@ public class IBViewPart extends ViewPart implements IShowInSource, IShowInTarget
return fTreeViewer;
}
private static class CopyCallHierarchyAction extends CopyTreeAction {
public CopyCallHierarchyAction(ViewPart view, TreeViewer viewer) {
super(IBMessages.IBViewPart_CopyIncludeHierarchy_label, view, viewer);
}
}
public ITranslationUnit[] getHistoryEntries() {
return fHistoryEntries.toArray(new ITranslationUnit[fHistoryEntries.size()]);
}