feat(ui): supports adding or removing breakpoint on debug
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -8,8 +8,8 @@ android {
|
|||||||
applicationId "org.autojs.autojs"
|
applicationId "org.autojs.autojs"
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 408
|
versionCode 409
|
||||||
versionName "4.0.2 Alpha3"
|
versionName "4.0.2 Alpha4"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
private int mUnmatchedBracket = -1;
|
private int mUnmatchedBracket = -1;
|
||||||
private LinkedHashMap<Integer, CodeEditor.Breakpoint> mBreakpoints = new LinkedHashMap<>();
|
private LinkedHashMap<Integer, CodeEditor.Breakpoint> mBreakpoints = new LinkedHashMap<>();
|
||||||
private int mDebuggingLine = -1;
|
private int mDebuggingLine = -1;
|
||||||
|
private CodeEditor.BreakpointChangeListener mBreakpointChangeListener;
|
||||||
|
|
||||||
|
|
||||||
public CodeEditText(Context context) {
|
public CodeEditText(Context context) {
|
||||||
@@ -474,8 +475,8 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
//当触摸有效时,对那一行设置断点或取消断点
|
//当触摸有效时,对那一行设置断点或取消断点
|
||||||
if (mTouchValid) {
|
if (mTouchValid) {
|
||||||
if (mBreakpoints.remove(mTouchedLine) == null) {
|
if (!removeBreakpoint(mTouchedLine)) {
|
||||||
mBreakpoints.put(mTouchedLine, new CodeEditor.Breakpoint(mTouchedLine));
|
addBreakpoint(mTouchedLine);
|
||||||
}
|
}
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
@@ -486,4 +487,35 @@ public class CodeEditText extends AppCompatEditText {
|
|||||||
|
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean removeBreakpoint(int line) {
|
||||||
|
boolean success = mBreakpoints.remove(line) != null;
|
||||||
|
if (success && mBreakpointChangeListener != null) {
|
||||||
|
mBreakpointChangeListener.onBreakpointChange(line, false);
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBreakpoint(int line) {
|
||||||
|
mBreakpoints.put(line, new CodeEditor.Breakpoint(line));
|
||||||
|
if (mBreakpointChangeListener != null) {
|
||||||
|
mBreakpointChangeListener.onBreakpointChange(line, true);
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBreakpointChangeListener(CodeEditor.BreakpointChangeListener listener) {
|
||||||
|
mBreakpointChangeListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAllBreakpoints() {
|
||||||
|
int size = mBreakpoints.size();
|
||||||
|
mBreakpoints.clear();
|
||||||
|
if (mBreakpointChangeListener != null) {
|
||||||
|
mBreakpointChangeListener.onAllBreakpointRemoved(size);
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ public class CodeEditor extends HVScrollView {
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isTextChanged() {
|
public boolean isTextChanged() {
|
||||||
return mTextViewRedoUndo.isTextChanged();
|
return mTextViewRedoUndo.isTextChanged();
|
||||||
}
|
}
|
||||||
@@ -183,7 +182,6 @@ public class CodeEditor extends HVScrollView {
|
|||||||
mTextViewRedoUndo.setEnabled(enabled);
|
mTextViewRedoUndo.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setProgress(boolean progress) {
|
public void setProgress(boolean progress) {
|
||||||
if (progress) {
|
if (progress) {
|
||||||
if (mProcessDialog != null) {
|
if (mProcessDialog != null) {
|
||||||
@@ -349,12 +347,14 @@ public class CodeEditor extends HVScrollView {
|
|||||||
mCodeEditText.setDebuggingLine(line);
|
mCodeEditText.setDebuggingLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBreakpointChangeListener(BreakpointChangeListener listener) {
|
||||||
|
mCodeEditText.setBreakpointChangeListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
public void addOrRemoveBreakpoint(int line) {
|
public void addOrRemoveBreakpoint(int line) {
|
||||||
LinkedHashMap<Integer, Breakpoint> breakpoints = mCodeEditText.getBreakpoints();
|
if (!mCodeEditText.removeBreakpoint(line)) {
|
||||||
if (breakpoints.remove(line) == null) {
|
mCodeEditText.addBreakpoint(line);
|
||||||
breakpoints.put(line, new Breakpoint(line));
|
|
||||||
}
|
}
|
||||||
mCodeEditText.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOrRemoveBreakpointAtCurrentLine() {
|
public void addOrRemoveBreakpointAtCurrentLine() {
|
||||||
@@ -364,12 +364,10 @@ public class CodeEditor extends HVScrollView {
|
|||||||
addOrRemoveBreakpoint(line);
|
addOrRemoveBreakpoint(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllBreakpoints(){
|
public void removeAllBreakpoints() {
|
||||||
mCodeEditText.getBreakpoints().clear();
|
mCodeEditText.removeAllBreakpoints();
|
||||||
mCodeEditText.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
int codeWidth = getWidth() - getPaddingLeft() - getPaddingRight();
|
int codeWidth = getWidth() - getPaddingLeft() - getPaddingRight();
|
||||||
@@ -391,4 +389,10 @@ public class CodeEditor extends HVScrollView {
|
|||||||
this.line = line;
|
this.line = line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface BreakpointChangeListener {
|
||||||
|
void onBreakpointChange(int line, boolean enabled);
|
||||||
|
|
||||||
|
void onAllBreakpointRemoved(int count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,12 +44,26 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
|||||||
private String mInitialEditorSourceUrl;
|
private String mInitialEditorSourceUrl;
|
||||||
private String mInitialEditorSource;
|
private String mInitialEditorSource;
|
||||||
private boolean mCursorChangeFromUser = true;
|
private boolean mCursorChangeFromUser = true;
|
||||||
|
private Dim.SourceInfo mSourceInfo;
|
||||||
private final RecyclerView.AdapterDataObserver mVariableChangeObserver = new RecyclerView.AdapterDataObserver() {
|
private final RecyclerView.AdapterDataObserver mVariableChangeObserver = new RecyclerView.AdapterDataObserver() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemRangeInserted(int positionStart, int itemCount) {
|
public void onItemRangeInserted(int positionStart, int itemCount) {
|
||||||
updateWatchingVariables(positionStart, positionStart + itemCount);
|
updateWatchingVariables(positionStart, positionStart + itemCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private CodeEditor.BreakpointChangeListener mBreakpointChangeListener = new CodeEditor.BreakpointChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onBreakpointChange(int line, boolean enabled) {
|
||||||
|
if (mSourceInfo != null) {
|
||||||
|
mSourceInfo.breakpoint(line + 1, enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAllBreakpointRemoved(int count) {
|
||||||
|
mDim.clearAllBreakpoints();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public DebugToolbarFragment() {
|
public DebugToolbarFragment() {
|
||||||
Log.d(LOG_TAG, "DebugToolbarFragment()");
|
Log.d(LOG_TAG, "DebugToolbarFragment()");
|
||||||
@@ -79,6 +93,7 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
|||||||
CodeEditor editor = mEditorView.getEditor();
|
CodeEditor editor = mEditorView.getEditor();
|
||||||
editor.setRedoUndoEnabled(false);
|
editor.setRedoUndoEnabled(false);
|
||||||
editor.addCursorChangeCallback(this);
|
editor.addCursorChangeCallback(this);
|
||||||
|
editor.setBreakpointChangeListener(mBreakpointChangeListener);
|
||||||
DebugBar debugBar = mEditorView.getDebugBar();
|
DebugBar debugBar = mEditorView.getDebugBar();
|
||||||
debugBar.registerVariableChangeObserver(mVariableChangeObserver);
|
debugBar.registerVariableChangeObserver(mVariableChangeObserver);
|
||||||
debugBar.setCodeEvaluator(this);
|
debugBar.setCodeEvaluator(this);
|
||||||
@@ -108,6 +123,7 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
|||||||
if (!mDim.isAttached()) {
|
if (!mDim.isAttached()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Log.d(LOG_TAG, "detachDebugger");
|
||||||
mDim.detach();
|
mDim.detach();
|
||||||
mDim.setGuiCallback(null);
|
mDim.setGuiCallback(null);
|
||||||
if (mEditorView == null) {
|
if (mEditorView == null) {
|
||||||
@@ -115,6 +131,8 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
|||||||
}
|
}
|
||||||
CodeEditor editor = mEditorView.getEditor();
|
CodeEditor editor = mEditorView.getEditor();
|
||||||
editor.removeCursorChangeCallback(this);
|
editor.removeCursorChangeCallback(this);
|
||||||
|
editor.setBreakpointChangeListener(null);
|
||||||
|
mSourceInfo = null;
|
||||||
editor.setRedoUndoEnabled(true);
|
editor.setRedoUndoEnabled(true);
|
||||||
if (!TextUtils.equals(mInitialEditorSourceUrl, mCurrentEditorSourceUrl)) {
|
if (!TextUtils.equals(mInitialEditorSourceUrl, mCurrentEditorSourceUrl)) {
|
||||||
editor.setText(mInitialEditorSource);
|
editor.setText(mInitialEditorSource);
|
||||||
@@ -168,6 +186,7 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
|||||||
Log.d(LOG_TAG, "not breakable: " + line);
|
Log.d(LOG_TAG, "not breakable: " + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mSourceInfo = sourceInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ public class Files {
|
|||||||
}
|
}
|
||||||
f = new File(f, path);
|
f = new File(f, path);
|
||||||
}
|
}
|
||||||
return f.getPath();
|
String path = f.getPath();
|
||||||
|
return relativePath.endsWith(File.separator) ? path + "/" : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String cwd() {
|
public String cwd() {
|
||||||
@@ -89,7 +90,7 @@ public class Files {
|
|||||||
return PFiles.read(path(path));
|
return PFiles.read(path(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readAssets(String path, String encoding){
|
public String readAssets(String path, String encoding) {
|
||||||
try {
|
try {
|
||||||
return PFiles.read(mRuntime.getUiHandler().getContext().getAssets().open(path), encoding);
|
return PFiles.read(mRuntime.getUiHandler().getContext().getAssets().open(path), encoding);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -97,11 +98,11 @@ public class Files {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readAssets(String path){
|
public String readAssets(String path) {
|
||||||
return readAssets(path, "UTF-8");
|
return readAssets(path, "UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] readBytes(String path){
|
public byte[] readBytes(String path) {
|
||||||
return PFiles.readBytes(path(path));
|
return PFiles.readBytes(path(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":408},"path":"commonRelease-4.0.2 Alpha3.apk","properties":{"packageId":"org.autojs.autojs","split":"","minSdkVersion":"17"}}]
|
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":409},"path":"commonRelease-4.0.2 Alpha4.apk","properties":{"packageId":"org.autojs.autojs","split":"","minSdkVersion":"17"}}]
|
||||||
Reference in New Issue
Block a user