/// <summary> /// /// </summary> public void Format(Object sender, System.EventArgs e) { ITabbedDocument doc = PluginBase.MainForm.CurrentDocument; if (doc.IsEditable) { doc.SciControl.BeginUndoAction(); Int32 oldPos = CurrentPos; String source = doc.SciControl.Text; try { switch (DocumentType) { case TYPE_AS3PURE: ASPrettyPrinter asPrinter = new ASPrettyPrinter(true, source); FormatUtility.ConfigureASPrinter(asPrinter, this.settingObject, PluginBase.Settings.TabWidth); String asResultData = asPrinter.Print(0); if (asResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = asResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; case TYPE_MXML: case TYPE_XML: MXMLPrettyPrinter mxmlPrinter = new MXMLPrettyPrinter(source); FormatUtility.ConfigureMXMLPrinter(mxmlPrinter, this.settingObject, PluginBase.Settings.TabWidth); String mxmlResultData = mxmlPrinter.Print(0); if (mxmlResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = mxmlResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; } } catch (Exception) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } CurrentPos = oldPos; doc.SciControl.EndUndoAction(); } }
public static void ConfigureMXMLPrinter(MXMLPrettyPrinter printer, Settings settings, int tabSize) { printer.SetAttrSortMode((Int32)settings.Pref_MXML_SortAttrMode); printer.SetUseTabs(settings.Pref_Flex_UseTabs); printer.SetTabSize(tabSize); printer.SetIndentAmount(tabSize); List<string> sortAttrData = new List<string>(); string[] sortAttrDataArray = settings.Pref_MXML_SortAttrData.Split('\n'); foreach (string attr in sortAttrDataArray) { sortAttrData.Add(attr); } printer.SetManualAttrSortData(sortAttrData); printer.SetSortOtherAttrs(settings.Pref_MXML_SortExtraAttrs); printer.SetSpacesAroundEquals(settings.Pref_MXML_SpacesAroundEquals); printer.SetSpacesBeforeEmptyTagEnd(settings.Pref_MXML_SpacesBeforeEmptyTagEnd); printer.SetKeepBlankLines(settings.Pref_MXML_KeepBlankLines); printer.SetBlankLinesBeforeTags(settings.Pref_MXML_BlankLinesBeforeTags); printer.SetWrapStyle((Int32)settings.Pref_MXML_WrapIndentStyle); printer.SetMaxLineLength(settings.Pref_MXML_MaxLineLength); printer.SetWrapMode((Int32)settings.Pref_MXML_AttrWrapMode); printer.SetAttrsPerLine(settings.Pref_MXML_AttrsPerLine); printer.SetAddNewlineAfterLastAttr(settings.Pref_MXML_AddNewlineAfterLastAttr); printer.SetUseAttrsToKeepOnSameLine(settings.Pref_MXML_UseAttrsToKeepOnSameLine); printer.SetRequireCDATAForASContent(settings.Pref_MXML_RequireCDATAForASFormatting); printer.SetAttrsToKeepOnSameLine(settings.Pref_MXML_AttrsToKeepOnSameLine); String[] tags = settings.Pref_MXML_TagsCannotFormat.Split(','); List<String> tagSet = new List<String>(); foreach (String tag in tags) { if (tag.Length > 0) tagSet.Add(tag); } printer.SetTagsThatCannotBeFormatted(tagSet); tags = settings.Pref_MXML_TagsCanFormat.Split(','); tagSet = new List<String>(); foreach (String tag in tags) { if (tag.Length > 0) tagSet.Add(tag); } printer.SetTagsThatCanBeFormatted(tagSet); tags = settings.Pref_MXML_TagsWithBlankLinesBefore.Split(','); tagSet = new List<String>(); foreach (String tag in tags) { if (tag.Length > 0) tagSet.Add(tag); } printer.SetTagsWithBlankLinesBeforeThem(tagSet); tags = settings.Pref_MXML_TagsWithASContent.Split(','); tagSet = new List<String>(); foreach (String tag in tags) { if (tag.Length > 0) tagSet.Add(tag); } printer.SetASScriptTags(tagSet); List<AttrGroup> attrGroups = new List<AttrGroup>(); String groupData = settings.Pref_MXML_AttrGroups; String[] groups = groupData.Split(Settings.LineSplitter); foreach (String g in groups) { AttrGroup group = AttrGroup.Load(g); if (group != null) attrGroups.Add(group); } printer.SetAttrGroups(attrGroups); ConfigureASPrinter(printer.GetASPrinter(), settings, tabSize); }
public static void configureMXMLPrinter(MXMLPrettyPrinter printer, Settings settings) { Boolean useTabs = PluginBase.Settings.UseTabs; Int32 tabSize = PluginBase.Settings.TabWidth; Int32 spaceSize = PluginBase.Settings.IndentSize; printer.setAttrSortMode((Int32)settings.Pref_MXML_SortAttrMode); printer.setIndentAmount(spaceSize); printer.setUseTabs(useTabs); printer.setTabSize(tabSize); printer.setTabSize(tabSize); printer.setIndentAmount(tabSize); printer.setSortOtherAttrs(settings.Pref_MXML_SortExtraAttrs); printer.setSpacesAroundEquals(settings.Pref_MXML_SpacesAroundEquals); printer.setSpacesBeforeEmptyTagEnd(settings.Pref_MXML_SpacesBeforeEmptyTagEnd); printer.setKeepBlankLines(settings.Pref_MXML_KeepBlankLines); printer.setKeepRelativeCommentIndent(settings.Pref_MXML_KeepRelativeIndentInMultilineComments); printer.setBlankLinesBeforeComments(settings.Pref_MXML_BlankLinesBeforeComments); printer.setBlankLinesBeforeTags(settings.Pref_MXML_BlankLinesBeforeTags); printer.setBlankLinesAfterSpecificParentTags(settings.Pref_MXML_BlankLinesAfterSpecificParentTags); printer.setSpacesBetweenSiblingTags(settings.Pref_MXML_BlankLinesBetweenSiblingTags); printer.setSpacesAfterParentTags(settings.Pref_MXML_BlankLinesAfterParentTags); printer.setBlankLinesBeforeCloseTags(settings.Pref_MXML_BlankLinesBeforeClosingTags); printer.setWrapStyle((Int32)settings.Pref_MXML_WrapIndentStyle); printer.setHangingIndentTabs(settings.Pref_MXML_TabsInHangingIndent); printer.setUseSpacesInsideAttrBraces(settings.Pref_MXML_UseSpacesInsideAttributeBraces); printer.setFormatBoundAttributes(settings.Pref_MXML_UseFormattingOfBoundAttributes); printer.setSpacesInsideAttrBraces(settings.Pref_MXML_SpacesInsideAttributeBraces); printer.setCDATAIndentTabs(settings.Pref_MXML_ScriptCDataIndentTabs); printer.setScriptIndentTabs(settings.Pref_MXML_ScriptIndentTabs); printer.setBlankLinesAtCDataStart(settings.Pref_MXML_BlankLinesAtCDataStart); printer.setBlankLinesAtCDataEnd(settings.Pref_MXML_BlankLinesAtCDataStart); printer.setKeepCDataOnSameLine(settings.Pref_MXML_KeepScriptCDataOnSameLine); printer.setMaxLineLength(settings.Pref_MXML_MaxLineLength); printer.setWrapMode((Int32)settings.Pref_MXML_AttrWrapMode); printer.setAttrsPerLine(settings.Pref_MXML_AttrsPerLine); printer.setAddNewlineAfterLastAttr(settings.Pref_MXML_AddNewlineAfterLastAttr); printer.setIndentCloseTag(settings.Pref_MXML_IndentTagClose); printer.setUseAttrsToKeepOnSameLine(settings.Pref_MXML_UseAttrsToKeepOnSameLine); printer.setRequireCDATAForASContent(settings.Pref_MXML_RequireCDATAForASFormatting); printer.setAttrsToKeepOnSameLine(settings.Pref_MXML_AttrsToKeepOnSameLine); printer.setObeyMaxLineLength(settings.Pref_MXML_AlwaysUseMaxLineLength); String[] tags=settings.Pref_MXML_TagsCannotFormat.Split(','); List<String> tagSet=new List<String>(); foreach (String tag in tags) { if (tag.Length>0) { tagSet.Add(tag); } } printer.setTagsThatCannotBeFormatted(tagSet); tags=settings.Pref_MXML_TagsCanFormat.Split(','); tagSet=new List<String>(); foreach (String tag in tags) { if (tag.Length>0) { tagSet.Add(tag); } } printer.setTagsThatCanBeFormatted(tagSet); tags = settings.Pref_MXML_TagsWithBlankLinesBefore.Split(','); tagSet=new List<String>(); foreach (String tag in tags) { if (tag.Length>0) { tagSet.Add(tag); } } printer.setTagsWithBlankLinesBeforeThem(tagSet); tags = settings.Pref_MXML_ParentTagsWithBlankLinesAfter.Split(','); tagSet=new List<String>(); foreach (String tag in tags) { if (tag.Length>0) { tagSet.Add(tag); } } printer.setParentTagsWithBlankLinesAfterThem(tagSet); tags = settings.Pref_MXML_TagsWithASContent.Split(','); tagSet=new List<String>(); foreach (String tag in tags) { if (tag.Length>0) { tagSet.Add(tag); } } printer.setASScriptTags(tagSet); List<AttrGroup> attrGroups=new List<AttrGroup>(); String groupData=settings.Pref_MXML_AttrGroups; String[] groups = groupData.Split(Settings.LineSplitter); foreach (String g in groups) { AttrGroup group=AttrGroup.load(g); if (group!=null) attrGroups.Add(group); } printer.setAttrGroups(attrGroups); printer.setUsePrivateTags(settings.Pref_MXML_UseTagsDoNotFormatInside); tags = settings.Pref_MXML_TagsDoNotFormatInside.Split(','); List<String> tagList=new List<String>(); foreach (String tag in tags) { if (tag.Length>0) { tagList.Add(tag); } } printer.setPrivateTags(tagList); configureASPrinter(printer.getASPrinter(), settings); printer.getASPrinter().setBlankLinesBeforeImports(0); //special case: we only want blank lines before imports in .as files }
/// <summary> /// Formats the specified document /// </summary> private void DoFormat(ITabbedDocument doc) { if (doc.IsEditable) { doc.SciControl.BeginUndoAction(); Int32 oldPos = CurrentPos; String source = doc.SciControl.Text; try { switch (DocumentType) { case TYPE_AS3: ASPrettyPrinter asPrinter = new ASPrettyPrinter(true, source); FormatUtility.configureASPrinter(asPrinter, this.settingObject); String asResultData = asPrinter.print(0); if (asResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = asResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; case TYPE_MXML: case TYPE_XML: MXMLPrettyPrinter mxmlPrinter = new MXMLPrettyPrinter(source); FormatUtility.configureMXMLPrinter(mxmlPrinter, this.settingObject); String mxmlResultData = mxmlPrinter.print(0); if (mxmlResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = mxmlResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; case TYPE_CPP: AStyleInterface asi = new AStyleInterface(); String optionData = this.GetOptionData(doc.SciControl.ConfigurationLanguage.ToLower()); String resultData = asi.FormatSource(source, optionData); if (String.IsNullOrEmpty(resultData)) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { // Remove all empty lines if not specified for astyle if (!optionData.Contains("--delete-empty-lines")) { resultData = Regex.Replace(resultData, @"^\s+$[\r\n]*", Environment.NewLine, RegexOptions.Multiline); } doc.SciControl.Text = resultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; } } catch (Exception) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } CurrentPos = oldPos; doc.SciControl.EndUndoAction(); } }
public static void configureMXMLPrinter(MXMLPrettyPrinter printer, Settings settings) { Boolean useTabs = PluginBase.Settings.UseTabs; Int32 tabSize = PluginBase.Settings.TabWidth; Int32 spaceSize = PluginBase.Settings.IndentSize; printer.setAttrSortMode((Int32)settings.Pref_MXML_SortAttrMode); printer.setIndentAmount(spaceSize); printer.setUseTabs(useTabs); printer.setTabSize(tabSize); printer.setTabSize(tabSize); printer.setIndentAmount(tabSize); printer.setSortOtherAttrs(settings.Pref_MXML_SortExtraAttrs); printer.setSpacesAroundEquals(settings.Pref_MXML_SpacesAroundEquals); printer.setSpacesBeforeEmptyTagEnd(settings.Pref_MXML_SpacesBeforeEmptyTagEnd); printer.setKeepBlankLines(settings.Pref_MXML_KeepBlankLines); printer.setKeepRelativeCommentIndent(settings.Pref_MXML_KeepRelativeIndentInMultilineComments); printer.setBlankLinesBeforeComments(settings.Pref_MXML_BlankLinesBeforeComments); printer.setBlankLinesBeforeTags(settings.Pref_MXML_BlankLinesBeforeTags); printer.setBlankLinesAfterSpecificParentTags(settings.Pref_MXML_BlankLinesAfterSpecificParentTags); printer.setSpacesBetweenSiblingTags(settings.Pref_MXML_BlankLinesBetweenSiblingTags); printer.setSpacesAfterParentTags(settings.Pref_MXML_BlankLinesAfterParentTags); printer.setBlankLinesBeforeCloseTags(settings.Pref_MXML_BlankLinesBeforeClosingTags); printer.setWrapStyle((Int32)settings.Pref_MXML_WrapIndentStyle); printer.setHangingIndentTabs(settings.Pref_MXML_TabsInHangingIndent); printer.setUseSpacesInsideAttrBraces(settings.Pref_MXML_UseSpacesInsideAttributeBraces); printer.setFormatBoundAttributes(settings.Pref_MXML_UseFormattingOfBoundAttributes); printer.setSpacesInsideAttrBraces(settings.Pref_MXML_SpacesInsideAttributeBraces); printer.setCDATAIndentTabs(settings.Pref_MXML_ScriptCDataIndentTabs); printer.setScriptIndentTabs(settings.Pref_MXML_ScriptIndentTabs); printer.setBlankLinesAtCDataStart(settings.Pref_MXML_BlankLinesAtCDataStart); printer.setBlankLinesAtCDataEnd(settings.Pref_MXML_BlankLinesAtCDataStart); printer.setKeepCDataOnSameLine(settings.Pref_MXML_KeepScriptCDataOnSameLine); printer.setMaxLineLength(settings.Pref_MXML_MaxLineLength); printer.setWrapMode((Int32)settings.Pref_MXML_AttrWrapMode); printer.setAttrsPerLine(settings.Pref_MXML_AttrsPerLine); printer.setAddNewlineAfterLastAttr(settings.Pref_MXML_AddNewlineAfterLastAttr); printer.setIndentCloseTag(settings.Pref_MXML_IndentTagClose); printer.setUseAttrsToKeepOnSameLine(settings.Pref_MXML_UseAttrsToKeepOnSameLine); printer.setRequireCDATAForASContent(settings.Pref_MXML_RequireCDATAForASFormatting); printer.setAttrsToKeepOnSameLine(settings.Pref_MXML_AttrsToKeepOnSameLine); printer.setObeyMaxLineLength(settings.Pref_MXML_AlwaysUseMaxLineLength); String[] tags = settings.Pref_MXML_TagsCannotFormat.Split(','); List <String> tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.setTagsThatCannotBeFormatted(tagSet); tags = settings.Pref_MXML_TagsCanFormat.Split(','); tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.setTagsThatCanBeFormatted(tagSet); tags = settings.Pref_MXML_TagsWithBlankLinesBefore.Split(','); tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.setTagsWithBlankLinesBeforeThem(tagSet); tags = settings.Pref_MXML_ParentTagsWithBlankLinesAfter.Split(','); tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.setParentTagsWithBlankLinesAfterThem(tagSet); tags = settings.Pref_MXML_TagsWithASContent.Split(','); tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.setASScriptTags(tagSet); List <AttrGroup> attrGroups = new List <AttrGroup>(); String groupData = settings.Pref_MXML_AttrGroups; String[] groups = groupData.Split(Settings.LineSplitter); foreach (String g in groups) { AttrGroup group = AttrGroup.load(g); if (group != null) { attrGroups.Add(group); } } printer.setAttrGroups(attrGroups); printer.setUsePrivateTags(settings.Pref_MXML_UseTagsDoNotFormatInside); tags = settings.Pref_MXML_TagsDoNotFormatInside.Split(','); List <String> tagList = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagList.Add(tag); } } printer.setPrivateTags(tagList); configureASPrinter(printer.getASPrinter(), settings); printer.getASPrinter().setBlankLinesBeforeImports(0); //special case: we only want blank lines before imports in .as files }
public static void ConfigureMXMLPrinter(MXMLPrettyPrinter printer, Settings settings, int tabSize) { printer.SetAttrSortMode((Int32)settings.Pref_MXML_SortAttrMode); printer.SetUseTabs(settings.Pref_Flex_UseTabs); printer.SetTabSize(tabSize); printer.SetIndentAmount(tabSize); List <string> sortAttrData = new List <string>(); string[] sortAttrDataArray = settings.Pref_MXML_SortAttrData.Split('\n'); foreach (string attr in sortAttrDataArray) { sortAttrData.Add(attr); } printer.SetManualAttrSortData(sortAttrData); printer.SetSortOtherAttrs(settings.Pref_MXML_SortExtraAttrs); printer.SetSpacesAroundEquals(settings.Pref_MXML_SpacesAroundEquals); printer.SetSpacesBeforeEmptyTagEnd(settings.Pref_MXML_SpacesBeforeEmptyTagEnd); printer.SetKeepBlankLines(settings.Pref_MXML_KeepBlankLines); printer.SetBlankLinesBeforeTags(settings.Pref_MXML_BlankLinesBeforeTags); printer.SetWrapStyle((Int32)settings.Pref_MXML_WrapIndentStyle); printer.SetMaxLineLength(settings.Pref_MXML_MaxLineLength); printer.SetWrapMode((Int32)settings.Pref_MXML_AttrWrapMode); printer.SetAttrsPerLine(settings.Pref_MXML_AttrsPerLine); printer.SetAddNewlineAfterLastAttr(settings.Pref_MXML_AddNewlineAfterLastAttr); printer.SetUseAttrsToKeepOnSameLine(settings.Pref_MXML_UseAttrsToKeepOnSameLine); printer.SetRequireCDATAForASContent(settings.Pref_MXML_RequireCDATAForASFormatting); printer.SetAttrsToKeepOnSameLine(settings.Pref_MXML_AttrsToKeepOnSameLine); String[] tags = settings.Pref_MXML_TagsCannotFormat.Split(','); List <String> tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.SetTagsThatCannotBeFormatted(tagSet); tags = settings.Pref_MXML_TagsCanFormat.Split(','); tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.SetTagsThatCanBeFormatted(tagSet); tags = settings.Pref_MXML_TagsWithBlankLinesBefore.Split(','); tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.SetTagsWithBlankLinesBeforeThem(tagSet); tags = settings.Pref_MXML_TagsWithASContent.Split(','); tagSet = new List <String>(); foreach (String tag in tags) { if (tag.Length > 0) { tagSet.Add(tag); } } printer.SetASScriptTags(tagSet); List <AttrGroup> attrGroups = new List <AttrGroup>(); String groupData = settings.Pref_MXML_AttrGroups; String[] groups = groupData.Split(Settings.LineSplitter); foreach (String g in groups) { AttrGroup group = AttrGroup.Load(g); if (group != null) { attrGroups.Add(group); } } printer.SetAttrGroups(attrGroups); ConfigureASPrinter(printer.GetASPrinter(), settings, tabSize); }