Skip to content

Commit 4c5e954

Browse files
committed
Register icons for git stash and nb shelve actions
So that they can be added to the toolbar.
1 parent 4ee1cc7 commit 4c5e954

File tree

3 files changed

+82
-57
lines changed

3 files changed

+82
-57
lines changed

Diff for: ide/git/nbproject/project.xml

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
<compile-dependency/>
3131
<run-dependency/>
3232
</dependency>
33+
<dependency>
34+
<code-name-base>org.netbeans.api.annotations.common</code-name-base>
35+
<build-prerequisite/>
36+
<compile-dependency/>
37+
<run-dependency>
38+
<release-version>1</release-version>
39+
<specification-version>1.56</specification-version>
40+
</run-dependency>
41+
</dependency>
3342
<dependency>
3443
<code-name-base>org.netbeans.api.progress</code-name-base>
3544
<build-prerequisite/>

Diff for: ide/git/src/org/netbeans/modules/git/ui/shelve/ShelveChangesAction.java

+48-38
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.List;
3131
import java.util.ListIterator;
3232
import java.util.Set;
33-
import java.util.concurrent.Callable;
3433
import javax.swing.Action;
3534
import javax.swing.BoxLayout;
3635
import javax.swing.JCheckBox;
@@ -39,6 +38,7 @@
3938
import javax.swing.JMenuItem;
4039
import javax.swing.JOptionPane;
4140
import javax.swing.JPanel;
41+
import org.netbeans.api.annotations.common.StaticResource;
4242
import org.netbeans.libs.git.GitClient.DiffMode;
4343
import org.netbeans.libs.git.GitException;
4444
import org.netbeans.libs.git.GitRevisionInfo;
@@ -69,18 +69,33 @@
6969
import org.openide.windows.WindowManager;
7070

7171
/**
72+
* Shelve modifications of one or more files in form of a patch file.
7273
*
7374
* @author Ondra Vrabec
7475
*/
7576
@ActionID(id = "org.netbeans.modules.git.ui.shelve.ShelveChangesAction", category = "Git")
7677
@ActionRegistration(displayName = "#CTL_ShelveChanges_Title")
7778
@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..."
8081
})
8182
public class ShelveChangesAction extends SingleRepositoryAction {
83+
8284
private static ShelveChangesActionProvider ACTION_PROVIDER;
8385

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+
8499
@Override
85100
protected void performAction (File repository, File[] roots, VCSContext context) {
86101
shelve(repository, roots);
@@ -94,14 +109,13 @@ public void shelve (File repository, File[] roots) {
94109
if (Git.getInstance().getFileStatusCache().listFiles(roots,
95110
FileInformation.STATUS_MODIFIED_HEAD_VS_WORKING).length == 0) {
96111
// 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+
);
105119
});
106120
return;
107121
}
@@ -192,33 +206,27 @@ protected void exportPatch (File toFile, File commonParent) throws IOException {
192206
"# {0} - repository name", "MSG_ShelveChanges.progress.reverting=Reverting local changes - {0}"
193207
})
194208
protected void postExportCleanup () {
195-
final Collection<File> notifiedFiles = new HashSet<File>();
209+
final Collection<File> notifiedFiles = new HashSet<>();
196210
if (support.isCanceled()) {
197211
return;
198212
}
199213
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());
221228
}
229+
return null;
222230
}, modifications);
223231
} catch (GitException ex) {
224232
GitClientExceptionHandler.notifyException(ex, true);
@@ -274,7 +282,7 @@ public Action getAction () {
274282

275283
@Override
276284
public JComponent[] getUnshelveActions (VCSContext ctx, boolean popup) {
277-
JComponent[] cont = UnshelveMenu.getInstance().getMenu(ctx, popup);
285+
JComponent[] cont = UnstashMenu.getInstance().getMenu(ctx, popup);
278286
if (cont == null) {
279287
cont = super.getUnshelveActions(ctx, popup);
280288
}
@@ -294,18 +302,20 @@ public void setDisplayName (String displayName) {
294302
}
295303
}
296304

305+
// TODO git unstash in shelve action?
306+
297307
@NbBundle.Messages({
298308
"CTL_UnstashMenu.name=&Git Unstash",
299309
"CTL_UnstashMenu.name.popup=Git Unstash",
300310
"# {0} - stash index", "# {1} - stash name", "CTL_UnstashAction.name={0} - {1}"
301311
})
302-
private static class UnshelveMenu {
312+
private static class UnstashMenu {
303313

304-
private static UnshelveMenu instance;
314+
private static UnstashMenu instance;
305315

306-
static synchronized UnshelveMenu getInstance () {
316+
static synchronized UnstashMenu getInstance() {
307317
if (instance == null) {
308-
instance = new UnshelveMenu();
318+
instance = new UnstashMenu();
309319
}
310320
return instance;
311321
}

Diff for: ide/git/src/org/netbeans/modules/git/ui/stash/SaveStashAction.java

+25-19
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Arrays;
2424
import java.util.Collection;
2525
import java.util.Collections;
26-
import java.util.concurrent.Callable;
26+
import org.netbeans.api.annotations.common.StaticResource;
2727
import org.netbeans.libs.git.GitException;
2828
import org.netbeans.modules.git.FileInformation;
2929
import org.netbeans.modules.git.Git;
@@ -43,6 +43,7 @@
4343
import org.openide.util.NbBundle;
4444

4545
/**
46+
* Git stash action, currently only repo wide.
4647
*
4748
* @author Ondra Vrabec
4849
*/
@@ -56,7 +57,20 @@
5657
"MSG_SaveStashAction.noModifications=There are no uncommitted changes to stash."
5758
})
5859
public class SaveStashAction extends SingleRepositoryAction {
59-
60+
61+
// TODO pick/create better icon
62+
@StaticResource
63+
private static final String ICON_RESOURCE = "org/netbeans/modules/git/resources/icons/get_clean.png"; //NOI18N
64+
65+
public SaveStashAction() {
66+
super(ICON_RESOURCE);
67+
}
68+
69+
@Override
70+
protected String iconResource() {
71+
return ICON_RESOURCE;
72+
}
73+
6074
@Override
6175
protected void performAction (File repository, File[] roots, VCSContext context) {
6276
saveStash(repository, roots);
@@ -75,20 +89,16 @@ public void saveStash (final File repository, final File[] roots) {
7589
NotifyDescriptor.DEFAULT_OPTION,
7690
NotifyDescriptor.INFORMATION_MESSAGE,
7791
new Object[]{NotifyDescriptor.OK_OPTION},
78-
NotifyDescriptor.OK_OPTION);
92+
NotifyDescriptor.OK_OPTION
93+
);
7994
DialogDisplayer.getDefault().notifyLater(nd);
8095
return;
8196
}
82-
Mutex.EVENT.readAccess(new Runnable () {
83-
84-
@Override
85-
public void run () {
86-
SaveStash saveStash = new SaveStash(repository, roots, RepositoryInfo.getInstance(repository).getActiveBranch());
87-
if (saveStash.show()) {
88-
start(repository, modifications, saveStash);
89-
}
97+
Mutex.EVENT.readAccess(() -> {
98+
SaveStash saveStash = new SaveStash(repository, roots, RepositoryInfo.getInstance(repository).getActiveBranch());
99+
if (saveStash.show()) {
100+
start(repository, modifications, saveStash);
90101
}
91-
92102
});
93103
}
94104

@@ -98,13 +108,9 @@ private void start (final File repository, final File[] modifications, final Sav
98108
protected void perform () {
99109
try {
100110
final GitClient client = getClient();
101-
GitUtils.runWithoutIndexing(new Callable<Void>() {
102-
103-
@Override
104-
public Void call () throws Exception {
105-
client.stashSave(saveStash.getMessage(), saveStash.isIncludeUncommitted(), getProgressMonitor());
106-
return null;
107-
}
111+
GitUtils.runWithoutIndexing(() -> {
112+
client.stashSave(saveStash.getMessage(), saveStash.isIncludeUncommitted(), getProgressMonitor());
113+
return null;
108114
}, new File[] { repository });
109115
RepositoryInfo.getInstance(repository).refreshStashes();
110116
} catch (GitException ex) {

0 commit comments

Comments
 (0)