OSDN Git Service

Tidy up of relative times, strings into resource files.
authorColin Law <colin@clanlaw.org.uk>
Sat, 31 Jan 2009 20:37:16 +0000 (20:37 +0000)
committerFrank Li <lznuaa@gmail.com>
Sun, 1 Feb 2009 08:11:20 +0000 (16:11 +0800)
src/Resources/TortoiseGitBlame.rc
src/TortoiseGitBlame/Resource.h
src/TortoiseGitBlame/TortoiseGitBlameAppUtils.cpp
src/TortoiseGitBlame/TortoiseGitBlameAppUtils.h
src/TortoiseProc/AppUtils.cpp
src/TortoiseProc/AppUtils.h
src/TortoiseProc/GitLogListBase.cpp
src/TortoiseProc/GitLogListBase.h

index 4233647..3096c3d 100644 (file)
@@ -498,6 +498,38 @@ BEGIN
     IDS_GIT_LOG_TAB         "Git Log"\r
 END\r
 \r
+STRINGTABLE \r
+BEGIN\r
+    IDS_YEAR_AGO\r
+                            "%1!d! Year ago"\r
+    IDS_YEARS_AGO\r
+                            "%1!d! Years ago"\r
+    IDS_MONTH_AGO\r
+                            "%1!d! Month ago"\r
+    IDS_MONTHS_AGO\r
+                            "%1!d! Months ago"\r
+    IDS_WEEK_AGO\r
+                            "%1!d! Week ago"\r
+    IDS_WEEKS_AGO\r
+                            "%1!d! Weeks ago"\r
+    IDS_DAY_AGO\r
+                            "%1!d! Day ago"\r
+    IDS_DAYS_AGO\r
+                            "%1!d! Days ago"\r
+    IDS_HOUR_AGO\r
+                            "%1!d! Hour ago"\r
+    IDS_HOURS_AGO\r
+                            "%1!d! Hours ago"\r
+    IDS_MINUTE_AGO\r
+                            "%1!d! Minute ago"\r
+    IDS_MINUTES_AGO\r
+                            "%1!d! minutes ago"\r
+    IDS_SECOND_AGO\r
+                            "%1!d! Second ago"\r
+    IDS_SECONDS_AGO\r
+                            "%1!d! Seconds ago"\r
+END\r
+\r
 #endif    // English (U.S.) resources\r
 /////////////////////////////////////////////////////////////////////////////\r
 \r
index 7426100..ad394cc 100644 (file)
 #define IDD_GOTODLG                     221\r
 #define IDC_LINENUMBER                  222\r
 \r
+#define IDS_YEAR_AGO                    9605\r
+#define IDS_YEARS_AGO                   9606\r
+#define IDS_MONTH_AGO                   9607\r
+#define IDS_MONTHS_AGO                  9608\r
+#define IDS_WEEK_AGO                    9609\r
+#define IDS_WEEKS_AGO                   9610\r
+#define IDS_DAY_AGO                     9611\r
+#define IDS_DAYS_AGO                    9612\r
+#define IDS_HOUR_AGO                    9613\r
+#define IDS_HOURS_AGO                   9614\r
+#define IDS_MINUTE_AGO                  9615\r
+#define IDS_MINUTES_AGO                 9616\r
+#define IDS_SECOND_AGO                  9617\r
+#define IDS_SECONDS_AGO                 9618\r
 \r
 #define IDS_STATUS_PANE1                20122\r
 #define IDS_STATUS_PANE2                20123\r
index 632aeea..4171afd 100644 (file)
@@ -112,40 +112,62 @@ CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeT
     //years\r
        if(fabs(ts.GetTotalDays()) >= 3*365)\r
     {\r
-               answer .FormatMessage(_T("%1!d! Years ago"), (int)(ts.GetTotalDays()/365));\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO );\r
        }\r
        //Months\r
        if(fabs(ts.GetTotalDays()) >= 60)\r
        {\r
-               answer.FormatMessage( _T("%1!d! Months ago"), (int)(ts.GetTotalDays()/30) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO );\r
                return answer;\r
        }\r
        //Weeks\r
        if(fabs(ts.GetTotalDays()) >= 14)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Weeks ago"), (int)(ts.GetTotalDays()/7) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO );\r
                return answer;\r
        }\r
        //Days\r
        if(fabs(ts.GetTotalDays()) >= 2)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Days ago"), (int)(ts.GetTotalDays()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO );\r
                return answer;\r
        }\r
        //hours\r
        if(fabs(ts.GetTotalHours()) >= 2)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Hours ago"), (int)(ts.GetTotalHours()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO );\r
                return answer;\r
        }\r
        //minutes\r
        if(fabs(ts.GetTotalMinutes()) >= 2)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Minutes ago"), (int)(ts.GetTotalMinutes()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO );\r
                return answer;\r
        }\r
        //seconds\r
-       answer.FormatMessage(_T("%1!d! Seconds ago"), (int)(ts.GetTotalSeconds()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO );\r
     return answer;\r
 }\r
 \r
+/** \r
+ * Passed a value and two resource string ids\r
+ * if count is 1 then FormatString is called with format_1 and the value\r
+ * otherwise format_2 is used\r
+ * the formatted string is returned\r
+*/\r
+CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n )\r
+{\r
+       CString answer;\r
+       answer.LoadString(9604);\r
+       answer.LoadString(9605);\r
+       if ( count == 1 )\r
+       {\r
+               answer.FormatMessage( format_1, count );\r
+       }\r
+       else\r
+       {\r
+               answer.FormatMessage( format_n, count );\r
+       }\r
+       return answer;\r
+}\r
+\r
index 1a49752..323942e 100644 (file)
@@ -53,4 +53,5 @@ private:
         *      Generates a display string showing the relative time between the two given times as COleDateTimes\r
         */\r
        static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);\r
+       static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n );\r
 };\r
index ee13c09..063ef21 100644 (file)
@@ -1635,40 +1635,60 @@ CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeT
     //years\r
        if(fabs(ts.GetTotalDays()) >= 3*365)\r
     {\r
-               answer.FormatMessage(_T("%1!d! Years ago"), (int)(ts.GetTotalDays()/365));\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO );\r
        }\r
        //Months\r
        if(fabs(ts.GetTotalDays()) >= 60)\r
        {\r
-               answer.FormatMessage( _T("%1!d! Months ago"), (int)(ts.GetTotalDays()/30) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO );\r
                return answer;\r
        }\r
        //Weeks\r
        if(fabs(ts.GetTotalDays()) >= 14)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Weeks ago"), (int)(ts.GetTotalDays()/7) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO );\r
                return answer;\r
        }\r
        //Days\r
        if(fabs(ts.GetTotalDays()) >= 2)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Days ago"), (int)(ts.GetTotalDays()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO );\r
                return answer;\r
        }\r
        //hours\r
        if(fabs(ts.GetTotalHours()) >= 2)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Hours ago"), (int)(ts.GetTotalHours()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO );\r
                return answer;\r
        }\r
        //minutes\r
        if(fabs(ts.GetTotalMinutes()) >= 2)\r
        {\r
-               answer.FormatMessage(_T("%1!d! Minutes ago"), (int)(ts.GetTotalMinutes()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO );\r
                return answer;\r
        }\r
        //seconds\r
-       answer.FormatMessage(_T("%1!d! Seconds ago"), (int)(ts.GetTotalSeconds()) );\r
+               answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO );\r
     return answer;\r
 }\r
 \r
+/** \r
+ * Passed a value and two resource string ids\r
+ * if count is 1 then FormatString is called with format_1 and the value\r
+ * otherwise format_2 is used\r
+ * the formatted string is returned\r
+*/\r
+CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n )\r
+{\r
+       CString answer;\r
+       if ( count == 1 )\r
+       {\r
+               answer.FormatMessage( format_1, count );\r
+       }\r
+       else\r
+       {\r
+               answer.FormatMessage( format_n, count );\r
+       }\r
+       return answer;\r
+}\r
+\r
index 17e34e9..955da17 100644 (file)
@@ -189,4 +189,5 @@ private:
         *      Generates a display string showing the relative time between the two given times as COleDateTimes\r
         */\r
        static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo);\r
+       static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n );\r
 };\r
index 1ffb73c..01e495b 100644 (file)
@@ -107,7 +107,7 @@ CGitLogListBase::CGitLogListBase():CHintListCtrl()
        }\r
        // get relative time display setting from registry\r
        DWORD regRelativeTimes = CRegDWORD(_T("Software\\TortoiseGit\\RelativeTimes"), FALSE);\r
-       m_bRelativeTimes = regRelativeTimes;\r
+       m_bRelativeTimes = (regRelativeTimes != 0);\r
 }\r
 \r
 CGitLogListBase::~CGitLogListBase()\r
index 9f9b06a..325c8fc 100644 (file)
@@ -234,7 +234,7 @@ protected:
        \r
        COLORREF                        m_LineColors[Lanes::COLORS_NUM];\r
        DWORD                           m_DateFormat;   // DATE_SHORTDATE or DATE_LONGDATE\r
-       BOOL                            m_bRelativeTimes;       // Show relative times\r
+       bool                            m_bRelativeTimes;       // Show relative times\r
 };\r
 \r
 \r