public OptionsForm() { _provider = OptionsProviderRegistry.CurrentOptionsProvider; _options = _provider.GetOptions(); InitializeComponent(); optionsUI.SetOptions(_options); }
public static Options Import(string filename) { Options options = null; try { if (File.Exists(filename)) { using (FileStream fin = File.OpenRead(filename)) { var serializer = new OptionsSerializer(); options = serializer.Deserialize(fin); var currentProvider = GetCurrentOptionsProvider(); if (!currentProvider.IsReadOnly) { currentProvider.Save(options); } } } } catch { options = new Options(); } return options; }
public static void Export(Options options, string filename) { using (FileStream fout = File.Create(filename)) { OptionsSerializer serializer = new OptionsSerializer(); serializer.Serialize(fout, options); } }
private void export_Click(object sender, EventArgs e) { if (exportFileDialog.ShowDialog() == DialogResult.OK) { Options exportedOptions = new Options(); SaveOptions(exportedOptions); OptionsProviderRegistry.Export(exportedOptions, exportFileDialog.FileName); } }
public void LoadOptions(Options options) { outputAsError.IsChecked = options.ErrorCategory == ErrorCategory.Error; outputAsWarning.IsChecked = options.ErrorCategory == ErrorCategory.Warning; outputAsMessage.IsChecked = options.ErrorCategory == ErrorCategory.Message; outputAsTask.IsChecked = options.ErrorCategory == ErrorCategory.Task; todoAsError.IsChecked = options.TODOCategory == ErrorCategory.Error; todoAsWarning.IsChecked = options.TODOCategory == ErrorCategory.Warning; todoAsMessage.IsChecked = options.TODOCategory == ErrorCategory.Message; todoAsTask.IsChecked = options.TODOCategory == ErrorCategory.Task; findTODOs.IsChecked = options.TODOEnabled; runOnSave.IsChecked = options.RunOnSave; runOnBuild.IsChecked = options.RunOnBuild; cancelBuildOnError.IsChecked = options.CancelBuildOnError; includeJS.IsChecked = (options.BuildFileTypes & IncludeFileType.JS) == IncludeFileType.JS; includeCSS.IsChecked = (options.BuildFileTypes & IncludeFileType.CSS) == IncludeFileType.CSS; includeHTML.IsChecked = (options.BuildFileTypes & IncludeFileType.HTML) == IncludeFileType.HTML; onSaveJs.IsChecked = (options.SaveFileTypes & IncludeFileType.JS) == IncludeFileType.JS; onSaveCss.IsChecked = (options.SaveFileTypes & IncludeFileType.CSS) == IncludeFileType.CSS; onSaveHtml.IsChecked = (options.SaveFileTypes & IncludeFileType.HTML) == IncludeFileType.HTML; fakeAtCharset.IsChecked = options.FakeCSSCharset; ignoreErrorStart.Text = options.IgnoreErrorStart; ignoreErrorEnd.Text = options.IgnoreErrorEnd; IgnoreErrorLine.Text = options.IgnoreErrorLine; JSLintOptions jslint = options.JSLintOptions; _optionsVM.LoadLinterSettings(jslint.SelectedLinter, jslint.BoolOptions2); warnOnUnused.IsChecked = jslint.ErrorOnUnused; indentSize.Text = jslint.IndentSize.ToString(); maxlen.Text = jslint.MaxLength.ToString(); if (jslint.PreDefined != null && jslint.PreDefined.Count > 0) { predefined.Text = string.Join(", ", jslint.PreDefined); } }
public void SaveOptions(Options dest) { if (outputAsError.IsChecked.GetValueOrDefault(false)) { dest.ErrorCategory = ErrorCategory.Error; } else if (outputAsWarning.IsChecked.GetValueOrDefault(false)) { dest.ErrorCategory = ErrorCategory.Warning; } else if (outputAsMessage.IsChecked.GetValueOrDefault(false)) { dest.ErrorCategory = ErrorCategory.Message; } else { dest.ErrorCategory = ErrorCategory.Task; } if (todoAsError.IsChecked.GetValueOrDefault(false)) { dest.TODOCategory = ErrorCategory.Error; } else if (todoAsWarning.IsChecked.GetValueOrDefault(false)) { dest.TODOCategory = ErrorCategory.Warning; } else if (todoAsMessage.IsChecked.GetValueOrDefault(false)) { dest.TODOCategory = ErrorCategory.Message; } else { dest.TODOCategory = ErrorCategory.Task; } dest.TODOEnabled = findTODOs.IsChecked.GetValueOrDefault(false); dest.RunOnBuild = runOnBuild.IsChecked.HasValue && runOnBuild.IsChecked.Value; dest.CancelBuildOnError = cancelBuildOnError.IsChecked.HasValue && cancelBuildOnError.IsChecked.Value; dest.BuildFileTypes = includeJS.IsChecked.GetValueOrDefault(true) ? IncludeFileType.JS : (IncludeFileType)0; if (includeCSS.IsChecked.GetValueOrDefault(false)) { dest.BuildFileTypes |= IncludeFileType.CSS; } if (includeHTML.IsChecked.GetValueOrDefault(false)) { dest.BuildFileTypes |= IncludeFileType.HTML; } dest.SaveFileTypes = onSaveJs.IsChecked.GetValueOrDefault(true) ? IncludeFileType.JS : (IncludeFileType)0; if (onSaveCss.IsChecked.GetValueOrDefault(false)) { dest.SaveFileTypes |= IncludeFileType.CSS; } if (onSaveHtml.IsChecked.GetValueOrDefault(false)) { dest.SaveFileTypes |= IncludeFileType.HTML; } dest.FakeCSSCharset = fakeAtCharset.IsChecked.GetValueOrDefault(false); dest.IgnoreErrorStart = ignoreErrorStart.Text; dest.IgnoreErrorEnd = ignoreErrorEnd.Text; dest.IgnoreErrorLine = IgnoreErrorLine.Text; dest.RunOnSave = runOnSave.IsChecked.GetValueOrDefault(false); var jslint = dest.JSLintOptions; jslint.SelectedLinter = _optionsVM.SaveLinterSettings(jslint.BoolOptions2); if (indentSize.Text.Length == 0) { jslint.IndentSize = null; } else { jslint.IndentSize = int.Parse(indentSize.Text); } if (maxlen.Text.Length == 0) { jslint.MaxLength = null; } else { jslint.MaxLength = int.Parse(maxlen.Text); } if (!string.IsNullOrWhiteSpace(predefined.Text)) { jslint.PreDefined = new List<string>(predefined.Text.Split(new string[] { ",", " ", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries)); } else { jslint.PreDefined = null; } if (jslint.SelectedLinter == Linters.JSHint) { jslint.ErrorOnUnused = false; } else { jslint.ErrorOnUnused = warnOnUnused.IsChecked.GetValueOrDefault(true); } }
public void SetOptions(Options options) { _options = options; DataContext = _optionsVM = new OptionsViewModel(options.JSLintOptions); }
private void LoadOptions(Options options) { optionsUI.LoadOptions(options); optionsUI.IsEnabled = enableJSLint.Checked = options.Enabled; }
private void SaveOptions(Options dest) { dest.Enabled = enableJSLint.Checked; optionsUI.SaveOptions(dest); }
public void Serialize(Stream stream, Options options) { XmlSerializer serializer = new XmlSerializer(typeof(Options)); serializer.Serialize(stream, options); }
public static void SaveChanges(Options options) { lock(options) { GetCurrentOptionsProvider().Save(options); } }
private void TestLint(string javascript, List<string> errorsExpected, JSLintOptions lintoptions = null, List<string> todos = null, Options options = null) { if (options == null) { options = new Options(); if (lintoptions != null) { options.JSLintOptions = lintoptions; } } lintoptions = options.JSLintOptions; IgnoreErrorSectionsHandler ignoreErrorHandler = new IgnoreErrorSectionsHandler(javascript); IEnumerable<JSLintError> errors = _linter.Lint(javascript, lintoptions, true); errors = errors.Where(a => !ignoreErrorHandler.IsErrorIgnored(a.Line, a.Column)); if (lintoptions.FindTodos) { errors = errors.Concat(TodoFinder.FindTodos(javascript)); } string errorMessage = "got "; for(var i = 0; i < errors.Count(); i++) { errorMessage += "<" + errors.ElementAt(i).Message + "> "; } for (var i = 0; i < errorsExpected.Count; i++) { if (errors.Count() <= i) { break; } Assert.AreEqual(errorsExpected[i], errors.ElementAt(i).Message, errorMessage); } Assert.AreEqual(errorsExpected.Count, errors.Count(), errorMessage); }
public IgnoreErrorSectionsHandler(string file, Options options = null) { if (options == null) { options = OptionsProviderRegistry.CurrentOptions; } SectionsToIgnore = new List<IgnoreErrorSection>(); string start = options.IgnoreErrorStart, end = options.IgnoreErrorEnd, ignoreline = options.IgnoreErrorLine; int line = 1, startLineCharacter = 0, endLineCharacter = 0, character = 0, i; IgnoreErrorSection currentSection = null; bool lookAtStartEnd = true, lookAtLines = true; if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end)) { lookAtStartEnd = false; } if (string.IsNullOrEmpty(ignoreline)) { lookAtLines = false; } while (lookAtLines || lookAtStartEnd) { endLineCharacter = file.IndexOf('\n', startLineCharacter); character = startLineCharacter; if (endLineCharacter < 0) { break; } while (true) { if (currentSection != null) { i = file.IndexOf(end, character, endLineCharacter - character); if (i >= 0) { currentSection.EndLine = line; currentSection.EndCol = i - startLineCharacter; SectionsToIgnore.Add(currentSection); currentSection = null; character = i; continue; } break; } i = file.IndexOf(ignoreline, character, endLineCharacter - character); if (i >= 0) { SectionsToIgnore.Add(new IgnoreErrorSection() { StartLine = line, EndLine = line, StartCol = -1 }); break; } i = file.IndexOf(start, character, endLineCharacter - character); if (i >= 0) { currentSection = new IgnoreErrorSection() { StartLine = line, StartCol = i - startLineCharacter }; character = i; } else { break; } } line++; startLineCharacter = endLineCharacter + 1; } }