From a8ddcad99e74f461afad23538992ba85e3805b83 Mon Sep 17 00:00:00 2001 From: Michael Kaspera Date: Wed, 28 Sep 2022 09:43:32 +0200 Subject: [PATCH] feat: ts and js files have their warnings updated if an ignored warning is deleted --- .../options/IgnoredWarningsTablePanel.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/options/IgnoredWarningsTablePanel.java b/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/options/IgnoredWarningsTablePanel.java index 4cdcd85..4635c68 100644 --- a/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/options/IgnoredWarningsTablePanel.java +++ b/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/options/IgnoredWarningsTablePanel.java @@ -7,8 +7,9 @@ import de.adito.swing.icon.IconAttributes; import org.jetbrains.annotations.*; import org.netbeans.api.project.Project; -import org.openide.filesystems.FileUtil; +import org.openide.filesystems.*; import org.openide.util.Lookup; +import org.openide.windows.TopComponent; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -17,6 +18,9 @@ import java.awt.*; import java.awt.event.*; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.attribute.FileTime; +import java.time.Instant; import java.util.List; import java.util.*; import java.util.stream.Collectors; @@ -153,6 +157,8 @@ private void fireModelChanged() private static class RemoveIgnoredWarningsAction extends AbstractAction { + @NotNull + private static final Set MIME_TYPES = Set.of("text/javascript", "text/typescript"); @NotNull private final Project project; @NotNull @@ -184,6 +190,8 @@ public void actionPerformed(ActionEvent e) { IgnoredWarningsFacade.unIgnoreWarnings(project, itemsToRemove); FileUtil.toFileObject(IgnoredWarningsProvider.getIgnoredWarningsFile(project)).refresh(); + updateTopcomponents(); + } catch (IOException pE) { @@ -191,5 +199,23 @@ public void actionPerformed(ActionEvent e) } } } + + /** + * trigger an update of all TopComponents containing js or ts files -> warnings are refreshed + * + * @throws IOException in case the lastModified time on a file cannot be set + */ + private void updateTopcomponents() throws IOException + { + for (TopComponent topComponent : TopComponent.getRegistry().getOpened()) + { + FileObject fileObject = topComponent.getLookup().lookup(FileObject.class); + if (MIME_TYPES.contains(fileObject.getMIMEType())) + { + Files.setLastModifiedTime(FileUtil.toFile(fileObject).toPath(), FileTime.from(Instant.now())); + fileObject.refresh(); + } + } + } } }