| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Notepad++
Revision: 305
Author: donho
Date: 15 Aug 2008 06:02:25
Changes:[NEW_FEATURE] Unicode path is supported.
Files:| ... | ...@@ -17,8 +17,8 @@ | |
| 17 | 17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | #ifndef SHORTCUTMAPPER | |
| 21 | #define SHORTCUTMAPPER | |
| 20 | #ifndef SHORTCUTMAPPER_H | |
| 21 | #define SHORTCUTMAPPER_H | |
| 22 | 22 | |
| 23 | 23 | #include "BabyGridWrapper.h" |
| 24 | 24 | #include "ShortcutMapper_rc.h" |
| ... | ...@@ -77,4 +77,4 @@ | |
| 77 | 77 | void fillOutBabyGrid(); |
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | #endif //SHORTCUTMAPPER | |
| 80 | #endif //SHORTCUTMAPPER_H |
| ... | ...@@ -1,4 +1,5 @@ | |
| 1 | ||
| 1 | #ifndef SIZABLEDLG_H | |
| 2 | #define SIZABLEDLG_H | |
| 2 | 3 | |
| 3 | 4 | #include "StaticDialog.h" |
| 4 | 5 | #include "WindowsDlgRc.h" |
| ... | ...@@ -18,3 +19,5 @@ | |
| 18 | 19 | virtual void onGetMinMaxInfo(MINMAXINFO* lpMMI); |
| 19 | 20 | virtual LRESULT onWinMgr(WPARAM wp, LPARAM lp); |
| 20 | 21 | }; |
| 22 | ||
| 23 | #endif //SIZABLEDLG_H |
| ... | ...@@ -21,6 +21,7 @@ | |
| 21 | 21 | #include <stdio.h> |
| 22 | 22 | #include <windows.h> |
| 23 | 23 | #include "PluginInterface.h" |
| 24 | #include "UniConversion.h" | |
| 24 | 25 | |
| 25 | 26 | const Utf8_16::utf8 Utf8_16::k_Boms[][3] = { |
| 26 | 27 | {0x00, 0x00, 0x00}, // Unknown |
| ... | ...@@ -222,6 +223,15 @@ | |
| 222 | 223 | return m_pFile; |
| 223 | 224 | } |
| 224 | 225 | |
| 226 | FILE * Utf8_16_Write::fopenW(const wchar_t *_name, const wchar_t *_type) | |
| 227 | { | |
| 228 | m_pFile = ::_wfopen(_name, _type); | |
| 229 | ||
| 230 | m_bFirstWrite = true; | |
| 231 | ||
| 232 | return m_pFile; | |
| 233 | } | |
| 234 | ||
| 225 | 235 | size_t Utf8_16_Write::fwrite(const void* p, size_t _size) |
| 226 | 236 | { |
| 227 | 237 | // no file open |
| ... | ...@@ -6,6 +6,6 @@ | |
| 6 | 6 | > |
| 7 | 7 | <Tool |
| 8 | 8 | Name="VCCLCompilerTool" |
| 9 | PreprocessorDefinitions="__STDC_WANT_SECURE_LIB__=0;_CRT_NONSTDC_NO_DEPRECATE" | |
| 9 | PreprocessorDefinitions="__STDC_WANT_SECURE_LIB__=0;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NON_CONFORMING_SWPRINTFS=1" | |
| 10 | 10 | /> |
| 11 | 11 | </VisualStudioPropertySheet> |
| ... | ...@@ -18,19 +18,19 @@ | |
| 18 | 18 | #ifndef FILENAME_STRING_SPLITTER_H |
| 19 | 19 | #define FILENAME_STRING_SPLITTER_H |
| 20 | 20 | |
| 21 | typedef std::vector<std::string> stringVector; | |
| 21 | typedef std::vector<std::wstring> stringVectorW; | |
| 22 | 22 | |
| 23 | 23 | class FileNameStringSplitter |
| 24 | 24 | { |
| 25 | 25 | public : |
| 26 | FileNameStringSplitter(const char *fileNameStr) { | |
| 26 | FileNameStringSplitter(const wchar_t *fileNameStr) { | |
| 27 | 27 | //if (!fileNameStr) return; |
| 28 | char *pStr = NULL; | |
| 28 | wchar_t *pStr = NULL; | |
| 29 | 29 | bool isInsideQuotes = false; |
| 30 | char str[256]; | |
| 30 | wchar_t str[256]; | |
| 31 | 31 | int i = 0; |
| 32 | 32 | bool fini = false; |
| 33 | for (pStr = (char *)fileNameStr ; !fini ; ) | |
| 33 | for (pStr = (wchar_t *)fileNameStr ; !fini ; ) | |
| 34 | 34 | { |
| 35 | 35 | switch (*pStr) |
| 36 | 36 | { |
| ... | ...@@ -39,7 +39,7 @@ | |
| 39 | 39 | { |
| 40 | 40 | str[i] = '\0'; |
| 41 | 41 | if (str[0]) |
| 42 | _fileNames.push_back(std::string(str)); | |
| 42 | _fileNames.push_back(std::wstring(str)); | |
| 43 | 43 | i = 0; |
| 44 | 44 | } |
| 45 | 45 | isInsideQuotes = !isInsideQuotes; |
| ... | ...@@ -56,7 +56,7 @@ | |
| 56 | 56 | { |
| 57 | 57 | str[i] = '\0'; |
| 58 | 58 | if (str[0]) |
| 59 | _fileNames.push_back(std::string(str)); | |
| 59 | _fileNames.push_back(std::wstring(str)); | |
| 60 | 60 | i = 0; |
| 61 | 61 | } |
| 62 | 62 | pStr++; |
| ... | ...@@ -65,7 +65,7 @@ | |
| 65 | 65 | case '\0' : |
| 66 | 66 | str[i] = *pStr; |
| 67 | 67 | if (str[0]) |
| 68 | _fileNames.push_back(std::string(str)); | |
| 68 | _fileNames.push_back(std::wstring(str)); | |
| 69 | 69 | fini = true; |
| 70 | 70 | break; |
| 71 | 71 | |
| ... | ...@@ -77,7 +77,7 @@ | |
| 77 | 77 | } |
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | const char * getFileName(int index) const { | |
| 80 | const wchar_t * getFileName(int index) const { | |
| 81 | 81 | return _fileNames[index].c_str(); |
| 82 | 82 | }; |
| 83 | 83 | |
| ... | ...@@ -86,7 +86,7 @@ | |
| 86 | 86 | }; |
| 87 | 87 | |
| 88 | 88 | private : |
| 89 | stringVector _fileNames; | |
| 89 | stringVectorW _fileNames; | |
| 90 | 90 | }; |
| 91 | 91 | |
| 92 | 92 | #endif //FILENAME_STRING_SPLITTER_H |
| ... | ...@@ -24,6 +24,7 @@ | |
| 24 | 24 | #include "ScintillaEditView.h" |
| 25 | 25 | #include "StatusBar.h" |
| 26 | 26 | #include "DockingDlgInterface.h" |
| 27 | #include "UniConversion.h" | |
| 27 | 28 | |
| 28 | 29 | |
| 29 | 30 | #define FIND_RECURSIVE 1 |
| ... | ...@@ -295,12 +296,18 @@ | |
| 295 | 296 | if (dir) |
| 296 | 297 | { |
| 297 | 298 | _directory = dir; |
| 298 | ::SetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, dir); | |
| 299 | ||
| 300 | wchar_t dirW[MAX_PATH]; | |
| 301 | char2wchar(dir, dirW); | |
| 302 | ::SetDlgItemTextW(_hSelf, IDD_FINDINFILES_DIR_COMBO, dirW); | |
| 299 | 303 | } |
| 300 | 304 | if (filters) |
| 301 | 305 | { |
| 302 | 306 | _filters = filters; |
| 303 | ::SetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters); | |
| 307 | ||
| 308 | wchar_t filtersW[MAX_PATH]; | |
| 309 | char2wchar(filters, filtersW); | |
| 310 | ::SetDlgItemTextW(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filtersW); | |
| 304 | 311 | } |
| 305 | 312 | }; |
| 306 | 313 |
| ... | ...@@ -9,6 +9,7 @@ | |
| 9 | 9 | |
| 10 | 10 | #include "Notepad_plus.h" |
| 11 | 11 | #include "ScintillaEditView.h" |
| 12 | #include "UniConversion.h" | |
| 12 | 13 | |
| 13 | 14 | FileManager * FileManager::_pSelf = new FileManager(); |
| 14 | 15 | |
| ... | ...@@ -82,7 +83,7 @@ | |
| 82 | 83 | |
| 83 | 84 | void Buffer::updateTimeStamp() { |
| 84 | 85 | struct _stat buf; |
| 85 | time_t timeStamp = (_stat(_fullPathName, &buf)==0)?buf.st_mtime:0; | |
| 86 | time_t timeStamp = (_wstat(_fullPathNameW, &buf)==0)?buf.st_mtime:0; | |
| 86 | 87 | |
| 87 | 88 | if (timeStamp != _timeStamp) { |
| 88 | 89 | _timeStamp = timeStamp; |
| ... | ...@@ -102,6 +103,8 @@ | |
| 102 | 103 | return; |
| 103 | 104 | } |
| 104 | 105 | strcpy(_fullPathName, fn); |
| 106 | char2wchar(_fullPathName, _fullPathNameW); | |
| 107 | _fileNameW = PathFindFileNameW(_fullPathNameW); | |
| 105 | 108 | _fileName = PathFindFileName(_fullPathName); |
| 106 | 109 | |
| 107 | 110 | // for _lang |
| ... | ...@@ -148,19 +151,19 @@ | |
| 148 | 151 | if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment |
| 149 | 152 | return false; |
| 150 | 153 | |
| 151 | if (_currentStatus != DOC_DELETED && !PathFileExists(_fullPathName)) //document has been deleted | |
| 154 | if (_currentStatus != DOC_DELETED && !PathFileExistsW(_fullPathNameW)) //document has been deleted | |
| 152 | 155 | { |
| 153 | 156 | _currentStatus = DOC_DELETED; |
| 154 | 157 | _isFileReadOnly = false; |
| 155 | _isDirty = true; //dirty sicne no match with filesystem | |
| 158 | _isDirty = true; //dirty since no match with filesystem | |
| 156 | 159 | _timeStamp = 0; |
| 157 | 160 | doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); |
| 158 | 161 | return true; |
| 159 | 162 | } |
| 160 | 163 | |
| 161 | if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName)) | |
| 164 | if (_currentStatus == DOC_DELETED && PathFileExistsW(_fullPathNameW)) | |
| 162 | 165 | { //document has returned from its grave |
| 163 | if (!_stat(_fullPathName, &buf)) | |
| 166 | if (!_wstat(_fullPathNameW, &buf)) | |
| 164 | 167 | { |
| 165 | 168 | _isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); |
| 166 | 169 | |
| ... | ...@@ -171,7 +174,7 @@ | |
| 171 | 174 | } |
| 172 | 175 | } |
| 173 | 176 | |
| 174 | if (!_stat(_fullPathName, &buf)) | |
| 177 | if (!_wstat(_fullPathNameW, &buf)) | |
| 175 | 178 | { |
| 176 | 179 | int mask = 0; //status always 'changes', even if from modified to modified |
| 177 | 180 | bool isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); |
| ... | ...@@ -443,20 +446,22 @@ | |
| 443 | 446 | bool FileManager::deleteFile(BufferID id) |
| 444 | 447 | { |
| 445 | 448 | Buffer * buf = getBufferByID(id); |
| 446 | const char *fileNamePath = buf->getFilePath(); | |
| 447 | if (!PathFileExists(fileNamePath)) | |
| 449 | const wchar_t *fileNamePath = buf->getFilePathW(); | |
| 450 | if (!PathFileExistsW(fileNamePath)) | |
| 448 | 451 | return false; |
| 449 | return ::DeleteFile(fileNamePath) != 0; | |
| 452 | return ::DeleteFileW(fileNamePath) != 0; | |
| 450 | 453 | } |
| 451 | 454 | |
| 452 | 455 | bool FileManager::moveFile(BufferID id, const char * newFileName) |
| 453 | 456 | { |
| 454 | 457 | Buffer * buf = getBufferByID(id); |
| 455 | const char *fileNamePath = buf->getFilePath(); | |
| 456 | if (!PathFileExists(fileNamePath)) | |
| 458 | const wchar_t *fileNamePath = buf->getFilePathW(); | |
| 459 | if (!PathFileExistsW(fileNamePath)) | |
| 457 | 460 | return false; |
| 458 | 461 | |
| 459 | if (::MoveFile(fileNamePath, newFileName) == 0) | |
| 462 | wchar_t newFileNameW[MAX_PATH]; | |
| 463 | char2wchar(newFileName, newFileNameW); | |
| 464 | if (::MoveFileW(fileNamePath, newFileNameW) == 0) | |
| 460 | 465 | return false; |
| 461 | 466 | |
| 462 | 467 | buf->setFileName(newFileName); |
| ... | ...@@ -472,19 +477,21 @@ | |
| 472 | 477 | char fullpath[MAX_PATH]; |
| 473 | 478 | ::GetFullPathName(filename, MAX_PATH, fullpath, NULL); |
| 474 | 479 | ::GetLongPathName(fullpath, fullpath, MAX_PATH); |
| 475 | if (PathFileExists(fullpath)) | |
| 480 | wchar_t fullpathW[MAX_PATH]; | |
| 481 | char2wchar(fullpath, fullpathW); | |
| 482 | if (PathFileExistsW(fullpathW)) | |
| 476 | 483 | { |
| 477 | attrib = ::GetFileAttributes(fullpath); | |
| 484 | attrib = ::GetFileAttributesW(fullpathW); | |
| 478 | 485 | |
| 479 | 486 | if (attrib != INVALID_FILE_ATTRIBUTES) |
| 480 | 487 | { |
| 481 | 488 | isHidden = (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; |
| 482 | 489 | if (isHidden) |
| 483 | ::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_HIDDEN); | |
| 490 | ::SetFileAttributesW(fullpathW, attrib & ~FILE_ATTRIBUTE_HIDDEN); | |
| 484 | 491 | |
| 485 | 492 | isSys = (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; |
| 486 | 493 | if (isSys) |
| 487 | ::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_SYSTEM); | |
| 494 | ::SetFileAttributesW(fullpathW, attrib & ~FILE_ATTRIBUTE_SYSTEM); | |
| 488 | 495 | } |
| 489 | 496 | } |
| 490 | 497 | |
| ... | ...@@ -495,11 +502,12 @@ | |
| 495 | 502 | Utf8_16_Write UnicodeConvertor; |
| 496 | 503 | UnicodeConvertor.setEncoding(mode); |
| 497 | 504 | |
| 498 | FILE *fp = UnicodeConvertor.fopen(fullpath, "wb"); | |
| 505 | FILE *fp = UnicodeConvertor.fopenW(fullpathW, L"wb"); | |
| 499 | 506 | if (fp) |
| 500 | 507 | { |
| 501 | 508 | _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, buffer->_doc); //generate new document |
| 502 | 509 | |
| 510 | ||
| 503 | 511 | char data[blockSize + 1]; |
| 504 | 512 | int lengthDoc = _pscratchTilla->getCurrentDocLen(); |
| 505 | 513 | for (int i = 0; i < lengthDoc; i += blockSize) |
| ... | ...@@ -514,10 +522,10 @@ | |
| 514 | 522 | UnicodeConvertor.fclose(); |
| 515 | 523 | |
| 516 | 524 | if (isHidden) |
| 517 | ::SetFileAttributes(fullpath, attrib | FILE_ATTRIBUTE_HIDDEN); | |
| 525 | ::SetFileAttributesW(fullpathW, attrib | FILE_ATTRIBUTE_HIDDEN); | |
| 518 | 526 | |
| 519 | 527 | if (isSys) |
| 520 | ::SetFileAttributes(fullpath, attrib | FILE_ATTRIBUTE_SYSTEM); | |
| 528 | ::SetFileAttributesW(fullpathW, attrib | FILE_ATTRIBUTE_SYSTEM); | |
| 521 | 529 | |
| 522 | 530 | if (isCopy) { |
| 523 | 531 | _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); |
| ... | ...@@ -571,17 +579,20 @@ | |
| 571 | 579 | const int blockSize = 128 * 1024; //128 kB |
| 572 | 580 | char data[blockSize]; |
| 573 | 581 | |
| 574 | __try { | |
| 575 | FILE *fp = fopen(filename, "rb"); | |
| 582 | WCHAR filenameW[MAX_PATH]; | |
| 583 | char2wchar(filename, filenameW); | |
| 584 | ||
| 585 | FILE *fp = _wfopen(filenameW, L"rb"); | |
| 576 | 586 | if (!fp) |
| 577 | 587 | return false; |
| 578 | 588 | |
| 589 | __try { | |
| 579 | 590 | //Setup scratchtilla for new filedata |
| 580 | 591 | _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc); |
| 581 | 592 | bool ro = _pscratchTilla->execute(SCI_GETREADONLY) != 0; |
| 582 | if (ro) { | |
| 593 | if (ro) { | |
| 583 | 594 | _pscratchTilla->execute(SCI_SETREADONLY, false); |
| 584 | } | |
| 595 | } | |
| 585 | 596 | _pscratchTilla->execute(SCI_CLEARALL); |
| 586 | 597 | if (language < L_EXTERNAL) { |
| 587 | 598 | _pscratchTilla->execute(SCI_SETLEXER, ScintillaEditView::langNames[language].lexerID); |
| ... | ...@@ -610,6 +621,7 @@ | |
| 610 | 621 | return true; |
| 611 | 622 | |
| 612 | 623 | }__except(filter(GetExceptionCode(), GetExceptionInformation())) { |
| 624 | ||
| 613 | 625 | printStr("File is too big to be opened by Notepad++"); |
| 614 | 626 | return false; |
| 615 | 627 | } |
| ... | ...@@ -634,7 +646,10 @@ | |
| 634 | 646 | } |
| 635 | 647 | |
| 636 | 648 | bool FileManager::createEmptyFile(const char * path) { |
| 637 | FILE * file = fopen(path, "wb"); | |
| 649 | WCHAR pathW[MAX_PATH]; | |
| 650 | char2wchar(path, pathW); | |
| 651 | ||
| 652 | FILE * file = _wfopen(pathW, L"wb"); | |
| 638 | 653 | if (!file) |
| 639 | 654 | return false; |
| 640 | 655 | fclose(file); |
| ... | ...@@ -7,6 +7,7 @@ | |
| 7 | 7 | |
| 8 | 8 | #include <stdlib.h> |
| 9 | 9 | #include <windows.h> |
| 10 | #include <vector> | |
| 10 | 11 | #include "UniConversion.h" |
| 11 | 12 | |
| 12 | 13 | unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen) { |
| ... | ...@@ -133,3 +134,46 @@ | |
| 133 | 134 | return nbByte; |
| 134 | 135 | } |
| 135 | 136 | |
| 137 | void char2wchar(const char* pszCHAR, wchar_t* pszWCHAR, UINT codepage) | |
| 138 | { | |
| 139 | int len = MultiByteToWideChar(codepage, 0, pszCHAR, -1, pszWCHAR, 0); | |
| 140 | if(len > 0) | |
| 141 | MultiByteToWideChar(codepage, 0, pszCHAR, -1, pszWCHAR, len); | |
| 142 | else | |
| 143 | pszWCHAR[0] = 0; | |
| 144 | } | |
| 145 | ||
| 146 | void wchar2char(const wchar_t* pszWCHAR, char* pszCHAR, UINT codepage) | |
| 147 | { | |
| 148 | int len = WideCharToMultiByte(codepage, 0, pszWCHAR, -1, pszCHAR, 0, NULL, NULL); | |
| 149 | if(len > 0) | |
| 150 | WideCharToMultiByte(codepage, 0, pszWCHAR, -1, pszCHAR, len, NULL, NULL); | |
| 151 | else | |
| 152 | pszCHAR[0] = 0; | |
| 153 | } | |
| 154 | ||
| 155 | std::wstring string2wstring(const std::string& rString, UINT codepage) | |
| 156 | { | |
| 157 | int len = MultiByteToWideChar(codepage, 0, rString.c_str(), -1, NULL, 0); | |
| 158 | if(len > 0) | |
| 159 | { | |
| 160 | std::vector<wchar_t> vw(len); | |
| 161 | MultiByteToWideChar(codepage, 0, rString.c_str(), -1, &vw[0], len); | |
| 162 | return &vw[0]; | |
| 163 | } | |
| 164 | else | |
| 165 | return L""; | |
| 166 | } | |
| 167 | ||
| 168 | std::string wstring2string(const std::wstring& rwString, UINT codepage) | |
| 169 | { | |
| 170 | int len = WideCharToMultiByte(codepage, 0, rwString.c_str(), -1, NULL, 0, NULL, NULL); | |
| 171 | if(len > 0) | |
| 172 | { | |
| 173 | std::vector<char> vw(len); | |
| 174 | WideCharToMultiByte(codepage, 0, rwString.c_str(), -1, &vw[0], len, NULL, NULL); | |
| 175 | return &vw[0]; | |
| 176 | } | |
| 177 | else | |
| 178 | return ""; | |
| 179 | } |
| ... | ...@@ -22,19 +22,19 @@ | |
| 22 | 22 | #include <exception> //default C++ exception |
| 23 | 23 | #include "Win32Exception.h" //Win32 exception |
| 24 | 24 | |
| 25 | typedef std::vector<const char*> ParamVector; | |
| 25 | typedef std::vector<const wchar_t*> ParamVector; | |
| 26 | 26 | |
| 27 | bool checkSingleFile(const char * commandLine) { | |
| 28 | char fullpath[MAX_PATH]; | |
| 29 | ::GetFullPathName(commandLine, MAX_PATH, fullpath, NULL); | |
| 30 | if (::PathFileExists(fullpath)) { | |
| 27 | bool checkSingleFile(const wchar_t * commandLine) { | |
| 28 | wchar_t fullpath[MAX_PATH]; | |
| 29 | ::GetFullPathNameW(commandLine, MAX_PATH, fullpath, NULL); | |
| 30 | if (::PathFileExistsW(fullpath)) { | |
| 31 | 31 | return true; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | void parseCommandLine(char * commandLine, ParamVector & paramVector) { | |
| 37 | void parseCommandLine(wchar_t * commandLine, ParamVector & paramVector) { | |
| 38 | 38 | bool isFile = checkSingleFile(commandLine); //if the commandline specifies only a file, open it as such |
| 39 | 39 | if (isFile) { |
| 40 | 40 | paramVector.push_back(commandLine); |
| ... | ...@@ -43,7 +43,7 @@ | |
| 43 | 43 | bool isInFile = false; |
| 44 | 44 | bool isInWhiteSpace = true; |
| 45 | 45 | paramVector.clear(); |
| 46 | size_t commandLength = strlen(commandLine); | |
| 46 | size_t commandLength = wcslen(commandLine); | |
| 47 | 47 | for(size_t i = 0; i < commandLength; i++) { |
| 48 | 48 | switch(commandLine[i]) { |
| 49 | 49 | case '\"': { //quoted filename, ignore any following whitespace |
| ... | ...@@ -72,12 +72,12 @@ | |
| 72 | 72 | //the commandline string is now a list of zero terminated strings concatenated, and the vector contains all the substrings |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | bool isInList(const char *token2Find, ParamVector & params) { | |
| 75 | bool isInList(const wchar_t *token2Find, ParamVector & params) { | |
| 76 | 76 | int nrItems = params.size(); |
| 77 | 77 | |
| 78 | 78 | for (int i = 0; i < nrItems; i++) |
| 79 | 79 | { |
| 80 | if (!strcmp(token2Find, params.at(i))) { | |
| 80 | if (!wcscmp(token2Find, params.at(i))) { | |
| 81 | 81 | params.erase(params.begin() + i); |
| 82 | 82 | return true; |
| 83 | 83 | } |
| ... | ...@@ -85,14 +85,14 @@ | |
| 85 | 85 | return false; |
| 86 | 86 | }; |
| 87 | 87 | |
| 88 | bool getParamVal(char c, ParamVector & params, string & value) { | |
| 89 | value = ""; | |
| 88 | bool getParamVal(wchar_t c, ParamVector & params, wstring & value) { | |
| 89 | value = L""; | |
| 90 | 90 | int nrItems = params.size(); |
| 91 | 91 | |
| 92 | 92 | for (int i = 0; i < nrItems; i++) |
| 93 | 93 | { |
| 94 | const char * token = params.at(i); | |
| 95 | if (token[0] == '-' && strlen(token) >= 2 && token[1] == c) { //dash, and enough chars | |
| 94 | const wchar_t * token = params.at(i); | |
| 95 | if (token[0] == '-' && wcslen(token) >= 2 && token[1] == c) { //dash, and enough chars | |
| 96 | 96 | value = (token+2); |
| 97 | 97 | params.erase(params.begin() + i); |
| 98 | 98 | return true; |
| ... | ...@@ -102,28 +102,30 @@ | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | LangType getLangTypeFromParam(ParamVector & params) { |
| 105 | string langStr; | |
| 105 | wstring langStr; | |
| 106 | 106 | if (!getParamVal('l', params, langStr)) |
| 107 | 107 | return L_EXTERNAL; |
| 108 | return NppParameters::getLangIDFromStr(langStr.c_str()); | |
| 108 | char lang[MAX_PATH]; | |
| 109 | wchar2char(langStr.c_str(), lang); | |
| 110 | return NppParameters::getLangIDFromStr(lang); | |
| 109 | 111 | }; |
| 110 | 112 | |
| 111 | 113 | int getLn2GoFromParam(ParamVector & params) { |
| 112 | string lineNumStr; | |
| 114 | wstring lineNumStr; | |
| 113 | 115 | if (!getParamVal('n', params, lineNumStr)) |
| 114 | 116 | return -1; |
| 115 | return atoi(lineNumStr.c_str()); | |
| 117 | return _wtoi(lineNumStr.c_str()); | |
| 116 | 118 | }; |
| 117 | 119 | |
| 118 | const char FLAG_MULTI_INSTANCE[] = "-multiInst"; | |
| 119 | const char FLAG_NO_PLUGIN[] = "-noPlugin"; | |
| 120 | const char FLAG_READONLY[] = "-ro"; | |
| 121 | const char FLAG_NOSESSION[] = "-nosession"; | |
| 122 | const char FLAG_NOTABBAR[] = "-notabbar"; | |
| 120 | const wchar_t FLAG_MULTI_INSTANCE[] = L"-multiInst"; | |
| 121 | const wchar_t FLAG_NO_PLUGIN[] = L"-noPlugin"; | |
| 122 | const wchar_t FLAG_READONLY[] = L"-ro"; | |
| 123 | const wchar_t FLAG_NOSESSION[] = L"-nosession"; | |
| 124 | const wchar_t FLAG_NOTABBAR[] = L"-notabbar"; | |
| 123 | 125 | |
| 124 | 126 | void doException(Notepad_plus & notepad_plus_plus); |
| 125 | 127 | |
| 126 | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdShow) | |
| 128 | int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpszCmdLine, int nCmdShow) | |
| 127 | 129 | { |
| 128 | 130 | bool TheFirstOne = true; |
| 129 | 131 | ::SetLastError(NO_ERROR); |
| ... | ...@@ -152,24 +154,24 @@ | |
| 152 | 154 | cmdLineParams._isNoSession = true; |
| 153 | 155 | } |
| 154 | 156 | |
| 155 | string quotFileName = ""; | |
| 157 | wstring quotFileName = L""; | |
| 156 | 158 | // tell the running instance the FULL path to the new files to load |
| 157 | 159 | size_t nrFilesToOpen = params.size(); |
| 158 | const char * currentFile; | |
| 159 | char fullFileName[MAX_PATH]; | |
| 160 | const wchar_t * currentFile; | |
| 161 | wchar_t fullFileName[MAX_PATH]; | |
| 160 | 162 | //TODO: try merging the flenames and see if it exists, user may have typed a single spaced filename without quotes |
| 161 | 163 | for(size_t i = 0; i < nrFilesToOpen; i++) { |
| 162 | 164 | currentFile = params.at(i); |
| 163 | 165 | //check if relative or full path. Relative paths dont have a colon for driveletter |
| 164 | BOOL isRelative = ::PathIsRelative(currentFile); | |
| 165 | quotFileName += "\""; | |
| 166 | BOOL isRelative = ::PathIsRelativeW(currentFile); | |
| 167 | quotFileName += L"\""; | |
| 166 | 168 | if (isRelative) { |
| 167 | ::GetFullPathName(currentFile, MAX_PATH, fullFileName, NULL); | |
| 169 | ::GetFullPathNameW(currentFile, MAX_PATH, fullFileName, NULL); | |
| 168 | 170 | quotFileName += fullFileName; |
| 169 | 171 | } else { |
| 170 | 172 | quotFileName += currentFile; |
| 171 | 173 | } |
| 172 | quotFileName += "\" "; | |
| 174 | quotFileName += L"\" "; | |
| 173 | 175 | } |
| 174 | 176 | if ((!isMultiInst) && (!TheFirstOne)) |
| 175 | 177 | { |
| ... | ...@@ -206,10 +208,10 @@ | |
| 206 | 208 | COPYDATASTRUCT fileNamesData; |
| 207 | 209 | fileNamesData.dwData = COPYDATA_FILENAMES; |
| 208 | 210 | fileNamesData.lpData = (void *)quotFileName.c_str(); |
| 209 | fileNamesData.cbData = long(quotFileName.length() + 1); | |
| 211 | fileNamesData.cbData = long((quotFileName.length() + 1) * sizeof(wchar_t)); | |
| 210 | 212 | |
| 211 | ::SendMessage(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)¶mData); | |
| 212 | ::SendMessage(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)&fileNamesData); | |
| 213 | ::SendMessageW(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)¶mData); | |
| 214 | ::SendMessageW(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)&fileNamesData); | |
| 213 | 215 | } |
| 214 | 216 | return 0; |
| 215 | 217 | } |
| ... | ...@@ -49,8 +49,11 @@ | |
| 49 | 49 | #include "AutoCompletion.h" |
| 50 | 50 | #include "Buffer.h" |
| 51 | 51 | #include "SmartHighlighter.h" |
| 52 | #include "UniConversion.h" | |
| 53 | #include "UrlHighlighter.h" | |
| 52 | 54 | |
| 53 | 55 | #define NOTEPAD_PP_CLASS_NAME "Notepad++" |
| 56 | #define NOTEPAD_PP_CLASS_NAME_W L"Notepad++" | |
| 54 | 57 | |
| 55 | 58 | #define MENU 0x01 |
| 56 | 59 | #define TOOLBAR 0x02 |
| ... | ...@@ -95,7 +98,7 @@ | |
| 95 | 98 | public: |
| 96 | 99 | Notepad_plus(); |
| 97 | 100 | virtual inline ~Notepad_plus(); |
| 98 | void init(HINSTANCE, HWND, const char *cmdLine, CmdLineParams *cmdLineParams); | |
| 101 | void init(HINSTANCE, HWND, const wchar_t *cmdLine, CmdLineParams *cmdLineParams); | |
| 99 | 102 | inline void killAllChildren(); |
| 100 | 103 | virtual inline void destroy(); |
| 101 | 104 | |
| ... | ...@@ -113,6 +116,7 @@ | |
| 113 | 116 | if (unicodeSupported?(::IsDialogMessageW(_hModelessDlgs[i], msg)):(::IsDialogMessageA(_hModelessDlgs[i], msg))) |
| 114 | 117 | return true; |
| 115 | 118 | } |
| 119 | ||
| 116 | 120 | return false; |
| 117 | 121 | }; |
| 118 | 122 | |
| ... | ...@@ -190,7 +194,9 @@ | |
| 190 | 194 | |
| 191 | 195 | void notifyBufferChanged(Buffer * buffer, int mask); |
| 192 | 196 | private: |
| 197 | void loadCommandlineParams(const wchar_t * commandLine, CmdLineParams * pCmdParams); | |
| 193 | 198 | static const char _className[32]; |
| 199 | static const wchar_t _classNameW[32]; | |
| 194 | 200 | char _nppPath[MAX_PATH]; |
| 195 | 201 | Window *_pMainWindow; |
| 196 | 202 | DockingManager _dockingManager; |
| ... | ...@@ -199,6 +205,7 @@ | |
| 199 | 205 | AutoCompletion _autoCompleteSub; //each Scintilla has its own autoComplete |
| 200 | 206 | |
| 201 | 207 | SmartHighlighter _smartHighlighter; |
| 208 | UrlHighlighter _urlHighlighter; | |
| 202 | 209 | |
| 203 | 210 | TiXmlNode *_nativeLang, *_toolIcons; |
| 204 | 211 | |
| ... | ...@@ -386,36 +393,44 @@ | |
| 386 | 393 | //END: Document management |
| 387 | 394 | |
| 388 | 395 | int doSaveOrNot(const char *fn) { |
| 389 | char pattern[64] = "Save file \"%s\" ?"; | |
| 390 | char phrase[512]; | |
| 391 | sprintf(phrase, pattern, fn); | |
| 392 | return doActionOrNot("Save", phrase, MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL); | |
| 396 | wchar_t fnW[MAX_PATH]; | |
| 397 | char2wchar(fn, fnW); | |
| 398 | wchar_t pattern[64] = L"Save file \"%s\" ?"; | |
| 399 | wchar_t phrase[512]; | |
| 400 | swprintf(phrase, pattern, fnW); | |
| 401 | return doActionOrNot(L"Save", phrase, MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL); | |
| 393 | 402 | }; |
| 394 | ||
| 395 | 403 | int doReloadOrNot(const char *fn) { |
| 396 | char pattern[128] = "The file \"%s\" is modified by another program.\rReload this file?"; | |
| 397 | char phrase[512]; | |
| 398 | sprintf(phrase, pattern, fn); | |
| 399 | return doActionOrNot("Reload", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); | |
| 404 | wchar_t fnW[MAX_PATH]; | |
| 405 | char2wchar(fn, fnW); | |
| 406 | wchar_t pattern[128] = L"The file \"%s\" is modified by another program.\rReload this file?"; | |
| 407 | wchar_t phrase[512]; | |
| 408 | swprintf(phrase, pattern, fnW); | |
| 409 | return doActionOrNot(L"Reload", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); | |
| 400 | 410 | }; |
| 401 | 411 | |
| 402 | 412 | int doCloseOrNot(const char *fn) { |
| 403 | char pattern[128] = "The file \"%s\" doesn't exist anymore.\rKeep this file in editor?"; | |
| 404 | char phrase[512]; | |
| 405 | sprintf(phrase, pattern, fn); | |
| 406 | return doActionOrNot("Keep non existing file", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); | |
| 413 | wchar_t fnW[MAX_PATH]; | |
| 414 | char2wchar(fn, fnW); | |
| 415 | wchar_t pattern[128] = L"The file \"%s\" doesn't exist anymore.\rKeep this file in editor?"; | |
| 416 | wchar_t phrase[512]; | |
| 417 | swprintf(phrase, pattern, fnW); | |
| 418 | return doActionOrNot(L"Keep non existing file", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); | |
| 407 | 419 | }; |
| 408 | 420 | |
| 409 | 421 | int doDeleteOrNot(const char *fn) { |
| 410 | char pattern[128] = "The file \"%s\"\rwill be deleted from your disk and this document will be closed.\rContinue?"; | |
| 411 | char phrase[512]; | |
| 412 | sprintf(phrase, pattern, fn); | |
| 413 | return doActionOrNot("Delete file", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); | |
| 422 | wchar_t fnW[MAX_PATH]; | |
| 423 | char2wchar(fn, fnW); | |
| 424 | wchar_t pattern[128] = L"The file \"%s\"\rwill be deleted from your disk and this document will be closed.\rContinue?"; | |
| 425 | wchar_t phrase[512]; | |
| 426 | swprintf(phrase, pattern, fnW); | |
| 427 | return doActionOrNot(L"Delete file", phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); | |
| 414 | 428 | }; |
| 415 | 429 | |
| 416 | int doActionOrNot(const char *title, const char *displayText, int type) { | |
| 417 | return ::MessageBox(_hSelf, displayText, title, type); | |
| 430 | int doActionOrNot(const wchar_t *title, const wchar_t *displayText, int type) { | |
| 431 | return ::MessageBoxW(_hSelf, displayText, title, type); | |
| 418 | 432 | }; |
| 433 | ||
| 419 | 434 | void enableMenu(int cmdID, bool doEnable) const { |
| 420 | 435 | int flag = doEnable?MF_ENABLED | MF_BYCOMMAND:MF_DISABLED | MF_GRAYED | MF_BYCOMMAND; |
| 421 | 436 | ::EnableMenuItem(_mainMenuHandle, cmdID, flag); |
| ... | ...@@ -685,25 +700,26 @@ | |
| 685 | 700 | void getMatchedFileNames(const char *dir, const vector<string> & patterns, vector<string> & fileNames, bool isRecursive, bool isInHiddenDir); |
| 686 | 701 | |
| 687 | 702 | void doSynScorll(HWND hW); |
| 688 | void setWorkingDir(char *dir) { | |
| 703 | void setWorkingDir(wchar_t *dir) { | |
| 689 | 704 | if (NppParameters::getInstance()->getNppGUI()._saveOpenKeepInSameDir) |
| 690 | 705 | return; |
| 691 | 706 | |
| 692 | if (!dir || !PathIsDirectory(dir)) | |
| 707 | if (!dir || !PathIsDirectoryW(dir)) | |
| 693 | 708 | { |
| 694 | 709 | //Non existing path, usually occurs when a new 1 file is open. |
| 695 | 710 | //Set working dir to Notepad++' directory to prevent directory lock. |
| 696 | char nppDir[MAX_PATH]; | |
| 711 | wchar_t nppDir[MAX_PATH]; | |
| 697 | 712 | |
| 698 | 713 | //wParam set to max_path in case boundary checks will ever be made. |
| 699 | SendMessage(_hSelf, NPPM_GETNPPDIRECTORY, (WPARAM)MAX_PATH, (LPARAM)nppDir); | |
| 700 | ::SetCurrentDirectory(nppDir); | |
| 714 | ::SendMessage(_hSelf, NPPM_GETNPPDIRECTORY, (WPARAM)MAX_PATH, (LPARAM)nppDir); | |
| 715 | ::SetCurrentDirectoryW(nppDir); | |
| 701 | 716 | return; |
| 702 | 717 | } |
| 703 | 718 | else |
| 704 | ::SetCurrentDirectory(dir); | |
| 719 | ::SetCurrentDirectoryW(dir); | |
| 705 | 720 | } |
| 706 | 721 | bool str2Cliboard(const char *str2cpy); |
| 722 | bool str2CliboardW(const wchar_t *str2cpy); | |
| 707 | 723 | bool bin2Cliboard(const unsigned char *uchar2cpy, size_t length); |
| 708 | 724 | |
| 709 | 725 | bool getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible); |
| ... | ...@@ -771,8 +787,6 @@ | |
| 771 | 787 | |
| 772 | 788 | bool dumpFiles(const char * outdir, const char * fileprefix = ""); //helper func |
| 773 | 789 | void drawTabbarColoursFromStylerArray(); |
| 774 | ||
| 775 | void loadCommandlineParams(const char * commandLine, CmdLineParams * pCmdParams); | |
| 776 | 790 | }; |
| 777 | 791 | |
| 778 | 792 | #endif //NOTEPAD_PLUS_H |
| ... | ...@@ -474,13 +474,13 @@ | |
| 474 | 474 | } |
| 475 | 475 | bool isSelected = (nTab == ::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0)); |
| 476 | 476 | |
| 477 | char label[MAX_PATH]; | |
| 478 | TCITEM tci; | |
| 477 | wchar_t label[MAX_PATH]; | |
| 478 | TCITEMW tci; | |
| 479 | 479 | tci.mask = TCIF_TEXT|TCIF_IMAGE; |
| 480 | 480 | tci.pszText = label; |
| 481 | 481 | tci.cchTextMax = MAX_PATH-1; |
| 482 | 482 | |
| 483 | if (!::SendMessage(_hSelf, TCM_GETITEM, nTab, reinterpret_cast<LPARAM>(&tci))) | |
| 483 | if (!::SendMessage(_hSelf, TCM_GETITEMW, nTab, reinterpret_cast<LPARAM>(&tci))) | |
| 484 | 484 | { |
| 485 | 485 | ::MessageBox(NULL, "! TCM_GETITEM", "", MB_OK); |
| 486 | 486 | //return ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam); |
| ... | ...@@ -693,7 +693,7 @@ | |
| 693 | 693 | else |
| 694 | 694 | Flags |= DT_BOTTOM; |
| 695 | 695 | } |
| 696 | ::DrawText(hDC, label, strlen(label), &rect, Flags); | |
| 696 | ::DrawTextW(hDC, label, wcslen(label), &rect, Flags); | |
| 697 | 697 | ::RestoreDC(hDC, nSavedDC); |
| 698 | 698 | } |
| 699 | 699 | |
| ... | ...@@ -736,37 +736,37 @@ | |
| 736 | 736 | ::SendMessage(_hSelf, TCM_SETCURSEL, nTab, 0); |
| 737 | 737 | |
| 738 | 738 | //2. shift their data, and insert the source |
| 739 | TCITEM itemData_nDraggedTab, itemData_shift; | |
| 739 | TCITEMW itemData_nDraggedTab, itemData_shift; | |
| 740 | 740 | itemData_nDraggedTab.mask = itemData_shift.mask = TCIF_IMAGE | TCIF_TEXT | TCIF_PARAM; |
| 741 | char str1[256]; | |
| 742 | char str2[256]; | |
| 741 | wchar_t str1[MAX_PATH]; | |
| 742 | wchar_t str2[MAX_PATH]; | |
| 743 | 743 | |
| 744 | 744 | itemData_nDraggedTab.pszText = str1; |
| 745 | itemData_nDraggedTab.cchTextMax = (sizeof(str1)); | |
| 745 | itemData_nDraggedTab.cchTextMax = (MAX_PATH-1); | |
| 746 | 746 | |
| 747 | 747 | itemData_shift.pszText = str2; |
| 748 | itemData_shift.cc |