Exemple #1
0
        private static void ShowNewVersionAvailable(Version version)
        {
            DialogAbout dialog = new DialogAbout();

            dialog.DownloadCompleted(version, null);
            App.Mainframe.ShowDialog(dialog);
        }
Exemple #2
0
 public static void CheckTranslationRequests(Dispatcher dispatcher)
 {
     try {
         string cultureName = App.CurrentCulture.Name;
         if (!cultureName.StartsWith("en", StringComparison.OrdinalIgnoreCase))
         {
             SettingsStringCache checkedVersion = DialogAbout.TranslationRequestVersion();
             if (!Version.TryParse(checkedVersion.Value, out Version version) || version < DialogAbout.CurrentVersion())
             {
                 string text = null;
                 using (WebClient client = new WebClient()) {
                     client.UseDefaultCredentials = true;
                     text = client.DownloadString(new Uri("https://www.LogicCircuit.org/TranslationRequests.txt"));
                 }
                 if (!string.IsNullOrWhiteSpace(text) && text.Contains(cultureName))
                 {
                     dispatcher.BeginInvoke(
                         new Action(() => App.Mainframe.InformationMessage(
                                        "If you can help translating this program to any language you are fluent in please contact me at:\n" +
                                        "<Hyperlink NavigateUri=\"https://www.logiccircuit.org/contact.html\">https://www.logiccircuit.org/contact.html</Hyperlink>"
                                        )),
                         DispatcherPriority.ApplicationIdle
                         );
                 }
                 checkedVersion.Value = DialogAbout.CurrentVersion().ToString();
             }
         }
     } catch (Exception exception) {
         Tracer.Report("DialogAbout.CheckTranslationRequests", exception);
         // ignore all exception here
     }
 }
        private void OkButtonClick(object sender, RoutedEventArgs e)
        {
            Settings.User.LoadLastFileOnStartup = this.loadLastFile.IsChecked.Value;
            Settings.User.MaxRecentFileCount    = (int)this.maxRecentFiles.SelectedItem;
            this.mainframe.AutoSaveInterval     = (this.autoSave.IsChecked.HasValue && this.autoSave.IsChecked.Value) ? this.AutoSaveInterval * 60 : 0;
            this.mainframe.ShowGrid             = this.showGrid.IsChecked.Value;
            Settings.User.GateShape             = ((EnumDescriptor <GateShape>) this.gateShape.SelectedItem).Value;
            App.CurrentCulture = this.CurrentCulture;

            if (Properties.Resources.Culture != this.CurrentCulture)
            {
                // Show message in both languages old and new.
                CultureInfo old        = Properties.Resources.Culture;
                string      oldMessage = Properties.Resources.MessageRestartRequared;
                Properties.Resources.Culture = this.CurrentCulture;
                string newMessage = Properties.Resources.MessageRestartRequared;
                Properties.Resources.Culture = old;
                if (oldMessage != newMessage)
                {
                    App.Mainframe.InformationMessage(oldMessage + "\n\n" + newMessage);
                }
                else
                {
                    App.Mainframe.InformationMessage(oldMessage);
                }
                // User changed culture, so recheck if there is a need for translation
                DialogAbout.ResetTranslationRequestVersion();
            }
            this.DialogResult = true;
            this.Close();
        }
Exemple #4
0
 public static void CheckVersion(Dispatcher dispatcher)
 {
     try {
         if (VersionChecker.NeedToCheck())
         {
             VersionChecker checker = new VersionChecker();
             checker.Check((version, error) => {
                 if (error == null && version != null && DialogAbout.CurrentVersion() < version)
                 {
                     dispatcher.BeginInvoke(
                         new Action(() => DialogAbout.ShowNewVersionAvailable(version)),
                         DispatcherPriority.ApplicationIdle
                         );
                 }
             });
         }
     } catch (Exception exception) {
         App.Mainframe.ReportException(exception);
     }
 }
Exemple #5
0
 public DialogAbout()
 {
     this.Version     = DialogAbout.CurrentVersion();
     this.DataContext = this;
     this.InitializeComponent();
 }
Exemple #6
0
        public static void ResetTranslationRequestVersion()
        {
            SettingsStringCache checkedVersion = DialogAbout.TranslationRequestVersion();

            checkedVersion.Value = null;
        }
        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
        }