Skip to content

Commit

Permalink
based on #3244 - show clock in accordance with system locale
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed May 21, 2016
1 parent e9fb2c6 commit 0e26210
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 62 deletions.
6 changes: 5 additions & 1 deletion 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 в редакторе.

Expand Down
4 changes: 1 addition & 3 deletions far/cmdline.cpp
Expand Up @@ -883,7 +883,6 @@ class execution_context: noncopyable
m_Activated(),
m_Consolised()
{
++Global->ProcessShowClock;
}

void Activate()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1038,7 +1036,7 @@ void CommandLine::ExecString(execute_info& Info)
}
}
if (Global->Opt->Clock)
ShowTime(0);
ShowTime();

if (!Silent)
{
Expand Down
2 changes: 1 addition & 1 deletion far/common/smart_ptr.hpp
Expand Up @@ -40,7 +40,7 @@ class array_ptr: public conditional<array_ptr<T>>
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; }
Expand Down
2 changes: 1 addition & 1 deletion far/common/zip_view.hpp
Expand Up @@ -68,7 +68,7 @@ namespace detail
inline void check() {}

template<typename arg, typename... args>
void check(arg&& Arg, args&&... Args)
void check(arg&&, args&&... Args)
{
static_assert(std::is_lvalue_reference<arg>::value, "argument must be lvalue");
check(std::forward<args>(Args)...);
Expand Down
2 changes: 1 addition & 1 deletion far/dialog.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion far/editor.cpp
Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions far/execute.cpp
Expand Up @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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 иногда не спасает
Expand Down
21 changes: 14 additions & 7 deletions far/fileedit.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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<int>(Global->CurrentTime.size() + 1);

NameLength = std::max(0, NameLength);

if (!strPluginTitle.empty() || !strTitle.empty())
TruncPathStr(strLocalTitle, (ObjWidth()<NameLength?ObjWidth():NameLength));
Expand Down Expand Up @@ -2335,7 +2339,9 @@ void FileEditor::ShowStatus() const
fmt::LeftAlign()<<fmt::MinWidth(4)<<m_editor->m_it_CurLine->GetCurPos()+1<<L' '<<
fmt::MinWidth(3)<<strAttr;

int StatusWidth=ObjWidth() - ((Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN))?5:0);
int StatusWidth = ObjWidth();
if (Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN))
StatusWidth -= static_cast<int>(Global->CurrentTime.size());

if (StatusWidth<0)
StatusWidth=0;
Expand All @@ -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<int>(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
Показываем в зависимости от базы */
Expand Down Expand Up @@ -2393,7 +2400,7 @@ void FileEditor::ShowStatus() const
}

if (Global->Opt->ViewerEditorClock && m_Flags.Check(FFILEEDIT_FULLSCREEN))
ShowTime(FALSE);
ShowTime();
}

/* $ 13.02.2001
Expand Down
8 changes: 4 additions & 4 deletions far/filelist.cpp
Expand Up @@ -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<size_t>(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<int>(ScrX - Global->CurrentTime.size()),(int)m_X2);

int MaxSize=TitleX2-m_X1-1;
int XShift = 0;
Expand All @@ -7681,8 +7681,8 @@ void FileList::ShowFileList(int Fast)
const int TitleSize = static_cast<int>(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<int>(Global->CurrentTime.size()))
TitleX = ScrX - static_cast<int>(Global->CurrentTime.size()) - TitleSize;

SetColor(IsFocused()? COL_PANELSELECTEDTITLE:COL_PANELTITLE);
GotoXY(TitleX, m_Y1);
Expand Down
5 changes: 2 additions & 3 deletions far/fileview.cpp
Expand Up @@ -382,7 +382,6 @@ int FileViewer::ProcessKey(const Manager::Key& Key)
SetTempViewName(L"");
SetExitCode(0);
}
ShowTime(2);
}

return TRUE;
Expand Down Expand Up @@ -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<int>(Global->CurrentTime.size());

NameLength = std::max(NameLength, 20);

Expand All @@ -536,7 +535,7 @@ void FileViewer::ShowStatus() const
Global->FS << fmt::LeftAlign()<<fmt::ExactWidth(m_View->Width+(m_View->ViOpt.ShowScrollbar?1:0))<<strStatus;

if (Global->Opt->ViewerEditorClock && IsFullScreen())
ShowTime(FALSE);
ShowTime();
}

void FileViewer::OnChangeFocus(bool focus)
Expand Down
1 change: 0 additions & 1 deletion far/global.cpp
Expand Up @@ -84,7 +84,6 @@ global::global():
AllowCancelExit=TRUE;
DisablePluginsOutput=FALSE;
ProcessException=FALSE;
ProcessShowClock=FALSE;
HelpFileMask=L"*.hlf";
#if defined(SYSLOG)
StartSysLog=0;
Expand Down
2 changes: 1 addition & 1 deletion far/global.hpp
Expand Up @@ -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)
Expand Down
29 changes: 5 additions & 24 deletions far/interf.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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<FAR_CHAR_INFO> 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<int>(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)
Expand Down
2 changes: 1 addition & 1 deletion far/interf.hpp
Expand Up @@ -109,7 +109,7 @@ enum BOX_DEF_SYMBOLS
BS_COUNT
};

void ShowTime(int ShowAlways);
void ShowTime();

/*$ 14.02.2001 SKV
Инитить ли палитру default значениями.
Expand Down
6 changes: 3 additions & 3 deletions far/keyboard.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions far/locale.cpp
Expand Up @@ -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<int>(std::size(TimeBuffer))))
{
return string(TimeBuffer, TimeBufferSize - 1);
}

// TODO: log
return {};
}
1 change: 1 addition & 0 deletions far/locale.hpp
Expand Up @@ -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
2 changes: 1 addition & 1 deletion far/manager.cpp
Expand Up @@ -1098,7 +1098,7 @@ void Manager::RefreshCommit(window_ptr_ref Param)
||
(Global->WaitInMainLoop && Global->Opt->Clock)
)
ShowTime(1);
ShowTime();
});
};

Expand Down
4 changes: 2 additions & 2 deletions far/scrbuf.cpp
Expand Up @@ -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::vector<SMALL_RECT>WriteList;
Expand Down
2 changes: 1 addition & 1 deletion far/setcolor.cpp
Expand Up @@ -67,7 +67,7 @@ void GetColor(PaletteColors PaletteIndex)
Global->WindowManager->PluginCommit(); // коммитим.

if (Global->Opt->Clock)
ShowTime(1);
ShowTime();

Global->ScrBuf->Unlock(); // разрешаем прорисовку
Global->WindowManager->PluginCommit(); // коммитим.
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4686)m4_dnl
m4_define(BUILD,4687)m4_dnl
4 changes: 2 additions & 2 deletions far/viewer.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<int>(Global->CurrentTime.size()) : 0));
int cp_len = static_cast<int>(std::to_wstring(m_Codepage).size());
// ViewMode CopdePage Goto
static const int keys[] = {KEY_SHIFTF4, KEY_SHIFTF8, KEY_ALTF8 };
Expand Down

0 comments on commit 0e26210

Please sign in to comment.