public static MessageBoxResult Show(
            Window parent, string caption, string message, string details, MessageBoxImage image, MessageBoxButton button
            )
        {
            DialogMessage dialog = new DialogMessage();

            dialog.Caption          = caption ?? string.Empty;
            dialog.Message          = message ?? string.Empty;
            dialog.Details          = details ?? string.Empty;
            dialog.image            = image;
            dialog.MessageBoxButton = button;
            dialog.DataContext      = dialog;
            dialog.InitializeComponent();
            dialog.Owner = parent;
            dialog.ShowDialog();
            return(dialog.messageBoxResult);
        }
 private void ShowMessage(string message, string details, MessageBoxImage messageBoxImage)
 {
     if (!this.Dispatcher.CheckAccess())
     {
         this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,
                                     new Action <string, string, MessageBoxImage>(this.ShowMessage), message, details, messageBoxImage
                                     );
     }
     else
     {
         DialogMessage.Show(this,
                            Properties.Resources.MainFrameCaption(null), message, details, messageBoxImage, MessageBoxButton.OK
                            );
         if (this.Editor != null && this.Editor.Power && messageBoxImage == MessageBoxImage.Error)
         {
             this.Editor.Power = false;
         }
     }
 }
 private void OpenRecent(string file)
 {
     if (Mainframe.IsFilePathValid(file) && File.Exists(file))
     {
         if (this.Editor == null || this.EnsureSaved())
         {
             this.Edit(file);
         }
     }
     else if (file != null)
     {
         MessageBoxResult result = DialogMessage.Show(this, this.Title,
                                                      Properties.Resources.MessageInvalidRecentFile(file), null,
                                                      MessageBoxImage.Question, MessageBoxButton.YesNo
                                                      );
         if (result == MessageBoxResult.Yes)
         {
             Settings.User.DeleteRecentFile(file);
         }
     }
 }
Example #4
0
        private static CircuitProject Create(Mainframe mainframe, string file)
        {
            bool   useAutoSaveFile = false;
            string autoSaveFile    = Mainframe.AutoSaveFile(file);

            if (Mainframe.IsFileExists(autoSaveFile))
            {
                App.Dispatch(() => {
                    MessageBoxResult result = DialogMessage.Show(
                        mainframe,
                        Properties.Resources.TitleApplication,
                        Properties.Resources.MessageLoadAutoSavedFile(file),
                        null,
                        MessageBoxImage.Question,
                        MessageBoxButton.YesNo
                        );
                    if (result == MessageBoxResult.Yes)
                    {
                        useAutoSaveFile = true;
                    }
                });
                if (!useAutoSaveFile)
                {
                    Mainframe.DeleteFile(autoSaveFile);
                }
            }
            if (!useAutoSaveFile)
            {
                autoSaveFile = file;
            }
            CircuitProject project = CircuitProject.Create(autoSaveFile);

            if (useAutoSaveFile)
            {
                project.InOmitTransaction(() => {});
            }
            return(project);
        }
 private void ButtonOkClick(object sender, RoutedEventArgs e)
 {
     try {
         BindingExpression filePathBindingExpression = BindingOperations.GetBindingExpression(this.fileName, TextBox.TextProperty);
         filePathBindingExpression.UpdateSource();
         if (File.Exists(this.FilePath))
         {
             if (MessageBoxResult.No == DialogMessage.Show(this, this.Title, Properties.Resources.MessageImageFileExists(this.FilePath),
                                                           null, MessageBoxImage.Warning, MessageBoxButton.YesNo
                                                           ))
             {
                 return;
             }
         }
         if (!Mainframe.IsFilePathValid(this.FilePath))
         {
             DialogMessage.Show(this, this.Title,
                                Properties.Resources.ImagePathInvalid, null, MessageBoxImage.Error, MessageBoxButton.OK
                                );
             return;
         }
         RenderTargetBitmap bitmap = this.editor.ExportImage();
         Tracer.Assert(bitmap != null);
         using (FileStream stream = new FileStream(this.FilePath, FileMode.Create)) {
             BitmapEncoder encoder = this.Encoder.BitmapEncoder;
             encoder.Frames.Clear();
             encoder.Frames.Add(BitmapFrame.Create(bitmap));
             encoder.Save(stream);
         }
         this.imageExportType.Value   = this.Encoder.Name;
         this.imageExportFolder.Value = Path.GetDirectoryName(this.FilePath);
         e.Handled         = true;
         this.DialogResult = true;
     } catch (Exception exception) {
         App.Mainframe.ReportException(exception);
     }
 }
        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
        }