feat(ui): supports adding or removing breakpoint on debug
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user