Example #1
0
        public BaseDocument ShowDocument(ProjectElement Element)
        {
            if (Element.DocumentInfo.Type == ProjectElement.ElementType.FOLDER)
            {
                return(null);
            }
            if (Element.Document == null)
            {
                BaseDocument document = Core.MainForm.CreateNewDocument(Element.DocumentInfo.Type, Element.DocumentInfo.Project);
                if (document == null)
                {
                    System.Windows.Forms.MessageBox.Show("Could not create document for " + Element.DocumentInfo.Type.ToString(), "Error creating document");
                    return(null);
                }
                Element.DocumentInfo.BaseDoc = document;
                Element.Document             = document;
                Element.Document.ShowHint    = DockState.Document;
                Element.Document.Icon        = Core.MainForm.IconFromType(Element.DocumentInfo);
                document.SetProjectElement(Element);
                document.Core = Core;
                document.SetDocumentFilename(Element.Filename);
                if (Element.DocumentInfo.Project == null)
                {
                    // icon for non project documents
                    document.Icon = System.Drawing.SystemIcons.Asterisk;
                }
                document.ToolTipText = "";

                if (document.DocumentFilename == null)
                {
                    // a new file
                    Element.Name = Element.Name;
                    Element.Document.Show(Core.MainForm.panelMain);
                }
                else if (document.Load())
                {
                    document.ToolTipText = document.DocumentInfo.FullPath;
                    Element.Name         = document.Text;
                    //Element.Name;
                    Element.Document.Show(Core.MainForm.panelMain);
                }
                else if (!string.IsNullOrEmpty(Element.Filename))
                {
                    Element.Document = null;
                    return(null);
                }
                if (Element.Document != null)
                {
                    Element.Document.DocumentInfo = Element.DocumentInfo;
                    Element.DocumentInfo.BaseDoc  = Element.Document;
                }

                if ((Element.Document != null) &&
                    (Element.Document is SourceASMEx))
                {
                    Element.Document.DocumentEvent += new BaseDocument.DocumentEventHandler(Core.MainForm.Document_DocumentEvent);
                }

                // set known tokens if we have any
                bool setFromMainDoc = false;
                if (!string.IsNullOrEmpty(Settings.MainDocument))
                {
                    var element = GetElementByFilename(Settings.MainDocument);
                    if ((element != null) &&
                        (element.DocumentInfo.Type == ProjectElement.ElementType.ASM_SOURCE) &&
                        (element.DocumentInfo.ASMFileInfo != null))
                    {
                        if (element.DocumentInfo.ASMFileInfo.ContainsFile(Element.DocumentInfo.FullPath))
                        {
                            if (!Core.Compiling.IsCurrentlyBuilding())
                            {
                                Element.DocumentInfo.SetASMFileInfo(element.DocumentInfo.ASMFileInfo, element.DocumentInfo.KnownKeywords, element.DocumentInfo.KnownTokens);
                            }
                            setFromMainDoc = true;
                        }
                    }
                }
                if ((!setFromMainDoc) &&
                    (Core.Compiling.ParserASM.ASMFileInfo.ContainsFile(Element.DocumentInfo.FullPath)))
                {
                    if (!Core.Compiling.IsCurrentlyBuilding())
                    {
                        Element.DocumentInfo.SetASMFileInfo(Core.Compiling.ParserASM.ASMFileInfo, Core.Compiling.ParserASM.KnownTokens(), Core.Compiling.ParserASM.KnownTokenInfo());
                    }
                }
                Core.MainForm.m_Outline.RefreshFromDocument(Element.DocumentInfo.BaseDoc);
            }
            Element.Document.Select();
            Element.IsShown = true;
            Core.MainForm.RaiseApplicationEvent(new RetroDevStudio.Types.ApplicationEvent(RetroDevStudio.Types.ApplicationEvent.Type.DOCUMENT_OPENED, Element.DocumentInfo));
            Core.MainForm.RaiseApplicationEvent(new RetroDevStudio.Types.ApplicationEvent(RetroDevStudio.Types.ApplicationEvent.Type.ELEMENT_OPENED, Element));

            return(Element.Document);
        }