77import com .chuntung .plugin .gistsnippet .action .CustomComboBoxAction ;
88import com .chuntung .plugin .gistsnippet .action .DeleteAction ;
99import com .chuntung .plugin .gistsnippet .action .OpenInBrowserAction ;
10+ import com .chuntung .plugin .gistsnippet .action .ReloadAction ;
1011import com .chuntung .plugin .gistsnippet .dto .ScopeEnum ;
1112import com .chuntung .plugin .gistsnippet .dto .SnippetNodeDTO ;
1213import com .chuntung .plugin .gistsnippet .dto .SnippetRootNode ;
1516import com .chuntung .plugin .gistsnippet .service .GistException ;
1617import com .chuntung .plugin .gistsnippet .service .GistSnippetService ;
1718import com .chuntung .plugin .gistsnippet .service .GithubAccountHolder ;
19+ import com .intellij .icons .AllIcons ;
1820import com .intellij .ide .BrowserUtil ;
1921import com .intellij .ide .util .PropertiesComponent ;
2022import com .intellij .ide .util .treeView .AbstractTreeStructure ;
3436import com .intellij .openapi .project .Project ;
3537import com .intellij .openapi .ui .DialogWrapper ;
3638import com .intellij .openapi .util .IconLoader ;
39+ import com .intellij .ui .ScrollPaneFactory ;
3740import com .intellij .ui .components .JBTabbedPane ;
3841import com .intellij .ui .components .labels .DropDownLink ;
3942import com .intellij .ui .components .labels .LinkLabel ;
5558import javax .swing .tree .DefaultMutableTreeNode ;
5659import javax .swing .tree .TreePath ;
5760import java .awt .*;
58- import java .awt .event .MouseAdapter ;
59- import java .awt .event .MouseEvent ;
6061import java .lang .reflect .Constructor ;
6162import java .util .ArrayList ;
6263import java .util .List ;
@@ -76,6 +77,7 @@ public class InsertGistDialog extends DialogWrapper {
7677 private JTextField textField1 ;
7778 private JComboBox languageComboBox ;
7879 private JComboBox sortByComboBox ;
80+ private JScrollPane scrollPane ;
7981
8082 private Project project ;
8183 private final boolean insertable ;
@@ -112,18 +114,8 @@ private void createUIComponents() {
112114 // Replace JTree with SimpleTree here due to ui designer fails to preview SimpleTree.
113115 snippetTree = new SimpleTree ();
114116 snippetTree .addTreeSelectionListener (e -> onSelect (e ));
115- snippetTree .addMouseListener (new MouseAdapter () {
116- @ Override
117- public void mouseClicked (MouseEvent e ) {
118- // double click to load forcibly
119- if (e .getButton () == e .BUTTON1 && e .getClickCount () == 2 ) {
120- DefaultMutableTreeNode selected = (DefaultMutableTreeNode ) ((JTree ) e .getComponent ()).getLastSelectedPathComponent ();
121- if (selected != null && selected .isLeaf ()) {
122- loadFileContent (project , selected , true );
123- }
124- }
125- }
126- });
117+
118+ scrollPane = ScrollPaneFactory .createScrollPane (snippetTree , true );
127119
128120 // use tree structure for rendering
129121 snippetRoot = new SnippetRootNode ();
@@ -226,7 +218,13 @@ private ActionGroup getPopupActions() {
226218 // delete gist
227219 group .add (new DeleteAction (snippetTree , snippetStructure , snippetRoot , project ));
228220
229- // open in browser
221+ // reload gist file
222+ group .add (new ReloadAction (snippetTree , e -> {
223+ DefaultMutableTreeNode node = (DefaultMutableTreeNode ) snippetTree .getLastSelectedPathComponent ();
224+ loadFileContent (project , node , true );
225+ }));
226+
227+ // open in browser for gist or file
230228 group .add (new OpenInBrowserAction (snippetTree ));
231229
232230 return group ;
@@ -264,6 +262,18 @@ public void actionPerformed(@NotNull AnActionEvent e) {
264262 )
265263 );
266264
265+ // refresh own/starred
266+ group .add (new AnAction ("Refresh" , "Refresh gist list" , AllIcons .Actions .Refresh ) {
267+ @ Override
268+ public void actionPerformed (@ NotNull AnActionEvent e ) {
269+ if ("Own" .equals (scopeAction .getText ())) {
270+ loadOwnGist (true );
271+ } else {
272+ loadStarredGist (true );
273+ }
274+ }
275+ });
276+
267277 group .addSeparator ();
268278
269279 group .add (new ExpandAllAction (snippetTree ));
@@ -273,8 +283,6 @@ public void actionPerformed(@NotNull AnActionEvent e) {
273283 }
274284
275285 private void initYoursPane (List <GithubAccount > accountList ) {
276- UIUtil .removeScrollBorder (yoursSplitPane );
277-
278286 yoursSplitPane .setVisible (true );
279287
280288 // init toolbar
@@ -284,7 +292,7 @@ private void initYoursPane(List<GithubAccount> accountList) {
284292 ((JPanel ) yoursSplitPane .getLeftComponent ()).add (actionToolbar .getComponent (), BorderLayout .NORTH );
285293
286294 // load remembered width
287- int width = PropertiesComponent .getInstance ().getInt (SPLIT_LEFT_WIDTH , 220 );
295+ int width = PropertiesComponent .getInstance ().getInt (SPLIT_LEFT_WIDTH , 240 );
288296 yoursSplitPane .getLeftComponent ().setPreferredSize (new Dimension (width , -1 ));
289297
290298 // bind editor
@@ -404,8 +412,10 @@ private <T> T getUserObject(DefaultMutableTreeNode node) {
404412 }
405413
406414 private void loadOwnGist (boolean forced ) {
407- // reset type filter
408- typeAction .reset ();
415+ // reset type filter for switch
416+ if (!forced ) {
417+ typeAction .reset ();
418+ }
409419
410420 // com.intellij.util.io.HttpRequests#process does not allow Network accessed in dispatch thread or read action
411421 // start a background task to bypass api limitation
@@ -443,7 +453,15 @@ public void run(@NotNull ProgressIndicator indicator) {
443453
444454 private void renderTree (List <GistDTO > gistList , ScopeEnum scope ) {
445455 snippetRoot .resetChildren (gistList , scope );
446- snippetStructure .invalidate ();
456+
457+ // filter by type if selected
458+ if ("Public" .equals (typeAction .getText ())) {
459+ filterByPublic (true );
460+ } else if ("Secret" .equals (typeAction .getText ())) {
461+ filterByPublic (false );
462+ } else {
463+ snippetStructure .invalidate ();
464+ }
447465 }
448466
449467 @ Nullable
0 commit comments