/// <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, 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();
            }
        }
Exemple #2
0
        /// <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();
            }
        }