30
30
import java .util .List ;
31
31
import java .util .ListIterator ;
32
32
import java .util .Set ;
33
- import java .util .concurrent .Callable ;
34
33
import javax .swing .Action ;
35
34
import javax .swing .BoxLayout ;
36
35
import javax .swing .JCheckBox ;
39
38
import javax .swing .JMenuItem ;
40
39
import javax .swing .JOptionPane ;
41
40
import javax .swing .JPanel ;
41
+ import org .netbeans .api .annotations .common .StaticResource ;
42
42
import org .netbeans .libs .git .GitClient .DiffMode ;
43
43
import org .netbeans .libs .git .GitException ;
44
44
import org .netbeans .libs .git .GitRevisionInfo ;
69
69
import org .openide .windows .WindowManager ;
70
70
71
71
/**
72
+ * Shelve modifications of one or more files in form of a patch file.
72
73
*
73
74
* @author Ondra Vrabec
74
75
*/
75
76
@ ActionID (id = "org.netbeans.modules.git.ui.shelve.ShelveChangesAction" , category = "Git" )
76
77
@ ActionRegistration (displayName = "#CTL_ShelveChanges_Title" )
77
78
@ NbBundle .Messages ({
78
- "CTL_ShelveChanges_Title=&Shelve Changes..." ,
79
- "LBL_ShelveChangesAction_Name=&Shelve Changes..."
79
+ "CTL_ShelveChanges_Title=&Shelve selected Changes..." ,
80
+ "LBL_ShelveChangesAction_Name=&Shelve selected Changes..."
80
81
})
81
82
public class ShelveChangesAction extends SingleRepositoryAction {
83
+
82
84
private static ShelveChangesActionProvider ACTION_PROVIDER ;
83
85
86
+ // TODO pick/create better icon
87
+ @ StaticResource
88
+ private static final String ICON_RESOURCE = "org/netbeans/modules/git/resources/icons/diff.png" ; //NOI18N
89
+
90
+ public ShelveChangesAction () {
91
+ super (ICON_RESOURCE );
92
+ }
93
+
94
+ @ Override
95
+ protected String iconResource () {
96
+ return ICON_RESOURCE ;
97
+ }
98
+
84
99
@ Override
85
100
protected void performAction (File repository , File [] roots , VCSContext context ) {
86
101
shelve (repository , roots );
@@ -94,14 +109,13 @@ public void shelve (File repository, File[] roots) {
94
109
if (Git .getInstance ().getFileStatusCache ().listFiles (roots ,
95
110
FileInformation .STATUS_MODIFIED_HEAD_VS_WORKING ).length == 0 ) {
96
111
// no local changes found
97
- EventQueue .invokeLater (new Runnable () {
98
- @ Override
99
- public void run () {
100
- JOptionPane .showMessageDialog (WindowManager .getDefault ().getMainWindow (),
101
- Bundle .MSG_ShelveAction_noModifications_text (),
102
- Bundle .LBL_ShelveAction_noModifications_title (),
103
- JOptionPane .INFORMATION_MESSAGE );
104
- }
112
+ EventQueue .invokeLater (() -> {
113
+ JOptionPane .showMessageDialog (
114
+ WindowManager .getDefault ().getMainWindow (),
115
+ Bundle .MSG_ShelveAction_noModifications_text (),
116
+ Bundle .LBL_ShelveAction_noModifications_title (),
117
+ JOptionPane .INFORMATION_MESSAGE
118
+ );
105
119
});
106
120
return ;
107
121
}
@@ -192,33 +206,27 @@ protected void exportPatch (File toFile, File commonParent) throws IOException {
192
206
"# {0} - repository name" , "MSG_ShelveChanges.progress.reverting=Reverting local changes - {0}"
193
207
})
194
208
protected void postExportCleanup () {
195
- final Collection <File > notifiedFiles = new HashSet <File >();
209
+ final Collection <File > notifiedFiles = new HashSet <>();
196
210
if (support .isCanceled ()) {
197
211
return ;
198
212
}
199
213
try {
200
- GitUtils .runWithoutIndexing (new Callable <Void >() {
201
- @ Override
202
- public Void call () throws Exception {
203
- support .setDisplayName (Bundle .MSG_ShelveChanges_progress_reverting (repository .getName ()));
204
- // init client
205
- GitClient client = Git .getInstance ().getClient (repository );
206
- client .addNotificationListener (new FileListener () {
207
- @ Override
208
- public void notifyFile (File file , String relativePathToRoot ) {
209
- notifiedFiles .add (file );
210
- }
211
- });
212
- client .addNotificationListener (support .new DefaultFileListener (modifications ));
213
-
214
- // revert
215
- client .checkout (modifications , doRevertIndex ? GitUtils .HEAD : null ,
216
- true , support .getProgressMonitor ());
217
- if (doPurge ) {
218
- client .clean (modifications , support .getProgressMonitor ());
219
- }
220
- return null ;
214
+ GitUtils .runWithoutIndexing (() -> {
215
+ support .setDisplayName (Bundle .MSG_ShelveChanges_progress_reverting (repository .getName ()));
216
+ // init client
217
+ GitClient client = Git .getInstance ().getClient (repository );
218
+ client .addNotificationListener ((FileListener ) (file , relativePathToRoot ) -> {
219
+ notifiedFiles .add (file );
220
+ });
221
+ client .addNotificationListener (support .new DefaultFileListener (modifications ));
222
+
223
+ // revert
224
+ client .checkout (modifications , doRevertIndex ? GitUtils .HEAD : null ,
225
+ true , support .getProgressMonitor ());
226
+ if (doPurge ) {
227
+ client .clean (modifications , support .getProgressMonitor ());
221
228
}
229
+ return null ;
222
230
}, modifications );
223
231
} catch (GitException ex ) {
224
232
GitClientExceptionHandler .notifyException (ex , true );
@@ -274,7 +282,7 @@ public Action getAction () {
274
282
275
283
@ Override
276
284
public JComponent [] getUnshelveActions (VCSContext ctx , boolean popup ) {
277
- JComponent [] cont = UnshelveMenu .getInstance ().getMenu (ctx , popup );
285
+ JComponent [] cont = UnstashMenu .getInstance ().getMenu (ctx , popup );
278
286
if (cont == null ) {
279
287
cont = super .getUnshelveActions (ctx , popup );
280
288
}
@@ -294,18 +302,20 @@ public void setDisplayName (String displayName) {
294
302
}
295
303
}
296
304
305
+ // TODO git unstash in shelve action?
306
+
297
307
@ NbBundle .Messages ({
298
308
"CTL_UnstashMenu.name=&Git Unstash" ,
299
309
"CTL_UnstashMenu.name.popup=Git Unstash" ,
300
310
"# {0} - stash index" , "# {1} - stash name" , "CTL_UnstashAction.name={0} - {1}"
301
311
})
302
- private static class UnshelveMenu {
312
+ private static class UnstashMenu {
303
313
304
- private static UnshelveMenu instance ;
314
+ private static UnstashMenu instance ;
305
315
306
- static synchronized UnshelveMenu getInstance () {
316
+ static synchronized UnstashMenu getInstance () {
307
317
if (instance == null ) {
308
- instance = new UnshelveMenu ();
318
+ instance = new UnstashMenu ();
309
319
}
310
320
return instance ;
311
321
}
0 commit comments