From f0229520133da7f32a9c35fbfa5cd18518ecade1 Mon Sep 17 00:00:00 2001 From: "Michael Z. Kadaner" Date: Sun, 29 Jan 2023 19:16:53 -0800 Subject: [PATCH] Viewer now uses the standard Search dialog. --- far/FarCze.hlf.m4 | 14 +- far/FarEng.hlf.m4 | 14 +- far/FarGer.hlf.m4 | 14 +- far/FarHun.hlf.m4 | 14 +- far/FarPol.hlf.m4 | 13 +- far/FarRus.hlf.m4 | 14 +- far/FarSky.hlf.m4 | 14 +- far/FarUkr.hlf.m4 | 14 +- far/changelog | 10 + far/config.cpp | 2 - far/config.hpp | 1 - far/farlang.templ.m4 | 14 -- far/vbuild.m4 | 2 +- far/viewer.cpp | 349 +++++---------------------------- far/viewer.hpp | 16 +- plugins/luamacro/macrotest.lua | 2 +- 16 files changed, 94 insertions(+), 413 deletions(-) diff --git a/far/FarCze.hlf.m4 b/far/FarCze.hlf.m4 index 4220a2a27b..639bd96d4d 100644 --- a/far/FarCze.hlf.m4 +++ b/far/FarCze.hlf.m4 @@ -2886,25 +2886,22 @@ beginning in the text. Poznámka: - 1. ^Do vyvolaného ~vyhledávacího~@ViewerSearch@ dialogu můžete začít psát text, -který hledáte. - - 2. ^The viewer opens files with the permission to be deleted. + 1. ^The viewer opens files with the permission to be deleted. If another process attempts to delete the file while it is open in the viewer, the file will be deleted after the viewer is closed. Any operation on a file while its deletion is pending will fail. This is a feature of the Windows operating system. - 3. ^The maximum number of columns displayed in the #text# + 2. ^The maximum number of columns displayed in the #text# ~view mode~@ViewerMode@ can be configured in the ~Viewer settings~@ViewerSettings@ dialog. The range is between 100 to 100,000, the default is 10,000. Lines longer than the maximum will be split into several screen rows even if word wrap mode is turned off. - 4. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the + 3. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the beginning of the currently visible area. - 5. ^To auto-scroll a file which is being appended by another + 4. ^To auto-scroll a file which is being appended by another process (conf. Linux “tail”), go to the end of the file (press the #End# key). @@ -3871,9 +3868,6 @@ Pro zadání souboru pro prohlížení použijte ~speciální symboly~@MetaSymbo #Persistent selection# Do not remove block selection after moving the cursor. - #Search dialog auto-focus# - Always returns focus to the search text field in the Viewer ~Search~@ViewerSearch@ dialog. - #Velikost Tabulátoru# Počet mezer ve znaku tabulátoru. diff --git a/far/FarEng.hlf.m4 b/far/FarEng.hlf.m4 index 912e3226f5..638c7102f9 100644 --- a/far/FarEng.hlf.m4 +++ b/far/FarEng.hlf.m4 @@ -2852,25 +2852,22 @@ beginning in the text. Notes: - 1. ^Start typing the search pattern to open the -~search~@ViewerSearch@ dialog. - - 2. ^The viewer opens files with the permission to be deleted. + 1. ^The viewer opens files with the permission to be deleted. If another process attempts to delete the file while it is open in the viewer, the file will be deleted after the viewer is closed. Any operation on a file while its deletion is pending will fail. This is a feature of the Windows operating system. - 3. ^The maximum number of columns displayed in the #text# + 2. ^The maximum number of columns displayed in the #text# ~view mode~@ViewerMode@ can be configured in the ~Viewer settings~@ViewerSettings@ dialog. The range is between 100 to 100,000, the default is 10,000. Lines longer than the maximum will be split into several screen rows even if word wrap mode is turned off. - 4. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the + 3. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the beginning of the currently visible area. - 5. ^To auto-scroll a file which is being appended by another + 4. ^To auto-scroll a file which is being appended by another process (conf. Linux “tail”), go to the end of the file (press the #End# key). @@ -3838,9 +3835,6 @@ Use ~special symbols~@MetaSymbols@ to specify the name of the file to view. #Persistent selection# Do not remove block selection after moving the cursor. - #Search dialog auto-focus# - Always returns focus to the search text field in the Viewer ~Search~@ViewerSearch@ dialog. - #Tab size# Number of spaces per single tab position. diff --git a/far/FarGer.hlf.m4 b/far/FarGer.hlf.m4 index 880e43d35e..cc76db1c23 100644 --- a/far/FarGer.hlf.m4 +++ b/far/FarGer.hlf.m4 @@ -2926,25 +2926,22 @@ beginning in the text. Hinweise: - 1. ^Sie können zusätzlich zu #F7# den ~Suchdialog~@ViewerSearch@ einfach -durch Eingabe des zu suchenden Textes starten. - - 2. ^The viewer opens files with the permission to be deleted. + 1. ^The viewer opens files with the permission to be deleted. If another process attempts to delete the file while it is open in the viewer, the file will be deleted after the viewer is closed. Any operation on a file while its deletion is pending will fail. This is a feature of the Windows operating system. - 3. ^The maximum number of columns displayed in the #text# + 2. ^The maximum number of columns displayed in the #text# ~view mode~@ViewerMode@ can be configured in the ~Viewer settings~@ViewerSettings@ dialog. The range is between 100 to 100,000, the default is 10,000. Lines longer than the maximum will be split into several screen rows even if word wrap mode is turned off. - 4. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the + 3. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the beginning of the currently visible area. - 5. ^To auto-scroll a file which is being appended by another + 4. ^To auto-scroll a file which is being appended by another process (conf. Linux “tail”), go to the end of the file (press the #End# key). @@ -3915,9 +3912,6 @@ Benutzen Sie die ~Spezialsymbole~@MetaSymbols@ um den Namen der anzuzeigenden Da #Persistent selection# Do not remove block selection after moving the cursor. - #Search dialog auto-focus# - Always returns focus to the search text field in the Viewer ~Search~@ViewerSearch@ dialog. - #Tabulatorgröße# Tab zeigt die entsprechende Anzahl Leerzeichen an. diff --git a/far/FarHun.hlf.m4 b/far/FarHun.hlf.m4 index 5646052ccc..59f38253f9 100644 --- a/far/FarHun.hlf.m4 +++ b/far/FarHun.hlf.m4 @@ -2934,24 +2934,21 @@ beginning in the text. Megjegyzések: - 1. ^A ~keresőablak~@ViewerSearch@ meghívásához a nézőkében az is elég, ha elkezdjük -begépelni a keresett szöveget. - - 2. ^Az, hogy a nézőkében megnyitunk egy fájlt, nem zárja ki, + 1. ^Az, hogy a nézőkében megnyitunk egy fájlt, nem zárja ki, hogy közben egy másik folyamat ne törölhetné azt. Annak ellenére, hogy a fájl valójában csak a nézőke bezárásakor törlődik, a törölt fájlra irányuló további műveletek hibával fognak leállni - ez Windows sajátosság. - 3. ^The maximum number of columns displayed in the #text# + 2. ^The maximum number of columns displayed in the #text# ~view mode~@ViewerMode@ can be configured in the ~Viewer settings~@ViewerSettings@ dialog. The range is between 100 to 100,000, the default is 10,000. Ha valamelyik sor túllépi ezt, a Far akkor is több sorban jeleníti meg, ha a sortörés ki van kapcsolva. - 4. ^A Far nézőke ~keresője~@ViewerSearch@ (#F7#) a fájl képernyőn + 3. ^A Far nézőke ~keresője~@ViewerSearch@ (#F7#) a fájl képernyőn megjelenő részének kezdetétől az első előfordulásig keresi a sztringet. - 5. ^Ha automatikusan szeretnénk gördíteni egy folyamatosan változó + 4. ^Ha automatikusan szeretnénk gördíteni egy folyamatosan változó tartalmú fájlt, vigyük a kurzort a fájl végére (az End billentyűvel). @@ -3932,9 +3929,6 @@ A parancssorban a megnézendő fájlnevek megadásához alkalmazhatunk ~különl #Maradó blokkok# Nem veszi le a kijelölést a blokkokról, ha megmozdítjuk a kurzort. - #Search dialog auto-focus# - Always returns focus to the search text field in the Viewer ~Search~@ViewerSearch@ dialog. - #Tabulátor mérete# A tabulátor szóközökben mért hossza. diff --git a/far/FarPol.hlf.m4 b/far/FarPol.hlf.m4 index 24fcf8be23..f681661a04 100644 --- a/far/FarPol.hlf.m4 +++ b/far/FarPol.hlf.m4 @@ -2849,24 +2849,22 @@ początkowym. Uwagi: - 1. ^Rozpoczęcie pisania otwiera okno ~wyszukiwania~@ViewerSearch@. - - 2. ^Przeglądarka otwiera pliki z uprawnieniem do usunięcia. + 1. ^Przeglądarka otwiera pliki z uprawnieniem do usunięcia. Jeżeli inny proces próbuje usunąć plik otwarty do poglądu, zostanie on usunięty po zamknięciu podglądu. Każda operacja na pliku oczekującym na usunięcie zakończy się niepowodzeniem. Jest to cecha systemu operacyjnego Windows. - 3. ^Maksymalna liczba kolumn wyświetlanych w ~podglądzie~@ViewerMode@ #tekstowym# + 2. ^Maksymalna liczba kolumn wyświetlanych w ~podglądzie~@ViewerMode@ #tekstowym# można skonfigurować w oknie ~ustawieniach podglądu~@ViewerSettings@. Zakres zawiera się między 100 a 100.000, domyślnie ustawione jest 10.000. Linie dłuższe niż ustawiony zakres zostaną podzielone kilka wierszy, nawet jeżeli opcja zawijania wierszy jest wyłączona. - 4. ^Far rozpoczyna ~wyszukiwanie~@ViewerSearch@ (#F7#) od początku + 3. ^Far rozpoczyna ~wyszukiwanie~@ViewerSearch@ (#F7#) od początku aktualnie widocznego obszaru. - 5. ^Aby automatycznie przewijać plik, który jest dołączany przez inny + 4. ^Aby automatycznie przewijać plik, który jest dołączany przez inny proces (podobnie jak polecenie Linux "tail"), należy przejść na koniec pliku (naciśnięcie klawisza #End#). @@ -3837,9 +3835,6 @@ Można użyć ~symboli specjalnych~@MetaSymbols@ do wpisania nazwy pliku. #Trwałe zaznaczenie# Nie usuwaj zaznaczonego bloku po przesunięciu kursora. - #Auto-focus okna szukania# - Zawsze przywraca fokus do pola tekstowego wyszukiwania w oknie dialogowym ~Szukaj~@ViewerSearch@. - #Rozmiar tabulatora# Liczba znaków spacji na pojedynczy znak tabulacji. diff --git a/far/FarRus.hlf.m4 b/far/FarRus.hlf.m4 index f4fdca3c81..96b2e1aaa4 100644 --- a/far/FarRus.hlf.m4 +++ b/far/FarRus.hlf.m4 @@ -2908,25 +2908,22 @@ $ #Программа просмотра: клавиши управления# Примечания: - 1. ^Начните вводить образец поиска, чтобы открыть диалог -~поиска~@ViewerSearch@. - - 2. ^Программа просмотра открывает файл в режиме, когда + 1. ^Программа просмотра открывает файл в режиме, когда разрешено его удаление. Если другой процесс попытается удалить файл, пока он открыт в программе просмотра, то файл будет удалён после закрытия программы просмотра. Все операции на файле, находящемся в таком состоянии, будут заканчиваться неуспехом. Это свойство операционной системы Windows. - 3. ^Максимальное число колонок, показываемых в + 2. ^Максимальное число колонок, показываемых в ~режиме просмотра~@ViewerMode@ #текст#, можно задать в диалоге ~настроек программы просмотра~@ViewerSettings@. Допустимые значения от 100 до 100 000, умолчание 10 000. Строки длиннее максимума будут разбиты на несколько строк, даже если режим переноса строк отключён. - 4. ^Far начинает ~поиск~@ViewerSearch@ (#F7#) от начала + 3. ^Far начинает ~поиск~@ViewerSearch@ (#F7#) от начала видимой в данный момент области. - 5. ^Для авто-скроллинга файла, который непрерывно пополняется + 4. ^Для авто-скроллинга файла, который непрерывно пополняется другим процессом (ср. Linux «tail»), установите текущую позицию на конец файла (нажмите клавишу #End#). @@ -3888,9 +3885,6 @@ $ #Настройка программы просмотра# #Постоянное выделение# Не удалять пометку блока при перемещении курсора. - #Авто-фокус в диалоге поиска# - В диалоге ~поиска~@ViewerSearch@ автоматически делать активным поле ввода искомого текста. - #Размер табуляции# Количество пробелов на одну позицию табуляции. diff --git a/far/FarSky.hlf.m4 b/far/FarSky.hlf.m4 index b0b099d8b2..a2932086b8 100644 --- a/far/FarSky.hlf.m4 +++ b/far/FarSky.hlf.m4 @@ -2847,25 +2847,22 @@ beginning in the text. Poznámky: - 1. ^Dialógové okno ~hľadania~@ViewerSearch@ sa spustí automaticky ak začnete -písať text, ktorý chcete vyhľadať. - - 2. ^The viewer opens files with the permission to be deleted. + 1. ^The viewer opens files with the permission to be deleted. If another process attempts to delete the file while it is open in the viewer, the file will be deleted after the viewer is closed. Any operation on a file while its deletion is pending will fail. This is a feature of the Windows operating system. - 3. ^The maximum number of columns displayed in the #text# + 2. ^The maximum number of columns displayed in the #text# ~view mode~@ViewerMode@ can be configured in the ~Viewer settings~@ViewerSettings@ dialog. The range is between 100 to 100,000, the default is 10,000. Lines longer than the maximum will be split into several screen rows even if word wrap mode is turned off. - 4. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the + 3. ^Far starts ~searching~@ViewerSearch@ (#F7#) from the beginning of the currently visible area. - 5. ^To auto-scroll a file which is being appended by another + 4. ^To auto-scroll a file which is being appended by another process (conf. Linux “tail”), go to the end of the file (press the #End# key). @@ -3833,9 +3830,6 @@ Na špecifikáciu mena súboru, ktorý sa má prezrieť použite ~špeciálne sy #Persistent selection# Do not remove block selection after moving the cursor. - #Search dialog auto-focus# - Always returns focus to the search text field in the Viewer ~Search~@ViewerSearch@ dialog. - #Veľkosť tabulátora# Počet medzier reprezentujúcich znak tabulátora. diff --git a/far/FarUkr.hlf.m4 b/far/FarUkr.hlf.m4 index 0898df47a5..f61dcf3c82 100644 --- a/far/FarUkr.hlf.m4 +++ b/far/FarUkr.hlf.m4 @@ -2915,26 +2915,23 @@ beginning in the text. Примітки: - 1. ^Для виклику діалогу ~пошуку~@ViewerSearch@ ви також можете просто почати -вводити призначений для пошуку текст. - - 2. ^Файл відкривається у програмі перегляду із дозволом на + 1. ^Файл відкривається у програмі перегляду із дозволом на видалення його стороннім процесом. Якщо відбудеться таке видалення, то реально файл буде видалений із каталогу тільки після закриття програми перегляду, при цьому він не буде доступний для обробки із любого процесу - це властивість операційної системи Windows. - 3. ^The maximum number of columns displayed in the #text# + 2. ^The maximum number of columns displayed in the #text# ~view mode~@ViewerMode@ can be configured in the ~Viewer settings~@ViewerSettings@ dialog. The range is between 100 to 100,000, the default is 10,000. Рядки довжиною більше цього числа будуть займати на екрані не один рядок, а кілька, навіть якщо вимкнений режим переносу рядків. - 4. ^Far ~шукає~@ViewerSearch@ перше входження підрядка (#F7#) з початку видимої + 3. ^Far ~шукає~@ViewerSearch@ перше входження підрядка (#F7#) з початку видимої ділянки екрана програми перегляду. - 5. ^To auto-scroll a file which is being appended by another + 4. ^To auto-scroll a file which is being appended by another process (conf. Linux “tail”), go to the end of the file (press the #End# key). @@ -3899,9 +3896,6 @@ $ #Конфігурація програми перегляду# #Persistent selection# Do not remove block selection after moving the cursor. - #Search dialog auto-focus# - Always returns focus to the search text field in the Viewer ~Search~@ViewerSearch@ dialog. - #Розмір табуляції# Кількість пробілів при показі символа табуляції. diff --git a/far/changelog b/far/changelog index bb6b9343f2..e573281769 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,13 @@ +-------------------------------------------------------------------------------- +MZK 30.01.2023 21:02:33 -0800 - build 6099 + +1. Viewer now uses the standard Search dialog. + +2. Removed the following features: + - Opening Viewer's Search dialog on typing the first character of the search pattern. + See gh-614 for the discussion. + - Search dialog auto-focus. + -------------------------------------------------------------------------------- rohitab 30.01.2023 01:17:44 +1100 - build 6098 diff --git a/far/config.cpp b/far/config.cpp index e3aa7089a8..adc1882803 100644 --- a/far/config.cpp +++ b/far/config.cpp @@ -817,7 +817,6 @@ void Options::ViewerConfig(ViewerOptions &ViOptRef, bool Local) Builder.StartColumns(); Builder.AddCheckbox(lng::MViewConfigPersistentSelection, ViOptRef.PersistentBlocks); - Builder.AddCheckbox(lng::MViewConfigEditAutofocus, ViOptRef.SearchEditFocus); const auto& TabSize = Builder.AddIntEditField(ViOptRef.TabSize, 3); Builder.AddTextAfter(TabSize, lng::MViewConfigTabSize); Builder.ColumnBreak(); @@ -2101,7 +2100,6 @@ void Options::InitConfigsData() {FSSF_PRIVATE, NKeyViewer, L"SaveViewerShortPos"sv, ViOpt.SaveShortPos, true}, {FSSF_PRIVATE, NKeyViewer, L"SaveViewerWrapMode"sv, ViOpt.SaveWrapMode, false}, {FSSF_PRIVATE, NKeyViewer, L"SaveViewMode"sv, ViOpt.SaveViewMode, true}, - {FSSF_PRIVATE, NKeyViewer, L"SearchEditFocus"sv, ViOpt.SearchEditFocus, false}, {FSSF_PRIVATE, NKeyViewer, L"SearchRegexp"sv, ViOpt.SearchRegexp, false}, {FSSF_PRIVATE, NKeyViewer, L"SearchWrapStop"sv, ViOpt.SearchWrapStop, BSTATE_CHECKED}, {FSSF_PRIVATE, NKeyViewer, L"ShowArrows"sv, ViOpt.ShowArrows, true}, diff --git a/far/config.hpp b/far/config.hpp index 5405b0847d..5aaf5282ae 100644 --- a/far/config.hpp +++ b/far/config.hpp @@ -604,7 +604,6 @@ class Options: noncopyable BoolOption SaveShortPos; BoolOption SaveViewMode; BoolOption SaveWrapMode; - BoolOption SearchEditFocus; // auto-focus on edit text/hex window BoolOption SearchRegexp; Bool3Option SearchWrapStop; // [NonStop] / {Start-End} / [Full Cycle] BoolOption ShowArrows; diff --git a/far/farlang.templ.m4 b/far/farlang.templ.m4 index 538f176035..f5fa2b12ad 100644 --- a/far/farlang.templ.m4 +++ b/far/farlang.templ.m4 @@ -3960,20 +3960,6 @@ upd:"Visible '\\0'" "Адлюстроўваць '\\&0'" upd:"Visible '\\&0'" -MViewConfigEditAutofocus -"Авто-&фокус в диалоге поиска" -"Search dialog auto-&focus" -"Automaticky aktivovat dialog hledání" -"Auto&fokus in der Suche in Dialog" -upd:"Search dialog auto-focus" -"Auto-&focus okna szukania" -"Auto-enfocar en &diálogo de búsqueda" -"Automaticky aktivovať dialóg hľadania" -"Auto Riposiziona Dialogo Di &Ricerca" -"Авто-&фокус у діалозі пошуку" -"Аўта-&фокус у гутарцы" -upd:"Search dialog auto-&focus" - MEditConfigTitle l: "Редактор" diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 18b77f7f3f..f01ddd67f2 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -6098 +6099 diff --git a/far/viewer.cpp b/far/viewer.cpp index 1db6deb910..00358abfc0 100644 --- a/far/viewer.cpp +++ b/far/viewer.cpp @@ -129,15 +129,15 @@ Viewer::Viewer(window_ptr Owner, bool bQuickView, uintptr_t aCodePage): SimpleScreenObject(std::move(Owner)), ViOpt(Global->Opt->ViOpt), Reader(ViewFile, (Global->Opt->ViOpt.MaxLineSize*2*64 > 64*1024 ? Global->Opt->ViOpt.MaxLineSize*2*64 : 64*1024)), - strLastSearchStr(Global->GetSearchString()), - LastSearchDlgOptions + LastSearchDlgParams { + .SearchStr = Global->GetSearchString(), + .Hex = Global->GetSearchHex(), .CaseSensitive = Global->GlobalSearchCaseSensitive, .WholeWords = Global->GlobalSearchWholeWords, .Reverse = Global->GlobalSearchReverse, .Regexp = Global->Opt->ViOpt.SearchRegexp, .Fuzzy = Global->GlobalSearchFuzzy, - .Hex = Global->GetSearchHex() }, LastSearchReverse(Global->GlobalSearchReverse), m_DefCodepage(aCodePage), @@ -265,14 +265,14 @@ void Viewer::SavePosition() void Viewer::KeepInitParameters() const { - Global->StoreSearchString(strLastSearchStr, LastSearchDlgOptions.Hex); - Global->GlobalSearchCaseSensitive = LastSearchDlgOptions.CaseSensitive; - Global->GlobalSearchWholeWords = LastSearchDlgOptions.WholeWords; - Global->GlobalSearchReverse = LastSearchDlgOptions.Reverse; - Global->GlobalSearchFuzzy = LastSearchDlgOptions.Fuzzy; + Global->StoreSearchString(LastSearchDlgParams.SearchStr, LastSearchDlgParams.Hex.value()); + Global->GlobalSearchCaseSensitive = LastSearchDlgParams.CaseSensitive.value(); + Global->GlobalSearchWholeWords = LastSearchDlgParams.WholeWords.value(); + Global->GlobalSearchReverse = LastSearchDlgParams.Reverse.value(); + Global->Opt->ViOpt.SearchRegexp = LastSearchDlgParams.Regexp.value(); + Global->GlobalSearchFuzzy = LastSearchDlgParams.Fuzzy.value(); Global->Opt->ViOpt.ViewerIsWrap = m_Wrap; Global->Opt->ViOpt.ViewerWrap = m_WordWrap; - Global->Opt->ViOpt.SearchRegexp = LastSearchDlgOptions.Regexp; } bool Viewer::OpenFile(string_view const Name, bool const Warn) @@ -1627,19 +1627,19 @@ bool Viewer::process_key(const Manager::Key& Key) case KEY_F7: { - Search(0,nullptr); + Search(0); return true; } case KEY_SHIFTF7: case KEY_SPACE: { - Search(1,nullptr); + Search(1); return true; } case KEY_ALTF7: case KEY_RALTF7: { - Search(-1,nullptr); + Search(-1); return true; } case KEY_F8: @@ -1984,13 +1984,6 @@ bool Viewer::process_key(const Manager::Key& Key) } return true; - default: - - if (LocalKey >= ' ' && IsCharKey(LocalKey)) - { - Search(0,&Key); - return true; - } } return false; @@ -2444,176 +2437,6 @@ void Viewer::ChangeViewKeyBar() } } -enum SEARCHDLG -{ - SD_DOUBLEBOX, - SD_RADIO_TEXT, - SD_RADIO_HEX, - SD_TEXT_SEARCH, - SD_EDIT_TEXT, - SD_EDIT_HEX, - SD_SEPARATOR1, - SD_CHECKBOX_CASE, - SD_CHECKBOX_WORDS, - SD_CHECKBOX_REVERSE, - SD_CHECKBOX_REGEXP, - SD_CHECKBOX_FUZZY, - SD_SEPARATOR2, - SD_BUTTON_OK, - SD_BUTTON_CANCEL, - - SD_COUNT, - SD_MAX_CHARS = 128 -}; - -enum -{ - DM_SDSETVISIBILITY = DM_USER + 1, -}; - -struct ViewerDialogData -{ - Viewer* viewer; - bool edit_autofocus; - bool hex_mode; - bool is_text_or_hex_hotkey_used; - bool recursive; -}; - -intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2) -{ - switch (Msg) - { - case DN_INITDIALOG: - { - Dlg->SendMessage(DM_SDSETVISIBILITY, Dlg->SendMessage(DM_GETCHECK, SD_RADIO_HEX, nullptr) == BSTATE_CHECKED, nullptr); - Dlg->SendMessage(DM_EDITUNCHANGEDFLAG,SD_EDIT_TEXT,ToPtr(1)); - Dlg->SendMessage(DM_EDITUNCHANGEDFLAG,SD_EDIT_HEX,ToPtr(1)); - auto& Data = edit_as(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); - Dlg->SendMessage(DM_SETFOCUS, Data.hex_mode? SD_EDIT_HEX : SD_EDIT_TEXT, nullptr); - return TRUE; - } - case DM_SDSETVISIBILITY: - { - Dlg->SendMessage(DM_SHOWITEM,SD_EDIT_TEXT,ToPtr(!Param1)); - Dlg->SendMessage(DM_SHOWITEM,SD_EDIT_HEX,ToPtr(Param1)); - Dlg->SendMessage(DM_ENABLE,SD_CHECKBOX_CASE,ToPtr(!Param1)); - const auto re = Dlg->SendMessage(DM_GETCHECK, SD_CHECKBOX_REGEXP, nullptr) == BSTATE_CHECKED; - Dlg->SendMessage(DM_ENABLE,SD_CHECKBOX_WORDS,ToPtr(!Param1 && !re)); - Dlg->SendMessage(DM_ENABLE,SD_CHECKBOX_REGEXP,ToPtr(!Param1)); - Dlg->SendMessage(DM_ENABLE,SD_CHECKBOX_FUZZY,ToPtr(!Param1 && !re)); - return TRUE; - } - case DN_KILLFOCUS: - { - if (SD_EDIT_TEXT == Param1 || SD_EDIT_HEX == Param1) - { - auto& Data = edit_as(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); - Data.hex_mode = (SD_EDIT_HEX == Param1); - } - break; - } - case DN_BTNCLICK: - { - bool need_focus = false; - auto& Data = edit_as(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); - const auto cradio = (Data.hex_mode? SD_RADIO_HEX : SD_RADIO_TEXT); - - if ((Param1 == SD_RADIO_TEXT || Param1 == SD_RADIO_HEX) && Param2) - { - need_focus = true; - if ( Param1 != cradio) - { - SCOPED_ACTION(Dialog::suppress_redraw)(Dlg); - - const auto new_hex = Param1 == SD_RADIO_HEX; - const auto sd_dst = new_hex? SD_EDIT_HEX : SD_EDIT_TEXT; - const auto sd_src = new_hex? SD_EDIT_TEXT : SD_EDIT_HEX; - - EditorSetPosition esp{ sizeof(esp) }; - esp.CurPos = -1; - Dlg->SendMessage(DM_GETEDITPOSITION, sd_src, &esp); - FarDialogItemData item{ sizeof(item) }; - Dlg->SendMessage(DM_GETTEXT, sd_src, &item); - const string Src(view_as(Dlg->SendMessage(DM_GETCONSTTEXTPTR, sd_src, nullptr)), item.PtrLength); - const auto strTo = ConvertHexString(Src, m_Codepage, !new_hex); - item.PtrLength = strTo.size(); - item.PtrData = UNSAFE_CSTR(strTo); - Dlg->SendMessage(DM_SETTEXT, sd_dst, &item); - Dlg->SendMessage(DM_SDSETVISIBILITY, new_hex, nullptr); - if (esp.CurPos >= 0) - { - const auto p = esp.CurPos; - if (Dlg->SendMessage(DM_GETEDITPOSITION, sd_dst, &esp)) - { - esp.CurPos = esp.CurTabPos = p; - esp.LeftPos = 0; - Dlg->SendMessage(DM_SETEDITPOSITION, sd_dst, &esp); - } - } - - if (!strTo.empty()) - { - const auto changed = Dlg->SendMessage(DM_EDITUNCHANGEDFLAG, sd_src, ToPtr(-1)); - Dlg->SendMessage(DM_EDITUNCHANGEDFLAG, sd_dst, ToPtr(changed)); - } - - Data.hex_mode = new_hex; - if (!(Data.edit_autofocus || Data.is_text_or_hex_hotkey_used)) - return TRUE; - } - } - else if (Param1 == SD_CHECKBOX_REGEXP) - { - Dlg->SendMessage(DM_SDSETVISIBILITY, Data.hex_mode, nullptr); - } - - if ((Data.edit_autofocus || Data.is_text_or_hex_hotkey_used) && !Data.recursive) - { - if ( need_focus - || Param1 == SD_CHECKBOX_CASE - || Param1 == SD_CHECKBOX_WORDS - || Param1 == SD_CHECKBOX_REVERSE - || Param1 == SD_CHECKBOX_REGEXP - || Param1 == SD_CHECKBOX_FUZZY - ){ - Data.recursive = true; - Dlg->SendMessage(DM_SETFOCUS, Data.hex_mode? SD_EDIT_HEX : SD_EDIT_TEXT, nullptr); - Data.recursive = false; - } - } - - if (need_focus) - return TRUE; - else - break; - } - case DN_DRAWDIALOGDONE: - { - if (const auto FirstChar = view_as(Dlg->SendMessage(DM_SETDLGDATA, 0, nullptr))) - Global->WindowManager->CallbackWindow([Dlg, FirstChar]() { Dlg->ProcessKey(*FirstChar); }); - break; - } - case DN_HOTKEY: - { - auto& Data = edit_as(Dlg->SendMessage(DM_GETITEMDATA, SD_EDIT_TEXT, nullptr)); - Data.is_text_or_hex_hotkey_used = Param1 == SD_RADIO_TEXT || Param1 == SD_RADIO_HEX; - break; - } - default: - break; - } - - return Dlg->DefProc(Msg,Param1,Param2); -} - -static auto hex2ss(const string_view from, intptr_t * const pos = nullptr) -{ - if (pos) - *pos /= 2; - return HexStringToBlob(trim_right(from), 0); -} - struct Viewer::search_data { long long CurPos{-1}; // IN: LastSelectPos in file, in bytes always. OUT: If Search_ NotFound/Eof/Bof/Cycle, current search position in file, in bytes always @@ -2782,7 +2605,7 @@ SEARCHER_RESULT Viewer::search_text_forward(search_data* sd) { assert(sd->searcher); - const auto bsize = 8192, slen = sd->search_len, ww = (LastSearchDlgOptions.WholeWords ? 1 : 0); + const auto bsize = 8192, slen = sd->search_len, ww = (LastSearchDlgParams.WholeWords.value() ? 1 : 0); wchar_t prev_char{}, *buff = Search_buffer.data(), *t_buff = (sd->ch_size < 0 ? buff + bsize : nullptr); long long to; const auto cpos = sd->CurPos; @@ -2828,8 +2651,8 @@ SEARCHER_RESULT Viewer::search_text_forward(search_data* sd) {}, CurPos, { - .CaseSensitive = LastSearchDlgOptions.CaseSensitive, - .WholeWords = LastSearchDlgOptions.WholeWords, + .CaseSensitive = LastSearchDlgParams.CaseSensitive.value(), + .WholeWords = LastSearchDlgParams.WholeWords.value(), }, SearchLength, sd->word_div)) @@ -2875,7 +2698,7 @@ SEARCHER_RESULT Viewer::search_text_backward(search_data* sd) { assert(sd->searcher); - const auto bsize = 8192, slen = sd->search_len, ww = (LastSearchDlgOptions.WholeWords ? 1 : 0); + const auto bsize = 8192, slen = sd->search_len, ww = (LastSearchDlgParams.WholeWords.value() ? 1 : 0); const auto buff = Search_buffer.data(); const auto t_buff = (sd->ch_size < 0 ? buff + bsize : nullptr); auto cpos = sd->CurPos; @@ -2923,8 +2746,8 @@ SEARCHER_RESULT Viewer::search_text_backward(search_data* sd) {}, CurPos, { - .CaseSensitive = LastSearchDlgOptions.CaseSensitive, - .WholeWords = LastSearchDlgOptions.WholeWords, + .CaseSensitive = LastSearchDlgParams.CaseSensitive.value(), + .WholeWords = LastSearchDlgParams.WholeWords.value(), .Reverse = true }, SearchLength, @@ -3166,140 +2989,57 @@ SEARCHER_RESULT Viewer::search_regex_backward(search_data* sd) 1 - Продолжить поиск со следующей позиции -1 - Продолжить поиск со следующей позиции в противоположном направлении */ -void Viewer::Search(int Next,const Manager::Key* FirstChar) +void Viewer::Search(int Next) { - if (!ViewFile || (Next && strLastSearchStr.empty())) + if (!ViewFile || (Next && LastSearchDlgParams.SearchStr.empty())) return; - string strSearchStr; - if (!strLastSearchStr.empty()) - strSearchStr = strLastSearchStr; - if (!Next) { - constexpr auto DlgWidth{ 76 }; - constexpr auto HorizontalRadioGap{ 2 }; - const auto& searchFor{ msg(lng::MSearchReplaceSearchFor) }; - const auto& searchForText{ msg(lng::MSearchReplaceText) }; - const auto& searchForHex{ msg(lng::MSearchReplaceHex) }; - const auto searchForW{ static_cast(HiStrlen(searchFor)) }; - const auto searchForTextW{ static_cast(HiStrlen(searchForText) + 4) }; - const auto searchForHexW{ static_cast(HiStrlen(searchForHex) + 4) }; - - const auto searchForX1{ 4 + 1 }; const auto searchForX2{ searchForX1 + searchForW }; - - const auto searchForTextX1_{ searchForX2 + HorizontalRadioGap }; const auto searchForTextX2_{ searchForTextX1_ + searchForTextW }; - const auto searchForHexX1_{ searchForTextX2_ + HorizontalRadioGap }; const auto searchForHexX2_{ searchForHexX1_ + searchForHexW }; - const auto searchForHexOverage{ std::max(searchForHexX2_ - (DlgWidth - 4 - 1), 0) }; - - const auto searchForTextX1{ searchForTextX1_ - searchForHexOverage }; const auto searchForTextX2{ searchForTextX2_ - searchForHexOverage }; - const auto searchForHexX1{ searchForHexX1_ - searchForHexOverage }; const auto searchForHexX2{ searchForHexX2_ - searchForHexOverage }; - - auto SearchDlg = MakeDialogItems( - { - { DI_DOUBLEBOX, {{3, 1}, {DlgWidth-4, 10}}, DIF_NONE, msg(lng::MSearchReplaceSearchTitle), }, - { DI_RADIOBUTTON, {{searchForTextX1, 2}, {searchForTextX2, 2 }}, DIF_GROUP, searchForText, }, - { DI_RADIOBUTTON, {{searchForHexX1, 2}, {searchForHexX2, 2 }}, DIF_NONE, searchForHex, }, - { DI_TEXT, {{searchForX1, 2}, {0, 2 }}, DIF_NONE, searchFor, }, - { DI_EDIT, {{5, 3}, {DlgWidth-4-2, 3 }}, DIF_HISTORY | DIF_USELASTHISTORY, }, - { DI_FIXEDIT, {{5, 3}, {DlgWidth-4-2, 3 }}, DIF_MASKEDIT, }, - { DI_TEXT, {{-1, 4}, {0, 4 }}, DIF_SEPARATOR, }, - { DI_CHECKBOX, {{5, 5}, {0, 5 }}, DIF_NONE, msg(lng::MSearchReplaceCase), }, - { DI_CHECKBOX, {{5, 6}, {0, 6 }}, DIF_NONE, msg(lng::MSearchReplaceWholeWords), }, - { DI_CHECKBOX, {{5, 7}, {0, 7 }}, DIF_NONE, msg(lng::MSearchReplaceReverse), }, - { DI_CHECKBOX, {{40, 5}, {0, 5 }}, DIF_NONE, msg(lng::MSearchReplaceRegexp), }, - { DI_CHECKBOX, {{40, 6}, {0, 6 }}, DIF_NONE, msg(lng::MSearchReplaceFuzzy), }, - { DI_TEXT, {{-1, 8}, {0, 8 }}, DIF_SEPARATOR, }, - { DI_BUTTON, {{0, 9}, {0, 9 }}, DIF_CENTERGROUP | DIF_DEFAULTBUTTON, msg(lng::MSearchReplaceSearch), }, - { DI_BUTTON, {{0, 9}, {0, 9 }}, DIF_CENTERGROUP, msg(lng::MSearchReplaceCancel), }, - }); - - string mask(3 * SD_MAX_CHARS, L'H'); - for (int i = 0; i < SD_MAX_CHARS; ++i) - mask[3 * i + 2] = L' '; // "HH HH ..." - SearchDlg[SD_RADIO_TEXT].Selected =!LastSearchDlgOptions.Hex; - SearchDlg[SD_RADIO_HEX].Selected = LastSearchDlgOptions.Hex; - SearchDlg[SD_EDIT_HEX].strMask = std::move(mask); - SearchDlg[SD_EDIT_TEXT].strHistory = L"SearchText"sv; - SearchDlg[SD_CHECKBOX_CASE].Selected = LastSearchDlgOptions.CaseSensitive; - SearchDlg[SD_CHECKBOX_WORDS].Selected = LastSearchDlgOptions.WholeWords; - SearchDlg[SD_CHECKBOX_REVERSE].Selected = LastSearchDlgOptions.Reverse; - SearchDlg[SD_CHECKBOX_REGEXP].Selected= LastSearchDlgOptions.Regexp; - SearchDlg[SD_CHECKBOX_FUZZY].Selected = LastSearchDlgOptions.Fuzzy; - SearchDlg[SearchDlg[SD_RADIO_HEX].Selected? SD_EDIT_HEX : SD_EDIT_TEXT].strData = strSearchStr; - - ViewerDialogData my - { - .viewer = this, - .edit_autofocus = (ViOpt.SearchEditFocus != 0), - .hex_mode = LastSearchDlgOptions.Hex, - .is_text_or_hex_hotkey_used = false, - .recursive = false, - }; - SearchDlg[SD_EDIT_TEXT].UserData = reinterpret_cast(&my); - - const auto Dlg = Dialog::create(SearchDlg, &Viewer::ViewerSearchDlgProc, this, const_cast(FirstChar)); - Dlg->SetId(ViewerSearchId); - Dlg->SetHelp(L"ViewerSearch"sv); - Dlg->SetPosition({ -1, -1, 76, 12 }); - - Dlg->Process(); - - if (Dlg->GetExitCode()!=SD_BUTTON_OK) - return; - - LastSearchDlgOptions.Hex = SearchDlg[SD_RADIO_HEX].Selected == BSTATE_CHECKED; - LastSearchDlgOptions.CaseSensitive = SearchDlg[SD_CHECKBOX_CASE].Selected == BSTATE_CHECKED; - LastSearchDlgOptions.WholeWords = SearchDlg[SD_CHECKBOX_WORDS].Selected == BSTATE_CHECKED; - LastSearchDlgOptions.Reverse = SearchDlg[SD_CHECKBOX_REVERSE].Selected == BSTATE_CHECKED; - LastSearchDlgOptions.Regexp = SearchDlg[SD_CHECKBOX_REGEXP].Selected == BSTATE_CHECKED; - LastSearchDlgOptions.Fuzzy = SearchDlg[SD_CHECKBOX_FUZZY].Selected == BSTATE_CHECKED; - - if (LastSearchDlgOptions.Hex) - { - strSearchStr = ExtractHexString(SearchDlg[SD_EDIT_HEX].strData); - } - else + if (!GetSearchReplaceString( + LastSearchDlgParams, + L"SearchText"sv, + {}, + m_Codepage, + L"ViewerSearch"sv, + &ViewerSearchId)) { - strSearchStr = SearchDlg[SD_EDIT_TEXT].strData; + return; } } - auto SearchReverse{ Next == -1 ? !LastSearchDlgOptions.Reverse : LastSearchDlgOptions.Reverse }; - - auto strMsgStr = strLastSearchStr = strSearchStr; + auto SearchReverse{ Next == -1 ? !LastSearchDlgParams.Reverse.value() : LastSearchDlgParams.Reverse.value() }; + auto strMsgStr = LastSearchDlgParams.SearchStr; searchers Searchers; search_data sd; - bytes search_bytes; decltype(&Viewer::search_hex_forward) searcher; - if (LastSearchDlgOptions.Hex) + if (LastSearchDlgParams.Hex.value()) { sd.ch_size = 1; - search_bytes = hex2ss(strSearchStr); - sd.search_bytes = search_bytes; - sd.search_len = static_cast(search_bytes.size()); + sd.search_bytes = LastSearchDlgParams.SearchBytes; + sd.search_len = static_cast(LastSearchDlgParams.SearchBytes.size()); searcher = (SearchReverse ? &Viewer::search_hex_backward : &Viewer::search_hex_forward); } else { sd.ch_size = getCharSize(); - sd.search_text = strSearchStr; - sd.search_len = static_cast(strSearchStr.size()); + sd.search_text = LastSearchDlgParams.SearchStr; + sd.search_len = static_cast(LastSearchDlgParams.SearchStr.size()); - if (LastSearchDlgOptions.Regexp) + if (LastSearchDlgParams.Regexp.value()) { searcher = (SearchReverse ? &Viewer::search_regex_backward : &Viewer::search_regex_forward); - const auto strSlash = InsertRegexpQuote(strSearchStr); + const auto strSlash = InsertRegexpQuote(LastSearchDlgParams.SearchStr); strMsgStr = strSlash; try { - sd.Rex.Compile(strSlash, OP_PERLSTYLE | OP_OPTIMIZE | (LastSearchDlgOptions.CaseSensitive? 0 : OP_IGNORECASE)); + sd.Rex.Compile(strSlash, OP_PERLSTYLE | OP_OPTIMIZE | (LastSearchDlgParams.CaseSensitive.value() ? 0 : OP_IGNORECASE)); } catch (regex_exception const& e) { @@ -3309,7 +3049,7 @@ void Viewer::Search(int Next,const Manager::Key* FirstChar) } else { - sd.searcher = &init_searcher(Searchers, LastSearchDlgOptions.CaseSensitive, LastSearchDlgOptions.Fuzzy, strLastSearchStr); + sd.searcher = &init_searcher(Searchers, LastSearchDlgParams.CaseSensitive.value(), LastSearchDlgParams.Fuzzy.value(), LastSearchDlgParams.SearchStr); sd.word_div = get_word_div(); searcher = (SearchReverse ? &Viewer::search_text_backward : &Viewer::search_text_forward); inplace::quote_unconditional(strMsgStr); @@ -3361,7 +3101,9 @@ void Viewer::Search(int Next,const Manager::Key* FirstChar) if (!sd.search_len || !FileSize) return; - const auto can_be_found = ((LastSearchDlgOptions.Regexp || LastSearchDlgOptions.Fuzzy) && !LastSearchDlgOptions.Hex) || static_cast(sd.search_len) <= FileSize; + const auto can_be_found = + ((LastSearchDlgParams.Regexp.value() || LastSearchDlgParams.Fuzzy.value()) && !LastSearchDlgParams.Hex.value()) + || static_cast(sd.search_len) <= FileSize; sd.CurPos = LastSelectPos; { @@ -3385,7 +3127,7 @@ void Viewer::Search(int Next,const Manager::Key* FirstChar) Message(MSG_WARNING, msg(lng::MSearchReplaceSearchTitle), { - msg(LastSearchDlgOptions.Hex? lng::MViewSearchCannotFindHex : lng::MViewSearchCannotFind), + msg(LastSearchDlgParams.Hex.value() ? lng::MViewSearchCannotFindHex : lng::MViewSearchCannotFind), strMsgStr }, { lng::MOk }); @@ -3445,7 +3187,10 @@ void Viewer::Search(int Next,const Manager::Key* FirstChar) } if (!Progress) - Progress.emplace(msg(lng::MSearchReplaceSearchTitle), concat(msg(LastSearchDlgOptions.Hex? lng::MViewSearchingHex : lng::MViewSearchingFor), L' ', strMsgStr), 0); + { + Progress.emplace( + msg(lng::MSearchReplaceSearchTitle), concat(msg(LastSearchDlgParams.Hex.value() ? lng::MViewSearchingHex : lng::MViewSearchingFor), L' ', strMsgStr), 0); + } Progress->update(percent); } diff --git a/far/viewer.hpp b/far/viewer.hpp index 7547339e36..b9111d392c 100644 --- a/far/viewer.hpp +++ b/far/viewer.hpp @@ -37,6 +37,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Internal: #include "scrobj.hpp" +#include "stddlg.hpp" #include "namelist.hpp" #include "poscache.hpp" #include "config.hpp" @@ -135,7 +136,7 @@ class Viewer:public SimpleScreenObject long long BegOfScreen(); long long XYfilepos(int col, int row); void ChangeViewKeyBar(); - void Search(int Next,const Manager::Key* FirstChar); + void Search(int Next); struct search_data; SEARCHER_RESULT search_hex_forward( search_data* sd ); SEARCHER_RESULT search_hex_backward( search_data* sd ); @@ -154,7 +155,6 @@ class Viewer:public SimpleScreenObject int GetStrBytesNum(const wchar_t* Str, int Length) const; // BUGBUG not string_view, could be unrelated 🤦 bool isBinaryFile(uintptr_t cp); void SavePosition(); - intptr_t ViewerSearchDlgProc(Dialog* Dlg, intptr_t Msg,intptr_t Param1,void* Param2); int getCharSize() const; int txt_dump(std::string_view Str, size_t ClientWidth, string& OutStr, wchar_t ZeroChar, int tail) const; @@ -192,17 +192,7 @@ class Viewer:public SimpleScreenObject bool m_DeleteFolder{true}; - string strLastSearchStr; - - struct SearchDlgOptions - { - bool CaseSensitive{}; - bool WholeWords{}; - bool Reverse{}; - bool Regexp{}; - bool Fuzzy{}; - bool Hex{}; - } LastSearchDlgOptions; + SearchReplaceDlgParams LastSearchDlgParams; bool LastSearchReverse{}; // Used to adjust StartSearchPos. NOT the same as LastSearchDlgOptions.Reverse. long long StartSearchPos{}; diff --git a/plugins/luamacro/macrotest.lua b/plugins/luamacro/macrotest.lua index c2b14b6061..05f821e881 100644 --- a/plugins/luamacro/macrotest.lua +++ b/plugins/luamacro/macrotest.lua @@ -1004,7 +1004,7 @@ local function test_Far_GetConfig() "Viewer.SaveViewerPos", "boolean", "Viewer.SaveViewerShortPos", "boolean", "Viewer.SaveViewerWrapMode", "boolean", - "Viewer.SearchEditFocus", "boolean", + -- "Viewer.SearchEditFocus", "boolean", // Removed in 6099 "Viewer.SearchRegexp", "boolean", "Viewer.SearchWrapStop", "3-state", "Viewer.ShowArrows", "boolean",