첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.02MB

▶ HotKeyManager.cs

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
    }
}

 

728x90

 

▶ SearchManager.cs

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

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요