Skip to content

Commit 634c8f6

Browse files
committed
fix task onSuccess vs modal dialog issue
1 parent a069463 commit 634c8f6

File tree

7 files changed

+19
-148
lines changed

7 files changed

+19
-148
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version = 1.0.0
2-
ideaVersion = IC-2019.3
2+
ideaVersion = IC-2019.1
33
customUtilBuild = 194.*
44
isEAP = false
55
pluginChannels = nightly

src/main/java/com/chuntung/plugin/gistsnippet/action/InsertAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
import com.intellij.openapi.editor.SelectionModel;
1414
import com.intellij.openapi.project.DumbAware;
1515
import com.intellij.openapi.project.Project;
16+
import com.intellij.openapi.util.IconLoader;
1617
import org.jetbrains.annotations.NotNull;
1718

1819
public class InsertAction extends AnAction implements DumbAware {
1920
public InsertAction() {
20-
super(AllIcons.Vcs.Vendors.Github);
21+
super(IconLoader.getIcon("/images/gist.png"));
2122
}
2223

2324
@Override

src/main/java/com/chuntung/plugin/gistsnippet/view/CustomDropDownLink.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String getSelectedItem() {
6060
}
6161

6262
/**
63-
* Set selected item and trigger consumer.
63+
* Only render selected item.
6464
*
6565
* @param selectedItem
6666
*/
@@ -73,9 +73,6 @@ public void setSelectedItem(String selectedItem) {
7373
if (icons.size() > 0) {
7474
leftIcon.setIcon(icons.get(items.indexOf(selectedItem)));
7575
}
76-
if (consumer != null) {
77-
consumer.accept(selectedItem);
78-
}
7976

8077
this.selectedItem = selectedItem;
8178
}
@@ -85,6 +82,9 @@ void showPopup() {
8582
final BaseListPopupStep<String> list = new BaseListPopupStep<String>(null, items, icons) {
8683
@Override
8784
public PopupStep onChosen(String selectedValue, boolean finalChoice) {
85+
if (consumer != null) {
86+
consumer.accept(selectedValue);
87+
}
8888
setSelectedItem(selectedValue);
8989
return super.onChosen(selectedValue, finalChoice);
9090
}

src/main/java/com/chuntung/plugin/gistsnippet/view/CustomTreeCellRenderer.java

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/main/java/com/chuntung/plugin/gistsnippet/view/InsertGistDialog.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.intellij.ui.components.JBTabbedPane;
2424
import com.intellij.ui.components.labels.DropDownLink;
2525
import com.intellij.ui.components.labels.LinkLabel;
26-
import com.intellij.ui.treeStructure.SimpleNode;
2726
import com.intellij.ui.treeStructure.SimpleTree;
2827
import com.intellij.ui.treeStructure.SimpleTreeBuilder;
2928
import com.intellij.util.Consumer;
@@ -196,6 +195,7 @@ private void initYoursPane(List<GithubAccount> accountList, GithubAccount single
196195
currentAccount = chosenItem;
197196
// load All Own Gist by default
198197
((CustomDropDownLink) scopeDropDownLink).setSelectedItem("Own");
198+
loadOwnGist(false);
199199
}
200200
}, true);
201201

@@ -297,23 +297,17 @@ private <T> T getUserObject(DefaultMutableTreeNode node) {
297297
}
298298

299299
private void loadOwnGist(boolean forced) {
300-
if (currentAccount == null) {
301-
return;
302-
}
300+
// reset type filter
301+
typeDropDownLink.setText("All");
303302

304-
// com.intellij.util.io.HttpRequests.process does not allow Network accessed in dispatch thread or read action
305-
// start a background task to access network due to api limitation
303+
// com.intellij.util.io.HttpRequests#process does not allow Network accessed in dispatch thread or read action
304+
// start a background task to bypass api limitation
306305
new Task.Backgroundable(project, "Loading own gists...") {
307-
308-
private List<GistDTO> ownGist;
309-
310306
@Override
311307
public void run(@NotNull ProgressIndicator indicator) {
312-
ownGist = service.queryOwnGist(currentAccount, forced);
313-
}
314-
315-
@Override
316-
public void onSuccess() {
308+
List<GistDTO> ownGist = service.queryOwnGist(currentAccount, forced);
309+
// non-modal task should not invoke onSuccess() in modal dialog initialization.
310+
// it will be blocked in dispatch thread by modal dialog, here just run in background
317311
if (ownGist != null) {
318312
renderTree(ownGist, ScopeEnum.OWN);
319313
}
@@ -322,20 +316,13 @@ public void onSuccess() {
322316
}
323317

324318
private void loadStarredGist(boolean forced) {
325-
if (currentAccount == null) {
326-
return;
327-
}
319+
// reset type filter
320+
typeDropDownLink.setText("All");
328321

329322
new Task.Backgroundable(project, "Loading starred gists...") {
330-
private List<GistDTO> starredGist;
331-
332323
@Override
333324
public void run(@NotNull ProgressIndicator indicator) {
334-
starredGist = service.queryStarredGist(currentAccount, forced);
335-
}
336-
337-
@Override
338-
public void onSuccess() {
325+
List<GistDTO> starredGist = service.queryStarredGist(currentAccount, forced);
339326
if (starredGist != null) {
340327
renderTree(starredGist, ScopeEnum.STARRED);
341328
}
@@ -346,9 +333,6 @@ public void onSuccess() {
346333
private void renderTree(List<GistDTO> gistList, ScopeEnum scope) {
347334
snippetRoot.setSetChildren(gistList, scope);
348335
treeBuilder.queueUpdate();
349-
350-
// reset type filter
351-
typeDropDownLink.setText("All");
352336
}
353337

354338
@Nullable

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<vendor email="ho@chuntung.com" url="https://gist.chuntung.com">Tony Ho</vendor>
55

66
<description><![CDATA[
7-
A code snippet tool based on GitHub gist, provides with an ability to fetch secret or starred gist of GitHub accounts.
7+
A code snippet tool based on GitHub gist, which provides with an ability to fetch secret or starred gist of GitHub accounts.
88
It depends on built-in GitHub plugin which should be enabled.
99
]]></description>
1010

src/main/resources/images/gist.png

497 Bytes
Loading

0 commit comments

Comments
 (0)