/// <summary> /// raised any time any file changes - filter for supported file types, and add jobs to the queue /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void SourceFileChanged(object source, FileSystemEventArgs e) { try { var ext = (new FileInfo(e.FullPath)).Extension; if (Regex.IsMatch(ext, @"\.(less|scss|sass|coffee|js|css|ts)", RegexOptions.IgnoreCase)) { if (e.ChangeType == WatcherChangeTypes.Changed) { bool?doIt = null; OrangeJob.JobType jobType = OrangeJob.JobType.Compile; switch (ext.ToLowerInvariant()) { case ".less": doIt = prefUtility.GetPref(e.FullPath, "AutoCompileLess", true) as bool?; break; case ".scss": case ".sass": doIt = prefUtility.GetPref(e.FullPath, "AutoCompileSass", true) as bool?; break; case ".coffee": doIt = prefUtility.GetPref(e.FullPath, "AutoCompileCoffee", true) as bool?; break; case ".js": doIt = e.FullPath.EndsWith(".min.js") ? false : prefUtility.GetPref(e.FullPath, "AutoMinifyJS", false) as bool?; jobType = OrangeJob.JobType.Minify; break; case ".css": doIt = e.FullPath.EndsWith(".min.css") ? false : prefUtility.GetPref(e.FullPath, "AutoMinifyCSS", false) as bool?; jobType = OrangeJob.JobType.Minify; break; case ".ts": doIt = prefUtility.GetPref(e.FullPath, "AutoCompileTypeScript", true) as bool?; break; } if (doIt.HasValue && doIt.Value && _worker != null) { _worker.AddItem(new OrangeJob() { Path = e.FullPath, OutputPath = GetOutputPath(e.FullPath), Type = jobType, Source = OrangeJob.JobSource.Save }); } } } } catch (Exception ex) { _host.ShowNotification("There was an error compiling your file: " + ex.ToString()); } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected void AddMultiMenu(ContextMenuOpeningEventArgs e, string[] supportedExtensions, OrangeJob.JobType jobType, string title, string multipleTitle) { var jobs = new List <OrangeJob>(); foreach (ISiteItem item in e.Items) { var fsi = item as ISiteFileSystemItem; if (fsi != null) { if (fsi is ISiteFolder) { // get all of the pngs under the selected path and add a job var dir = new DirectoryInfo((fsi as ISiteFolder).Path); var files = supportedExtensions.SelectMany(x => dir.GetFiles("*" + x, SearchOption.AllDirectories)); foreach (var f in files) { if (jobType != OrangeJob.JobType.Minify || (!f.FullName.EndsWith(".min.js") && !f.FullName.EndsWith(".min.css"))) { jobs.Add(new OrangeJob() { Path = f.FullName, OutputPath = GetOutputPath(f.FullName), Type = jobType, Source = OrangeJob.JobSource.Context }); } } } else if (supportedExtensions.Contains((new FileInfo(fsi.Path)).Extension.ToLower())) { if (jobType != OrangeJob.JobType.Minify || (!fsi.Path.EndsWith(".min.js") && !fsi.Path.EndsWith(".min.css"))) { jobs.Add(new OrangeJob() { Path = fsi.Path, OutputPath = GetOutputPath(fsi.Path), Type = jobType, Source = OrangeJob.JobSource.Context }); } } } } if (jobs.Count > 0) { var menuTitle = jobs.Count > 1 ? multipleTitle : title; var menuItem = new ContextMenuItem(menuTitle, null, new DelegateCommand(new Action <object>(AddJob)), jobs); e.AddMenuItem(menuItem); } }