[NEW_FEATURE] Add the utf8->ansi / ansi->utf8 conversion feature.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@130 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
ec338d909a
commit
393ded102c
@ -307,7 +307,7 @@ bool Notepad_plus::loadSession(Session & session)
|
||||
setLangFromName(pLn);
|
||||
|
||||
_pEditView->getCurrentBuffer().setPosition(session._mainViewFiles[i]);
|
||||
_pEditView->restoreCurrentPos(session._mainViewFiles[i]);
|
||||
_pEditView->restoreCurrentPos();
|
||||
|
||||
for (size_t j = 0 ; j < session._mainViewFiles[i].marks.size() ; j++)
|
||||
bookmarkAdd(session._mainViewFiles[i].marks[j]);
|
||||
@ -345,7 +345,7 @@ bool Notepad_plus::loadSession(Session & session)
|
||||
setLangFromName(pLn);
|
||||
|
||||
_pEditView->getCurrentBuffer().setPosition(session._subViewFiles[k]);
|
||||
_pEditView->restoreCurrentPos(session._subViewFiles[k]);
|
||||
_pEditView->restoreCurrentPos();
|
||||
|
||||
for (size_t j = 0 ; j < session._subViewFiles[k].marks.size() ; j++)
|
||||
bookmarkAdd(session._subViewFiles[k].marks[j]);
|
||||
@ -3266,6 +3266,120 @@ void Notepad_plus::command(int id)
|
||||
break;
|
||||
}
|
||||
|
||||
case IDM_FORMAT_CONV2_ANSI:
|
||||
case IDM_FORMAT_CONV2_AS_UTF_8:
|
||||
case IDM_FORMAT_CONV2_UTF_8:
|
||||
case IDM_FORMAT_CONV2_UCS_2BE:
|
||||
case IDM_FORMAT_CONV2_UCS_2LE:
|
||||
{
|
||||
int idEncoding = -1;
|
||||
Buffer & currentBuffer = _pEditView->getCurrentBuffer();
|
||||
UniMode um = currentBuffer._unicodeMode;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case IDM_FORMAT_CONV2_ANSI:
|
||||
{
|
||||
if (um == uni8Bit)
|
||||
return;
|
||||
|
||||
idEncoding = IDM_FORMAT_ANSI;
|
||||
break;
|
||||
}
|
||||
case IDM_FORMAT_CONV2_AS_UTF_8:
|
||||
{
|
||||
idEncoding = IDM_FORMAT_AS_UTF_8;
|
||||
if (um == uniCookie)
|
||||
return;
|
||||
|
||||
if (um != uni8Bit)
|
||||
{
|
||||
::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case IDM_FORMAT_CONV2_UTF_8:
|
||||
{
|
||||
idEncoding = IDM_FORMAT_UTF_8;
|
||||
if (um == uniUTF8)
|
||||
return;
|
||||
|
||||
if (um != uni8Bit)
|
||||
{
|
||||
::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case IDM_FORMAT_CONV2_UCS_2BE:
|
||||
{
|
||||
idEncoding = IDM_FORMAT_UCS_2BE;
|
||||
if (um == uni16BE)
|
||||
return;
|
||||
|
||||
if (um != uni8Bit)
|
||||
{
|
||||
::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case IDM_FORMAT_CONV2_UCS_2LE:
|
||||
{
|
||||
idEncoding = IDM_FORMAT_UCS_2LE;
|
||||
if (um == uni16LE)
|
||||
return;
|
||||
if (um != uni8Bit)
|
||||
{
|
||||
::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idEncoding != -1)
|
||||
{
|
||||
// Save the current clipboard content
|
||||
::OpenClipboard(_hSelf);
|
||||
HANDLE clipboardData = ::GetClipboardData(CF_TEXT);
|
||||
int len = ::GlobalSize(clipboardData);
|
||||
HANDLE allocClipboardData = ::GlobalAlloc(GMEM_MOVEABLE, len);
|
||||
HANDLE clipboardData2 = ::GlobalLock(allocClipboardData);
|
||||
::memcpy(clipboardData2, clipboardData, len);
|
||||
::GlobalUnlock(allocClipboardData);
|
||||
::CloseClipboard();
|
||||
|
||||
_pEditView->saveCurrentPos();
|
||||
|
||||
// Cut all text
|
||||
int docLen = _pEditView->getCurrentDocLen();
|
||||
_pEditView->execute(SCI_COPYRANGE, 0, docLen);
|
||||
_pEditView->execute(SCI_CLEARALL);
|
||||
|
||||
// Change to the proper buffer, save buffer status
|
||||
|
||||
::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0);
|
||||
|
||||
// Paste the texte, restore buffer status
|
||||
_pEditView->execute(SCI_PASTE);
|
||||
_pEditView->restoreCurrentPos();
|
||||
|
||||
// Restore the previous clipboard data
|
||||
::OpenClipboard(_hSelf);
|
||||
::EmptyClipboard();
|
||||
::SetClipboardData(CF_TEXT, clipboardData2);
|
||||
::CloseClipboard();
|
||||
|
||||
::GlobalFree(allocClipboardData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case IDM_SETTING_TAB_REPLCESPACE:
|
||||
{
|
||||
NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI());
|
||||
@ -4283,7 +4397,6 @@ void Notepad_plus::reload(const char *fileName)
|
||||
{
|
||||
Utf8_16_Read UnicodeConvertor;
|
||||
Buffer & buffer = _pEditView->getCurrentBuffer();
|
||||
Position pos = buffer._pos;
|
||||
|
||||
FILE *fp = fopen(fileName, "rb");
|
||||
if (fp)
|
||||
@ -4311,7 +4424,7 @@ void Notepad_plus::reload(const char *fileName)
|
||||
_pEditView->getFocus();
|
||||
_pEditView->execute(SCI_SETSAVEPOINT);
|
||||
_pEditView->execute(EM_EMPTYUNDOBUFFER);
|
||||
_pEditView->restoreCurrentPos(pos);
|
||||
_pEditView->restoreCurrentPos();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -6643,21 +6756,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_APPCOMMAND :
|
||||
{
|
||||
switch(GET_APPCOMMAND_LPARAM(lParam))
|
||||
{
|
||||
case APPCOMMAND_BROWSER_BACKWARD :
|
||||
case APPCOMMAND_BROWSER_FORWARD :
|
||||
int nbDoc = _mainDocTab.isVisible()?_mainEditView.getNbDoc():0;
|
||||
nbDoc += _subDocTab.isVisible()?_subEditView.getNbDoc():0;
|
||||
if (nbDoc > 1)
|
||||
activateNextDoc((GET_APPCOMMAND_LPARAM(lParam) == APPCOMMAND_BROWSER_FORWARD)?dirDown:dirUp);
|
||||
_linkTriggered = true;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case NPPM_GETNBSESSIONFILES :
|
||||
{
|
||||
const char *sessionFileName = (const char *)lParam;
|
||||
@ -6801,7 +6899,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
}
|
||||
|
||||
case NPPM_ACTIVATEDOC :
|
||||
case NPPM_TRIGGERTABBARCONTEXTMENU:
|
||||
// case NPPM_ACTIVATEDOCMENU:
|
||||
{
|
||||
// similar to NPPM_ACTIVEDOC
|
||||
int whichView = ((wParam != MAIN_VIEW) && (wParam != SUB_VIEW))?getCurrentView():wParam;
|
||||
@ -6810,7 +6908,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
switchEditViewTo(whichView);
|
||||
activateDoc(index);
|
||||
|
||||
if (Message == NPPM_TRIGGERTABBARCONTEXTMENU)
|
||||
//if (Message == NPPM_ACTIVATEDOCMENU)
|
||||
{
|
||||
// open here tab menu
|
||||
NMHDR nmhdr;
|
||||
@ -6876,7 +6974,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
int counter = 0;
|
||||
int lastLine = int(_pEditView->execute(SCI_GETLINECOUNT)) - 1;
|
||||
int currLine = _pEditView->getCurrentLineNumber();
|
||||
|
@ -397,7 +397,12 @@ BEGIN
|
||||
MENUITEM "Encode in UTF-8", IDM_FORMAT_UTF_8
|
||||
MENUITEM "Encode in UCS-2 Big Endian", IDM_FORMAT_UCS_2BE
|
||||
MENUITEM "Encode in UCS-2 Little Endian", IDM_FORMAT_UCS_2LE
|
||||
//MENUITEM SEPARATOR
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Convert to ANSI", IDM_FORMAT_CONV2_ANSI
|
||||
MENUITEM "Convert to UTF-8 without BOM", IDM_FORMAT_CONV2_AS_UTF_8
|
||||
MENUITEM "Convert to UTF-8", IDM_FORMAT_CONV2_UTF_8
|
||||
MENUITEM "Convert to UCS-2 Big Endian", IDM_FORMAT_CONV2_UCS_2BE
|
||||
MENUITEM "Convert to UCS-2 Little Endian", IDM_FORMAT_CONV2_UCS_2LE
|
||||
END
|
||||
|
||||
POPUP "&Language"
|
||||
|
@ -884,7 +884,7 @@ void ScintillaEditView::saveCurrentPos()
|
||||
buf._pos._selMode = execute(SCI_GETSELECTIONMODE);
|
||||
}
|
||||
|
||||
void ScintillaEditView::restoreCurrentPos(const Position & prevPos)
|
||||
void ScintillaEditView::restoreCurrentPos()
|
||||
{
|
||||
_wrapRestoreNeeded = isWrap();
|
||||
execute(SCI_GOTOPOS, 0); //make sure first line visible by setting caret there, will scroll to top of document
|
||||
@ -928,7 +928,7 @@ char * ScintillaEditView::activateDocAt(int index)
|
||||
// before activating another document, we get the current position
|
||||
// from the Scintilla view then save it to the current document
|
||||
saveCurrentPos();
|
||||
Position & prevDocPos = _buffers[_currentIndex]._pos;
|
||||
//Position & prevDocPos = _buffers[_currentIndex]._pos;
|
||||
|
||||
// get foldStateIOnfo of current doc
|
||||
std::vector<HeaderLineState> lineStateVector;
|
||||
@ -981,7 +981,7 @@ char * ScintillaEditView::activateDocAt(int index)
|
||||
//if (isDocTypeDiff)
|
||||
defineDocType(_buffers[_currentIndex]._lang);
|
||||
|
||||
restoreCurrentPos(prevDocPos);
|
||||
restoreCurrentPos();
|
||||
|
||||
execute(SCI_SETEOLMODE, _buffers[_currentIndex]._format);
|
||||
::SendMessage(_hParent, NPPM_INTERNAL_DOCSWITCHIN, 0, (LPARAM)_hSelf);
|
||||
@ -1074,7 +1074,7 @@ int ScintillaEditView::closeCurrentDoc(int & i2Activate)
|
||||
{
|
||||
int oldCurrent = _currentIndex;
|
||||
|
||||
Position & prevDocPos = _buffers[_currentIndex]._pos;
|
||||
//Position & prevDocPos = _buffers[_currentIndex]._pos;
|
||||
|
||||
// if the file 2 delete is the last one
|
||||
if (_currentIndex == int(_buffers.size()) - 1)
|
||||
@ -1108,7 +1108,7 @@ int ScintillaEditView::closeCurrentDoc(int & i2Activate)
|
||||
execute(SCI_RELEASEDOCUMENT, 0, _buffers[_currentIndex]._doc);
|
||||
|
||||
defineDocType(_buffers[_currentIndex]._lang);
|
||||
restoreCurrentPos(prevDocPos);
|
||||
restoreCurrentPos();
|
||||
|
||||
// restore the collapsed info
|
||||
int nbLineState = _buffers[_currentIndex]._foldState.size();
|
||||
|
@ -242,7 +242,7 @@ public:
|
||||
};
|
||||
|
||||
void saveCurrentPos();
|
||||
void restoreCurrentPos(const Position & prevPos);
|
||||
void restoreCurrentPos();
|
||||
bool needRestoreFromWrap() {
|
||||
return _wrapRestoreNeeded;
|
||||
}
|
||||
|
@ -183,6 +183,11 @@
|
||||
#define IDM_FORMAT_UCS_2BE (IDM_FORMAT + 6)
|
||||
#define IDM_FORMAT_UCS_2LE (IDM_FORMAT + 7)
|
||||
#define IDM_FORMAT_AS_UTF_8 (IDM_FORMAT + 8)
|
||||
#define IDM_FORMAT_CONV2_ANSI (IDM_FORMAT + 9)
|
||||
#define IDM_FORMAT_CONV2_AS_UTF_8 (IDM_FORMAT + 10)
|
||||
#define IDM_FORMAT_CONV2_UTF_8 (IDM_FORMAT + 11)
|
||||
#define IDM_FORMAT_CONV2_UCS_2BE (IDM_FORMAT + 12)
|
||||
#define IDM_FORMAT_CONV2_UCS_2LE (IDM_FORMAT + 13)
|
||||
|
||||
#define IDM_LANG (IDM + 6000)
|
||||
#define IDM_LANGSTYLE_CONFIG_DLG (IDM_LANG + 1)
|
||||
|
Loading…
Reference in New Issue
Block a user