View | Details | Raw Unified | Return to bug 321701 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/AbstractDeleteLineHandler.java (+53 lines)
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.provisional.commons.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.ITextViewer;
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 AbstractTextViewerHandler 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
		ITextViewer viewer = getTextViewer(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
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/AbstractTextViewerHandler.java (+48 lines)
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.provisional.commons.ui.commands;
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.jface.text.ITextViewer;
18
import org.eclipse.jface.text.source.ISourceViewer;
19
import org.eclipse.swt.custom.StyledText;
20
import org.eclipse.ui.handlers.HandlerUtil;
21
22
/**
23
 * Abstract command handler that can get the current text viewer.
24
 * 
25
 * @author David Green
26
 */
27
public abstract class AbstractTextViewerHandler extends AbstractHandler {
28
29
	/**
30
	 * get the {@link ITextViewer} for the given event. Depends on the <tt>activeFocusControl</tt> event variable being
31
	 * an instanceof {@link StyledText}. The {@link StyledText#getData(String))} is expected to have a value for one of
32
	 * <code>ITextViewer.class.getName()</code> or <code>ISourceViewer.class.getName()</code>.
33
	 * 
34
	 * @return the text viewer or null if it cannot be found
35
	 */
36
	protected ITextViewer getTextViewer(ExecutionEvent event) throws ExecutionException {
37
		Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl"); //$NON-NLS-1$
38
		if (activeFocusControl instanceof StyledText) {
39
			StyledText textWidget = (StyledText) activeFocusControl;
40
			ITextViewer viewer = (ITextViewer) textWidget.getData(ITextViewer.class.getName());
41
			if (viewer == null) {
42
				viewer = (ITextViewer) textWidget.getData(ISourceViewer.class.getName());
43
			}
44
			return viewer;
45
		}
46
		return null;
47
	}
48
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/CutLineHandler.java (+25 lines)
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.provisional.commons.ui.commands;
13
14
import org.eclipse.ui.texteditor.DeleteLineAction;
15
16
/**
17
 * Command handler for cut line command (whole)
18
 * 
19
 * @author David Green
20
 */
21
public class CutLineHandler extends AbstractDeleteLineHandler {
22
	public CutLineHandler() {
23
		super(DeleteLineAction.WHOLE, true);
24
	}
25
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/CutLineToBeginningHandler.java (+25 lines)
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.provisional.commons.ui.commands;
13
14
import org.eclipse.ui.texteditor.DeleteLineAction;
15
16
/**
17
 * Command handler for cut line command (to beginning)
18
 * 
19
 * @author David Green
20
 */
21
public class CutLineToBeginningHandler extends AbstractDeleteLineHandler {
22
	public CutLineToBeginningHandler() {
23
		super(DeleteLineAction.TO_BEGINNING, true);
24
	}
25
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/CutLineToEndHandler.java (+25 lines)
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.provisional.commons.ui.commands;
13
14
import org.eclipse.ui.texteditor.DeleteLineAction;
15
16
/**
17
 * Command handler for cut line command (to end)
18
 * 
19
 * @author David Green
20
 */
21
public class CutLineToEndHandler extends AbstractDeleteLineHandler {
22
	public CutLineToEndHandler() {
23
		super(DeleteLineAction.TO_END, true);
24
	}
25
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/DeleteLineHandler.java (+25 lines)
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.provisional.commons.ui.commands;
13
14
import org.eclipse.ui.texteditor.DeleteLineAction;
15
16
/**
17
 * Command handler for delete line command (whole)
18
 * 
19
 * @author David Green
20
 */
21
public class DeleteLineHandler extends AbstractDeleteLineHandler {
22
	public DeleteLineHandler() {
23
		super(DeleteLineAction.WHOLE, false);
24
	}
25
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/DeleteLineToBeginningHandler.java (+25 lines)
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.provisional.commons.ui.commands;
13
14
import org.eclipse.ui.texteditor.DeleteLineAction;
15
16
/**
17
 * Command handler for delete line command (to beginning)
18
 * 
19
 * @author David Green
20
 */
21
public class DeleteLineToBeginningHandler extends AbstractDeleteLineHandler {
22
	public DeleteLineToBeginningHandler() {
23
		super(DeleteLineAction.TO_BEGINNING, false);
24
	}
25
}
(-)src/org/eclipse/mylyn/internal/provisional/commons/ui/commands/DeleteLineToEndHandler.java (+25 lines)
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.provisional.commons.ui.commands;
13
14
import org.eclipse.ui.texteditor.DeleteLineAction;
15
16
/**
17
 * Command handler for delete line command (to end)
18
 * 
19
 * @author David Green
20
 */
21
public class DeleteLineToEndHandler extends AbstractDeleteLineHandler {
22
	public DeleteLineToEndHandler() {
23
		super(DeleteLineAction.TO_END, false);
24
	}
25
}
(-)plugin.xml (+83 lines)
Lines 224-227 Link Here
224
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
224
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
225
      	</key>
225
      	</key>
226
	</extension>
226
	</extension>
227
 <extension
228
       point="org.eclipse.ui.handlers">
229
    <handler
230
          class="org.eclipse.mylyn.internal.provisional.commons.ui.commands.DeleteLineHandler"
231
          commandId="org.eclipse.ui.edit.text.delete.line">
232
         <activeWhen>
233
         	<with variable="activeContexts">
234
	            <iterate operator="or" ifEmpty="false">
235
	               <equals
236
	                     value="org.eclipse.mylyn.wikitext.tasks.ui.markupSourceContext"/>
237
	            </iterate>
238
         	</with>
239
		</activeWhen>
240
    </handler>
241
    
242
    <handler
243
          class="org.eclipse.mylyn.internal.provisional.commons.ui.commands.CutLineHandler"
244
          commandId="org.eclipse.ui.edit.text.cut.line">
245
         <activeWhen>
246
         	<with variable="activeContexts">
247
	            <iterate operator="or" ifEmpty="false">
248
	               <equals
249
	                     value="org.eclipse.mylyn.wikitext.tasks.ui.markupSourceContext"/>
250
	            </iterate>
251
         	</with>
252
		</activeWhen>
253
    </handler>
254
    
255
    <handler
256
          class="org.eclipse.mylyn.internal.provisional.commons.ui.commands.DeleteLineToBeginningHandler"
257
          commandId="org.eclipse.ui.edit.text.delete.line.to.beginning">
258
         <activeWhen>
259
         	<with variable="activeContexts">
260
	            <iterate operator="or" ifEmpty="false">
261
	               <equals
262
	                     value="org.eclipse.mylyn.wikitext.tasks.ui.markupSourceContext"/>
263
	            </iterate>
264
         	</with>
265
		</activeWhen>
266
    </handler>
267
    
268
    <handler
269
          class="org.eclipse.mylyn.internal.provisional.commons.ui.commands.CutLineToBeginningHandler"
270
          commandId="org.eclipse.ui.edit.text.cut.line.to.beginning">
271
         <activeWhen>
272
         	<with variable="activeContexts">
273
	            <iterate operator="or" ifEmpty="false">
274
	               <equals
275
	                     value="org.eclipse.mylyn.wikitext.tasks.ui.markupSourceContext"/>
276
	            </iterate>
277
         	</with>
278
		</activeWhen>
279
    </handler>
280
    
281
    
282
    <handler
283
          class="org.eclipse.mylyn.internal.provisional.commons.ui.commands.DeleteLineToEndHandler"
284
          commandId="org.eclipse.ui.edit.text.delete.line.to.end">
285
         <activeWhen>
286
         	<with variable="activeContexts">
287
	            <iterate operator="or" ifEmpty="false">
288
	               <equals
289
	                     value="org.eclipse.mylyn.wikitext.tasks.ui.markupSourceContext"/>
290
	            </iterate>
291
         	</with>
292
		</activeWhen>
293
    </handler>
294
    
295
    
296
    <handler
297
          class="org.eclipse.mylyn.internal.provisional.commons.ui.commands.CutLineToEndHandler"
298
          commandId="org.eclipse.ui.edit.text.cut.line.to.end">
299
         <activeWhen>
300
         	<with variable="activeContexts">
301
	            <iterate operator="or" ifEmpty="false">
302
	               <equals
303
	                     value="org.eclipse.mylyn.wikitext.tasks.ui.markupSourceContext"/>
304
	            </iterate>
305
         	</with>
306
		</activeWhen>
307
    </handler>
308
    
309
 </extension>
227
</plugin>
310
</plugin>

Return to bug 321701