Ejemplo n.º 1
0
        private void OpenScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter      = SCRIPTFILEFILTER;
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.Title       = "Open Script File";
            openFileDialog1.FileName    = "";

            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                if (IsFileLoaded(openFileDialog1.FileName))
                {
                    return;
                }

                frmDocument docNew = new frmDocument(openFileDialog1.FileName, null);
                docNew.ToolTipShown += Document_ToolTipShown;

                if (documents.Count < 1)
                {
                    docNew.Show(dockPanel1, DockState.Document);
                }
                else
                {
                    docNew.Show(documents[0].Pane, null);
                }

                documents.Add(docNew);
            }
        }
Ejemplo n.º 2
0
        private bool ContinueIfChanges(frmDocument docToCheck)
        {
            if (docToCheck == null)
            {
                return(true);
            }

            if (docToCheck.FileModified && !string.IsNullOrEmpty(docToCheck.ScriptText))
            {
                DialogResult dlgResult = SaveChangesQuestion(docToCheck.FileName);

                if (dlgResult == DialogResult.Cancel)
                {
                    return(false);
                }
                else if (dlgResult == DialogResult.Yes)
                {
                    SaveScript(docToCheck);

                    if (docToCheck.FileModified)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            if (File.Exists(LAYOUTSTOREFILE))
            {
                dockPanel1.LoadFromXml(LAYOUTSTOREFILE, m_deserializeDockContent);

                for (int i = documents.Count; i > 0; i--)
                {
                    frmDocument doc = documents[i - 1];

                    if (!doc.FileExists)
                    {
                        documents.Remove(doc);
                        doc.Close();
                    }
                }
            }
            else
            {
                ResetLayout();
            }

            imagePreview.VisibleChanged += DockWindow_VisibleChanged;
            hintWindow.VisibleChanged   += DockWindow_VisibleChanged;
            outputWindow.VisibleChanged += DockWindow_VisibleChanged;
            svgContents.VisibleChanged  += DockWindow_VisibleChanged;

            AddNewScriptIfNone();

            RefreshViewMenuItemsCheckedState();
        }
Ejemplo n.º 4
0
        private void NewScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int maxNew = 0;

            foreach (frmDocument fDoc in documents)
            {
                if (fDoc.FileName.StartsWith(NEWSCRIPTFORMATSTRINGPREFIX))
                {
                    if (int.TryParse(fDoc.FileName.Substring(4), out int i))
                    {
                        if (i > maxNew)
                        {
                            maxNew = i;
                        }
                    }
                }
            }

            frmDocument docNew = new frmDocument(string.Format(NEWSCRIPTFORMATSTRINGPREFIX + "{0}", maxNew + 1), "");

            docNew.ToolTipShown += Document_ToolTipShown;

            if (documents.Count < 1)
            {
                docNew.Show(dockPanel1, DockState.Document);
            }
            else
            {
                docNew.Show(documents[0].Pane, null);
            }

            documents.Add(docNew);
        }
Ejemplo n.º 5
0
        private void SaveScriptAs(frmDocument docToSave)
        {
            if (docToSave == null)
            {
                MessageBox.Show(this, "Failed to get active document", "Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (string.IsNullOrEmpty(docToSave.ScriptText))
            {
                MessageBox.Show(this, "No script to save", "Cannot Save Script", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            saveFileDialog1.Filter      = SCRIPTFILEFILTER;
            saveFileDialog1.FilterIndex = 0;
            saveFileDialog1.Title       = "Save Script File";

            if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                if (IsFileLoaded(saveFileDialog1.FileName, true))
                {
                    return;
                }

                docToSave.SaveScriptFile(saveFileDialog1.FileName);
            }
        }
Ejemplo n.º 6
0
        private IDockContent GetContentFromPersistString(string persistString)
        {
            string[] persistStringParts = persistString.Split(new char[] { '\t' });

            switch (persistStringParts[0].ToLower())
            {
            case "document":
                // persistStringParts[1] is FileName
                frmDocument doc = new frmDocument(persistStringParts[1], null);
                doc.ToolTipShown += Document_ToolTipShown;

                documents.Add(doc);
                return(doc);

            case "imagepreview":
                // persistStringParts[1] is empty
                return(imagePreview);

            case "hint":
                // persistStringParts[1] is TextControlType
                return(hintWindow);

            case "output":
                // persistStringParts[1] is TextControlType
                return(outputWindow);

            case "svg file":
                // persistStringParts[1] is TextControlType
                return(svgContents);

            default:
                return(null);
            }
        }
Ejemplo n.º 7
0
 private void AddNewScriptIfNone()
 {
     if (documents.Count < 1)
     {
         frmDocument docNew = new frmDocument(string.Format(NEWSCRIPTFORMATSTRINGPREFIX + "{0}", 1), "");
         docNew.ToolTipShown += Document_ToolTipShown;
         docNew.Show(dockPanel1, DockState.Document);
         documents.Add(docNew);
     }
 }
Ejemplo n.º 8
0
        private void CloseScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDocument docToClose = GetActiveDocument();

            if (ContinueIfChanges(docToClose))
            {
                documents.Remove(docToClose);
                docToClose.Close();
            }

            AddNewScriptIfNone();
        }
Ejemplo n.º 9
0
        private void RunScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PictureBox  picBox = imagePreview.PicBox;
            frmDocument doc    = GetActiveDocument();

            svgContents.Clear();
            imagePreview.Clear();
            outputWindow.Clear();

            saveImageToolStripMenuItem.Enabled = false;

            Cursor = Cursors.WaitCursor;

            SvgGraphics ig       = new SvgGraphics();
            Bitmap      bitmap   = new Bitmap(picBox.Width, picBox.Height, PixelFormat.Format32bppArgb);
            GdiGraphics graphics = new GdiGraphics(Graphics.FromImage(bitmap));

            if (dpmmX <= 0 || dpmmY <= 0)
            {
                dpmmX = graphics.DpiX / 25.4F;
                dpmmY = graphics.DpiY / 25.4F;
            }

            try
            {
                RunScript(ig, doc.ScriptText);
                RunScript(graphics, doc.ScriptText);

                if (bitmap == null)
                {
                    return;
                }

                svgContents.ReadOnlyText = ig.WriteSVGString();
                picBox.Image             = bitmap;

                saveImageToolStripMenuItem.Enabled = true;

                Cursor = Cursors.Default;
            }
            catch (Exception exp)
            {
                Cursor = Cursors.Default;
                outputWindow.ReadOnlyText = exp.Message;
                outputWindow.Activate();
                MessageBox.Show(this, "There were script errors. Unable to draw image.", "Script Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 10
0
        private void SaveScript(frmDocument docToSave)
        {
            if (docToSave == null)
            {
                MessageBox.Show(this, "Failed to get active document", "Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (string.IsNullOrEmpty(docToSave.FileName) || docToSave.FileName.StartsWith(NEWSCRIPTFORMATSTRINGPREFIX))
            {
                SaveScriptAs(docToSave);
                return;
            }

            docToSave.SaveScriptFile();
        }
Ejemplo n.º 11
0
        private bool IsFileLoaded(string FileName, bool ExcludeActiveDocument)
        {
            frmDocument activeDoc = GetActiveDocument();

            foreach (frmDocument doc in documents)
            {
                if (ExcludeActiveDocument && doc == activeDoc)
                {
                    continue;
                }

                if (doc.FileName == FileName)
                {
                    MessageBox.Show(this, "File is opened in another window.", "Duplicate File", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(true);
                }
            }

            return(false);
        }