-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFrmSettings.cs
More file actions
1244 lines (1135 loc) · 55.5 KB
/
FrmSettings.cs
File metadata and controls
1244 lines (1135 loc) · 55.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------
// <copyright file="FrmSettings.cs" company="NoteFly">
// NoteFly a note application.
// Copyright (C) 2010-2015 Tom
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
//-----------------------------------------------------------------------
namespace NoteFly
{
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
/// <summary>
/// Setting window.
/// </summary>
public sealed partial class FrmSettings : Form
{
#region Fields (3)
/// <summary>
/// Reference to notes class.
/// </summary>
private Notes notes;
/// <summary>
/// In which folder notes are saved.
/// </summary>
private string oldnotesavepath;
/// <summary>
/// Array with languagescodes related to every language name in the cbxLanguage control.
/// </summary>
private string[] languagecodes;
/// <summary>
/// Last key from hotkey for new note.
/// </summary>
private int hotkeysnewnotekeycode;
/// <summary>
/// Last key from hotkey for manage notes.
/// </summary>
private int hotkeysmanagenoteskeycode;
/// <summary>
/// Last key from hotkey for notes to front.
/// </summary>
private int hotkeysnotestofront;
#endregion Fields
#region Constructors (1)
/// <summary>
/// Initializes a new instance of the FrmSettings class.
/// </summary>
/// <param name="notes">The notes class.</param>
public FrmSettings(Notes notes)
{
this.DoubleBuffered = Settings.ProgramFormsDoublebuffered;
this.oldnotesavepath = Settings.NotesSavepath;
this.InitializeComponent();
this.notes = notes;
Strings.TranslateForm(this);
this.SetFormTitle(Settings.SettingsExpertEnabled);
this.AddPluginsSettingsTabs();
this.tabControlSettings_SelectedIndexChanged(null, null);
this.LoadCbxLanguage();
this.LoadCbxActionLeftclick();
this.LoadCbxFonts();
this.LoadCbxSkins();
this.SetControlsBySettings();
}
#endregion Constructors
#region Methods (34)
/// <summary>
/// User want to browse for notes save path.
/// </summary>
/// <param name="sender">Sender object.</param>
/// <param name="e">Event arguments</param>
private void btnBrowse_Click(object sender, EventArgs e)
{
this.folderBrowseDialogNotessavepath.Description = Strings.T("Select a folder to store the all the notes files in");
DialogResult dlgresult = this.folderBrowseDialogNotessavepath.ShowDialog();
if (dlgresult == DialogResult.OK)
{
string newpathsavenotes = this.folderBrowseDialogNotessavepath.SelectedPath;
if (Directory.Exists(newpathsavenotes))
{
this.tbNotesSavePath.Text = this.folderBrowseDialogNotessavepath.SelectedPath;
}
else
{
string settings_dirdoesnotexist = Strings.T("Directory does not exist.\nPlease choose a valid directory.");
string settings_dirdoesnotexisttitle = Strings.T("Directory does not exist.");
Log.Write(LogType.info, settings_dirdoesnotexist);
MessageBox.Show(settings_dirdoesnotexist, settings_dirdoesnotexisttitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
/// <summary>
/// Cancel button pressed.
/// Don't save any change made.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// Add settings tab to this settings window from a plugin.
/// </summary>
private void AddPluginsSettingsTabs()
{
if (PluginsManager.EnabledPlugins != null)
{
for (int i = 0; i < PluginsManager.EnabledPlugins.Count; i++)
{
TabPage tabsettings = PluginsManager.EnabledPlugins[i].InitTabFrmSettings();
if (tabsettings != null)
{
this.tabControlSettings.TabPages.Add(tabsettings);
}
}
}
}
/// <summary>
/// Set the title of this form.
/// </summary>
/// <param name="expertsettings">Is showing expert settings enabled.</param>
private void SetFormTitle(bool expertsettings)
{
this.RightToLeft = (RightToLeft)Settings.FontTextdirection;
StringBuilder sbtitle = new StringBuilder();
if (expertsettings)
{
sbtitle.Append(Strings.T("Expert settings"));
}
else
{
sbtitle.Append(Strings.T("Settings"));
}
sbtitle.Append(" - ");
sbtitle.Append(Program.AssemblyTitle);
this.Text = sbtitle.ToString();
}
/// <summary>
/// Loads cbxActionLeftclick
/// </summary>
private void LoadCbxActionLeftclick()
{
this.cbxActionLeftclick.Items.Clear();
this.cbxActionLeftclick.Items.Add(Strings.T("Do nothing"));
this.cbxActionLeftclick.Items.Add(Strings.T("Bring notes to front"));
this.cbxActionLeftclick.Items.Add(Strings.T("New note"));
}
/// <summary>
/// Check the form input. If everything is okay
/// call xmlHandler class to save the xml setting file.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnOK_Click(object sender, EventArgs e)
{
if (this.CheckAllSettingValid())
{
// everything looks okay now
// tab: General
Settings.ConfirmExit = this.chxConfirmExit.Checked;
Settings.ConfirmDeletenote = this.chxConfirmDeletenote.Checked;
Settings.NotesDeleteRecyclebin = this.chxNotesDeleteRecyclebin.Checked;
Settings.ProgramPluginsAllEnabled = this.chxLoadPlugins.Checked;
Settings.TrayiconLeftclickaction = this.cbxActionLeftclick.SelectedIndex;
Settings.SettingsExpertEnabled = this.chxSettingsExpertEnabled.Checked;
Settings.ProgramLanguage = this.GetLanguageCode(this.cbxLanguage.SelectedIndex);
// tab: Hotkeys
Settings.HotkeysNewNoteEnabled = this.chxHotkeyNewNoteEnabled.Checked;
Settings.HotkeysNewNoteAltInsteadShift = this.shortcutTextBoxNewNote.UseAltInsteadofShift;
Settings.HotkeysNewNoteKeycode = this.shortcutTextBoxNewNote.ShortcutKeyposition;
Settings.HotkeysManageNotesEnabled = this.chxHotkeyManageNotesEnabled.Checked;
Settings.HotkeysManageNotesAltInsteadShift = this.shortcutTextBoxManageNotes.UseAltInsteadofShift;
Settings.HotkeysManageNotesKeycode = this.shortcutTextBoxManageNotes.ShortcutKeyposition;
Settings.HotkeysNotesToFrontEnabled = this.chxHotkeyNotesFrontEnabled.Checked;
Settings.HotkeysNotesToFrontAltInsteadShift = this.shortcutTextBoxNotesToFront.UseAltInsteadofShift;
Settings.HotkeysNotesToFrontKeycode = this.shortcutTextBoxNotesToFront.ShortcutKeyposition;
// tab: Appearance, Overall
Settings.NotesTransparencyEnabled = this.chxTransparecy.Checked;
Settings.NotesTransparencyLevel = Convert.ToDouble(this.numProcTransparency.Value / 100);
Settings.NotesTooltipsEnabled = this.chxShowTooltips.Checked;
// tab: Appearance, New note
Settings.NotesDefaultRandomSkin = this.chxUseRandomDefaultNote.Checked;
Settings.NotesDefaultSkinnr = this.cbxDefaultSkin.SelectedIndex;
Settings.NotesDefaultWidth = Convert.ToInt32(this.numNotesDefaultWidth.Value);
Settings.NotesDefaultHeight = Convert.ToInt32(this.numNotesDefaultHeight.Value);
Settings.NotesDefaultTitleDate = this.chxUseDateAsDefaultTitle.Checked;
// tab: Appearance, Notes
Settings.FontContentFamily = this.cbxFontNoteContent.SelectedItem.ToString();
Settings.FontContentSize = (float)this.numFontSizeContent.Value;
Settings.FontTitleStylebold = this.chxFontNoteTitleBold.Checked;
Settings.FontTitleFamily = this.cbxFontNoteTitle.SelectedItem.ToString();
Settings.FontTitleSize = (float)this.numFontSizeTitle.Value;
Settings.FontTextdirection = this.cbxTextDirection.SelectedIndex;
Settings.NotesDoubleclickRollup = this.chxNotesDoubleclickRollup.Checked;
// tab: Appearance, Trayicon
Settings.FontTrayicon = this.cbxFontTrayicon.SelectedItem.ToString();
Settings.TrayiconFontsize = (float)this.numTrayiconFontsize.Value;
Settings.TrayiconCreatenotebold = this.chxTrayiconBoldNewnote.Checked;
Settings.TrayiconManagenotesbold = this.chxTrayiconBoldManagenotes.Checked;
Settings.TrayiconSettingsbold = this.chxTrayiconBoldSettings.Checked;
Settings.TrayiconExitbold = this.chxTrayiconBoldExit.Checked;
Settings.TrayiconAlternateIcon = this.chxUseAlternativeTrayicon.Checked;
// tab: Appearance, Manage notes
Settings.ManagenotesSkinnr = this.cbxManageNotesSkin.SelectedIndex;
Settings.ManagenotesTooltip = this.chxManagenotesTooltipContent.Checked;
Settings.ManagenotesFontsize = (float)this.numManagenotesFont.Value;
Settings.ManagenotesSearchCasesentive = this.chxCaseSentiveSearch.Checked;
// tab: Highlight
Settings.HighlightHyperlinks = this.chxHighlightHyperlinks.Checked;
Settings.ConfirmLinkclick = this.chxConfirmLink.Checked;
Settings.HighlightHTML = this.chxHighlightHTML.Checked;
Settings.HighlightPHP = this.chxHighlightPHP.Checked;
Settings.HighlightSQL = this.chxHighlightSQL.Checked;
Settings.HighlightClearLexiconMemory = this.chxLexiconMemory.Checked;
// tab: Actions, E-mail
Settings.SharingEmailEnabled = this.chxActionsEmailEnabled.Checked;
Settings.SharingEmailDefaultadres = string.Empty;
if (this.chxActionsEmailDefaultaddressSet.Checked)
{
Settings.SharingEmailDefaultadres = this.tbDefaultEmail.Text;
}
// tab: Network, updates
if (this.chxCheckUpdates.Checked)
{
Settings.UpdatecheckEverydays = Convert.ToInt32(this.numUpdateCheckDays.Value);
Settings.UpdatecheckPluginsEverydays = Convert.ToInt32(this.numUpdateCheckPluginsDays.Value);
}
else
{
Settings.UpdatecheckEverydays = 0;
}
Settings.UpdateSilentInstall = this.chxUpdateSilentInstall.Checked;
// tab: Network, Proxy
Settings.NetworkProxyEnabled = this.chxProxyEnabled.Checked;
Settings.NetworkProxyAddress = this.iptbProxy.GetIPAddress();
Settings.NetworkConnectionTimeout = Convert.ToInt32(this.numTimeout.Value);
// tab: Network, GnuPG
Settings.UpdatecheckUseGPG = this.chxCheckUpdatesSignature.Checked;
Settings.UpdatecheckGPGPath = this.tbGPGPath.Text;
// tab: Advance
if (Directory.Exists(this.tbNotesSavePath.Text))
{
Settings.NotesSavepath = this.tbNotesSavePath.Text;
}
Settings.NotesWarnlimitTotal = Convert.ToInt32(this.numWarnLimitTotal.Value);
Settings.NotesWarnlimitVisible = Convert.ToInt32(this.numWarnLimitVisible.Value);
Settings.ProgramLogError = this.chxLogErrors.Checked;
Settings.ProgramLogInfo = this.chxLogDebug.Checked;
Settings.ProgramLogException = this.chxLogExceptions.Checked;
Settings.SettingsLastTab = this.tabControlSettings.SelectedIndex;
if (Program.CurrentOS == Program.OS.WINDOWS)
{
this.AddNoteFlyLogon();
}
xmlUtil.WriteSettings();
if (!Settings.NotesSavepath.Equals(this.oldnotesavepath, StringComparison.OrdinalIgnoreCase))
{
for (int i = 0; i < this.notes.CountNotes; i++)
{
this.notes.GetNote(i).DestroyForm();
}
while (this.notes.CountNotes > 0)
{
this.notes.RemoveNote(0);
}
try
{
this.Cursor = Cursors.WaitCursor;
Thread movenotesthread = new Thread(new ParameterizedThreadStart(this.MoveNotesThread));
string[] args = new string[2];
args[0] = this.oldnotesavepath;
args[1] = Settings.NotesSavepath;
movenotesthread.Start(args);
movenotesthread.Join(300); // if finished within 300ms don't display busy moving notes message.
this.ShowWaitOnThread(movenotesthread, 300, Strings.T("{0} is busy moving your notes.", Program.AssemblyTitle));
this.notes.LoadNotes(true, false);
}
finally
{
this.Cursor = Cursors.Default;
}
}
Program.Formmanager.FrmManageNotesNeedUpdate = true;
Program.Formmanager.RefreshFrmManageNotes();
if (Settings.ProgramPluginsAllEnabled)
{
PluginsManager.LoadPlugins();
}
SyntaxHighlight.InitHighlighter();
this.notes.UpdateAllNoteForms();
Program.RestartTrayicon();
if (SyntaxHighlight.KeywordsInitialized)
{
// clean memory
SyntaxHighlight.DeinitHighlighter();
}
Log.Write(LogType.info, "Settings updated");
this.Close();
}
}
/// <summary>
/// Add a notefly registery key to the run section if this.chxStartOnLogin is checked and not already added to registery.
/// </summary>
private void AddNoteFlyLogon()
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (key != null)
{
if (this.chxStartOnLogin.Checked)
{
try
{
key.SetValue(Program.AssemblyTitle, "\"" + Application.ExecutablePath + "\"");
}
catch (UnauthorizedAccessException unauthexc)
{
string nowriterightsregistery = Strings.T("No rights to add key to registry.");
Log.Write(LogType.exception, nowriterightsregistery + unauthexc.Message);
MessageBox.Show(unauthexc.Message);
}
catch (Exception exc)
{
throw new ApplicationException(exc.Message + " " + exc.StackTrace);
}
}
else
{
if (key.GetValue(Program.AssemblyTitle, null) != null)
{
key.DeleteValue(Program.AssemblyTitle, false);
}
}
}
else
{
string settings_regkeynotexist = Strings.T("Run key in registry does not exist.");
string settings_regkeynotexisttitle = Strings.T("Error run key registry missing");
Log.Write(LogType.error, settings_regkeynotexist);
MessageBox.Show(settings_regkeynotexist, settings_regkeynotexisttitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Check if all settings are valid, if a setting in this form is not correct display a error about it.
/// </summary>
/// <returns>True if all set settings seems to be valid.</returns>
private bool CheckAllSettingValid()
{
bool allsettingsvalid = false;
string settings_invalidfontsize = Strings.T("Font size invalid. Minimal 4pt maximum 128pt allowed.");
string settings_invalidfontsizetitle = Strings.T("Error invalid font size");
string settings_nofont = Strings.T("Please select a font.");
string settings_nofonttitle = Strings.T("Error no font.");
if (!Directory.Exists(this.tbNotesSavePath.Text))
{
this.tabControlSettings.SelectedTab = this.tabAdvance;
string settings_invalidfoldersavenote = Strings.T("Invalid folder for saving notes folder.");
string settings_invalidfoldersavenotetitle = Strings.T("Error invalid notes folder");
Log.Write(LogType.info, settings_invalidfoldersavenote);
MessageBox.Show(settings_invalidfoldersavenote, settings_invalidfoldersavenotetitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (string.IsNullOrEmpty(this.cbxFontNoteContent.Text) == true)
{
this.tabControlSettings.SelectedTab = this.tabAppearance;
Log.Write(LogType.info, settings_nofont);
MessageBox.Show(settings_nofont, settings_nofonttitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (string.IsNullOrEmpty(this.cbxFontNoteTitle.Text) == true)
{
this.tabControlSettings.SelectedTab = this.tabAppearance;
Log.Write(LogType.info, settings_nofont);
MessageBox.Show(settings_nofont, settings_nofonttitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if ((this.numFontSizeContent.Value < 4) || (this.numFontSizeContent.Value > 128))
{
this.tabControlSettings.SelectedTab = this.tabAppearance;
Log.Write(LogType.info, settings_invalidfontsize);
MessageBox.Show(settings_invalidfontsize, settings_invalidfontsizetitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if ((this.numFontSizeTitle.Value < 4) || (this.numFontSizeTitle.Value > 128))
{
this.tabControlSettings.SelectedTab = this.tabAppearance;
Log.Write(LogType.info, settings_invalidfontsize);
MessageBox.Show(settings_invalidfontsize, settings_invalidfontsizetitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (this.cbxTextDirection.SelectedIndex > 1)
{
this.tabControlSettings.SelectedTab = this.tabAppearance;
string settings_noknowtextdir = Strings.T("Settings text direction invalid.");
string settings_noknowtextdirtitle = Strings.T("Error text direction");
Log.Write(LogType.error, settings_noknowtextdir);
MessageBox.Show(settings_noknowtextdir, settings_noknowtextdirtitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!this.tbDefaultEmail.IsValidEmailAddress() && this.chxActionsEmailDefaultaddressSet.Checked)
{
this.tabControlSettings.SelectedTab = this.tabSharing;
string settings_emailnotvalid = Strings.T("Given email address as default email address is not valid.");
string settings_emailnotvalidtitle = Strings.T("email address invalid");
Log.Write(LogType.error, settings_emailnotvalid);
MessageBox.Show(settings_emailnotvalid, settings_emailnotvalidtitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!File.Exists(this.tbGPGPath.Text) && this.chxCheckUpdatesSignature.Checked)
{
this.tabControlSettings.SelectedTab = this.tabNetwork;
string settings_gpgpathinvalid = Strings.T("The path to gpg.exe is not valid.");
string settings_gpgpathinvalidtitle = Strings.T("Error not valid gpg path.");
Log.Write(LogType.info, settings_gpgpathinvalid);
MessageBox.Show(settings_gpgpathinvalid, settings_gpgpathinvalidtitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (PluginsManager.EnabledPlugins != null)
{
// check plugin settings
for (int i = 0; i < PluginsManager.EnabledPlugins.Count; i++)
{
if (!PluginsManager.EnabledPlugins[i].SaveSettingsTab())
{
//this.tabControlSettings.SelectedTab = this.tabSharing; // todo select plugin tab with error
return false;
}
}
}
allsettingsvalid = true;
}
return allsettingsvalid;
}
/// <summary>
/// Show a message form while thread is buzy.
/// And auto close while done.
/// </summary>
/// <param name="worktread">The thread that is doing work while message being showed</param>
/// <param name="checktimems">Miliseconds to check if workthread is done, is also the minimum show time of the message, if being showed</param>
/// <param name="message">The message to show</param>
private void ShowWaitOnThread(Thread worktread, int checktimems, string message)
{
Form frmmgs = null;
bool mgsshowed = false;
while (worktread.ThreadState == ThreadState.Running)
{
if (!mgsshowed)
{
mgsshowed = true;
frmmgs = new Form();
frmmgs.StartPosition = FormStartPosition.CenterScreen;
frmmgs.Size = new Size(240, 80);
frmmgs.ShowIcon = false;
frmmgs.ShowInTaskbar = false;
frmmgs.MinimizeBox = false;
frmmgs.MaximizeBox = false;
frmmgs.Text = Strings.T("Please wait");
Label lblmgs = new Label();
lblmgs.Text = message;
lblmgs.SetBounds(10, 10, 200, 40);
frmmgs.Controls.Add(lblmgs);
frmmgs.Show();
}
Thread.Sleep(checktimems);
}
if (frmmgs != null)
{
frmmgs.Close();
}
}
/// <summary>
/// Reset button clicked.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnResetSettings_Click(object sender, EventArgs e)
{
string settings_sureresetdefault = Strings.T("Are you sure, you want to reset all the settings to default?");
string settings_sureresetdefaulttitle = Strings.T("Reset settings?");
DialogResult dlgres = MessageBox.Show(settings_sureresetdefault, settings_sureresetdefaulttitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgres == DialogResult.Yes)
{
xmlUtil.WriteDefaultSettings();
// override first runned setting to true, so people are not annoyed with demo note and tooltip again.
Settings.ProgramFirstrunned = true;
this.SetControlsBySettings();
}
}
/// <summary>
/// The user de-/selected checking for updates.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void cbxCheckUpdates_CheckedChanged(object sender, EventArgs e)
{
this.numUpdateCheckDays.Enabled = this.chxCheckUpdates.Checked;
this.numUpdateCheckPluginsDays.Enabled = this.chxCheckUpdates.Checked;
}
/// <summary>
/// Toggle tbDefaultEmail enabled.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void chxSocialEmailDefaultaddressBlank_CheckedChanged(object sender, EventArgs e)
{
this.tbDefaultEmail.Enabled = this.chxActionsEmailDefaultaddressSet.Checked;
}
/// <summary>
/// Toggle iptbProxyAddress enabled.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void chxUseProxy_CheckedChanged(object sender, EventArgs e)
{
this.iptbProxy.Enabled = this.chxProxyEnabled.Checked;
this.numProxyPort.Enabled = this.chxProxyEnabled.Checked;
}
/// <summary>
/// Toggle cbxDefaultColor enabled.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void chxUseRandomDefaultNote_CheckedChanged(object sender, EventArgs e)
{
this.cbxDefaultSkin.Enabled = !this.chxUseRandomDefaultNote.Checked;
}
/// <summary>
/// Fill combobox that are use to select a font with fontnames.
/// </summary>
private void LoadCbxFonts()
{
this.cbxFontNoteTitle.Items.Clear();
this.cbxFontNoteContent.Items.Clear();
this.cbxFontTrayicon.Items.Clear();
foreach (FontFamily oneFontFamily in FontFamily.Families)
{
this.cbxFontNoteTitle.Items.Add(oneFontFamily.Name);
this.cbxFontNoteContent.Items.Add(oneFontFamily.Name);
this.cbxFontTrayicon.Items.Add(oneFontFamily.Name);
}
}
/// <summary>
/// Fill the combobox that are use to select a skin with skinnames.
/// </summary>
private void LoadCbxSkins()
{
this.cbxDefaultSkin.Items.AddRange(this.notes.GetSkinsNames());
this.cbxManageNotesSkin.Items.AddRange(this.notes.GetSkinsNames());
}
/// <summary>
/// Move notes files with a seperate the to a other location.
/// </summary>
/// <param name="args">The orginal and new paths as string array.</param>
private void MoveNotesThread(object args)
{
string[] pathsargs = (string[])args;
this.MoveNotes(pathsargs[0], pathsargs[1]);
}
/// <summary>
/// Move note files.
/// </summary>
/// <param name="oldsavenotespath">The old path where notes are saved.</param>
/// <param name="newsavenotespath">The new path to save the notes to.</param>
private void MoveNotes(string oldsavenotespath, string newsavenotespath)
{
bool errorshowed = false;
if (!Directory.Exists(oldsavenotespath) || !Directory.Exists(newsavenotespath))
{
return;
}
string[] notefilespath = Directory.GetFiles(oldsavenotespath, "*" + Notes.NOTEEXTENSION, SearchOption.TopDirectoryOnly);
string[] notefiles = new string[notefilespath.Length];
for (int i = 0; i < notefilespath.Length; i++)
{
notefiles[i] = Path.GetFileName(notefilespath[i]);
}
notefilespath = null;
for (int i = 0; i < notefiles.Length; i++)
{
string oldfile = Path.Combine(oldsavenotespath, notefiles[i]);
string newfile = Path.Combine(newsavenotespath, notefiles[i]);
if (!File.Exists(newfile))
{
FileInfo fi = new FileInfo(oldfile);
if (fi.Attributes != FileAttributes.System)
{
try
{
File.Move(oldfile, newfile);
}
catch (UnauthorizedAccessException unauthexc)
{
Log.Write(LogType.error, unauthexc.Message);
}
}
else
{
string settings_excsystemfilenotmoved = Strings.T("File is marked as system file. Did not move.");
throw new ApplicationException(settings_excsystemfilenotmoved);
}
}
else
{
if (!errorshowed)
{
string settings_filealreadyexisttitle = Strings.T("Error moving note(s)");
string settings_filealreadyexist = Strings.T("Note file(s) already exist.");
Log.Write(LogType.error, settings_filealreadyexist);
MessageBox.Show(settings_filealreadyexist, settings_filealreadyexisttitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
errorshowed = true;
}
}
}
}
/// <summary>
/// Read setting and set controls to display them correctly.
/// </summary>
private void SetControlsBySettings()
{
this.chxSettingsExpertEnabled.Checked = Settings.SettingsExpertEnabled;
// tab: General
if (Program.CurrentOS == Program.OS.WINDOWS)
{
this.chxStartOnLogin.Checked = this.GetStartOnLogon();
}
this.chxConfirmExit.Checked = Settings.ConfirmExit;
this.chxConfirmDeletenote.Checked = Settings.ConfirmDeletenote;
this.chxNotesDeleteRecyclebin.Checked = Settings.NotesDeleteRecyclebin;
this.chxLoadPlugins.Checked = Settings.ProgramPluginsAllEnabled;
this.SetComboBoxSelectedIndex(this.cbxActionLeftclick, Settings.TrayiconLeftclickaction);
// tab: Hotkeys
this.chxHotkeyNewNoteEnabled.Checked = Settings.HotkeysNewNoteEnabled;
this.shortcutTextBoxNewNote.UseAltInsteadofShift = Settings.HotkeysNewNoteAltInsteadShift;
this.shortcutTextBoxNewNote.ShortcutKeyposition = Settings.HotkeysNewNoteKeycode;
this.chxHotkeyManageNotesEnabled.Checked = Settings.HotkeysManageNotesEnabled;
this.shortcutTextBoxManageNotes.UseAltInsteadofShift = Settings.HotkeysManageNotesAltInsteadShift;
this.shortcutTextBoxManageNotes.ShortcutKeyposition = Settings.HotkeysManageNotesKeycode;
this.chxHotkeyNotesFrontEnabled.Checked = Settings.HotkeysNotesToFrontEnabled;
this.shortcutTextBoxNotesToFront.UseAltInsteadofShift = Settings.HotkeysNotesToFrontAltInsteadShift;
this.shortcutTextBoxNotesToFront.ShortcutKeyposition = Settings.HotkeysNotesToFrontKeycode;
// tab: Appearance, overall
this.chxTransparecy.Checked = Settings.NotesTransparencyEnabled;
this.SetUpDownSpinnerValue(this.numProcTransparency, Settings.NotesTransparencyLevel * 100);
this.chxShowTooltips.Checked = Settings.NotesTooltipsEnabled;
// tab: Appearance, new note
this.chxUseRandomDefaultNote.Checked = Settings.NotesDefaultRandomSkin;
this.SetComboBoxSelectedIndex(this.cbxDefaultSkin, Settings.NotesDefaultSkinnr);
this.SetUpDownSpinnerValue(this.numNotesDefaultWidth, Settings.NotesDefaultWidth);
this.SetUpDownSpinnerValue(this.numNotesDefaultHeight, Settings.NotesDefaultHeight);
this.chxUseDateAsDefaultTitle.Checked = Settings.NotesDefaultTitleDate;
// tab: Appearance, notes
this.SetUpDownSpinnerValue(this.numFontSizeTitle, Settings.FontTitleSize);
this.SetUpDownSpinnerValue(this.numFontSizeContent, Settings.FontContentSize);
this.SetComboBoxSelectedIndex(this.cbxTextDirection, Settings.FontTextdirection);
this.cbxFontNoteContent.Text = Settings.FontContentFamily;
this.cbxFontNoteTitle.Text = Settings.FontTitleFamily;
this.chxFontNoteTitleBold.Checked = Settings.FontTitleStylebold;
this.chxNotesDoubleclickRollup.Checked = Settings.NotesDoubleclickRollup;
// tab: Appearance, trayicon
this.SetUpDownSpinnerValue(this.numTrayiconFontsize, Settings.TrayiconFontsize);
this.cbxFontTrayicon.Text = Settings.FontTrayicon;
this.chxTrayiconBoldNewnote.Checked = Settings.TrayiconCreatenotebold;
this.chxTrayiconBoldManagenotes.Checked = Settings.TrayiconManagenotesbold;
this.chxTrayiconBoldSettings.Checked = Settings.TrayiconSettingsbold;
this.chxTrayiconBoldExit.Checked = Settings.TrayiconExitbold;
this.chxUseAlternativeTrayicon.Checked = Settings.TrayiconAlternateIcon;
// tab: Appearance, manage notes
this.SetComboBoxSelectedIndex(this.cbxManageNotesSkin, Settings.ManagenotesSkinnr);
this.chxManagenotesTooltipContent.Checked = Settings.ManagenotesTooltip;
this.SetUpDownSpinnerValue(this.numManagenotesFont, Settings.ManagenotesFontsize);
this.chxCaseSentiveSearch.Checked = Settings.ManagenotesSearchCasesentive;
// tab: Highlight
this.chxHighlightHyperlinks.Checked = Settings.HighlightHyperlinks;
this.chxHighlightHTML.Checked = Settings.HighlightHTML;
this.chxHighlightPHP.Checked = Settings.HighlightPHP;
this.chxHighlightSQL.Checked = Settings.HighlightSQL;
this.chxConfirmLink.Checked = Settings.ConfirmLinkclick;
this.chxLexiconMemory.Checked = Settings.HighlightClearLexiconMemory;
// tab: Sharing
this.tbDefaultEmail.Text = Settings.SharingEmailDefaultadres;
this.chxActionsEmailEnabled.Checked = Settings.SharingEmailEnabled;
this.chxActionsEmailDefaultaddressSet.Checked = false;
if (!string.IsNullOrEmpty(Settings.SharingEmailDefaultadres))
{
this.chxActionsEmailDefaultaddressSet.Checked = true;
}
// tab: Network, Updates
if (Settings.UpdatecheckEverydays > 0)
{
this.chxCheckUpdates.Checked = true;
this.SetUpDownSpinnerValue(this.numUpdateCheckDays, Settings.UpdatecheckEverydays);
this.SetUpDownSpinnerValue(this.numUpdateCheckPluginsDays, Settings.UpdatecheckPluginsEverydays);
this.numUpdateCheckDays.Enabled = true;
this.numUpdateCheckPluginsDays.Enabled = true;
}
else
{
this.chxCheckUpdates.Checked = false;
this.numUpdateCheckDays.Enabled = false;
this.numUpdateCheckPluginsDays.Enabled = false;
}
this.chxUpdateSilentInstall.Checked = Settings.UpdateSilentInstall;
this.SetLastUpdatecheckDate(Settings.SettingsExpertEnabled);
// tab: Network, Proxy
this.chxProxyEnabled.Checked = Settings.NetworkProxyEnabled;
this.iptbProxy.Text = Settings.NetworkProxyAddress;
this.SetUpDownSpinnerValue(this.numTimeout, Settings.NetworkConnectionTimeout);
// tab: Network, GnuPG
this.chxCheckUpdatesSignature.Checked = Settings.UpdatecheckUseGPG;
this.tbGPGPath.Enabled = Settings.UpdatecheckUseGPG;
this.tbGPGPath.Text = Settings.UpdatecheckGPGPath;
// tab: Advance
this.tbNotesSavePath.Text = Settings.NotesSavepath;
this.SetUpDownSpinnerValue(this.numWarnLimitTotal, Settings.NotesWarnlimitTotal);
this.SetUpDownSpinnerValue(this.numWarnLimitVisible, Settings.NotesWarnlimitVisible);
this.chxLogDebug.Checked = Settings.ProgramLogInfo;
this.chxLogErrors.Checked = Settings.ProgramLogError;
this.chxLogExceptions.Checked = Settings.ProgramLogException;
// Set last used tab as active.
this.tabControlSettings.SelectedIndex = Settings.SettingsLastTab;
}
/// <summary>
/// Set a updownspinner valeau with a double valeau.
/// </summary>
/// <param name="numupdownctrl">NumericUpDown control.</param>
/// <param name="valeau">Valeau to set in the NumericUpDown control.</param>
private void SetUpDownSpinnerValue(System.Windows.Forms.NumericUpDown numupdownctrl, double valeau)
{
try
{
decimal valeaudec = Convert.ToDecimal(valeau);
this.SetUpDownSpinnerValue(numupdownctrl, valeaudec);
}
catch (OverflowException overexc)
{
Log.Write(LogType.error, overexc.Message);
}
}
/// <summary>
/// Set a updownspinner valeau with a integer valeau.
/// </summary>
/// <param name="numupdownctrl">NumericUpDown control</param>
/// <param name="value">Integer valeau to set in the NumericUpDown control.</param>
private void SetUpDownSpinnerValue(System.Windows.Forms.NumericUpDown numupdownctrl, int value)
{
decimal valeaudec = Convert.ToDecimal(value);
this.SetUpDownSpinnerValue(numupdownctrl, valeaudec);
}
/// <summary>
/// Set a updownspinner valeau with a decimal valeau, directly.
/// Checks if it does not exceed the minimum and maximum value.
/// </summary>
/// <param name="numupdownctrl">NumericUpDown control</param>
/// <param name="valuedec">Value to set in the NumericUpDown control</param>
private void SetUpDownSpinnerValue(System.Windows.Forms.NumericUpDown numupdownctrl, decimal valuedec)
{
if (valuedec < numupdownctrl.Minimum)
{
numupdownctrl.Value = numupdownctrl.Minimum;
}
else if (valuedec > numupdownctrl.Maximum)
{
numupdownctrl.Value = numupdownctrl.Maximum;
}
else
{
numupdownctrl.Value = valuedec;
}
}
/// <summary>
/// Set a combobox selected index.
/// Check if selectedindex parameter is not bigger than the availible items in the combobox and not negative.
/// </summary>
/// <param name="cbxctrl">ComboBox control</param>
/// <param name="selectedindexvalue">ComboBox selected index</param>
private void SetComboBoxSelectedIndex(System.Windows.Forms.ComboBox cbxctrl, int selectedindexvalue)
{
if (selectedindexvalue < cbxctrl.Items.Count && selectedindexvalue >= 0)
{
cbxctrl.SelectedIndex = selectedindexvalue;
}
}
/// <summary>
/// Gets if notefly is used to run at logon.
/// </summary>
/// <returns>The boolean if it starts at logon.</returns>
private bool GetStartOnLogon()
{
bool startonlogon = false;
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (key != null)
{
if (key.GetValue(Program.AssemblyTitle, null) != null)
{
startonlogon = true;
}
}
return startonlogon;
}
/// <summary>
/// Toggle enabling numProcTransparency.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event argument</param>
private void chxTransparecy_CheckedChanged(object sender, EventArgs e)
{
this.numProcTransparency.Enabled = this.chxTransparecy.Checked;
}
/// <summary>
/// Requested to manually do an update check.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event argument</param>
private void btnCheckUpdates_Click(object sender, EventArgs e)
{
Settings.UpdatecheckLastDate = Program.UpdateGetLatestVersion();
xmlUtil.WriteSettings();
if (!string.IsNullOrEmpty(Settings.UpdatecheckLastDate))
{
this.SetLastUpdatecheckDate(this.chxSettingsExpertEnabled.Checked);
}
this.btnCheckUpdates.Enabled = false;
}
/// <summary>
/// Show and hide expert settings.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event argument</param>
private void chxShowExpertSettings_CheckedChanged(object sender, EventArgs e)
{
bool expertsettings = this.chxSettingsExpertEnabled.Checked;
this.SetFormTitle(expertsettings);
this.chxConfirmDeletenote.Visible = expertsettings;
this.chxLoadPlugins.Visible = expertsettings;
this.chxNotesDeleteRecyclebin.Visible = expertsettings;
this.chxUseAlternativeTrayicon.Visible = expertsettings;
this.chxConfirmLink.Visible = expertsettings;
this.chxUpdateSilentInstall.Visible = expertsettings;
this.lblTextGPGPath.Visible = expertsettings;
this.tbGPGPath.Visible = expertsettings;
this.btnGPGPathBrowse.Visible = expertsettings;
this.chxCheckUpdatesSignature.Visible = expertsettings;
this.lblTextNetworkTimeout.Visible = expertsettings;
this.numTimeout.Visible = expertsettings;
this.lblTextMiliseconds.Visible = expertsettings;
this.lblTextNetworkMiliseconds.Visible = expertsettings;
this.chxFontNoteTitleBold.Visible = expertsettings;
this.lblTextTotalNotesWarnLimit.Visible = expertsettings;
this.numWarnLimitTotal.Visible = expertsettings;
this.lblTextVisibleNotesWarnLimit.Visible = expertsettings;
this.numWarnLimitVisible.Visible = expertsettings;
this.chxCaseSentiveSearch.Visible = expertsettings;
this.chxManagenotesTooltipContent.Visible = expertsettings;
this.chxLogErrors.Visible = expertsettings;
this.chxLogExceptions.Visible = expertsettings;
this.btnOpenSettingsFolder.Visible = expertsettings;
this.chxLexiconMemory.Visible = expertsettings;
this.SetLastUpdatecheckDate(expertsettings);
this.SetTabPageGPGVisible(expertsettings);
}
/// <summary>
/// Display the last update date.
/// Show also the time of the last update if expert settings is enabled.
/// </summary>
/// <param name="expertsettings">Is expert setting being used.</param>
private void SetLastUpdatecheckDate(bool expertsettings)
{
if (expertsettings)
{
this.lblLatestUpdateCheck.Text = Settings.UpdatecheckLastDate;
}
else
{
DateTime dt;
if (DateTime.TryParse(Settings.UpdatecheckLastDate, out dt))
{
this.lblLatestUpdateCheck.Text = dt.ToShortDateString();
}
else
{
this.lblLatestUpdateCheck.Text = Settings.UpdatecheckLastDate;
}
}
}
/// <summary>
/// Set the TabPageGPG visible if expertsetting is true otherwise make TabPageGPG not visible.
/// </summary>
/// <param name="expertsettings">Is expert settings being used</param>
private void SetTabPageGPGVisible(bool expertsettings)
{
if (expertsettings)
{
if (!this.tabControlNetwork.TabPages.Contains(this.tabPageGPG))
{
this.tabControlNetwork.TabPages.Add(this.tabPageGPG);
}
}
else
{
if (this.tabControlNetwork.TabPages.Contains(this.tabPageGPG))
{
this.tabControlNetwork.TabPages.Remove(this.tabPageGPG);