add: jump, find, replace, copy, paste for editor
@@ -166,10 +166,13 @@
|
|||||||
|
|
||||||
function findNext(cm, rev, callback) {cm.operation(function() {
|
function findNext(cm, rev, callback) {cm.operation(function() {
|
||||||
var state = getSearchState(cm);
|
var state = getSearchState(cm);
|
||||||
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
|
var query = parseQuery(state.query);
|
||||||
if (!cursor.find(rev)) {
|
var cursor = getSearchCursor(cm, query, rev ? state.posFrom : state.posTo);
|
||||||
cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
|
var match = cursor.find(rev);
|
||||||
if (!cursor.find(rev)) return;
|
if (!match) {
|
||||||
|
cursor = getSearchCursor(cm, query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
|
||||||
|
match = cursor.find(rev);
|
||||||
|
if (!match) return;
|
||||||
}
|
}
|
||||||
cm.setSelection(cursor.from(), cursor.to());
|
cm.setSelection(cursor.from(), cursor.to());
|
||||||
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
|
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
|
||||||
@@ -202,42 +205,12 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function replace(cm, all) {
|
function replaceSelection(cm) {
|
||||||
if (cm.getOption("readOnly")) return;
|
var text = parseString(cm.state.search.text);
|
||||||
var query = cm.getSelection() || getSearchState(cm).lastQuery;
|
var query = parseQuery(cm.state.search.query);
|
||||||
var dialogText = '<span class="CodeMirror-search-label">' + (all ? 'Replace all:' : 'Replace:') + '</span>';
|
var match = cm.getRange(cm.state.search.posFrom, cm.state.search.posTo).match(query);
|
||||||
dialog(cm, dialogText + replaceQueryDialog, dialogText, query, function(query) {
|
cm.replaceSelection(typeof query == "string" ? text :
|
||||||
if (!query) return;
|
text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
|
||||||
query = parseQuery(query);
|
|
||||||
dialog(cm, replacementQueryDialog, "Replace with:", "", function(text) {
|
|
||||||
text = parseString(text)
|
|
||||||
if (all) {
|
|
||||||
replaceAll(cm, query, text)
|
|
||||||
} else {
|
|
||||||
clearSearch(cm);
|
|
||||||
var cursor = getSearchCursor(cm, query, cm.getCursor("from"));
|
|
||||||
var advance = function() {
|
|
||||||
var start = cursor.from(), match;
|
|
||||||
if (!(match = cursor.findNext())) {
|
|
||||||
cursor = getSearchCursor(cm, query);
|
|
||||||
if (!(match = cursor.findNext()) ||
|
|
||||||
(start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
|
|
||||||
}
|
|
||||||
cm.setSelection(cursor.from(), cursor.to());
|
|
||||||
cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
|
|
||||||
confirmDialog(cm, doReplaceConfirm, "Replace?",
|
|
||||||
[function() {doReplace(match);}, advance,
|
|
||||||
function() {replaceAll(cm, query, text)}]);
|
|
||||||
};
|
|
||||||
var doReplace = function(match) {
|
|
||||||
cursor.replace(typeof query == "string" ? text :
|
|
||||||
text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
|
|
||||||
advance();
|
|
||||||
};
|
|
||||||
advance();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
|
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
|
||||||
@@ -247,6 +220,13 @@
|
|||||||
CodeMirror.commands.findNext = doSearch;
|
CodeMirror.commands.findNext = doSearch;
|
||||||
CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
|
CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
|
||||||
CodeMirror.commands.clearSearch = clearSearch;
|
CodeMirror.commands.clearSearch = clearSearch;
|
||||||
CodeMirror.commands.replace = replace;
|
CodeMirror.commands.replace = replaceSelection;
|
||||||
CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
|
CodeMirror.commands.replaceAll = function(cm) {
|
||||||
|
if (cm.getOption("readOnly")) return;
|
||||||
|
var query = cm.state.search.query;
|
||||||
|
var text = cm.state.search.text;
|
||||||
|
query = parseQuery(query);
|
||||||
|
text = parseString(text);
|
||||||
|
replaceAll(cm, query, text);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
height: 300px;
|
height: 300px;
|
||||||
color: black;
|
color: black;
|
||||||
direction: ltr;
|
direction: ltr;
|
||||||
font-size: 35px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PADDING */
|
/* PADDING */
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
<script src="codemirror/addon/fold/indent-fold.js"></script>
|
<script src="codemirror/addon/fold/indent-fold.js"></script>
|
||||||
<script src="codemirror/addon/fold/comment-fold.js"></script>
|
<script src="codemirror/addon/fold/comment-fold.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<!-- 代码补全 -->
|
<!-- 代码补全 -->
|
||||||
<link rel="stylesheet" href="codemirror/addon/hint/show-hint.css">
|
<link rel="stylesheet" href="codemirror/addon/hint/show-hint.css">
|
||||||
<script src="codemirror/addon/hint/javascript-hint.js"></script>
|
<script src="codemirror/addon/hint/javascript-hint.js"></script>
|
||||||
@@ -36,6 +37,11 @@
|
|||||||
<!-- 代码格式化 -->
|
<!-- 代码格式化 -->
|
||||||
<script type="text/javascript" src="beautify/beautify.min.js"></script>
|
<script type="text/javascript" src="beautify/beautify.min.js"></script>
|
||||||
|
|
||||||
|
<!-- 查找替换 -->
|
||||||
|
<script type="text/javascript" src="codemirror/addon/search/search.js"></script>
|
||||||
|
<script type="text/javascript" src="codemirror/addon/search/searchcursor.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>CodeMirrorEditor</title>
|
<title>CodeMirrorEditor</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -59,5 +65,6 @@
|
|||||||
editor.on("keyup", function(cm, e) {
|
editor.on("keyup", function(cm, e) {
|
||||||
editor.execCommand("autocomplete")
|
editor.execCommand("autocomplete")
|
||||||
})
|
})
|
||||||
|
editor.setCursor({line: 0, ch: 0});
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
@@ -3,7 +3,9 @@ package com.stardust.scriptdroid.script;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.stardust.autojs.engine.RhinoJavaScriptEngine;
|
||||||
import com.stardust.autojs.execution.ExecutionConfig;
|
import com.stardust.autojs.execution.ExecutionConfig;
|
||||||
import com.stardust.autojs.execution.ScriptExecution;
|
import com.stardust.autojs.execution.ScriptExecution;
|
||||||
import com.stardust.autojs.execution.ScriptExecutionListener;
|
import com.stardust.autojs.execution.ScriptExecutionListener;
|
||||||
@@ -21,6 +23,8 @@ import com.stardust.scriptdroid.script.sample.Sample;
|
|||||||
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
import com.stardust.scriptdroid.ui.edit.EditActivity;
|
||||||
import com.stardust.util.AssetsCache;
|
import com.stardust.util.AssetsCache;
|
||||||
|
|
||||||
|
import org.mozilla.javascript.RhinoException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +35,8 @@ public class Scripts {
|
|||||||
|
|
||||||
public static final String ACTION_ON_EXECUTION_FINISHED = "Don't leave me alone...";
|
public static final String ACTION_ON_EXECUTION_FINISHED = "Don't leave me alone...";
|
||||||
public static final String EXTRA_EXCEPTION_MESSAGE = "Say something...Eating...17.5.3";
|
public static final String EXTRA_EXCEPTION_MESSAGE = "Say something...Eating...17.5.3";
|
||||||
|
public static final String EXTRA_EXCEPTION_LINE_NUMBER = "Can we fall in love with each other again...17.9.28";
|
||||||
|
public static final String EXTRA_EXCEPTION_COLUMN_NUMBER = "I lost myself....";
|
||||||
|
|
||||||
private static final ScriptExecutionListener BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER = new SimpleScriptExecutionListener() {
|
private static final ScriptExecutionListener BROADCAST_SENDER_SCRIPT_EXECUTION_LISTENER = new SimpleScriptExecutionListener() {
|
||||||
|
|
||||||
@@ -41,11 +47,21 @@ public class Scripts {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onException(ScriptExecution execution, Exception e) {
|
public void onException(ScriptExecution execution, Exception e) {
|
||||||
|
RhinoException rhinoException = getRhinoException(e);
|
||||||
|
int line = -1, col = 0;
|
||||||
|
if (rhinoException != null) {
|
||||||
|
line = rhinoException.lineNumber();
|
||||||
|
col = rhinoException.columnNumber();
|
||||||
|
}
|
||||||
if (ScriptInterruptedException.causedByInterrupted(e)) {
|
if (ScriptInterruptedException.causedByInterrupted(e)) {
|
||||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED));
|
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
||||||
|
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
|
||||||
|
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
|
||||||
} else {
|
} else {
|
||||||
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
|
||||||
.putExtra(EXTRA_EXCEPTION_MESSAGE, e.getMessage()));
|
.putExtra(EXTRA_EXCEPTION_MESSAGE, e.getMessage())
|
||||||
|
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
|
||||||
|
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,4 +130,15 @@ public class Scripts {
|
|||||||
.path(directoryPath, StorageFileProvider.DEFAULT_DIRECTORY_PATH)
|
.path(directoryPath, StorageFileProvider.DEFAULT_DIRECTORY_PATH)
|
||||||
.loop(delay, loopTimes, interval));
|
.loop(delay, loopTimes, interval));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static RhinoException getRhinoException(Throwable e) {
|
||||||
|
while (e != null) {
|
||||||
|
if (e instanceof RhinoException) {
|
||||||
|
return (RhinoException) e;
|
||||||
|
}
|
||||||
|
e = e.getCause();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import android.widget.FrameLayout;
|
|||||||
|
|
||||||
import com.stardust.pio.PFile;
|
import com.stardust.pio.PFile;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringEscapeUtils;
|
||||||
import org.jdeferred.Deferred;
|
import org.jdeferred.Deferred;
|
||||||
import org.jdeferred.DoneCallback;
|
import org.jdeferred.DoneCallback;
|
||||||
import org.jdeferred.impl.DeferredObject;
|
import org.jdeferred.impl.DeferredObject;
|
||||||
@@ -40,6 +41,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
|
|
||||||
private static final String LOG_TAG = "CodeMirrorEditor";
|
private static final String LOG_TAG = "CodeMirrorEditor";
|
||||||
|
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onChange();
|
void onChange();
|
||||||
|
|
||||||
@@ -54,6 +56,11 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private Deferred<Void, Void, Void> mPageFinished = new DeferredObject<>();
|
private Deferred<Void, Void, Void> mPageFinished = new DeferredObject<>();
|
||||||
|
|
||||||
|
private PublishSubject<String> mStringFromJs;
|
||||||
|
private PublishSubject<Integer> mIntFromJs;
|
||||||
|
private String mTextFromAndroid;
|
||||||
|
|
||||||
|
|
||||||
public CodeMirrorEditor(Context context) {
|
public CodeMirrorEditor(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init();
|
init();
|
||||||
@@ -143,9 +150,9 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
WebSettings settings = mWebView.getSettings();
|
WebSettings settings = mWebView.getSettings();
|
||||||
settings.setUseWideViewPort(true);
|
settings.setUseWideViewPort(true);
|
||||||
settings.setBuiltInZoomControls(true);
|
settings.setBuiltInZoomControls(true);
|
||||||
settings.setLoadWithOverviewMode(true);
|
//settings.setLoadWithOverviewMode(true);
|
||||||
settings.setJavaScriptEnabled(true);
|
settings.setJavaScriptEnabled(true);
|
||||||
settings.setUseWideViewPort(true);
|
//settings.setUseWideViewPort(true);
|
||||||
settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
||||||
settings.setDomStorageEnabled(true);
|
settings.setDomStorageEnabled(true);
|
||||||
settings.setNeedInitialFocus(true);
|
settings.setNeedInitialFocus(true);
|
||||||
@@ -159,15 +166,24 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setText(final String text) {
|
public void setText(final String text) {
|
||||||
mJavaScriptBridge.mTextFromAndroid = text;
|
mTextFromAndroid = text;
|
||||||
mPageFinished.promise().done(new DoneCallback<Void>() {
|
mPageFinished.promise().done(new DoneCallback<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void onDone(Void result) {
|
public void onDone(Void result) {
|
||||||
evalJavaScript("editor.setValue(__bridge__.getText());");
|
evalJavaScript("editor.setValue(__bridge__.getStringFromAndroid());");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insert(String text) {
|
||||||
|
mTextFromAndroid = text;
|
||||||
|
mPageFinished.promise().done(new DoneCallback<Void>() {
|
||||||
|
@Override
|
||||||
|
public void onDone(Void result) {
|
||||||
|
evalJavaScript("editor.replaceSelection(__bridge__.getStringFromAndroid());");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void loadFile(final File file) {
|
public void loadFile(final File file) {
|
||||||
setProgress(true);
|
setProgress(true);
|
||||||
@@ -188,9 +204,26 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Observable<String> getText() {
|
public Observable<String> getText() {
|
||||||
mJavaScriptBridge.mTextFromJs = PublishSubject.create();
|
mStringFromJs = PublishSubject.create();
|
||||||
evalJavaScript("__bridge__.setText(editor.getValue());");
|
evalJavaScript("__bridge__.setStringFromJs(editor.getValue());");
|
||||||
return mJavaScriptBridge.mTextFromJs;
|
return mStringFromJs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Observable<String> getLine() {
|
||||||
|
mStringFromJs = PublishSubject.create();
|
||||||
|
evalJavaScript("__bridge__.setStringFromJs(editor.getLine(editor.getCursor().line))");
|
||||||
|
return mStringFromJs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteLine() {
|
||||||
|
evalJavaScript("editor.replaceRange('', {line: editor.getCursor().line, ch: 0}," +
|
||||||
|
" {line: editor.getCursor().line + 1, ch: 0});");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Observable<Integer> getLineCount() {
|
||||||
|
mIntFromJs = PublishSubject.create();
|
||||||
|
evalJavaScript("__bridge__.setIntFromJs(editor.lineCount())");
|
||||||
|
return mIntFromJs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -202,6 +235,50 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
evalJavaScript("editor.redo();");
|
evalJavaScript("editor.redo();");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void jumpTo(int line, int col) {
|
||||||
|
evalJavaScript("editor.setCursor({line: " + line + ", ch: " + col + "});");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void find(String keywords, boolean usingRegex) {
|
||||||
|
setQuery(keywords, usingRegex);
|
||||||
|
findNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setQuery(String keywords, boolean usingRegex) {
|
||||||
|
keywords = keywords.replace("'", "\'");
|
||||||
|
if (usingRegex) {
|
||||||
|
keywords = "/" + keywords + "/";
|
||||||
|
}
|
||||||
|
evalJavaScript("editor.execCommand('clearSearch'); editor.state.search.query = '" +
|
||||||
|
keywords + "';");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void findNext() {
|
||||||
|
evalJavaScript("editor.execCommand('findNext');");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void findPrev() {
|
||||||
|
evalJavaScript("editor.execCommand('findPrev');");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replaceAll(String keywords, String replacement, boolean usingRegex) {
|
||||||
|
setQuery(keywords, usingRegex);
|
||||||
|
replacement = replacement.replace("'", "\'");
|
||||||
|
evalJavaScript("editor.state.search.text = '" + replacement + "';");
|
||||||
|
evalJavaScript("editor.execCommand('replaceAll');");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replace(String keywords, String replacement, boolean usingRegex) {
|
||||||
|
setQuery(keywords, usingRegex);
|
||||||
|
replacement = replacement.replace("'", "\'");
|
||||||
|
evalJavaScript("editor.state.search.text = '" + replacement + "';");
|
||||||
|
findNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replaceSelection() {
|
||||||
|
evalJavaScript("editor.execCommand('replace');");
|
||||||
|
}
|
||||||
|
|
||||||
private void evalJavaScript(String script) {
|
private void evalJavaScript(String script) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
mWebView.evaluateJavascript(script, null);
|
mWebView.evaluateJavascript(script, null);
|
||||||
@@ -217,27 +294,33 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
|
|
||||||
public class JavaScriptBridge {
|
public class JavaScriptBridge {
|
||||||
|
|
||||||
private PublishSubject<String> mTextFromJs;
|
|
||||||
private String mTextFromAndroid;
|
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void setText(String text) {
|
public void setStringFromJs(String text) {
|
||||||
if (mTextFromJs != null) {
|
if (mStringFromJs != null) {
|
||||||
mTextFromJs.onNext(text);
|
mStringFromJs.onNext(text);
|
||||||
mTextFromJs.onComplete();
|
mStringFromJs.onComplete();
|
||||||
mTextFromJs = null;
|
mStringFromJs = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public String getText() {
|
public void setIntFromJs(int i) {
|
||||||
|
if (mIntFromJs != null) {
|
||||||
|
mIntFromJs.onNext(i);
|
||||||
|
mIntFromJs.onComplete();
|
||||||
|
mIntFromJs = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public String getStringFromAndroid() {
|
||||||
String t = mTextFromAndroid;
|
String t = mTextFromAndroid;
|
||||||
mTextFromAndroid = null;
|
mTextFromAndroid = null;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void onChange() {
|
public void onTextChange() {
|
||||||
if (mCallback != null) {
|
if (mCallback != null) {
|
||||||
mWebView.post(new Runnable() {
|
mWebView.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -260,12 +343,11 @@ public class CodeMirrorEditor extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MyWebViewClient extends WebViewClient {
|
private class MyWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
private final String INIT_SCRIPT = "editor.on('change', function(){__bridge__.onChange();});";
|
private final String INIT_SCRIPT = "editor.on('change', function(){__bridge__.onTextChange();});";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
|
|||||||
@@ -1,11 +1,24 @@
|
|||||||
package com.stardust.scriptdroid.ui.edit;
|
package com.stardust.scriptdroid.ui.edit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.text.InputType;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.stardust.autojs.engine.JavaScriptEngine;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
import com.stardust.pio.PFile;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||||
import com.stardust.scriptdroid.script.Scripts;
|
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||||
|
import com.stardust.util.ClipboardUtil;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.annotations.NonNull;
|
||||||
|
import io.reactivex.functions.BiFunction;
|
||||||
|
import io.reactivex.functions.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/9/28.
|
* Created by Stardust on 2017/9/28.
|
||||||
@@ -14,9 +27,13 @@ import com.stardust.scriptdroid.script.Scripts;
|
|||||||
public class EditorMenu {
|
public class EditorMenu {
|
||||||
|
|
||||||
private EditorView mEditorView;
|
private EditorView mEditorView;
|
||||||
|
private Context mContext;
|
||||||
|
private CodeMirrorEditor mEditor;
|
||||||
|
|
||||||
public EditorMenu(EditorView editor) {
|
public EditorMenu(EditorView editorView) {
|
||||||
mEditorView = editor;
|
mEditorView = editorView;
|
||||||
|
mContext = editorView.getContext();
|
||||||
|
mEditor = editorView.mEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
@@ -27,22 +44,156 @@ public class EditorMenu {
|
|||||||
case R.id.action_log:
|
case R.id.action_log:
|
||||||
showLog();
|
showLog();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_editor_theme:
|
case R.id.action_force_stop:
|
||||||
mEditorView.selectEditorTheme();
|
forceStop();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_jump:
|
||||||
|
jump();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
if (onEditOptionsSelected(item)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (onMoreOptionsSelected(item)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean onMoreOptionsSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
case R.id.action_beautify:
|
case R.id.action_beautify:
|
||||||
beautifyCode();
|
beautifyCode();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_editor_theme:
|
||||||
|
mEditorView.selectEditorTheme();
|
||||||
|
return true;
|
||||||
case R.id.action_open_by_other_apps:
|
case R.id.action_open_by_other_apps:
|
||||||
openByOtherApps();
|
openByOtherApps();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_force_stop:
|
case R.id.action_info:
|
||||||
forceStop();
|
showInfo();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean onEditOptionsSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.action_find_or_replace:
|
||||||
|
findOrReplace();
|
||||||
|
return true;
|
||||||
|
case R.id.action_copy_all:
|
||||||
|
copyAll();
|
||||||
|
return true;
|
||||||
|
case R.id.action_paste:
|
||||||
|
paste();
|
||||||
|
return true;
|
||||||
|
case R.id.action_copy_line:
|
||||||
|
copyLine();
|
||||||
|
return true;
|
||||||
|
case R.id.action_delete_line:
|
||||||
|
deleteLine();
|
||||||
|
return true;
|
||||||
|
case R.id.action_clear:
|
||||||
|
mEditor.setText("");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void jump() {
|
||||||
|
mEditor.getLineCount()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Consumer<Integer>() {
|
||||||
|
@Override
|
||||||
|
public void accept(@NonNull Integer lineCount) throws Exception {
|
||||||
|
showJumpDialog(lineCount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showJumpDialog(final int lineCount) {
|
||||||
|
String hint = "1 ~ " + lineCount;
|
||||||
|
new ThemeColorMaterialDialogBuilder(mContext)
|
||||||
|
.title(R.string.text_jump_to_line)
|
||||||
|
.input(hint, "", new MaterialDialog.InputCallback() {
|
||||||
|
@Override
|
||||||
|
public void onInput(@android.support.annotation.NonNull MaterialDialog dialog, CharSequence input) {
|
||||||
|
int line = Integer.parseInt(input.toString());
|
||||||
|
mEditor.jumpTo(line - 1, 0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.inputType(InputType.TYPE_CLASS_NUMBER)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showInfo() {
|
||||||
|
Observable.zip(mEditor.getText(), mEditor.getLineCount(), new BiFunction<String, Integer, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(@NonNull String text, @NonNull Integer lineCount) throws Exception {
|
||||||
|
String size = PFile.getHumanReadableSize(text.length());
|
||||||
|
return String.format(Locale.getDefault(), mContext.getString(R.string.format_editor_info),
|
||||||
|
text.length(), lineCount, size);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Consumer<String>() {
|
||||||
|
@Override
|
||||||
|
public void accept(@NonNull String info) throws Exception {
|
||||||
|
showInfo(info);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showInfo(String info) {
|
||||||
|
new ThemeColorMaterialDialogBuilder(mContext)
|
||||||
|
.title(R.string.text_info)
|
||||||
|
.content(info)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyLine() {
|
||||||
|
mEditor.getLine()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Consumer<String>() {
|
||||||
|
@Override
|
||||||
|
public void accept(@NonNull String s) throws Exception {
|
||||||
|
ClipboardUtil.setClip(mContext, s);
|
||||||
|
Snackbar.make(mEditorView, R.string.text_already_copy_to_clip, Snackbar.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void deleteLine() {
|
||||||
|
mEditor.deleteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void paste() {
|
||||||
|
mEditor.insert(ClipboardUtil.getClip(mContext).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void findOrReplace() {
|
||||||
|
new FindOrReplaceDialogBuilder(mContext, mEditorView)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyAll() {
|
||||||
|
mEditor.getText().observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {
|
||||||
|
@Override
|
||||||
|
public void accept(@NonNull String s) throws Exception {
|
||||||
|
ClipboardUtil.setClip(mContext, s);
|
||||||
|
Snackbar.make(mEditorView, R.string.text_already_copy_to_clip, Snackbar.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void showLog() {
|
private void showLog() {
|
||||||
AutoJs.getInstance().getScriptEngineService().getGlobalConsole().show();
|
AutoJs.getInstance().getScriptEngineService().getGlobalConsole().show();
|
||||||
@@ -52,7 +203,6 @@ public class EditorMenu {
|
|||||||
mEditorView.showConsole();
|
mEditorView.showConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void forceStop() {
|
private void forceStop() {
|
||||||
mEditorView.forceStop();
|
mEditorView.forceStop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import com.stardust.scriptdroid.R;
|
|||||||
import com.stardust.scriptdroid.script.Scripts;
|
import com.stardust.scriptdroid.script.Scripts;
|
||||||
import com.stardust.scriptdroid.ui.edit.completion.CodeCompletions;
|
import com.stardust.scriptdroid.ui.edit.completion.CodeCompletions;
|
||||||
import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhanceBar;
|
import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhanceBar;
|
||||||
|
import com.stardust.widget.ToolbarMenuItem;
|
||||||
|
import com.stardust.widget.ViewSwitcher;
|
||||||
|
|
||||||
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.AfterViews;
|
||||||
import org.androidannotations.annotations.Click;
|
import org.androidannotations.annotations.Click;
|
||||||
@@ -55,6 +57,12 @@ public class EditorView extends FrameLayout {
|
|||||||
@ViewById(R.id.input_method_enhance_bar)
|
@ViewById(R.id.input_method_enhance_bar)
|
||||||
InputMethodEnhanceBar mInputMethodEnhanceBar;
|
InputMethodEnhanceBar mInputMethodEnhanceBar;
|
||||||
|
|
||||||
|
@ViewById(R.id.toolbar_switcher)
|
||||||
|
ViewSwitcher mToolbarSwitcher;
|
||||||
|
|
||||||
|
@ViewById(R.id.replace)
|
||||||
|
ToolbarMenuItem mReplaceMenuItem;
|
||||||
|
|
||||||
private static final String KEY_EDITOR_THEME = "我...深爱着...你呀...17.9.28";
|
private static final String KEY_EDITOR_THEME = "我...深爱着...你呀...17.9.28";
|
||||||
|
|
||||||
private String mName;
|
private String mName;
|
||||||
@@ -70,6 +78,11 @@ public class EditorView extends FrameLayout {
|
|||||||
mScriptExecution = null;
|
mScriptExecution = null;
|
||||||
setMenuItemStatus(R.id.run, true);
|
setMenuItemStatus(R.id.run, true);
|
||||||
String msg = intent.getStringExtra(Scripts.EXTRA_EXCEPTION_MESSAGE);
|
String msg = intent.getStringExtra(Scripts.EXTRA_EXCEPTION_MESSAGE);
|
||||||
|
int line = intent.getIntExtra(Scripts.EXTRA_EXCEPTION_LINE_NUMBER, -1);
|
||||||
|
int col = intent.getIntExtra(Scripts.EXTRA_EXCEPTION_COLUMN_NUMBER, 0);
|
||||||
|
if (line >= 1) {
|
||||||
|
mEditor.jumpTo(line - 1, col);
|
||||||
|
}
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
Snackbar.make(EditorView.this, getResources().getString(R.string.text_error) + ": " + msg, Snackbar.LENGTH_LONG).show();
|
Snackbar.make(EditorView.this, getResources().getString(R.string.text_error) + ": " + msg, Snackbar.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
@@ -228,6 +241,26 @@ public class EditorView extends FrameLayout {
|
|||||||
save().subscribe();
|
save().subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Click(R.id.find_next)
|
||||||
|
void findNext() {
|
||||||
|
mEditor.findNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Click(R.id.find_prev)
|
||||||
|
void findPrev() {
|
||||||
|
mEditor.findPrev();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Click(R.id.cancel)
|
||||||
|
void cancelSearch() {
|
||||||
|
mToolbarSwitcher.showFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Click(R.id.replace)
|
||||||
|
void replace() {
|
||||||
|
mEditor.replaceSelection();
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return mName;
|
return mName;
|
||||||
}
|
}
|
||||||
@@ -273,4 +306,20 @@ public class EditorView extends FrameLayout {
|
|||||||
public CodeMirrorEditor getEditor() {
|
public CodeMirrorEditor getEditor() {
|
||||||
return mEditor;
|
return mEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void find(String keywords, boolean usingRegex) {
|
||||||
|
mEditor.find(keywords, usingRegex);
|
||||||
|
mReplaceMenuItem.setVisibility(GONE);
|
||||||
|
mToolbarSwitcher.showSecond();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replace(String keywords, String replacement, boolean usingRegex) {
|
||||||
|
mEditor.replace(keywords, replacement, usingRegex);
|
||||||
|
mReplaceMenuItem.setVisibility(VISIBLE);
|
||||||
|
mToolbarSwitcher.showSecond();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replaceAll(String keywords, String replacement, boolean usingRegex) {
|
||||||
|
mEditor.replaceAll(keywords, replacement, usingRegex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.stardust.scriptdroid.ui.edit;
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.design.widget.TextInputEditText;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import com.afollestad.materialdialogs.DialogAction;
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
import com.github.aakira.expandablelayout.ExpandableRelativeLayout;
|
||||||
|
import com.stardust.scriptdroid.R;
|
||||||
|
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnCheckedChanged;
|
||||||
|
import butterknife.OnTextChanged;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Stardust on 2017/9/28.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FindOrReplaceDialogBuilder extends ThemeColorMaterialDialogBuilder {
|
||||||
|
|
||||||
|
private static final String KEY_KEYWORDS = "你回来好不好...";
|
||||||
|
|
||||||
|
@BindView(R.id.checkbox_regex)
|
||||||
|
CheckBox mRegexCheckBox;
|
||||||
|
|
||||||
|
@BindView(R.id.checkbox_replace)
|
||||||
|
CheckBox mReplaceCheckBox;
|
||||||
|
|
||||||
|
@BindView(R.id.checkbox_replace_all)
|
||||||
|
CheckBox mReplaceAllCheckBox;
|
||||||
|
|
||||||
|
@BindView(R.id.keywords)
|
||||||
|
TextInputEditText mKeywordsEditText;
|
||||||
|
|
||||||
|
@BindView(R.id.replacement)
|
||||||
|
TextInputEditText mReplacementEditText;
|
||||||
|
|
||||||
|
private EditorView mEditorView;
|
||||||
|
|
||||||
|
|
||||||
|
public FindOrReplaceDialogBuilder(@NonNull Context context, EditorView editorView) {
|
||||||
|
super(context);
|
||||||
|
mEditorView = editorView;
|
||||||
|
setupViews();
|
||||||
|
restoreState();
|
||||||
|
onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||||
|
storeState();
|
||||||
|
findOrReplace();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupViews() {
|
||||||
|
View view = View.inflate(context, R.layout.dialog_find_or_replace, null);
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
customView(view, true);
|
||||||
|
positiveText(R.string.ok);
|
||||||
|
negativeText(R.string.cancel);
|
||||||
|
title(R.string.text_find_or_replace);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void storeState() {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(getContext()).edit()
|
||||||
|
.putString(KEY_KEYWORDS, mKeywordsEditText.getText().toString())
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void restoreState() {
|
||||||
|
mKeywordsEditText.setText(PreferenceManager.getDefaultSharedPreferences(getContext())
|
||||||
|
.getString(KEY_KEYWORDS, ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnCheckedChanged(R.id.checkbox_replace_all)
|
||||||
|
void syncWithReplaceCheckBox() {
|
||||||
|
if (mReplaceAllCheckBox.isChecked() && !mReplaceCheckBox.isChecked()) {
|
||||||
|
mReplaceCheckBox.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnTextChanged(R.id.replacement)
|
||||||
|
void onTextChanged() {
|
||||||
|
if (mReplacementEditText.getText().length() > 0) {
|
||||||
|
mReplaceCheckBox.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void findOrReplace() {
|
||||||
|
String keywords = mKeywordsEditText.getText().toString();
|
||||||
|
if (keywords.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean usingRegex = mRegexCheckBox.isChecked();
|
||||||
|
if (!mReplaceCheckBox.isChecked()) {
|
||||||
|
mEditorView.find(keywords, usingRegex);
|
||||||
|
} else {
|
||||||
|
String replacement = mReplacementEditText.getText().toString();
|
||||||
|
if (mReplaceAllCheckBox.isChecked()) {
|
||||||
|
mEditorView.replaceAll(keywords, replacement, usingRegex);
|
||||||
|
} else {
|
||||||
|
mEditorView.replace(keywords, replacement, usingRegex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
app/src/main/res/drawable-hdpi/ic_close_white_48dp.png
Normal file
|
After Width: | Height: | Size: 347 B |
BIN
app/src/main/res/drawable-mdpi/ic_close_white_48dp.png
Normal file
|
After Width: | Height: | Size: 257 B |
BIN
app/src/main/res/drawable-xhdpi/ic_close_white_48dp.png
Normal file
|
After Width: | Height: | Size: 436 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_close_white_48dp.png
Normal file
|
After Width: | Height: | Size: 524 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_close_white_48dp.png
Normal file
|
After Width: | Height: | Size: 707 B |
BIN
app/src/main/res/drawable/ic_ali_down.png
Normal file
|
After Width: | Height: | Size: 814 B |
BIN
app/src/main/res/drawable/ic_ali_replace.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
app/src/main/res/drawable/ic_ali_up.png
Normal file
|
After Width: | Height: | Size: 813 B |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
69
app/src/main/res/layout/dialog_find_or_replace.xml
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:paddingTop="16dp">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/keywords"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/text_find"/>
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/checkbox_regex"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/text_regex"/>
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/replacement"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/text_replace"/>
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/checkbox_replace"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/text_replace"/>
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/checkbox_replace_all"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/text_replace_all"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:text="@string/hint_regex"
|
||||||
|
android:textColor="#929397"
|
||||||
|
android:textSize="12sp"/>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:theme="@style/AppTheme.AppBarOverlay">
|
android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
|
|
||||||
<com.stardust.theme.widget.ThemeColorToolbar
|
<com.stardust.theme.widget.ThemeColorToolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -18,46 +19,92 @@
|
|||||||
android:title="@string/_app_name"
|
android:title="@string/_app_name"
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay">
|
app:popupTheme="@style/AppTheme.PopupOverlay">
|
||||||
|
|
||||||
<LinearLayout
|
<com.stardust.widget.ViewSwitcher
|
||||||
|
android:id="@+id/toolbar_switcher"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="right">
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<com.stardust.widget.ToolbarMenuItem
|
<LinearLayout
|
||||||
android:id="@+id/run"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:icon="@drawable/ic_play_arrow_white_48dp"
|
android:layout_gravity="right"
|
||||||
app:icon_color="@android:color/white"
|
android:orientation="horizontal">
|
||||||
app:text="@string/text_run"/>
|
|
||||||
|
|
||||||
<com.stardust.widget.ToolbarMenuItem
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
android:id="@+id/undo"
|
android:id="@+id/run"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:icon="@drawable/ic_play_arrow_white_48dp"
|
||||||
|
app:icon_color="@android:color/white"
|
||||||
|
app:text="@string/text_run"/>
|
||||||
|
|
||||||
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
|
android:id="@+id/undo"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:icon="@drawable/ic_undo_white_48dp"
|
||||||
|
app:text="@string/text_undo"/>
|
||||||
|
|
||||||
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
|
android:id="@+id/redo"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:icon="@drawable/ic_redo_white_48dp"
|
||||||
|
app:text="@string/text_redo"/>
|
||||||
|
|
||||||
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
|
android:id="@+id/save"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:icon="@drawable/ic_save_white_48dp"
|
||||||
|
app:text="@string/text_save"/>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:icon="@drawable/ic_undo_white_48dp"
|
android:layout_gravity="right"
|
||||||
app:text="@string/text_undo"/>
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<com.stardust.widget.ToolbarMenuItem
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
android:id="@+id/redo"
|
android:id="@+id/replace"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:icon="@drawable/ic_redo_white_48dp"
|
app:icon="@drawable/ic_ali_replace"
|
||||||
app:text="@string/text_redo"/>
|
app:text="@string/text_replace"/>
|
||||||
|
|
||||||
<com.stardust.widget.ToolbarMenuItem
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
android:id="@+id/save"
|
android:id="@+id/find_prev"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:icon="@drawable/ic_save_white_48dp"
|
app:icon="@drawable/ic_ali_up"
|
||||||
app:text="@string/text_save"/>
|
app:text="@string/text_find_prev"/>
|
||||||
|
|
||||||
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
|
android:id="@+id/find_next"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:icon="@drawable/ic_ali_down"
|
||||||
|
app:text="@string/text_find_next"/>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
<com.stardust.widget.ToolbarMenuItem
|
||||||
|
android:id="@+id/cancel"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:icon="@drawable/ic_close_white_48dp"
|
||||||
|
app:text="@string/text_cancel"/>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</com.stardust.widget.ViewSwitcher>
|
||||||
|
|
||||||
</com.stardust.theme.widget.ThemeColorToolbar>
|
</com.stardust.theme.widget.ThemeColorToolbar>
|
||||||
|
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,39 +3,86 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_beautify"
|
android:id="@+id/action_force_stop"
|
||||||
android:orderInCategory="100"
|
android:title="@string/text_force_stop"
|
||||||
android:title="@string/text_code_beautify"
|
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item android:title="@string/text_edit">
|
||||||
|
|
||||||
|
<menu>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_find_or_replace"
|
||||||
|
android:title="@string/text_find_or_replace"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_copy_all"
|
||||||
|
android:title="@string/text_copy_all"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_paste"
|
||||||
|
android:title="@string/text_paste"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_copy_line"
|
||||||
|
android:title="@string/text_copy_line"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_delete_line"
|
||||||
|
android:title="@string/text_delete_line"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_clear"
|
||||||
|
android:title="@string/text_clear"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
</menu>
|
||||||
|
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_jump"
|
||||||
|
android:title="@string/text_jump_to_line"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_console"
|
android:id="@+id/action_console"
|
||||||
android:orderInCategory="200"
|
|
||||||
android:title="@string/text_console"
|
android:title="@string/text_console"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_force_stop"
|
|
||||||
android:orderInCategory="250"
|
|
||||||
android:title="@string/text_force_stop"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_log"
|
android:id="@+id/action_log"
|
||||||
android:orderInCategory="280"
|
|
||||||
android:title="@string/text_log"
|
android:title="@string/text_log"
|
||||||
app:showAsAction="never"/>
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
<item
|
<item android:title="@string/text_more">
|
||||||
android:id="@+id/action_editor_theme"
|
<menu>
|
||||||
android:orderInCategory="300"
|
|
||||||
android:title="@string/text_editor_theme"
|
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_open_by_other_apps"
|
android:id="@+id/action_beautify"
|
||||||
android:orderInCategory="400"
|
android:title="@string/text_code_beautify"
|
||||||
android:title="@string/text_open_by_other_apps"
|
app:showAsAction="never"/>
|
||||||
app:showAsAction="never"/>
|
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_info"
|
||||||
|
android:title="@string/text_info"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_editor_theme"
|
||||||
|
android:title="@string/text_editor_theme"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_open_by_other_apps"
|
||||||
|
android:title="@string/text_open_by_other_apps"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
</menu>
|
</menu>
|
||||||
@@ -254,6 +254,22 @@
|
|||||||
<string name="text_type">类型</string>
|
<string name="text_type">类型</string>
|
||||||
<string name="text_donate">捐赠</string>
|
<string name="text_donate">捐赠</string>
|
||||||
<string name="text_editor_theme">编辑器主题</string>
|
<string name="text_editor_theme">编辑器主题</string>
|
||||||
|
<string name="text_util">工具</string>
|
||||||
|
<string name="text_jump_to_line">跳转到行</string>
|
||||||
|
<string name="text_info">信息</string>
|
||||||
|
<string name="text_find_or_replace">查找/替换</string>
|
||||||
|
<string name="text_paste">粘贴</string>
|
||||||
|
<string name="text_copy_all">复制全部</string>
|
||||||
|
<string name="text_copy_line">复制行</string>
|
||||||
|
<string name="text_delete_line">删除行</string>
|
||||||
|
<string name="format_editor_info" formatted="false">字符数: %d\n行数: %d\n大小: %s</string>
|
||||||
|
<string name="text_find">查找</string>
|
||||||
|
<string name="text_replace">替换</string>
|
||||||
|
<string name="text_regex">正则表达式</string>
|
||||||
|
<string name="text_replace_all">全部替换</string>
|
||||||
|
<string name="text_find_next">向下</string>
|
||||||
|
<string name="text_find_prev">向上</string>
|
||||||
|
<string name="hint_regex">正则语法与JavaScript中相同, 可使用$1-9代替被捕获的匹配</string>
|
||||||
|
|
||||||
|
|
||||||
<string-array name="record_control_keys">
|
<string-array name="record_control_keys">
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.stardust.autojs.runtime.exception;
|
package com.stardust.autojs.runtime.exception;
|
||||||
|
|
||||||
|
import org.mozilla.javascript.EvaluatorException;
|
||||||
|
import org.mozilla.javascript.RhinoException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/1/29.
|
* Created by Stardust on 2017/1/29.
|
||||||
*/
|
*/
|
||||||
public class ScriptException extends RuntimeException {
|
public class ScriptException extends RuntimeException {
|
||||||
|
|
||||||
|
|
||||||
public ScriptException(String message, Throwable cause) {
|
public ScriptException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
@@ -15,7 +17,6 @@ public class ScriptException extends RuntimeException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ScriptException() {
|
public ScriptException() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptException(Throwable cause) {
|
public ScriptException(Throwable cause) {
|
||||||
|
|||||||