示例#1
0
        public MainWindowViewModel(Window window)
        {
            _window               = window;
            _grammarTextBox       = _window.Find <TextEditor>("GrammarTextBox");
            _textTextBox          = _window.Find <TextEditor>("TextTextBox");
            _grammarErrorsListBox = _window.Find <ListBox>("GrammarErrorsListBox");
            _textErrorsListBox    = _window.Find <ListBox>("TextErrorsListBox");
            _parseTreeTextBox     = _window.Find <TextEditor>("ParseTreeTextBox");
            _tokensTextBox        = _window.Find <TextEditor>("TokensTextBox");

            _grammarTextBox.SetupHightlighting(".g4");

            _settings = Settings.Load();

            _window.WindowState = _settings.WindowState;
            if (_settings.Width > 0)
            {
                _window.Width = _settings.Width;
            }
            if (_settings.Height > 0)
            {
                _window.Height = _settings.Height;
            }
            if (_settings.Left != -1 && _settings.Top != -1)
            {
                _window.Position = new PixelPoint(_settings.Left, _settings.Top);
            }

            Grammar grammar = null;

            bool   openDefaultGrammar = false;
            string packageName        = null;
            string root = null;

            if (string.IsNullOrEmpty(_settings.GrammarFileOrDirectory))
            {
                openDefaultGrammar = true;
            }
            else
            {
                try
                {
                    grammar = GrammarFactory.Open(_settings.GrammarFileOrDirectory, out packageName, out root);
                }
                catch (Exception ex)
                {
                    ShowOpenFileErrorMessage(_settings.GrammarFileOrDirectory, ex.Message);

                    _settings.OpenedGrammarFile = "";
                    openDefaultGrammar          = true;
                }
            }

            if (openDefaultGrammar)
            {
                grammar = GrammarFactory.CreateDefault();
                GrammarFactory.FillGrammarFiles(grammar, Settings.Directory, false);
                _settings.GrammarFileOrDirectory = grammar.Directory;
                _settings.Save();
            }

            _workflow       = new Workflow(grammar);
            SelectedRuntime = RuntimeInfo.InitOrGetRuntimeInfo(_workflow.Runtime);
            PackageName     = packageName;
            Root            = root;

            InitFiles();
            if (string.IsNullOrEmpty(_settings.OpenedGrammarFile) || !grammar.Files.Contains(_settings.OpenedGrammarFile))
            {
                OpenedGrammarFile = GrammarFiles.FirstOrDefault();
            }
            else
            {
                OpenedGrammarFile = _settings.OpenedGrammarFile;
            }

            if (string.IsNullOrEmpty(_settings.OpenedTextFile))
            {
                OpenedTextFile = TextFiles.Count > 0 ? TextFiles.First() : null;
            }
            else
            {
                OpenedTextFile = new FileName(_settings.OpenedTextFile);
            }

            SetupWindowSubscriptions();
            SetupWorkflowSubscriptions();
            SetupTextBoxSubscriptions();
            SetupCommandSubscriptions();

            AutoProcessing = _settings.Autoprocessing;
        }
示例#2
0
        public MainWindowViewModel(Window window)
        {
            _window               = window;
            _grammarTextBox       = _window.Find <TextEditor>("GrammarTextBox");
            _textTextBox          = _window.Find <TextEditor>("TextTextBox");
            _grammarErrorsListBox = _window.Find <ListBox>("GrammarErrorsListBox");
            _textErrorsListBox    = _window.Find <ListBox>("TextErrorsListBox");
            _parseTreeTextBox     = _window.Find <TextEditor>("ParseTreeTextBox");
            _tokensTextBox        = _window.Find <TextEditor>("TokensTextBox");

            _grammarTextBox.SetupHightlighting(".g4");

            _settings = Settings.Load();

            _window.WindowState = _settings.WindowState;
            if (_settings.Width > 0)
            {
                _window.Width = _settings.Width;
            }
            if (_settings.Height > 0)
            {
                _window.Height = _settings.Height;
            }
            if (_settings.Left > 0 && _settings.Top > 0)
            {
                _window.Position = new PixelPoint(_settings.Left, _settings.Top);
            }

            Grammar grammar = null;

            bool   openDefaultGrammar = false;
            string packageName        = null;
            string root = null;

            if (string.IsNullOrEmpty(_settings.GrammarFileOrDirectory))
            {
                openDefaultGrammar = true;
            }
            else
            {
                try
                {
                    grammar = GrammarFactory.Open(_settings.GrammarFileOrDirectory, out packageName, out root);
                }
                catch (Exception ex)
                {
                    ShowOpenFileErrorMessage(_settings.GrammarFileOrDirectory, ex.Message);

                    _settings.OpenedGrammarFile = "";
                    openDefaultGrammar          = true;
                }
            }

            if (openDefaultGrammar)
            {
                grammar = GrammarFactory.CreateDefault();
                GrammarFactory.FillGrammarFiles(grammar, Settings.Directory, false);
                _settings.GrammarFileOrDirectory = grammar.Directory;
                _settings.Save();
            }

            _workflow = new Workflow(grammar);

            var availableRuntimes = new[]
            {
                Runtime.Java, Runtime.CSharpStandard, Runtime.CSharpOptimized, Runtime.Python2, Runtime.Python3,
                Runtime.Go, Runtime.Php
            };

            _runtimeInfoWrappers = new Dictionary <Runtime, RuntimeInfoWrapper>();

            foreach (Runtime runtime in availableRuntimes)
            {
                _runtimeInfoWrappers.Add(runtime, new RuntimeInfoWrapper(RuntimeInfo.InitOrGetRuntimeInfo(runtime)));
            }

            var list = new List <RuntimeInfoWrapper> {
                AutodetectRuntime
            };

            list.AddRange(_runtimeInfoWrappers.Values);

            Runtimes = new ObservableCollection <RuntimeInfoWrapper>(list);

            SelectedRuntime = GetAutoOrSelectedRuntime();
            PackageName     = packageName;
            Root            = root;

            InitFiles();
            if (string.IsNullOrEmpty(_settings.OpenedGrammarFile) || !grammar.Files.Contains(_settings.OpenedGrammarFile))
            {
                OpenedGrammarFile = GrammarFiles.FirstOrDefault();
            }
            else
            {
                OpenedGrammarFile = _settings.OpenedGrammarFile;
            }

            if (string.IsNullOrEmpty(_settings.OpenedTextFile))
            {
                OpenedTextFile = TextFiles.Count > 0 ? TextFiles.First() : null;
            }
            else
            {
                OpenedTextFile = new FileName(_settings.OpenedTextFile);
            }

            SetupWindowSubscriptions();
            SetupWorkflowSubscriptions();
            SetupTextBoxSubscriptions();
            SetupCommandSubscriptions();

            AutoProcessing = _settings.Autoprocessing;
        }