Make the EOL type more explicite
This commit is contained in:
parent
2fd963d932
commit
280ddcd493
@ -2117,15 +2117,15 @@ void Notepad_plus::setLangStatus(LangType langType)
|
||||
}
|
||||
|
||||
|
||||
void Notepad_plus::setDisplayFormat(FormatType format)
|
||||
void Notepad_plus::setDisplayFormat(EolType format)
|
||||
{
|
||||
const TCHAR* str = TEXT("??");
|
||||
switch (format)
|
||||
{
|
||||
case FormatType::windows: str = TEXT("Dos\\Windows"); break;
|
||||
case FormatType::macos: str = TEXT("Macintosh"); break;
|
||||
case FormatType::unix: str = TEXT("UNIX"); break;
|
||||
case FormatType::unknown: str = TEXT("Unknown"); assert(false); break;
|
||||
case EolType::windows: str = TEXT("Dos\\Windows"); break;
|
||||
case EolType::macos: str = TEXT("Macintosh"); break;
|
||||
case EolType::unix: str = TEXT("UNIX"); break;
|
||||
case EolType::unknown: str = TEXT("Unknown"); assert(false); break;
|
||||
}
|
||||
_statusBar.setText(str, STATUSBAR_EOF_FORMAT);
|
||||
}
|
||||
@ -3503,11 +3503,11 @@ void Notepad_plus::dynamicCheckMenuAndTB() const
|
||||
}
|
||||
|
||||
|
||||
void Notepad_plus::enableConvertMenuItems(FormatType format) const
|
||||
void Notepad_plus::enableConvertMenuItems(EolType format) const
|
||||
{
|
||||
enableCommand(IDM_FORMAT_TODOS, (format != FormatType::windows), MENU);
|
||||
enableCommand(IDM_FORMAT_TOUNIX, (format != FormatType::unix), MENU);
|
||||
enableCommand(IDM_FORMAT_TOMAC, (format != FormatType::macos), MENU);
|
||||
enableCommand(IDM_FORMAT_TODOS, (format != EolType::windows), MENU);
|
||||
enableCommand(IDM_FORMAT_TOUNIX, (format != EolType::unix), MENU);
|
||||
enableCommand(IDM_FORMAT_TOMAC, (format != EolType::macos), MENU);
|
||||
}
|
||||
|
||||
|
||||
|
@ -496,14 +496,14 @@ private:
|
||||
void getMainClientRect(RECT & rc) const;
|
||||
void staticCheckMenuAndTB() const;
|
||||
void dynamicCheckMenuAndTB() const;
|
||||
void enableConvertMenuItems(FormatType f) const;
|
||||
void enableConvertMenuItems(EolType f) const;
|
||||
void checkUnicodeMenuItems() const;
|
||||
|
||||
generic_string getLangDesc(LangType langType, bool getName = false);
|
||||
|
||||
void setLangStatus(LangType langType);
|
||||
|
||||
void setDisplayFormat(FormatType f);
|
||||
void setDisplayFormat(EolType f);
|
||||
int getCmdIDFromEncoding(int encoding) const;
|
||||
void setUniModeText();
|
||||
void checkLangsMenu(int id) const ;
|
||||
|
@ -326,8 +326,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
if (!wParam)
|
||||
return FALSE;
|
||||
|
||||
FormatType newFormat = convertIntToFormatType(static_cast<int>(lParam), FormatType::unknown);
|
||||
if (FormatType::unknown == newFormat)
|
||||
EolType newFormat = convertIntToFormatType(static_cast<int>(lParam), EolType::unknown);
|
||||
if (EolType::unknown == newFormat)
|
||||
{
|
||||
assert(false and "invalid buffer format message");
|
||||
return FALSE;
|
||||
|
@ -1704,9 +1704,9 @@ void Notepad_plus::command(int id)
|
||||
case IDM_FORMAT_TOUNIX:
|
||||
case IDM_FORMAT_TOMAC:
|
||||
{
|
||||
FormatType newFormat = (id == IDM_FORMAT_TODOS)
|
||||
? FormatType::windows
|
||||
: (id == IDM_FORMAT_TOUNIX) ? FormatType::unix : FormatType::macos;
|
||||
EolType newFormat = (id == IDM_FORMAT_TODOS)
|
||||
? EolType::windows
|
||||
: (id == IDM_FORMAT_TOUNIX) ? EolType::unix : EolType::macos;
|
||||
|
||||
Buffer* buf = _pEditView->getCurrentBuffer();
|
||||
buf->setFormat(newFormat);
|
||||
|
@ -4134,17 +4134,17 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
|
||||
int i;
|
||||
if (element->Attribute(TEXT("format"), &i))
|
||||
{
|
||||
FormatType newFormat = FormatType::osdefault;
|
||||
EolType newFormat = EolType::osdefault;
|
||||
switch (i)
|
||||
{
|
||||
case static_cast<LPARAM>(FormatType::windows) :
|
||||
newFormat = FormatType::windows;
|
||||
case static_cast<LPARAM>(EolType::windows) :
|
||||
newFormat = EolType::windows;
|
||||
break;
|
||||
case static_cast<LPARAM>(FormatType::macos) :
|
||||
newFormat = FormatType::macos;
|
||||
case static_cast<LPARAM>(EolType::macos) :
|
||||
newFormat = EolType::macos;
|
||||
break;
|
||||
case static_cast<LPARAM>(FormatType::unix) :
|
||||
newFormat = FormatType::unix;
|
||||
case static_cast<LPARAM>(EolType::unix) :
|
||||
newFormat = EolType::unix;
|
||||
break;
|
||||
default:
|
||||
assert(false and "invalid buffer format - fallback to default");
|
||||
@ -6462,16 +6462,16 @@ void Date::now()
|
||||
}
|
||||
|
||||
|
||||
FormatType convertIntToFormatType(int value, FormatType defvalue)
|
||||
EolType convertIntToFormatType(int value, EolType defvalue)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case static_cast<LPARAM>(FormatType::windows):
|
||||
return FormatType::windows;
|
||||
case static_cast<LPARAM>(FormatType::macos):
|
||||
return FormatType::macos;
|
||||
case static_cast<LPARAM>(FormatType::unix):
|
||||
return FormatType::unix;
|
||||
case static_cast<LPARAM>(EolType::windows) :
|
||||
return EolType::windows;
|
||||
case static_cast<LPARAM>(EolType::macos) :
|
||||
return EolType::macos;
|
||||
case static_cast<LPARAM>(EolType::unix) :
|
||||
return EolType::unix;
|
||||
default:
|
||||
return defvalue;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ const int TAB_MULTILINE = 128; // 1000 0000
|
||||
const int TAB_HIDE = 256; //1 0000 0000
|
||||
|
||||
|
||||
enum class FormatType: std::uint8_t
|
||||
enum class EolType: std::uint8_t
|
||||
{
|
||||
windows,
|
||||
macos,
|
||||
@ -109,7 +109,7 @@ enum class FormatType: std::uint8_t
|
||||
** \param value An arbitrary int
|
||||
** \param defvalue The default value to use if an invalid value is provided
|
||||
*/
|
||||
FormatType convertIntToFormatType(int value, FormatType defvalue = FormatType::osdefault);
|
||||
EolType convertIntToFormatType(int value, EolType defvalue = EolType::osdefault);
|
||||
|
||||
|
||||
|
||||
@ -571,7 +571,7 @@ private :
|
||||
|
||||
struct NewDocDefaultSettings final
|
||||
{
|
||||
FormatType _format = FormatType::osdefault;
|
||||
EolType _format = EolType::osdefault;
|
||||
UniMode _unicodeMode = uniCookie;
|
||||
bool _openAnsiAsUtf8 = true;
|
||||
LangType _lang = L_TEXT;
|
||||
|
@ -54,7 +54,7 @@ long Buffer::_recentTagCtr = 0;
|
||||
namespace // anonymous
|
||||
{
|
||||
|
||||
static FormatType getEOLFormatForm(const char* const data, size_t length, FormatType defvalue = FormatType::osdefault)
|
||||
static EolType getEOLFormatForm(const char* const data, size_t length, EolType defvalue = EolType::osdefault)
|
||||
{
|
||||
assert(length == 0 or data != nullptr && "invalid buffer for getEOLFormatForm()");
|
||||
|
||||
@ -63,13 +63,13 @@ namespace // anonymous
|
||||
if (data[i] == CR)
|
||||
{
|
||||
if (i + 1 < length && data[i + 1] == LF)
|
||||
return FormatType::windows;
|
||||
return EolType::windows;
|
||||
|
||||
return FormatType::macos;
|
||||
return EolType::macos;
|
||||
}
|
||||
|
||||
if (data[i] == LF)
|
||||
return FormatType::unix;
|
||||
return EolType::unix;
|
||||
}
|
||||
|
||||
return defvalue; // fallback unknown
|
||||
@ -592,7 +592,7 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
|
||||
Utf8_16_Read UnicodeConvertor; //declare here so we can get information after loading is done
|
||||
|
||||
char data[blockSize + 8]; // +8 for incomplete multibyte char
|
||||
FormatType bkformat = FormatType::unknown;
|
||||
EolType bkformat = EolType::unknown;
|
||||
LangType detectedLang = L_TEXT;
|
||||
bool res = loadFileData(doc, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, detectedLang, encoding, &bkformat);
|
||||
if (res)
|
||||
@ -663,7 +663,7 @@ bool FileManager::reloadBuffer(BufferID id)
|
||||
buf->_canNotify = false; //disable notify during file load, we dont want dirty to be triggered
|
||||
int encoding = buf->getEncoding();
|
||||
char data[blockSize + 8]; // +8 for incomplete multibyte char
|
||||
FormatType bkformat;
|
||||
EolType bkformat;
|
||||
LangType lang = buf->getLangType();
|
||||
|
||||
|
||||
@ -682,7 +682,7 @@ bool FileManager::reloadBuffer(BufferID id)
|
||||
|
||||
if (nullptr != UnicodeConvertor.getNewBuf())
|
||||
{
|
||||
FormatType format = getEOLFormatForm(UnicodeConvertor.getNewBuf(), UnicodeConvertor.getNewSize(),ndds._format);
|
||||
EolType format = getEOLFormatForm(UnicodeConvertor.getNewBuf(), UnicodeConvertor.getNewSize(), ndds._format);
|
||||
buf->setFormat(format);
|
||||
}
|
||||
else{
|
||||
@ -1340,7 +1340,7 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
|
||||
return L_TEXT;
|
||||
}
|
||||
|
||||
inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * UnicodeConvertor, LangType & language, int & encoding, FormatType* pFormat)
|
||||
inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * unicodeConvertor, LangType & language, int & encoding, EolType* pFormat)
|
||||
{
|
||||
FILE *fp = generic_fopen(filename, TEXT("rb"));
|
||||
if (!fp)
|
||||
@ -1395,7 +1395,7 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
|
||||
_pscratchTilla->execute(SCI_SETCODEPAGE, SC_CP_UTF8);
|
||||
|
||||
bool success = true;
|
||||
FormatType format = FormatType::unknown;
|
||||
EolType format = EolType::unknown;
|
||||
__try
|
||||
{
|
||||
// First allocate enough memory for the whole file (this will reduce memory copy during loading)
|
||||
@ -1452,15 +1452,15 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
|
||||
_pscratchTilla->execute(SCI_APPENDTEXT, newDataLen, (LPARAM)newData);
|
||||
}
|
||||
|
||||
if (format == FormatType::unknown)
|
||||
format = getEOLFormatForm(data, lenFile, FormatType::unknown);
|
||||
if (format == EolType::unknown)
|
||||
format = getEOLFormatForm(data, lenFile, EolType::unknown);
|
||||
}
|
||||
else
|
||||
{
|
||||
lenConvert = UnicodeConvertor->convert(data, lenFile);
|
||||
_pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf()));
|
||||
if (format == FormatType::unknown)
|
||||
format = getEOLFormatForm(UnicodeConvertor->getNewBuf(), UnicodeConvertor->getNewSize(), FormatType::unknown);
|
||||
lenConvert = unicodeConvertor->convert(data, lenFile);
|
||||
_pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(unicodeConvertor->getNewBuf()));
|
||||
if (format == EolType::unknown)
|
||||
format = getEOLFormatForm(unicodeConvertor->getNewBuf(), unicodeConvertor->getNewSize(), EolType::unknown);
|
||||
}
|
||||
|
||||
if (_pscratchTilla->execute(SCI_GETSTATUS) != SC_STATUS_OK)
|
||||
@ -1486,7 +1486,7 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
|
||||
// broadcast the format
|
||||
if (pFormat != nullptr)
|
||||
{
|
||||
if (format == FormatType::unknown)
|
||||
if (format == EolType::unknown)
|
||||
{
|
||||
NppParameters *pNppParamInst = NppParameters::getInstance();
|
||||
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); // for ndds._format
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
private:
|
||||
~FileManager();
|
||||
int detectCodepage(char* buf, size_t len);
|
||||
bool loadFileData(Document doc, const TCHAR* filename, char* buffer, Utf8_16_Read* UnicodeConvertor, LangType & language, int& encoding, FormatType* pFormat = nullptr);
|
||||
bool loadFileData(Document doc, const TCHAR* filename, char* buffer, Utf8_16_Read* UnicodeConvertor, LangType & language, int& encoding, EolType* pFormat = nullptr);
|
||||
LangType detectLanguageFromTextBegining(const unsigned char *data, unsigned int dataLen);
|
||||
|
||||
|
||||
@ -196,11 +196,11 @@ public:
|
||||
doNotify(BufferChangeReadonly);
|
||||
}
|
||||
|
||||
FormatType getFormat() const {
|
||||
EolType getFormat() const {
|
||||
return _format;
|
||||
}
|
||||
|
||||
void setFormat(FormatType format) {
|
||||
void setFormat(EolType format) {
|
||||
_format = format;
|
||||
doNotify(BufferChangeFormat);
|
||||
}
|
||||
@ -365,7 +365,7 @@ private:
|
||||
LangType _lang;
|
||||
generic_string _userLangExt; // it's useful if only (_lang == L_USER)
|
||||
bool _isDirty = false;
|
||||
FormatType _format = FormatType::osdefault;
|
||||
EolType _format = EolType::osdefault;
|
||||
UniMode _unicodeMode;
|
||||
int _encoding = -1;
|
||||
bool _isUserReadOnly = false;
|
||||
|
@ -1107,16 +1107,16 @@ INT_PTR CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPAR
|
||||
int ID2Check = IDC_RADIO_F_WIN;
|
||||
switch (ndds._format)
|
||||
{
|
||||
case FormatType::windows:
|
||||
case EolType::windows:
|
||||
ID2Check = IDC_RADIO_F_WIN;
|
||||
break;
|
||||
case FormatType::macos:
|
||||
case EolType::macos:
|
||||
ID2Check = IDC_RADIO_F_MAC;
|
||||
break;
|
||||
case FormatType::unix:
|
||||
case EolType::unix:
|
||||
ID2Check = IDC_RADIO_F_UNIX;
|
||||
break;
|
||||
case FormatType::unknown:
|
||||
case EolType::unknown:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
@ -1255,17 +1255,17 @@ INT_PTR CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPAR
|
||||
|
||||
case IDC_RADIO_F_MAC:
|
||||
{
|
||||
ndds._format = FormatType::macos;
|
||||
ndds._format = EolType::macos;
|
||||
return TRUE;
|
||||
}
|
||||
case IDC_RADIO_F_UNIX:
|
||||
{
|
||||
ndds._format = FormatType::unix;
|
||||
ndds._format = EolType::unix;
|
||||
return TRUE;
|
||||
}
|
||||
case IDC_RADIO_F_WIN:
|
||||
{
|
||||
ndds._format = FormatType::windows;
|
||||
ndds._format = EolType::windows;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user