Example #1
0
        public static void LoadItem(int index)
        {
            _ScripterForm.CreateNewDocument(Scripter.DEF_FILE_NAME);

            string filename = "Template" + index + ".tem";
            string path     = Path.Combine(Path.Combine(Path.Combine(Scripter.AppPath, "data"), "templates"), filename);

            if (!File.Exists(path))
            {
                UtilSys.MessageBox("File '" + path + "' does not exist.");
                return;
            }

            string[] buffer = UtilIO.ReadFile2Array(path);

            _ScripterForm.CurrentEditor.Loading = true;

            foreach (string line in buffer)
            {
                _ScripterForm.CurrentEditor.AddLine(line);
            }
            _ScripterForm.CurrentEditor.Loading = false;
            _ScripterForm.CurrentEditor.Dirty   = false;
            _ScripterForm.CurrentEditor.InitUndoStack();
            Scripter.DoEvents();
            _ScripterForm.OnReParse();
            Scripter.DoEvents();
            _ScripterForm.CurrentEditor.Focus();
        }
Example #2
0
        public static void Open(string path, string filter)
        {
            if (string.IsNullOrEmpty(filter))
            {
                filter = "QABOT Script Files (*.scp)|*.scp|QABOT Script Import Modules (*.sci)|*.sci|QABOT Data Files (*.dat)|*.dat|QABOT Project Files (*.qpf)|*.qpf|QABOT Template Files (*.tem)|*.tem|All Files (*.*)|*.*";
            }

            if (string.IsNullOrEmpty(path))
            {
                path = UtilSys.OpenFileDialog("Open QABOT Script, Data or Template File", filter, LastOpenedFolder);
            }

            if (string.Empty == path)
            {
                return;
            }

            bool bOpened = false;

            // if the script is already opened in one of tabs
            // check if it is modified if yes, ask to save it?
            int    i      = 0;
            Editor editor = null;

            foreach (TabPage page in frm.tabFiles.TabPages)
            {
                editor = (Editor)page.Controls[0].Controls[0];

                Debug.Assert(null != editor);

                if (editor.Path2File == path)
                {
                    bOpened = true;
                    frm.tabFiles.SelectedIndex = i;
                    editor.Clear();
                    Application.DoEvents();
                    break;
                }
                ++i;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            string[] buffer = ScriptLoader.Load(frm, mru, path);

            if (null == buffer)
            {
                frm.UpdateMRUMenu();
                return;
            }

            LastOpenedFolder = Path.GetDirectoryName(path);

            FrmProgress frmP = new FrmProgress();

            frmP.Show();
            frmP.Top  = frm.Top + frm.Height / 2;
            frmP.Left = (frm.Left + frm.Width / 2) - frmP.Width / 2;

            frmP.SetProgressMax(buffer.Length);

            if (!bOpened)
            {
                frm.CreateNewDocument(path);
                editor = frm.CurrentEditor;
            }

            editor.Dirty   = false;
            editor.Loading = true;
            editor.SuspendLayout();

            bool IsCompatibilityChangeMade = false;

            string line = string.Empty;

            for (int j = 0; j < buffer.Length; ++j)
            {
                line = buffer[j];

                if (_bCompatibilty)
                {
                    line = CreateCompatibileLine(line);

                    if (line != buffer[j])
                    {
                        IsCompatibilityChangeMade = true;
                        Scripter.Output("Line(" + j.ToString() + ") changed from -> to: '" + buffer[j] + "' -> '" + line + "'");
                    }
                }
                editor.AddLine(line);
                frmP.UpdateProgress();
                frmP.Text = "Progress... (" + j + "/" + buffer.Length + ")";
            }

            editor.ResumeLayout();
            editor.Loading = false;
            editor.HandleBlockComments();
            editor.InitUndoStack();
            frmP.Close();

            if (!bOpened)
            {
                frm.tabFiles.SelectedIndex = frm.tabFiles.TabPages.Count - 1;
                frm.tabFiles.TabPages[frm.tabFiles.SelectedIndex].Focus();
                frm.UpdateDebugButtons();
            }

            editor.Dirty = IsCompatibilityChangeMade;

            frm.UpdateMRUMenu();
            frm.OnReParse();
            editor.Focus();

            sw.Stop();

            TimeSpan span = sw.Elapsed;

            Scripter.Output("Load Time: " + span.Hours + ":" + span.Minutes + ":" + span.Seconds + ":" + span.Milliseconds);
        }