-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFrmNewNote.cs
More file actions
1180 lines (1078 loc) · 46.2 KB
/
FrmNewNote.cs
File metadata and controls
1180 lines (1078 loc) · 46.2 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="FrmNewNote.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.IO;
using System.Text;
using System.Windows.Forms;
/// <summary>
/// New and edit note window.
/// </summary>
public sealed partial class FrmNewNote : Form
{
#region Fields (5)
/// <summary>
/// Margin between format buttons and content.
/// </summary>
private const int MARGIN = 5;
/// <summary>
/// Indicated if the form is being moved.
/// </summary>
private bool moving = false;
/// <summary>
/// Reference to a new or editing note,
/// </summary>
private Note note;
/// <summary>
/// Pointer to the notes class.
/// </summary>
private Notes notes;
/// <summary>
/// Pointer to rtfdirectedit class.
/// </summary>
private RTFDirectEdit rtfdirectedit = new RTFDirectEdit();
/// <summary>
/// The tooltip.
/// </summary>
private ToolTip tooltip;
/// <summary>
/// The old position of the mouse while resizing.
/// </summary>
private Point oldp;
#endregion Fields
#region Constructors (2)
/// <summary>
/// Initializes a new instance of the FrmNewNote class for editing a exist note.
/// </summary>
/// <param name="notes">The class with access to all notes.</param>
/// <param name="note">The note to edit.</param>
/// <param name="locfrmnewnote">The location of the FrmNewNote should get.</param>
/// <param name="sizefrmnewnote">The size of the FrnNewNote should get.</param>
/// <param name="wordwrap">Wrap words that exceeded the width of the richedittext control.</param>
public FrmNewNote(Notes notes, Note note, Point locfrmnewnote, Size sizefrmnewnote, bool wordwrap)
{
this.ConstructFrmNewNote(notes);
this.SetFormTitle(true);
this.SetFormTooltips(true);
this.Location = locfrmnewnote;
this.Size = sizefrmnewnote;
this.rtbNewNote.WordWrap = wordwrap;
this.menuWordWarp.Checked = wordwrap;
this.note = note;
this.SetColorsForm(this.note.SkinNr);
this.tbTitle.Text = note.Title;
if (string.IsNullOrEmpty(this.note.Tempcontent))
{
this.rtbNewNote.Rtf = note.GetContent();
}
else
{
this.rtbNewNote.Rtf = this.note.Tempcontent;
// clear memory:
this.note.Tempcontent = string.Empty;
this.note.Tempcontent = null;
}
}
/// <summary>
/// Initializes a new instance of the FrmNewNote class for a new note.
/// </summary>
/// <param name="notes">The class with access to all notes.</param>
/// <param name="deltaX">X position change from center screen position to show form.</param>
/// <param name="deltaY">Y position change from center screen position to show form.</param>
/// <param name="contentclipboard"></param>
public FrmNewNote(Notes notes, int deltaX, int deltaY, string newtitle, string newcontent)
{
this.ConstructFrmNewNote(notes);
this.SetFormTitle(false);
this.SetFormTooltips(false);
this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width / 2) - (this.Width / 2) + deltaX, (Screen.PrimaryScreen.WorkingArea.Height / 2) - (this.Height / 2) + deltaY);
this.note = null;
if (Settings.NotesDefaultRandomSkin)
{
Settings.NotesDefaultSkinnr = notes.GenerateRandomSkinnr();
}
this.SetColorsForm(Settings.NotesDefaultSkinnr);
if (!string.IsNullOrEmpty(newtitle))
{
this.tbTitle.Text = newtitle;
}
else
{
if (Settings.NotesDefaultTitleDate)
{
// The string returned by the ToShortDateString method is culture-sensitive.
this.tbTitle.Text = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
}
}
if (!string.IsNullOrEmpty(newcontent))
{
this.rtbNewNote.Text = newcontent;
}
}
#endregion Constructors
#region Methods (30)
/// <summary>
/// Set the form title.
/// </summary>
/// <param name="editnote">True if this form is used for note editing and not creating a new note.</param>
private void SetFormTitle(bool editnote)
{
this.RightToLeft = (RightToLeft)Settings.FontTextdirection;
StringBuilder sbtitle = new StringBuilder();
if (editnote)
{
sbtitle.Append(Strings.T("edit note"));
}
else
{
sbtitle.Append(Strings.T("new note"));
}
sbtitle.Append(" - ");
sbtitle.Append(Program.AssemblyTitle);
this.Text = sbtitle.ToString();
}
/// <summary>
/// Set all form tooltips if tooltips are enabled.
/// </summary>
/// <param name="editnote"></param>
private void SetFormTooltips(bool editnote)
{
if (Settings.NotesTooltipsEnabled)
{
this.tooltip = new ToolTip(this.components);
if (editnote)
{
this.tooltip.SetToolTip(this.btnAddNote, Strings.T("Save editing note (Ctrl+S)"));
this.tooltip.SetToolTip(this.btnCancel, Strings.T("Cancel editing note (escape)"));
}
else
{
this.tooltip.SetToolTip(this.btnAddNote, Strings.T("Save new note (Ctrl+S)"));
this.tooltip.SetToolTip(this.btnCancel, Strings.T("Cancel new note (escape)"));
}
this.tooltip.SetToolTip(this.btnTextBold, Strings.T("Bold text (Ctrl+B)"));
this.tooltip.SetToolTip(this.btnTextItalic, Strings.T("Italic text (Ctrl+I)"));
this.tooltip.SetToolTip(this.btnTextUnderline, Strings.T("Underline text (Ctrl+U)"));
this.tooltip.SetToolTip(this.btnTextStriketrough, Strings.T("Strike-through text (Ctrl+T)"));
this.tooltip.SetToolTip(this.btnTextBulletlist, Strings.T("Bullet list (Ctrl+shift+L)"));
this.tooltip.SetToolTip(this.btnFontBigger, Strings.T("Bigger text (Ctrl+shift+>)"));
this.tooltip.SetToolTip(this.btnFontSmaller, Strings.T("Smaller text (Ctrl+shift+<)"));
}
else
{
if (this.tooltip != null)
{
this.tooltip.Active = false;
this.tooltip.Dispose();
}
}
}
/// <summary>
/// Initialize components FrmNewNote, set font, tooltip and richtextbox settings
/// </summary>
/// <param name="notes">Reference to notes class.</param>
private void ConstructFrmNewNote(Notes notes)
{
this.DoubleBuffered = Settings.ProgramFormsDoublebuffered;
this.InitializeComponent();
Strings.TranslateForm(this);
this.Size = new Size(Settings.NotesDefaultWidth, Settings.NotesDefaultHeight);
this.notes = notes;
this.SetFontSettings();
this.rtbNewNote.DetectUrls = Settings.HighlightHyperlinks;
this.tbTitle.Select();
}
/// <summary>
/// Plugin format button clicked.
/// </summary>
/// <param name="sender">The button clicked</param>
/// <param name="e">Event arguments</param>
private void btnPluginFormatBtn_Click(object sender, EventArgs e)
{
this.rtbNewNote.EnableAutoDragDrop = true;
for (int p = 0; p < PluginsManager.EnabledPlugins.Count; p++)
{
this.rtbNewNote.Rtf = PluginsManager.EnabledPlugins[p].NoteFormatBtnClicked(this.rtbNewNote, (Button)sender);
}
}
/// <summary>
/// Set all the form colors by the skinnr.
/// </summary>
/// <param name="skinnr">Skin number</param>
private void SetColorsForm(int skinnr)
{
this.BackColor = this.notes.GetPrimaryClr(skinnr);
this.pnlHeadNewNote.BackColor = this.notes.GetPrimaryClr(skinnr);
this.lbTextTitle.ForeColor = this.notes.GetTextClr(skinnr);
this.tbTitle.ForeColor = this.notes.GetTextClr(skinnr);
this.rtbNewNote.ForeColor = this.notes.GetTextClr(skinnr);
this.tbTitle.BackColor = this.notes.GetHighlightClr(skinnr);
this.rtbNewNote.BackColor = this.notes.GetSelectClr(skinnr);
this.btnTextBold.ForeColor = this.notes.GetTextClr(skinnr);
this.btnTextItalic.ForeColor = this.notes.GetTextClr(skinnr);
this.btnTextStriketrough.ForeColor = this.notes.GetTextClr(skinnr);
this.btnTextUnderline.ForeColor = this.notes.GetTextClr(skinnr);
this.btnTextBulletlist.ForeColor = this.notes.GetTextClr(skinnr);
this.btnFontBigger.ForeColor = this.notes.GetTextClr(skinnr);
this.btnFontSmaller.ForeColor = this.notes.GetTextClr(skinnr);
this.btnTextBold.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
this.btnTextItalic.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
this.btnTextStriketrough.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
this.btnTextUnderline.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
this.btnTextBulletlist.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
this.btnFontBigger.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
this.btnFontSmaller.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
if (this.notes.GetPrimaryTexture(skinnr) != null)
{
this.BackgroundImageLayout = this.notes.GetPrimaryTextureLayout(skinnr);
this.BackgroundImage = this.notes.GetPrimaryTexture(skinnr);
this.pnlHeadNewNote.BackColor = Color.Transparent;
this.lbTextTitle.BackColor = Color.Transparent;
this.lbTextTitle.BackColor = Color.Transparent;
}
this.CreatePluginButtons(skinnr);
}
/// <summary>
/// Create plugin buttons
/// </summary>
/// <param name="skinnr">The skin position</param>
private void CreatePluginButtons(int skinnr)
{
if (PluginsManager.EnabledPlugins != null)
{
for (int p = 0; p < PluginsManager.EnabledPlugins.Count; p++)
{
if (PluginsManager.EnabledPlugins[p].InitNoteFormatBtns() != null)
{
foreach (Button btnPluginFormatBtn in PluginsManager.EnabledPlugins[p].InitNoteFormatBtns())
{
this.tlpnlFormatbtn.ColumnCount += 1;
this.tlpnlFormatbtn.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize, 32));
btnPluginFormatBtn.Click += new EventHandler(this.btnPluginFormatBtn_Click);
btnPluginFormatBtn.FlatStyle = FlatStyle.Flat;
btnPluginFormatBtn.FlatAppearance.BorderColor = Color.Black;
btnPluginFormatBtn.ForeColor = this.notes.GetTextClr(skinnr);
btnPluginFormatBtn.FlatAppearance.MouseOverBackColor = this.notes.GetSelectClr(skinnr);
btnPluginFormatBtn.TabStop = false;
this.tlpnlFormatbtn.Controls.Add(btnPluginFormatBtn, this.tlpnlFormatbtn.ColumnCount - 1, 0);
}
}
}
}
}
/// <summary>
/// User pressed the accept note button. Note will now be saved.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnAddNote_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.tbTitle.Text))
{
this.tbTitle.Text = DateTime.Now.ToString();
}
else if (string.IsNullOrEmpty(this.rtbNewNote.Text))
{
string newnote_entercontent = Strings.T("Please enter some content.");
this.rtbNewNote.Text = newnote_entercontent;
this.rtbNewNote.Focus();
this.rtbNewNote.SelectAll();
}
else
{
if (this.note == null)
{
// new note
this.note = this.notes.AddNoteDefaultSettings(this.tbTitle.Text, Settings.NotesDefaultSkinnr, this.Location.X, this.Location.Y, this.Width, this.Height, this.rtbNewNote.Rtf, this.rtbNewNote.WordWrap);
}
else
{
// editing note, update note
this.note.Title = this.tbTitle.Text;
if (!xmlUtil.WriteNote(this.note, this.notes.GetSkinName(this.note.SkinNr), this.rtbNewNote.Rtf))
{
string newnote_exccantwritenote = Strings.T("Could not write note.");
throw new ApplicationException(newnote_exccantwritenote);
}
this.note.Tempcontent = this.rtbNewNote.Rtf;
this.note.Wordwarp = this.rtbNewNote.WordWrap;
this.note.CreateForm();
this.note.Tempcontent = null;
}
if (PluginsManager.EnabledPlugins != null)
{
for (int i = 0; i < PluginsManager.EnabledPlugins.Count; i++)
{
PluginsManager.EnabledPlugins[i].SavingNote(this.note.Filename, this.rtbNewNote.Rtf, this.note.Title);
}
}
Program.Formmanager.Frmneweditnoteopen = false;
SyntaxHighlight.DeinitHighlighter();
Program.Formmanager.FrmManageNotesNeedUpdate = true;
Program.Formmanager.RefreshFrmManageNotes();
this.Close();
GC.Collect();
}
}
/// <summary>
/// User pressed the cancel button, all things typed in FrmNewNote window will be lost.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnCancel_Click(object sender, EventArgs e)
{
Program.Formmanager.Frmneweditnoteopen = false;
if (this.note != null)
{
this.note.CreateForm();
}
Program.Formmanager.FrmManageNotesNeedUpdate = true;
Program.Formmanager.RefreshFrmManageNotes();
this.Close();
}
/// <summary>
/// Make note content text bold, or if the selected text is already bold
/// then remove the bold style.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnTextBold_Click(object sender, EventArgs e)
{
if (this.IsTextSelected())
{
int pos = this.rtbNewNote.SelectionStart;
int len = this.rtbNewNote.SelectionLength;
if (this.rtbNewNote.SelectionFont.Bold)
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, this.removestyle(this.rtbNewNote.SelectionFont.Style, FontStyle.Bold));
this.rtbNewNote.Rtf = this.rtfdirectedit.RemoveBoldTagsInRTF(this.rtbNewNote.Rtf, pos, len);
}
else
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, (this.rtbNewNote.SelectionFont.Style | System.Drawing.FontStyle.Bold));
this.rtbNewNote.Rtf = this.rtfdirectedit.AddBoldTagInRTF(this.rtbNewNote.Rtf, pos, len);
}
this.rtbNewNote.SelectionStart = pos;
this.rtbNewNote.SelectionLength = len;
}
this.rtbNewNote.Focus();
}
/// <summary>
/// Italic text
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnTextItalic_Click(object sender, EventArgs e)
{
if (this.IsTextSelected())
{
int pos = this.rtbNewNote.SelectionStart;
int len = this.rtbNewNote.SelectionLength;
if (this.rtbNewNote.SelectionFont.Italic)
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, this.removestyle(this.rtbNewNote.SelectionFont.Style, FontStyle.Italic));
this.rtbNewNote.Rtf = this.rtfdirectedit.RemoveItalicTagsInRTF(this.rtbNewNote.Rtf, pos, len);
}
else
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, (this.rtbNewNote.SelectionFont.Style | System.Drawing.FontStyle.Italic));
this.rtbNewNote.Rtf = this.rtfdirectedit.AddItalicTagInRTF(this.rtbNewNote.Rtf, pos, len);
}
this.rtbNewNote.SelectionStart = pos;
this.rtbNewNote.SelectionLength = len;
}
this.rtbNewNote.Focus();
}
/// <summary>
/// Striketrough text
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnTextStriketrough_Click(object sender, EventArgs e)
{
if (this.IsTextSelected())
{
int pos = this.rtbNewNote.SelectionStart;
int len = this.rtbNewNote.SelectionLength;
if (this.rtbNewNote.SelectionFont.Strikeout)
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, this.removestyle(this.rtbNewNote.SelectionFont.Style, FontStyle.Strikeout));
this.rtbNewNote.Rtf = this.rtfdirectedit.RemoveStrikeTagsInRTF(this.rtbNewNote.Rtf, pos, len);
}
else
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, (this.rtbNewNote.SelectionFont.Style | System.Drawing.FontStyle.Strikeout));
this.rtbNewNote.Rtf = this.rtfdirectedit.AddStrikeTagInRTF(this.rtbNewNote.Rtf, pos, len);
}
this.rtbNewNote.SelectionStart = pos;
this.rtbNewNote.SelectionLength = len;
}
this.rtbNewNote.Focus();
}
/// <summary>
/// Underline text
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnTextUnderline_Click(object sender, EventArgs e)
{
if (this.IsTextSelected())
{
int pos = this.rtbNewNote.SelectionStart;
int len = this.rtbNewNote.SelectionLength;
if (this.rtbNewNote.SelectionFont.Underline)
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, this.removestyle(this.rtbNewNote.SelectionFont.Style, FontStyle.Underline));
this.rtbNewNote.Rtf = this.rtfdirectedit.RemoveUnderlineTagsInRTF(this.rtbNewNote.Rtf, pos, len);
}
else
{
////this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, this.rtbNewNote.SelectionFont.SizeInPoints, (this.rtbNewNote.SelectionFont.Style | System.Drawing.FontStyle.Underline));
this.rtbNewNote.Rtf = this.rtfdirectedit.AddUnderlineTagInRTF(this.rtbNewNote.Rtf, pos, len);
}
this.rtbNewNote.SelectionStart = pos;
this.rtbNewNote.SelectionLength = len;
}
this.rtbNewNote.Focus();
}
/// <summary>
/// Make text bigger.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnFontBigger_Click(object sender, EventArgs e)
{
if (!this.IsTextSelected())
{
return;
}
if (this.rtbNewNote.SelectionFont == null)
{
Log.Write(LogType.exception, "Text has no font.");
return;
}
this.ChangeFontSizeSelected(this.rtbNewNote.SelectionFont.SizeInPoints + 1);
this.rtbNewNote.Focus();
}
/// <summary>
/// Make text smaller.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void btnFontSmaller_Click(object sender, EventArgs e)
{
if (!this.IsTextSelected())
{
return;
}
if (this.rtbNewNote.SelectionFont == null)
{
Log.Write(LogType.exception, "Text has no font.");
return;
}
this.ChangeFontSizeSelected(this.rtbNewNote.SelectionFont.SizeInPoints - 1);
this.rtbNewNote.Focus();
}
/// <summary>
/// Change the fontsize of the selected text limited from 6pt to 108pt.
/// </summary>
/// <param name="newsize">Event arguments</param>
private void ChangeFontSizeSelected(float newsize)
{
if ((newsize < 6) || (newsize > 108))
{
return;
}
else
{
this.rtbNewNote.SelectionFont = new System.Drawing.Font(this.rtbNewNote.SelectionFont.FontFamily, newsize, this.rtbNewNote.SelectionFont.Style);
}
}
/// <summary>
/// Check if selection length of rtbNote is larger than zero.
/// </summary>
/// <returns>true if length is larger than 0.</returns>
private bool IsTextSelected()
{
if (this.rtbNewNote.SelectedText.Length > 0 && this.rtbNewNote.SelectionStart >= 0)
{
return true;
}
return false;
}
/// <summary>
/// Check if menuCopyContent and menuCopyTitle should be enabled
/// and add plugin contenxt menu's
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void contextMenuStripTextActions_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
this.menuCopyContent.Enabled = false;
if (this.rtbNewNote.TextLength > 0)
{
this.menuCopyContent.Enabled = true;
}
this.menuCopyTitle.Enabled = false;
if (this.tbTitle.TextLength > 0)
{
this.menuCopyTitle.Enabled = true;
}
while (this.contextMenuStripTextActions.Items.Count > 8)
{
this.contextMenuStripTextActions.Items.RemoveAt(8);
}
if (PluginsManager.EnabledPlugins != null)
{
for (int i = 0; i < PluginsManager.EnabledPlugins.Count; i++)
{
if (PluginsManager.EnabledPlugins[i].InitFrmNewNoteMenu() != null)
{
ToolStripItem menuplugin = PluginsManager.EnabledPlugins[i].InitFrmNewNoteMenu();
menuplugin.Click += new EventHandler(this.menumain_Click);
this.contextMenuStripTextActions.Items.Add(menuplugin);
}
}
}
}
/// <summary>
/// Plugin menu in main contextmenu clicked
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void menumain_Click(object sender, EventArgs e)
{
if (PluginsManager.EnabledPlugins != null)
{
for (int i = 0; i < PluginsManager.EnabledPlugins.Count; i++)
{
ToolStripItem toolstripitemplugin = (ToolStripItem)sender;
this.rtbNewNote.Rtf = PluginsManager.EnabledPlugins[i].MenuFrmNewNoteClicked(this.rtbNewNote, toolstripitemplugin);
}
}
}
/// <summary>
/// Copy the note content.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void copyTextToolStripMenuItem_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.rtbNewNote.Text))
{
Log.Write(LogType.error, "No content to copy.");
}
else
{
Clipboard.SetText(this.rtbNewNote.Text);
}
}
/// <summary>
/// Check whether pastTextToolStripMenuItem should be enabled.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void copyTextToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
if (Clipboard.ContainsText())
{
this.menuPasteTo.Enabled = true;
}
else
{
this.menuPasteTo.Enabled = false;
}
}
/// <summary>
/// Form got focus, remove transparency.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void frmNewNote_Activated(object sender, EventArgs e)
{
if (Settings.NotesTransparencyEnabled)
{
this.Opacity = 1.0;
}
}
/// <summary>
/// Form lost focus, make transparent.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void frmNewNote_Deactivate(object sender, EventArgs e)
{
if (Settings.NotesTransparencyEnabled)
{
this.Opacity = Settings.NotesTransparencyLevel;
this.Refresh();
}
}
/// <summary>
/// Import a file as note.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void importToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofdlgimportnote = new OpenFileDialog();
StringBuilder sbfilter = new StringBuilder();
sbfilter.Append(Strings.T("Plain text file (*.txt)")).Append("|*.txt|");
sbfilter.Append(Strings.T("RTF file (*.rtf)")).Append("|*.rtf|");
sbfilter.Append(Strings.T("KeyNote NF note (*.knt)")).Append("|*.knt|");
sbfilter.Append(Strings.T("TomBoy note (*.note)")).Append("|*.note|");
sbfilter.Append(Strings.T("MicroSE note (*.not)")).Append("|*.not|");
sbfilter.Append(Strings.T("QuickPad note (*.qpn)")).Append("|*.qpn");
ofdlgimportnote.Filter = sbfilter.ToString();
ofdlgimportnote.Title = Strings.T("import single (note)file");
DialogResult dlgresopennote = ofdlgimportnote.ShowDialog();
if (dlgresopennote == DialogResult.OK)
{
StreamReader reader = null;
try
{
if (File.Exists(ofdlgimportnote.FileName))
{
reader = new StreamReader(ofdlgimportnote.FileName, true); // detect encoding
ImportNotes importnote = new ImportNotes(this.notes);
switch (ofdlgimportnote.FilterIndex)
{
case 1:
importnote.ReadTextfile(reader, this.rtbNewNote);
break;
case 2:
importnote.ReadRTFfile(reader, this.rtbNewNote);
break;
case 3:
importnote.ReadKeyNotefile(reader, this.rtbNewNote);
break;
case 4:
importnote.ReadTomboyfile(reader, ofdlgimportnote.FileName, this.tbTitle, this.rtbNewNote);
break;
case 5:
importnote.ReadMicroSENotefile(reader, this.tbTitle, this.rtbNewNote);
break;
case 6:
importnote.ReadQuickpadFile(reader, this.tbTitle, this.rtbNewNote);
break;
}
}
}
finally
{
reader.Close();
}
}
}
/// <summary>
/// Set this note ontop, CheckOnClick is set to true.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void menuStickyOnTop_Click(object sender, EventArgs e)
{
this.TopMost = this.menuStickyOnTop.Checked;
}
/// <summary>
/// Pasting text as note content.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void pastTextToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Clipboard.ContainsText())
{
this.rtbNewNote.Text = this.rtbNewNote.Text + Clipboard.GetText();
if (SyntaxHighlight.KeywordsInitialized)
{
SyntaxHighlight.InitHighlighter();
}
SyntaxHighlight.CheckSyntaxFull(this.rtbNewNote, this.GetSkinnr(), this.notes);
}
else
{
string newnote_emptyclipboard = Strings.T("There is no text on the clipboard.");
MessageBox.Show(newnote_emptyclipboard);
Log.Write(LogType.error, newnote_emptyclipboard);
}
}
/// <summary>
/// Resizing the FtmNewNote form.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Mouse event arguments</param>
private void pbResizeGrip_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Cursor = Cursors.SizeNWSE;
this.Size = new Size(this.PointToClient(MousePosition).X, this.PointToClient(MousePosition).Y);
}
this.Cursor = Cursors.Default;
}
/// <summary>
/// Moving the note.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Mouse event arguments</param>
private void pnlHeadNewNote_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.moving = true;
this.oldp = e.Location;
if (this.note != null)
{
this.pnlHeadNewNote.BackColor = this.notes.GetSelectClr(this.note.SkinNr);
}
else
{
this.pnlHeadNewNote.BackColor = this.notes.GetSelectClr(Settings.NotesDefaultSkinnr);
}
}
}
/// <summary>
/// Move note if pnlHead is being left clicked.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Mouse event arguments</param>
private void pnlHeadNewNote_MouseMove(object sender, MouseEventArgs e)
{
if (this.moving && e.Button == MouseButtons.Left)
{
if (this.note != null)
{
this.pnlHeadNewNote.BackColor = this.notes.GetSelectClr(this.note.SkinNr);
}
else
{
this.pnlHeadNewNote.BackColor = this.notes.GetSelectClr(Settings.NotesDefaultSkinnr);
}
int dpx = e.Location.X - this.oldp.X;
int dpy = e.Location.Y - this.oldp.Y;
if (Program.CurrentOS == Program.OS.LINUX) {
// workround limit the moving of this window under mono/linux so this window cannot move uncontrolled a lot.
if (dpx > 8)
{
dpx = 8;
}
else if (dpx < -8)
{
dpx = -8;
}
if (dpy > 8)
{
dpy = 8;
}
else if (dpy < -8)
{
dpy = -8;
}
}
this.Location = new Point(this.Location.X + dpx, this.Location.Y + dpy);
}
}
/// <summary>
/// End moving note.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void pnlHeadNewNote_MouseUp(object sender, MouseEventArgs e)
{
this.moving = false;
if (this.note != null)
{
this.pnlHeadNewNote.BackColor = this.notes.GetPrimaryClr(this.note.SkinNr);
if (this.BackgroundImage != null)
{
this.pnlHeadNewNote.BackColor = Color.Transparent;
}
}
else
{
this.pnlHeadNewNote.BackColor = this.notes.GetPrimaryClr(Settings.NotesDefaultSkinnr);
}
}
/// <summary>
/// Removes 1 fontsyle from the fontsyles of the checkstyle rtb text.
/// This methode does not check if selection lenght is okay.
/// </summary>
/// <param name="checkstyles">The FontStyle apply operations on.</param>
/// <param name="removestyle">The FontStyle to remove.</param>
/// <returns>The new fontstyle</returns>
private FontStyle removestyle(FontStyle checkstyles, FontStyle removestyle)
{
FontStyle newstyles = checkstyles;
newstyles -= removestyle;
return newstyles;
}
/// <summary>
/// User entered the note content box.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void rtbNote_Enter(object sender, EventArgs e)
{
if (this.note != null)
{
this.rtbNewNote.BackColor = this.notes.GetHighlightClr(this.note.SkinNr);
}
else
{
this.rtbNewNote.BackColor = this.notes.GetHighlightClr(Settings.NotesDefaultSkinnr);
}
this.SetToolbarEnabled(true);
}
/// <summary>
/// User leaved the note content box.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void rtbNote_Leave(object sender, EventArgs e)
{
if (this.note != null)
{
this.rtbNewNote.BackColor = this.notes.GetSelectClr(this.note.SkinNr);
}
else
{
this.rtbNewNote.BackColor = this.notes.GetSelectClr(Settings.NotesDefaultSkinnr);
}
}
/// <summary>
/// A hyperlink is clicked, check settings to see if confirm launch dialog have
/// to be showed, if not then directly launch the URL.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event arguments</param>
private void rtbNote_LinkClicked(object sender, LinkClickedEventArgs e)
{
Program.LoadLink(e.LinkText, true);
}
/// <summary>
/// Force context menu to show up.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Mouse event arguments</param>
private void rtbNote_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.contextMenuStripTextActions.Show(this.Location.X + e.X, this.Location.X + e.Y);
}
}
/// <summary>
/// Set the font and textdirection FrmNewNote.
/// </summary>
private void SetFontSettings()
{
this.tbTitle.Font = new Font(Settings.FontTitleFamily, 11);
this.rtbNewNote.Font = new Font(Settings.FontContentFamily, this.rtbNewNote.Font.Size);
switch (Settings.FontTextdirection)
{
case 0:
this.tbTitle.RightToLeft = RightToLeft.No;
this.rtbNewNote.RightToLeft = RightToLeft.No;
break;
case 1:
this.tbTitle.RightToLeft = RightToLeft.Yes;
this.rtbNewNote.RightToLeft = RightToLeft.Yes;
break;
default:
this.tbTitle.RightToLeft = RightToLeft.No;
this.rtbNewNote.RightToLeft = RightToLeft.No;
break;
}
this.rtbNewNote.Focus();
this.rtbNewNote.Select();
this.BringToFront();
}
/// <summary>
/// Toggle toolbar buttons.
/// </summary>
/// <param name="enabled">True if toolbar should be enabled.</param>
private void SetToolbarEnabled(bool enabled)
{