Ejemplo n.º 1
0
        /// <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();
            }
        }