예제 #1
0
        public void Load(string path, Project project, PleasantTabItem pleasantTabItem, Editor editor)
        {
            S3PEViewModel viewModel = path != null
                                ? new S3PEViewModel(pleasantTabItem, editor, this, path, project)
                                : new S3PEViewModel(pleasantTabItem, editor, this);

            _viewModel = viewModel;

            DataContext = _viewModel;

            _viewModel.S3Pe = this;
        }
예제 #2
0
        public MainWindow()
        {
            AvaloniaXamlLoader.Load(this);

            this.AttachDevTools();

            MainViewModel viewModel = new MainViewModel();

            DataContext = viewModel;

            viewModel.NotificationManager = new WindowNotificationManager(this)
            {
                Position = NotificationPosition.TopRight,
                MaxItems = 3,
                ZIndex   = 1
            };

#if DEBUG
            KeyDown += (s, e) =>
            {
                if (e.Key == Key.LeftShift)
                {
                    _canGetAnException = true;
                }
                else
                {
                    _canGetAnException = false;
                }
            };
#endif

            TemplateApplied += (s, e) => this.GetDataContext <MainViewModel>().Initialize();
            Closing         += async(s, e) =>
            {
                e.Cancel = true;

                if (!_closing && !CancelClose)
                {
                    GeneralSettings.Save();
                    PleasantSettings.Save();

                    for (int i = 0; i < viewModel.TabItems.Count; i++)
                    {
                        PleasantTabItem tabItem = viewModel.TabItems[i];
                        if (!tabItem.IsEditedIndicator)
                        {
                            continue;
                        }

                        viewModel.SelectedTab = tabItem;
                        SavedResult result = await viewModel.SaveFile(tabItem, true);

                        if (result == SavedResult.Cancel)
                        {
                            return;
                        }
                    }

                    for (int i1 = 0; i1 < ModuleManager.System.Modules.Count; i1++)
                    {
                        ModuleManager.System.Modules[i1].Release();
                    }

                    _closing = true;

#if DEBUG
                    if (_canGetAnException)
                    {
                        throw new System.Exception("Debug exception");
                    }
#endif

                    Close();
                }
                else
                {
                    e.Cancel = false;
                }
            };

            WindowsManager.OtherModalWindows.CollectionChanged += OtherModalWindows_CollectionChanged;
        }