protected override void Run(object tool)
        {
            Document doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null)
            {
                return;
            }
            string    mt        = DesktopService.GetMimeTypeForUri(doc.FileName);
            Formatter formatter = TextFileService.GetFormatter(mt);

            if (formatter == null)
            {
                return;
            }
            doc.TextEditor.BeginAtomicUndo();
            int line   = doc.TextEditor.CursorLine;
            int column = doc.TextEditor.CursorColumn;

            doc.TextEditor.Select(0, doc.TextEditor.TextLength);
            doc.TextEditor.SelectedText = formatter.FormatText(doc.Project != null ? doc.Project.Policies : null, doc.TextEditor.Text);
            doc.TextEditor.CursorLine   = line;
            doc.TextEditor.CursorColumn = column;
            doc.TextEditor.EndAtomicUndo();
        }
示例#2
0
 public void Init()
 {
     // This will work for now but really ought to have DI/IoC.
     bs   = new BusinessService();
     udcs = new UserDataCollectionService(bs);
     rs   = new ReportService(bs, udcs);
     tfs  = new TextFileService(udcs);
 }
示例#3
0
        private void CreateServices()
        {
            var textFileService = new TextFileService();
            var xmlFileService  = new XmlFileService();

            //var sqlDataService = new SqlDataService();
            //var webAppPoolService = new WebAppPoolService();

            this.LogService           = new LogService(this.AppName, textFileService);
            this.ConfigurationService = new ConfigurationService(this.AppName, xmlFileService);
            //this.MonitorService = new MonitorService(sqlDataService, this.WebAppPoolService, this.LogService);
        }
示例#4
0
        static string FormatGeneratedFile(string file, string content, CodeDomProvider provider)
        {
            content = StripHeaderAndBlankLines(content, provider);
            string    mt        = DesktopService.GetMimeTypeForUri(file);
            Formatter formatter = TextFileService.GetFormatter(mt);

            if (formatter != null)
            {
                content = formatter.FormatText(PolicyService.InvariantPolicies, content);
            }
            return(content);
        }
 protected override void Update(CommandInfo info)
 {
     if (IdeApp.Workbench.ActiveDocument != null && IdeApp.Workbench.ActiveDocument.IsFile)
     {
         string    mt        = DesktopService.GetMimeTypeForUri(IdeApp.Workbench.ActiveDocument.FileName);
         Formatter formatter = TextFileService.GetFormatter(mt);
         if (formatter != null)
         {
             return;
         }
     }
     info.Enabled = false;
 }
示例#6
0
        void UpdateExample()
        {
            Formatter formatter = TextFileService.GetFormatter(description.MimeType);

            if (formatter == null)
            {
                return;
            }
            DotNetAssemblyProject parent = new DotNetAssemblyProject();

            parent.Policies.Set <T> (settings, description.MimeType);
            texteditor1.Document.Text = formatter.FormatText(parent.Policies, texteditor1.Document.Text);
        }
        // Returns a stream with the content of the file.
        // project and language parameters are optional
        public virtual Stream CreateFileContent(SolutionItem policyParent, Project project, string language, string fileName, string identifier)
        {
            Dictionary <string, string> tags = new Dictionary <string, string> ();

            ModifyTags(policyParent, project, language, identifier, fileName, ref tags);

            string content = CreateContent(project, tags, language);

            content = StringParserService.Parse(content, tags);
            string    mime      = DesktopService.GetMimeTypeForUri(fileName);
            Formatter formatter = !String.IsNullOrEmpty(mime) ? TextFileService.GetFormatter(mime) : null;

            if (formatter != null)
            {
                content = formatter.FormatText(policyParent != null ? policyParent.Policies : null, content);
            }

            MemoryStream ms = new MemoryStream();

            byte[] data;
            if (AddStandardHeader)
            {
                string header = StandardHeaderService.GetHeader(policyParent, fileName, true);
                data = System.Text.Encoding.UTF8.GetBytes(header);
                ms.Write(data, 0, data.Length);
            }

            Mono.TextEditor.Document doc = new Mono.TextEditor.Document();
            doc.Text = content;

            TextStylePolicy textPolicy = policyParent != null?policyParent.Policies.Get <TextStylePolicy> ("text/plain") : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <TextStylePolicy> ("text/plain");

            string eolMarker = TextStylePolicy.GetEolMarker(textPolicy.EolMarker);

            byte[] eolMarkerBytes = System.Text.Encoding.UTF8.GetBytes(eolMarker);
            foreach (Mono.TextEditor.LineSegment line in doc.Lines)
            {
                data = System.Text.Encoding.UTF8.GetBytes(doc.GetTextAt(line.Offset, line.EditableLength));
                ms.Write(data, 0, data.Length);
                ms.Write(eolMarkerBytes, 0, eolMarkerBytes.Length);
            }

            ms.Position = 0;
            return(ms);
        }
示例#8
0
 void HandleTextPaste(int insertionOffset, string text)
 {
     if (PropertyService.Get("OnTheFlyFormatting", false))
     {
         Formatter prettyPrinter = TextFileService.GetFormatter(Document.MimeType);
         if (prettyPrinter != null && prettyPrinter.SupportsOnTheFlyFormatting && ProjectDom != null && text != null)
         {
             try {
                 string newText = prettyPrinter.FormatText(ProjectDom.Project.Policies, Document.MimeType, Document.Text, insertionOffset, insertionOffset + text.Length);
                 if (!string.IsNullOrEmpty(newText))
                 {
                     Replace(insertionOffset, text.Length, newText);
                     Caret.Offset = insertionOffset + newText.Length;
                 }
             } catch (Exception e) {
                 Console.WriteLine(e);
             }
         }
     }
 }
示例#9
0
        internal void InsertTemplate(CodeTemplate template, MonoDevelop.Ide.Gui.Document document)
        {
            Document.BeginAtomicUndo();
            var result           = template.InsertTemplateContents(document);
            TextLinkEditMode tle = new TextLinkEditMode(this,
                                                        result.InsertPosition,
                                                        result.TextLinks);

            if (PropertyService.Get("OnTheFlyFormatting", false))
            {
                Formatter prettyPrinter = TextFileService.GetFormatter(Document.MimeType);
                if (prettyPrinter != null && prettyPrinter.SupportsOnTheFlyFormatting)
                {
                    int    endOffset = result.InsertPosition + result.Code.Length;
                    string text      = prettyPrinter.FormatText(document.Project.Policies, Document.MimeType, Document.Text, result.InsertPosition, endOffset);
                    string oldText   = Document.GetTextAt(result.InsertPosition, result.Code.Length);
                    //					Console.WriteLine (result.InsertPosition);
                    //					Console.WriteLine ("old:" + oldText);
                    //					Console.WriteLine ("new:" + text);
                    Replace(result.InsertPosition, result.Code.Length, text);
                    Caret.Offset = result.InsertPosition + TranslateOffset(oldText, text, Caret.Offset - result.InsertPosition);
                    foreach (TextLink textLink in tle.Links)
                    {
                        foreach (ISegment segment in textLink.Links)
                        {
                            segment.Offset = TranslateOffset(oldText, text, segment.Offset);
                        }
                    }
                }
            }

            if (tle.ShouldStartTextLinkMode)
            {
                tle.OldMode = CurrentMode;
                tle.StartMode();
                CurrentMode = tle;
            }
            Document.EndAtomicUndo();
        }