Skip to content

Commit

Permalink
fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntungho committed May 17, 2020
1 parent 93f2765 commit c27eca9
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 31 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

![ci-status](https://travis-ci.org/chuntungho/gist-snippet.svg?branch=master)

A code snippet tool based on GitHub gist, which provides with an ability to fetch secret or starred gist of GitHub accounts.
It depends on built-in GitHub plugin which should be enabled.
<a href="https://gist.chuntung.com/">Getting Started</a>
<a href="https://gist.chuntung.com/">Getting Started</a> | <a href="https://chuntung.com/donate">Donate</a>

A code snippet tool based on GitHub gist, which provides with a feature to fetch secret or starred gist of GitHub accounts. It depends on built-in GitHub plugin which should be enabled.
4 changes: 1 addition & 3 deletions changeNotes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<ul>
<li>Compatible with latest IDE</li>
<li>Fixed multiple Github accounts issue</li>
<li>Supported deleting gists</li>
<li>Fixed minor issues</li>
</ul>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 1.0.1
version = 1.0.2
ideaVersion = IC-2019.1
customUtilBuild = 299.*
isEAP = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020 Tony Ho. Some rights reserved.
*/

package com.chuntung.plugin.gistsnippet.action;

import com.chuntung.plugin.gistsnippet.dto.api.GistFileDTO;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAware;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.function.Consumer;

/**
* Reload selected gist.
*/
public class ReloadAction extends AnAction implements DumbAware {
private JTree tree;
private Consumer consumer;

public ReloadAction(JTree tree, Consumer consumer) {
super("Reload", "Reload first selected gist file", null);
this.tree = tree;
this.consumer = consumer;
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
consumer.accept(e);
}

@Override
public void update(@NotNull AnActionEvent e) {
// check if gist file selected
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (!(node.getUserObject() instanceof GistFileDTO)) {
e.getPresentation().setVisible(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jetbrains.plugins.github.api.GithubApiRequestExecutor;
import org.jetbrains.plugins.github.api.GithubApiRequestExecutorManager;
import org.jetbrains.plugins.github.authentication.accounts.GithubAccount;
import org.jetbrains.plugins.github.exceptions.GithubJsonException;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -159,7 +160,11 @@ public void deleteGist(GithubAccount account, List<String> gistIds) {
String url = String.format(GIST_DETAIL_URL, gistId);
// since 2019.1
GithubApiRequest.Delete.Json<String> delete = new GithubApiRequest.Delete.Json<>(url, null, String.class);
executor.execute(delete);
try {
executor.execute(delete);
} catch (GithubJsonException e) {
logger.debug("Ignored exception due to no result returned by API");
}
gistCache.remove(gistId);
}
String key = account.toString() + "#own";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<properties/>
<border type="none"/>
<children>
<scrollpane id="7c571">
<scrollpane id="7c571" binding="scrollPane" custom-create="true">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.chuntung.plugin.gistsnippet.action.CustomComboBoxAction;
import com.chuntung.plugin.gistsnippet.action.DeleteAction;
import com.chuntung.plugin.gistsnippet.action.OpenInBrowserAction;
import com.chuntung.plugin.gistsnippet.action.ReloadAction;
import com.chuntung.plugin.gistsnippet.dto.ScopeEnum;
import com.chuntung.plugin.gistsnippet.dto.SnippetNodeDTO;
import com.chuntung.plugin.gistsnippet.dto.SnippetRootNode;
Expand All @@ -15,6 +16,7 @@
import com.chuntung.plugin.gistsnippet.service.GistException;
import com.chuntung.plugin.gistsnippet.service.GistSnippetService;
import com.chuntung.plugin.gistsnippet.service.GithubAccountHolder;
import com.intellij.icons.AllIcons;
import com.intellij.ide.BrowserUtil;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.ide.util.treeView.AbstractTreeStructure;
Expand All @@ -34,6 +36,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.components.JBTabbedPane;
import com.intellij.ui.components.labels.DropDownLink;
import com.intellij.ui.components.labels.LinkLabel;
Expand All @@ -55,8 +58,6 @@
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -76,6 +77,7 @@ public class InsertGistDialog extends DialogWrapper {
private JTextField textField1;
private JComboBox languageComboBox;
private JComboBox sortByComboBox;
private JScrollPane scrollPane;

private Project project;
private final boolean insertable;
Expand Down Expand Up @@ -112,18 +114,8 @@ private void createUIComponents() {
// Replace JTree with SimpleTree here due to ui designer fails to preview SimpleTree.
snippetTree = new SimpleTree();
snippetTree.addTreeSelectionListener(e -> onSelect(e));
snippetTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// double click to load forcibly
if (e.getButton() == e.BUTTON1 && e.getClickCount() == 2) {
DefaultMutableTreeNode selected = (DefaultMutableTreeNode) ((JTree) e.getComponent()).getLastSelectedPathComponent();
if (selected != null && selected.isLeaf()) {
loadFileContent(project, selected, true);
}
}
}
});

scrollPane = ScrollPaneFactory.createScrollPane(snippetTree, true);

// use tree structure for rendering
snippetRoot = new SnippetRootNode();
Expand Down Expand Up @@ -226,7 +218,13 @@ private ActionGroup getPopupActions() {
// delete gist
group.add(new DeleteAction(snippetTree, snippetStructure, snippetRoot, project));

// open in browser
// reload gist file
group.add(new ReloadAction(snippetTree, e -> {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) snippetTree.getLastSelectedPathComponent();
loadFileContent(project, node, true);
}));

// open in browser for gist or file
group.add(new OpenInBrowserAction(snippetTree));

return group;
Expand Down Expand Up @@ -264,6 +262,18 @@ public void actionPerformed(@NotNull AnActionEvent e) {
)
);

// refresh own/starred
group.add(new AnAction("Refresh", "Refresh gist list", AllIcons.Actions.Refresh) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
if ("Own".equals(scopeAction.getText())) {
loadOwnGist(true);
} else {
loadStarredGist(true);
}
}
});

group.addSeparator();

group.add(new ExpandAllAction(snippetTree));
Expand All @@ -273,8 +283,6 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}

private void initYoursPane(List<GithubAccount> accountList) {
UIUtil.removeScrollBorder(yoursSplitPane);

yoursSplitPane.setVisible(true);

// init toolbar
Expand All @@ -284,7 +292,7 @@ private void initYoursPane(List<GithubAccount> accountList) {
((JPanel) yoursSplitPane.getLeftComponent()).add(actionToolbar.getComponent(), BorderLayout.NORTH);

// load remembered width
int width = PropertiesComponent.getInstance().getInt(SPLIT_LEFT_WIDTH, 220);
int width = PropertiesComponent.getInstance().getInt(SPLIT_LEFT_WIDTH, 240);
yoursSplitPane.getLeftComponent().setPreferredSize(new Dimension(width, -1));

// bind editor
Expand Down Expand Up @@ -404,8 +412,10 @@ private <T> T getUserObject(DefaultMutableTreeNode node) {
}

private void loadOwnGist(boolean forced) {
// reset type filter
typeAction.reset();
// reset type filter for switch
if (!forced) {
typeAction.reset();
}

// com.intellij.util.io.HttpRequests#process does not allow Network accessed in dispatch thread or read action
// start a background task to bypass api limitation
Expand Down Expand Up @@ -443,7 +453,15 @@ public void run(@NotNull ProgressIndicator indicator) {

private void renderTree(List<GistDTO> gistList, ScopeEnum scope) {
snippetRoot.resetChildren(gistList, scope);
snippetStructure.invalidate();

// filter by type if selected
if ("Public".equals(typeAction.getText())) {
filterByPublic(true);
} else if ("Secret".equals(typeAction.getText())) {
filterByPublic(false);
} else {
snippetStructure.invalidate();
}
}

@Nullable
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<vendor email="ho@chuntung.com" url="https://gist.chuntung.com">Tony Ho</vendor>

<description><![CDATA[
<a href="https://gist.chuntung.com">Getting Started</a> | <a href="https://chuntung.com/donate">Donate</a>
<br><br>
A code snippet tool based on GitHub Gist, that provides with a feature to fetch own or starred gists of GitHub accounts.
It depends on built-in GitHub plugin which should be enabled. <a href="https://gist.chuntung.com">Getting Started</a>
It depends on built-in GitHub plugin which should be enabled.
]]></description>

<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
Expand Down

0 comments on commit c27eca9

Please sign in to comment.