コード例 #1
0
        public override bool HandleExport(ExportCharsetScreenInfo Info, TextBox EditOutput, DocumentInfo DocInfo)
        {
            Types.ComboItem comboItem = (Types.ComboItem)comboCharsetFiles.SelectedItem;
            if (comboItem.Tag == null)
            {
                // to new file
                BaseDocument document = null;
                if (DocInfo.Project == null)
                {
                    document = Core.MainForm.CreateNewDocument(ProjectElement.ElementType.CHARACTER_SET, null);
                }
                else
                {
                    document = Core.MainForm.CreateNewElement(ProjectElement.ElementType.CHARACTER_SET, "Character Set", DocInfo.Project).Document;
                }
                if (document.DocumentInfo.Element != null)
                {
                    document.SetDocumentFilename("New Character Set.charsetproject");
                    document.DocumentInfo.Element.Filename = document.DocumentInfo.DocumentFilename;
                }
                ((CharsetEditor)document).OpenProject(Info.CharsetData);
                document.SetModified();
                document.Save(SaveMethod.SAVE);
            }
            else
            {
                DocumentInfo  docInfo  = (DocumentInfo)comboItem.Tag;
                CharsetEditor document = (CharsetEditor)docInfo.BaseDoc;
                if (document == null)
                {
                    if (docInfo.Project != null)
                    {
                        docInfo.Project.ShowDocument(docInfo.Element);
                        document = (CharsetEditor)docInfo.BaseDoc;
                    }
                }
                if (document != null)
                {
                    document.OpenProject(Info.CharsetData);
                    document.SetModified();
                }
            }

            return(true);
        }
コード例 #2
0
        public override bool HandleExport(ExportCharsetScreenInfo Info, TextBox EditOutput, DocumentInfo DocInfo)
        {
            var  sb        = new StringBuilder();
            int  curColor  = -1;
            bool isReverse = false;
            bool replaceSpaceWithCursorRight = checkExportToBASICReplaceSpaceWithRight.Checked;
            bool replaceShiftSpaceWithSpace  = checkExportToBASICReplaceShiftSpaceWithSpace.Checked;
            bool stripInvisibleColors        = checkExportToBASICCollapseColors.Checked;
            bool asString = checkExportToBASICAsString.Checked;


            int startLine = GR.Convert.ToI32(editExportBASICLineNo.Text);

            if ((startLine < 0) ||
                (startLine > 63999))
            {
                startLine = 10;
            }
            int lineStep = GR.Convert.ToI32(editExportBASICLineOffset.Text);

            if ((lineStep < 0) ||
                (lineStep > 63999))
            {
                lineStep = 10;
            }

            int wrapByteCount = GetExportWrapCount();

            if (!asString)
            {
                sb.Append(startLine);
                sb.Append(" PRINT\"" + ConstantData.PetSCIIToChar[147].CharValue + "\";\n");
                startLine += lineStep;

                sb.Append(startLine);
                startLine += lineStep;
                sb.Append(" POKE53280," + Info.Charscreen.CharSet.Colors.BackgroundColor.ToString() + ":POKE53281," + Info.Charscreen.CharSet.Colors.BackgroundColor.ToString() + "\n");
            }

            int colorChangeCache = -1;

            if (asString)
            {
                sb.Append(startLine);
                sb.Append(" B$=\"");
                startLine += lineStep;
            }

            int startLength = sb.Length;

            for (int i = Info.Area.Top; i < Info.Area.Bottom; ++i)
            {
                if (!asString)
                {
                    startLength = sb.Length;
                    sb.Append(startLine);
                    startLine += lineStep;
                    sb.Append(" PRINT\"");
                    if ((isReverse) &&
                        (Info.Area.Width != Info.Charscreen.ScreenWidth))
                    {
                        // need to re-start reverse mode
                        sb.Append(ConstantData.PetSCIIToChar[18].CharValue);
                    }
                }

                for (int x = Info.Area.Left; x < Info.Area.Right; ++x)
                {
                    ushort newColor = (ushort)(Info.Charscreen.ColorAt(x, i) & 0x0f);
                    ushort newChar  = Info.Charscreen.CharacterAt(x, i);

                    if ((replaceShiftSpaceWithSpace) &&
                        ((newChar == 96) ||
                         (newChar == 96 + 128)))
                    {
                        newChar -= 64;
                    }

                    List <string> charsToAppend = new List <string>();

                    if (newColor != curColor)
                    {
                        if (stripInvisibleColors)
                        {
                            colorChangeCache = newColor;
                        }
                        else
                        {
                            charsToAppend.Add("" + ConstantData.PetSCIIToChar[ConstantData.ColorToPetSCIIChar[(byte)newColor]].CharValue);
                        }
                        curColor = newColor;
                    }
                    // skip color changes for space and shift-space
                    if ((newChar != 32) &&
                        (newChar != 96) &&
                        (stripInvisibleColors))
                    {
                        if (colorChangeCache != -1)
                        {
                            charsToAppend.Add("" + ConstantData.PetSCIIToChar[ConstantData.ColorToPetSCIIChar[(byte)colorChangeCache]].CharValue);
                            colorChangeCache = -1;
                        }
                    }
                    if (newChar >= 128)
                    {
                        if (!isReverse)
                        {
                            isReverse = true;
                            charsToAppend.Add("" + ConstantData.PetSCIIToChar[18].CharValue);
                        }
                    }
                    else if (isReverse)
                    {
                        isReverse = false;
                        charsToAppend.Add("" + ConstantData.PetSCIIToChar[146].CharValue);
                    }
                    if (isReverse)
                    {
                        if (newChar == 128 + 34)
                        {
                            // reverse apostrophe
                            string replacement = "\"CHR$(34)CHR$(20)CHR$(34)\"";
                            if (asString)
                            {
                                replacement = "\"+CHR$(34)+CHR$(20)+CHR$(34)+\"";
                            }

                            string replacementString = "";
                            for (int t = 0; t < replacement.Length; ++t)
                            {
                                replacementString += ConstantData.CharToC64Char[replacement[t]].CharValue;
                            }
                            charsToAppend.Add(replacementString);
                        }
                        else
                        {
                            charsToAppend.Add("" + ConstantData.ScreenCodeToChar[(byte)(newChar - 128)].CharValue);
                        }
                    }
                    else
                    {
                        if (newChar == 34)
                        {
                            // a regular apostrophe
                            string replacement = "\"CHR$(34)CHR$(20)CHR$(34)\"";
                            if (asString)
                            {
                                replacement = "\"+CHR$(34)+CHR$(20)+CHR$(34)+\"";
                            }

                            string replacementString = "";
                            for (int t = 0; t < replacement.Length; ++t)
                            {
                                replacementString += ConstantData.CharToC64Char[replacement[t]].CharValue;
                            }
                            charsToAppend.Add(replacementString);
                        }
                        else if ((replaceSpaceWithCursorRight) &&
                                 (newChar == 32))
                        {
                            charsToAppend.Add("" + ConstantData.PetSCIIToChar[29].CharValue);
                        }
                        else
                        {
                            charsToAppend.Add("" + ConstantData.ScreenCodeToChar[(byte)newChar].CharValue);
                        }
                    }

                    // don't make lines too long!
                    foreach (var stringToAppend in charsToAppend)
                    {
                        if (sb.Length - startLength + stringToAppend.Length >= wrapByteCount - 1)
                        {
                            // we need to break and start a new line
                            if (!asString)
                            {
                                sb.Append("\"");
                                if (Info.Area.Width == Info.Charscreen.ScreenWidth)
                                {
                                    sb.Append(";");
                                }
                                sb.Append("\n");
                                startLength = sb.Length;
                                sb.Append(startLine);
                                startLine += lineStep;
                                sb.Append(" PRINT\"");
                                if ((isReverse) &&
                                    (Info.Area.Width != Info.Charscreen.ScreenWidth))
                                {
                                    // need to re-start reverse mode
                                    sb.Append(ConstantData.PetSCIIToChar[18].CharValue);
                                }
                            }
                            else
                            {
                                if ((sb.Length >= 2) &&
                                    (sb[sb.Length - 2] == '+') &&
                                    (sb[sb.Length - 1] == '\"'))
                                {
                                    sb.Length -= 2;
                                }
                                else
                                {
                                    sb.Append("\"");
                                }
                                sb.Append("\n");
                                startLength = sb.Length;
                                sb.Append(startLine);
                                startLine += lineStep;
                                sb.Append(" B$=B$+\"");
                            }
                        }
                        foreach (char toAppend in stringToAppend)
                        {
                            sb.Append(toAppend);
                        }
                    }
                }

                if (!asString)
                {
                    sb.Append("\"");
                    if (Info.Area.Width == Info.Charscreen.ScreenWidth)
                    {
                        sb.Append(";");
                    }
                    sb.Append("\n");
                }
                else
                {
                    // down
                    sb.Append(ConstantData.PetSCIIToChar[17].CharValue);
                    // left
                    for (int x = 0; x < Info.Area.Width; ++x)
                    {
                        sb.Append(ConstantData.PetSCIIToChar[157].CharValue);
                    }
                }
            }
            if (asString)
            {
                if ((sb.Length >= 2) &&
                    (sb[sb.Length - 2] == '+') &&
                    (sb[sb.Length - 1] == '\"'))
                {
                    sb.Length -= 2;
                }
                else
                {
                    sb.Append("\"");
                }
                sb.Append("\n");
            }

            Types.ComboItem comboItem = (Types.ComboItem)comboBasicFiles.SelectedItem;
            if (comboItem.Tag == null)
            {
                if (comboItem.Desc == "To output")
                {
                    EditOutput.Font = new System.Drawing.Font(Core.MainForm.m_FontC64.Families[0], 16, System.Drawing.GraphicsUnit.Pixel);
                    EditOutput.Text = sb.ToString().Replace("\n", "\r\n");
                }
                else
                {
                    // to new file
                    BaseDocument document = null;
                    if (DocInfo.Project == null)
                    {
                        document = Core.MainForm.CreateNewDocument(ProjectElement.ElementType.BASIC_SOURCE, null);
                    }
                    else
                    {
                        document = Core.MainForm.CreateNewElement(ProjectElement.ElementType.BASIC_SOURCE, "BASIC Screen", DocInfo.Project).Document;
                    }
                    if (document.DocumentInfo.Element != null)
                    {
                        document.SetDocumentFilename("New BASIC File.bas");
                        document.DocumentInfo.Element.Filename = document.DocumentInfo.DocumentFilename;
                    }
                    document.FillContent(sb.ToString(), false);
                    document.SetModified();
                    document.Save(SaveMethod.SAVE);
                }
            }
            else
            {
                var document = (DocumentInfo)comboItem.Tag;
                if (document.BaseDoc == null)
                {
                    if (document.Project == null)
                    {
                        return(false);
                    }
                    document.Project.ShowDocument(document.Element);
                }
                document.BaseDoc.InsertText(sb.ToString());
                document.BaseDoc.SetModified();
            }

            return(true);
        }
コード例 #3
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);
        }