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"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 408
|
||||
versionName "4.0.2 Alpha3"
|
||||
versionCode 409
|
||||
versionName "4.0.2 Alpha4"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
|
||||
@@ -69,6 +69,7 @@ public class CodeEditText extends AppCompatEditText {
|
||||
private int mUnmatchedBracket = -1;
|
||||
private LinkedHashMap<Integer, CodeEditor.Breakpoint> mBreakpoints = new LinkedHashMap<>();
|
||||
private int mDebuggingLine = -1;
|
||||
private CodeEditor.BreakpointChangeListener mBreakpointChangeListener;
|
||||
|
||||
|
||||
public CodeEditText(Context context) {
|
||||
@@ -474,8 +475,8 @@ public class CodeEditText extends AppCompatEditText {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
//当触摸有效时,对那一行设置断点或取消断点
|
||||
if (mTouchValid) {
|
||||
if (mBreakpoints.remove(mTouchedLine) == null) {
|
||||
mBreakpoints.put(mTouchedLine, new CodeEditor.Breakpoint(mTouchedLine));
|
||||
if (!removeBreakpoint(mTouchedLine)) {
|
||||
addBreakpoint(mTouchedLine);
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
@@ -486,4 +487,35 @@ public class CodeEditText extends AppCompatEditText {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
public boolean isTextChanged() {
|
||||
return mTextViewRedoUndo.isTextChanged();
|
||||
}
|
||||
@@ -183,7 +182,6 @@ public class CodeEditor extends HVScrollView {
|
||||
mTextViewRedoUndo.setEnabled(enabled);
|
||||
}
|
||||
|
||||
|
||||
public void setProgress(boolean progress) {
|
||||
if (progress) {
|
||||
if (mProcessDialog != null) {
|
||||
@@ -349,12 +347,14 @@ public class CodeEditor extends HVScrollView {
|
||||
mCodeEditText.setDebuggingLine(line);
|
||||
}
|
||||
|
||||
public void setBreakpointChangeListener(BreakpointChangeListener listener) {
|
||||
mCodeEditText.setBreakpointChangeListener(listener);
|
||||
}
|
||||
|
||||
public void addOrRemoveBreakpoint(int line) {
|
||||
LinkedHashMap<Integer, Breakpoint> breakpoints = mCodeEditText.getBreakpoints();
|
||||
if (breakpoints.remove(line) == null) {
|
||||
breakpoints.put(line, new Breakpoint(line));
|
||||
if (!mCodeEditText.removeBreakpoint(line)) {
|
||||
mCodeEditText.addBreakpoint(line);
|
||||
}
|
||||
mCodeEditText.invalidate();
|
||||
}
|
||||
|
||||
public void addOrRemoveBreakpointAtCurrentLine() {
|
||||
@@ -364,12 +364,10 @@ public class CodeEditor extends HVScrollView {
|
||||
addOrRemoveBreakpoint(line);
|
||||
}
|
||||
|
||||
public void removeAllBreakpoints(){
|
||||
mCodeEditText.getBreakpoints().clear();
|
||||
mCodeEditText.invalidate();
|
||||
public void removeAllBreakpoints() {
|
||||
mCodeEditText.removeAllBreakpoints();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int codeWidth = getWidth() - getPaddingLeft() - getPaddingRight();
|
||||
@@ -391,4 +389,10 @@ public class CodeEditor extends HVScrollView {
|
||||
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 mInitialEditorSource;
|
||||
private boolean mCursorChangeFromUser = true;
|
||||
private Dim.SourceInfo mSourceInfo;
|
||||
private final RecyclerView.AdapterDataObserver mVariableChangeObserver = new RecyclerView.AdapterDataObserver() {
|
||||
@Override
|
||||
public void onItemRangeInserted(int positionStart, int 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() {
|
||||
Log.d(LOG_TAG, "DebugToolbarFragment()");
|
||||
@@ -79,6 +93,7 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
CodeEditor editor = mEditorView.getEditor();
|
||||
editor.setRedoUndoEnabled(false);
|
||||
editor.addCursorChangeCallback(this);
|
||||
editor.setBreakpointChangeListener(mBreakpointChangeListener);
|
||||
DebugBar debugBar = mEditorView.getDebugBar();
|
||||
debugBar.registerVariableChangeObserver(mVariableChangeObserver);
|
||||
debugBar.setCodeEvaluator(this);
|
||||
@@ -108,6 +123,7 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
if (!mDim.isAttached()) {
|
||||
return;
|
||||
}
|
||||
Log.d(LOG_TAG, "detachDebugger");
|
||||
mDim.detach();
|
||||
mDim.setGuiCallback(null);
|
||||
if (mEditorView == null) {
|
||||
@@ -115,6 +131,8 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
}
|
||||
CodeEditor editor = mEditorView.getEditor();
|
||||
editor.removeCursorChangeCallback(this);
|
||||
editor.setBreakpointChangeListener(null);
|
||||
mSourceInfo = null;
|
||||
editor.setRedoUndoEnabled(true);
|
||||
if (!TextUtils.equals(mInitialEditorSourceUrl, mCurrentEditorSourceUrl)) {
|
||||
editor.setText(mInitialEditorSource);
|
||||
@@ -168,6 +186,7 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
Log.d(LOG_TAG, "not breakable: " + line);
|
||||
}
|
||||
}
|
||||
mSourceInfo = sourceInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,7 +37,8 @@ public class Files {
|
||||
}
|
||||
f = new File(f, path);
|
||||
}
|
||||
return f.getPath();
|
||||
String path = f.getPath();
|
||||
return relativePath.endsWith(File.separator) ? path + "/" : path;
|
||||
}
|
||||
|
||||
public String cwd() {
|
||||
@@ -89,7 +90,7 @@ public class Files {
|
||||
return PFiles.read(path(path));
|
||||
}
|
||||
|
||||
public String readAssets(String path, String encoding){
|
||||
public String readAssets(String path, String encoding) {
|
||||
try {
|
||||
return PFiles.read(mRuntime.getUiHandler().getContext().getAssets().open(path), encoding);
|
||||
} 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");
|
||||
}
|
||||
|
||||
public byte[] readBytes(String path){
|
||||
public byte[] readBytes(String 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