|
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 |
} |