Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
Fix WorkbenchOperationExecutor bug. Changed fmt operation error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Jun 17, 2016
1 parent 5fc7bb7 commit 52a222a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Expand Up @@ -47,11 +47,11 @@
import melnorme.lang.ide.ui.LangImages; import melnorme.lang.ide.ui.LangImages;
import melnorme.lang.ide.ui.LangUIPlugin; import melnorme.lang.ide.ui.LangUIPlugin;
import melnorme.lang.ide.ui.LangUIPlugin_Actual; import melnorme.lang.ide.ui.LangUIPlugin_Actual;
import melnorme.lang.ide.ui.editor.actions.AbstractEditorToolOperation;
import melnorme.lang.ide.ui.editor.actions.GotoMatchingBracketManager; import melnorme.lang.ide.ui.editor.actions.GotoMatchingBracketManager;
import melnorme.lang.ide.ui.editor.text.LangPairMatcher; import melnorme.lang.ide.ui.editor.text.LangPairMatcher;
import melnorme.lang.ide.ui.text.AbstractLangSourceViewerConfiguration; import melnorme.lang.ide.ui.text.AbstractLangSourceViewerConfiguration;
import melnorme.lang.ide.ui.utils.PluginImagesHelper.ImageHandle; import melnorme.lang.ide.ui.utils.PluginImagesHelper.ImageHandle;
import melnorme.lang.ide.ui.utils.operations.BasicUIOperation;
import melnorme.lang.utils.EnablementCounter; import melnorme.lang.utils.EnablementCounter;
import melnorme.utilbox.concurrency.ICancelMonitor; import melnorme.utilbox.concurrency.ICancelMonitor;
import melnorme.utilbox.misc.ArrayUtil; import melnorme.utilbox.misc.ArrayUtil;
Expand Down Expand Up @@ -298,7 +298,8 @@ protected void performSave(boolean overwrite, IProgressMonitor pm) {
if(saveActionsEnablement.isEnabled()) { if(saveActionsEnablement.isEnabled()) {
IProject associatedProject = EditorUtils.getAssociatedProject(getEditorInput()); IProject associatedProject = EditorUtils.getAssociatedProject(getEditorInput());
if(ToolchainPreferences.FORMAT_ON_SAVE.getEffectiveValue(associatedProject)) { if(ToolchainPreferences.FORMAT_ON_SAVE.getEffectiveValue(associatedProject)) {
BasicUIOperation formatOperation = LangUIPlugin_Actual.getFormatOperation(this); AbstractEditorToolOperation<?> formatOperation = LangUIPlugin_Actual.getFormatOperation(this);
formatOperation.handleSoftFailureWithDialog = false;
formatOperation.executeAndHandle(); formatOperation.executeAndHandle();
} }
} }
Expand Down
Expand Up @@ -32,6 +32,8 @@


public abstract class AbstractEditorToolOperation<RESULT> extends AbstractEditorOperation2<ToolResponse<RESULT>> { public abstract class AbstractEditorToolOperation<RESULT> extends AbstractEditorOperation2<ToolResponse<RESULT>> {


public boolean handleSoftFailureWithDialog = true;

public AbstractEditorToolOperation(String operationName, ITextEditor editor) { public AbstractEditorToolOperation(String operationName, ITextEditor editor) {
super(operationName, editor); super(operationName, editor);
} }
Expand Down Expand Up @@ -80,13 +82,14 @@ protected void handleComputationResult(ToolResponse<RESULT> response) throws Com
protected abstract void handleResultData(RESULT resultData) throws CommonException; protected abstract void handleResultData(RESULT resultData) throws CommonException;


protected void handleStatus(IStatusMessage status) { protected void handleStatus(IStatusMessage status) {
String statusMsg = status.getMessage().trim(); String statusMessage = status.getMessage().trim();
if(statusMsg.contains("\n")) {
if(handleSoftFailureWithDialog) {
// Use a dialog // Use a dialog
UIOperationsStatusHandler.displayStatusMessage(operationName, status.getSeverity(), statusMsg); UIOperationsStatusHandler.displayStatusMessage(operationName, status.getSeverity(), statusMessage);
} else { } else {
// Just use status // Note, message may have newlines, if so, only first line will be displayed
EditorUtils.setStatusLineErrorMessage(editor, statusMsg, null); EditorUtils.setStatusLineErrorMessage(editor, statusMessage, null);
Display.getCurrent().beep(); Display.getCurrent().beep();
} }
} }
Expand Down
Expand Up @@ -38,23 +38,23 @@
public class WorkbenchOperationExecutor { public class WorkbenchOperationExecutor {


protected final boolean allowBackgroundAlready; protected final boolean allowBackgroundAlready;
protected final boolean fork; protected final boolean executeInUIOnly;


public WorkbenchOperationExecutor() { public WorkbenchOperationExecutor() {
this(false); this(false);
} }


public WorkbenchOperationExecutor(boolean executeInUIOnly) { public WorkbenchOperationExecutor(boolean executeInUIOnly) {
super(); super();
this.fork = !executeInUIOnly; this.executeInUIOnly = executeInUIOnly;
this.allowBackgroundAlready = !executeInUIOnly; this.allowBackgroundAlready = !executeInUIOnly;
} }


protected final void runRunnableWithProgress(IRunnableWithProgress progressRunnable) protected final void runRunnableWithProgress(IRunnableWithProgress progressRunnable)
throws InvocationTargetException, InterruptedException { throws InvocationTargetException, InterruptedException {


if(allowBackgroundAlready && Display.getCurrent() == null) { if(allowBackgroundAlready && Display.getCurrent() == null) {
assertTrue(fork == false); assertTrue(executeInUIOnly == false);
// Perform computation directly in this thread, but cancellation won't be possible. // Perform computation directly in this thread, but cancellation won't be possible.
progressRunnable.run(new NullProgressMonitor()); progressRunnable.run(new NullProgressMonitor());
} else { } else {
Expand All @@ -68,7 +68,7 @@ protected final void runRunnableWithProgress(IRunnableWithProgress progressRunna
protected void doRunRunnableWithProgress(IRunnableWithProgress progressRunnable) protected void doRunRunnableWithProgress(IRunnableWithProgress progressRunnable)
throws InvocationTargetException, InterruptedException { throws InvocationTargetException, InterruptedException {
IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
progressService.run(fork, true, progressRunnable); progressService.run(!executeInUIOnly, true, progressRunnable);
} }


public void execute(CommonOperation coreOperation) throws CommonException, OperationCancellation { public void execute(CommonOperation coreOperation) throws CommonException, OperationCancellation {
Expand Down Expand Up @@ -149,7 +149,7 @@ public ProgressMonitorDialogOpRunner(Shell shell) {
@Override @Override
protected void doRunRunnableWithProgress(IRunnableWithProgress progressRunnable) protected void doRunRunnableWithProgress(IRunnableWithProgress progressRunnable)
throws InvocationTargetException, InterruptedException { throws InvocationTargetException, InterruptedException {
progressMonitorDialog.run(fork, true, progressRunnable); progressMonitorDialog.run(!executeInUIOnly, true, progressRunnable);
} }
} }


Expand Down
Expand Up @@ -8,13 +8,13 @@
import com.googlecode.goclipse.ui.GoPluginImages; import com.googlecode.goclipse.ui.GoPluginImages;
import com.googlecode.goclipse.ui.GoStructureElementLabelProvider; import com.googlecode.goclipse.ui.GoStructureElementLabelProvider;
import com.googlecode.goclipse.ui.editor.GoDocTextHover; import com.googlecode.goclipse.ui.editor.GoDocTextHover;
import com.googlecode.goclipse.ui.editor.actions.GoFmtOperation; import com.googlecode.goclipse.ui.editor.actions.GoFmtEditorOperation;
import com.googlecode.goclipse.ui.editor.text.GoAutoEditStrategy; import com.googlecode.goclipse.ui.editor.text.GoAutoEditStrategy;


import melnorme.lang.ide.core.LangCore_Actual; import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.ui.editor.actions.AbstractEditorToolOperation;
import melnorme.lang.ide.ui.editor.hover.ILangEditorTextHover; import melnorme.lang.ide.ui.editor.hover.ILangEditorTextHover;
import melnorme.lang.ide.ui.editor.text.LangAutoEditsPreferencesAccess; import melnorme.lang.ide.ui.editor.text.LangAutoEditsPreferencesAccess;
import melnorme.lang.ide.ui.utils.operations.BasicUIOperation;
import melnorme.lang.ide.ui.views.StructureElementLabelProvider; import melnorme.lang.ide.ui.views.StructureElementLabelProvider;


/** /**
Expand Down Expand Up @@ -57,8 +57,8 @@ public static StructureElementLabelProvider getStructureElementLabelProvider() {


/* ----------------- ----------------- */ /* ----------------- ----------------- */


public static BasicUIOperation getFormatOperation(ITextEditor editor) { public static AbstractEditorToolOperation<?> getFormatOperation(ITextEditor editor) {
return new GoFmtOperation(editor); return new GoFmtEditorOperation(editor);
} }


} }

0 comments on commit 52a222a

Please sign in to comment.