View Issue Details

IDProjectCategoryView StatusLast Update
0027415PatchesPatchpublic2015-02-10 18:13
Reportertheo Assigned ToBart Broersma  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version1.3 (SVN) 
Summary0027415: TShellTreeView should show expand sign only when if is a subdirectory
DescriptionTShellTreeView should show the expand sign only if there is at least one subdirectory.
TagsNo tags attached.
Fixed in Revisionr47650
LazTarget-
Widgetset
Attached Files

Relationships

related to 0027439 closedBart Broersma TShellTreeView: Display of expand signs (r47650) should be consitent with property ObjectTypes 

Activities

theo

2015-02-07 13:35

reporter  

ShellTV.diff (1,415 bytes)   
Index: lcl/shellctrls.pas
===================================================================
--- lcl/shellctrls.pas	(Revision 47642)
+++ lcl/shellctrls.pas	(Arbeitskopie)
@@ -657,6 +657,30 @@
   i: Integer;
   Files: TStringList;
   NewNode: TTreeNode;
+
+  function _HasSubDirectoryUTF8(Const Directory: String): Boolean;
+  var
+    sr: TSearchRec;
+  begin
+    Result:=False;
+    try
+      if FindFirstUTF8(IncludeTrailingPathDelimiter(directory) +
+        AllFilesMask, faDirectory, sr) < 0 then
+        Exit
+      else
+        repeat
+          if ((sr.Attr and faDirectory <> 0) and (sr.Name <> '.') and
+            (sr.Name <> '..')) then
+              begin
+                Result:=true;
+                Break;
+              end;
+        until FindNextUTF8(sr) <> 0;
+    finally
+      FindCloseUTF8(sr);
+    end;
+  end;
+
 begin
   Result := False;
   // avoids crashes in the IDE by not populating during design
@@ -670,7 +694,8 @@
     for i := 0 to Files.Count - 1 do
     begin
       NewNode := Items.AddChildObject(ANode, Files.Strings[i], nil); //@Files.Strings[i]);
-      NewNode.HasChildren := Files.Objects[i] <> nil; // This marks if the node is a directory
+      NewNode.HasChildren :=  (Files.Objects[i] <> nil) and // This marks if the node is a directory
+      _HasSubDirectoryUTF8(IncludeTrailingPathDelimiter(ANodePath)+Files[i]);
     end;
   finally
     Files.Free;
ShellTV.diff (1,415 bytes)   

theo

2015-02-07 14:13

reporter   ~0080839

Sorry, it is only correct in case of forfObjectTypes = [otFolders].
See ShellTV2.diff

theo

2015-02-07 14:13

reporter  

ShellTV2.diff (1,503 bytes)   
Index: lcl/shellctrls.pas
===================================================================
--- lcl/shellctrls.pas	(Revision 47642)
+++ lcl/shellctrls.pas	(Arbeitskopie)
@@ -657,6 +657,30 @@
   i: Integer;
   Files: TStringList;
   NewNode: TTreeNode;
+
+  function _HasSubDirectoryUTF8(Const Directory: String): Boolean;
+  var
+    sr: TSearchRec;
+  begin
+    Result:=False;
+    try
+      if FindFirstUTF8(IncludeTrailingPathDelimiter(directory) +
+        AllFilesMask, faDirectory, sr) < 0 then
+        Exit
+      else
+        repeat
+          if ((sr.Attr and faDirectory <> 0) and (sr.Name <> '.') and
+            (sr.Name <> '..')) then
+              begin
+                Result:=true;
+                Break;
+              end;
+        until FindNextUTF8(sr) <> 0;
+    finally
+      FindCloseUTF8(sr);
+    end;
+  end;
+
 begin
   Result := False;
   // avoids crashes in the IDE by not populating during design
@@ -670,7 +694,9 @@
     for i := 0 to Files.Count - 1 do
     begin
       NewNode := Items.AddChildObject(ANode, Files.Strings[i], nil); //@Files.Strings[i]);
-      NewNode.HasChildren := Files.Objects[i] <> nil; // This marks if the node is a directory
+      NewNode.HasChildren :=  (Files.Objects[i] <> nil); // This marks if the node is a directory
+      if NewNode.HasChildren and (fObjectTypes = [otFolders]) then
+        NewNode.HasChildren:=_HasSubDirectoryUTF8(IncludeTrailingPathDelimiter(ANodePath)+Files[i]);
     end;
   finally
     Files.Free;
ShellTV2.diff (1,503 bytes)   

Bart Broersma

2015-02-07 17:14

developer   ~0080842

> fObjectTypes = [otFolders]
or: otFolders in fObjectTypes ?

theo

2015-02-07 17:18

reporter   ~0080843

> fObjectTypes = [otFolders]
or: otFolders in fObjectTypes ?

I think the first is correct. As soon as there is anything else but folders, you may want to expand to see the files. But in Mode [otFolders] (default), trying to expand on a folder without subfolder just deletes the expand sign, which is frustrating ;-)

Bart Broersma

2015-02-07 18:20

developer   ~0080844

Is HasChildren (in general) only used to determine wether or not to draw the expand sign, or does it have other uses as well (which this patch then may break)?

theo

2015-02-07 18:33

reporter   ~0080846

I can't see other uses in this component.
TShellTreeView is not very complex.

Bart Broersma

2015-02-08 00:30

developer   ~0080851

Modified and applied.
Please test and close if OK.

theo

2015-02-08 11:51

reporter   ~0080855

Thank you.
Do you think HasSubDir should go to unit FileUtil?
It is not specific to ShellTreeView.

Bart Broersma

2015-02-08 13:10

developer   ~0080861

Last edited: 2015-02-08 13:11

View 2 revisions

> Do you think HasSubDir should go to unit FileUtil?
If more components need it, it should.
ATM I would not do that.

Please close.

theo

2015-02-08 13:29

reporter   ~0080862

Thank you!

Issue History

Date Modified Username Field Change
2015-02-07 13:35 theo New Issue
2015-02-07 13:35 theo File Added: ShellTV.diff
2015-02-07 14:13 theo Note Added: 0080839
2015-02-07 14:13 theo File Added: ShellTV2.diff
2015-02-07 17:14 Bart Broersma Note Added: 0080842
2015-02-07 17:15 Bart Broersma LazTarget => -
2015-02-07 17:15 Bart Broersma Assigned To => Bart Broersma
2015-02-07 17:15 Bart Broersma Status new => feedback
2015-02-07 17:18 theo Note Added: 0080843
2015-02-07 17:18 theo Status feedback => assigned
2015-02-07 18:20 Bart Broersma Note Added: 0080844
2015-02-07 18:20 Bart Broersma Status assigned => feedback
2015-02-07 18:33 theo Note Added: 0080846
2015-02-07 18:33 theo Status feedback => assigned
2015-02-08 00:30 Bart Broersma Fixed in Revision => r47650
2015-02-08 00:30 Bart Broersma Note Added: 0080851
2015-02-08 00:30 Bart Broersma Status assigned => resolved
2015-02-08 00:30 Bart Broersma Resolution open => fixed
2015-02-08 11:51 theo Note Added: 0080855
2015-02-08 13:10 Bart Broersma Note Added: 0080861
2015-02-08 13:11 Bart Broersma Note Edited: 0080861 View Revisions
2015-02-08 13:29 theo Note Added: 0080862
2015-02-08 13:29 theo Status resolved => closed
2015-02-10 18:13 Juha Manninen Relationship added related to 0027439