//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "HotKey_F.h" #include "HotKey.h" #include "Common.h" #include "Define.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzTabs" #pragma link "RzButton" #pragma link "RzCmboBx" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_SHORTCUTS HotKeyFormStringTable[0] #define IDS_SET HotKeyFormStringTable[1] #define IDS_MSG_NOT_ASSIGN_HOTKEY HotKeyFormStringTable[2] #define IDS_MSG_HOTKEY_ALREADY_SET HotKeyFormStringTable[3] #define IDS_MSG_FILE_NOT_EXIST HotKeyFormStringTable[4] #define IDS_MSG_ENTER_FILE_NAME HotKeyFormStringTable[5] #define IDS_MSG_HOTKEY_FILE_NAME HotKeyFormStringTable[6] #define IDS_MSG_CANNOT_SAVE_DEFAULT_FILE HotKeyFormStringTable[7] #define IDS_MSG_OVERWRITE_FILE HotKeyFormStringTable[8] #define IDS_MSG_CANNOT_DELETE_DEFAULT_FILE HotKeyFormStringTable[9] #define IDS_MSG_DELETE_FILENAME HotKeyFormStringTable[10] #define IDS_MSG_NOT_FOUND_FILE HotKeyFormStringTable[11] //--------------------------------------------------------------------------- THotKeyForm *HotKeyForm; //--------------------------------------------------------------------------- __fastcall THotKeyForm::THotKeyForm(TComponent* Owner) : TForm(Owner) { // TDW HotKeyFormStringTable.Create(DirectoryBin, Language, "HotKeyForm"); HotKeyMenuStringTable.Create(DirectoryItem, Language, "HotKeyMenu"); } //--------------------------------------------------------------------------- void __fastcall THotKeyForm::FormCreate(TObject *Sender) { String strHotKeyFileName, strHotKeyFileExt; // ¸®½ºÆ® ÃʱâÈ­ CurrentValueEditorList = new TList; // TDW Caption = IDS_SHORTCUTS; lbSelectHotKey->Caption = IDS_SET; spdbtnSaveHotKey->Hint = IDS_COMMON_SAVEAS; spdbtnDeleteHotKey->Hint = IDS_COMMON_DELETE; for (int i = 0; i < 3; i++){ rztabctrlMenu->Tabs->Items[i]->Caption = HotKeyMenuStringTable[i]; } for (int i = 0; i < 2; i++){ rztabctrlTopMenu->Tabs->Items[i]->Caption = HotKeyMenuStringTable[i+3]; } for (int i = 0; i < 10; i++){ rztabctrlMainMenu->Tabs->Items[i]->Caption = HotKeyMenuStringTable[i+5]; } // Æû ÃʱâÈ­ InitForm(); // ÄÞº¸¹Ú½º Ç¥½Ã FindHotKeyFiles(); strHotKeyFileName = ExtractFileName(TexActionManager->ActionFileName); strHotKeyFileExt = ExtractFileExt(strHotKeyFileName); strHotKeyFileName = strHotKeyFileName.SubString(1, strHotKeyFileName.Length()-strHotKeyFileExt.Length()); combobxHotKeyFileList->ItemIndex = combobxHotKeyFileList->Items->IndexOf(strHotKeyFileName); // OnChange À̺¥Æ®¸¦ °­Á¦ È£ÃâÇÏ¿© »õ·Î °¡Á®¿Àµµ·Ï ÇÑ´Ù combobxHotKeyFileListChange(combobxHotKeyFileList); } //--------------------------------------------------------------------------- void __fastcall THotKeyForm::InitForm() { // Æû ÃʱâÈ­ rztabctrlMenu->TabIndex = 0; rztabctrlTopMenu->Visible = true; rztabctrlMainMenu->Visible = false; rztabctrlTopMenu->BringToFront(); rztabctrlTopMenu->TabIndex = 0; ChangeValueEditList("Main", false); vallstedHotKeyList->BringToFront(); } //--------------------------------------------------------------------------- void __fastcall THotKeyForm::FormDestroy(TObject *Sender) { // Æ÷ÀÎÅ͸¸ °¡Áö°í ÀÖ´Â ¸®½ºÆ®À̹ǷΠµ¥ÀÌÅÍ´Â »èÁ¦ÇØÁÖÁö ¾Ê¾Æµµ µÊ if (CurrentValueEditorList) { delete CurrentValueEditorList; } CurrentValueEditorList = NULL; } //--------------------------------------------------------------------------- void __fastcall THotKeyForm::rztabctrlMenuChange(TObject *Sender) { if (rztabctrlMenu->TabIndex == 0) { rztabctrlTopMenu->Visible = true; rztabctrlMainMenu->Visible = false; rztabctrlTopMenu->BringToFront(); rztabctrlTopMenu->TabIndex = 0; ChangeValueEditList("Main", false); vallstedHotKeyList->Width = 384; } else if (rztabctrlMenu->TabIndex == 1) { rztabctrlTopMenu->Visible = false; rztabctrlMainMenu->Visible = true; rztabctrlMainMenu->BringToFront(); rztabctrlMainMenu->TabIndex = 0; ChangeValueEditList("MainMenu", false); vallstedHotKeyList->Width = 348; } else { rztabctrlTopMenu->Visible = false; rztabctrlMainMenu->Visible = false; ChangeValueEditList("DisplayOnly", true); vallstedHotKeyList->Width = 384; } vallstedHotKeyList->BringToFront(); } //--------------------------------------------------------------------------- void __fastcall THotKeyForm::rztabctrlTopMenuChange(TObject *Sender) { switch (rztabctrlTopMenu->TabIndex) { case 0: ChangeValueEditList("Main", false); break; case 1: ChangeValueEditList("Normal", false); break; } vallstedHotKeyList->BringToFront(); } //--------------------------------------------------------------------------- void __fastcall THotKeyForm::rztabctrlMainMenuChange(TObject *Sender) { switch(rztabctrlMainMenu->TabIndex) { case 0: ChangeValueEditList("MainMenu", false); break; case 1: ChangeValueEditList("WorkArea", false); break; case 2: ChangeValueEditList("MoveCopy", false); break; case 3: ChangeValueEditList("ColorChange", false); break; case 4: ChangeValueEditList("Clear", false); break; case 5: ChangeValueEditList("ColorGrouping", false); break; case 6: ChangeValueEditList("ManualRepeat", false); break; case 7: ChangeValueEditList("AutoRepeat", false); break; case 8: ChangeValueEditList("Proportion", false); break; case 9: ChangeValueEditList("Vector", false); break; // case 8: // ChangeValueEditList("Draw", false); // break; // case 9: // ChangeValueEditList("Proportion", false); // break; // case 10: // ChangeValueEditList("Fill", false); // break; // case 11: // ChangeValueEditList("Vector", false); // break; } vallstedHotKeyList->BringToFront(); } //--------------------------------------------------------------------------- /** @brief ShortCutÀ» ÀÔ·Â¹Þ¾Æ ´ÜÃàŰ·Î µî·ÏÇÑ´Ù ÇöÀç ÀÔ·ÂÇÏ·Á´Â ۰¡ ÀÌ¹Ì µî·ÏÀÌ µÇ¾îÀÖ´Ù¸é ¸Þ½ÃÁö¸¦ Ãâ·ÂÇÑ´Ù */ void __fastcall THotKeyForm::FormShortCut(TWMKey &Msg, bool &Handled) { TAction *CheckAction = NULL, *CurrentAction = NULL; String strState, strMsg; bool bAlt = false, bShift = false, bCtrl = false; int nCharCode = 0; unsigned short nShortCut = 0; int nCurrentIndex = -1; // Àбâ Àü¿ëÀÌ ¾Æ´Ò °æ¿ì¿¡¸¸ if (vallstedHotKeyList->Tag == 0) { // Ư¼öŰ ÀԷ üũ bAlt = GetAsyncKeyState(VK_MENU) < 0; bShift = GetAsyncKeyState(VK_SHIFT) < 0; bCtrl = GetAsyncKeyState(VK_CONTROL) < 0; nCharCode = Msg.CharCode; nShortCut = nCharCode; strState = ""; // È­¸é »ó¿¡ Ç¥½ÃÇϱâ À§ÇÑ Á¶ÇÕ if (bAlt) { nShortCut |= 0x8000; strState += "Alt + "; } if (bShift) { nShortCut |= 0x2000; strState += "Shift + "; } if (bCtrl) { nShortCut |= 0x4000; strState += "Ctrl + "; } if (TexActionManager->IsExcludedShortCut(nShortCut)) { // Message : ´ÜÃàŰ·Î ÁöÁ¤ÇÒ ¼ö ¾ø´Â Ű ÀÔ´Ï´Ù. MessageDlg(IDS_MSG_NOT_ASSIGN_HOTKEY, mtConfirmation, TMsgDlgButtons() << mbOK, 0); return; } if (vallstedHotKeyList->Row <= CurrentValueEditorList->Count) { CurrentAction = (TAction *)CurrentValueEditorList->Items[vallstedHotKeyList->Row-1]; } if (CurrentAction) { // ÀԷ¹ÞÀº Ű¿Í °°Àº ۰¡ Á¸ÀçÇÏ´ÂÁö üũ CheckAction = TexActionManager->FindAction(nShortCut); // Á¸ÀçÇϴ Ű°¡ ÀÚ±â ÀÚ½ÅÀÌ¸é ¹«½Ã if (CheckAction && CurrentAction == CheckAction) return; // ÀÔ·Â ¹ÞÀº Ű¿Í °°Àº ۰¡ Á¸ÀçÇÏ´Â °æ¿ì if (CheckAction && CurrentAction != CheckAction) { // ÀԷ¹ÞÀº Ű¿Í °°Àº ۰¡ Á¸ÀçÇÏ´Â °æ¿ì // Message : ´ÜÃà۰¡ ÀÌ¹Ì Á¸ÀçÇÕ´Ï´Ù. /* MessageDlg(IDS_MSG_HOTKEY_ALREADY_SET + " [" + CheckAction->Hint + "]", mtConfirmation, TMsgDlgButtons() << mbOK, 0); */ // Ãß°¡ °³¹ß ¿äû »çÇ× ///* // ±âÁ¸ ´ÜÃà۸¦ ÇöÀçŰ·Î ´ëüÇÑ´Ù // Message : ±âÁ¸ [%s] ´ÜÃàŰ Á¦°Å ÈÄ Áö±Ý ´ÜÃà۸¦ Àû¿ëÇϽðڽÀ´Ï±î? strMsg = Format(IDS_MSG_HOTKEY_ALREADY_SET, OPENARRAY(TVarRec, (CheckAction->Hint))); if (MessageDlg(strMsg, mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes) { CheckAction->ShortCut = 0; // ±âÁ¸ ´ÜÃàŰ ÃʱâÈ­ if ('A' <= nCharCode && nCharCode <= 'Z') { if (CurrentAction->Category != "Etc" && CurrentAction->Category != "Textile" && CurrentAction->Category != "System") { CurrentAction->ShortCut = nShortCut; // ´ÜÃàŰ ÀÔ·Â nCurrentIndex = vallstedHotKeyList->Row; // ±âÁ¸ À§Ä¡ ¹é¾÷ // Àû¿ëµÇ¸é ±âÁ¸ ´ÜÃàŰ´Â ´ÜÃà۰¡ »èÁ¦µÇ¾î¾ß Çϰí, // ÇöÀç ´ÜÃà۰¡ Àû¿ëµÇ¾î¾ß ÇϹǷΠ»õ·Î ºÒ·¯¿Â´Ù ChangeValueEditList(CurrentAction->Category, false); vallstedHotKeyList->Row = nCurrentIndex; // ±âÁ¸ À§Ä¡·Î µÇµ¹¸² } } } //*/ return; } else { // Alt, Shift, Ctrl, ESC ¿Ü¿¡ ¿µ¹® A~Z±îÁö¸¸ ÀÔ·Â ¹ÞÀ» ¼ö ÀÖ´Ù // 1~0Àº °¢ ¸Þ´º¿¡¼­ »ç¿ëÇϰí, F1~F12 ¹× ±âÈ£ ۵éÀº ´Ù¸¥ ºÎºÐ¿¡ ¿µÇâÀ» ÁÙ ¼ö Àֱ⠶§¹®À̸ç // ¿µ¹®¸¸ ÀÔ·Â ¹Þ¾Æµµ ÃæºÐÇÏ´Ù if ('A' <= nCharCode && nCharCode <= 'Z') { CurrentAction->ShortCut = nShortCut; strState += (wchar_t)nCharCode; vallstedHotKeyList->Cells[1][vallstedHotKeyList->Row] = strState; } else if (nCharCode == VK_ESCAPE) { // ESC ó¸® CurrentAction->ShortCut = nCharCode; vallstedHotKeyList->Cells[1][vallstedHotKeyList->Row] = "ESC"; } else if (nCharCode == VK_DELETE) { // Delete ó¸® CurrentAction->ShortCut = 0; vallstedHotKeyList->Cells[1][vallstedHotKeyList->Row] = ""; } } } } } //--------------------------------------------------------------------------- /** @brief Category°¡ º¯°æµÇ¸é ±× ³»¿ëÀ» È­¸é¿¡ Ç¥½ÃÇÑ´Ù @param ACategory : º¯°æµÉ Category */ void __fastcall THotKeyForm::ChangeValueEditList(String strACategory, bool bReadOnly) { TAction *Action = NULL; String strKeyState; int nCharCode; // ÃʱâÈ­ CurrentValueEditorList->Clear(); while (2 < vallstedHotKeyList->RowCount) { vallstedHotKeyList->DeleteRow(vallstedHotKeyList->RowCount-1); } vallstedHotKeyList->Cells[0][1] = ""; vallstedHotKeyList->Cells[1][1] = ""; // È­¸é Ç¥½Ã ºÎºÐ if (bReadOnly == false) { TexActionManager->FindCategory(strACategory, CurrentValueEditorList); // ValueListEditorÀÇ InsertRow´Â ¸®½ºÆ®ÀÇ ¿ª¼øÀ¸·Î ÇØ¾ßÇÑ´Ù for (int i = CurrentValueEditorList->Count - 1; 0 <= i; i--) { Action = (TAction*)CurrentValueEditorList->Items[i]; strKeyState = ""; if (Action->Category == strACategory) { strKeyState = TexActionManager->ShortCutToString(Action->ShortCut); vallstedHotKeyList->InsertRow(Action->Hint, strKeyState, false); } } } else { // Àбâ Àü¿ëÀÏ °æ¿ì for (int i = TexActionManager->DisplayOnlyList->Count - 1; 0 <= i; i--) { Action = (TAction *)TexActionManager->DisplayOnlyList->Items[i]; if (Action->Category == strACategory) { strKeyState = Action->Caption; vallstedHotKeyList->InsertRow(Action->Hint, strKeyState, false); } } } // Àбâ Àü¿ë °ü·Ã (Æí¹ý) if (bReadOnly == false) vallstedHotKeyList->Tag = 0; else vallstedHotKeyList->Tag = 1; } //--------------------------------------------------------------------------- /** @brief ´ÜÃàŰ ÆÄÀϵéÀ» °Ë»öÇÏ¿© ÄÞº¸¹Ú½º¿¡ Ç¥½ÃÇÑ´Ù */ void __fastcall THotKeyForm::FindHotKeyFiles() { HANDLE hSrch = INVALID_HANDLE_VALUE; WIN32_FIND_DATA fd; BOOL bResult = TRUE; combobxHotKeyFileList->Clear(); String strPath = DirectoryBin + "\\TexStylist\\HotKey\\*.hkf"; String strFileName, strExt; hSrch=FindFirstFile(strPath.c_str(),&fd); if (hSrch != INVALID_HANDLE_VALUE){ while(bResult){ if (fd.dwFileAttributes && !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) && !(fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)){ //&& !(fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)){ strFileName = String(fd.cFileName); strExt = ExtractFileExt(strFileName); // È®ÀåÀÚ ºñ±³ if (strExt.LowerCase() == ".hkf") { // È®ÀåÀÚ¸¦ Á¦°ÅÇÑ ÆÄÀϸíÀ» ÀÔ·ÂÇÑ´Ù strFileName = strFileName.SubString(1, strFileName.Length()-strExt.Length()); combobxHotKeyFileList->Items->Add(strFileName); } } bResult = FindNextFile(hSrch,&fd); } } FindClose(hSrch); } //--------------------------------------------------------------------------- /** @brief ÄÞº¸¹Ú½º°¡ º¯°æµÇ¸é ÇØ´ç ´ÜÃàŰ ÆÄÀÏÀ» Àоî È­¸é¿¡ º¸¿©ÁØ´Ù */ void __fastcall THotKeyForm::combobxHotKeyFileListChange(TObject *Sender) { TIniFile *IniFile = NULL; String strHotKeyFileName, strTDWFileName, strSelectedFileName; strSelectedFileName = combobxHotKeyFileList->Items->Strings[combobxHotKeyFileList->ItemIndex]; strHotKeyFileName = DirectoryBin + "\\TexStylist\\HotKey\\"+strSelectedFileName+".hkf"; strTDWFileName = DirectoryBin + "\\TexStylist\\HotKey\\"+Language+".hdw"; // ÆÄÀÏ Á¸Àç½Ã Àбâ if (FileExists(strHotKeyFileName) && FileExists(strTDWFileName)) { TexActionManager->LoadFromFile(strHotKeyFileName, strTDWFileName); InitForm(); // ÆÄÀÏÀ» °¡Á®¿Â ÈÄ ÃʱâÈ­ÇÑ´Ù // HotKey - monkman (2010.06.30) IniFile = new TIniFile(AppDataItem+"\\status.ini"); if (IniFile) { IniFile->WriteString("HotKey", "File", strSelectedFileName); delete IniFile; } } else { // Message : ´ÜÃàŰ ÆÄÀÏÀÌ ¾ø½À´Ï´Ù. MessageDlg(IDS_MSG_FILE_NOT_EXIST, mtError, TMsgDlgButtons() << mbOK, 0); } IniFile = NULL; } //--------------------------------------------------------------------------- void __fastcall THotKeyForm::spdbtnSaveHotKeyClick(TObject *Sender) { String strInputFileName, strHotKeyFileName; int nExistIndex = -1; bool bSave = true; strInputFileName = combobxHotKeyFileList->Items->Strings[combobxHotKeyFileList->ItemIndex]; // CancelÀ» Ŭ¸¯Çϸé returnÇÑ´Ù if (InputQuery(IDS_MSG_ENTER_FILE_NAME, IDS_MSG_HOTKEY_FILE_NAME, strInputFileName) == false) return; // DeafultÀÎÁö üũ if (strInputFileName.LowerCase() == "texstylist") { // Message : "texstylist" ÆÄÀϸíÀ¸·Î ÀúÀåÇÒ ¼ö ¾ø½À´Ï´Ù. MessageDlg(IDS_MSG_CANNOT_SAVE_DEFAULT_FILE, mtWarning, TMsgDlgButtons() << mbOK, 0); return; } if (strInputFileName.IsEmpty() == false) { // CancelÀ» Ŭ¸¯ÇÏÁö ¾Ê¾Ò´Ù¸é // °°Àº ÆÄÀÏÀÌ Á¸ÀçÇÑ´Ù¸é nExistIndex = combobxHotKeyFileList->Items->IndexOf(strInputFileName); strHotKeyFileName = DirectoryBin + "\\TexStylist\\HotKey\\"+strInputFileName+".hkf"; if (0 <= nExistIndex || FileExists(strHotKeyFileName) == true) { // Message : ÆÄÀÏÀ» µ¤¾î ¾º¿ì°Ú½À´Ï±î? if (MessageDlg(IDS_MSG_OVERWRITE_FILE, mtWarning, TMsgDlgButtons() << mbYes << mbNo, 0) == mrNo) bSave = false; } if (bSave) { TexActionManager->SaveToFile(strHotKeyFileName); FindHotKeyFiles(); combobxHotKeyFileList->ItemIndex = combobxHotKeyFileList->Items->IndexOf(strInputFileName); // OnChange À̺¥Æ®¸¦ °­Á¦ È£ÃâÇÏ¿© »õ·Î °¡Á®¿Àµµ·Ï ÇÑ´Ù combobxHotKeyFileListChange(combobxHotKeyFileList); } } } //--------------------------------------------------------------------------- /** @brief ÇöÀç ¼±ÅÃµÈ ´ÜÃàŰ ÆÄÀÏÀ» »èÁ¦ÇÑ´Ù */ void __fastcall THotKeyForm::spdbtnDeleteHotKeyClick(TObject *Sender) { String strSelectedFileName, strHotKeyFileName; strSelectedFileName = combobxHotKeyFileList->Items->Strings[combobxHotKeyFileList->ItemIndex]; strHotKeyFileName = DirectoryBin + "\\TexStylist\\HotKey\\"+strSelectedFileName+".hkf"; if (FileExists(strHotKeyFileName)) { if (strSelectedFileName.LowerCase() == "textile") { // Message : "Textile" ÆÄÀÏÀº »èÁ¦ÇÒ ¼ö ¾ø½À´Ï´Ù. MessageDlg(IDS_MSG_CANNOT_DELETE_DEFAULT_FILE, mtWarning, TMsgDlgButtons() << mbOK, 0); return; } // Message : ¼±ÅÃÇÑ ÆÄÀÏÀ» »èÁ¦ÇϽðڽÀ´Ï±î? if (MessageDlg(IDS_MSG_DELETE_FILENAME, mtWarning, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes) { // ÆÄÀÏ »èÁ¦ DeleteFile(strHotKeyFileName.c_str()); // ÄÞº¸¹Ú½º¿¡¼­µµ »èÁ¦ combobxHotKeyFileList->Items->Delete(combobxHotKeyFileList->ItemIndex); // ±âº» °ªÀÎ Textile Ű·Î µÇµ¹¸² combobxHotKeyFileList->ItemIndex = combobxHotKeyFileList->Items->IndexOf("Textile"); // OnChange À̺¥Æ®¸¦ °­Á¦ È£ÃâÇÏ¿© »õ·Î °¡Á®¿Àµµ·Ï ÇÑ´Ù combobxHotKeyFileListChange(combobxHotKeyFileList); } } else { // Message : ¼±ÅÃÇÑ ´ÜÃàŰ ÆÄÀÏÀ» ãÀ» ¼ö ¾ø½À´Ï´Ù. MessageDlg(IDS_MSG_NOT_FOUND_FILE, mtError, TMsgDlgButtons() << mbOK, 0); } } //---------------------------------------------------------------------------