11package appland .actions ;
22
3+ import appland .AppMapBundle ;
4+ import appland .notifications .AppMapNotifications ;
35import appland .webviews .navie .NavieEditorProvider ;
46import appland .webviews .navie .NaviePromptSuggestion ;
57import com .intellij .icons .AllIcons ;
68import com .intellij .ide .util .PropertiesComponent ;
9+ import com .intellij .notification .Notification ;
10+ import com .intellij .notification .NotificationType ;
11+ import com .intellij .notification .Notifications ;
712import com .intellij .openapi .actionSystem .ActionUpdateThread ;
813import com .intellij .openapi .actionSystem .AnAction ;
914import com .intellij .openapi .actionSystem .AnActionEvent ;
@@ -43,23 +48,33 @@ public class QuickReviewAction extends AnAction implements DumbAware {
4348 return ActionUpdateThread .BGT ;
4449 }
4550
51+ @ Override
52+ public void update (@ NotNull AnActionEvent e ) {
53+ super .update (e );
54+ e .getPresentation ().setEnabled (e .getProject () != null );
55+ }
56+
4657 @ Override
4758 public void actionPerformed (@ NotNull AnActionEvent e ) {
4859 var project = e .getProject ();
49- if (project == null ) {
50- return ;
51- }
60+ assert (project != null );
5261
5362 var repositoryManager = GitRepositoryManager .getInstance (project );
5463 var repositories = repositoryManager .getRepositories ();
5564 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 );
5671 return ;
5772 }
5873
5974 // For now, we'll just use the first repository
6075 var repository = repositories .get (0 );
6176
62- new Task .Backgroundable (project , "Fetching Git Refs" , true ) {
77+ new Task .Backgroundable (project , AppMapBundle . get ( "action.appmap.quickReview.fetchingRefs.progressTitle" ) , true ) {
6378 private List <GitRef > refs ;
6479 private boolean dirty = false ;
6580
@@ -69,7 +84,7 @@ public void run(@NotNull ProgressIndicator indicator) {
6984 refs = getItems (project , repository );
7085 dirty = isDirty ();
7186 } catch (VcsException ex ) {
72- throw new RuntimeException ("Failed to fetch Git refs" , ex );
87+ throw new RuntimeException (ex );
7388 }
7489 }
7590
@@ -86,6 +101,18 @@ private boolean isDirty() {
86101 }
87102 }
88103
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+
89116 @ Override
90117 public void onSuccess () {
91118 if (refs == null || refs .isEmpty ()) {
@@ -100,9 +127,10 @@ public void onSuccess() {
100127 /* only show HEAD if the repository is dirty */
101128 .filter (gitRef -> dirty || !gitRef .commit .equals (head ))
102129 .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" );
104132 if (gitRef .label .equals (lastPickedRef )) {
105- gitRef .description = "last picked ⋅ " + gitRef .description ;
133+ gitRef .description = AppMapBundle . get ( "action.appmap.quickReview.lastPickedPrefix" ) + " ⋅ " + gitRef .description ;
106134 seenLastPicked .set (true );
107135 }
108136 })
@@ -116,19 +144,21 @@ public void onSuccess() {
116144 var popup = JBPopupFactory .getInstance ()
117145 .createPopupChooserBuilder (refs )
118146 .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" )
122152 .setRequestFocus (true )
123153 .setItemChosenCallback ((selectedValue ) -> {
124154 if (selectedValue != null ) {
125155 PropertiesComponent .getInstance ().setValue (LAST_PICKED_REF_KEY , selectedValue .label );
126156 NavieEditorProvider .openEditorWithPrompt (project , new NaviePromptSuggestion (
127- "Quick Review" ,
157+ AppMapBundle . get ( "action.appmap.quickReview.text" ) ,
128158 String .format ("@review /base=%s" , selectedValue .label )));
129159 }
130160 }).createPopup ();
131- popup .showCenteredInCurrentWindow ( project );
161+ popup .showInBestPositionFor ( e . getDataContext () );
132162 }
133163 }.queue ();
134164 }
@@ -241,8 +271,11 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
241271 var component = (JLabel ) super .getListCellRendererComponent (list , value , index , isSelected , cellHasFocus );
242272 if (value instanceof GitRef ) {
243273 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 ) + "..." ;
244277 component .setText ("<html><b>" + ref .label + "</b> " +
245- "<small>" + ref . description + "</small></html>" );
278+ "<small>" + description + "</small></html>" );
246279 component .setIcon (ref .getIcon ());
247280 }
248281 return component ;
@@ -252,7 +285,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
252285 // HACK: platform version 241 does not define GitCommand.FOR_EACH_REF
253286 // and the final GitCommand constructors are private, so we need to replace
254287 // the command in GitLineHandler with a custom one.
255- class GitCommandLineHandler extends GitLineHandler {
288+ private static class GitCommandLineHandler extends GitLineHandler {
256289 public GitCommandLineHandler (@ Nullable Project project , @ NotNull VirtualFile directory , @ NotNull String command ) {
257290 super (project , directory , GitCommand .LOG );
258291 var paramsList = this .myCommandLine .getParametersList ();
0 commit comments