[haiku-commits] haiku: hrev51300 - src/kits/tracker

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 22 Jul 2017 19:24:47 +0200 (CEST)

hrev51300 adds 1 changeset to branch 'master'
old head: 1416521f1099252bb740e1e3d8991c716501e4da
new head: 0597752447e9bbad2e9953b874c29f7db6cba7bb
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=0597752447e9+%5E1416521f1099

----------------------------------------------------------------------------

0597752447e9: Remove full date format from Tracker date columns
  
  It is too similar to the long format and does not add much value.
  And it creates some problems with using a locale format with another's
  string.
  
  Fixes #11343.

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51300
Commit:      0597752447e9bbad2e9953b874c29f7db6cba7bb
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0597752447e9
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Sat Jul 22 17:23:42 2017 UTC

Ticket:      https://dev.haiku-os.org/ticket/11343

----------------------------------------------------------------------------

1 file changed, 10 insertions(+), 3 deletions(-)
src/kits/tracker/WidgetAttributeText.cpp | 13 ++++++++++---

----------------------------------------------------------------------------

diff --git a/src/kits/tracker/WidgetAttributeText.cpp 
b/src/kits/tracker/WidgetAttributeText.cpp
index 6e24632..b5bf389 100644
--- a/src/kits/tracker/WidgetAttributeText.cpp
+++ b/src/kits/tracker/WidgetAttributeText.cpp
@@ -52,6 +52,7 @@ All rights reserved.
 #include <MessageFormat.h>
 #include <NodeInfo.h>
 #include <Path.h>
+#include <SupportDefs.h>
 #include <TextView.h>
 #include <Volume.h>
 #include <VolumeRoster.h>
@@ -198,11 +199,11 @@ TruncTimeBase(BString* outString, int64 value, const 
View* view, float width)
 
        time_t timeValue = (time_t)value;
 
+       // Find the longest possible format that will fit the available space
        struct {
                BDateFormatStyle dateStyle;
                BTimeFormatStyle timeStyle;
-       } formats[5] = {
-               { B_FULL_DATE_FORMAT, B_MEDIUM_TIME_FORMAT },
+       } formats[] = {
                { B_LONG_DATE_FORMAT, B_MEDIUM_TIME_FORMAT },
                { B_LONG_DATE_FORMAT, B_SHORT_TIME_FORMAT },
                { B_MEDIUM_DATE_FORMAT, B_SHORT_TIME_FORMAT },
@@ -211,13 +212,19 @@ TruncTimeBase(BString* outString, int64 value, const 
View* view, float width)
 
        BString date;
        BDateTimeFormat formatter;
-       for (int i = 0; resultWidth > width && i < 5; ++i) {
+       for (unsigned int i = 0; i < B_COUNT_OF(formats); ++i) {
                if (formatter.Format(date, timeValue, formats[i].dateStyle,
                                formats[i].timeStyle) == B_OK) {
                        resultWidth = view->StringWidth(date.String(), 
date.Length());
+                       if (resultWidth <= width) {
+                               // Found a format that fits the available 
space, stop searching
+                               break;
+                       }
                }
        }
 
+       // If we couldn't fit the date, try with just the time
+       // TODO we could use only the time for "today" dates
        if (resultWidth > width
                && BDateFormat().Format(date, timeValue,
                        B_SHORT_DATE_FORMAT) == B_OK) {


Other related posts:

  • » [haiku-commits] haiku: hrev51300 - src/kits/tracker - pulkomandy