+ chg: drag-n-drop: replace current file (Ctrl+ for new instance)

+ chg: drag-n-drop: allow multiple files to drop
+ chg: menu/shortcut:  launch "New Empty Wnd" <-> "Duplicate Instance"
+ fix: prevent dup instance, if setting does not allow
This commit is contained in:
Rainer Kottenhoff 2021-04-13 13:58:28 +02:00
parent d5475fafc8
commit 6d899074e1
10 changed files with 206 additions and 181 deletions

View File

@ -77,10 +77,10 @@ BEGIN
END
POPUP "&Starte"
BEGIN
MENUITEM "Suche in &Dateien\tCtrl+Shift+F", IDM_GREP_WIN_SEARCH
MENUITEM "Suche in &Dateien\tCtrl+Shift+F", IDM_GREP_WIN_SEARCH
MENUITEM SEPARATOR
MENUITEM "&Neues Fenster\tAlt+N", IDM_FILE_NEWWINDOW
MENUITEM "&Leeres Fenster\tAlt+Shift+N", IDM_FILE_NEWWINDOW2
MENUITEM "&Neues Leeres Fenster\tAlt+N", IDM_FILE_NEWWINDOW
MENUITEM "&Dupliziere Instanz\tAlt+Shift+N", IDM_FILE_NEWWINDOW2
MENUITEM SEPARATOR
MENUITEM "Mit erhöhten &Rechten starten", IDM_FILE_LAUNCH_ELEVATED
MENUITEM SEPARATOR
@ -453,7 +453,7 @@ BEGIN
MENUITEM "Auto &Lexer KeyWord Vorschläge", IDM_VIEW_AUTOCLEXKEYWORDS
MENUITEM "&Beschleunigte Wort Navigation\tCtrl+Alt+A", IDM_VIEW_ACCELWORDNAV
MENUITEM SEPARATOR
MENUITEM "Eine &Instanz per Datei", IDM_VIEW_SINGLEFILEINSTANCE
MENUITEM "Eine &Instanz pro selber Datei", IDM_VIEW_SINGLEFILEINSTANCE
MENUITEM "Nachricht bei &Dateiänderung...\tAlt+F5", IDM_VIEW_CHANGENOTIFY
MENUITEM "Keine Nachrichten &Beeps", IDM_VIEW_MUTE_MESSAGEBEEP
POPUP "Esc-&Key Funktion"

View File

@ -79,8 +79,8 @@ BEGIN
BEGIN
MENUITEM "&Search in Files\tCtrl+Shift+F", IDM_GREP_WIN_SEARCH
MENUITEM SEPARATOR
MENUITEM "&New Window\tAlt+N", IDM_FILE_NEWWINDOW
MENUITEM "&Empty Window\tAlt+Shift+N", IDM_FILE_NEWWINDOW2
MENUITEM "&New Empty Window\tAlt+N", IDM_FILE_NEWWINDOW
MENUITEM "&Duplicate Instance\tAlt+Shift+N", IDM_FILE_NEWWINDOW2
MENUITEM SEPARATOR
MENUITEM "&Relaunch Elevated", IDM_FILE_LAUNCH_ELEVATED
MENUITEM SEPARATOR
@ -453,7 +453,7 @@ BEGIN
MENUITEM "Auto Complete Lexer-&Key-Words", IDM_VIEW_AUTOCLEXKEYWORDS
MENUITEM "Accelerated Word Navi&gation\tCtrl+Alt+A", IDM_VIEW_ACCELWORDNAV
MENUITEM SEPARATOR
MENUITEM "Single &File Instance", IDM_VIEW_SINGLEFILEINSTANCE
MENUITEM "One Instance per same &File", IDM_VIEW_SINGLEFILEINSTANCE
MENUITEM "File &Change Notification...\tAlt+F5", IDM_VIEW_CHANGENOTIFY
MENUITEM "&Mute Message Beeps", IDM_VIEW_MUTE_MESSAGEBEEP
POPUP "&Esc Key Function"

View File

@ -2070,7 +2070,7 @@ bool SaveWindowPositionSettings(bool bClearSettings)
}
// set current window position as ne initial window
WININFO const winInfo = GetMyWindowPlacement(Globals.hwndMain, NULL);
WININFO const winInfo = GetMyWindowPlacement(Globals.hwndMain, NULL, 0);
int const ResX = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int const ResY = GetSystemMetrics(SM_CYVIRTUALSCREEN);

View File

@ -4321,48 +4321,6 @@ void WinInfoToScreen(WININFO* pWinInfo)
}
//=============================================================================
//
// GetMyWindowPlacement()
//
WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo)
{
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(hwnd, &wndpl);
// corrections in case of aero snapped position
if (SW_SHOWNORMAL == wndpl.showCmd) {
RECT rc;
GetWindowRect(hwnd, &rc);
MONITORINFO mi = { sizeof(MONITORINFO) };
GetMonitorInfoFromRect(&rc, &mi);
LONG const width = rc.right - rc.left;
LONG const height = rc.bottom - rc.top;
rc.left -= (mi.rcWork.left - mi.rcMonitor.left);
rc.right = rc.left + width;
rc.top -= (mi.rcWork.top - mi.rcMonitor.top);
rc.bottom = rc.top + height;
wndpl.rcNormalPosition = rc;
}
WININFO wi = { 0 };
wi.x = wndpl.rcNormalPosition.left;
wi.y = wndpl.rcNormalPosition.top;
wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED);
wi.zoom = SciCall_GetZoom();
// set monitor info too
if (hMonitorInfo) {
GetMonitorInfoFromRect(&(wndpl.rcNormalPosition), hMonitorInfo);
}
return wi;
}
//=============================================================================
//
// GetWindowRectEx()
@ -4404,6 +4362,59 @@ bool GetWindowRectEx(HWND hwnd, LPRECT pRect) {
}
//=============================================================================
//
// GetMyWindowPlacement()
//
WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo, const int offset)
{
RECT rc;
GetWindowRect(hwnd, &rc);
MONITORINFO mi = { sizeof(MONITORINFO) };
GetMonitorInfoFromRect(&rc, &mi);
// set monitor info
if (hMonitorInfo) {
if (hMonitorInfo->cbSize == mi.cbSize) {
*hMonitorInfo = mi;
} else {
GetMonitorInfoFromRect(&rc, hMonitorInfo);
}
}
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
GetWindowPlacement(hwnd, &wndpl);
// corrections in case of aero snapped position
if (SW_SHOWNORMAL == wndpl.showCmd) {
LONG const width = rc.right - rc.left;
LONG const height = rc.bottom - rc.top;
rc.left -= (mi.rcWork.left - mi.rcMonitor.left);
rc.right = rc.left + width;
rc.top -= (mi.rcWork.top - mi.rcMonitor.top);
rc.bottom = rc.top + height;
wndpl.rcNormalPosition = rc;
}
WININFO wi = { 0 };
wi.x = wndpl.rcNormalPosition.left + offset;
wi.y = wndpl.rcNormalPosition.top + offset;
wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED);
wi.zoom = SciCall_GetZoom();
// check if window fits monitor
if ((wi.x + wi.cx) > mi.rcWork.right || (wi.y + wi.cy) > mi.rcWork.bottom) {
wi.x = mi.rcMonitor.left;
wi.y = mi.rcMonitor.top;
}
return wi;
}
//=============================================================================
//
// FitIntoMonitorGeometry()
@ -4503,8 +4514,8 @@ WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* pWinInfo, SCRE
// DialogNewWindow()
//
//
void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, LPCWSTR lpcwFilePath)
{
void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, LPCWSTR lpcwFilePath, WININFO* wi) {
if (bSaveOnRunTools && !FileSave(false, true, false, false, Flags.bPreserveFileModTime)) {
return;
}
@ -4529,21 +4540,10 @@ void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, LPCWSTR lpcwFilePath)
} else {
StringCchCat(szParameters, COUNTOF(szParameters), L"0");
}
StringCchCat(szParameters, COUNTOF(szParameters), L" -n");
StringCchCat(szParameters, COUNTOF(szParameters), Flags.bSingleFileInstance ? L" -ns" : L" -n");
MONITORINFO mi;
WININFO wi = GetMyWindowPlacement(hwnd, &mi);
//~ offset new window position +10/+10
//~wi.x += 10;
//~wi.y += 10;
//~// check if window fits monitor
//~if ((wi.x + wi.cx) > mi.rcWork.right || (wi.y + wi.cy) > mi.rcWork.bottom) {
//~ wi.x = mi.rcMonitor.left;
//~ wi.y = mi.rcMonitor.top;
//~}
//~wi.max = IsZoomed(hwnd);
StringCchPrintf(tch, COUNTOF(tch), L" -pos %i,%i,%i,%i,%i", wi.x, wi.y, wi.cx, wi.cy, wi.max);
WININFO const _wi = wi ? *wi : GetMyWindowPlacement(hwnd, NULL, 0);
StringCchPrintf(tch, COUNTOF(tch), L" -pos %i,%i,%i,%i,%i", _wi.x, _wi.y, _wi.cx, _wi.cy, _wi.max);
StringCchCat(szParameters, COUNTOF(szParameters), tch);
if (StrIsNotEmpty(lpcwFilePath)) {

View File

@ -60,12 +60,12 @@ bool WarnIndentationDlg(HWND hwnd, EditFileIOStatus* fioStatus);
bool GetMonitorInfoFromRect(const LPRECT rc, MONITORINFO *hMonitorInfo);
void WinInfoToScreen(WININFO* pWinInfo);
WININFO GetMyWindowPlacement(HWND hwnd,MONITORINFO * hMonitorInfo);
WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO *hMonitorInfo, const int offset);
bool GetWindowRectEx(HWND hwnd, LPRECT pRect);
void FitIntoMonitorGeometry(LPRECT pRect, WININFO *pWinInfo, SCREEN_MODE mode);
WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* pWinInfo, SCREEN_MODE mode);
void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, LPCWSTR lpcwFilePath);
void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, LPCWSTR lpcwFilePath, WININFO* wi);
void DialogFileBrowse(HWND hwnd);
void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern);
void DialogAdminExe(HWND hwnd,bool);

View File

@ -1820,7 +1820,7 @@ void EditURLEncode(const bool isPathConvert)
if (!bStraightSel) {
SciCall_SwapMainAnchorCaret();
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
_END_UNDO_ACTION_;
@ -1906,7 +1906,7 @@ void EditURLDecode(const bool isPathConvert)
if (!bStraightSel) {
SciCall_SwapMainAnchorCaret();
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
_END_UNDO_ACTION_;
}
@ -1970,7 +1970,7 @@ void EditReplaceAllChr(const WCHAR chSearch, const WCHAR chReplace) {
if (!bStraightSel) {
SciCall_SwapMainAnchorCaret();
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
_END_UNDO_ACTION_;
@ -2193,7 +2193,7 @@ void EditFindMatchingBrace()
if (iMatchingBracePos != (DocPos)-1) {
iMatchingBracePos = bIsAfter ? iMatchingBracePos : SciCall_PositionAfter(iMatchingBracePos);
Sci_GotoPosChooseCaret(iMatchingBracePos);
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
}
@ -3101,7 +3101,7 @@ void EditIndentBlock(HWND hwnd, int cmd, bool bFormatIndentation, bool bForceAll
}
} else {
Sci_GotoPosChooseCaret(iInitialPos);
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
_END_UNDO_ACTION_;
@ -3388,7 +3388,7 @@ void EditEncloseSelection(LPCWSTR pwszOpen, LPCWSTR pwszClose)
if (!bStraightSel) {
SciCall_SwapMainAnchorCaret();
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
_END_UNDO_ACTION_;
@ -3541,7 +3541,7 @@ void EditToggleLineCommentsSimple(LPCWSTR pwszComment, bool bInsertAtStart)
if (!bStraightSel) {
SciCall_SwapMainAnchorCaret();
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
_END_UNDO_ACTION_;
@ -3813,7 +3813,7 @@ void EditPadWithSpaces(HWND hwnd, bool bSkipEmpty, bool bNoUndoGroup)
const DocPos iSelEnd = SciCall_GetSelectionEnd();
DocLn iStartLine = 0;
DocLn iEndLine = SciCall_GetLineCount() - 1;
DocLn iEndLine = Sci_GetLastDocLineNumber();
if (iSelStart != iSelEnd) {
iStartLine = SciCall_LineFromPosition(iSelStart);
@ -4238,7 +4238,7 @@ void EditRemoveBlankLines(HWND hwnd, bool bMerge, bool bRemoveWhiteSpace)
if (iSelStart > SciCall_PositionFromLine(iBegLine)) {
++iBegLine;
}
if ((iSelEnd <= SciCall_PositionFromLine(iEndLine)) && (iEndLine != SciCall_GetLineCount() - 1)) {
if ((iSelEnd <= SciCall_PositionFromLine(iEndLine)) && (iEndLine != Sci_GetLastDocLineNumber())) {
--iEndLine;
}
@ -5096,9 +5096,9 @@ void EditSortLines(HWND hwnd, int iSortFlags)
//=============================================================================
//
// _EnsureRangeVisible()
// _EnsurePositionsVisible()
//
static void _EnsureRangeVisible(const DocPos iAnchorPos, const DocPos iCurrentPos) {
static void _EnsurePositionsVisible(const DocPos iAnchorPos, const DocPos iCurrentPos) {
DocLn const iAnchorLine = SciCall_LineFromPosition(iAnchorPos);
DocLn const iCurrentLine = SciCall_LineFromPosition(iCurrentPos);
@ -5115,12 +5115,12 @@ static void _EnsureRangeVisible(const DocPos iAnchorPos, const DocPos iCurrentPo
//=============================================================================
//
// EditEnsureSelectionVisible()
// EditScrollSelectionToView()
//
void EditEnsureSelectionVisible() {
void EditScrollSelectionToView() {
DocPos const iAnchorPos = SciCall_GetAnchor();
DocPos const iCurrentPos = SciCall_GetCurrentPos();
_EnsureRangeVisible(iAnchorPos, iCurrentPos);
_EnsurePositionsVisible(iAnchorPos, iCurrentPos);
SciCall_ScrollRange(iAnchorPos, iCurrentPos);
}
@ -5145,7 +5145,7 @@ void EditSetSelectionEx(DocPos iAnchorPos, DocPos iCurrentPos, DocPos vSpcAnchor
// Ensure that the first and last lines of a selection are always unfolded
// This needs to be done *before* the SCI_SETSEL message
_EnsureRangeVisible(iAnchorPos, iCurrentPos);
_EnsurePositionsVisible(iAnchorPos, iCurrentPos);
if ((vSpcAnchor >= 0) && (vSpcCurrent >= 0)) {
SciCall_SetRectangularSelectionAnchor(iAnchorPos);
@ -5185,7 +5185,7 @@ void EditEnsureConsistentLineEndings(HWND hwnd)
void EditJumpTo(DocLn iNewLine, DocPos iNewCol)
{
// Line maximum is iMaxLine - 1 (doc line count starts with 0)
DocLn const iMaxLine = SciCall_GetLineCount() - 1;
DocLn const iMaxLine = Sci_GetLastDocLineNumber();
// jump to end with line set to -1
if ((iNewLine < 0) || (iNewLine > iMaxLine)) {
@ -6037,7 +6037,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
if (s_anyMatch == NO_MATCH) {
EditSetSelectionEx(s_InitialAnchorPos, s_InitialCaretPos, -1, -1);
} else {
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
}
@ -6178,7 +6178,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
_DelayMarkAll(_MQ_STD);
if (!SciCall_IsSelectionEmpty()) {
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
/// don't do: ///~SendWMCommandEx(hwnd, IDC_FINDTEXT, CBN_EDITCHANGE);
break;
@ -6939,7 +6939,7 @@ void EditMarkAllOccurrences(HWND hwnd, bool bForceClear)
// get visible lines for update
DocLn const iStartLine = SciCall_DocLineFromVisible(SciCall_GetFirstVisibleLine());
DocLn const iEndLine = min_ln((iStartLine + SciCall_LinesOnScreen()), (SciCall_GetLineCount() - 1));
DocLn const iEndLine = min_ln((iStartLine + SciCall_LinesOnScreen()), Sci_GetLastDocLineNumber());
DocPos const iPosStart = SciCall_PositionFromLine(iStartLine);
DocPos const iPosEnd = SciCall_GetLineEndPosition(iEndLine);
@ -6974,7 +6974,7 @@ void EditSelectionMultiSelectAll()
if (SciCall_GetSelectionNAnchor(0) > SciCall_GetSelectionNCaret(0)) {
SciCall_SwapMainAnchorCaret();
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
_RESTORE_TARGET_RANGE_;
}
@ -7671,7 +7671,7 @@ bool EditAutoCompleteWord(HWND hwnd, bool autoInsert)
void EditUpdateVisibleIndicators()
{
DocLn const iStartLine = SciCall_DocLineFromVisible(SciCall_GetFirstVisibleLine());
DocLn const iEndLine = min_ln((iStartLine + SciCall_LinesOnScreen()), (SciCall_GetLineCount() - 1));
DocLn const iEndLine = min_ln((iStartLine + SciCall_LinesOnScreen()), Sci_GetLastDocLineNumber());
EditUpdateIndicators(SciCall_PositionFromLine(iStartLine), SciCall_GetLineEndPosition(iEndLine), false);
}
@ -7812,7 +7812,7 @@ void EditFoldMarkedLineRange(HWND hwnd, bool bHideLines)
int const baseLevel = SC_FOLDLEVELBASE;
DocLn const iStartLine = 0;
DocLn const iEndLine = SciCall_GetLineCount() - 1;
DocLn const iEndLine = Sci_GetLastDocLineNumber();
// 1st line
int level = baseLevel;
@ -9078,7 +9078,7 @@ void EditSetBookmarkList(HWND hwnd, LPCWSTR pszBookMarks)
return;
}
DocLn const iLineMax = SciCall_GetLineCount() - 1;
DocLn const iLineMax = Sci_GetLastDocLineNumber();
while (*p1) {
const WCHAR* p2 = StrChr(p1, L';');
@ -9260,7 +9260,7 @@ void EditToggleFolds(FOLD_ACTION action, bool bForceAll)
}
}
if (fToggled) {
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
}
}

View File

@ -89,7 +89,7 @@ void EditSortLines(HWND hwnd,int iSortFlags);
void EditJumpTo(DocLn iNewLine, DocPos iNewCol);
void EditSetSelectionEx(DocPos iAnchorPos, DocPos iCurrentPos, DocPos vSpcAnchor, DocPos vSpcCurrent);
void EditFixPositions();
void EditEnsureSelectionVisible();
void EditScrollSelectionToView();
void EditEnsureConsistentLineEndings(HWND hwnd);
void EditGetExcerpt(HWND hwnd,LPWSTR lpszExcerpt,DWORD cchExcerpt);

View File

@ -91,6 +91,7 @@ FILEWATCHING_T FileWatching;
WININFO g_IniWinInfo = INIT_WININFO;
WININFO g_DefWinInfo = INIT_WININFO;
HANDLE g_hndlScintilla = NULL;
COLORREF g_colorCustom[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@ -1065,7 +1066,7 @@ WININFO GetWinInfoByFlag(const int flagsPos)
WININFO winfo = INIT_WININFO;
if (flagsPos < 0) {
winfo = GetMyWindowPlacement(Globals.hwndMain, NULL); // current window position
winfo = GetMyWindowPlacement(Globals.hwndMain, NULL, 0); // current window position
} else if (flagsPos == 0) {
winfo = g_IniWinInfo; // initial window position
} else if (flagsPos == 1) {
@ -1504,7 +1505,7 @@ HWND InitInstance(const HINSTANCE hInstance, LPCWSTR pszCmdLine, int nCmdShow)
EditJumpTo(s_iInitialLine, s_iInitialColumn);
SciCall_SetYCaretPolicy(s_iCaretPolicyV, Settings2.CurrentLineVerticalSlop);
} else {
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
}
}
@ -1610,9 +1611,6 @@ HWND InitInstance(const HINSTANCE hInstance, LPCWSTR pszCmdLine, int nCmdShow)
//
// Messages are distributed to the MsgXXX-handlers
//
//
//inline bool KeyboardIsKeyDown(int key) { return (GetKeyState(key) & 0x8000) != 0; }
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
switch(umsg) {
@ -1647,22 +1645,16 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case WM_DPICHANGED:
return MsgDPIChanged(hwnd, wParam, lParam);
// update Scintilla colors
case WM_SYSCOLORCHANGE:
if (Flags.bHugeFileLoadState) {
EditUpdateVisibleIndicators();
} else {
EditUpdateIndicators(0, -1, false);
}
MarkAllOccurrences(_MQ_FAST, true);
UpdateToolbar();
UpdateStatusbar(true);
UpdateMarginWidth(true);
return DefWindowProc(hwnd,umsg,wParam,lParam);
case WM_SIZE:
return MsgSize(hwnd, wParam, lParam);
// update Scintilla colors
case WM_SYSCOLORCHANGE:
Style_ResetCurrentLexer(Globals.hwndEdit);
UpdateUI();
SendMessage(Globals.hwndEdit, WM_SYSCOLORCHANGE, wParam, lParam);
break;
#ifdef D_NP3_WIN10_DARK_MODE
case WM_SETTINGCHANGE: {
if (IsColorSchemeChangeMessage(lParam)) {
@ -2213,8 +2205,7 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam,LPARAM lParam)
hInstance,
NULL);
///~~~SciCall_GetDirectPointer();
Globals.hndlScintilla = (HANDLE)SendMessage(Globals.hwndEdit, SCI_GETDIRECTPOINTER, 0, 0);
InitScintillaHandle(Globals.hwndEdit);
_InitializeSciEditCtrl(Globals.hwndEdit);
@ -2261,24 +2252,22 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam,LPARAM lParam)
SetDlgItemInt(hwnd,IDC_REUSELOCK,GetTickCount(),false);
// Menu
//SetMenuDefaultItem(GetSubMenu(GetMenu(hwnd),0),0);
//~SetMenuDefaultItem(GetSubMenu(GetMenu(hwnd),0),0);
// Drag & Drop
DragAcceptFiles(hwnd,true);
DragAcceptFiles(hwnd,TRUE);
if (Globals.hwndEdit == NULL || s_hwndEditFrame == NULL ||
Globals.hwndStatus == NULL || Globals.hwndToolbar == NULL || Globals.hwndRebar == NULL) {
if (Globals.hwndEdit == NULL || s_hwndEditFrame == NULL || Globals.hwndStatus == NULL || Globals.hwndToolbar == NULL || Globals.hwndRebar == NULL) {
return -1LL;
}
Style_SetDefaultLexer(Globals.hwndEdit);
Encoding_Current(Settings.DefaultEncoding);
ObserveNotifyDocChangedEvent();
SciCall_SetZoom(g_IniWinInfo.zoom ? g_IniWinInfo.zoom : 100);
if (g_IniWinInfo.zoom) {
SciCall_SetZoom(g_IniWinInfo.zoom);
}
ObserveNotifyDocChangedEvent();
return 0LL;
}
@ -2754,7 +2743,7 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
// Terminate file watching
InstallFileWatching(false);
DragAcceptFiles(hwnd, true);
DragAcceptFiles(hwnd, FALSE);
// Terminate clipboard watching
if (s_flagPasteBoard) {
@ -2994,52 +2983,65 @@ LRESULT MsgDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam)
//=============================================================================
//
// MsgDropFiles() - Handles WM_DROPFILES
// _OnDropOneFile()
//
//
LRESULT MsgDropFiles(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
bool const bMsgFromSciUriDrop = (lParam != 0);
WCHAR szDropStrgBuf[MAX_PATH + 40];
HDROP const hDrop = bMsgFromSciUriDrop ? NULL : (HDROP)wParam;
static LRESULT _OnDropOneFile(HWND hwnd, LPCWSTR szFilePath, WININFO* wi) {
if (IsIconic(hwnd)) {
ShowWindow(hwnd, SW_RESTORE);
}
if (hDrop) {
DragQueryFile(hDrop, 0, szDropStrgBuf, COUNTOF(szDropStrgBuf));
} else if (bMsgFromSciUriDrop) {
StringCchCopy(szDropStrgBuf, COUNTOF(szDropStrgBuf), (LPCWSTR)wParam);
} else {
return FALSE;
}
if (PathIsDirectory(szDropStrgBuf)) {
if (PathIsDirectory(szFilePath)) {
WCHAR tchFile[MAX_PATH] = { L'\0' };
if (OpenFileDlg(Globals.hwndMain, tchFile, COUNTOF(tchFile), szDropStrgBuf)) {
if (OpenFileDlg(Globals.hwndMain, tchFile, COUNTOF(tchFile), szFilePath)) {
FileLoad(tchFile, false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, false);
}
} else if (PathIsExistingFile(szDropStrgBuf)) {
if (Flags.bReuseWindow || IsKeyDown(VK_CONTROL)) {
FileLoad(szDropStrgBuf, false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, false);
} else {
DialogNewWindow(hwnd, Settings.SaveBeforeRunningTools, szDropStrgBuf);
} else if (PathIsExistingFile(szFilePath)) {
//~ ignore Flags.bReuseWindow
if (IsKeyDown(VK_CONTROL) || wi) {
DialogNewWindow(hwnd, Settings.SaveBeforeRunningTools, szFilePath, wi);
} else {
FileLoad(szFilePath, false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, false);
}
} else {
// Windows Bug: wParam (HDROP) pointer is corrupted if dropped from 32-bit App
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_DROP_NO_FILE);
}
if (hDrop) {
if (DragQueryFile(hDrop, (UINT)(-1), NULL, 0) > 1) {
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_DROP);
return FALSE;
}
//=============================================================================
//
// MsgDropFiles() - Handles WM_DROPFILES
//
LRESULT MsgDropFiles(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
HDROP const hDrop = (HDROP)wParam;
WCHAR szDropFilePath[MAX_PATH + 40];
UINT const cnt = DragQueryFile(hDrop, UINT_MAX, NULL, 0);
int const offset = 20;
MONITORINFO mi = { sizeof(MONITORINFO) };
WININFO wi = GetMyWindowPlacement(hwnd, &mi, (IsKeyDown(VK_CONTROL) ? offset : 0));
for (UINT i = 0; i < cnt; ++i) {
DragQueryFile(hDrop, i, szDropFilePath, COUNTOF(szDropFilePath));
_OnDropOneFile(hwnd, szDropFilePath, (((0 == i) && !IsKeyDown(VK_CONTROL)) ? NULL : &wi));
// offset next window position
wi.x += offset;
wi.y += offset;
// check if window fits monitor
if ((wi.x + wi.cx) > mi.rcWork.right || (wi.y + wi.cy) > mi.rcWork.bottom) {
wi.x = mi.rcMonitor.left;
wi.y = mi.rcMonitor.top;
}
DragFinish(hDrop);
}
return FALSE;
DragFinish(hDrop);
return 0;
}
#if 0
@ -3353,7 +3355,7 @@ LRESULT MsgChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
} else {
Sci_GotoPosChooseCaret(iCurPos);
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
} else {
@ -3628,15 +3630,12 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
return FALSE;
}
bool const si = Flags.bSingleFileInstance;
bool const cf = StrIsNotEmpty(Paths.CurrentFile);
bool const sav = Globals.bCanSaveIniFile;
bool const ro = SciCall_GetReadOnly(); // scintilla mode read-only
bool const lck = (FileWatching.FileWatchingMode == FWM_EXCLUSIVELOCK); // file write lock
bool const faro = s_bFileReadOnly; // file attrib read-only
DocPos const iCurPos = SciCall_GetCurrentPos();
DocLn const iCurLine = SciCall_LineFromPosition(iCurPos);
bool const bPosInSel = Sci_IsPosInSelection(iCurPos);
bool const pst = SciCall_CanPaste();
bool const se = SciCall_IsSelectionEmpty();
bool const mrs = Sci_IsMultiOrRectangleSelection();
@ -3644,6 +3643,12 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
bool const mls = Sci_IsSelectionMultiLine();
//bool const lfl = Flags.bHugeFileLoadState;
DocPos const iCurPos = SciCall_GetCurrentPos();
DocLn const iCurLine = SciCall_LineFromPosition(iCurPos);
bool const bPosInSel = Sci_IsPosInSelection(iCurPos);
// ------------------------------------------------------
EnableCmd(hmenu, IDM_FILE_REVERT, cf);
EnableCmd(hmenu, CMD_RELOADASCIIASUTF8, cf);
EnableCmd(hmenu, CMD_RELOADFORCEDETECTION, cf);
@ -3652,13 +3657,14 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
EnableCmd(hmenu, CMD_RELOADNOFILEVARS, cf);
EnableCmd(hmenu, CMD_RECODEDEFAULT, cf);
EnableCmd(hmenu, CMD_RECODEGB18030, cf);
EnableCmd(hmenu, IDM_FILE_NEWWINDOW2, !(cf && si));
EnableCmd(hmenu, IDM_FILE_LAUNCH, cf);
SetUACIcon(hwnd, hmenu, IDM_FILE_LAUNCH_ELEVATED);
CheckCmd(hmenu, IDM_FILE_LAUNCH_ELEVATED, s_bIsProcessElevated);
EnableCmd(hmenu, IDM_FILE_LAUNCH_ELEVATED, !s_bIsProcessElevated);
EnableCmd(hmenu, IDM_FILE_LAUNCH, cf);
EnableCmd(hmenu, IDM_FILE_PROPERTIES, cf);
EnableCmd(hmenu, IDM_FILE_CREATELINK, cf);
EnableCmd(hmenu, IDM_FILE_ADDTOFAV, cf);
@ -4201,22 +4207,21 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case IDM_FILE_NEWWINDOW:
case IDM_FILE_NEWWINDOW2:
case IDM_FILE_NEWWINDOW2: {
SaveAllSettings(false);
LPCWSTR lpcwFilePath = (iLoWParam != IDM_FILE_NEWWINDOW2) ? Paths.CurrentFile : NULL;
DialogNewWindow(hwnd, Settings.SaveBeforeRunningTools, lpcwFilePath);
break;
LPCWSTR lpcwFilePath = (iLoWParam == IDM_FILE_NEWWINDOW2) ? Paths.CurrentFile : NULL;
DialogNewWindow(hwnd, Settings.SaveBeforeRunningTools, lpcwFilePath, NULL);
}
break;
case IDM_FILE_LAUNCH: {
if (StrIsEmpty(Paths.CurrentFile)) {
break;
}
if (Settings.SaveBeforeRunningTools && !FileSave(false,true,false,false,Flags.bPreserveFileModTime)) {
break;
}
StringCchCopy(tchMaxPathBuffer,COUNTOF(tchMaxPathBuffer),Paths.CurrentFile);
PathCchRemoveFileSpec(tchMaxPathBuffer, COUNTOF(tchMaxPathBuffer));
@ -5153,7 +5158,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
switch (iLoWParam) {
case IDM_EDIT_SELTONEXT: {
SciCall_RotateSelection();
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
break;
@ -5165,7 +5170,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
DocPosU const iNewMain = SciCall_GetSelections() - 1;
SciCall_SetMainSelection(iNewMain);
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
break;
@ -5306,7 +5311,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
Globals.fvCurFile.bWordWrap = Settings.WordWrap = !Settings.WordWrap;
BeginWaitCursorUID(Flags.bHugeFileLoadState, IDS_MUI_SB_WRAP_LINES);
_SetWrapIndentMode(Globals.hwndEdit);
EditEnsureSelectionVisible();
EditScrollSelectionToView();
EndWaitCursor();
UpdateToolbar();
break;
@ -5655,7 +5660,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
UndoRedoRecordingStart();
SciCall_SetEndAtLastLine(!Settings.ScrollPastEOF);
}
EditEnsureSelectionVisible();
EditScrollSelectionToView();
InstallFileWatching(true);
@ -6002,7 +6007,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
if ((!SciCall_IsSelectionEmpty() || Sci_IsMultiOrRectangleSelection()) && (skipLevel == Settings2.ExitOnESCSkipLevel)) {
Sci_GotoPosChooseCaret(iCurPos);
EditEnsureSelectionVisible();
EditScrollSelectionToView();
skipLevel -= Defaults2.ExitOnESCSkipLevel;
}
@ -6018,7 +6023,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
default:
Sci_GotoPosChooseCaret(iCurPos);
EditEnsureSelectionVisible();
EditScrollSelectionToView();
break;
}
}
@ -6448,7 +6453,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case CMD_COPYWINPOS: {
WININFO wi = GetMyWindowPlacement(Globals.hwndMain,NULL);
WININFO wi = GetMyWindowPlacement(Globals.hwndMain, NULL, 0);
StringCchPrintf(tchMaxPathBuffer,COUNTOF(tchMaxPathBuffer),L"/pos %i,%i,%i,%i,%i",wi.x,wi.y,wi.cx,wi.cy,wi.max);
SetClipboardText(hwnd, tchMaxPathBuffer, StringCchLen(tchMaxPathBuffer, 0));
}
@ -6460,7 +6465,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
break;
case CMD_FULLSCRWINPOS: {
WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL);
WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL, 0);
SnapToWinInfoPos(hwnd, wi, SCR_FULL_SCREEN);
}
break;
@ -6470,7 +6475,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
break;
case CMD_SAVEASDEFWINPOS: {
WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL);
WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL, 0);
WCHAR tchDefWinPos[80];
StringCchPrintf(tchDefWinPos, COUNTOF(tchDefWinPos), L"%i,%i,%i,%i,%i", wi.x, wi.y, wi.cx, wi.cy, wi.max);
if (Globals.bCanSaveIniFile) {
@ -7508,6 +7513,7 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const SCNotification* const scn)
}
break;
case SCN_STYLENEEDED: {
// this event needs SCI_SETLEXER(SCLEX_CONTAINER)
//EditUpdateIndicators(SciCall_GetEndStyled(), scn->position, false);
@ -7706,7 +7712,7 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const SCNotification* const scn)
case SCN_URIDROPPED: {
WCHAR szBuf[MAX_PATH + 40] = { L'\0' };
if (MultiByteToWideChar(CP_UTF8, 0, scn->text, -1, szBuf, (int)COUNTOF(szBuf)) > 0) {
return MsgDropFiles(hwnd, (WPARAM)szBuf, 1); // (1) to identify src
return _OnDropOneFile(hwnd, szBuf, false);
}
}
break;
@ -10119,7 +10125,7 @@ bool FileRevert(LPCWSTR szFileName, bool bIgnoreCmdLnEnc)
if (bIsAtDocEnd || FileWatching.MonitoringLog) {
bPreserveView = false;
SciCall_DocumentEnd();
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
}
@ -10130,7 +10136,7 @@ bool FileRevert(LPCWSTR szFileName, bool bIgnoreCmdLnEnc)
SciCall_ClearSelections();
bPreserveView = false;
SciCall_DocumentEnd();
EditEnsureSelectionVisible();
EditScrollSelectionToView();
}
}
@ -10205,7 +10211,7 @@ bool DoElevatedRelaunch(EditFileIOStatus* pFioStatus, bool bAutoSaveOnRelaunch)
DocPos const iCurPos = SciCall_GetCurrentPos();
int const iCurLn = (int)SciCall_LineFromPosition(iCurPos) + 1;
int const iCurCol = (int)SciCall_GetColumn(iCurPos) + 1;
WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL);
WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL, 0);
WCHAR szArguments[2048] = { L'\0' };
@ -10424,7 +10430,7 @@ bool FileSave(bool bSaveAlways, bool bAsk, bool bSaveAs, bool bSaveCopy, bool bP
answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONINFORMATION, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, L""));
}
if ((IDOK == answer) || (IDYES == answer)) {
DialogNewWindow(Globals.hwndMain, false, Paths.CurrentFile);
DialogNewWindow(Globals.hwndMain, false, Paths.CurrentFile, NULL);
CloseApplication();
}
}
@ -11135,7 +11141,7 @@ void CALLBACK PasteBoardTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTi
SciCall_Paste();
SciCall_NewLine();
_END_UNDO_ACTION_;
EditEnsureSelectionVisible();
EditScrollSelectionToView();
Settings.AutoIndent = bAutoIndent2;
}
s_dwLastCopyTime = 0;

View File

@ -57,6 +57,22 @@
#include "Scintilla.h"
#include "TypeDefs.h"
//=============================================================================
//
// Scintilla Window Handle
//
#if defined(__cplusplus)
extern "C" HANDLE g_hndlScintilla;
#else
extern HANDLE g_hndlScintilla;
#endif
__forceinline void InitScintillaHandle(HWND hwnd) {
g_hndlScintilla = (HANDLE)SendMessage(hwnd, SCI_GETDIRECTPOINTER, 0, 0);
}
//=============================================================================
//
// SciCall()
@ -64,20 +80,24 @@
#ifdef SCI_DIRECTFUNCTION_INTERFACE
LRESULT WINAPI Scintilla_DirectFunction(HANDLE, UINT, WPARAM, LPARAM);
#define SciCall(m, w, l) Scintilla_DirectFunction(Globals.hndlScintilla, (m), (w), (l))
#define SciCall(m, w, l) Scintilla_DirectFunction(g_hndlScintilla, (m), (w), (l))
#else
#define SciCall(m, w, l) SendMessage(Globals.hwndEdit, m, w, l)
#define SciCall(m, w, l) SendMessage(g_hndlScintilla, m, w, l)
#endif // SCI_DIRECTFUNCTION_INTERFACE
//=============================================================================
// SciOniguruma RegEx search
ptrdiff_t WINAPI OnigRegExFind(const char *pchPattern, const char *pchText,
const bool caseSensitive, const int eolMode, int *matchLen_out);
//=============================================================================
//=============================================================================
//
// DeclareSciCall[RV][0-2] Macros

View File

@ -348,7 +348,6 @@ typedef struct _globals_t
HWND hwndMain;
HANDLE hndlProcessHeap;
HWND hwndEdit;
HANDLE hndlScintilla;
HANDLE hwndToolbar;
HANDLE hwndRebar;
HWND hwndStatus;