From 0e26210736a15b720326f55689e02aaaf5d3275c Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Sat, 21 May 2016 17:35:38 +0000 Subject: [PATCH] based on #3244 - show clock in accordance with system locale --- far/changelog | 6 +++++- far/cmdline.cpp | 4 +--- far/common/smart_ptr.hpp | 2 +- far/common/zip_view.hpp | 2 +- far/dialog.cpp | 2 +- far/editor.cpp | 2 +- far/execute.cpp | 9 ++++++--- far/fileedit.cpp | 21 ++++++++++++++------- far/filelist.cpp | 8 ++++---- far/fileview.cpp | 5 ++--- far/global.cpp | 1 - far/global.hpp | 2 +- far/interf.cpp | 29 +++++------------------------ far/interf.hpp | 2 +- far/keyboard.cpp | 6 +++--- far/locale.cpp | 12 ++++++++++++ far/locale.hpp | 1 + far/manager.cpp | 2 +- far/scrbuf.cpp | 4 ++-- far/setcolor.cpp | 2 +- far/vbuild.m4 | 2 +- far/viewer.cpp | 4 ++-- 22 files changed, 66 insertions(+), 62 deletions(-) diff --git a/far/changelog b/far/changelog index 07157c306d..4e6e55139a 100644 --- a/far/changelog +++ b/far/changelog @@ -1,4 +1,8 @@ -zg 21.05.2016 11:27:47 +0200 - build 4686 +drkns 21.05.2016 20:30:22 +0200 - build 4687 + +1. По мотивам #0003244 - отображаем часы в соответствии с региональными настройками ОС. + +zg 21.05.2016 11:27:47 +0200 - build 4686 1. с форума: резкое замедление работы UNDO/REDO в редакторе. diff --git a/far/cmdline.cpp b/far/cmdline.cpp index d927593449..45f4a4f304 100644 --- a/far/cmdline.cpp +++ b/far/cmdline.cpp @@ -883,7 +883,6 @@ class execution_context: noncopyable m_Activated(), m_Consolised() { - ++Global->ProcessShowClock; } void Activate() @@ -962,7 +961,6 @@ class execution_context: noncopyable Global->WindowManager->SubmergeWindow(Global->CtrlObject->Desktop); Global->WindowManager->ActivateWindow(m_CurrentWindow); Global->WindowManager->ResizeAllWindows(); - --Global->ProcessShowClock; } private: @@ -1038,7 +1036,7 @@ void CommandLine::ExecString(execute_info& Info) } } if (Global->Opt->Clock) - ShowTime(0); + ShowTime(); if (!Silent) { diff --git a/far/common/smart_ptr.hpp b/far/common/smart_ptr.hpp index 1242ffe125..e010e94bd9 100644 --- a/far/common/smart_ptr.hpp +++ b/far/common/smart_ptr.hpp @@ -40,7 +40,7 @@ class array_ptr: public conditional> TRIVIALLY_MOVABLE(array_ptr); array_ptr() : m_size() {} - array_ptr(size_t size, bool init = false) : m_array(init? new T[size]() : new T[size]), m_size(size) {} + array_ptr(size_t size, bool init = false) { reset(size, init); } void reset(size_t size, bool init = false) { m_array.reset(init? new T[size]() : new T[size]); m_size = size;} void reset() { m_array.reset(); m_size = 0; } diff --git a/far/common/zip_view.hpp b/far/common/zip_view.hpp index 34d0ad0d93..ba36162dee 100644 --- a/far/common/zip_view.hpp +++ b/far/common/zip_view.hpp @@ -68,7 +68,7 @@ namespace detail inline void check() {} template - void check(arg&& Arg, args&&... Args) + void check(arg&&, args&&... Args) { static_assert(std::is_lvalue_reference::value, "argument must be lvalue"); check(std::forward(Args)...); diff --git a/far/dialog.cpp b/far/dialog.cpp index 802dfcf5c5..e509bcdb18 100644 --- a/far/dialog.cpp +++ b/far/dialog.cpp @@ -410,7 +410,7 @@ Dialog::~Dialog() if (Global) { if (Global->Opt->Clock && Global->WindowManager->IsPanelsActive(true)) - ShowTime(0); + ShowTime(); if (!CheckDialogMode(DMODE_ISMENU)) Global->ScrBuf->Flush(); diff --git a/far/editor.cpp b/far/editor.cpp index e896d6048b..404c79b8a0 100644 --- a/far/editor.cpp +++ b/far/editor.cpp @@ -803,7 +803,7 @@ bool Editor::ProcessKeyInternal(const Manager::Key& Key, bool& Refresh) if (LocalKey()==KEY_IDLE) { if (Global->Opt->ViewerEditorClock && HostFileEditor && HostFileEditor->IsFullScreen() && Global->Opt->EdOpt.ShowTitleBar) - ShowTime(FALSE); + ShowTime(); return TRUE; } diff --git a/far/execute.cpp b/far/execute.cpp index e68f0203ce..b14e7d256a 100644 --- a/far/execute.cpp +++ b/far/execute.cpp @@ -746,13 +746,18 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio } } + if (Info.WaitMode == Info.wait_finish) + { + // It's better to show console rather than non-responding panels + Silent = false; + } + bool Visible=false; DWORD CursorSize=0; SMALL_RECT ConsoleWindowRect; COORD ConsoleSize={}; int ConsoleCP = CP_OEMCP; int ConsoleOutputCP = CP_OEMCP; - int add_show_clock = 0; SCOPED_ACTION(ChangePriority)(THREAD_PRIORITY_NORMAL); @@ -761,7 +766,6 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio seInfo.lpDirectory=strCurDir.data(); seInfo.nShow = SW_SHOWNORMAL; - if(!Silent) { ConsoleActivator(); @@ -976,7 +980,6 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio Result = true; } - Global->ProcessShowClock -= add_show_clock; SetFarConsoleMode(TRUE); /* Принудительная установка курсора, т.к. SetCursorType иногда не спасает diff --git a/far/fileedit.cpp b/far/fileedit.cpp index 43fcef16cd..2f07a63560 100644 --- a/far/fileedit.cpp +++ b/far/fileedit.cpp @@ -908,8 +908,6 @@ int FileEditor::ReProcessKey(const Manager::Key& Key,int CalledFromControl) strTitle.empty() ? nullptr : strTitle.data(), delete_on_close, shared_from_this()); } - - ShowTime(2); } return TRUE; @@ -2302,9 +2300,15 @@ void FileEditor::ShowStatus() const GotoXY(m_X1,m_Y1); //?? string strLineStr; string strLocalTitle = GetTitle(); - int NameLength = (Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN)) ? 15:21; + int NameLength = 21; + if (m_X2 > 80) - NameLength += (m_X2-80); + NameLength += (m_X2 - 80); + + if (Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN)) + NameLength -= static_cast(Global->CurrentTime.size() + 1); + + NameLength = std::max(0, NameLength); if (!strPluginTitle.empty() || !strTitle.empty()) TruncPathStr(strLocalTitle, (ObjWidth()m_it_CurLine->GetCurPos()+1<Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN))?5:0); + int StatusWidth = ObjWidth(); + if (Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN)) + StatusWidth -= static_cast(Global->CurrentTime.size()); if (StatusWidth<0) StatusWidth=0; @@ -2347,7 +2353,8 @@ void FileEditor::ShowStatus() const if (CurPos < Str.size()) { - GotoXY(m_X2-((Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN)) ? 14:8)-(!m_editor->EdOpt.CharCodeBase?3:0),m_Y1); + const int ClockSize = Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN)? static_cast(Global->CurrentTime.size() + 1) : 0; + GotoXY(m_X2 - 14 - ClockSize - (!m_editor->EdOpt.CharCodeBase?3:0), m_Y1); SetColor(COL_EDITORSTATUS); /* $ 27.02.2001 SVS Показываем в зависимости от базы */ @@ -2393,7 +2400,7 @@ void FileEditor::ShowStatus() const } if (Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN)) - ShowTime(FALSE); + ShowTime(); } /* $ 13.02.2001 diff --git a/far/filelist.cpp b/far/filelist.cpp index ab94645e49..88312a42fb 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -7659,8 +7659,8 @@ void FileList::ShowFileList(int Fast) strTitle = GetTitle(); int TitleX2 = m_X2; - if (Global->Opt->Clock && !Global->Opt->ShowMenuBar && m_X1 + strTitle.size() + 2 >= static_cast(ScrX-5)) - TitleX2 = std::min(ScrX-5,(int)m_X2); + if (Global->Opt->Clock && !Global->Opt->ShowMenuBar && m_X1 + strTitle.size() + 2 >= ScrX - Global->CurrentTime.size()) + TitleX2 = std::min(static_cast(ScrX - Global->CurrentTime.size()),(int)m_X2); int MaxSize=TitleX2-m_X1-1; int XShift = 0; @@ -7681,8 +7681,8 @@ void FileList::ShowFileList(int Fast) const int TitleSize = static_cast(strTitle.size()); int TitleX = m_X1 + 1 + XShift + (TitleX2 - m_X1 - XShift - TitleSize) / 2; - if (Global->Opt->Clock && !Global->Opt->ShowMenuBar && TitleX + TitleSize > ScrX - 5) - TitleX = ScrX - 5 - TitleSize; + if (Global->Opt->Clock && !Global->Opt->ShowMenuBar && TitleX + TitleSize > ScrX - static_cast(Global->CurrentTime.size())) + TitleX = ScrX - static_cast(Global->CurrentTime.size()) - TitleSize; SetColor(IsFocused()? COL_PANELSELECTEDTITLE:COL_PANELTITLE); GotoXY(TitleX, m_Y1); diff --git a/far/fileview.cpp b/far/fileview.cpp index 8c402f3868..ec31b7cf71 100644 --- a/far/fileview.cpp +++ b/far/fileview.cpp @@ -382,7 +382,6 @@ int FileViewer::ProcessKey(const Manager::Key& Key) SetTempViewName(L""); SetExitCode(0); } - ShowTime(2); } return TRUE; @@ -514,7 +513,7 @@ void FileViewer::ShowStatus() const int NameLength = ScrX+1 - 40; if (Global->Opt->ViewerEditorClock && IsFullScreen()) - NameLength -= 3+5; + NameLength -= 3 + static_cast(Global->CurrentTime.size()); NameLength = std::max(NameLength, 20); @@ -536,7 +535,7 @@ void FileViewer::ShowStatus() const Global->FS << fmt::LeftAlign()<Width+(m_View->ViOpt.ShowScrollbar?1:0))<Opt->ViewerEditorClock && IsFullScreen()) - ShowTime(FALSE); + ShowTime(); } void FileViewer::OnChangeFocus(bool focus) diff --git a/far/global.cpp b/far/global.cpp index 065f9e2d0a..cb4831d2b4 100644 --- a/far/global.cpp +++ b/far/global.cpp @@ -84,7 +84,6 @@ global::global(): AllowCancelExit=TRUE; DisablePluginsOutput=FALSE; ProcessException=FALSE; - ProcessShowClock=FALSE; HelpFileMask=L"*.hlf"; #if defined(SYSLOG) StartSysLog=0; diff --git a/far/global.hpp b/far/global.hpp index b227332cac..33d73937f2 100644 --- a/far/global.hpp +++ b/far/global.hpp @@ -73,7 +73,7 @@ class global: noncopyable BOOL IsProcessAssignMacroKey; size_t PluginPanelsCount; BOOL ProcessException; - BOOL ProcessShowClock; + string CurrentTime; const wchar_t *HelpFileMask; bool OnlyEditorViewerUsed; // -e or -v #if defined(SYSLOG) diff --git a/far/interf.cpp b/far/interf.cpp index bc6d066ea5..1b8c43223e 100644 --- a/far/interf.cpp +++ b/far/interf.cpp @@ -53,6 +53,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "plugins.hpp" #include "language.hpp" #include "TaskBar.hpp" +#include "locale.hpp" consoleicons& ConsoleIcons() { @@ -549,40 +550,20 @@ void GetVideoMode(COORD& Size) _OT(ViewConsoleInfo()); } -void ShowTime(int ShowAlways) +void ShowTime() { - static SYSTEMTIME lasttm={}; - - if (ShowAlways==2) - { - ClearStruct(lasttm); - return; - } - if (Global->ScreenSaverActive) return; - SYSTEMTIME tm; - matrix colon(1, 1); - GetLocalTime(&tm); - GetText(ScrX - 4 + 2, 0, ScrX - 4 + 2, 0, colon); - if (!ShowAlways && lasttm.wMinute == tm.wMinute && lasttm.wHour == tm.wHour && colon[0][0].Char == L':') - return; - - Global->ProcessShowClock++; - - lasttm=tm; - string strClockText = str_printf(L"%02d:%02d",tm.wHour,tm.wMinute); - GotoXY(ScrX-4,0); + Global->CurrentTime = locale::GetTimeFormat(); if (const auto CurrentWindow = Global->WindowManager->GetCurrentWindow()) { + GotoXY(static_cast(ScrX + 1 - Global->CurrentTime.size()), 0); int ModType=CurrentWindow->GetType(); SetColor(ModType==windowtype_viewer?COL_VIEWERCLOCK:(ModType==windowtype_editor?COL_EDITORCLOCK:COL_CLOCK)); - Text(strClockText); + Text(Global->CurrentTime); } - - Global->ProcessShowClock--; } void GotoXY(int X,int Y) diff --git a/far/interf.hpp b/far/interf.hpp index bd7860fae8..84c8d8e75d 100644 --- a/far/interf.hpp +++ b/far/interf.hpp @@ -109,7 +109,7 @@ enum BOX_DEF_SYMBOLS BS_COUNT }; -void ShowTime(int ShowAlways); +void ShowTime(); /*$ 14.02.2001 SKV Инитить ли палитру default значениями. diff --git a/far/keyboard.cpp b/far/keyboard.cpp index 2d645883d8..61c5e5d14d 100644 --- a/far/keyboard.cpp +++ b/far/keyboard.cpp @@ -638,7 +638,7 @@ static DWORD __GetInputRecord(INPUT_RECORD *rec,bool ExcludeMacro,bool ProcessMo Global->CtrlObject->Macro.GetArea()==MACROAREA_SEARCH)); if (EnableShowTime) - ShowTime(1); + ShowTime(); Global->ScrBuf->Flush(); @@ -711,7 +711,7 @@ static DWORD __GetInputRecord(INPUT_RECORD *rec,bool ExcludeMacro,bool ProcessMo clock_t CurTime=clock(); if (EnableShowTime) - ShowTime(0); + ShowTime(); if (Global->WaitInMainLoop) { @@ -863,7 +863,7 @@ static DWORD __GetInputRecord(INPUT_RECORD *rec,bool ExcludeMacro,bool ProcessMo Console().ReadInput(rec, 1, ReadCount); if (EnableShowTime) - ShowTime(1); + ShowTime(); bool SizeChanged=false; if(Global->Opt->WindowMode) diff --git a/far/locale.cpp b/far/locale.cpp index efeb701c34..6d3a2e268c 100644 --- a/far/locale.cpp +++ b/far/locale.cpp @@ -86,3 +86,15 @@ string locale::GetValue(LCID lcid, LCTYPE id) } return Result; } + +string locale::GetTimeFormat() +{ + wchar_t TimeBuffer[MAX_PATH]{}; + if (const auto TimeBufferSize = ::GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, nullptr, nullptr, TimeBuffer, static_cast(std::size(TimeBuffer)))) + { + return string(TimeBuffer, TimeBufferSize - 1); + } + + // TODO: log + return {}; +} diff --git a/far/locale.hpp b/far/locale.hpp index f2f49471b1..74883d8acd 100644 --- a/far/locale.hpp +++ b/far/locale.hpp @@ -41,6 +41,7 @@ namespace locale wchar_t GetDecimalSeparator(); wchar_t GetThousandSeparator(); string GetValue(LCID lcid, LCTYPE id); + string GetTimeFormat(); } #endif // LOCALE_HPP_C358EF79_F894_425E_B689_C4F4131DBE76 diff --git a/far/manager.cpp b/far/manager.cpp index c43a686b07..5b3e1a3ac4 100644 --- a/far/manager.cpp +++ b/far/manager.cpp @@ -1098,7 +1098,7 @@ void Manager::RefreshCommit(window_ptr_ref Param) || (Global->WaitInMainLoop && Global->Opt->Clock) ) - ShowTime(1); + ShowTime(); }); }; diff --git a/far/scrbuf.cpp b/far/scrbuf.cpp index 4223e0b5f9..b334b61ba5 100644 --- a/far/scrbuf.cpp +++ b/far/scrbuf.cpp @@ -357,9 +357,9 @@ void ScreenBuf::Flush(flush_type FlushType) SetMacroChar(Where, L'A', B_LIGHTRED | F_WHITE); } - if (Global->WaitInMainLoop && Global->Opt->Clock && !Global->ProcessShowClock) + if (Global->WaitInMainLoop && Global->Opt->Clock) { - ShowTime(FALSE); + ShowTime(); } std::vectorWriteList; diff --git a/far/setcolor.cpp b/far/setcolor.cpp index c34f6d410c..5736b78b80 100644 --- a/far/setcolor.cpp +++ b/far/setcolor.cpp @@ -67,7 +67,7 @@ void GetColor(PaletteColors PaletteIndex) Global->WindowManager->PluginCommit(); // коммитим. if (Global->Opt->Clock) - ShowTime(1); + ShowTime(); Global->ScrBuf->Unlock(); // разрешаем прорисовку Global->WindowManager->PluginCommit(); // коммитим. diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 2c412e02fa..d197535db3 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,4686)m4_dnl +m4_define(BUILD,4687)m4_dnl diff --git a/far/viewer.cpp b/far/viewer.cpp index acc0df214a..937e0ee9f9 100644 --- a/far/viewer.cpp +++ b/far/viewer.cpp @@ -1599,7 +1599,7 @@ int Viewer::process_key(const Manager::Key& Key) case KEY_IDLE: { if (Global->Opt->ViewerEditorClock && HostFileViewer && HostFileViewer->IsFullScreen() && Global->Opt->ViOpt.ShowTitleBar) - ShowTime(FALSE); + ShowTime(); if (ViewFile) { @@ -2135,7 +2135,7 @@ int Viewer::ProcessMouse(const MOUSE_EVENT_RECORD *MouseEvent) if (IntKeyState.MouseY != m_Y1-1) return TRUE; - int NameLen = std::max(20, ObjWidth()-40-(Global->Opt->ViewerEditorClock && HostFileViewer && HostFileViewer->IsFullScreen() ? 3+5 : 0)); + int NameLen = std::max(20, ObjWidth()-40-(Global->Opt->ViewerEditorClock && HostFileViewer && HostFileViewer->IsFullScreen()? 3 + static_cast(Global->CurrentTime.size()) : 0)); int cp_len = static_cast(std::to_wstring(m_Codepage).size()); // ViewMode CopdePage Goto static const int keys[] = {KEY_SHIFTF4, KEY_SHIFTF8, KEY_ALTF8 };