[C#/WINFORM/SCINTILLA] Scintilla 클래스 : 코드 편집기(Code Editor) 만들기
■ Scintilla 클래스를 사용해 코드 편집기(Code Editor)를 만드는 방법을 보여준다. ▶ HotKeyManager.cs
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 |
using System; using System.Windows.Forms; namespace TestProject { /// <summary> /// 핫키 관리자 /// </summary> internal class HotKeyManager { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 이용 가능 여부 /// </summary> public static bool Enable = true; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 핫 키 여부 구하기 - IsHotkey(e, key, ctrl, shift, alt) /// <summary> /// 핫 키 여부 구하기 /// </summary> /// <param name="e">이벤트 인자</param> /// <param name="key">키</param> /// <param name="ctrl">CTRL 키 눌림 여부</param> /// <param name="shift">SHIFT 키 눌림 여부</param> /// <param name="alt">ALT 키 눌림 여부</param> /// <returns>핫 키 여부</returns> public static bool IsHotkey(KeyEventArgs e, Keys key, bool ctrl = false, bool shift = false, bool alt = false) { return e.KeyCode == key && e.Control == ctrl && e.Shift == shift && e.Alt == alt; } #endregion #region 핫 키 추가하기 - AddHotKey(form, action, key, ctrl, shift, alt) /// <summary> /// 핫키 추가하기 /// </summary> /// <param name="form">폼</param> /// <param name="action">액션</param> /// <param name="key">키</param> /// <param name="ctrl">CTRL 키 눌림 여부</param> /// <param name="shift">SHIFT 키 눌림 여부</param> /// <param name="alt">ALT 키 눌림 여부</param> public static void AddHotKey(Form form, Action action, Keys key, bool ctrl = false, bool shift = false, bool alt = false) { form.KeyPreview = true; form.KeyDown += delegate(object sender, KeyEventArgs e) { if(IsHotkey(e, key, ctrl, shift, alt)) { action(); } }; } #endregion } } |
▶ SearchManager.cs
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 |
using System.Windows.Forms; using ScintillaNET; namespace TestProject { /// <summary> /// 검색 관리자 /// </summary> internal class SearchManager { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 에디터 /// </summary> public static Scintilla Editor; /// <summary> /// 검색 텍스트 박스 /// </summary> public static TextBox SearchTextBox; /// <summary> /// 마지막 검색 문자열 /// </summary> public static string LastSearchString = string.Empty; /// <summary> /// 마지막 검색 인덱스 /// </summary> public static int LastSearchIndex; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 찾기 - Find(next, incremental) /// <summary> /// 찾기 /// </summary> /// <param name="next">다음 찾기 여부</param> /// <param name="incremental">증분 검색 여부</param> public static void Find(bool next, bool incremental) { LastSearchString = SearchTextBox.Text; if(LastSearchString.Length > 0) { if(next) { Editor.TargetStart = LastSearchIndex - 1; Editor.TargetEnd = LastSearchIndex + (LastSearchString.Length + 1); Editor.SearchFlags = SearchFlags.None; if(!incremental || Editor.SearchInTarget(LastSearchString) == -1) { Editor.TargetStart = Editor.CurrentPosition; Editor.TargetEnd = Editor.TextLength; Editor.SearchFlags = SearchFlags.None; if(Editor.SearchInTarget(LastSearchString) == -1) { Editor.TargetStart = 0; Editor.TargetEnd = Editor.TextLength; if(Editor.SearchInTarget(LastSearchString) == -1) { Editor.ClearSelections(); return; } } } } else { Editor.TargetStart = 0; Editor.TargetEnd = Editor.CurrentPosition; Editor.SearchFlags = SearchFlags.None; if(Editor.SearchInTarget(LastSearchString) == -1) { Editor.TargetStart = Editor.CurrentPosition; Editor.TargetEnd = Editor.TextLength; if(Editor.SearchInTarget(LastSearchString) == -1) { Editor.ClearSelections(); return; } } } LastSearchIndex = Editor.TargetStart; Editor.SetSelection(Editor.TargetEnd, Editor.TargetStart); Editor.ScrollCaret(); } SearchTextBox.Focus(); } #endregion } } |
▶ MainForm.cs
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
using System; using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; using ScintillaNET; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 배경 색상 /// </summary> private const int BACKGROUND_COLOR = 0x2A211C; /// <summary> /// 전경 색상 /// </summary> private const int FOREGROUND_COLOR = 0xB7B7B7; /// <summary> /// 코드 폴딩 원 여부 /// </summary> private const bool CODEFOLDING_CIRCULAR = true; /// <summary> /// 키워드 배열 1 /// </summary> private string[] keywordArray1 = new string[] { "abstract", "arguments", "as", "AS3", "author", "base", "bool", "break", "by", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "copy", "decimal", "default", "delegate", "delete", "deprecated", "descending", "do", "double", "dynamic", "each", "else", "enum", "event", "eventType", "example", "exampleText", "exception", "explicit", "extends", "extern", "false", "final", "finally", "fixed", "float", "for", "foreach", "from", "function", "get", "goto", "group", "haxe", "if", "implements", "implicit", "import", "in", "include", "Infinity", "inheritDoc", "instanceof", "int", "interface", "internal", "into", "intrinsic", "is", "langversion", "link", "lock", "long", "mtasc", "mxmlc", "namespace", "NaN", "native", "new", "null", "object", "operator", "orderby", "out", "override", "package", "param", "params", "partial", "playerversion", "private", "productversion", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "see", "select", "serial", "serialData", "serialField", "set", "short", "since", "sizeof", "stackalloc", "static", "string", "struct", "super", "switch", "this", "throw", "throws", "true", "try", "typeof", "uint", "ulong", "unchecked", "undefined", "unsafe", "usage", "use", "ushort", "using", "var", "version", "virtual", "void", "volatile", "where", "while", "with", "yield" }; /// <summary> /// 키워드 배열 2 /// </summary> private string[] keywordArray2 = new string[] { "ArgumentError", "Array", "Boolean", "Byte", "Char", "Class", "Date", "DateTime", "Decimal", "DefinitionError", "Double", "Error", "EvalError", "File", "Forms", "Function", "Int16", "Int32", "Int64", "IntPtr", "Math", "Namespace", "Null", "Number", "Object", "Path", "RangeError", "ReferenceError", "RegExp", "SByte", "ScintillaNET", "SecurityError", "Single", "String", "SyntaxError", "System", "TypeError", "UInt16", "UInt32", "UInt64", "UIntPtr", "Void", "Windows", "XML", "XMLList", "arguments", "int", "uint", "void" }; /// <summary> /// 검색 패널 오픈 여부 /// </summary> bool isSearchPanelOpen = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.scintilla.Dock = DockStyle.Fill; this.scintilla.WrapMode = WrapMode.None; this.scintilla.IndentationGuides = IndentView.LookBoth; this.scintilla.SetSelectionBackColor(true, GetColor(0x114D9C)); this.scintilla.StyleResetDefault(); this.scintilla.Styles[Style.Default].BackColor = GetColor(0x212121); this.scintilla.Styles[Style.Default].ForeColor = GetColor(0xFFFFFF); this.scintilla.Styles[Style.Default].Font = "나눔고딕코딩"; this.scintilla.Styles[Style.Default].Size = 12; this.scintilla.StyleClearAll(); this.scintilla.Styles[Style.Cpp.Identifier ].ForeColor = GetColor(0xD0DAE2); this.scintilla.Styles[Style.Cpp.Comment ].ForeColor = GetColor(0xBD758B); this.scintilla.Styles[Style.Cpp.CommentLine ].ForeColor = GetColor(0x40BF57); this.scintilla.Styles[Style.Cpp.CommentDoc ].ForeColor = GetColor(0x2FAE35); this.scintilla.Styles[Style.Cpp.Number ].ForeColor = GetColor(0xFFFF00); this.scintilla.Styles[Style.Cpp.String ].ForeColor = GetColor(0xFFFF00); this.scintilla.Styles[Style.Cpp.Character ].ForeColor = GetColor(0xE95454); this.scintilla.Styles[Style.Cpp.Preprocessor ].ForeColor = GetColor(0x8AAFEE); this.scintilla.Styles[Style.Cpp.Operator ].ForeColor = GetColor(0xE0E0E0); this.scintilla.Styles[Style.Cpp.Regex ].ForeColor = GetColor(0xff00ff); this.scintilla.Styles[Style.Cpp.CommentLineDoc ].ForeColor = GetColor(0x77A7DB); this.scintilla.Styles[Style.Cpp.Word ].ForeColor = GetColor(0x48A8EE); this.scintilla.Styles[Style.Cpp.Word2 ].ForeColor = GetColor(0xF98906); this.scintilla.Styles[Style.Cpp.CommentDocKeyword ].ForeColor = GetColor(0xB3D991); this.scintilla.Styles[Style.Cpp.CommentDocKeywordError].ForeColor = GetColor(0xFF0000); this.scintilla.Styles[Style.Cpp.GlobalClass ].ForeColor = GetColor(0x48A8EE); this.scintilla.Lexer = Lexer.Cpp; this.scintilla.SetKeywords(0, ConnectString(this.keywordArray1, " ")); this.scintilla.SetKeywords(1, ConnectString(this.keywordArray2, " ")); this.scintilla.Styles[Style.LineNumber ].BackColor = GetColor(BACKGROUND_COLOR); this.scintilla.Styles[Style.LineNumber ].ForeColor = GetColor(FOREGROUND_COLOR); this.scintilla.Styles[Style.IndentGuide].ForeColor = GetColor(FOREGROUND_COLOR); this.scintilla.Styles[Style.IndentGuide].BackColor = GetColor(BACKGROUND_COLOR); this.scintilla.Margins[1].Width = 30; this.scintilla.Margins[1].Type = MarginType.Number; this.scintilla.Margins[1].Mask = 0; this.scintilla.Margins[1].Sensitive = true; this.scintilla.Margins[2].Width = 20; this.scintilla.Margins[2].Type = MarginType.Symbol; this.scintilla.Markers[2].Symbol = MarkerSymbol.Circle; this.scintilla.Margins[2].Mask = (1 << 2); this.scintilla.Margins[2].Sensitive = true; this.scintilla.Markers[2].SetBackColor(GetColor(0xFF003B)); this.scintilla.Markers[2].SetForeColor(GetColor(0x000000)); this.scintilla.Markers[2].SetAlpha(100); this.scintilla.SetFoldMarginColor (true, GetColor(BACKGROUND_COLOR)); this.scintilla.SetFoldMarginHighlightColor(true, GetColor(BACKGROUND_COLOR)); this.scintilla.SetProperty("fold" , "1"); this.scintilla.SetProperty("fold.compact", "1"); this.scintilla.Margins[3].Width = 20; this.scintilla.Margins[3].Type = MarginType.Symbol; this.scintilla.Margins[3].Mask = Marker.MaskFolders; this.scintilla.Margins[3].Sensitive = true; for(int i = 25; i <= 31; i++) { this.scintilla.Markers[i].SetForeColor(GetColor(BACKGROUND_COLOR)); this.scintilla.Markers[i].SetBackColor(GetColor(FOREGROUND_COLOR)); } this.scintilla.Markers[Marker.Folder ].Symbol = CODEFOLDING_CIRCULAR ? MarkerSymbol.CirclePlus : MarkerSymbol.BoxPlus; this.scintilla.Markers[Marker.FolderOpen ].Symbol = CODEFOLDING_CIRCULAR ? MarkerSymbol.CircleMinus : MarkerSymbol.BoxMinus; this.scintilla.Markers[Marker.FolderEnd ].Symbol = CODEFOLDING_CIRCULAR ? MarkerSymbol.CirclePlusConnected : MarkerSymbol.BoxPlusConnected; this.scintilla.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner; this.scintilla.Markers[Marker.FolderOpenMid].Symbol = CODEFOLDING_CIRCULAR ? MarkerSymbol.CircleMinusConnected : MarkerSymbol.BoxMinusConnected; this.scintilla.Markers[Marker.FolderSub ].Symbol = MarkerSymbol.VLine; this.scintilla.Markers[Marker.FolderTail ].Symbol = MarkerSymbol.LCorner; this.scintilla.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change); this.scintilla.AllowDrop = true; this.scintilla.ClearCmdKey(Keys.Control | Keys.F); this.scintilla.ClearCmdKey(Keys.Control | Keys.L); this.scintilla.ClearCmdKey(Keys.Control | Keys.U); HotKeyManager.AddHotKey(this, OpenSearchPanel , Keys.F , true); HotKeyManager.AddHotKey(this, Uppercase , Keys.U , true); HotKeyManager.AddHotKey(this, Lowercase , Keys.L , true); HotKeyManager.AddHotKey(this, ZoomIn , Keys.Oemplus , true); HotKeyManager.AddHotKey(this, ZoomOut , Keys.OemMinus, true); HotKeyManager.AddHotKey(this, ResetZoom , Keys.D0 , true); HotKeyManager.AddHotKey(this, CloseSearchPanel, Keys.Escape ); this.Load += Form_Load; this.openMenuItem.Click += openMenuItem_Click; this.cutMenuItem.Click += cutMenuItem_Click; this.copyMenuItem.Click += copyMenuItem_Click; this.pasteMenuItem.Click += pasteMenuItem_Click; this.selectLineMenuItem.Click += selectLineMenuItem_Click; this.selectAllMenuItem.Click += selectAllMenuItem_Click; this.clearSelectionMenuItem.Click += clearSelectionMenuItem_Click; this.indentMenuItem.Click += indentMenuItem_Click; this.outdentMenuItem.Click += outdentMenuItem_Click; this.uppercaseMenuItem.Click += uppercaseMenuItem_Click; this.lowercaseMenuItem.Click += lowercaseMenuItem_Click; this.findMenuItem.Click += findMenuItem_Click; this.wordWrapMenuItem.Click += wordWrapMenuItem_Click; this.showIndentGuideMenuItem.Click += showIndentGuideMenuItem_Click; this.showWhitespaceMenuItem.Click += showWhitespaceMenuItem_Click; this.zoomInMenuItem.Click += zoomInMenuItem_Click; this.zoomOutMenuItem.Click += zoomOutMenuItem_Click; this.zoom100MenuItem.Click += zoom100MenuItem_Click; this.collapseAllMenuItem.Click += collapseAllMenuItem_Click; this.expandAllMenuItem.Click += expandAllMenuItem_Click; this.searchTextBox.KeyDown += searchTextBox_KeyDown; this.searchTextBox.TextChanged += searchTextBox_TextChanged; this.searchPreviousButton.Click += searchPreviousButton_Click; this.searchNextButton.Click += searchNextButton_Click; this.searchCloseButton.Click += searchCloseButton_Click; this.scintilla.MarginClick += scintilla_MarginClick; this.scintilla.DragEnter += scintilla_DragEnter; this.scintilla.DragDrop += scintilla_DragDrop; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 폼 로드시 처리하기 - Form_Load(sender, e) /// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_Load(object sender, EventArgs e) { LoadFile("../../MainForm.cs"); } #endregion #region 열기 메뉴 항목 클릭시 처리하기 - openMenuItem_Click(sender, e) /// <summary> /// 열기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void openMenuItem_Click(object sender, EventArgs e) { if(this.openFileDialog.ShowDialog() == DialogResult.OK) { LoadFile(this.openFileDialog.FileName); } } #endregion #region 잘라내기 메뉴 항목 클릭시 처리하기 - cutMenuItem_Click(sender, e) /// <summary> /// 잘라내기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void cutMenuItem_Click(object sender, EventArgs e) { this.scintilla.Cut(); } #endregion #region 복사하기 메뉴 항목 클릭시 처리하기 - copyMenuItem_Click(sender, e) /// <summary> /// 복사하기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void copyMenuItem_Click(object sender, EventArgs e) { this.scintilla.Copy(); } #endregion #region 붙여넣기 메뉴 항목 클릭시 처리하기 - pasteMenuItem_Click(sender, e) /// <summary> /// 붙여넣기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void pasteMenuItem_Click(object sender, EventArgs e) { this.scintilla.Paste(); } #endregion #region 줄 선택하기 메뉴 항목 클릭시 처리하기 - selectLineMenuItem_Click(sender, e) /// <summary> /// 줄 선택하기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void selectLineMenuItem_Click(object sender, EventArgs e) { Line line = this.scintilla.Lines[this.scintilla.CurrentLine]; this.scintilla.SetSelection(line.Position + line.Length, line.Position); } #endregion #region 모두 선택하기 메뉴 항목 클릭시 처리하기 - selectAllMenuItem_Click(sender, e) /// <summary> /// 모두 선택하기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void selectAllMenuItem_Click(object sender, EventArgs e) { this.scintilla.SelectAll(); } #endregion #region 선택 지우기 메뉴 항목 클릭시 처리하기 - clearSelectionMenuItem_Click(sender, e) /// <summary> /// 선택 지우기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void clearSelectionMenuItem_Click(object sender, EventArgs e) { this.scintilla.SetEmptySelection(0); } #endregion #region 들여쓰기 메뉴 항목 클릭시 처리하기 - indentMenuItem_Click(sender, e) /// <summary> /// 들여쓰기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void indentMenuItem_Click(object sender, EventArgs e) { Indent(); } #endregion #region 내어쓰기 메뉴 항목 클릭시 처리하기 - outdentMenuItem_Click(sender, e) /// <summary> /// 내어쓰기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void outdentMenuItem_Click(object sender, EventArgs e) { Outdent(); } #endregion #region 대문자 메뉴 항목 클릭시 처리하기 - upperCaseMenuItem_Click(sender, e) /// <summary> /// 대문자 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void uppercaseMenuItem_Click(object sender, EventArgs e) { Uppercase(); } #endregion #region 소문자 메뉴 항목 클릭시 처리하기 - lowerCaseMenuItem_Click(sender, e) /// <summary> /// 소문자 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void lowercaseMenuItem_Click(object sender, EventArgs e) { Lowercase(); } #endregion #region 빨리 찾기 메뉴 항목 클릭시 처리하기 - findQuicklyMenuItem_Click(sender, e) /// <summary> /// 빨리 찾기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void findMenuItem_Click(object sender, EventArgs e) { OpenSearchPanel(); } #endregion #region 자동 줄 바꿈 메뉴 항목 클릭시 처리하기 - wordWrapMenuItem_Click(sender, e) /// <summary> /// 자동 줄 바꿈 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void wordWrapMenuItem_Click(object sender, EventArgs e) { this.wordWrapMenuItem.Checked = !this.wordWrapMenuItem.Checked; this.scintilla.WrapMode = this.wordWrapMenuItem.Checked ? WrapMode.Word : WrapMode.None; } #endregion #region 들여쓰기 가이드 표시 메뉴 항목 클릭시 처리하기 - showIndentGuideMenuItem_Click(sender, e) /// <summary> /// 들여쓰기 가이드 표시 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void showIndentGuideMenuItem_Click(object sender, EventArgs e) { this.showIndentGuideMenuItem.Checked = !this.showIndentGuideMenuItem.Checked; this.scintilla.IndentationGuides = this.showIndentGuideMenuItem.Checked ? IndentView.LookBoth : IndentView.None; } #endregion #region 공백 표시하기 메뉴 항목 클릭시 처리하기 - showWhitespaceMenuItem_Click(sender, e) /// <summary> /// 공백 표시하기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void showWhitespaceMenuItem_Click(object sender, EventArgs e) { this.showWhitespaceMenuItem.Checked = !this.showWhitespaceMenuItem.Checked; this.scintilla.ViewWhitespace = this.showWhitespaceMenuItem.Checked ? WhitespaceMode.VisibleAlways : WhitespaceMode.Invisible; } #endregion #region 확대 메뉴 항목 클릭시 처리하기 - zoomInMenuItem_Click(sender, e) /// <summary> /// 확대 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void zoomInMenuItem_Click(object sender, EventArgs e) { ZoomIn(); } #endregion #region 축소 메뉴 항목 클릭시 처리하기 - zoomOutMenuItem_Click(sender, e) /// <summary> /// 축소 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void zoomOutMenuItem_Click(object sender, EventArgs e) { ZoomOut(); } #endregion #region 100% 크기 메뉴 항목 클릭시 처리하기 - zoom100MenuItem_Click(sender, e) /// <summary> /// 100% 크기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void zoom100MenuItem_Click(object sender, EventArgs e) { ResetZoom(); } #endregion #region 모두 축소하기 메뉴 항목 클릭시 처리하기 - collapseAllMenuItem_Click(sender, e) /// <summary> /// 모두 축소하기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void collapseAllMenuItem_Click(object sender, EventArgs e) { this.scintilla.FoldAll(FoldAction.Contract); } #endregion #region 모두 확장하기 메뉴 항목 클릭시 처리하기 - expandAllMenuItem_Click(sender, e) /// <summary> /// 모두 확장하기 메뉴 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void expandAllMenuItem_Click(object sender, EventArgs e) { this.scintilla.FoldAll(FoldAction.Expand); } #endregion #region 조회/닫기 버튼 클릭시 처리하기 - searchCloseButton_Click(sender, e) /// <summary> /// 조회/닫기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void searchCloseButton_Click(object sender, EventArgs e) { CloseSearchPanel(); } #endregion #region 조회/이전 버튼 클릭시 처리하기 - searchPreviousButton_Click(sender, e) /// <summary> /// 조회/이전 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void searchPreviousButton_Click(object sender, EventArgs e) { SearchManager.Find(false, false); } #endregion #region 조회/다음 버튼 클릭시 처리하기 - searchNextButton_Click(sender, e) /// <summary> /// 조회/다음 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void searchNextButton_Click(object sender, EventArgs e) { SearchManager.Find(true, false); } #endregion #region 조회 텍스트 박스 키 DOWN 처리하기 - searchTextBox_KeyDown(sender, e) /// <summary> /// 조회 텍스트 박스 키 DOWN 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void searchTextBox_KeyDown(object sender, KeyEventArgs e) { if(HotKeyManager.IsHotkey(e, Keys.Enter)) { SearchManager.Find(true, false); } if(HotKeyManager.IsHotkey(e, Keys.Enter, true) || HotKeyManager.IsHotkey(e, Keys.Enter, false, true)) { SearchManager.Find(false, false); } } #endregion #region 조회 텍스트 박스 텍스트 변경시 처리하기 - searchTextBox_TextChanged(sender, e) /// <summary> /// 조회 텍스트 박스 텍스트 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void searchTextBox_TextChanged(object sender, EventArgs e) { SearchManager.Find(true, true); } #endregion #region SCINTILLA 마진 클릭시 처리하기 - scintilla_MarginClick(sender, e) /// <summary> /// SCINTILLA 마진 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void scintilla_MarginClick(object sender, MarginClickEventArgs e) { Scintilla scintilla = sender as Scintilla; if(e.Margin == 2) { const uint mask = (1 << 2); Line line = scintilla.Lines[scintilla.LineFromPosition(e.Position)]; if((line.MarkerGet() & mask) > 0) { line.MarkerDelete(2); } else { line.MarkerAdd(2); } } } #endregion #region SCINTILLA 드래그 진입시 처리하기 - scintilla_DragEnter(sender, e) /// <summary> /// SCINTILLA 드래그 진입시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void scintilla_DragEnter(object sender, DragEventArgs e) { if(e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } #endregion #region SCINTILLA 드래그 DROP 처리하기 - scintilla_DragDrop(sender, e) /// <summary> /// SCINTILLA 드래그 DROP 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void scintilla_DragDrop(object sender, DragEventArgs e) { if(e.Data.GetDataPresent(DataFormats.FileDrop)) { Array array = (Array)e.Data.GetData(DataFormats.FileDrop); if(array != null) { string filePath = array.GetValue(0).ToString(); LoadFile(filePath); } } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 색상 구하기 - GetColor(rgb) /// <summary> /// 색상 구하기 /// </summary> /// <param name="rgb">RGB 값</param> /// <returns>색상</returns> private Color GetColor(int rgb) { return Color.FromArgb(255, (byte)(rgb >> 16), (byte)(rgb >> 8), (byte)rgb); } #endregion #region 액션 호출하기 - InvokeAction(action) /// <summary> /// 액션 호출하기 /// </summary> /// <param name="action">액션</param> public void InvokeAction(Action action) { if(InvokeRequired) { BeginInvoke(action); } else { action.Invoke(); } } #endregion #region 문자열 연결하기 - ConnectString(sourceArray, link) /// <summary> /// 문자열 연결하기 /// </summary> /// <param name="sourceArray">소스 문자열 배열</param> /// <param name="link">연결 문자열</param> /// <returns>연결 문자열</returns> private string ConnectString(string[] sourceArray, string link) { StringBuilder stringBuilder = new StringBuilder(); for(int i = 0; i < sourceArray.Length; i++) { if(sourceArray[i].Length > 0) { if(stringBuilder.Length > 0) { stringBuilder.Append(link); } stringBuilder.Append(sourceArray[i]); } } return stringBuilder.ToString(); } #endregion #region 파일 로드하기 - LoadFile(filePath) /// <summary> /// 파일 로드하기 /// </summary> /// <param name="filePath">파일 경로</param> private void LoadFile(string filePath) { if(File.Exists(filePath)) { this.fileNameLabel.Text = Path.GetFileName(filePath); this.scintilla.Text = File.ReadAllText(filePath); } } #endregion #region 키 보내기 - SendKeys(keyString) /// <summary> /// 키 보내기 /// </summary> /// <param name="keyString">키 문자열</param> private void SendKeys(string keyString) { HotKeyManager.Enable = false; this.scintilla.Focus(); System.Windows.Forms.SendKeys.Send(keyString); HotKeyManager.Enable = true; } #endregion #region 들여쓰기 - Indent() /// <summary> /// 들여쓰기 /// </summary> private void Indent() { SendKeys("{TAB}"); } #endregion #region 내어쓰기 - Outdent() /// <summary> /// 내어쓰기 /// </summary> private void Outdent() { SendKeys("+{TAB}"); } #endregion #region 대문자로 변경하기 - Uppercase() /// <summary> /// 대문자로 변경하기 /// </summary> private void Uppercase() { int start = this.scintilla.SelectionStart; int end = this.scintilla.SelectionEnd; this.scintilla.ReplaceSelection(this.scintilla.GetTextRange(start, end - start).ToUpper()); this.scintilla.SetSelection(start, end); } #endregion #region 소문자로 변경하기 - Lowercase() /// <summary> /// 소문자로 변경하기 /// </summary> private void Lowercase() { int start = this.scintilla.SelectionStart; int end = this.scintilla.SelectionEnd; this.scintilla.ReplaceSelection(this.scintilla.GetTextRange(start, end - start).ToLower()); this.scintilla.SetSelection(start, end); } #endregion #region 검색 패널 열기 - OpenSearchPanel() /// <summary> /// 검색 패널 열기 /// </summary> private void OpenSearchPanel() { SearchManager.SearchTextBox = this.searchTextBox; SearchManager.Editor = this.scintilla; if(!this.isSearchPanelOpen) { this.isSearchPanelOpen = true; InvokeAction ( delegate() { this.searchPanel.Visible = true; this.searchTextBox.Text = SearchManager.LastSearchString; this.searchTextBox.Focus(); this.searchTextBox.SelectAll(); } ); } else { InvokeAction ( delegate() { this.searchTextBox.Focus(); this.searchTextBox.SelectAll(); } ); } } #endregion #region 검색 패널 닫기 - CloseSearchPanel() /// <summary> /// 검색 패널 닫기 /// </summary> private void CloseSearchPanel() { if(this.isSearchPanelOpen) { this.isSearchPanelOpen = false; InvokeAction ( delegate() { this.searchPanel.Visible = false; } ); } } #endregion #region 확대하기 - ZoomIn() /// <summary> /// 확대하기 /// </summary> private void ZoomIn() { this.scintilla.ZoomIn(); } #endregion #region 축소하기 - ZoomOut() /// <summary> /// 축소하기 /// </summary> private void ZoomOut() { this.scintilla.ZoomOut(); } #endregion #region 확대/축소 리셋하기 - ResetZoom() /// <summary> /// 확대/축소 리셋하기 /// </summary> private void ResetZoom() { this.scintilla.Zoom = 0; } #endregion } } |
TestProject.zip