|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007, 2010 David Green 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 |
* David Green - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.mylyn.internal.wikitext.tasks.ui.commands; |
| 13 |
|
| 14 |
import org.eclipse.core.commands.ExecutionEvent; |
| 15 |
import org.eclipse.core.commands.ExecutionException; |
| 16 |
import org.eclipse.core.commands.IHandler; |
| 17 |
import org.eclipse.jface.text.BadLocationException; |
| 18 |
import org.eclipse.jface.text.ITextSelection; |
| 19 |
import org.eclipse.jface.text.source.ISourceViewer; |
| 20 |
import org.eclipse.ui.texteditor.TextViewerDeleteLineTarget; |
| 21 |
|
| 22 |
/** |
| 23 |
* Abstract command handler that uses {@link TextViewerDeleteLineTarget}. Subclasses can specify the type of delete line |
| 24 |
* and copyToClipboard. |
| 25 |
* |
| 26 |
* @author David Green |
| 27 |
*/ |
| 28 |
public class AbstractDeleteLineHandler extends AbstractMarkupSourceViewerHandler implements IHandler { |
| 29 |
protected final int type; |
| 30 |
|
| 31 |
protected final boolean copyToClipboard; |
| 32 |
|
| 33 |
protected AbstractDeleteLineHandler(int type, boolean copyToClipboard) { |
| 34 |
this.type = type; |
| 35 |
this.copyToClipboard = copyToClipboard; |
| 36 |
} |
| 37 |
|
| 38 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
| 39 |
ISourceViewer viewer = getSourceViewer(event); |
| 40 |
if (viewer != null) { |
| 41 |
TextViewerDeleteLineTarget target = new TextViewerDeleteLineTarget(viewer); |
| 42 |
|
| 43 |
try { |
| 44 |
target.deleteLine(viewer.getDocument(), (ITextSelection) viewer.getSelectionProvider().getSelection(), |
| 45 |
type, copyToClipboard); |
| 46 |
} catch (BadLocationException e) { |
| 47 |
throw new ExecutionException(e.getMessage(), e); |
| 48 |
} |
| 49 |
} |
| 50 |
return null; |
| 51 |
} |
| 52 |
|
| 53 |
} |