diff --git a/far/changelog b/far/changelog index 40ff48c491..19b3705ee6 100644 --- a/far/changelog +++ b/far/changelog @@ -1,7 +1,12 @@ +-------------------------------------------------------------------------------- +drkns 19.07.2021 22:08:39 +0100 - build 5850 + +1. Experimental: removed fake dialogs and preredraw magic from editor load/save/find progress bars. + -------------------------------------------------------------------------------- drkns 13.07.2021 20:22:19 +0100 - build 5849 -4. Preserve the locked state when reopening editor from history. +1. Preserve the locked state when reopening editor from history. -------------------------------------------------------------------------------- drkns 12.07.2021 20:53:26 +0100 - build 5848 diff --git a/far/editor.cpp b/far/editor.cpp index f5b0cdbd38..358e60023e 100644 --- a/far/editor.cpp +++ b/far/editor.cpp @@ -46,7 +46,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "dialog.hpp" #include "fileedit.hpp" #include "scrbuf.hpp" -#include "TPreRedrawFunc.hpp" #include "taskbar.hpp" #include "interf.hpp" #include "message.hpp" @@ -3403,7 +3402,6 @@ bool Editor::Search(bool Next) const auto FindAllList = VMenu2::create({}, {}); size_t AllRefLines{}; { - SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique()); SetCursorType(false, -1); Match = false; UserBreak = false; @@ -3461,6 +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); int StartLine = m_it_CurLine.Number(); SCOPED_ACTION(taskbar::indeterminate); SCOPED_ACTION(wakeful); @@ -3482,7 +3481,7 @@ bool Editor::Search(bool Next) SetCursorType(false, -1); const auto Total = FindAllReferences? Lines.size() : ReverseSearch? StartLine : Lines.size() - StartLine; const auto Current = abs(CurPtr.Number() - StartLine); - EditorShowMsg(msg(lng::MEditSearchTitle), msg(lng::MEditSearchingFor), QuotedStr, Total > 0? Current * 100 / Total : 100); + Progress.update(Total > 0? Current * 100 / Total : 100); taskbar::set_value(Current,Total); } @@ -6556,48 +6555,6 @@ void Editor::SetSavePosMode(int SavePos, int SaveShortPos) EdOpt.SaveShortPos = (0 != SaveShortPos); } -static void EditorShowMsgImpl(string_view const Title, const string& Msg, const string& Name, size_t Percent) -{ - const auto strMsg = concat(Msg, L' ', Name); - const size_t Length = std::max(std::min(ScrX - 1 - 10, static_cast(strMsg.size())), 40); - auto strProgress = make_progressbar(Length, Percent, true, true); - - std::vector MsgItems{ strMsg }; - if (!strProgress.empty()) - MsgItems.emplace_back(strProgress); - - Message(MSG_LEFTALIGN, - Title, - std::move(MsgItems), - {}); -} - -void Editor::EditorShowMsg(string_view const Title, const string& Msg, const string& Name, size_t Percent) -{ - EditorShowMsgImpl(Title, Msg, Name, Percent); - - TPreRedrawFunc::instance()([&](EditorPreRedrawItem& Item) - { - Item.Title = Title; - Item.Msg = Msg; - Item.Name = Name; - Item.Percent = Percent; - }); -} - -void Editor::PR_EditorShowMsg() -{ - TPreRedrawFunc::instance()([](const EditorPreRedrawItem& Item) - { - EditorShowMsg(Item.Title, Item.Msg, Item.Name, Item.Percent); - }); -} - -Editor::EditorPreRedrawItem::EditorPreRedrawItem(): - PreRedrawItem(PR_EditorShowMsg) -{ -} - Editor::numbered_iterator Editor::InsertString(const string_view Str, const numbered_iterator& Where) { const auto Empty = Lines.empty(); @@ -6963,3 +6920,59 @@ 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 b7f1cb2575..c7e3f8af16 100644 --- a/far/editor.hpp +++ b/far/editor.hpp @@ -307,7 +307,6 @@ class Editor: public SimpleScreenObject bool IsLastLine(const iterator& Line) const; static bool InitSessionBookmarksForPlugin(EditorBookmarks *Param, size_t Count, size_t& Size); - static void EditorShowMsg(string_view Title, const string& Msg, const string& Name, size_t Percent); bool IsAnySelection() const { assert(Lines.end() == m_it_AnyBlockStart || m_BlockType != BTYPE_NONE); return Lines.end() != m_it_AnyBlockStart; } bool IsStreamSelection() const { return IsAnySelection() && m_BlockType == BTYPE_STREAM; } @@ -397,15 +396,6 @@ class Editor: public SimpleScreenObject int CursorPos{}; int m_InEERedraw{}; bool m_GotoHex{}; - - struct EditorPreRedrawItem : public PreRedrawItem - { - EditorPreRedrawItem(); - string Title; - string Msg; - string Name; - size_t Percent{}; - }; }; class EditorContainer @@ -415,4 +405,16 @@ 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 29add55886..43d4d53a50 100644 --- a/far/farlang.templ.m4 +++ b/far/farlang.templ.m4 @@ -6694,18 +6694,18 @@ MEditCannotOpen "Negaliu atidaryti failo" MEditReading -"Чтение файла" -"Reading the file" -"Načítám soubor" -"Lesen der Datei" -"Fájl olvasása" -"Czytam plik" -"Leyendo el archivo" -"Načítavam súbor" -"Lettura Del File" -"Читання файлу" -"Чытанне файла" -"Skaitau failą" +"Чтение файла {0}" +"Reading the file {0}" +"Načítám soubor {0}" +"Lesen der Datei {0}" +"Fájl olvasása {0}" +"Czytam plik {0}" +"Leyendo el archivo {0}" +"Načítavam súbor {0}" +"Lettura Del File {0}" +"Читання файлу {0}" +"Чытанне файла {0}" +"Skaitau failą {0}" MEditAskSave "Файл был изменён. Сохранить?" @@ -6793,18 +6793,18 @@ MEditOvr "Ar norite užrašyti ant jo?" MEditSaving -"Сохранение файла" -"Saving the file" -"Ukládám soubor" -"Speichere die Datei" -"Fájl mentése" -"Zapisuję plik" -"Guardando el archivo" -"Ukladám súbor" -"Salvataggio In Corso" -"Збереження файлу" -"Захаванне файла" -"Išsaugau failą" +"Сохранение файла {0}" +"Saving the file {0}" +"Ukládám soubor {0}" +"Speichere die Datei {0}" +"Fájl mentése {0}" +"Zapisuję plik {0}" +"Guardando el archivo {0}" +"Ukladám súbor {0}" +"Salvataggio In Corso {0}" +"Збереження файлу {0}" +"Захаванне файла {0}" +"Išsaugau failą {0}" MEditStatusLine l:// Up to 3 characters @@ -7151,18 +7151,18 @@ MEditReplaceReplace MEditSearchingFor l: -"Искать" -"Searching for" -"Vyhledávám" -"Suche nach" -"Keresett szöveg:" -"Szukam" -"Buscando por" -"Vyhľadávam" -"Ricerca Di" -"Шукати" -"Шукаць" -"Ieškau" +"Искать {0}" +"Searching for {0}" +"Vyhledávám {0}" +"Suche nach {0}" +"Keresett szöveg {0}" +"Szukam {0}" +"Buscando por {0}" +"Vyhľadávam {0}" +"Ricerca Di {0}" +"Шукати {0}" +"Шукаць {0}" +"Ieškau {0}" MEditSearchStatistics "Вхождений: {0}, строк: {1}" diff --git a/far/fileedit.cpp b/far/fileedit.cpp index b397fed0bc..2cc57cb59a 100644 --- a/far/fileedit.cpp +++ b/far/fileedit.cpp @@ -1526,7 +1526,6 @@ bool FileEditor::LoadFile(const string& Name,int &UserBreak, error_state_ex& Err try { // TODO: indentation - SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique()); SCOPED_ACTION(taskbar::indeterminate); SCOPED_ACTION(wakeful); @@ -1641,6 +1640,8 @@ 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); + const time_check TimeCheck; os::fs::filebuf StreamBuffer(EditFile, std::ios::in); @@ -1687,7 +1688,8 @@ bool FileEditor::LoadFile(const string& Name,int &UserBreak, error_state_ex& Err Percent = FileSize? std::min(CurPos * 100 / FileSize, 100ull) : 100; } - Editor::EditorShowMsg(msg(lng::MEditTitle), msg(lng::MEditReading), Name, Percent); + + Progress.update(Percent); } if (m_editor->GlobalEOL == eol::none && Str.Eol != eol::none) @@ -2034,11 +2036,12 @@ int FileEditor::SaveFile(const string& Name,int Ask, bool bSaveAs, error_state_e m_editor->m_Flags.Clear(Editor::FEDITOR_UNDOSAVEPOSLOST); SetCursorType(false, 0); - SCOPED_ACTION(TPreRedrawFuncGuard)(std::make_unique()); if (!bSaveAs) AddSignature = m_bAddSignature; + editor_progress const Progress(msg(lng::MEditTitle), format(msg(lng::MEditSaving), Name), 0); + const time_check TimeCheck; // We've already validated the codepage above @@ -2052,7 +2055,7 @@ int FileEditor::SaveFile(const string& Name,int Ask, bool bSaveAs, error_state_e if (TimeCheck) { - Editor::EditorShowMsg(msg(lng::MEditTitle), msg(lng::MEditSaving), Name, LineNumber * 100 / m_editor->Lines.size()); + Progress.update(LineNumber * 100 / m_editor->Lines.size()); } const auto& SaveStr = Line.GetString(); diff --git a/far/history.cpp b/far/history.cpp index 363d3a235f..ac970d9175 100644 --- a/far/history.cpp +++ b/far/history.cpp @@ -354,6 +354,8 @@ history_return_type History::ProcessMenu(string& strStr, UUID* const Uuid, strin SetUpMenuPos=false; } + HistoryMenu.Redraw(); + MenuExitCode=HistoryMenu.Run([&](const Manager::Key& RawKey) { const auto Key=RawKey(); diff --git a/far/palette.hpp b/far/palette.hpp index 6ee0d0ad5f..13b30d719d 100644 --- a/far/palette.hpp +++ b/far/palette.hpp @@ -57,14 +57,15 @@ enum F_MAGENTA = FOREGROUND_BLUE | FOREGROUND_RED, F_BROWN = FOREGROUND_GREEN | FOREGROUND_RED, F_LIGHTGRAY = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED, - F_DARKGRAY = FOREGROUND_INTENSITY, - F_LIGHTBLUE = FOREGROUND_BLUE | FOREGROUND_INTENSITY, - F_LIGHTGREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY, - F_LIGHTCYAN = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY, - F_LIGHTRED = FOREGROUND_RED | FOREGROUND_INTENSITY, - F_LIGHTMAGENTA = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY, - F_YELLOW = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY, - F_WHITE = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY, + F_DARKGRAY = FOREGROUND_INTENSITY | F_BLACK, + F_LIGHTBLUE = FOREGROUND_INTENSITY | F_BLUE, + F_LIGHTGREEN = FOREGROUND_INTENSITY | F_GREEN, + F_LIGHTCYAN = FOREGROUND_INTENSITY | F_CYAN, + F_LIGHTRED = FOREGROUND_INTENSITY | F_RED, + F_LIGHTMAGENTA = FOREGROUND_INTENSITY | F_MAGENTA, + F_YELLOW = FOREGROUND_INTENSITY | F_BROWN, + F_WHITE = FOREGROUND_INTENSITY | F_LIGHTGRAY, + B_BLACK = 0, B_BLUE = BACKGROUND_BLUE, B_GREEN = BACKGROUND_GREEN, @@ -73,14 +74,15 @@ enum B_MAGENTA = BACKGROUND_BLUE | BACKGROUND_RED, B_BROWN = BACKGROUND_GREEN | BACKGROUND_RED, B_LIGHTGRAY = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED, - B_DARKGRAY = BACKGROUND_INTENSITY, - B_LIGHTBLUE = BACKGROUND_BLUE | BACKGROUND_INTENSITY, - B_LIGHTGREEN = BACKGROUND_GREEN | BACKGROUND_INTENSITY, - B_LIGHTCYAN = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY, - B_LIGHTRED = BACKGROUND_RED | BACKGROUND_INTENSITY, - B_LIGHTMAGENTA = BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY, - B_YELLOW = BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY, - B_WHITE = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY, + B_DARKGRAY = BACKGROUND_INTENSITY | B_BLACK, + B_LIGHTBLUE = BACKGROUND_INTENSITY | B_BLUE, + B_LIGHTGREEN = BACKGROUND_INTENSITY | B_GREEN, + B_LIGHTCYAN = BACKGROUND_INTENSITY | B_CYAN, + B_LIGHTRED = BACKGROUND_INTENSITY | B_RED, + B_LIGHTMAGENTA = BACKGROUND_INTENSITY | B_MAGENTA, + B_YELLOW = BACKGROUND_INTENSITY | B_BROWN, + B_WHITE = BACKGROUND_INTENSITY | B_LIGHTGRAY, + F_MASK = F_WHITE, B_MASK = B_WHITE }; diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 171b5e5c59..eaadb4de9b 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -5849 +5850