コード例 #1
0
        internal static void Run(Window parent, string script)
        {
            IronPythonConsole.Run(parent);
            IronPythonConsole console = IronPythonConsole.currentConsole;

            if (console != null)
            {
                console.writer.WriteLine(script);
                console.Execute(script);
            }
        }
コード例 #2
0
        public Mainframe()
        {
            App.Mainframe     = this;
            this.ProjectWidth = new SettingsGridLengthCache(Settings.User, "Mainframe.ProjectWidth", "0.25*");
            this.DiagramWidth = new SettingsGridLengthCache(Settings.User, "Mainframe.DiagramWidth", "0.75*");

            // Create this command here as it used multiple times not like all other commands only onces when menu is created.
            this.CommandOpenRecent = new LambdaUICommand(Properties.Resources.CommandFileOpenRecent, file => this.OpenRecent(file as string));

            this.DataContext = this;
            this.InitializeComponent();

            this.autoSaveTimer = new Timer(o => this.Editor?.AutoSave(), null, Timeout.Infinite, Timeout.Infinite);

            Thread thread = new Thread(new ThreadStart(() => {
                try {
                    string file = App.CurrentApp.FileToOpen;
                    if (string.IsNullOrEmpty(file) || !File.Exists(file))
                    {
                        if (Settings.User.LoadLastFileOnStartup)
                        {
                            file = Settings.User.RecentFile();
                        }
                    }
                    if (!string.IsNullOrEmpty(file) && File.Exists(file))
                    {
                        this.Edit(file);
                    }
                    else
                    {
                        this.Edit(null);
                    }
                    if (!string.IsNullOrEmpty(App.CurrentApp.CommandLineErrors))
                    {
                        this.ShowErrorMessage(App.CurrentApp.CommandLineErrors, null);
                    }
                    else if (!string.IsNullOrEmpty(App.CurrentApp.ScriptToRun))
                    {
                        this.Dispatcher.BeginInvoke(new Action(() => IronPythonConsole.Run(this, App.CurrentApp.ScriptToRun)));
                    }
                    else
                    {
                        // Reuse this thread to check if there are any translations requests are pending
                        DialogAbout.CheckTranslationRequests(this.Dispatcher);
                    }
                } catch (Exception exception) {
                    Tracer.Report("Mainframe.PostLoaded", exception);
                    this.ReportException(exception);
                    this.Edit(null);
                }
            }));

            //TextNote validator will instantiate FlowDocument that in some cases required to happened only on STA.
            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Name         = "ProjectLoader";
            thread.Priority     = ThreadPriority.AboveNormal;
            thread.Start();

            // Check for new available version
            Thread versionThread = new Thread(new ThreadStart(() => DialogAbout.CheckVersion(this.Dispatcher)))
            {
                IsBackground = true,
                Name         = "CheckVersion",
                Priority     = ThreadPriority.BelowNormal
            };

            versionThread.Start();

                        #if DEBUG && false
            this.Loaded += (object sender, RoutedEventArgs e) => {
                Menu   menu = (Menu)((Grid)this.Content).Children[0];
                string text = "Test";
                menu.Items.Add(new MenuItem()
                {
                    Header = text, Command = new LambdaUICommand(text, o => {
                        DialogMessage.Show(this,
                                           "hello",
                                           "world <Hyperlink NavigateUri=\"http://www.rbc.ru\">link 1</Hyperlink> or <Hyperlink NavigateUri=\"http://www.lenta.ru\">link 2</Hyperlink> hello <Hyperlink NavigateUri=\"http://www.cnn.com\">and link 3</Hyperlink> end",
                                           "details",
                                           MessageBoxImage.Error,
                                           MessageBoxButton.OKCancel
                                           );
                    })
                });
            };
                        #endif
        }