| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.debug.ui.actions; | 5 package org.chromium.debug.ui.actions; |
| 6 | 6 |
| 7 import java.util.List; | 7 import java.util.List; |
| 8 | 8 |
| 9 import org.chromium.debug.core.ChromiumDebugPlugin; | 9 import org.chromium.debug.core.ChromiumDebugPlugin; |
| 10 import org.chromium.debug.core.model.PushChangesPlan; | 10 import org.chromium.debug.core.model.PushChangesPlan; |
| 11 import org.chromium.debug.core.util.ScriptTargetMapping; | 11 import org.chromium.debug.core.util.ScriptTargetMapping; |
| 12 import org.chromium.debug.ui.liveedit.LiveEditResultDialog; | 12 import org.chromium.debug.ui.liveedit.LiveEditResultDialog; |
| 13 import org.chromium.debug.ui.liveedit.LiveEditResultDialog.SingleInput; |
| 13 import org.chromium.sdk.UpdatableScript; | 14 import org.chromium.sdk.UpdatableScript; |
| 14 import org.chromium.sdk.UpdatableScript.ChangeDescription; | 15 import org.chromium.sdk.UpdatableScript.ChangeDescription; |
| 15 import org.eclipse.core.runtime.IStatus; | 16 import org.eclipse.core.runtime.IStatus; |
| 16 import org.eclipse.core.runtime.Status; | 17 import org.eclipse.core.runtime.Status; |
| 17 import org.eclipse.swt.widgets.Shell; | 18 import org.eclipse.swt.widgets.Shell; |
| 18 import org.eclipse.ui.IWorkbenchPart; | 19 import org.eclipse.ui.IWorkbenchPart; |
| 20 import org.eclipse.ui.texteditor.ITextEditor; |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * The main action of LiveEdit feature. It gets the current state of a working f
ile and pushes | 23 * The main action of LiveEdit feature. It gets the current state of a working f
ile and pushes |
| 22 * it into running V8 VM. | 24 * it into running V8 VM. |
| 23 */ | 25 */ |
| 24 public class PushChangesAction extends V8ScriptAction { | 26 public class PushChangesAction extends V8ScriptAction { |
| 25 @Override | 27 @Override |
| 26 protected void execute(List<? extends ScriptTargetMapping> filePairList, Shell
shell, | 28 protected void execute(List<? extends ScriptTargetMapping> filePairList, Shell
shell, |
| 27 IWorkbenchPart workbenchPart) { | 29 IWorkbenchPart workbenchPart) { |
| 30 LiveEditResultDialog.ErrorPositionHighlighter positionHighlighter = |
| 31 createPositionHighlighter(workbenchPart); |
| 28 for (ScriptTargetMapping pair : filePairList) { | 32 for (ScriptTargetMapping pair : filePairList) { |
| 29 execute(pair, shell); | 33 execute(pair, shell, positionHighlighter); |
| 30 } | 34 } |
| 31 } | 35 } |
| 32 | 36 |
| 33 private void execute(final ScriptTargetMapping filePair, final Shell shell) { | 37 private void execute(final ScriptTargetMapping filePair, final Shell shell, |
| 38 final LiveEditResultDialog.ErrorPositionHighlighter positionHighlighter) { |
| 34 final PushChangesPlan plan = PushChangesPlan.create(filePair); | 39 final PushChangesPlan plan = PushChangesPlan.create(filePair); |
| 35 | 40 |
| 36 UpdatableScript.UpdateCallback callback = new UpdatableScript.UpdateCallback
() { | 41 UpdatableScript.UpdateCallback callback = new UpdatableScript.UpdateCallback
() { |
| 37 @Override | 42 @Override |
| 38 public void success(Object report, ChangeDescription changeDescription) { | 43 public void success(Object report, ChangeDescription changeDescription) { |
| 39 ChromiumDebugPlugin.log(new Status(IStatus.OK, ChromiumDebugPlugin.PLUGI
N_ID, | 44 ChromiumDebugPlugin.log(new Status(IStatus.OK, ChromiumDebugPlugin.PLUGI
N_ID, |
| 40 "Script has been successfully updated on remote: " + report)); //$NO
N-NLS-1$ | 45 "Script has been successfully updated on remote: " + report)); //$NO
N-NLS-1$ |
| 41 } | 46 } |
| 42 | 47 |
| 43 @Override | 48 @Override |
| 44 public void failure(final String message, UpdatableScript.Failure failure)
{ | 49 public void failure(final String message, final UpdatableScript.Failure fa
ilure) { |
| 45 shell.getDisplay().asyncExec(new Runnable() { | 50 shell.getDisplay().asyncExec(new Runnable() { |
| 46 @Override | 51 @Override |
| 47 public void run() { | 52 public void run() { |
| 48 LiveEditResultDialog dialog = new LiveEditResultDialog(shell, | 53 SingleInput textInput = LiveEditResultDialog.createTextInput(message
, plan, |
| 49 LiveEditResultDialog.createTextInput(message, plan)); | 54 failure); |
| 55 LiveEditResultDialog dialog = |
| 56 new LiveEditResultDialog(shell, textInput, positionHighlighter); |
| 50 dialog.open(); | 57 dialog.open(); |
| 51 } | 58 } |
| 52 }); | 59 }); |
| 53 } | 60 } |
| 54 }; | 61 }; |
| 55 | 62 |
| 56 plan.execute(false, callback, null); | 63 plan.execute(false, callback, null); |
| 57 } | 64 } |
| 65 |
| 66 public static LiveEditResultDialog.ErrorPositionHighlighter createPositionHigh
lighter( |
| 67 IWorkbenchPart workbenchPart) { |
| 68 if (workbenchPart instanceof ITextEditor == false) { |
| 69 return null; |
| 70 } |
| 71 final ITextEditor textEditor = (ITextEditor) workbenchPart; |
| 72 return new LiveEditResultDialog.ErrorPositionHighlighter() { |
| 73 @Override |
| 74 public void highlight(int offset, int length) { |
| 75 textEditor.selectAndReveal(offset, length); |
| 76 } |
| 77 }; |
| 78 } |
| 58 } | 79 } |
| OLD | NEW |