1
1
package appland .actions ;
2
2
3
+ import appland .AppMapBundle ;
4
+ import appland .notifications .AppMapNotifications ;
3
5
import appland .webviews .navie .NavieEditorProvider ;
4
6
import appland .webviews .navie .NaviePromptSuggestion ;
5
7
import com .intellij .icons .AllIcons ;
6
8
import com .intellij .ide .util .PropertiesComponent ;
9
+ import com .intellij .notification .Notification ;
10
+ import com .intellij .notification .NotificationType ;
11
+ import com .intellij .notification .Notifications ;
7
12
import com .intellij .openapi .actionSystem .ActionUpdateThread ;
8
13
import com .intellij .openapi .actionSystem .AnAction ;
9
14
import com .intellij .openapi .actionSystem .AnActionEvent ;
@@ -43,23 +48,33 @@ public class QuickReviewAction extends AnAction implements DumbAware {
43
48
return ActionUpdateThread .BGT ;
44
49
}
45
50
51
+ @ Override
52
+ public void update (@ NotNull AnActionEvent e ) {
53
+ super .update (e );
54
+ e .getPresentation ().setEnabled (e .getProject () != null );
55
+ }
56
+
46
57
@ Override
47
58
public void actionPerformed (@ NotNull AnActionEvent e ) {
48
59
var project = e .getProject ();
49
- if (project == null ) {
50
- return ;
51
- }
60
+ assert (project != null );
52
61
53
62
var repositoryManager = GitRepositoryManager .getInstance (project );
54
63
var repositories = repositoryManager .getRepositories ();
55
64
if (repositories .isEmpty ()) {
65
+ Notifications .Bus .notify (new Notification (
66
+ AppMapNotifications .GENERIC_NOTIFICATIONS_ID ,
67
+ AppMapBundle .get ("action.appmap.quickReview.noRepositories.title" ),
68
+ AppMapBundle .get ("action.appmap.quickReview.noRepositories.message" ),
69
+ NotificationType .INFORMATION
70
+ ), project );
56
71
return ;
57
72
}
58
73
59
74
// For now, we'll just use the first repository
60
75
var repository = repositories .get (0 );
61
76
62
- new Task .Backgroundable (project , "Fetching Git Refs" , true ) {
77
+ new Task .Backgroundable (project , AppMapBundle . get ( "action.appmap.quickReview.fetchingRefs.progressTitle" ) , true ) {
63
78
private List <GitRef > refs ;
64
79
private boolean dirty = false ;
65
80
@@ -69,7 +84,7 @@ public void run(@NotNull ProgressIndicator indicator) {
69
84
refs = getItems (project , repository );
70
85
dirty = isDirty ();
71
86
} catch (VcsException ex ) {
72
- throw new RuntimeException ("Failed to fetch Git refs" , ex );
87
+ throw new RuntimeException (ex );
73
88
}
74
89
}
75
90
@@ -86,6 +101,18 @@ private boolean isDirty() {
86
101
}
87
102
}
88
103
104
+ @ Override
105
+ public void onThrowable (@ NotNull Throwable error ) {
106
+ new Notification (
107
+ AppMapNotifications .GENERIC_NOTIFICATIONS_ID ,
108
+ AppMapBundle .get ("action.appmap.quickReview.fetchingRefs.error" ),
109
+ error .getMessage () != null
110
+ ? error .getMessage () + "<br><br><code>" + error .toString () + "</code>"
111
+ : error .toString (),
112
+ NotificationType .ERROR
113
+ ).notify (project );
114
+ }
115
+
89
116
@ Override
90
117
public void onSuccess () {
91
118
if (refs == null || refs .isEmpty ()) {
@@ -100,9 +127,10 @@ public void onSuccess() {
100
127
/* only show HEAD if the repository is dirty */
101
128
.filter (gitRef -> dirty || !gitRef .commit .equals (head ))
102
129
.peek (gitRef -> {
103
- if (gitRef .commit .equals (head )) gitRef .description = "review uncommitted changes" ;
130
+ if (gitRef .commit .equals (head ))
131
+ gitRef .description = AppMapBundle .get ("action.appmap.quickReview.reviewUncommittedChanges" );
104
132
if (gitRef .label .equals (lastPickedRef )) {
105
- gitRef .description = "last picked ⋅ " + gitRef .description ;
133
+ gitRef .description = AppMapBundle . get ( "action.appmap.quickReview.lastPickedPrefix" ) + " ⋅ " + gitRef .description ;
106
134
seenLastPicked .set (true );
107
135
}
108
136
})
@@ -116,19 +144,21 @@ public void onSuccess() {
116
144
var popup = JBPopupFactory .getInstance ()
117
145
.createPopupChooserBuilder (refs )
118
146
.setRenderer (new GitRefCellRenderer ())
119
- .setTitle ("Select base for review" )
120
- .setMovable (false )
121
- .setResizable (false )
147
+ .setTitle (AppMapBundle .get ("action.appmap.quickReview.selectBase.title" ))
148
+ .setNamerForFiltering (GitRef ::toString )
149
+ .setMovable (true )
150
+ .setResizable (true )
151
+ .setDimensionServiceKey ("appmap.quickReviewPopup" )
122
152
.setRequestFocus (true )
123
153
.setItemChosenCallback ((selectedValue ) -> {
124
154
if (selectedValue != null ) {
125
155
PropertiesComponent .getInstance ().setValue (LAST_PICKED_REF_KEY , selectedValue .label );
126
156
NavieEditorProvider .openEditorWithPrompt (project , new NaviePromptSuggestion (
127
- "Quick Review" ,
157
+ AppMapBundle . get ( "action.appmap.quickReview.text" ) ,
128
158
String .format ("@review /base=%s" , selectedValue .label )));
129
159
}
130
160
}).createPopup ();
131
- popup .showCenteredInCurrentWindow ( project );
161
+ popup .showInBestPositionFor ( e . getDataContext () );
132
162
}
133
163
}.queue ();
134
164
}
@@ -241,8 +271,11 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
241
271
var component = (JLabel ) super .getListCellRendererComponent (list , value , index , isSelected , cellHasFocus );
242
272
if (value instanceof GitRef ) {
243
273
var ref = (GitRef ) value ;
274
+ var description = ref .description != null ? ref .description : "" ;
275
+ // sometimes description is very long, truncate it then
276
+ if (description .length () > 100 ) description = description .substring (0 , 100 ) + "..." ;
244
277
component .setText ("<html><b>" + ref .label + "</b> " +
245
- "<small>" + ref . description + "</small></html>" );
278
+ "<small>" + description + "</small></html>" );
246
279
component .setIcon (ref .getIcon ());
247
280
}
248
281
return component ;
@@ -252,7 +285,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
252
285
// HACK: platform version 241 does not define GitCommand.FOR_EACH_REF
253
286
// and the final GitCommand constructors are private, so we need to replace
254
287
// the command in GitLineHandler with a custom one.
255
- class GitCommandLineHandler extends GitLineHandler {
288
+ private static class GitCommandLineHandler extends GitLineHandler {
256
289
public GitCommandLineHandler (@ Nullable Project project , @ NotNull VirtualFile directory , @ NotNull String command ) {
257
290
super (project , directory , GitCommand .LOG );
258
291
var paramsList = this .myCommandLine .getParametersList ();
0 commit comments