Beispiel #1
0
        protected override bool Execute(MinifyCommandId commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (_spansTuple == null)
            {
                return(false);
            }

            var    source = _spansTuple.Item2.GetText();
            string result = Mef.GetImport <IFileMinifier>(_spansTuple.Item2.Snapshot.TextBuffer.ContentType)
                            .MinifyString(source);

            if (result == null)
            {
                return(false); // IFileMinifier already displayed an error
            }
            if (result == source)
            {
                EditorExtensionsPackage.DTE.StatusBar.Text = "The selection is already minified";
                return(false);
            }

            using (EditorExtensionsPackage.UndoContext("Minify"))
                TextView.TextBuffer.Replace(_spansTuple.Item1, result);

            return(true);
        }
Beispiel #2
0
 protected override bool IsEnabled()
 {
     // Don't minify Markdown
     _spansTuple = TextView.GetSelectedSpan(c => !c.IsOfType("Markdown") &&
                                            Mef.GetImport <IFileMinifier>(c) != null);
     return(_spansTuple != null);
 }
        private async static Threading.Task WriteMinFile(string bundleSourcePath, string extension, bool bundleChanged)
        {
            string minPath = Path.ChangeExtension(bundleSourcePath, ".min" + Path.GetExtension(bundleSourcePath));

            // If the bundle didn't change, don't re-minify, unless the user just enabled minification.
            if (!bundleChanged && File.Exists(minPath))
            {
                return;
            }

            var  fers        = WebEditor.ExportProvider.GetExport <IFileExtensionRegistryService>().Value;
            var  contentType = fers.GetContentTypeForExtension(extension);
            var  settings    = WESettings.Instance.ForContentType <IMinifierSettings>(contentType);
            var  minifier    = Mef.GetImport <IFileMinifier>(contentType);
            bool changed     = await minifier.MinifyFile(bundleSourcePath, minPath);

            if (settings.GzipMinifiedFiles && (changed || !File.Exists(minPath + ".gzip")))
            {
                FileHelpers.GzipFile(minPath);
            }
        }
 protected CompilingMarginBase(IMarginSettings settings, ITextDocument document)
     : base(settings, document)
 {
     Notifier = Mef.GetImport <ICompilationNotifierProvider>(Document.TextBuffer.ContentType).GetCompilationNotifier(document);
     Notifier.CompilationReady += (s, e) => UpdateMargin(e.CompilerResult);
 }