From 5c7660b7b99bebd5b64f6158285528663740a910 Mon Sep 17 00:00:00 2001 From: Don HO Date: Wed, 4 Mar 2020 10:45:34 +0100 Subject: [PATCH] Fix inaccurate sorting result in Windows dialog Both sorting results of size & type columns in Windows dialog were incorrect. Now they are fixed. --- .../src/WinControls/WindowsDlg/WindowsDlg.cpp | 69 +++++++++++++------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp index f27250d72..4fb10c0c4 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp @@ -1,4 +1,4 @@ -// This file is part of Notepad++ project +// This file is part of Notepad++ project // Copyright (C)2003 Don HO // // This program is free software; you can redistribute it and/or @@ -175,14 +175,43 @@ struct BufferEquivalent } else if (_iColumn == 2) { - auto t1 = b1->getLangType(); - auto t2 = b2->getLangType(); + NppParameters & nppParameters = NppParameters::getInstance(); + const TCHAR *s1; + const TCHAR *s2; + //const TCHAR empty[] = ; + Lang *lang1 = nppParameters.getLangFromID(b1->getLangType()); + + if (lang1) + { + s1 = lang1->getLangName(); + } + else + s1 = TEXT(""); + + Lang *lang2 = nppParameters.getLangFromID(b2->getLangType()); + if (lang2) + { + s2 = lang2->getLangName(); + } + else + s2 = TEXT(""); + + int result = _strequiv(s1, s2); + + if (result != 0) // default to filepath sorting when equivalent + return result < 0; + + } + else if (_iColumn == 3) + { + auto t1 = b1->docLength(); + auto t2 = b2->docLength(); if (t1 != t2) // default to filepath sorting when equivalent return (t1 < t2); } - // _iColumn == 1 + // _iColumn == 1 const TCHAR *s1 = b1->getFullPathName(); const TCHAR *s2 = b2->getFullPathName(); return _strequiv(s1, s2) < 0; //we can compare the full path to sort on directory, since after sorting directories sorting files is the second thing to do (if directories are the same that is) @@ -516,23 +545,23 @@ BOOL WindowsDlg::onInitDialog() generic_string columnText; NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); - columnText = TEXT("\u21F5 ") + pNativeSpeaker->getAttrNameStr(TEXT("Name"), WD_ROOTNODE, WD_CLMNNAME); + columnText = TEXT("⇵ ") + pNativeSpeaker->getAttrNameStr(TEXT("Name"), WD_ROOTNODE, WD_CLMNNAME); lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = width / 4; SendMessage(_hList, LVM_INSERTCOLUMN, 0, LPARAM(&lvColumn)); - columnText = TEXT("\u21F5 ") + pNativeSpeaker->getAttrNameStr(TEXT("Path"), WD_ROOTNODE, WD_CLMNPATH); + columnText = TEXT("⇵ ") + pNativeSpeaker->getAttrNameStr(TEXT("Path"), WD_ROOTNODE, WD_CLMNPATH); lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = 300; SendMessage(_hList, LVM_INSERTCOLUMN, 1, LPARAM(&lvColumn)); lvColumn.fmt = LVCFMT_CENTER; - columnText = TEXT("\u21F5 ") + pNativeSpeaker->getAttrNameStr(TEXT("Type"), WD_ROOTNODE, WD_CLMNTYPE); + columnText = TEXT("⇵ ") + pNativeSpeaker->getAttrNameStr(TEXT("Type"), WD_ROOTNODE, WD_CLMNTYPE); lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = 100; SendMessage(_hList, LVM_INSERTCOLUMN, 2, LPARAM(&lvColumn)); - columnText = TEXT("\u21F5 ") + pNativeSpeaker->getAttrNameStr(TEXT("Size"), WD_ROOTNODE, WD_CLMNSIZE); + columnText = TEXT("⇵ ") + pNativeSpeaker->getAttrNameStr(TEXT("Size"), WD_ROOTNODE, WD_CLMNSIZE); lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = 100; SendMessage(_hList, LVM_INSERTCOLUMN, 3, LPARAM(&lvColumn)); @@ -566,15 +595,15 @@ void WindowsDlg::updateColumnNames() columnText = pNativeSpeaker->getAttrNameStr(TEXT("Name"), WD_ROOTNODE, WD_CLMNNAME); if (_currentColumn != 0) { - columnText = TEXT("\u21F5 ") + columnText; + columnText = TEXT("⇵ ") + columnText; } else if (_reverseSort) { - columnText = TEXT("\u25B3 ") + columnText; + columnText = TEXT("△ ") + columnText; } else { - columnText = TEXT("\u25BD ") + columnText; + columnText = TEXT("▽ ") + columnText; } lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = static_cast(SendMessage(_hList, LVM_GETCOLUMNWIDTH, 0, 0)); @@ -583,15 +612,15 @@ void WindowsDlg::updateColumnNames() columnText = pNativeSpeaker->getAttrNameStr(TEXT("Path"), WD_ROOTNODE, WD_CLMNPATH); if (_currentColumn != 1) { - columnText = TEXT("\u21F5 ") + columnText; + columnText = TEXT("⇵ ") + columnText; } else if (_reverseSort) { - columnText = TEXT("\u25B3 ") + columnText; + columnText = TEXT("△ ") + columnText; } else { - columnText = TEXT("\u25BD ") + columnText; + columnText = TEXT("▽ ") + columnText; } lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = static_cast(SendMessage(_hList, LVM_GETCOLUMNWIDTH, 1, 0)); @@ -601,15 +630,15 @@ void WindowsDlg::updateColumnNames() columnText = pNativeSpeaker->getAttrNameStr(TEXT("Type"), WD_ROOTNODE, WD_CLMNTYPE); if (_currentColumn != 2) { - columnText = TEXT("\u21F5 ") + columnText; + columnText = TEXT("⇵ ") + columnText; } else if (_reverseSort) { - columnText = TEXT("\u25B3 ") + columnText; + columnText = TEXT("△ ") + columnText; } else { - columnText = TEXT("\u25BD ") + columnText; + columnText = TEXT("▽ ") + columnText; } lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = static_cast(SendMessage(_hList, LVM_GETCOLUMNWIDTH, 2, 0)); @@ -618,15 +647,15 @@ void WindowsDlg::updateColumnNames() columnText = pNativeSpeaker->getAttrNameStr(TEXT("Size"), WD_ROOTNODE, WD_CLMNSIZE); if (_currentColumn != 3) { - columnText = TEXT("\u21F5 ") + columnText; + columnText = TEXT("⇵ ") + columnText; } else if (_reverseSort) { - columnText = TEXT("\u25B3 ") + columnText; + columnText = TEXT("△ ") + columnText; } else { - columnText = TEXT("\u25BD ") + columnText; + columnText = TEXT("▽ ") + columnText; } lvColumn.pszText = const_cast(columnText.c_str()); lvColumn.cx = static_cast(SendMessage(_hList, LVM_GETCOLUMNWIDTH, 3, 0));