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 154779 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/texteditor/MarkerRulerAction.java (-22 / +40 lines)
Lines 20-33 Link Here
20
20
21
import org.osgi.framework.Bundle;
21
import org.osgi.framework.Bundle;
22
22
23
import org.eclipse.core.commands.ExecutionException;
24
import org.eclipse.core.commands.operations.IUndoableOperation;
23
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IMarker;
26
import org.eclipse.core.resources.IMarker;
25
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.resources.IResource;
26
import org.eclipse.core.resources.IWorkspace;
27
import org.eclipse.core.resources.IWorkspaceRunnable;
28
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.IAdaptable;
29
import org.eclipse.core.runtime.ILog;
30
import org.eclipse.core.runtime.ILog;
30
import org.eclipse.core.runtime.IProgressMonitor;
31
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.IStatus;
32
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.core.runtime.Platform;
33
import org.eclipse.core.runtime.Status;
33
import org.eclipse.core.runtime.Status;
Lines 49-55 Link Here
49
49
50
import org.eclipse.ui.IEditorInput;
50
import org.eclipse.ui.IEditorInput;
51
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.PlatformUI;
52
52
import org.eclipse.ui.ide.undo.CreateMarkersOperation;
53
import org.eclipse.ui.ide.undo.DeleteMarkersOperation;
53
54
54
/**
55
/**
55
 * A ruler action which can add and remove markers which have a visual
56
 * A ruler action which can add and remove markers which have a visual
Lines 365-376 Link Here
365
			if (!askForLabel(attributes))
366
			if (!askForLabel(attributes))
366
				return;
367
				return;
367
		}
368
		}
368
369
		IUndoableOperation op = new CreateMarkersOperation(fMarkerType,
369
		try {
370
				attributes, resource, getText());
370
			MarkerUtilities.createMarker(resource, attributes, fMarkerType);
371
		execute(op);
371
		} catch (CoreException x) {
372
			handleCoreException(x, TextEditorMessages.MarkerRulerAction_addMarker);
373
		}
374
	}
372
	}
375
373
376
	/**
374
	/**
Lines 379-396 Link Here
379
	 * @param markers the markers to be deleted
377
	 * @param markers the markers to be deleted
380
	 */
378
	 */
381
	protected void removeMarkers(final List markers) {
379
	protected void removeMarkers(final List markers) {
382
		try {
380
		IMarker[] markersArray = (IMarker[]) markers.toArray(new IMarker[markers.size()]);
383
			getResource().getWorkspace().run(new IWorkspaceRunnable() {
381
		IUndoableOperation op = new DeleteMarkersOperation(markersArray, getText());
384
				public void run(IProgressMonitor monitor) throws CoreException {
382
		execute(op);
385
					for (int i= 0; i < markers.size(); ++i) {
386
						IMarker marker= (IMarker) markers.get(i);
387
						marker.delete();
388
					}
389
				}
390
			}, null, IWorkspace.AVOID_UPDATE, null);
391
		} catch (CoreException x) {
392
			handleCoreException(x, TextEditorMessages.MarkerRulerAction_removeMarkers);
393
		}
394
	}
383
	}
395
384
396
	/**
385
	/**
Lines 491-494 Link Here
491
			return null;
480
			return null;
492
		}
481
		}
493
	}
482
	}
483
		
484
	/**
485
	 * Execute the specified undoable operation
486
	 * @param operation the operation to execute
487
	 * 
488
	 * @since 3.3
489
	 */
490
	private void execute(IUndoableOperation operation) {
491
		try {
492
			PlatformUI.getWorkbench().getOperationSupport()
493
					.getOperationHistory().execute(operation, null,
494
							new IAdaptable() {
495
								public Object getAdapter(Class clazz) {
496
									if (clazz == Shell.class && getTextEditor() != null) {
497
										return getTextEditor().getSite().getShell();
498
									}
499
									return null;
500
								}
501
							});
502
		} catch (ExecutionException e) {
503
			// TODO: A generic error has already been shown by the undoable 
504
			// operation.  We log the error again to preserve the error message
505
			// originally used.  This may be removed if considered redundant.
506
			Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
507
			ILog log= Platform.getLog(bundle);
508
			String msg= getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$
509
			log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, e));
510
		}
511
	}
494
}
512
}
(-)src/org/eclipse/ui/texteditor/AddMarkerAction.java (-11 / +31 lines)
Lines 16-30 Link Here
16
16
17
import org.osgi.framework.Bundle;
17
import org.osgi.framework.Bundle;
18
18
19
import org.eclipse.core.commands.ExecutionException;
20
import org.eclipse.core.commands.operations.IUndoableOperation;
19
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.ILog;
23
import org.eclipse.core.runtime.ILog;
24
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.core.runtime.Status;
24
27
25
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.swt.widgets.Shell;
26
29
27
import org.eclipse.jface.dialogs.ErrorDialog;
28
import org.eclipse.jface.dialogs.IInputValidator;
30
import org.eclipse.jface.dialogs.IInputValidator;
29
import org.eclipse.jface.dialogs.InputDialog;
31
import org.eclipse.jface.dialogs.InputDialog;
30
import org.eclipse.jface.window.Window;
32
import org.eclipse.jface.window.Window;
Lines 35-40 Link Here
35
37
36
import org.eclipse.ui.IEditorInput;
38
import org.eclipse.ui.IEditorInput;
37
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.PlatformUI;
40
import org.eclipse.ui.ide.undo.CreateMarkersOperation;
38
41
39
42
40
/**
43
/**
Lines 124-141 Link Here
124
		}
127
		}
125
128
126
		try {
129
		try {
127
			MarkerUtilities.createMarker(resource, attributes, fMarkerType);
130
			// TODO:  client could have set tooltip text to null, or
128
		} catch (CoreException x) {
131
			// resource bundle is missing.  
129
132
			// Is there a better course of action than a hard coded
133
			// default or an NPE in CreateMarkersOperation?
134
			String text = getToolTipText();
135
			if (text == null) {
136
				text = "Missing Label Text (Add Marker)"; //$NON-NLS-1$
137
			}
138
			IUndoableOperation op = new CreateMarkersOperation(fMarkerType,
139
					attributes, resource, text);
140
			final ITextEditor editor = getTextEditor();
141
			PlatformUI.getWorkbench().getOperationSupport()
142
			.getOperationHistory().execute(op, null,
143
					new IAdaptable() {
144
						public Object getAdapter(Class clazz) {
145
							if (clazz == Shell.class && editor != null) {
146
								return editor.getSite().getShell();
147
							}
148
							return null;
149
						}
150
					});
151
		} catch (ExecutionException e) {
130
			Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
152
			Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
131
			ILog log= Platform.getLog(bundle);
153
			ILog log= Platform.getLog(bundle);
132
			log.log(x.getStatus());
154
			// TODO: A generic error has already been shown by the undoable 
133
155
			// operation.  We log the error again to preserve the error message
134
			Shell shell= getTextEditor().getSite().getShell();
156
			// originally used.  This may be removed if considered redundant.
135
			String title= getString(fBundle, fPrefix + "error.dialog.title", fPrefix + "error.dialog.title"); //$NON-NLS-2$ //$NON-NLS-1$
136
			String msg= getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$
157
			String msg= getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$
137
158
			log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, e));
138
			ErrorDialog.openError(shell, title, msg, x.getStatus());
139
		}
159
		}
140
	}
160
	}
141
161

Return to bug 154779