From e78d951eb46afe1b932225921133721f96a29379 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Sun, 30 Mar 2025 11:11:37 +0200 Subject: [PATCH] Register icons for git stash and nb shelve actions So that they can be added to the toolbar. --- ide/git/nbproject/project.xml | 9 ++ .../git/ui/shelve/ShelveChangesAction.java | 90 ++++++++++--------- .../modules/git/ui/stash/SaveStashAction.java | 44 +++++---- 3 files changed, 84 insertions(+), 59 deletions(-) diff --git a/ide/git/nbproject/project.xml b/ide/git/nbproject/project.xml index 816ff589d1c4..c11cca52fa07 100644 --- a/ide/git/nbproject/project.xml +++ b/ide/git/nbproject/project.xml @@ -30,6 +30,15 @@ + + org.netbeans.api.annotations.common + + + + 1 + 1.56 + + org.netbeans.api.progress diff --git a/ide/git/src/org/netbeans/modules/git/ui/shelve/ShelveChangesAction.java b/ide/git/src/org/netbeans/modules/git/ui/shelve/ShelveChangesAction.java index e59bc03def10..4654463464a9 100644 --- a/ide/git/src/org/netbeans/modules/git/ui/shelve/ShelveChangesAction.java +++ b/ide/git/src/org/netbeans/modules/git/ui/shelve/ShelveChangesAction.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.ListIterator; import java.util.Set; -import java.util.concurrent.Callable; import javax.swing.Action; import javax.swing.BoxLayout; import javax.swing.JCheckBox; @@ -39,6 +38,7 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.libs.git.GitClient.DiffMode; import org.netbeans.libs.git.GitException; import org.netbeans.libs.git.GitRevisionInfo; @@ -69,18 +69,33 @@ import org.openide.windows.WindowManager; /** + * Shelve modifications of one or more files in form of a patch file. * * @author Ondra Vrabec */ @ActionID(id = "org.netbeans.modules.git.ui.shelve.ShelveChangesAction", category = "Git") @ActionRegistration(displayName = "#CTL_ShelveChanges_Title") @NbBundle.Messages({ - "CTL_ShelveChanges_Title=&Shelve Changes...", - "LBL_ShelveChangesAction_Name=&Shelve Changes..." + "CTL_ShelveChanges_Title=&Shelve selected Changes...", + "LBL_ShelveChangesAction_Name=&Shelve selected Changes..." }) public class ShelveChangesAction extends SingleRepositoryAction { + private static ShelveChangesActionProvider ACTION_PROVIDER; + // TODO pick/create better icon + @StaticResource + private static final String ICON_RESOURCE = "org/netbeans/modules/git/resources/icons/diff.png"; //NOI18N + + public ShelveChangesAction() { + super(ICON_RESOURCE); + } + + @Override + protected String iconResource() { + return ICON_RESOURCE; + } + @Override protected void performAction (File repository, File[] roots, VCSContext context) { shelve(repository, roots); @@ -94,14 +109,13 @@ public void shelve (File repository, File[] roots) { if (Git.getInstance().getFileStatusCache().listFiles(roots, FileInformation.STATUS_MODIFIED_HEAD_VS_WORKING).length == 0) { // no local changes found - EventQueue.invokeLater(new Runnable() { - @Override - public void run () { - JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), - Bundle.MSG_ShelveAction_noModifications_text(), - Bundle.LBL_ShelveAction_noModifications_title(), - JOptionPane.INFORMATION_MESSAGE); - } + EventQueue.invokeLater(() -> { + JOptionPane.showMessageDialog( + WindowManager.getDefault().getMainWindow(), + Bundle.MSG_ShelveAction_noModifications_text(), + Bundle.LBL_ShelveAction_noModifications_title(), + JOptionPane.INFORMATION_MESSAGE + ); }); return; } @@ -192,33 +206,26 @@ protected void exportPatch (File toFile, File commonParent) throws IOException { "# {0} - repository name", "MSG_ShelveChanges.progress.reverting=Reverting local changes - {0}" }) protected void postExportCleanup () { - final Collection notifiedFiles = new HashSet(); + final Collection notifiedFiles = new HashSet<>(); if (support.isCanceled()) { return; } try { - GitUtils.runWithoutIndexing(new Callable() { - @Override - public Void call () throws Exception { - support.setDisplayName(Bundle.MSG_ShelveChanges_progress_reverting(repository.getName())); - // init client - GitClient client = Git.getInstance().getClient(repository); - client.addNotificationListener(new FileListener() { - @Override - public void notifyFile (File file, String relativePathToRoot) { - notifiedFiles.add(file); - } - }); - client.addNotificationListener(support.new DefaultFileListener(modifications)); - - // revert - client.checkout(modifications, doRevertIndex ? GitUtils.HEAD : null, - true, support.getProgressMonitor()); - if(doPurge) { - client.clean(modifications, support.getProgressMonitor()); - } - return null; + GitUtils.runWithoutIndexing(() -> { + support.setDisplayName(Bundle.MSG_ShelveChanges_progress_reverting(repository.getName())); + // init client + GitClient client = Git.getInstance().getClient(repository); + client.addNotificationListener((FileListener) (file, relativePathToRoot) -> { + notifiedFiles.add(file); + }); + client.addNotificationListener(support.new DefaultFileListener(modifications)); + + // revert + client.checkout(modifications, doRevertIndex ? GitUtils.HEAD : null, true, support.getProgressMonitor()); + if(doPurge) { + client.clean(modifications, support.getProgressMonitor()); } + return null; }, modifications); } catch (GitException ex) { GitClientExceptionHandler.notifyException(ex, true); @@ -239,8 +246,9 @@ private void startAsync (RequestProcessor rp, final File repository, final File[ support = new ShelveChangesProgressSupport() { @Override protected void perform () { - modifications = Git.getInstance().getFileStatusCache().listFiles(roots, - FileInformation.STATUS_MODIFIED_HEAD_VS_WORKING); + modifications = Git.getInstance().getFileStatusCache().listFiles( + roots, FileInformation.STATUS_MODIFIED_HEAD_VS_WORKING + ); // shelve changes builds common root, it must be the repository root folder // because we use export diff action from the git api File[] arr = Arrays.copyOf(modifications, modifications.length + 1); @@ -274,7 +282,7 @@ public Action getAction () { @Override public JComponent[] getUnshelveActions (VCSContext ctx, boolean popup) { - JComponent[] cont = UnshelveMenu.getInstance().getMenu(ctx, popup); + JComponent[] cont = UnstashMenu.getInstance().getMenu(ctx, popup); if (cont == null) { cont = super.getUnshelveActions(ctx, popup); } @@ -294,18 +302,20 @@ public void setDisplayName (String displayName) { } } + // TODO git unstash in shelve action? + @NbBundle.Messages({ "CTL_UnstashMenu.name=&Git Unstash", "CTL_UnstashMenu.name.popup=Git Unstash", "# {0} - stash index", "# {1} - stash name", "CTL_UnstashAction.name={0} - {1}" }) - private static class UnshelveMenu { + private static class UnstashMenu { - private static UnshelveMenu instance; + private static UnstashMenu instance; - static synchronized UnshelveMenu getInstance () { + static synchronized UnstashMenu getInstance() { if (instance == null) { - instance = new UnshelveMenu(); + instance = new UnstashMenu(); } return instance; } diff --git a/ide/git/src/org/netbeans/modules/git/ui/stash/SaveStashAction.java b/ide/git/src/org/netbeans/modules/git/ui/stash/SaveStashAction.java index ec91d1b6e4f5..f12478950c96 100644 --- a/ide/git/src/org/netbeans/modules/git/ui/stash/SaveStashAction.java +++ b/ide/git/src/org/netbeans/modules/git/ui/stash/SaveStashAction.java @@ -23,7 +23,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.concurrent.Callable; +import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.libs.git.GitException; import org.netbeans.modules.git.FileInformation; import org.netbeans.modules.git.Git; @@ -43,6 +43,7 @@ import org.openide.util.NbBundle; /** + * Git stash action, currently only repo wide. * * @author Ondra Vrabec */ @@ -56,7 +57,20 @@ "MSG_SaveStashAction.noModifications=There are no uncommitted changes to stash." }) public class SaveStashAction extends SingleRepositoryAction { - + + // TODO pick/create better icon + @StaticResource + private static final String ICON_RESOURCE = "org/netbeans/modules/git/resources/icons/get_clean.png"; //NOI18N + + public SaveStashAction() { + super(ICON_RESOURCE); + } + + @Override + protected String iconResource() { + return ICON_RESOURCE; + } + @Override protected void performAction (File repository, File[] roots, VCSContext context) { saveStash(repository, roots); @@ -75,20 +89,16 @@ public void saveStash (final File repository, final File[] roots) { NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.INFORMATION_MESSAGE, new Object[]{NotifyDescriptor.OK_OPTION}, - NotifyDescriptor.OK_OPTION); + NotifyDescriptor.OK_OPTION + ); DialogDisplayer.getDefault().notifyLater(nd); return; } - Mutex.EVENT.readAccess(new Runnable () { - - @Override - public void run () { - SaveStash saveStash = new SaveStash(repository, roots, RepositoryInfo.getInstance(repository).getActiveBranch()); - if (saveStash.show()) { - start(repository, modifications, saveStash); - } + Mutex.EVENT.readAccess(() -> { + SaveStash saveStash = new SaveStash(repository, roots, RepositoryInfo.getInstance(repository).getActiveBranch()); + if (saveStash.show()) { + start(repository, modifications, saveStash); } - }); } @@ -98,13 +108,9 @@ private void start (final File repository, final File[] modifications, final Sav protected void perform () { try { final GitClient client = getClient(); - GitUtils.runWithoutIndexing(new Callable() { - - @Override - public Void call () throws Exception { - client.stashSave(saveStash.getMessage(), saveStash.isIncludeUncommitted(), getProgressMonitor()); - return null; - } + GitUtils.runWithoutIndexing(() -> { + client.stashSave(saveStash.getMessage(), saveStash.isIncludeUncommitted(), getProgressMonitor()); + return null; }, new File[] { repository }); RepositoryInfo.getInstance(repository).refreshStashes(); } catch (GitException ex) {