From 21c20226690670439ab7fefc8df6a0ccb1b8c56c Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Sun, 1 Aug 2021 15:36:56 +0100 Subject: [PATCH] Remove more fake dialogs --- far/changelog | 5 ++ far/copy_progress.cpp | 11 ++-- far/delete.cpp | 2 +- far/dirinfo.cpp | 5 +- far/dizlist.cpp | 2 +- far/editor.cpp | 65 ++----------------- far/editor.hpp | 12 ---- far/farlang.templ.m4 | 26 ++++---- far/fileedit.cpp | 18 ++---- far/filelist.cpp | 144 ++++++++++++++---------------------------- far/filelist.hpp | 6 +- far/keyboard.cpp | 6 +- far/keyboard.hpp | 2 +- far/panel.hpp | 1 - far/plugapi.cpp | 2 +- far/print.cpp | 31 +++++---- far/setattr.cpp | 4 +- far/stddlg.cpp | 64 +++++++++++++++++++ far/stddlg.hpp | 15 +++++ far/treelist.cpp | 24 +++---- far/vbuild.m4 | 2 +- far/viewer.cpp | 9 +-- 22 files changed, 204 insertions(+), 252 deletions(-) diff --git a/far/changelog b/far/changelog index e7b5c3fffe..8926d93006 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,8 @@ +-------------------------------------------------------------------------------- +drkns 01.08.2021 15:34:13 +0100 - build 5864 + +1. Remove more fake dialogs. + -------------------------------------------------------------------------------- drkns 31.07.2021 14:22:45 +0100 - build 5863 diff --git a/far/copy_progress.cpp b/far/copy_progress.cpp index cf31ee45f4..92e58913b2 100644 --- a/far/copy_progress.cpp +++ b/far/copy_progress.cpp @@ -198,13 +198,10 @@ unsigned long long copy_progress::get_total_bytes() const bool copy_progress::CheckEsc() { - if (!m_IsCancelled) - { - if (CheckForEscSilent()) - { - m_IsCancelled = ConfirmAbortOp() != 0; - } - } + if (m_IsCancelled) + return m_IsCancelled; + + m_IsCancelled = CheckForEscAndConfirmAbort(); return m_IsCancelled; } diff --git a/far/delete.cpp b/far/delete.cpp index f88446e2ef..12acaca670 100644 --- a/far/delete.cpp +++ b/far/delete.cpp @@ -181,7 +181,7 @@ static void ShellDeleteMsgImpl(string_view const Name, DEL_MODE Mode, ShellDelet static void ShellDeleteMsg(string_view const Name, DEL_MODE Mode, ShellDelete::progress Files, int WipePercent) { - if (CheckForEscSilent() && ConfirmAbortOp()) + if (CheckForEscAndConfirmAbort()) cancel_operation(); ShellDeleteMsgImpl(Name, Mode, Files, WipePercent); diff --git a/far/dirinfo.cpp b/far/dirinfo.cpp index 2c33493b9c..79761d5c41 100644 --- a/far/dirinfo.cpp +++ b/far/dirinfo.cpp @@ -326,10 +326,9 @@ static void ScanPluginDir(plugin_panel* hDirListPlugin, OPERATION_MODES OpMode, span PanelData; - if (CheckForEscSilent()) + if (CheckForEscAndConfirmAbort()) { - if (ConfirmAbortOp()) - StopSearch = true; + StopSearch = true; } if (StopSearch || !Global->CtrlObject->Plugins->GetFindData(hDirListPlugin, PanelData, OPM_FIND | OpMode)) diff --git a/far/dizlist.cpp b/far/dizlist.cpp index 5ef8bca1e1..a57dc2e8fa 100644 --- a/far/dizlist.cpp +++ b/far/dizlist.cpp @@ -122,7 +122,7 @@ void DizList::Read(string_view const Path, const string* DizName) SetCursorType(false, 0); PR_ReadingMsg(); - if (CheckForEsc()) + if (CheckForEscAndConfirmAbort()) break; } diff --git a/far/editor.cpp b/far/editor.cpp index 4587c69f18..965c13608a 100644 --- a/far/editor.cpp +++ b/far/editor.cpp @@ -3459,7 +3459,7 @@ bool Editor::Search(bool Next) const auto strSearchStrLower = Case? strSearchStr : lower(strSearchStr); const time_check TimeCheck; - editor_progress const Progress(msg(lng::MEditSearchTitle), format(msg(lng::MEditSearchingFor), QuotedStr), 0); + single_progress const Progress(msg(lng::MEditSearchTitle), format(msg(lng::MEditSearchingFor), QuotedStr), 0); int StartLine = m_it_CurLine.Number(); SCOPED_ACTION(taskbar::indeterminate); SCOPED_ACTION(wakeful); @@ -3469,13 +3469,10 @@ bool Editor::Search(bool Next) { if (TimeCheck) { - if (CheckForEscSilent()) + if (CheckForEscAndConfirmAbort()) { - if (ConfirmAbortOp()) - { - UserBreak = true; - break; - } + UserBreak = true; + break; } SetCursorType(false, -1); @@ -6920,57 +6917,3 @@ void Editor::AutoDeleteColors() m_AutoDeletedColors.clear(); } - -namespace -{ - enum - { - DlgW = 76, - DlgH = 6, - }; - - enum progress_items - { - pr_doublebox, - pr_label, - pr_progress, - - pr_count - }; -} - -editor_progress::editor_progress(string_view const Title, string_view const Msg, size_t const Percent) -{ - auto ProgressDlgItems = MakeDialogItems( - { - { DI_DOUBLEBOX, {{ 3, 1 }, { DlgW - 4, DlgH - 2 }}, DIF_NONE, Title, }, - { DI_TEXT, {{ 5, 2 }, { DlgW - 6, 2 }}, DIF_CENTERTEXT, Msg }, - { DI_TEXT, {{ 5, 3 }, { DlgW - 6, 3 }}, DIF_NONE, make_progressbar(DlgW - 10, Percent, true, true) }, - }); - - m_Dialog = Dialog::create(ProgressDlgItems, [](Dialog* const Dlg, intptr_t const Msg, intptr_t const Param1, void* const Param2) - { - if (Msg == DN_RESIZECONSOLE) - { - COORD Position{ -1, -1 }; - Dlg->SendMessage(DM_MOVEDIALOG, 1, &Position); - } - - return Dlg->DefProc(Msg, Param1, Param2); - }); - - m_Dialog->SetPosition({ -1, -1, DlgW, DlgH }); - m_Dialog->SetCanLoseFocus(true); - m_Dialog->Process(); -} - -editor_progress::~editor_progress() -{ - if (m_Dialog) - m_Dialog->CloseDialog(); -} - -void editor_progress::update(size_t const Percent) const -{ - m_Dialog->SendMessage(DM_SETTEXTPTR, progress_items::pr_progress, UNSAFE_CSTR(make_progressbar(DlgW - 10, Percent, true, true))); -} diff --git a/far/editor.hpp b/far/editor.hpp index c7e3f8af16..1199e787a7 100644 --- a/far/editor.hpp +++ b/far/editor.hpp @@ -405,16 +405,4 @@ class EditorContainer virtual Editor* GetEditor() = 0; }; -class editor_progress -{ -public: - editor_progress(string_view Title, string_view Msg, size_t Percent); - ~editor_progress(); - - void update(size_t Percent) const; - -private: - dialog_ptr m_Dialog; -}; - #endif // EDITOR_HPP_79DE09D5_8F9C_467E_A3BF_8E1BB34E4BD3 diff --git a/far/farlang.templ.m4 b/far/farlang.templ.m4 index 46a5db3a08..d2682c3a3b 100644 --- a/far/farlang.templ.m4 +++ b/far/farlang.templ.m4 @@ -21396,19 +21396,19 @@ MPrintFilesTo "Друк {0} файлаў на" "Spausdinti {0} failus su" -MPreparingForPrinting -"Подготовка файлов к печати" -"Preparing files for printing" -"Připravuji soubory pro tisk" -"Vorbereiten der Druckaufträge" -"Fájlok előkészítése nyomtatáshoz" -"Przygotowuję plik(i) do drukowania" -"Preparando archivos para imprimir" -"Pripravujem súbory na tlač" -"Preparazione Dei Files Per La Stampa" -"Підготовка файлів до друку" -"Падрыхтоўка файлаў да друку" -"Ruošiu failus spausdinimui" +MPrintingFile +"Печать {0}" +"Printing {0}" +"Tisk {0}" +"Drucken {0}" +"Nyomtatás {0}" +"Druk {0}" +"Impresión {0}" +"Tlač {0}" +"Stampa {0}" +"Друк {0}" +"Друк {0}" +"Spausdinimas {0}" MCannotEnumeratePrinters "Не удалось получить список доступных принтеров" diff --git a/far/fileedit.cpp b/far/fileedit.cpp index 2cc57cb59a..9a04f47b13 100644 --- a/far/fileedit.cpp +++ b/far/fileedit.cpp @@ -57,7 +57,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "scrbuf.hpp" #include "savescr.hpp" #include "filestr.hpp" -#include "TPreRedrawFunc.hpp" #include "taskbar.hpp" #include "interf.hpp" #include "message.hpp" @@ -1640,7 +1639,7 @@ bool FileEditor::LoadFile(const string& Name,int &UserBreak, error_state_ex& Err LOGWARNING(L"GetSize({}): {}"sv, EditFile.GetName(), last_error()); } - editor_progress const Progress(msg(lng::MEditTitle), format(msg(lng::MEditReading), Name), 0); + single_progress const Progress(msg(lng::MEditTitle), format(msg(lng::MEditReading), Name), 0); const time_check TimeCheck; @@ -1663,14 +1662,11 @@ bool FileEditor::LoadFile(const string& Name,int &UserBreak, error_state_ex& Err if (TimeCheck) { - if (CheckForEscSilent()) + if (CheckForEscAndConfirmAbort()) { - if (ConfirmAbortOp()) - { - UserBreak = 1; - EditFile.Close(); - return false; - } + UserBreak = 1; + EditFile.Close(); + return false; } SetCursorType(false, 0); @@ -2040,7 +2036,7 @@ int FileEditor::SaveFile(const string& Name,int Ask, bool bSaveAs, error_state_e if (!bSaveAs) AddSignature = m_bAddSignature; - editor_progress const Progress(msg(lng::MEditTitle), format(msg(lng::MEditSaving), Name), 0); + single_progress const Progress(msg(lng::MEditTitle), format(msg(lng::MEditSaving), Name), 0); const time_check TimeCheck; @@ -2423,7 +2419,7 @@ bool FileEditor::UpdateFileList() const if (strPanelPath == strFilePath) { - ActivePanel->Update(UPDATE_KEEP_SELECTION|UPDATE_DRAW_MESSAGE); + ActivePanel->Update(UPDATE_KEEP_SELECTION); return true; } diff --git a/far/filelist.cpp b/far/filelist.cpp index 90a9ea641c..8ec08d6d30 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -5032,7 +5032,7 @@ bool FileList::ApplyCommand() const auto ExecutionContext = Global->WindowManager->Desktop()->ConsoleSession().GetContext(); for (const auto& i: enum_selected()) { - if (CheckForEsc()) + if (CheckForEscAndConfirmAbort()) break; string strConvertedCommand = strCommand; @@ -6567,19 +6567,23 @@ void FileList::Update(int Mode) { if (m_EnableUpdate) { + const auto + IsKeepSelection = (Mode & UPDATE_KEEP_SELECTION) != 0, + IsIgnoreVisible = (Mode & UPDATE_IGNORE_VISIBLE) != 0; + switch (m_PanelMode) { case panel_mode::NORMAL_PANEL: - ReadFileNames(Mode & UPDATE_KEEP_SELECTION, Mode & UPDATE_IGNORE_VISIBLE, Mode & UPDATE_DRAW_MESSAGE); + ReadFileNames(IsKeepSelection, IsIgnoreVisible); break; case panel_mode::PLUGIN_PANEL: Global->CtrlObject->Plugins->GetOpenPanelInfo(GetPluginHandle(), &m_CachedOpenPanelInfo); if (m_PanelMode != panel_mode::PLUGIN_PANEL) - ReadFileNames(Mode & UPDATE_KEEP_SELECTION, Mode & UPDATE_IGNORE_VISIBLE, Mode & UPDATE_DRAW_MESSAGE); + ReadFileNames(IsKeepSelection, IsIgnoreVisible); else if ((m_CachedOpenPanelInfo.Flags & OPIF_REALNAMES) || Parent()->GetAnotherPanel(this)->GetMode() == panel_mode::PLUGIN_PANEL || !(Mode & UPDATE_SECONDARY)) - UpdatePlugin(Mode & UPDATE_KEEP_SELECTION, Mode & UPDATE_IGNORE_VISIBLE); + UpdatePlugin(IsKeepSelection, IsIgnoreVisible); break; } } @@ -6591,49 +6595,11 @@ void FileList::UpdateIfRequired() return; UpdateRequired = false; - Update(UpdateRequiredMode | UPDATE_IGNORE_VISIBLE); -} - -static void PR_ReadFileNamesMsg(); - -struct FileListPreRedrawItem : PreRedrawItem -{ - FileListPreRedrawItem() : PreRedrawItem(PR_ReadFileNamesMsg){} - - string Msg; -}; - -static void ReadFileNamesMsgImpl(const string& Msg) -{ - Message(0, - msg(lng::MReadingTitleFiles), - { - Msg - }, - {}); + Update((m_KeepSelection? UPDATE_KEEP_SELECTION : 0) | UPDATE_IGNORE_VISIBLE); } -static void ReadFileNamesMsg(const string& Msg) +void FileList::ReadFileNames(bool const KeepSelection, bool const UpdateEvenIfPanelInvisible) { - ReadFileNamesMsgImpl(Msg); - - TPreRedrawFunc::instance()([&](FileListPreRedrawItem& Item) - { - Item.Msg = Msg; - }); -} - -static void PR_ReadFileNamesMsg() -{ - TPreRedrawFunc::instance()([](const FileListPreRedrawItem& Item) - { - ReadFileNamesMsgImpl(Item.Msg); - }); -} - -void FileList::ReadFileNames(int KeepSelection, int UpdateEvenIfPanelInvisible, int DrawMessage) -{ - SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique()); SCOPED_ACTION(taskbar::indeterminate)(false); strOriginalCurDir = m_CurDir; @@ -6641,7 +6607,7 @@ void FileList::ReadFileNames(int KeepSelection, int UpdateEvenIfPanelInvisible, if (!IsVisible() && !UpdateEvenIfPanelInvisible) { UpdateRequired = true; - UpdateRequiredMode=KeepSelection; + m_KeepSelection = KeepSelection; return; } @@ -6814,75 +6780,59 @@ void FileList::ReadFileNames(int KeepSelection, int UpdateEvenIfPanelInvisible, { ErrorState = last_error(); + const auto IsDirectory = (fdata.Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + if (fdata.Attributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM) && !Global->Opt->ShowHidden) continue; if (UseFilter && !m_Filter->FileInFilter(fdata, {}, fdata.FileName)) { - if (!(fdata.Attributes & FILE_ATTRIBUTE_DIRECTORY)) + if (!IsDirectory) m_FilteredExtensions.emplace(name_ext(fdata.FileName).second); continue; } - { - FileListItem NewItem{}; - - static_cast(NewItem) = fdata; - - if (!(fdata.Attributes & FILE_ATTRIBUTE_DIRECTORY)) - { - TotalFileSize += NewItem.FileSize; - } + { + FileListItem NewItem{}; - NewItem.SortGroup = DEFAULT_SORT_GROUP; - NewItem.Position = m_ListData.size(); - m_ListData.emplace_back(std::move(NewItem)); - } + static_cast(NewItem) = fdata; - if (fdata.Attributes & FILE_ATTRIBUTE_DIRECTORY) + if (!IsDirectory) { - ++m_TotalDirCount; - } - else - { - ++m_TotalFileCount; + TotalFileSize += NewItem.FileSize; } - if (TimeCheck) - { - if (IsVisible()) - { - if (!IsShowTitle) - { - if (!DrawMessage) - { - Text({ m_Where.left + 1, m_Where.top }, colors::PaletteColorToFarColor(COL_PANELBOX), Title); - IsShowTitle = true; - SetColor(IsFocused()? COL_PANELSELECTEDTITLE:COL_PANELTITLE); - } - } + NewItem.SortGroup = DEFAULT_SORT_GROUP; + NewItem.Position = m_ListData.size(); + m_ListData.emplace_back(std::move(NewItem)); + } - auto strReadMsg = format(msg(lng::MReadingFiles), m_ListData.size()); + ++(IsDirectory? m_TotalDirCount : m_TotalFileCount); - if (DrawMessage) - { - ReadFileNamesMsg(strReadMsg); - } - else - { - inplace::truncate_left(strReadMsg, Title.size() - 2); - GotoXY(m_Where.left + 1 + static_cast(Title.size() - strReadMsg.size() - 1) / 2, m_Where.top); - Text(concat(L' ', strReadMsg, L' ')); - } + if (TimeCheck) + { + if (IsVisible()) + { + if (!IsShowTitle) + { + Text({ m_Where.left + 1, m_Where.top }, colors::PaletteColorToFarColor(COL_PANELBOX), Title); + IsShowTitle = true; + SetColor(IsFocused()? COL_PANELSELECTEDTITLE:COL_PANELTITLE); } - Global->CtrlObject->Macro.SuspendMacros(true); - bool check = CheckForEsc(); - Global->CtrlObject->Macro.SuspendMacros(false); - if (check) - break; + auto strReadMsg = format(msg(lng::MReadingFiles), m_ListData.size()); + inplace::truncate_left(strReadMsg, Title.size() - 2); + GotoXY(m_Where.left + 1 + static_cast(Title.size() - strReadMsg.size() - 1) / 2, m_Where.top); + Text(concat(L' ', strReadMsg, L' ')); } + + Global->CtrlObject->Macro.SuspendMacros(true); + SCOPE_EXIT{ Global->CtrlObject->Macro.SuspendMacros(false); }; + + if (CheckForEscAndConfirmAbort()) + break; + } } if (!ErrorState) @@ -7168,12 +7118,12 @@ void FileList::MoveSelection(list_data& From, list_data& To) From.clear(); } -void FileList::UpdatePlugin(int KeepSelection, int UpdateEvenIfPanelInvisible) +void FileList::UpdatePlugin(bool const KeepSelection, bool const UpdateEvenIfPanelInvisible) { if (!IsVisible() && !UpdateEvenIfPanelInvisible) { UpdateRequired = true; - UpdateRequiredMode=KeepSelection; + m_KeepSelection = KeepSelection; return; } @@ -7508,7 +7458,7 @@ void FileList::DisplayObject() if (UpdateRequired) { UpdateRequired = false; - Update(UpdateRequiredMode); + Update(m_KeepSelection? UPDATE_KEEP_SELECTION : 0); } ShowFileList(false); } diff --git a/far/filelist.hpp b/far/filelist.hpp index 62a2028047..91415c9407 100644 --- a/far/filelist.hpp +++ b/far/filelist.hpp @@ -265,8 +265,8 @@ class FileList:public Panel bool ChangeDir(string_view NewDir, bool IsParent, bool ResolvePath, bool IsUpdated, const UserDataItem* DataItem, OPENFILEPLUGINTYPE OfpType, bool Silent); bool ChangeDir(string_view NewDir, bool IsParent); void CountDirSize(bool IsRealNames); - void ReadFileNames(int KeepSelection, int UpdateEvenIfPanelInvisible, int DrawMessage); - void UpdatePlugin(int KeepSelection, int UpdateEvenIfPanelInvisible); + void ReadFileNames(bool KeepSelection, bool UpdateEvenIfPanelInvisible); + void UpdatePlugin(bool KeepSelection, bool UpdateEvenIfPanelInvisible); void MoveSelection(list_data& From, list_data& To); void PushPlugin(std::unique_ptr&& hPlugin, string_view HostFile); bool PopPlugin(int EnableRestoreViewMode); @@ -386,7 +386,7 @@ class FileList:public Panel bool empty{}; // указывает на полностью пустую колонку bool AccessTimeUpdateRequired{}; bool UpdateRequired{}; - int UpdateRequiredMode{}; + bool m_KeepSelection{}; int UpdateDisabled{}; bool SortGroupsRead{}; int InternalProcessKey{}; diff --git a/far/keyboard.cpp b/far/keyboard.cpp index cbc33cf628..3bef984e78 100644 --- a/far/keyboard.cpp +++ b/far/keyboard.cpp @@ -1253,15 +1253,15 @@ bool CheckForEscSilent() bool ConfirmAbortOp() { - return (Global->Opt->Confirm.Esc && !Global->CloseFAR)? AbortMessage() : true; + return !Global->Opt->Confirm.Esc || Global->CloseFAR || AbortMessage(); } /* $ 09.02.2001 IS Подтверждение нажатия Esc */ -bool CheckForEsc() +bool CheckForEscAndConfirmAbort() { - return CheckForEscSilent()? ConfirmAbortOp() : false; + return CheckForEscSilent() && ConfirmAbortOp(); } using tfkey_to_text = string_view(const TFKey&); diff --git a/far/keyboard.hpp b/far/keyboard.hpp index b05bd74fb9..a18b17c604 100644 --- a/far/keyboard.hpp +++ b/far/keyboard.hpp @@ -145,9 +145,9 @@ bool WriteInput(int Key); bool IsModifKey(DWORD Key); bool IsInternalKeyReal(unsigned int Key); bool IsCharKey(unsigned int Key); -bool CheckForEsc(); bool CheckForEscSilent(); bool ConfirmAbortOp(); +bool CheckForEscAndConfirmAbort(); void wakeup_for_clock(bool Value); void wakeup_for_screensaver(bool Value); diff --git a/far/panel.hpp b/far/panel.hpp index 95fa9aba89..a0cc3c151d 100644 --- a/far/panel.hpp +++ b/far/panel.hpp @@ -106,7 +106,6 @@ enum UPDATE_KEEP_SELECTION = 0_bit, UPDATE_SECONDARY = 1_bit, UPDATE_IGNORE_VISIBLE = 2_bit, - UPDATE_DRAW_MESSAGE = 3_bit, }; enum class panel_mode diff --git a/far/plugapi.cpp b/far/plugapi.cpp index 08d64fdbd7..b566f12c17 100644 --- a/far/plugapi.cpp +++ b/far/plugapi.cpp @@ -1617,7 +1617,7 @@ intptr_t WINAPI apiGetDirList(const wchar_t *Dir,PluginPanelItem **pPanelItem,si { if (TimeCheck) { - if (CheckForEsc()) + if (CheckForEscAndConfirmAbort()) { FreePluginPanelItemsData(*Items); return FALSE; diff --git a/far/print.cpp b/far/print.cpp index c0e11c451b..52e0e6494b 100644 --- a/far/print.cpp +++ b/far/print.cpp @@ -44,7 +44,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "filelist.hpp" #include "savescr.hpp" #include "ctrlobj.hpp" -#include "TPreRedrawFunc.hpp" +#include "keyboard.hpp" #include "interf.hpp" #include "message.hpp" #include "delete.hpp" @@ -54,6 +54,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "strmix.hpp" #include "global.hpp" #include "log.hpp" +#include "stddlg.hpp" +#include "datetime.hpp" // Platform: #include "platform.fs.hpp" @@ -177,19 +179,11 @@ void PrintFiles(FileList* SrcPanel) SCOPED_ACTION(SaveScreen); - const auto PR_PrintMsg = [] - { - Message(0, - msg(lng::MPrintTitle), - { - msg(lng::MPreparingForPrinting) - }, - {}); - }; + single_progress const Progress(msg(lng::MPrintTitle), {}, 0); + time_check const TimeCheck; - SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique(PR_PrintMsg)); SetCursorType(false, 0); - PR_PrintMsg(); + const auto hPlugin = SrcPanel->GetPluginHandle(); const auto UseInternalCommand = [&] @@ -201,11 +195,24 @@ void PrintFiles(FileList* SrcPanel) const auto PluginMode = SrcPanel->GetMode() == panel_mode::PLUGIN_PANEL && !UseInternalCommand(); + size_t PrintIndex{}; + for (const auto& i: SrcPanel->enum_selected()) { if (i.Attributes & FILE_ATTRIBUTE_DIRECTORY) continue; + if (TimeCheck) + { + if (CheckForEscAndConfirmAbort()) + break; + + Progress.update(format(msg(lng::MPrintingFile), i.FileName)); + Progress.update(ToPercent(PrintIndex, SelCount - DirsCount)); + } + + ++PrintIndex; + delayed_deleter Deleter(true); string FileName; diff --git a/far/setattr.cpp b/far/setattr.cpp index 0430d88549..d960934861 100644 --- a/far/setattr.cpp +++ b/far/setattr.cpp @@ -1277,7 +1277,7 @@ static bool ShellSetFileAttributesImpl(Panel* SrcPanel, const string* Object) { ShellSetFileAttributesMsg(SingleSelFileName); - if (CheckForEsc()) + if (CheckForEscAndConfirmAbort()) break; } @@ -1308,7 +1308,7 @@ static bool ShellSetFileAttributesImpl(Panel* SrcPanel, const string* Object) { ShellSetFileAttributesMsg(strFullName); - if (CheckForEsc()) + if (CheckForEscAndConfirmAbort()) { return false; } diff --git a/far/stddlg.cpp b/far/stddlg.cpp index 247c997ab4..e8fb3c9265 100644 --- a/far/stddlg.cpp +++ b/far/stddlg.cpp @@ -876,3 +876,67 @@ bool RetryAbort(std::vector&& Messages) return ConsoleYesNo(L"Retry"sv, false); } + +namespace +{ + enum + { + DlgW = 76, + DlgH = 6, + }; + + enum progress_items + { + pr_console_title, + pr_doublebox, + pr_message, + pr_progress, + + pr_count + }; +} + +single_progress::single_progress(string_view const Title, string_view const Msg, size_t const Percent) +{ + auto ProgressDlgItems = MakeDialogItems( + { + { DI_TEXT, {{ 0, 0 }, { 0, 0 }}, DIF_HIDDEN, {}, }, + { DI_DOUBLEBOX, {{ 3, 1 }, { DlgW - 4, DlgH - 2 }}, DIF_NONE, Title, }, + { DI_TEXT, {{ 5, 2 }, { DlgW - 6, 2 }}, DIF_NONE, Msg }, + { DI_TEXT, {{ 5, 3 }, { DlgW - 6, 3 }}, DIF_NONE, make_progressbar(DlgW - 10, Percent, true, true) }, + }); + + m_Dialog = Dialog::create(ProgressDlgItems, [](Dialog* const Dlg, intptr_t const Msg, intptr_t const Param1, void* const Param2) + { + if (Msg == DN_RESIZECONSOLE) + { + COORD Position{ -1, -1 }; + Dlg->SendMessage(DM_MOVEDIALOG, 1, &Position); + } + + return Dlg->DefProc(Msg, Param1, Param2); + }); + + m_Dialog->SetPosition({ -1, -1, DlgW, DlgH }); + m_Dialog->SetCanLoseFocus(true); + m_Dialog->Process(); +} + +single_progress::~single_progress() +{ + if (m_Dialog) + m_Dialog->CloseDialog(); +} + +void single_progress::update(string_view const Msg) const +{ + m_Dialog->SendMessage(DM_SETTEXTPTR, progress_items::pr_message, UNSAFE_CSTR(null_terminated(Msg))); +} + +void single_progress::update(size_t const Percent) const +{ + m_Dialog->SendMessage(DM_SETTEXTPTR, progress_items::pr_progress, UNSAFE_CSTR(make_progressbar(DlgW - 10, Percent, true, true))); + + const auto Title = reinterpret_cast(m_Dialog->SendMessage(DM_GETCONSTTEXTPTR, pr_doublebox, {})); + m_Dialog->SendMessage(DM_SETTEXTPTR, progress_items::pr_console_title, UNSAFE_CSTR(concat(L'{', str(Percent), L"%} "sv, Title))); +} diff --git a/far/stddlg.hpp b/far/stddlg.hpp index 2e188bb252..963a903c55 100644 --- a/far/stddlg.hpp +++ b/far/stddlg.hpp @@ -36,6 +36,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // Internal: +#include "windowsfwd.hpp" // Platform: @@ -190,4 +191,18 @@ bool GoToRowCol(goto_coord& Row, goto_coord& Col, bool& Hex, string_view HelpTop bool RetryAbort(std::vector&& Messages); +class single_progress +{ +public: + single_progress(string_view Title, string_view Msg, size_t Percent); + ~single_progress(); + + void update(string_view Msg) const; + void update(size_t Percent) const; + +private: + dialog_ptr m_Dialog; +}; + + #endif // STDDLG_HPP_D7E3481D_D478_4F57_8C20_7E0A21FAE788 diff --git a/far/treelist.cpp b/far/treelist.cpp index 331de17f61..c8b934ed9d 100644 --- a/far/treelist.cpp +++ b/far/treelist.cpp @@ -813,7 +813,7 @@ bool TreeList::ReadTree() m_ListData.emplace_back(m_Root); - auto AscAbort = false; + auto Aborted = false; TreeStartTime = std::chrono::steady_clock::now(); SCOPED_ACTION(RefreshWindowManager)(ScrX, ScrY); ScTree.SetFindPath(m_Root, L"*"sv); @@ -825,13 +825,11 @@ bool TreeList::ReadTree() { MsgReadTree(m_ListData.size()); - if (CheckForEscSilent()) - { - // BUGBUG, Dialog calls Commit, TreeList redraws and crashes. - AscAbort=ConfirmAbortOp(); - } + // BUGBUG, Dialog calls Commit, TreeList redraws and crashes. + if (CheckForEscAndConfirmAbort()) + Aborted = true; - if (AscAbort) + if (Aborted) break; if (!(fdata.Attributes & FILE_ATTRIBUTE_DIRECTORY)) @@ -840,7 +838,7 @@ bool TreeList::ReadTree() m_ListData.emplace_back(strFullName); } - if (AscAbort && m_ModalMode) + if (Aborted && m_ModalMode) { m_ListData.clear(); RestoreState(); @@ -852,7 +850,7 @@ bool TreeList::ReadTree() if (!FillLastData()) return false; - if (!AscAbort) + if (!Aborted) SaveTreeFile(); m_CurFile = PrevCurFile; @@ -1873,7 +1871,6 @@ void TreeList::ReadSubTree(string_view const Path) const auto strDirName = ConvertNameToFull(Path); AddTreeName(strDirName); - auto AscAbort = false; ScTree.SetFindPath(strDirName, L"*"sv); LastScrX = ScrX; LastScrY = ScrY; @@ -1887,12 +1884,7 @@ void TreeList::ReadSubTree(string_view const Path) { MsgReadTree(Count + 1); - if (CheckForEscSilent()) - { - AscAbort=ConfirmAbortOp(); - } - - if (AscAbort) + if (CheckForEscAndConfirmAbort()) break; AddTreeName(strFullName); diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 7c2175db35..4ad949fb79 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -5863 +5864 diff --git a/far/viewer.cpp b/far/viewer.cpp index 228162fe30..70483a8ab7 100644 --- a/far/viewer.cpp +++ b/far/viewer.cpp @@ -3481,13 +3481,10 @@ void Viewer::Search(int Next,const Manager::Key* FirstChar) if (TimeCheck) { - if (CheckForEscSilent()) + if (CheckForEscAndConfirmAbort()) { - if (ConfirmAbortOp()) - { - Redraw(); - return; - } + Redraw(); + return; } int percent = -1;