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 / +39 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, TextEditorMessages.MarkerRulerAction_addMarker);
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, TextEditorMessages.MarkerRulerAction_removeMarkers);
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
	 * @param message the error message to show in case of an exception
488
	 * 
489
	 * @since 3.3
490
	 */
491
	private void execute(IUndoableOperation operation, String message) {
492
		try {
493
			PlatformUI.getWorkbench().getOperationSupport()
494
					.getOperationHistory().execute(operation, null,
495
							new IAdaptable() {
496
								public Object getAdapter(Class clazz) {
497
									if (clazz == Shell.class && getTextEditor() != null) {
498
										return getTextEditor().getSite().getShell();
499
									}
500
									return null;
501
								}
502
							});
503
		} catch (ExecutionException e) {
504
			Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
505
			ILog log= Platform.getLog(bundle);
506
			log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, message, e));
507
			String msg= getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$
508
			log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, e));
509
		}
510
	}
494
}
511
}
(-)src/org/eclipse/ui/texteditor/AddMarkerAction.java (-11 / +27 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 text to null, or
128
		} catch (CoreException x) {
131
			// resource bundle is missing.  What
129
132
			// is the proper course of action?
133
			String text = getText();
134
			if (text == null) {
135
				text = "Missing Label Text"; //$NON-NLS-1$
136
			}
137
			IUndoableOperation op = new CreateMarkersOperation(fMarkerType,
138
					attributes, resource, text);
139
			PlatformUI.getWorkbench().getOperationSupport()
140
			.getOperationHistory().execute(op, null,
141
					new IAdaptable() {
142
						public Object getAdapter(Class clazz) {
143
							if (clazz == Shell.class && getTextEditor() != null) {
144
								return getTextEditor().getSite().getShell();
145
							}
146
							return null;
147
						}
148
					});
149
		} catch (ExecutionException e) {
130
			Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
150
			Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
131
			ILog log= Platform.getLog(bundle);
151
			ILog log= Platform.getLog(bundle);
132
			log.log(x.getStatus());
152
			log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, TextEditorMessages.MarkerRulerAction_addMarker, e));
133
134
			Shell shell= getTextEditor().getSite().getShell();
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$
153
			String msg= getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$
137
154
			log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, e));
138
			ErrorDialog.openError(shell, title, msg, x.getStatus());
139
		}
155
		}
140
	}
156
	}
141
157

Return to bug 154779