Skip to content
Permalink
Browse files

Notify binary file been locked for editing.

  • Loading branch information...
zufuliu committed May 25, 2019
1 parent 6bf6f24 commit 67a3fb397f7fde7b0a02b4c2f8e87e7bf8270c07
Showing with 43 additions and 2 deletions.
  1. +1 −1 src/Dialogs.c
  2. +1 −1 src/Dialogs.h
  3. +34 −0 src/Notepad2.c
  4. +5 −0 src/Notepad2.h
  5. +1 −0 src/Notepad2.rc
  6. +1 −0 src/resource.h
@@ -2334,7 +2334,7 @@ static INT_PTR CALLBACK InfoBoxDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR
// InfoBox()
//
//
INT_PTR InfoBox(int iType, LPCWSTR lpstrSetting, int uidMessage, ...) {
INT_PTR InfoBox(int iType, LPCWSTR lpstrSetting, UINT uidMessage, ...) {
const int iMode = IniGetInt(INI_SECTION_NAME_SUPPRESSED_MESSAGES, lpstrSetting, 0);
if (StrNotEmpty(lpstrSetting) && iMode == 1) {
return (iType == MBYESNO) ? IDYES : IDOK;
@@ -66,7 +66,7 @@ void InitZoomLevelComboBox(HWND hwnd, int nCtlId, int zoomLevel);
BOOL GetZoomLevelComboBoxValue(HWND hwnd, int nCtrId, int *zoomLevel);
void ZoomLevelDlg(HWND hwnd, BOOL bBottom);
BOOL AutoCompletionSettingsDlg(HWND hwnd);
INT_PTR InfoBox(int iType, LPCWSTR lpstrSetting, int uidMessage, ...);
INT_PTR InfoBox(int iType, LPCWSTR lpstrSetting, UINT uidMessage, ...);

#endif // NOTEPAD2_DIALOGS_H_

@@ -2121,6 +2121,12 @@ BOOL IsIMEInNativeMode(void) {
void MsgNotifyZoom(void) {
iZoomLevel = SciCall_GetZoom();

#if 0
char buf[64];
sprintf(buf, "Zoom: %d%%", iZoomLevel);
ShowNotificationA(SC_NOTIFICATIONPOSITION_CENTER, buf);
#endif

UpdateStatusBarCache(STATUS_DOCZOOM);
UpdateLineNumberWidth();
UpdateFoldMarginWidth();
@@ -7103,6 +7109,7 @@ BOOL FileLoad(BOOL bDontSave, BOOL bNew, BOOL bReload, BOOL bNoEncDetect, LPCWST
}
// notify binary file been locked for editing
if (binary) {
ShowNotificationMessage(SC_NOTIFICATIONPOSITION_BOTTOMRIGHT, IDS_BINARY_FILE_LOCKED);
return fSuccess;
}
// Show inconsistent line endings warning
@@ -7938,6 +7945,33 @@ void SetNotifyIconTitle(HWND hwnd) {
Shell_NotifyIcon(NIM_MODIFY, &nid);
}

void ShowNotificationA(int notifyPos, LPCSTR lpszText) {
SciCall_ShowNotification(notifyPos, lpszText);
}

void ShowNotificationW(int notifyPos, LPCWSTR lpszText) {
const int cpEdit = SciCall_GetCodePage();
const int wchLen = lstrlen(lpszText);
const int cchLen = wchLen*kMaxMultiByteCount + 1;
char *cchText = (char *)NP2HeapAlloc(cchLen);
WideCharToMultiByte(cpEdit, 0, lpszText, -1, cchText, cchLen, NULL, NULL);
ShowNotificationA(notifyPos, cchText);
NP2HeapFree(cchText);
}

void ShowNotificationMessage(int notifyPos, UINT uidMessage, ...) {
WCHAR wchFormat[1024] = L"";
WCHAR wchMessage[2048] = L"";
GetString(uidMessage, wchFormat, COUNTOF(wchFormat));

va_list va;
va_start(va, uidMessage);
wvsprintf(wchMessage, wchFormat, va);
va_end(va);

ShowNotificationW(notifyPos, wchMessage);
}

//=============================================================================
//
// InstallFileWatching()
@@ -133,6 +133,11 @@ BOOL RelaunchElevated(void);
void SnapToDefaultPos(HWND hwnd);
void ShowNotifyIcon(HWND hwnd, BOOL bAdd);
void SetNotifyIconTitle(HWND hwnd);

void ShowNotificationA(int notifyPos, LPCSTR lpszText);
void ShowNotificationW(int notifyPos, LPCWSTR lpszText);
void ShowNotificationMessage(int notifyPos, UINT uidMessage, ...);

void InstallFileWatching(LPCWSTR lpszFile);
void CALLBACK WatchTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
void CALLBACK PasteBoardTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
@@ -1821,6 +1821,7 @@ BEGIN
IDS_ASK_ENCODING2 "You are about to change the encoding of an empty file from ANSI to non-ANSI. Note that this will clear the undo history, as it can't be synchronized with the new encoding. Continue?"
IDS_ERR_ENCODINGNA "Code page conversion tables for the selected encoding are not available on your system."
IDS_ERR_UNICODE "Error converting this Unicode file.\nData will be lost if the file is saved!"
IDS_BINARY_FILE_LOCKED "This is most likely not a text file, so it is locked for editing\nto prevent accidental editing cause file corruption."
END

STRINGTABLE
@@ -769,6 +769,7 @@
#define IDS_SETTINGSNOTSAVED 50039
#define IDS_EXPORT_FAIL 50040
#define IDS_LOCKED 50041
#define IDS_BINARY_FILE_LOCKED 50042
#define IDS_CMDLINEHELP 60000
#define IDS_EOLMODENAME_CRLF 62000
#define IDS_EOLMODENAME_LF 62001

0 comments on commit 67a3fb3

Please sign in to comment.
You can’t perform that action at this time.