[haiku-commits] r41197 - haiku/trunk/src/kits/tracker

  • From: jonas@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 8 Apr 2011 07:11:24 +0200 (CEST)

Author: kirilla
Date: 2011-04-08 07:11:23 +0200 (Fri, 08 Apr 2011)
New Revision: 41197
Changeset: https://dev.haiku-os.org/changeset/41197

Modified:
   haiku/trunk/src/kits/tracker/Attributes.h
   haiku/trunk/src/kits/tracker/ContainerWindow.cpp
   haiku/trunk/src/kits/tracker/PoseView.cpp
   haiku/trunk/src/kits/tracker/TextWidget.cpp
   haiku/trunk/src/kits/tracker/TrackerSettings.cpp
   haiku/trunk/src/kits/tracker/WidgetAttributeText.cpp
   haiku/trunk/src/kits/tracker/WidgetAttributeText.h
Log:
Offer a 'Real name' column in Tracker list view mode, when set to show 
localized names. As discussed a while back. I honestly don't know if this is 
such a great idea after all. Name + real name is kind of silly. Ideally it 
would be labeled in a more logical way, or the feature should be dropped.

Modified: haiku/trunk/src/kits/tracker/Attributes.h
===================================================================
--- haiku/trunk/src/kits/tracker/Attributes.h   2011-04-07 21:54:25 UTC (rev 
41196)
+++ haiku/trunk/src/kits/tracker/Attributes.h   2011-04-08 05:11:23 UTC (rev 
41197)
@@ -39,6 +39,7 @@
 
 // viewable attributes
 #define        kAttrStatName                                   "_stat/name"
+#define        kAttrRealName                                   "_stat/realname"
 #define        kAttrStatSize                                   "_stat/size"
 #define        kAttrStatModified                               "_stat/modified"
 #define        kAttrStatCreated                                "_stat/created"

Modified: haiku/trunk/src/kits/tracker/ContainerWindow.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/ContainerWindow.cpp    2011-04-07 21:54:25 UTC 
(rev 41196)
+++ haiku/trunk/src/kits/tracker/ContainerWindow.cpp    2011-04-08 05:11:23 UTC 
(rev 41197)
@@ -3186,6 +3186,11 @@
        menu->AddItem(NewAttributeMenuItem(B_TRANSLATE("Name"),
                kAttrStatName, B_STRING_TYPE, 145, B_ALIGN_LEFT, true, true));
 
+       if (gLocalizedNamePreferred) {
+               menu->AddItem(NewAttributeMenuItem(B_TRANSLATE("Real name"),
+                       kAttrRealName, B_STRING_TYPE, 145, B_ALIGN_LEFT, true, 
true));
+       }
+
        menu->AddItem(NewAttributeMenuItem (B_TRANSLATE("Size"), kAttrStatSize, 
B_OFF_T_TYPE,
                80, B_ALIGN_RIGHT, false, true));
 

Modified: haiku/trunk/src/kits/tracker/PoseView.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/PoseView.cpp   2011-04-07 21:54:25 UTC (rev 
41196)
+++ haiku/trunk/src/kits/tracker/PoseView.cpp   2011-04-08 05:11:23 UTC (rev 
41197)
@@ -2479,6 +2479,8 @@
                                                                
settings.SetSortFolderNamesFirst(sortFolderNamesFirst);
 
                                                        
NameAttributeText::SetSortFolderNamesFirst(settings.SortFolderNamesFirst());
+                                                       
RealNameAttributeText::SetSortFolderNamesFirst(
+                                                               
settings.SortFolderNamesFirst());
                                                        SortPoses();
                                                        Invalidate();
                                                }

Modified: haiku/trunk/src/kits/tracker/TextWidget.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/TextWidget.cpp 2011-04-07 21:54:25 UTC (rev 
41196)
+++ haiku/trunk/src/kits/tracker/TextWidget.cpp 2011-04-08 05:11:23 UTC (rev 
41197)
@@ -321,9 +321,6 @@
        if (!IsEditable())
                return;
 
-       if (pose->TargetModel()->HasLocalizedName())
-               return;
-
        BEntry entry(pose->TargetModel()->EntryRef());
        if (entry.InitCheck() == B_OK
                && !ConfirmChangeIfWellKnownDirectory(&entry,

Modified: haiku/trunk/src/kits/tracker/TrackerSettings.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/TrackerSettings.cpp    2011-04-07 21:54:25 UTC 
(rev 41196)
+++ haiku/trunk/src/kits/tracker/TrackerSettings.cpp    2011-04-08 05:11:23 UTC 
(rev 41197)
@@ -191,6 +191,8 @@
        TryReadingSettings();
 
        
NameAttributeText::SetSortFolderNamesFirst(fSortFolderNamesFirst->Value());
+       RealNameAttributeText::SetSortFolderNamesFirst(
+               fSortFolderNamesFirst->Value());
 
        fSettingsLoaded = true;
 }
@@ -364,6 +366,7 @@
 {
        gTrackerState.fSortFolderNamesFirst->SetValue(enabled);
        NameAttributeText::SetSortFolderNamesFirst(enabled);
+       RealNameAttributeText::SetSortFolderNamesFirst(enabled);
 }
 
 

Modified: haiku/trunk/src/kits/tracker/WidgetAttributeText.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/WidgetAttributeText.cpp        2011-04-07 
21:54:25 UTC (rev 41196)
+++ haiku/trunk/src/kits/tracker/WidgetAttributeText.cpp        2011-04-08 
05:11:23 UTC (rev 41197)
@@ -82,6 +82,7 @@
 
 
 bool NameAttributeText::sSortFolderNamesFirst = false;
+bool RealNameAttributeText::sSortFolderNamesFirst = false;
 
 
 template <class View>
@@ -243,6 +244,8 @@
                return new KindAttributeText(model, column);
        if (strcmp(attrName, kAttrStatName) == 0)
                return new NameAttributeText(model, column);
+       if (strcmp(attrName, kAttrRealName) == 0)
+               return new RealNameAttributeText(model, column);
        if (strcmp(attrName, kAttrStatSize) == 0)
                return new SizeAttributeText(model, column);
        if (strcmp(attrName, kAttrStatModified) == 0)
@@ -833,6 +836,144 @@
 }
 
 
+bool
+NameAttributeText::IsEditable() const
+{
+       return StringAttributeText::IsEditable()
+               && !fModel->HasLocalizedName();
+}
+
+
+// #pragma mark -
+
+
+RealNameAttributeText::RealNameAttributeText(const Model* model,
+       const BColumn* column)
+       :
+       StringAttributeText(model, column)
+{
+}
+
+
+int
+RealNameAttributeText::Compare(WidgetAttributeText& attr, BPoseView* view)
+{
+       RealNameAttributeText* compareTo
+               = dynamic_cast<RealNameAttributeText*>(&attr);
+
+       ASSERT(compareTo);
+
+       if (fValueDirty)
+               ReadValue(&fFullValueText);
+
+       if (RealNameAttributeText::sSortFolderNamesFirst)
+               return fModel->CompareFolderNamesFirst(attr.TargetModel());
+
+       return NaturalCompare(fFullValueText.String(),
+               compareTo->ValueAsText(view));
+}
+
+
+void
+RealNameAttributeText::ReadValue(BString* result)
+{
+       *result = fModel->EntryRef()->name;
+
+       fValueDirty = false;
+}
+
+
+void
+RealNameAttributeText::FitValue(BString* result, const BPoseView* view)
+{
+       if (fValueDirty)
+               ReadValue(&fFullValueText);
+       fOldWidth = fColumn->Width();
+       fTruncatedWidth = TruncString(result, fFullValueText.String(),
+               fFullValueText.Length(), view, fOldWidth, B_TRUNCATE_END);
+       fDirty = false;
+}
+
+
+void
+RealNameAttributeText::SetUpEditing(BTextView* textView)
+{
+       DisallowFilenameKeys(textView);
+
+       textView->SetMaxBytes(B_FILE_NAME_LENGTH);
+       textView->SetText(fFullValueText.String(), fFullValueText.Length());
+}
+
+
+bool
+RealNameAttributeText::CommitEditedTextFlavor(BTextView* textView)
+{
+       const char* text = textView->Text();
+
+       BEntry entry(fModel->EntryRef());
+       if (entry.InitCheck() != B_OK)
+               return false;
+
+       BDirectory      parent;
+       if (entry.GetParent(&parent) != B_OK)
+               return false;
+
+       bool removeExisting = false;
+       if (parent.Contains(text)) {
+               BAlert* alert = new BAlert("",
+                       B_TRANSLATE("That name is already taken. "
+                       "Please type another one."),
+                       B_TRANSLATE("Replace other file"),
+                       B_TRANSLATE("OK"),
+                       NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
+
+               alert->SetShortcut(0, 'r');
+
+               if (alert->Go())
+                       return false;
+
+               removeExisting = true;
+       }
+
+       // TODO:
+       // use model-flavor specific virtuals for all of these special
+       // renamings
+       status_t result;
+       if (fModel->IsVolume()) {
+               BVolume volume(fModel->NodeRef()->device);
+               result = volume.InitCheck();
+               if (result == B_OK) {
+                       RenameVolumeUndo undo(volume, text);
+
+                       result = volume.SetName(text);
+                       if (result != B_OK)
+                               undo.Remove();
+               }
+       } else {
+               if (fModel->IsQuery()) {
+                       BModelWriteOpener opener(fModel);
+                       ASSERT(fModel->Node());
+                       MoreOptionsStruct::SetQueryTemporary(fModel->Node(), 
false);
+               }
+
+               RenameUndo undo(entry, text);
+
+               result = entry.Rename(text, removeExisting);
+               if (result != B_OK)
+                       undo.Remove();
+       }
+
+       return result == B_OK;
+}
+
+
+void
+RealNameAttributeText::SetSortFolderNamesFirst(bool enabled)
+{
+       RealNameAttributeText::sSortFolderNamesFirst = enabled;
+}
+
+
 // #pragma mark - owner/group
 
 

Modified: haiku/trunk/src/kits/tracker/WidgetAttributeText.h
===================================================================
--- haiku/trunk/src/kits/tracker/WidgetAttributeText.h  2011-04-07 21:54:25 UTC 
(rev 41196)
+++ haiku/trunk/src/kits/tracker/WidgetAttributeText.h  2011-04-08 05:11:23 UTC 
(rev 41197)
@@ -101,7 +101,7 @@
 
                Model *TargetModel() const;
 
-               bool IsEditable() const;
+               virtual bool IsEditable() const;
 
                void SetDirty(bool);
 
@@ -329,6 +329,7 @@
                NameAttributeText(const Model *, const BColumn *);
                virtual void SetUpEditing(BTextView *);
                virtual void FitValue(BString *result, const BPoseView *);
+               virtual bool IsEditable() const;
 
                static void SetSortFolderNamesFirst(bool);
        protected:
@@ -340,6 +341,24 @@
 };
 
 
+class RealNameAttributeText : public StringAttributeText {
+public:
+                                                       
RealNameAttributeText(const Model *,
+                                                               const BColumn 
*);
+       virtual void                    SetUpEditing(BTextView *);
+       virtual void                    FitValue(BString *result, const 
BPoseView *);
+
+       static  void                    SetSortFolderNamesFirst(bool);
+
+protected:
+       virtual bool                    CommitEditedTextFlavor(BTextView *);
+       virtual int                             Compare(WidgetAttributeText &, 
BPoseView *view);
+       virtual void                    ReadValue(BString *result);
+
+       static  bool                    sSortFolderNamesFirst;
+};
+
+
 #ifdef OWNER_GROUP_ATTRIBUTES
 
 class OwnerAttributeText : public StringAttributeText {


Other related posts: