private void miPerformanceMode_Click(object sender, RoutedEventArgs e)
        {
            performanceMode performanceMode = new performanceMode();

            performanceMode.Show();
            nwDebug.nwLog("Show Performance Mode.", nwDebug.Severity.Info, logFile);
        }
        private void anyOpen_Click(object sender, RoutedEventArgs e)
        {
            Nullable <bool> result = ofdOpen.ShowDialog();

            if (result == true)
            {
                nwDebug.nwLog("Opening from Open.", nwDebug.Severity.Info, logFile);
                try
                {
                    long length = new FileInfo(ofdOpen.FileName).Length;
                    if (length > performanceModeMinSize)
                    {
                        nwDebug.nwLog("File is above performance treshold.", nwDebug.Severity.Info, logFile);
                        messageBox = new customMessageBox();
                        messageBox.SetupMsgBox("Opening this file may cause performance issues. Do you wish to open it using Performance Mode?", "Performance Mode", this.FindResource("iconWarning"), "Yes", "No", "Cancel");
                        messageBox.ShowDialog();
                        switch (messageBox.result.ToString())
                        {
                        case "Yes":
                            nwDebug.nwLog("Attempting to open file in Performance Mode.", nwDebug.Severity.Info, logFile);
                            performanceMode performanceMode = new performanceMode();
                            performanceMode.openDocument(ofdOpen.FileName);
                            performanceMode.Show();
                            return;

                        case "No":
                            break;

                        case "Cancel":
                            return;
                        }
                    }
                    openDocument(ofdOpen.FileName, rtbMain);
                    currentlyOpenPath = ofdOpen.FileName;
                }
                catch (Exception ex)
                {
                    messageBox = new customMessageBox();
                    messageBox.SetupMsgBox(ex.Message + errorPreset, "Error!", this.FindResource("iconError"));
                    messageBox.ShowDialog();
                    nwDebug.nwLog("Exception " + ex.Message, nwDebug.Severity.Error, logFile);
                }
            }
        }
        public MainWindow()
        {
            // Initialize
            InitializeComponent();
            applySettings();
            //logFile = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            nwDebug.nwLog("NoteyWrite started.", nwDebug.Severity.Info, logFile);
            arguments = getArguments();
            if (arguments.Length > 1)
            {
                nwDebug.nwLog("Opening from argument.", nwDebug.Severity.Info, logFile);
                if (File.Exists(arguments[1]))
                {
                    nwDebug.nwLog("Argument file exists.", nwDebug.Severity.Info, logFile);
                    try
                    {
                        long length = new FileInfo(arguments[1]).Length;
                        if (length > performanceModeMinSize)
                        {
                            nwDebug.nwLog("File is above performance treshold.", nwDebug.Severity.Info, logFile);
                            messageBox = new customMessageBox();
                            messageBox.SetupMsgBox("Opening this file may cause performance issues. Do you wish to open it using Performance Mode?", "Performance Mode", this.FindResource("iconWarning"), "Yes", "No", "Cancel");
                            messageBox.ShowDialog();
                            switch (messageBox.result.ToString())
                            {
                            case "Yes":
                                nwDebug.nwLog("Attempting to open file in Performance Mode.", nwDebug.Severity.Info, logFile);
                                performanceMode performanceMode = new performanceMode();
                                performanceMode.openDocument(arguments[1]);
                                performanceMode.Show();
                                return;

                            case "No":
                                break;

                            case "Cancel":
                                return;
                            }
                        }
                        openDocument(arguments[1], rtbMain);
                        currentlyOpenPath = arguments[1];
                    }
                    catch (Exception ex)
                    {
                        nwDebug.nwLog("Exception " + ex.Message, nwDebug.Severity.Error, logFile);
                        messageBox = new customMessageBox();
                        messageBox.SetupMsgBox(ex.Message + errorPreset, "Error!", this.FindResource("iconError"));
                        messageBox.ShowDialog();
                    }
                }
            }

            mainWindow.Title = "NoteyWriteWPF " + currentVersion;
            sfdSave.Filter   = "XML Document (*.xml)|*.xml|Rich Text File (*.rtf)|*.rtf|Plain Text File (*.txt)|*.txt|All files (*.*)|*.*";
            sfdSave.Title    = "Save a document | NoteyWriteWPF";
            ofdOpen.Filter   = "Known Documents (*.xml, *.rtf, *.txt)|*.xml;*.rtf;*.txt|XML Document (*.xml)|*.xml|Rich Text File (*.rtf)|*.rtf|Plain Text File (*.txt)|*.txt|All files (*.*)|*.*";
            ofdOpen.Title    = "Open a document | NoteyWriteWPF";
            ofdImage.Filter  = "Known Image Formats (*.png, *.jpg, *.jpeg, *.bmp)|*.png;*.jpg;*.jpeg;*.bmp";
            ofdImage.Title   = "Open an image | NoteyWrite";

            //List<string> fonts = new List<string>();
            foreach (System.Drawing.FontFamily font in System.Drawing.FontFamily.Families)
            {
                //fonts.Add(font.Name);
                cbFont.Items.Add(new ComboBoxItem()
                {
                    Content = font.Name, FontFamily = new FontFamily(font.Name)
                });
            }
            nwDebug.nwLog("Added all fonts.", nwDebug.Severity.Info, logFile);

            //cbFont.ItemsSource = fonts;
            cbFontSize.ItemsSource = new List <Double>()
            {
                8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 102, 144, 288
            };

            //Override the default RichTextBox Events
            rtbMain.AddHandler(RichTextBox.DragOverEvent, new DragEventHandler(rtbMain_DragOver), true);
            rtbMain.AddHandler(RichTextBox.DropEvent, new DragEventHandler(rtbMain_Drop), true);
            rtbMain.AddHandler(RichTextBox.DragEnterEvent, new DragEventHandler(rtbMain_DragEnter), true);
            rtbMain.AddHandler(RichTextBox.DragLeaveEvent, new DragEventHandler(rtbMain_DragLeave), true);

            spellcheckTimer.Tick += SpellcheckTimer_Tick;
            timerAutosave.Tick   += timerAutosave_Click;
        }
        private void rtbMain_Drop(object sender, DragEventArgs e)
        {
            //Make sure the Drop event doesn't trigger twice, very hacky solution since nothing else worked
            if (!canDrop)
            {
                canDrop = true;
                return;
            }
            canDrop = false;
            //Check if the dropped data is a file to not override the existing functionality
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                nwDebug.nwLog("Opening from DragDrop.", nwDebug.Severity.Info, logFile);
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                animate(new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0.25))), new PropertyPath(RichTextBox.OpacityProperty), animationStoryboard, canvasDragDrop.Name);
                //Until multiple documents can be opened, only open the first one
                try
                {
                    if (Path.GetExtension(files[0]) == ".jpg" || Path.GetExtension(files[0]) == ".png")
                    {
                        insertImage = new Image()
                        {
                            Source = new BitmapImage(new Uri(files[0])), Stretch = Stretch.Uniform, Width = rtbMain.ActualWidth - 50
                        };
                        insertImageUIContainer = new BlockUIContainer(insertImage);
                        rtbMain.Document.Blocks.Add(insertImageUIContainer);
                        return;
                    }
                    long length = new FileInfo(files[0]).Length;
                    if (length > performanceModeMinSize)
                    {
                        nwDebug.nwLog("File is above performance treshold.", nwDebug.Severity.Info, logFile);
                        messageBox = new customMessageBox();
                        messageBox.SetupMsgBox("Opening this file may cause performance issues. Do you wish to open it using Performance Mode?", "Performance Mode", this.FindResource("iconWarning"), "Yes", "No", "Cancel");
                        messageBox.ShowDialog();
                        switch (messageBox.result.ToString())
                        {
                        case "Yes":
                            nwDebug.nwLog("Attempting to open file in Performance Mode.", nwDebug.Severity.Info, logFile);
                            performanceMode performanceMode = new performanceMode();
                            performanceMode.openDocument(files[0]);
                            performanceMode.Show();
                            return;

                        case "No":
                            break;

                        case "Cancel":
                            return;

                        default:
                            nwDebug.nwLog("Unknown result returned.", nwDebug.Severity.Warning, logFile);
                            return;
                        }
                    }
                    openDocument(files[0], rtbMain);
                    currentlyOpenPath = files[0];
                }
                catch (Exception ex)
                {
                    messageBox = new customMessageBox();
                    messageBox.SetupMsgBox(ex.Message + errorPreset, "Error!", this.FindResource("iconError"));
                    messageBox.ShowDialog();
                    nwDebug.nwLog("Exception " + ex.Message, nwDebug.Severity.Error, logFile);
                }
            }
            e.Handled = true;
        }