Exemplo n.º 1
0
        private bool saveGeneral(ref _ChangesAction result, ref bool changeDockSize)
        {
            try
            {
                var applyAutoHeight = false;
                if (PNStatic.Settings.GeneralSettings.Language != _TempSettings.GeneralSettings.Language)
                {
                    PNStatic.FormMain.ApplyNewLanguage(_TempSettings.GeneralSettings.Language);
                }
                if (PNStatic.Settings.GeneralSettings.UseSkins != _TempSettings.GeneralSettings.UseSkins)
                {
                    //apply or remove skins
                    PNStatic.Settings.GeneralSettings.UseSkins = _TempSettings.GeneralSettings.UseSkins;
                    result |= _ChangesAction.SkinsReload;
                }
                // hide toolbar
                if (PNStatic.Settings.GeneralSettings.HideToolbar != _TempSettings.GeneralSettings.HideToolbar &&
                    _TempSettings.GeneralSettings.HideToolbar)
                {
                    PNNotesOperations.ApplyHideToolbar();
                }
                // hide or show delete button
                if (PNStatic.Settings.GeneralSettings.HideDeleteButton !=
                    _TempSettings.GeneralSettings.HideDeleteButton)
                {
                    PNNotesOperations.ApplyDeleteButtonVisibility(!_TempSettings.GeneralSettings.HideDeleteButton);
                }
                // change hide to delete
                if (PNStatic.Settings.GeneralSettings.ChangeHideToDelete !=
                    _TempSettings.GeneralSettings.ChangeHideToDelete)
                {
                    PNNotesOperations.ApplyUseAlternative(_TempSettings.GeneralSettings.ChangeHideToDelete);
                }
                // hide or show hide button
                if (PNStatic.Settings.GeneralSettings.HideHideButton !=
                    _TempSettings.GeneralSettings.HideHideButton)
                {
                    PNNotesOperations.ApplyHideButtonVisibility(!_TempSettings.GeneralSettings.HideHideButton);
                }
                // scroll bars
                if (PNStatic.Settings.GeneralSettings.ShowScrollbar !=
                    _TempSettings.GeneralSettings.ShowScrollbar)
                {
                    if (_TempSettings.GeneralSettings.ShowScrollbar == System.Windows.Forms.RichTextBoxScrollBars.None)
                        PNNotesOperations.ApplyShowScrollBars(_TempSettings.GeneralSettings.ShowScrollbar);
                    else
                    {
                        if (!_TempSettings.GeneralSettings.AutoHeight)
                            PNNotesOperations.ApplyShowScrollBars(_TempSettings.GeneralSettings.ShowScrollbar);
                    }
                }
                // auto height
                if (PNStatic.Settings.GeneralSettings.AutoHeight != _TempSettings.GeneralSettings.AutoHeight)
                {
                    // auto height after
                    if (_TempSettings.GeneralSettings.AutoHeight)
                    {
                        // scroll bars after (and may be before)
                        if (_TempSettings.GeneralSettings.ShowScrollbar != System.Windows.Forms.RichTextBoxScrollBars.None)
                        {
                            // remove scroll bars
                            PNNotesOperations.ApplyShowScrollBars(System.Windows.Forms.RichTextBoxScrollBars.None);
                        }
                        // apply auto height
                        applyAutoHeight = true;
                    }
                    else
                    {
                        // scroll bars after (and may be before)
                        if (_TempSettings.GeneralSettings.ShowScrollbar != System.Windows.Forms.RichTextBoxScrollBars.None)
                        {
                            // restore scroll bars
                            PNNotesOperations.ApplyShowScrollBars(_TempSettings.GeneralSettings.ShowScrollbar);
                        }
                    }
                }
                // buttons size
                if (PNStatic.Settings.GeneralSettings.ButtonsSize != _TempSettings.GeneralSettings.ButtonsSize)
                {
                    PNNotesOperations.ApplyButtonsSize(_TempSettings.GeneralSettings.ButtonsSize);
                }
                // custom fonts
                if (PNStatic.Settings.GeneralSettings.UseCustomFonts !=
                    _TempSettings.GeneralSettings.UseCustomFonts)
                {
                    if (_TempSettings.GeneralSettings.UseCustomFonts)
                    {
                        PNInterop.AddCustomFonts();
                    }
                    else
                    {
                        PNInterop.RemoveCustomFonts();
                    }
                }
                // margins
                if (PNStatic.Settings.GeneralSettings.MarginWidth != _TempSettings.GeneralSettings.MarginWidth)
                {
                    if (!PNStatic.Settings.GeneralSettings.UseSkins)
                    {
                        PNNotesOperations.ApplyMarginsWidth(_TempSettings.GeneralSettings.MarginWidth);
                    }
                }
                // docked notes width and/or height
                if (PNStatic.Settings.GeneralSettings.DockWidth != _TempSettings.GeneralSettings.DockWidth ||
                    PNStatic.Settings.GeneralSettings.DockHeight != _TempSettings.GeneralSettings.DockHeight)
                {
                    changeDockSize = true;
                }
                // spell check color
                if (PNStatic.Settings.GeneralSettings.SpellColor != _TempSettings.GeneralSettings.SpellColor)
                {
                    if (Spellchecking.Initialized)
                    {
                        Spellchecking.ColorUnderlining = _TempSettings.GeneralSettings.SpellColor;
                        PNNotesOperations.ApplySpellColor();
                    }
                }
                // autosave
                if (PNStatic.Settings.GeneralSettings.Autosave != _TempSettings.GeneralSettings.Autosave)
                {
                    if (_TempSettings.GeneralSettings.Autosave)
                    {
                        PNStatic.FormMain.TimerAutosave.Interval =
                            _TempSettings.GeneralSettings.AutosavePeriod * 60000;
                        PNStatic.FormMain.TimerAutosave.Start();
                    }
                    else
                    {
                        PNStatic.FormMain.TimerAutosave.Stop();
                    }
                }
                else
                {
                    if (PNStatic.Settings.GeneralSettings.AutosavePeriod !=
                        _TempSettings.GeneralSettings.AutosavePeriod)
                    {
                        if (PNStatic.Settings.GeneralSettings.Autosave)
                        {
                            PNStatic.FormMain.TimerAutosave.Stop();
                            PNStatic.FormMain.TimerAutosave.Interval =
                                _TempSettings.GeneralSettings.AutosavePeriod * 60000;
                            PNStatic.FormMain.TimerAutosave.Start();
                        }
                    }
                }
                // clean bin
                if (PNStatic.Settings.GeneralSettings.RemoveFromBinPeriod !=
                    _TempSettings.GeneralSettings.RemoveFromBinPeriod)
                {
                    if (_TempSettings.GeneralSettings.RemoveFromBinPeriod == 0)
                    {
                        // stop timer
                        PNStatic.FormMain.TimerCleanBin.Stop();
                    }
                    else if (PNStatic.Settings.GeneralSettings.RemoveFromBinPeriod == 0)
                    {
                        // start timer
                        PNStatic.FormMain.TimerCleanBin.Start();
                    }
                }

                //create or delete shortcut
                string shortcutFile = Environment.GetFolderPath(Environment.SpecialFolder.Startup) +
                                      PNStrings.SHORTCUT_FILE;
                if (PNStatic.Settings.GeneralSettings.RunOnStart != _TempSettings.GeneralSettings.RunOnStart)
                {
                    if (_TempSettings.GeneralSettings.RunOnStart)
                    {
                        //create shortcut
                        if (!File.Exists(shortcutFile))
                        {
                            using (var link = new PNShellLink())
                            {
                                link.ShortcutFile = shortcutFile;
                                link.Target = System.Windows.Forms.Application.ExecutablePath;
                                link.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
                                link.IconPath = System.Windows.Forms.Application.ExecutablePath;
                                link.IconIndex = 0;
                                link.Save();
                            }
                        }
                    }
                    else
                    {
                        //delete shortcut
                        if (File.Exists(shortcutFile))
                        {
                            File.Delete(shortcutFile);
                        }
                    }
                }
                PNStatic.Settings.GeneralSettings = (PNGeneralSettings)_TempSettings.GeneralSettings.Clone();
                if (applyAutoHeight)
                {
                    PNNotesOperations.ApplyAutoHeight();
                }
                PNData.SaveGeneralSettings();
                return true;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return false;
            }
        }
Exemplo n.º 2
0
 internal static void SaveAsShortcut(PNote note)
 {
     try
     {
         // create shortcut
         var counter = 1;
         var arguments = "-i " + note.ID;
         var pntargets = new List<string>();
         var desktop = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
         var shortcuts = desktop.GetFiles("*.lnk");
         //get all desktop shortcuts first
         foreach (var f in shortcuts)
         {
             using (var link = new PNShellLink())
             {
                 link.Load(f.FullName);
                 if (string.Equals(link.Target, System.Windows.Forms.Application.ExecutablePath, StringComparison.OrdinalIgnoreCase))
                 {
                     //collect shortcuts to PNotes.NET
                     pntargets.Add(f.FullName);
                 }
             }
         }
         var shortcutName = note.Name;
         while (true)
         {
             if (pntargets.Any(s =>
             {
                 var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(s);
                 return fileNameWithoutExtension != null && string.Equals(fileNameWithoutExtension, shortcutName, StringComparison.OrdinalIgnoreCase);
             }))
             {
                 counter++;
                 shortcutName = note.Name + "(" + counter + ")";
                 continue;
             }
             break;
         }
         foreach (var s in pntargets)
         {
             using (var link = new PNShellLink())
             {
                 link.Load(s);
                 if (link.Arguments == arguments)
                 {
                     //exit if there is shortcut to the current note
                     return;
                 }
             }
         }
         var shortcutFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" +
                            shortcutName + ".lnk";
         if (File.Exists(shortcutFile)) return;
         using (var link = new PNShellLink())
         {
             link.ShortcutFile = shortcutFile;
             link.Target = System.Windows.Forms.Application.ExecutablePath;
             link.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
             link.IconPath = System.Windows.Forms.Application.ExecutablePath;
             link.IconIndex = 1;
             link.Arguments = arguments;
             link.Save();
         }
         if (PNStatic.Settings.GeneralSettings.CloseOnShortcut)
         {
             ShowHideSpecificNote(note, false);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Exemplo n.º 3
0
 private void checkStartUpShortcut()
 {
     try
     {
         var shortcutFile = Environment.GetFolderPath(Environment.SpecialFolder.Startup) +
                                       PNStrings.SHORTCUT_FILE;
         if (PNStatic.Settings.GeneralSettings.RunOnStart && !File.Exists(shortcutFile))
         {
             // create shortcut
             using (var link = new PNShellLink())
             {
                 link.ShortcutFile = shortcutFile;
                 link.Target = System.Windows.Forms.Application.ExecutablePath;
                 link.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
                 link.IconPath = System.Windows.Forms.Application.ExecutablePath;
                 link.IconIndex = 0;
                 link.Save();
             }
         }
         else if (!PNStatic.Settings.GeneralSettings.RunOnStart && File.Exists(shortcutFile))
         {
             // delete shortcut
             File.Delete(shortcutFile);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }