private static string onSearchClicked(BulkWindow.BulkCommunicator bc, ICollection <string> files, object userObject) { bc.ReportProgress(string.Format("Found {0} files to pretty print", files.Count)); StringBuilder errorlog = new StringBuilder(); foreach (string file in files) { try { string newFileName = Path.ChangeExtension(file, ".pretty.xml"); bc.ReportProgress("Prettyprinting file: " + file); string xml = File.ReadAllText(file); string res = PrettyPrint.Execute(xml, true, false); File.WriteAllText(newFileName, res); } catch (Exception e) { errorlog.AppendLine("Error while prettyprinting " + file + ": " + e.Message); } } errorlog.AppendLine("Prettyprinting completed"); return(errorlog.ToString()); }
protected override void Execute(EditorFrame ef) { TextEditor te = ef.XmlEditor; //TODO undo works this way // string vorher = te.Text; // te.Document.Remove(0, te.Document.TextLength); // te.Document.Insert(0, PrettyPrint.Execute( // vorher, // ef.Data.PrettyPrintData.Indent, // ef.Data.PrettyPrintData.NewLineOnAttributes // )); if (te.SelectionLength != 0) { try { te.SelectedText = PrettyPrint.Execute( te.SelectedText, ef.Data.PrettyPrintData.Indent, ef.Data.PrettyPrintData.NewLineOnAttributes ); } catch (Exception e) { MessageBox.Show(Application.Current.MainWindow, "Cannot prettyprint selected text:\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { try { te.Text = PrettyPrint.Execute( te.Text, ef.Data.PrettyPrintData.Indent, ef.Data.PrettyPrintData.NewLineOnAttributes ); } catch (Exception e) { MessageBox.Show(Application.Current.MainWindow, "Cannot prettyprint text:\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }