Skip to content

Commit 0300d73

Browse files
committed
Improve goto line dialog
1 parent 7e04bc7 commit 0300d73

File tree

7 files changed

+103
-51
lines changed

7 files changed

+103
-51
lines changed

lib-n-ide/build.gradle

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import java.util.regex.Pattern
2-
31
apply plugin: 'com.android.library'
42

53
android {
@@ -41,9 +39,6 @@ android {
4139

4240
tasks.whenTaskAdded { task ->
4341
if (task.name == "assembleRelease") {
44-
task.doFirst {
45-
cleanBuildCache
46-
}
4742
task.finalizedBy(copyReleaseToJavaNIDE)
4843
}
4944
}
@@ -76,6 +71,7 @@ dependencies {
7671
api "com.android.support:preference-v7:$androidSupportLibVersion"
7772
}
7873

74+
ext.nIdeVersion = 10
7975

8076
task copyReleaseToJavaNIDE << {
8177
File javaIdeDir = new File("C:\\github\\javaide")
@@ -84,7 +80,7 @@ task copyReleaseToJavaNIDE << {
8480
}
8581
final String prefix = "lib-n-ide-release";
8682
String oldModuleName = null;
87-
final String newModuleName = "$prefix-${android.defaultConfig.versionCode}";
83+
final String newModuleName = "$prefix-${project.ext.nIdeVersion}";
8884
println "New module name $newModuleName"
8985
for (File f : javaIdeDir.listFiles()) {
9086
if (f.getName().startsWith(prefix)) {
@@ -116,31 +112,31 @@ task copyReleaseToJavaNIDE << {
116112
println "rename success"
117113

118114
//now modify setting.gradle
119-
println "modify settings.gradle"
120-
File settingsFile = new File(javaIdeDir, "settings.gradle");
121-
String content = fileToString(settingsFile);
122-
//comment it
123-
content = content.replaceAll("^include ':${Pattern.quote(oldModuleName)}'", "//include ':${newModuleName}'");
124-
FileOutputStream output = new FileOutputStream(settingsFile);
125-
output.write(content.getBytes());
126-
output.close();
127-
128-
//now modify build.gradle
129-
println "modify build.gradle"
130-
File gradleFile = new File(moduleDir, "build.gradle")
131-
output = new FileOutputStream(gradleFile);
132-
output.write(("configurations.maybeCreate(\"default\")\n" +
133-
"artifacts.add(\"default\", file('${newModuleName}.aar'))").getBytes());
134-
output.close();
135-
136-
File appGradleFile = new File(javaIdeDir, "app/build.gradle");
137-
if (appGradleFile.exists()) {
138-
content = fileToString(appGradleFile);
139-
content = content.replaceAll(":${Pattern.quote(oldModuleName)}", ":$newModuleName");
140-
output = new FileOutputStream(appGradleFile);
141-
output.write(content.getBytes())
142-
output.close();
143-
}
115+
// println "modify settings.gradle"
116+
// File settingsFile = new File(javaIdeDir, "settings.gradle");
117+
// String content = fileToString(settingsFile);
118+
// //comment it
119+
// content = content.replaceAll("include\\s+':${Pattern.quote(oldModuleName)}'", "//include ':${newModuleName}'");
120+
// FileOutputStream output = new FileOutputStream(settingsFile);
121+
// output.write(content.getBytes());
122+
// output.close();
123+
//
124+
// //now modify build.gradle
125+
// println "modify build.gradle"
126+
// File gradleFile = new File(moduleDir, "build.gradle")
127+
// output = new FileOutputStream(gradleFile);
128+
// output.write(("configurations.maybeCreate(\"default\")\n" +
129+
// "artifacts.add(\"default\", file('${newModuleName}.aar'))").getBytes());
130+
// output.close();
131+
//
132+
// File appGradleFile = new File(javaIdeDir, "app/build.gradle");
133+
// if (appGradleFile.exists()) {
134+
// content = fileToString(appGradleFile);
135+
// content = content.replaceAll(":${Pattern.quote(oldModuleName)}", ":$newModuleName");
136+
// output = new FileOutputStream(appGradleFile);
137+
// output.write(content.getBytes())
138+
// output.close();
139+
// }
144140
}
145141

146142
String fileToString(File file) {

lib-n-ide/src/main/java/com/duy/ide/code/api/SuggestItem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.duy.ide.code.api;
22

3+
import com.duy.ide.editor.view.IEditAreaView;
4+
35
/**
46
* The item will be display in list suggestion
57
* <p>
@@ -39,4 +41,9 @@ public interface SuggestItem {
3941
* etc
4042
*/
4143
char getTypeHeader();
44+
45+
/**
46+
* @param editAreaView - editor you will modify for this suggestion
47+
*/
48+
void onSelectThis(IEditAreaView editAreaView);
4249
}

lib-n-ide/src/main/java/com/duy/ide/core/api/IdeActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,10 @@ public boolean onMenuItemClick(MenuItem item) {
486486
openFileExplorer();
487487

488488
} else if (id == R.id.action_goto_line) {
489-
new GotoLineDialog(this).show();
490-
489+
EditorDelegate editorDelegate = getCurrentEditorDelegate();
490+
if (editorDelegate != null) {
491+
new GotoLineDialog(this, editorDelegate).show();
492+
}
491493
} else if (id == R.id.action_file_history) {
492494
RecentFilesManager rfm = new RecentFilesManager(this);
493495
rfm.setOnFileItemClickListener(new RecentFilesManager.OnFileItemClickListener() {

lib-n-ide/src/main/java/com/duy/ide/editor/internal/suggestion/DefaultSuggestItem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.duy.ide.editor.internal.suggestion;
22

3+
import com.duy.ide.editor.view.IEditAreaView;
4+
35
public class DefaultSuggestItem implements com.duy.ide.code.api.SuggestItem {
46
private String name;
57
private String desc;
@@ -50,4 +52,9 @@ public int getSuggestionPriority() {
5052
public char getTypeHeader() {
5153
return 0;
5254
}
55+
56+
@Override
57+
public void onSelectThis(IEditAreaView editAreaView) {
58+
59+
}
5360
}
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
package com.duy.ide.editor.internal.suggestion;
22

33
public class Editor {
4-
private String text;
5-
private int cursor;
4+
private final String text;
5+
private final int cursor;
66

77
public Editor(String text, int cursor) {
88
this.text = text;
99
this.cursor = cursor;
1010
}
11+
12+
public String getText() {
13+
return text;
14+
}
15+
16+
public int getCursor() {
17+
return cursor;
18+
}
19+
20+
public int length() {
21+
return text.length();
22+
}
23+
24+
@Override
25+
public String toString() {
26+
return "Editor{" +
27+
"text='" + text + '\'' +
28+
", cursor=" + cursor +
29+
'}';
30+
}
1131
}

lib-n-ide/src/main/java/com/duy/ide/editor/view/SuggestionEditor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ private void performCompletion(int position) {
459459
return;
460460
}
461461
SuggestItem item = mAdapter.getItem(position);
462-
if (mOnSuggestItemClickListener != null) {
463-
//noinspection ConstantConditions
464-
mOnSuggestItemClickListener.onClickSuggest(this, position, item);
462+
if (item != null) {
463+
//handle by this item
464+
item.onSelectThis(SuggestionEditor.this);
465465
}
466466
}
467467

lib-n-ide/src/main/java/com/jecelyin/editor/v2/dialog/GotoLineDialog.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,54 @@
1919
import android.content.Context;
2020
import android.view.inputmethod.EditorInfo;
2121

22+
import com.duy.ide.editor.Document;
23+
import com.duy.ide.editor.EditorDelegate;
2224
import com.duy.ide.editor.editor.R;
2325
import com.jecelyin.common.utils.DLog;
2426
import com.jecelyin.common.utils.StringUtils;
2527
import com.jecelyin.common.utils.UIUtils;
2628
import com.jecelyin.editor.v2.common.Command;
2729

30+
import org.gjt.sp.jedit.LineManager;
31+
2832
/**
2933
* @author Jecelyin Peng <jecelyin@gmail.com>
3034
*/
3135
public class GotoLineDialog extends AbstractDialog {
32-
public GotoLineDialog(Context context) {
36+
private final EditorDelegate editorDelegate;
37+
38+
public GotoLineDialog(Context context, EditorDelegate editorDelegate) {
3339
super(context);
40+
this.editorDelegate = editorDelegate;
3441
}
3542

3643
@Override
3744
public void show() {
38-
UIUtils.showInputDialog(context, R.string.goto_line, 0, null, EditorInfo.TYPE_CLASS_NUMBER, new UIUtils.OnShowInputCallback() {
39-
@Override
40-
public void onConfirm(CharSequence input) {
41-
try {
42-
int line = StringUtils.toInt(input.toString());
43-
Command command = new Command(Command.CommandEnum.GOTO_INDEX);
44-
command.args.putInt("line", line);
45-
getMainActivity().doCommand(command);
46-
} catch (Exception e) {
47-
DLog.e(e);
48-
}
45+
int lineCount = -1;
46+
if (editorDelegate != null) {
47+
Document document = editorDelegate.getDocument();
48+
if (document != null) {
49+
LineManager lineManager = document.getBuffer().getLineManager();
50+
lineCount = lineManager.getLineCount();
4951
}
50-
});
52+
}
53+
UIUtils.showInputDialog(
54+
context,
55+
context.getString(R.string.goto_line),
56+
lineCount >= 1 ? ("1-" + lineCount) : null,
57+
null, EditorInfo.TYPE_CLASS_NUMBER,
58+
new UIUtils.OnShowInputCallback() {
59+
@Override
60+
public void onConfirm(CharSequence input) {
61+
try {
62+
int line = StringUtils.toInt(input.toString());
63+
Command command = new Command(Command.CommandEnum.GOTO_INDEX);
64+
command.args.putInt("line", line);
65+
getMainActivity().doCommand(command);
66+
} catch (Exception e) {
67+
DLog.e(e);
68+
}
69+
}
70+
});
5171
}
5272
}

0 commit comments

Comments
 (0)