示例#1
0
 private void Runner_AsyncTaskСhanged(ParseTaskRunner runner, Parser parser)
 {
     if (InvokeRequired)
     {
         Invoke(new ParseTaskRunner.AsyncTaskChangedDelegate(Runner_AsyncTaskСhanged), runner, parser);
     }
     else
     {
         CurrentTask = Tasks[runner.index - 1].Name;
     }
 }
示例#2
0
文件: Editor.cs 项目: Coestaris/hasm
 private void Parser_AsyncTaskChanged(ParseTaskRunner runner, HASMSource Source)
 {
     if (InvokeRequired)
     {
         Invoke(new ParseTaskRunner.AsyncTaskChangedDelegate(Parser_AsyncTaskChanged), runner, Source);
     }
     else
     {
         Tasks = runner.Tasks;
         OutputToTextBox();
     }
 }
示例#3
0
        private void ProgressDialog_Load(object sender, EventArgs e)
        {
            ParseTaskRunner runner = new ParseTaskRunner(parser);

            progressBarTotal.Maximum   = Tasks.Count * MaxValue;
            progressBarCurrent.Maximum = MaxValue;

            runner.UpdatePeriod         = 50;
            runner.AsyncParseEnd       += Runner_AsyncParseEnd;
            runner.AsyncTaskPeriodical += Runner_AsyncTaskPeriodical;
            runner.AsyncTaskСhanged    += Runner_AsyncTaskСhanged;

            runner.RunAsync(Tasks);
        }
示例#4
0
文件: Editor.cs 项目: Coestaris/hasm
        public void Run(string FileName)
        {
            HASMSource source = new HASMSource(Machine, new FileInfo(FileName.NormalizePath()), null);

            loadingCircle1.Visible        = true;
            tabControl1.Enabled           = false;
            stopToolStripMenuItem.Enabled = true;

            var parser = new ParseTaskRunner(source);

            parser.AsyncParseEnd    += ParsingEnd;
            parser.AsyncTaskСhanged += Parser_AsyncTaskChanged;

            parser.RunAsync();
        }
示例#5
0
        private void Runner_AsyncParseEnd(ParseTaskRunner runner, Parser parser)
        {
            if (InvokeRequired)
            {
                Invoke(new ParseTaskRunner.AsyncParseEndDelegate(Runner_AsyncParseEnd), runner, parser);
            }
            else
            {
                Exception ex = Tasks[runner.FailedTaskIndex].Error;
                if (ex != null)
                {
                    MessageBox.Show(string.Format("{0}\n{1}\n\n{2}",
                                                  ex.Message, ex.StackTrace, ex.InnerException), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Close();
            }
        }
示例#6
0
        private void Runner_AsyncTaskPeriodical(ParseTaskRunner runner, Parser parser)
        {
            if (InvokeRequired)
            {
                Invoke(new ParseTaskRunner.AsyncTaskPeriodicalDelegate(Runner_AsyncTaskPeriodical), runner, parser);
            }
            else
            {
                progressBarTotal.Value   = Math.Min(progressBarTotal.Maximum, (int)((runner.index - 1) * MaxValue + Tasks[runner.index - 1].CurrentStep * MaxValue));
                progressBarCurrent.Value = Math.Min(progressBarCurrent.Maximum, (int)(Tasks[runner.index - 1].SubTaskCurrentStep * MaxValue));

                labelTotal.Text = string.Format("[{0:0.0}%. {1:0}/{2:0}]. Task: {3}", (float)progressBarTotal.Value / progressBarTotal.Maximum * 100,
                                                runner.index, Tasks.Count, CurrentTask);

                labelCurrent.Text = string.Format("{0:0.0}% - {1}", (float)progressBarCurrent.Value / progressBarCurrent.Maximum * 100,
                                                  Tasks[runner.index - 1].SubtaskName);
            }
        }
示例#7
0
文件: Cache.cs 项目: Coestaris/hasm
        public ParseError BuildCache()
        {
            foreach (var file in PathsToCache)
            {
                HASMSource      source = new HASMSource(parrent, new FileInfo(file));
                ParseTaskRunner runner = new ParseTaskRunner(source);
                runner.Run();

                if (runner.Status != ParseTaskStatus.Ok)
                {
                    return(runner.Tasks[runner.FailedTaskIndex].Error);
                }

                FileCache.Add(file, new FileCache()
                {
                    AbsoluteFileName = file,
                    CompiledClasses  = source.Assembly == null ? new List <Class>() : source.Assembly.Classes,
                    CompiledDefines  = PreprocessorDirective.defines ?? new List <Define>()
                });
            }

            return(null);
        }
示例#8
0
        public TextEditor(string path, Control parent)
        {
            InitPlatformSpecificRegexes();
            path = path.NormalizePath();

            Parrent = parent as Editor;
            if (!File.Exists(path))
            {
                MessageBox.Show($"Unable to find file \"{path}\"");
                return;
            }

            TextBox = new FastColoredTextBox
            {
                Dock = DockStyle.Fill,
                Text = File.ReadAllText(path),

                BracketsHighlightStrategy = BracketsHighlightStrategy.Strategy1,
                AutoCompleteBrackets      = true,
                LeftBracket  = '(',
                RightBracket = ')',
            };


            popupMenu = new AutocompleteMenu(TextBox)
            {
                ImageList         = AutocompleteImageList,
                MinFragmentLength = 1
            };
            popupMenu.Items.SetAutocompleteItems(AutoCompleteStaticValues);
            popupMenu.Items.MaximumSize = new Size(300, 200);
            popupMenu.Items.Width       = 300;

            HASMSource source = new HASMSource(Parrent.Machine, TextBox.Text);

            TaskRunner = new ParseTaskRunner(source);

            Directory   = new FileInfo(path).Directory.FullName;
            DisplayName = path.Remove(0, path.LastIndexOf(PlatformSpecific.NameSeparator) + 1) + "  [x]";
            Text        = DisplayName;

            if (DisplayName.EndsWith(".cfg", true, CultureInfo.InvariantCulture))
            {
                TextBox.VisibleRangeChanged += (obj, args) =>
                {
                    TextBox.VisibleRange.ClearStyle(StyleIndex.All);
                    TextBox.SyntaxHighlighter.XMLSyntaxHighlight(TextBox.VisibleRange);
                    TextBox.SyntaxHighlighter.XmlTagNameStyle = TextBox.SyntaxHighlighter.BlueStyle;
                };
            }
            else
            {
                TextBox.SyntaxHighlighter.InitStyleSchema(Language.CSharp);
                TextBox.ToolTipDelay = 200;
                TextBox.ToolTip      = new ToolTip();
                TextBox.DelayedTextChangedInterval = 200;
                TextBox.ToolTipNeeded      += TextBox_ToolTipNeeded;
                TextBox.TextChangedDelayed += TextBox_TextChangedDelayed;
            }

            TextBox.TextChanged          += TextBox_TextChanged;
            TextBox.KeyDown              += TextBox_KeyDown;
            TextBox.HighlightingRangeType = HighlightingRangeType.ChangedRange;
            Path = path;

            Controls.Add(TextBox);
            toolStripLabel = Parrent.toolStripLabel1;
        }
示例#9
0
文件: Editor.cs 项目: Coestaris/hasm
        void ParsingEnd(ParseTaskRunner runner, HASMSource source)
        {
            if (InvokeRequired)
            {
                var del = new ParseTaskRunner.AsyncParseEndDelegate(ParsingEnd);
                Invoke(del, runner, source);
            }
            else
            {
                if (runner.Status == ParseTaskStatus.Failed)
                {
                    ParseError error = runner.Tasks[runner.FailedTaskIndex].Error;

                    error.Line++;
                    MessageBox.Show($"Task \"{runner.Tasks[runner.FailedTaskIndex].Name}\" failed\n{error.ToString()}", "Parsing error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    loadingCircle1.Visible        = false;
                    stopToolStripMenuItem.Enabled = false;
                    tabControl1.Enabled           = true;

                    if (error.FileName != null)
                    {
                        bool found = false;
                        foreach (TextEditor page in tabControl1.TabPages)
                        {
                            if (page.Path == error.FileName)
                            {
                                tabControl1.SelectedTab = page;
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            AddTab(error.FileName);
                        }

                        if (error.Line != -1)
                        {
                            TextEditor         tab = (tabControl1.SelectedTab as TextEditor);
                            FastColoredTextBox tb  = tab.TextBox;
                            var minLines           = 0;
                            var maxLines           = tb.LinesCount;
                            var max              = tb.VerticalScroll.Maximum;
                            var min              = tb.VerticalScroll.Minimum;
                            var currentLine      = error.Line;
                            var maxLinesInScreen = tb.Height / tb.Font.SizeInPoints;

                            if (tab.HighlightedLine != -1)
                            {
                                tb[tab.HighlightedLine].BackgroundBrush = Brushes.Transparent;
                                tab.HighlightedLine = -1;
                            }
                            tab.HighlightedLine = error.Line - 1;
                            tb[error.Line - 1].BackgroundBrush = Brushes.Pink;

                            if (maxLinesInScreen < maxLines)
                            {
                                currentLine = Math.Max(Math.Abs((int)(maxLinesInScreen / 2) - currentLine) + 1, 1);
                                int position = (int)((currentLine - minLines) * (max - min) / (float)(maxLines - minLines) + min);
                                tb.VerticalScroll.Value = position - 1;
                                tb.VerticalScroll.Value = position;
                            }
                        }
                    }
                }
                else
                {
                    IOStream stdOut = new IOStream("stdout", StreamDirection.Out);
                    IOStream stdIn  = new IOStream("stdin", StreamDirection.In);

                    var runtime = source.Machine.CreateRuntimeMachine(source, new List <IOStream>()
                    {
                        stdOut,
                        stdIn
                    });

                    runThread = new Thread(p =>
                    {
                        var result = runtime.Run();
                        if (result != null)
                        {
                            MessageBox.Show(result.ToString(), "Runtime error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        RunEnd(stdOut, runtime, source);
                    });

                    runThread.Start();
                }
            }
        }