This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor API refactoring of Go preference constants.
- Loading branch information
1 parent
5606493
commit 7f6e57d
Showing
7 changed files
with
191 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 105 additions & 102 deletions
207
...n_ide.ui/src/com/googlecode/goclipse/ui/editor/actions/AbstractEditorGoToolOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,103 +1,106 @@ | |||
/******************************************************************************* | /******************************************************************************* | ||
* Copyright (c) 2014 Bruno Medeiros and other Contributors. | * Copyright (c) 2014 Bruno Medeiros and other Contributors. | ||
* All rights reserved. This program and the accompanying materials | * All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | * are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | * which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | * http://www.eclipse.org/legal/epl-v10.html | ||
* | * | ||
* Contributors: | * Contributors: | ||
* Bruno Medeiros - initial API and implementation | * Bruno Medeiros - initial API and implementation | ||
*******************************************************************************/ | *******************************************************************************/ | ||
package com.googlecode.goclipse.ui.editor.actions; | package com.googlecode.goclipse.ui.editor.actions; | ||
|
|
||
|
|
||
import static melnorme.lang.ide.ui.editor.EditorUtils.getEditorDocument; | import static melnorme.lang.ide.ui.editor.EditorUtils.getEditorDocument; | ||
import static melnorme.utilbox.core.CoreUtil.areEqual; | import static melnorme.utilbox.core.CoreUtil.areEqual; | ||
|
|
||
import java.nio.file.Path; | import java.nio.file.Path; | ||
|
|
||
import org.eclipse.core.resources.IProject; | import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.CoreException; | import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.jface.text.source.ISourceViewer; | import org.eclipse.jface.text.source.ISourceViewer; | ||
import org.eclipse.jface.viewers.ISelection; | import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.ui.texteditor.ITextEditor; | import org.eclipse.ui.texteditor.ITextEditor; | ||
|
|
||
import com.googlecode.goclipse.core.GoProjectEnvironment; | import com.googlecode.goclipse.core.GoProjectEnvironment; | ||
import com.googlecode.goclipse.core.operations.GoToolManager; | import com.googlecode.goclipse.core.operations.GoToolManager; | ||
import com.googlecode.goclipse.tooling.env.GoEnvironment; | import com.googlecode.goclipse.tooling.env.GoEnvironment; | ||
import com.googlecode.goclipse.ui.editor.GoEditor; | import com.googlecode.goclipse.ui.editor.GoEditor; | ||
|
|
||
import melnorme.lang.ide.core.LangCore; | import melnorme.lang.ide.core.LangCore; | ||
import melnorme.lang.ide.ui.editor.EditorUtils; | import melnorme.lang.ide.ui.editor.EditorUtils; | ||
import melnorme.lang.ide.ui.utils.operations.AbstractEditorOperation2; | import melnorme.lang.ide.ui.utils.operations.AbstractEditorOperation2; | ||
import melnorme.utilbox.concurrency.OperationCancellation; | import melnorme.utilbox.concurrency.OperationCancellation; | ||
import melnorme.utilbox.core.CommonException; | import melnorme.utilbox.core.CommonException; | ||
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; | import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult; | ||
|
|
||
public abstract class AbstractEditorGoToolOperation extends AbstractEditorOperation2<String> { | public abstract class AbstractEditorGoToolOperation extends AbstractEditorOperation2<String> { | ||
|
|
||
protected GoEditor goEditor; | protected GoEditor goEditor; | ||
protected String editorText; | protected IProject project; // Can be null | ||
protected ProcessBuilder pb; |
|
||
|
protected ProcessBuilder pb; | ||
public AbstractEditorGoToolOperation(String operationName, ITextEditor editor) { |
|
||
super(operationName, editor); | protected String editorText; | ||
} |
|
||
|
public AbstractEditorGoToolOperation(String operationName, ITextEditor editor) { | ||
@Override | super(operationName, editor); | ||
protected void prepareOperation() throws CoreException { | } | ||
if(!(editor instanceof GoEditor)) { |
|
||
throw LangCore.createCoreException("Editor is not a GoEditor.", null); | @Override | ||
} | protected void prepareOperation() throws CoreException { | ||
goEditor = (GoEditor) editor; | if(!(editor instanceof GoEditor)) { | ||
editorText = getEditorDocument(editor).get(); | throw LangCore.createCoreException("Editor is not a GoEditor.", null); | ||
|
} | ||
IProject project = EditorUtils.getAssociatedProject(editorInput); | goEditor = (GoEditor) editor; | ||
|
editorText = getEditorDocument(editor).get(); | ||
GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project); |
|
||
|
project = EditorUtils.getAssociatedProject(editorInput); | ||
try { |
|
||
Path goSDKPath = GoToolManager.getDefault().getSDKToolPath(project); | GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project); | ||
pb = prepareProcessBuilder(goSDKPath, goEnv); |
|
||
} catch (CommonException ce) { | try { | ||
throw LangCore.createCoreException(ce); | Path goSDKPath = GoToolManager.getDefault().getSDKToolPath(project); | ||
} | pb = prepareProcessBuilder(goSDKPath, goEnv); | ||
} | } catch (CommonException ce) { | ||
|
throw LangCore.createCoreException(ce); | ||
protected abstract ProcessBuilder prepareProcessBuilder(Path goSDKPath, GoEnvironment goEnv) | } | ||
throws CoreException, CommonException; | } | ||
|
|
||
@Override | protected abstract ProcessBuilder prepareProcessBuilder(Path goSDKPath, GoEnvironment goEnv) | ||
protected String doBackgroundValueComputation(IProgressMonitor monitor) | throws CoreException, CommonException; | ||
throws CoreException, CommonException, OperationCancellation { |
|
||
ExternalProcessResult processResult = | @Override | ||
GoToolManager.getDefault().newRunToolOperation2(pb, monitor).runProcess(editorText, true); | protected String doBackgroundValueComputation(IProgressMonitor monitor) | ||
|
throws CoreException, CommonException, OperationCancellation { | ||
return processResult.getStdOutBytes().toString(); | ExternalProcessResult processResult = | ||
} | GoToolManager.getDefault().newRunToolOperation2(pb, monitor).runProcess(editorText, true); | ||
|
|
||
@Override | return processResult.getStdOutBytes().toString(); | ||
protected void handleComputationResult() throws CoreException { | } | ||
if(!areEqual(result, editorText)) { |
|
||
replaceText(goEditor.getSourceViewer_(), result); | @Override | ||
} | protected void handleComputationResult() throws CoreException { | ||
} | if(!areEqual(result, editorText)) { | ||
|
replaceText(goEditor.getSourceViewer_(), result); | ||
|
} | ||
public static void replaceText(ISourceViewer sourceViewer, String newText) { | } | ||
ISelection sel = sourceViewer.getSelectionProvider().getSelection(); |
|
||
int topIndex = sourceViewer.getTopIndex(); |
|
||
|
public static void replaceText(ISourceViewer sourceViewer, String newText) { | ||
sourceViewer.getDocument().set(newText); | ISelection sel = sourceViewer.getSelectionProvider().getSelection(); | ||
|
int topIndex = sourceViewer.getTopIndex(); | ||
if (sel != null) { |
|
||
sourceViewer.getSelectionProvider().setSelection(sel); | sourceViewer.getDocument().set(newText); | ||
} |
|
||
|
if (sel != null) { | ||
if (topIndex != -1) { | sourceViewer.getSelectionProvider().setSelection(sel); | ||
sourceViewer.setTopIndex(topIndex); | } | ||
} |
|
||
} | if (topIndex != -1) { | ||
|
sourceViewer.setTopIndex(topIndex); | ||
} | |||
} | |||
|
|||
} | } |
Oops, something went wrong.