Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 77014 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.handlers;
13
14
import org.eclipse.core.commands.AbstractHandler;
15
import org.eclipse.core.commands.ExecutionEvent;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.expressions.IEvaluationContext;
18
import org.eclipse.ui.IEditorPart;
19
import org.eclipse.ui.ISources;
20
import org.eclipse.ui.IViewPart;
21
import org.eclipse.ui.IWorkbenchPart;
22
import org.eclipse.ui.IWorkbenchWindow;
23
24
/**
25
 * Provide a Handler for the Close Part command. This can then be bound to
26
 * whatever keybinding the user prefers.
27
 * 
28
 * @since 3.3
29
 */
30
public class ClosePartHandler extends AbstractHandler {
31
32
	/*
33
	 * (non-Javadoc)
34
	 * 
35
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
36
	 */
37
	public Object execute(ExecutionEvent event) throws ExecutionException {
38
		IWorkbenchPart part = null;
39
		IWorkbenchWindow window = null;
40
		if (event.getApplicationContext() instanceof IEvaluationContext) {
41
			IEvaluationContext appContext = (IEvaluationContext) event
42
					.getApplicationContext();
43
			window = (IWorkbenchWindow) appContext
44
					.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME);
45
			if (window == null) {
46
				throw new ExecutionException("No active workbench window"); //$NON-NLS-1$
47
			}
48
			part = (IWorkbenchPart) appContext
49
					.getVariable(ISources.ACTIVE_PART_NAME);
50
			if (part == null) {
51
				throw new ExecutionException("No active part"); //$NON-NLS-1$
52
			}
53
		}
54
55
		if (part instanceof IEditorPart) {
56
			window.getActivePage().closeEditor((IEditorPart) part, true);
57
		} else if (part instanceof IViewPart) {
58
			window.getActivePage().hideView((IViewPart) part);
59
		}
60
61
		return null;
62
	}
63
}
(-)plugin.xml (+6 lines)
Lines 537-542 Link Here
537
            categoryId="org.eclipse.ui.category.file"
537
            categoryId="org.eclipse.ui.category.file"
538
            id="org.eclipse.ui.file.close" />
538
            id="org.eclipse.ui.file.close" />
539
      <command
539
      <command
540
            categoryId="org.eclipse.ui.category.file"
541
            defaultHandler="org.eclipse.ui.internal.handlers.ClosePartHandler"
542
            description="%command.closePart.description"
543
            id="org.eclipse.ui.file.closePart"
544
            name="%command.closePart.name"/>
545
      <command
540
            name="%command.closeAll.name"
546
            name="%command.closeAll.name"
541
            description="%command.closeAll.description"
547
            description="%command.closeAll.description"
542
            categoryId="org.eclipse.ui.category.file"
548
            categoryId="org.eclipse.ui.category.file"
(-)plugin.properties (+2 lines)
Lines 103-108 Link Here
103
command.backwardHistory.name = Backward History
103
command.backwardHistory.name = Backward History
104
command.close.description = Close the active editor
104
command.close.description = Close the active editor
105
command.close.name = Close
105
command.close.name = Close
106
command.closePart.description = Close the active workbench part
107
command.closePart.name = Close Part
106
command.closeAll.description = Close all editors
108
command.closeAll.description = Close all editors
107
command.closeAll.name = Close All
109
command.closeAll.name = Close All
108
command.closeOthers.description = Close all editors except the one that is active
110
command.closeOthers.description = Close all editors except the one that is active

Return to bug 77014