コード例 #1
0
        private void bSetBG_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofdOpen = new OpenFileDialog();

            ofdOpen.Filter = "Known Image Formats (*.png, *.jpg, *.jpeg, *.bmp)|*.png;*.jpg;*.jpeg;*.bmp";
            if (ofdOpen.ShowDialog() == true)
            {
                try
                {
                    imgBG.Source = new BitmapImage(new Uri(ofdOpen.FileName));
                    filePathBG   = ofdOpen.FileName;
                    rbThemeAdaptive.IsEnabled = true;
                    if (rbThemeAdaptive.IsChecked == false)
                    {
                        frameAdaptiveWarning.Visibility = Visibility.Visible;
                    }
                }
                catch (Exception ex)
                {
                    messageBox = new customMessageBox();
                    messageBox.SetupMsgBox(ex.Message + "\nYour image may be corrupt.", "Error!", this.FindResource("iconError"));
                    messageBox.ShowDialog();
                }
            }
        }
コード例 #2
0
 private void miError_Click(object sender, RoutedEventArgs e)
 {
     messageBox = new customMessageBox();
     messageBox.SetupMsgBox("A user-initiated error has occured." + errorPreset, "Error!", this.FindResource("iconError"), "OK", "Cancel", "I'm special!");
     messageBox.ShowDialog();
     if (messageBox.result.ToString() == "Button3")
     {
         Console.WriteLine("Selected 3");
     }
 }
コード例 #3
0
        public settings()
        {
            InitializeComponent();
            cbDoLogging.IsChecked  = Properties.Settings.Default.doLogging;
            cbDeleteLogs.IsChecked = Properties.Settings.Default.autoDeleteLogs;
            cbAutosave.IsChecked   = Properties.Settings.Default.doAutosave;
            cbDelaySpellcheckExecution.IsChecked = Properties.Settings.Default.delaySpellcheckExecution;
            logStoreDays             = Properties.Settings.Default.autoDeleteLogsDays;
            spellcheckExecutionDelay = Properties.Settings.Default.spellcheckExecutionDelay;
            autosaveInterval         = Properties.Settings.Default.autosaveInterval;
            switch (Properties.Settings.Default.themeName)
            {
            case "white":
                rbThemeWhite.IsChecked = true;
                break;

            case "blue":
                rbThemeBlue.IsChecked = true;
                break;

            case "green":
                rbThemeGreen.IsChecked = true;
                break;
            }
            filePathBG = Properties.Settings.Default.themeBG;
            if (filePathBG != "" && filePathBG != null)
            {
                try
                {
                    imgBG.Source = new BitmapImage(new Uri(filePathBG));
                    rbThemeAdaptive.IsEnabled = true;
                }
                catch (Exception ex)
                {
                    messageBox = new customMessageBox();
                    messageBox.SetupMsgBox(ex.Message + "\nYour background image may be corrupt.", "Error!", this.FindResource("iconError"));
                    messageBox.ShowDialog();
                }
            }
            if (Properties.Settings.Default.themeName == "adaptive" && rbThemeAdaptive.IsEnabled)
            {
                rbThemeAdaptive.IsChecked = true;
            }
            else if (Properties.Settings.Default.themeName == "adaptive" && !rbThemeAdaptive.IsEnabled)
            {
                rbThemeBlue.IsChecked = true;
            }
            if (filePathBG != "" && Properties.Settings.Default.themeName != "adaptive")
            {
                frameAdaptiveWarning.Visibility = Visibility.Visible;
            }
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        private void anySaveAs_Click(object sender, RoutedEventArgs e)
        {
            Nullable <bool> result = sfdSave.ShowDialog();

            if (result == true)
            {
                nwDebug.nwLog("Saving from Save.", nwDebug.Severity.Info, logFile);
                try
                {
                    saveDocument(sfdSave.FileName, rtbMain);
                }
                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);
                }
            }
        }
コード例 #6
0
 private void anySave_Click(object sender, RoutedEventArgs e)
 {
     if (currentlyOpenPath == null)
     {
         anySaveAs_Click(sender, e);
     }
     else
     {
         try
         {
             saveDocument(currentlyOpenPath, rtbMain);
         }
         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);
         }
     }
 }
コード例 #7
0
 public void openDocument(string filePath)
 {
     try
     {
         string fileExtension = System.IO.Path.GetExtension(filePath);
         if (fileExtension != ".rtf" && fileExtension != ".txt")
         {
             //rtbMain.Rtf = new FileStream(filePath, FileMode.Open);
             rtbMain.LoadFile(filePath, System.Windows.Forms.RichTextBoxStreamType.PlainText);
             currentlyOpenFile = filePath;
             return;
         }
         rtbMain.LoadFile(filePath);
         currentlyOpenFile = filePath;
     }
     catch (Exception ex)
     {
         messageBox = new customMessageBox();
         messageBox.SetupMsgBox(ex.Message, "Error!");
         messageBox.ShowDialog();
     }
 }
コード例 #8
0
        private void bFindReplace_Click(object sender, RoutedEventArgs e)
        {
            var         content     = frameSidebar.Content as Page;
            var         grid        = content.Content as Grid;
            TextBox     tbFind      = (TextBox)grid.Children[2];
            TextBox     tbReplace   = (TextBox)grid.Children[4];
            var         expander    = (Expander)grid.Children[9];
            CheckBox    cbMatchCase = (CheckBox)((Grid)expander.Content).Children[0];
            CheckBox    cbMatchWord = (CheckBox)((Grid)expander.Content).Children[1];
            TextRange   textRange   = null;
            FindOptions findOptions = FindOptions.None;

            if (cbMatchCase.IsChecked == true)
            {
                findOptions = FindOptions.MatchCase;
            }
            if (cbMatchWord.IsChecked == true)
            {
                findOptions ^= FindOptions.MatchWholeWord;
            }
            if (findReplaceChanges)
            {
                findAndReplace     = new FindAndReplaceManager(rtbMain.Document);
                findReplaceChanges = false;
            }
            switch (((Button)sender).Content.ToString())
            {
            case "Find Next":
                textRange = findAndReplace.FindNext(tbFind.Text, findOptions);
                break;

            case "Replace All":
                int results = findAndReplace.ReplaceAll(tbFind.Text, tbReplace.Text, findOptions, null);
                customMessageBox customMessageBox = new customMessageBox();
                customMessageBox.SetupMsgBox($"Replaced {results} occurences.", "Replace All", this.FindResource("iconInformation"));
                customMessageBox.ShowDialog();
                rtbMain.Focus();
                return;

            case "Replace Next":
                textRange = findAndReplace.Replace(tbFind.Text, tbReplace.Text, findOptions);
                break;

            case "Count":
                RichTextBox rtbTemp = XamlReader.Parse(XamlWriter.Save(rtbMain)) as RichTextBox;
                findAndReplace = new FindAndReplaceManager(rtbTemp.Document);
                int count = findAndReplace.ReplaceAll(tbFind.Text, "", findOptions, null);
                customMessageBox customMessageBox2 = new customMessageBox();
                customMessageBox2.SetupMsgBox($"\"{tbFind.Text}\" appeared {count} times.", "Count", this.FindResource("iconInformation"));
                customMessageBox2.ShowDialog();
                findReplaceChanges = true;
                return;

            default:
                break;
            }

            if (textRange == null)
            {
                customMessageBox customMessageBox = new customMessageBox();
                customMessageBox.SetupMsgBox("No (more) results.\nDo you wish to start at the top again?", "Reset search?", this.FindResource("iconInformation"), "Yes", "No");
                customMessageBox.ShowDialog();
                if (customMessageBox.result.ToString() == "Yes")
                {
                    findAndReplace     = new FindAndReplaceManager(rtbMain.Document);
                    findReplaceChanges = false;
                    textRange          = findAndReplace.FindNext(tbFind.Text, findOptions);
                    if (textRange == null)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            rtbMain.Selection.Select(textRange.Start, textRange.End);
            rtbMain.Focus();
        }
コード例 #9
0
        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;
        }
コード例 #10
0
        private void applySettings()
        {
            string        filePath      = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            DirectoryInfo directoryInfo = new DirectoryInfo(filePath);

            if (Properties.Settings.Default.doLogging)
            {
                logFile = filePath + "\\log" + DateTime.UtcNow.ToString().Replace(' ', '_').Replace('/', '-').Replace(':', '-') + ".nwlog";
            }
            else
            {
                logFile = null;
            }

            if (Properties.Settings.Default.autoDeleteLogs)
            {
                //Delete all logs older than autoDeleteLogsDays days
                foreach (var file in directoryInfo.GetFiles("*.nwlog"))
                {
                    if (file.CreationTimeUtc < DateTime.UtcNow.AddDays(-Properties.Settings.Default.autoDeleteLogsDays))
                    {
                        file.Delete();
                    }
                }
            }

            //Delete all logs older than 2 days
            foreach (var file in directoryInfo.GetFiles("autosave*.xml"))
            {
                if (file.CreationTimeUtc < DateTime.UtcNow.AddDays(-2))
                {
                    file.Delete();
                }
            }

            //Apply skins
            IEnumerable <Control> skinables = FindVisualChildren <Control>(gridMain).Where(x => x.Tag != null && x.Tag.ToString() == "skinable");

            switch (Properties.Settings.Default.themeName)
            {
            case "white":
                foreach (Control control in skinables)
                {
                    control.Background = (Brush)this.FindResource("colorWhiteBG");
                }
                tbtrayTop.Background = (Brush)this.FindResource("colorWhiteBG");
                break;

            case "blue":
                foreach (Control control in skinables)
                {
                    control.Background = (Brush)this.FindResource("colorBlueBG");
                }
                tbtrayTop.Background = (Brush)this.FindResource("colorBlueBG");
                break;

            case "green":
                foreach (Control control in skinables)
                {
                    control.Background = (Brush)this.FindResource("colorGreenBG");
                }
                tbtrayTop.Background = (Brush)this.FindResource("colorGreenBG");
                break;

            case "adaptive":
                try
                {
                    ImageBrush imgBG = new ImageBrush(new BitmapImage(new Uri(Properties.Settings.Default.themeBG)));
                    imgBG.Stretch        = Stretch.UniformToFill;
                    tbtrayTop.Background = imgBG;
                    System.Drawing.Color avgColor = getAverageColor((System.Drawing.Bitmap)System.Drawing.Image.FromFile(Properties.Settings.Default.themeBG));
                    SolidColorBrush      bgBrush  = new SolidColorBrush(Color.FromRgb(avgColor.R, avgColor.G, avgColor.B));
                    foreach (Control control in skinables)
                    {
                        control.Background = bgBrush;
                    }
                }
                catch (Exception ex)
                {
                    messageBox = new customMessageBox();
                    messageBox.SetupMsgBox(ex.Message + errorPreset + "\nTheme will be reset to Blue.", "Error!", this.FindResource("iconError"));
                    messageBox.ShowDialog();
                    nwDebug.nwLog("Exception " + ex.Message, nwDebug.Severity.Error, logFile);
                    Properties.Settings.Default.themeName = "blue";
                    Properties.Settings.Default.Save();
                }
                break;
            }

            spellcheckTimer.Interval = Properties.Settings.Default.spellcheckExecutionDelay;
            delaySpellcheckExecution = Properties.Settings.Default.delaySpellcheckExecution;
            timerAutosave.Interval   = Properties.Settings.Default.autosaveInterval;
            timerAutosave.Enabled    = Properties.Settings.Default.doAutosave;

            //Add Keyboard Shortcuts
            RoutedCommand commandNew = new RoutedCommand();

            commandNew.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(commandNew, anyNew_Click));
            RoutedCommand commandOpen = new RoutedCommand();

            commandOpen.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(commandOpen, anyOpen_Click));
            RoutedCommand commandSave = new RoutedCommand();

            commandSave.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(commandSave, anySave_Click));
            RoutedCommand commandSaveAs = new RoutedCommand();

            commandSaveAs.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control ^ ModifierKeys.Shift));
            CommandBindings.Add(new CommandBinding(commandSaveAs, anySaveAs_Click));
            RoutedCommand commandFindReplace = new RoutedCommand();

            commandFindReplace.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
            CommandBindings.Add(new CommandBinding(commandFindReplace, miFindReplace_Click));
        }
コード例 #11
0
        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;
        }