コード例 #1
0
 internal void OnFileChanged(CssFeatures features)
 {
     if (features == this.features) return;
     this.features = features;
     enabled = features != null;
     if (enabled)
     {
         wordChars = lang.characterclass.Characters;
         if (features.Mode != "CSS") wordChars += features.Trigger;
         InitBlockLevel();
     }
 }
コード例 #2
0
ファイル: Optimizer.cs プロジェクト: heon21st/flashdevelop
 static public void CompressFile(string fileName, CssFeatures features, Settings settings)
 {
     if (settings.DisableMinifyOnSave) return;
     try
     {
         if (!File.Exists(fileName)) return;
         string raw = File.ReadAllText(fileName);
         string min = CssMinifier.Minify(raw);
         string outFile = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)) + ".min.css";
         TraceManager.Add("minify " + Path.GetFileName(outFile));
         File.WriteAllText(outFile, min);
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
     }
 }
コード例 #3
0
ファイル: PluginMain.cs プロジェクト: CamWiseOwl/flashdevelop
        /// <summary>
        /// Loads the plugin settings
        /// </summary>
        public void LoadSettings()
        {
            this.settingObject = new Settings();
            if (!File.Exists(this.settingFilename)) this.SaveSettings();
            else
            {
                Object obj = ObjectSerializer.Deserialize(this.settingFilename, this.settingObject);
                this.settingObject = (Settings)obj;
            }

            enabledLanguages = new Dictionary<string, CssFeatures>();
            config = ConfigHelper.Parse(PathHelper.ResolvePath("tools/css/completion.ini"), false);
            foreach (var def in config)
            {
                var section = def.Value;
                if (section.ContainsKey("ext"))
                {
                    string[] exts = section["ext"].Trim().Split(',');
                    var features = new CssFeatures(def.Key, section);
                    foreach (string ext in exts)
                        enabledLanguages.Add("." + ext, features);
                }
            }
        }
コード例 #4
0
ファイル: PluginMain.cs プロジェクト: CamWiseOwl/flashdevelop
 /// <summary>
 /// Handles the incoming events
 /// </summary>
 public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
 {
     ITabbedDocument document = PluginBase.MainForm.CurrentDocument;
     if (document == null || !document.IsEditable) return;
     switch (e.Type)
     {
         case EventType.Keys:
         {
             Keys keys = (e as KeyEvent).Value;
             if (this.IsSupported(document) && keys == (Keys.Control | Keys.Space))
             {
                 if (completion != null)
                 {
                     completion.OnComplete(document.SciControl, document.SciControl.CurrentPos);
                     e.Handled = true;
                 }
             }
             break;
         }
         case EventType.FileSwitch:
         case EventType.SyntaxChange:
         case EventType.ApplySettings:
         {
             if (document.IsEditable && this.IsSupported(document))
             {
                 string ext = Path.GetExtension(document.FileName).ToLower();
                 features = enabledLanguages.ContainsKey(ext) ? enabledLanguages[ext] : null;
                 if (completion == null) completion = new Completion(config, settingObject);
                 completion.OnFileChanged(features);
                 if (features != null && features.Syntax != null)
                 {
                     ScintillaControl sci = document.SciControl;
                     sci.SetProperty(features.Syntax, features != null ? "1" : "0");
                     sci.Colourise(0, -1);
                 }
             }
             break;
         }
         case EventType.Completion:
         {
             if (features != null) e.Handled = true;
             return;
         }
         case EventType.FileSave:
         {
             if (document != null && document.IsEditable && this.IsSupported(document))
             {
                 updateFile = document.FileName;
                 updateFeatures = features;
                 updater.Start();
             }
             break;
         }
     }
 }
コード例 #5
0
ファイル: Optimizer.cs プロジェクト: heon21st/flashdevelop
        static public void CompileFile(string fileName, CssFeatures features, Settings settings)
        {
            EventManager.DispatchEvent(features, new NotifyEvent(EventType.ProcessStart));

            string raw = File.ReadAllText(fileName);
            string options = "";
            Match mParams = Regex.Match(raw, "\\@options\\s(.*)", RegexOptions.Multiline);
            if (mParams.Success)
            {
                options = mParams.Groups[1].Value.Trim();
                int endComment = options.IndexOf("*/");
                if (endComment > 0) options = options.Substring(0, endComment).Trim();
            }

            string toolsDir = Path.Combine(PathHelper.ToolDir, "css");
            string[] parts = features.Compile.Split(';');
            if (parts.Length != 2)
            {
                TraceManager.Add(features.Compile + " is invalid, see 'compile' in completion.ini");
                return;
            }
            string cmd = PathHelper.ResolvePath(parts[0], toolsDir);
            if (cmd == null)
            {
                TraceManager.Add(parts[0] + " command not found");
                return;
            }
            string outFile = Path.GetFileNameWithoutExtension(fileName) + ".css";
            string args = parts[1].Replace("$(options)", options)
                .Replace("$(in)", Path.GetFileName(fileName))
                .Replace("$(out)", outFile);
            TraceManager.Add(Path.GetFileNameWithoutExtension(cmd) + " " + args.Trim());

            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = cmd;
            info.Arguments = args;
            if (info.EnvironmentVariables.ContainsKey("path")) info.EnvironmentVariables["path"] += ";" + toolsDir;
            else info.EnvironmentVariables["path"] = toolsDir;
            info.CreateNoWindow = true;
            info.WorkingDirectory = Path.GetDirectoryName(fileName);
            info.UseShellExecute = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError = true;
            Process p = Process.Start(info);
            if (p.WaitForExit(3000))
            {
                string res = p.StandardOutput.ReadToEnd() ?? "";
                string err = p.StandardError.ReadToEnd() ?? "";

                MatchCollection matches = features.ErrorPattern.Matches(err);
                if (matches.Count > 0)
                    foreach (Match m in matches)
                        TraceManager.Add(fileName + ":" + m.Groups["line"] + ": " + m.Groups["desc"].Value.Trim(), -3);

                if (settings.EnableVerboseCompilation || (err != "" && matches.Count == 0))
                {
                    if (res.Trim().Length > 0) TraceManager.Add(res);
                    if (err.Trim().Length > 0) TraceManager.Add(err, 3);
                }

                EventManager.DispatchEvent(features, new TextEvent(EventType.ProcessEnd, "Done(" + p.ExitCode + ")"));

                if (p.ExitCode == 0)
                {
                    outFile = Path.Combine(Path.GetDirectoryName(fileName), outFile);
                    CompressFile(outFile, features, settings);
                }
            }
            else
            {
                p.Kill();
                EventManager.DispatchEvent(features, new TextEvent(EventType.ProcessEnd, "Done(99): Style compiler not responding."));
            }
        }
コード例 #6
0
ファイル: Optimizer.cs プロジェクト: heon21st/flashdevelop
 static public void ProcessFile(string fileName, CssFeatures features, Settings settings)
 {
     if (settings.DisableCompileOnSave) return;
     if (!string.IsNullOrEmpty(features.Compile)) CompileFile(fileName, features, settings);
     else CompressFile(fileName, features, settings);
 }