Exemple #1
0
        public void FileOpen()
        {
            var path = _ioService.OpenFileDialog();

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            EditorTabViewModel tab;

            if (Items.SingleOrDefault(t => t.FullPath.Equals(path, StringComparison.OrdinalIgnoreCase)) is EditorTabViewModel item)
            {
                tab = item;
            }
            else
            {
                _logger.LogInformation("Opening file '{fullPath}'", path);

                var sw = Stopwatch.StartNew();

                var textReader = _ioService.OpenTextFile(path);

                tab          = _editorTabFactory();
                tab.FullPath = path;
                tab.Map      = _mapFactory.FromText(textReader);
                _logger.LogInformation("{action} took {ms} ms", "Opening", sw.ElapsedMilliseconds);

                Items.Add(tab);

                if (Items.Count == 1)
                {
                    NotifyOfPropertyChange(nameof(HasOpenTabs));
                }
            }

            ActivateItem(tab);
        }