Skip to content

Commit c88bad7

Browse files
committed
move to editor when select diagnostic
1 parent d9b0252 commit c88bad7

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/CompileManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void onCompileFailed(ShellResult shellResult) {
8686
mCompileDialog.dismiss();
8787
}
8888
if (DLog.DEBUG) DLog.w(TAG, "onCompileFailed: \n" + shellResult.getMessage());
89+
8990
if (mDiagnosticPresenter != null) {
9091
DiagnosticsCollector diagnosticsCollector = new DiagnosticsCollector<>();
9192
OutputParser parser = new OutputParser(diagnosticsCollector);

app/src/main/java/com/duy/ccppcompiler/diagnostic/DiagnosticPresenter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.duy.ccppcompiler.diagnostic;
1818

1919
import android.support.annotation.MainThread;
20+
import android.support.v4.util.Pair;
2021
import android.view.View;
2122

2223
import com.duy.ccppcompiler.compiler.diagnostic.Diagnostic;
@@ -58,8 +59,14 @@ public void onDiagnosticClick(View view, Diagnostic diagnostic) {
5859
Object source = diagnostic.getSource();
5960
if (source instanceof File) {
6061
File file = (File) source;
61-
EditorDelegate editorDelegate = mTabManager.getEditorDelegate(file);
62-
if (editorDelegate != null) {
62+
Pair<Integer, EditorDelegate> pair = mTabManager.getEditorDelegate(file);
63+
if (pair != null) {
64+
int index = pair.first;
65+
EditorDelegate editorDelegate = pair.second;
66+
67+
mTabManager.setCurrentTab(index);
68+
editorDelegate.doCommand(new Command(Command.CommandEnum.REQUEST_FOCUS));
69+
6370
Command command = new Command(Command.CommandEnum.GOTO_LINE_COL);
6471
command.args.putInt("line", (int) diagnostic.getLineNumber());
6572
command.args.putInt("col", (int) diagnostic.getColumnNumber());

app/src/main/java/com/jecelyin/editor/v2/common/Command.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ public enum CommandEnum {
6060
INSERT_TEXT,
6161
RELOAD_WITH_ENCODING,
6262
FULL_SCREEN,
63-
THEME,
63+
THEME, REQUEST_FOCUS,
6464
}
6565
}

app/src/main/java/com/jecelyin/editor/v2/ui/editor/EditorDelegate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ public boolean doCommand(Command command) {
347347
case BACK:
348348
mEditText.backLocation();
349349
break;
350+
case REQUEST_FOCUS:
351+
mEditText.requestFocus();
352+
break;
350353
}
351354
return true;
352355
}

app/src/main/java/com/jecelyin/editor/v2/ui/manager/TabManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import android.database.DataSetObserver;
2222
import android.support.annotation.Nullable;
23+
import android.support.v4.util.Pair;
2324
import android.support.v4.view.GravityCompat;
2425
import android.support.v4.view.ViewPager;
2526
import android.view.View;
@@ -239,12 +240,13 @@ public IEditorPagerAdapter getEditorPagerAdapter() {
239240
* @return null if not found
240241
*/
241242
@Nullable
242-
public EditorDelegate getEditorDelegate(File file) {
243+
public Pair<Integer, EditorDelegate> getEditorDelegate(File file) {
243244
String path = file.getPath();
244245
ArrayList<EditorDelegate> allEditor = mEditorFragmentPagerAdapter.getAllEditor();
245-
for (EditorDelegate editorDelegate : allEditor) {
246+
for (int i = 0, allEditorSize = allEditor.size(); i < allEditorSize; i++) {
247+
EditorDelegate editorDelegate = allEditor.get(i);
246248
if (editorDelegate.getPath().equals(path)) {
247-
return editorDelegate;
249+
return new Pair<>(i, editorDelegate);
248250
}
249251
}
250252
return null;

0 commit comments

Comments
 (0)