From ce575ef028d538f7149ecfa7e5ffed0f549ff59b Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 20 Dec 2020 12:52:22 +0100 Subject: [PATCH] #63 - Fixed & refactored code. --- pom.xml | 16 +--- .../netbeans/minifierbeans/css/CSSMinify.java | 30 +++--- .../minifierbeans/javascript/JSMinify.java | 35 ++++--- .../javascript/ui/options/JsOptionsPanel.java | 23 ----- .../minifierbeans/task/EditorSaveTask.java | 35 ++++--- .../task/EditorSaveTaskFactory.java | 2 +- .../util/source/minify/MinifyUtil.java | 94 +++++++++++-------- .../util/source/minify/MinifyWebContent.java | 8 +- .../xml/ui/options/XmlOptionsPanel.java | 50 +++------- 9 files changed, 127 insertions(+), 166 deletions(-) diff --git a/pom.xml b/pom.xml index 37e0f28..e984573 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.github.chris2011.netbeans.minifierbeans Minifierbeans - 3.3.0 + 3.4.0 nbm Minifierbeans https://github.com/Chris2011/minifierbeans @@ -85,20 +85,6 @@ - diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/css/CSSMinify.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/css/CSSMinify.java index 7b1aea0..c3cfd37 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/css/CSSMinify.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/css/CSSMinify.java @@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.netbeans.api.progress.ProgressHandle; -import org.netbeans.api.progress.ProgressHandleFactory; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import io.github.chris2011.netbeans.minifierbeans.ui.MinifyProperty; @@ -62,19 +61,22 @@ public CSSMinify(DataObject context) { @Override public void actionPerformed(ActionEvent ev) { - execute(context, null, true); + execute(context, null, null, true); } - public static void execute(final DataObject context, final String content, final boolean notify) { + public static void execute(final DataObject context, final FileObject file, final String content, final boolean notify) { Runnable runnable = new Runnable() { @Override public void run() { - cssMinify(context, content, notify); + cssMinify(context, file, content, notify); } }; final RequestProcessor.Task theTask = RP.create(runnable); - final ProgressHandle ph = ProgressHandleFactory.createHandle("Minifying CSS " + context.getPrimaryFile().getName(), theTask); + + String foString = context == null ? file.getName() : context.getPrimaryFile().getName(); + + final ProgressHandle ph = ProgressHandle.createHandle("Minifying CSS " + foString, theTask); theTask.addTaskListener(new TaskListener() { @Override @@ -87,20 +89,26 @@ public void taskFinished(org.openide.util.Task task) { theTask.schedule(0); } - private static void cssMinify(DataObject context, String content, boolean notify) { + private static void cssMinify(DataObject context, FileObject file, String content, boolean notify) { Project project = TopComponent.getRegistry().getActivated().getLookup().lookup(Project.class); - FileObject file = context.getPrimaryFile(); + FileObject primaryFile = null; + + if (context != null) { + primaryFile = context.getPrimaryFile(); + } else { + primaryFile = file; + } MinifyProperty minifyProperty = MinifyProperty.getInstance(); MinifyUtil util = new MinifyUtil(); MinifyFileResult minifyFileResult = new MinifyFileResult(); - if (!util.isMinifiedFile(file.getName(), minifyProperty.getPreExtensionCSS())) { - String inputFilePath = file.getPath(); + if (!util.isMinifiedFile(primaryFile.getName(), minifyProperty.getPreExtensionCSS())) { + String inputFilePath = primaryFile.getPath(); String outputFilePath; if (minifyProperty.isNewCSSFile() && minifyProperty.getPreExtensionCSS() != null && !minifyProperty.getPreExtensionCSS().trim().isEmpty()) { - outputFilePath = file.getParent().getPath() + "/" + file.getName() + minifyProperty.getPreExtensionCSS() + "." + file.getExt(); + outputFilePath = primaryFile.getParent().getPath() + "/" + primaryFile.getName() + minifyProperty.getPreExtensionCSS() + "." + primaryFile.getExt(); } else { outputFilePath = inputFilePath; } @@ -114,7 +122,7 @@ private static void cssMinify(DataObject context, String content, boolean notify outputWriter.flush(); if (project == null) { - project = FileOwnerQuery.getOwner(file); + project = FileOwnerQuery.getOwner(primaryFile); } PostCssCliExecutable postCssCliExecutable = PostCssCliExecutable.getDefault(project); diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/JSMinify.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/JSMinify.java index b083792..483ea4d 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/JSMinify.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/JSMinify.java @@ -52,29 +52,31 @@ }) @Messages("CTL_JSMinify=Minify JS") public final class JSMinify implements ActionListener { - private final DataObject context; + private final static RequestProcessor RP = new RequestProcessor("JSMinify", 1, true); public JSMinify(DataObject context) { this.context = context; } - private final static RequestProcessor RP = new RequestProcessor("JSMinify", 1, true); @Override public void actionPerformed(ActionEvent ev) { - execute(context, null, true); + execute(context, null, null, true); } - public static void execute(final DataObject context, final String content, final boolean notify) { + public static void execute(final DataObject context, final FileObject file, final String content, final boolean notify) { Runnable runnable = new Runnable() { @Override public void run() { - jsMinify(context, content, notify); + jsMinify(context, file, content, notify); } }; final RequestProcessor.Task theTask = RP.create(runnable); - final ProgressHandle ph = ProgressHandle.createHandle("Minifying JS " + context.getPrimaryFile().getName(), theTask); + + String foString = context == null ? file.getName() : context.getPrimaryFile().getName(); + + final ProgressHandle ph = ProgressHandle.createHandle("Minifying JS " + foString, theTask); theTask.addTaskListener(new TaskListener() { @Override @@ -87,20 +89,26 @@ public void taskFinished(org.openide.util.Task task) { theTask.schedule(0); } - private static void jsMinify(DataObject context, String content, boolean notify) { + private static void jsMinify(DataObject context, FileObject file, String content, boolean notify) { Project project = TopComponent.getRegistry().getActivated().getLookup().lookup(Project.class); - FileObject file = context.getPrimaryFile(); + FileObject primaryFile = null; + + if (context != null) { + primaryFile = context.getPrimaryFile(); + } else { + primaryFile = file; + } MinifyProperty minifyProperty = MinifyProperty.getInstance(); MinifyUtil util = new MinifyUtil(); MinifyFileResult minifyFileResult = new MinifyFileResult(); - if (!util.isMinifiedFile(file.getName(), minifyProperty.getPreExtensionJS())) { - String inputFilePath = file.getPath(); + if (!util.isMinifiedFile(primaryFile.getName(), minifyProperty.getPreExtensionJS())) { + String inputFilePath = primaryFile.getPath(); String outputFilePath; if (minifyProperty.isNewJSFile() && minifyProperty.getPreExtensionJS() != null && !minifyProperty.getPreExtensionJS().trim().isEmpty()) { - outputFilePath = file.getParent().getPath() + "/" + file.getName() + minifyProperty.getPreExtensionJS() + "." + file.getExt(); + outputFilePath = primaryFile.getParent().getPath() + "/" + primaryFile.getName() + minifyProperty.getPreExtensionJS() + "." + primaryFile.getExt(); } else { outputFilePath = inputFilePath; } @@ -114,7 +122,7 @@ private static void jsMinify(DataObject context, String content, boolean notify) outputWriter.flush(); if (project == null) { - project = FileOwnerQuery.getOwner(file); + project = FileOwnerQuery.getOwner(primaryFile); } GoogleClosureCompilerCliExecutable googleClosureCompilerCliExecutable = GoogleClosureCompilerCliExecutable.getDefault(project); @@ -135,6 +143,7 @@ private static void jsMinify(DataObject context, String content, boolean notify) // } else { // minifyFileResult = util.compress(inputFilePath, "text/javascript", outputFilePath, minifyProperty); // } + if (minifyProperty.isEnableOutputLogAlert() && notify) { NotificationDisplayer.getDefault().notify("Successful JS minification", NotificationDisplayer.Priority.NORMAL.getIcon(), String.format( @@ -145,4 +154,4 @@ private static void jsMinify(DataObject context, String content, boolean notify) } } } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/ui/options/JsOptionsPanel.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/ui/options/JsOptionsPanel.java index a325743..3bcfb83 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/ui/options/JsOptionsPanel.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/javascript/ui/options/JsOptionsPanel.java @@ -334,27 +334,4 @@ void fireChange() { public void stateChanged(ChangeEvent e) { fireChange(); } - -// private final class DefaultDocumentListener implements DocumentListener { -// -// @Override -// public void insertUpdate(DocumentEvent e) { -// processUpdate(); -// } -// -// @Override -// public void removeUpdate(DocumentEvent e) { -// processUpdate(); -// } -// -// @Override -// public void changedUpdate(DocumentEvent e) { -// processUpdate(); -// } -// -// private void processUpdate() { -// fireChange(); -// } -// -// } } diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTask.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTask.java index b2a0033..604240c 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTask.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTask.java @@ -15,7 +15,6 @@ */ package io.github.chris2011.netbeans.minifierbeans.task; - import javax.swing.text.BadLocationException; import javax.swing.text.Document; import io.github.chris2011.netbeans.minifierbeans.ui.MinifyProperty; @@ -30,7 +29,6 @@ import org.openide.util.Exceptions; public class EditorSaveTask implements OnSaveTask { - private final Context context; public EditorSaveTask(Context ctx) { @@ -39,23 +37,23 @@ public EditorSaveTask(Context ctx) { @Override public void performTask() { - try { - + try { + Document document = context.getDocument(); String content = document.getText(0, document.getLength()); - - DataObject dataObject = NbEditorUtilities.getDataObject(context.getDocument()); - if(dataObject.getPrimaryFile().getMIMEType().equals("text/html") && MinifyProperty.getInstance().isAutoMinifyHTML()){ - HTMLMinify.execute(dataObject,content,false); - } else if(dataObject.getPrimaryFile().getMIMEType().equals("text/javascript") && MinifyProperty.getInstance().isAutoMinifyJS()){ - JSMinify.execute(dataObject,content,false); - } else if(dataObject.getPrimaryFile().getMIMEType().equals("text/css") && MinifyProperty.getInstance().isAutoMinifyCSS()){ - CSSMinify.execute(dataObject,content,false); - } else if(dataObject.getPrimaryFile().getMIMEType().equals("text/x-json") && MinifyProperty.getInstance().isAutoMinifyJSON()){ - JSONMinify.execute(dataObject,content,false); - } else if(dataObject.getPrimaryFile().getMIMEType().equals("text/xml-mime") && MinifyProperty.getInstance().isAutoMinifyXML()){ - XMLMinify.execute(dataObject,content,false); - } + + DataObject dataObject = NbEditorUtilities.getDataObject(context.getDocument()); + if (dataObject.getPrimaryFile().getMIMEType().equals("text/html") && MinifyProperty.getInstance().isAutoMinifyHTML()) { + HTMLMinify.execute(dataObject, content, false); + } else if (dataObject.getPrimaryFile().getMIMEType().equals("text/javascript") && MinifyProperty.getInstance().isAutoMinifyJS()) { + JSMinify.execute(dataObject, null, content, false); + } else if (dataObject.getPrimaryFile().getMIMEType().equals("text/css") && MinifyProperty.getInstance().isAutoMinifyCSS()) { + CSSMinify.execute(dataObject, null, content, false); + } else if (dataObject.getPrimaryFile().getMIMEType().equals("text/x-json") && MinifyProperty.getInstance().isAutoMinifyJSON()) { + JSONMinify.execute(dataObject, content, false); + } else if (dataObject.getPrimaryFile().getMIMEType().equals("text/xml-mime") && MinifyProperty.getInstance().isAutoMinifyXML()) { + XMLMinify.execute(dataObject, content, false); + } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } @@ -71,5 +69,4 @@ public boolean cancel() { return true; } - -} \ No newline at end of file +} diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTaskFactory.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTaskFactory.java index 13bcc18..f597e11 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTaskFactory.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/task/EditorSaveTaskFactory.java @@ -24,7 +24,7 @@ @MimeRegistration(mimeType = "text/javascript", service = OnSaveTask.Factory.class), @MimeRegistration(mimeType = "text/css", service = OnSaveTask.Factory.class), @MimeRegistration(mimeType = "text/x-json", service = OnSaveTask.Factory.class), - @MimeRegistration(mimeType = "text/xml-mime", service = OnSaveTask.Factory.class) + @MimeRegistration(mimeType = "text/xml", service = OnSaveTask.Factory.class) }) public class EditorSaveTaskFactory implements OnSaveTask.Factory { diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyUtil.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyUtil.java index 4548437..6fd4a33 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyUtil.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyUtil.java @@ -24,6 +24,8 @@ import com.googlecode.htmlcompressor.compressor.HtmlCompressor; import com.googlecode.htmlcompressor.compressor.XmlCompressor; import com.yahoo.platform.yui.compressor.CssCompressor; +import io.github.chris2011.netbeans.minifierbeans.css.CSSMinify; +import io.github.chris2011.netbeans.minifierbeans.javascript.JSMinify; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -41,6 +43,7 @@ import org.apache.commons.lang.StringUtils; import io.github.chris2011.netbeans.minifierbeans.ui.MinifyProperty; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; public class MinifyUtil { @@ -52,12 +55,13 @@ MinifyResult minify(FileObject parentFile, MinifyProperty minifyProperty) { if (file.isFolder()) { directory++; MinifyResult preMinifyResult = minify(file, minifyProperty); - directory = directory + preMinifyResult.getDirectories(); - cssFile = cssFile + preMinifyResult.getCssFiles(); - jsFile = jsFile + preMinifyResult.getJsFiles(); - htmlFile = htmlFile + preMinifyResult.getHtmlFiles(); - xmlFile = xmlFile + preMinifyResult.getXmlFiles(); - jsonFile = jsonFile + preMinifyResult.getJsonFiles(); + + directory += preMinifyResult.getDirectories(); + cssFile += preMinifyResult.getCssFiles(); + jsFile += preMinifyResult.getJsFiles(); + htmlFile += preMinifyResult.getHtmlFiles(); + xmlFile += preMinifyResult.getXmlFiles(); + jsonFile += preMinifyResult.getJsonFiles(); minifyResult.setInputJsFilesSize(minifyResult.getInputJsFilesSize() + preMinifyResult.getInputJsFilesSize()); minifyResult.setOutputJsFilesSize(minifyResult.getOutputJsFilesSize() + preMinifyResult.getOutputJsFilesSize()); @@ -71,30 +75,33 @@ MinifyResult minify(FileObject parentFile, MinifyProperty minifyProperty) { minifyResult.setOutputJsonFilesSize(minifyResult.getOutputJsonFilesSize() + preMinifyResult.getOutputJsonFilesSize()); } else if (file.getExt().equalsIgnoreCase("js") && minifyProperty.isBuildJSMinify()) { jsFile++; - try { - Boolean allow = true; - String inputFilePath = file.getPath(); - String outputFilePath; - if (minifyProperty.isSkipPreExtensionJS() && minifyProperty.isBuildJSMinify() && minifyProperty.isNewJSFile()) { - if (minifyProperty.getPreExtensionJS() != null && !minifyProperty.getPreExtensionJS().trim().isEmpty() - && file.getName().matches(".*" + Pattern.quote(minifyProperty.getPreExtensionJS()))) { - allow = false; - } + Boolean allow = true; + String inputFilePath = file.getPath(); + String outputFilePath; + + if (minifyProperty.isSkipPreExtensionJS() && minifyProperty.isBuildJSMinify() && minifyProperty.isNewJSFile()) { + if (minifyProperty.getPreExtensionJS() != null && !minifyProperty.getPreExtensionJS().trim().isEmpty() + && file.getName().matches(".*" + Pattern.quote(minifyProperty.getPreExtensionJS()))) { + allow = false; } - if (allow) { + } + + if (allow) { + try { if (minifyProperty.isNewJSFile() && minifyProperty.getPreExtensionJS() != null && !minifyProperty.getPreExtensionJS().trim().isEmpty()) { outputFilePath = file.getParent().getPath() + File.separator + file.getName() + minifyProperty.getPreExtensionJS() + "." + file.getExt(); } else { outputFilePath = inputFilePath; } - + MinifyFileResult minifyFileResult = compress(inputFilePath, "text/javascript", outputFilePath, minifyProperty); + minifyResult.setInputJsFilesSize(minifyResult.getInputJsFilesSize() + minifyFileResult.getInputFileSize()); minifyResult.setOutputJsFilesSize(minifyResult.getOutputJsFilesSize() + minifyFileResult.getOutputFileSize()); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); } - } catch (IOException ex) { - Exceptions.printStackTrace(ex); } } else if (file.getExt().equalsIgnoreCase("css") && minifyProperty.isBuildCSSMinify()) { cssFile++; @@ -109,6 +116,7 @@ MinifyResult minify(FileObject parentFile, MinifyProperty minifyProperty) { allow = false; } } + if (allow) { if (minifyProperty.isNewCSSFile() && minifyProperty.getPreExtensionCSS() != null && !minifyProperty.getPreExtensionCSS().trim().isEmpty()) { outputFilePath = file.getParent().getPath() + File.separator + file.getName() + minifyProperty.getPreExtensionCSS() + "." + file.getExt(); @@ -117,6 +125,7 @@ MinifyResult minify(FileObject parentFile, MinifyProperty minifyProperty) { } MinifyFileResult minifyFileResult = compress(inputFilePath, "text/css", outputFilePath, minifyProperty); + minifyResult.setInputCssFilesSize(minifyResult.getInputCssFilesSize() + minifyFileResult.getInputFileSize()); minifyResult.setOutputCssFilesSize(minifyResult.getOutputCssFilesSize() + minifyFileResult.getOutputFileSize()); } @@ -229,7 +238,7 @@ public String compressSelectedJavaScript(String inputFilename, String content, M CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); - List inputs = new ArrayList(); + List inputs = new ArrayList<>(); inputs.add(SourceFile.fromCode(inputFilename, content)); StringWriter outputWriter = new StringWriter(); @@ -375,22 +384,20 @@ public MinifyFileResult compressContent(String inputFilename, String content, St return minifyFileResult; } +// public MinifyFileResult compress(String inputFilename, String mimeType, String outputFilename, MinifyProperty minifyProperty) throws IOException { public MinifyFileResult compress(String inputFilename, String mimeType, String outputFilename, MinifyProperty minifyProperty) throws IOException { InputStreamReader in = null; Writer out = null; MinifyFileResult minifyFileResult = new MinifyFileResult(); - Compiler compiler = new Compiler(); - CompilerOptions options = new CompilerOptions(); +// Compiler compiler = new Compiler(); +// CompilerOptions options = new CompilerOptions(); - compiler.initOptions(options); +// compiler.initOptions(options); - options.setEmitUseStrict(false); - options.setTrustedStrings(true); +// options.setEmitUseStrict(false); +// options.setTrustedStrings(true); - CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); - - List inputs = new ArrayList<>(); - inputs.add(SourceFile.fromFile(inputFilename)); +// CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); try { File inputFile = new File(inputFilename); @@ -412,28 +419,33 @@ public MinifyFileResult compress(String inputFilename, String mimeType, String o break; case "text/javascript": - // TODO: Change to Google Closure Compiler. - compiler.compile(CommandLineRunner.getDefaultExterns(), inputs, options); + JSMinify.execute(null, FileUtil.toFileObject(inputFile), null, false); if (StringUtils.isBlank(MinifyProperty.getInstance().getHeaderJS())) { - out.write(compiler.toSource()); + // TODO: Change +// out.write(compiler.toSource()); } else { - out.write(MinifyProperty.getInstance().getHeaderJS() + "\n" + compiler.toSource()); + // TODO: Change +// out.write(MinifyProperty.getInstance().getHeaderJS() + "\n" + compiler.toSource()); } break; case "text/css": // TODO: Change to CSSNano. - CssCompressor cssCompressor = new CssCompressor(in); - StringWriter outputWriter = new StringWriter(); + CSSMinify.execute(null, FileUtil.toFileObject(inputFile), null, false); +// CssCompressor cssCompressor = new CssCompressor(in); +// StringWriter outputWriter = new StringWriter(); - cssCompressor.compress(outputWriter, minifyProperty.getLineBreakPosition()); - outputWriter.flush(); - if (StringUtils.isBlank(MinifyProperty.getInstance().getHeaderJS())) { - out.write(outputWriter.toString()); +// cssCompressor.compress(outputWriter, minifyProperty.getLineBreakPosition()); +// outputWriter.flush(); + if (StringUtils.isBlank(MinifyProperty.getInstance().getHeaderCSS())) { + // TODO: Change +// out.write(outputWriter.toString()); } else { - out.write(MinifyProperty.getInstance().getHeaderCSS() + "\n" + outputWriter.toString()); - } outputWriter.close(); + // TODO: Change +// out.write(MinifyProperty.getInstance().getHeaderCSS() + "\n" + outputWriter.toString()); + } +// outputWriter.close(); break; case "text/x-json": diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyWebContent.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyWebContent.java index 207dd16..ebd4048 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyWebContent.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/util/source/minify/MinifyWebContent.java @@ -39,8 +39,6 @@ import org.openide.util.NbBundle.Messages; import org.openide.util.RequestProcessor; import org.openide.util.TaskListener; -import org.openide.windows.IOProvider; -import org.openide.windows.InputOutput; @ActionID(category = "Build", id = "org.netbeans.util.source.minify.Minify") @@ -96,7 +94,7 @@ File getTargetFolder(File file) throws IOException { public void minify() { MinifyProperty minifyProperty = MinifyProperty.getInstance(); - InputOutput io = IOProvider.getDefault().getIO(Bundle.CTL_Minify(), false); +// InputOutput io = IOProvider.getDefault().getIO(Bundle.CTL_Minify(), false); MinifyUtil util = new MinifyUtil(); try { @@ -155,7 +153,7 @@ public void minify() { showNotification(minifyResult, jsEval, cssEval, htmlEval, xmlEval, jsonEval, totalTime); } } catch (HeadlessException | IOException ex) { - io.getOut().println("Exception: " + ex.toString()); +// io.getOut().println("Exception: " + ex.toString()); } } @@ -169,7 +167,7 @@ private void showNotification(MinifyResult minifyResult, String jsEval, String c + "%s%s%s%s%s \n\n" + "Total Time - %d ms"; - NotificationDisplayer.getDefault().notify("Successful JS & CSS minification", + NotificationDisplayer.getDefault().notify("Successful minification", NotificationDisplayer.Priority.NORMAL.getIcon(), String.format(message, minifyResult.getDirectories(), diff --git a/src/main/java/io/github/chris2011/netbeans/minifierbeans/xml/ui/options/XmlOptionsPanel.java b/src/main/java/io/github/chris2011/netbeans/minifierbeans/xml/ui/options/XmlOptionsPanel.java index 24c85ae..a3b5c53 100644 --- a/src/main/java/io/github/chris2011/netbeans/minifierbeans/xml/ui/options/XmlOptionsPanel.java +++ b/src/main/java/io/github/chris2011/netbeans/minifierbeans/xml/ui/options/XmlOptionsPanel.java @@ -36,8 +36,11 @@ private void init() { newXMLFile.setSelected(minifyProperty.isNewXMLFile()); preExtensionXML.setEnabled(minifyProperty.isNewXMLFile()); + projectOptionsPanel.skipPreExtensionXML.setEnabled(minifyProperty.isNewXMLFile()); - this.preExtensionXML.setText(minifyProperty.getPreExtensionXML()); + minifyProperty.setSkipPreExtensionXML(minifyProperty.isNewXMLFile()); + preExtensionXML.setText(minifyProperty.getPreExtensionXML()); + autoMinifyXML.setSelected(minifyProperty.isAutoMinifyXML()); xmlMinifierFlagsTextField.setText(minifyProperty.getCompilerFlagsXML()); @@ -149,13 +152,6 @@ public void removeChangeListener(ChangeListener listener) { changeSupport.removeChangeListener(listener); } -// public String getCssNanoCli() { -// return cssNanoCliPathTextField.getText(); -// } -// -// public void setCssNanoCli(String cssNanoCli) { -// cssNanoCliPathTextField.setText(cssNanoCli); -// } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -296,13 +292,14 @@ private void initComponents() { jPanel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(XmlOptionsPanel.class, "XmlOptionsPanel.jPanel2.AccessibleContext.accessibleName")); // NOI18N }// //GEN-END:initComponents -// void load() { -// String ngCli = NbPreferences.forModule(CssOptionsPanel.class).get("ngCliExecutableLocation", ""); -// cssNanoCliPathTextField.setText(ngCli); -// } -// void store() { -// NbPreferences.forModule(CssOptionsPanel.class).put("ngCliExecutableLocation", cssNanoCliPathTextField.getText()); -// } + void load() { + minifyProperty.load(); + } + + void store() { + minifyProperty.store(); + } + boolean valid() { // TODO check whether form is consistent and complete return true; @@ -332,27 +329,4 @@ void fireChange() { public void stateChanged(ChangeEvent e) { fireChange(); } - - private final class DefaultDocumentListener implements DocumentListener { - - @Override - public void insertUpdate(DocumentEvent e) { - processUpdate(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - processUpdate(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - processUpdate(); - } - - private void processUpdate() { - fireChange(); - } - - } }