Recent

Author Topic: [SOLVED] TShellTreeView - redraw / refresh a node  (Read 2382 times)

petevick

  • Sr. Member
  • ****
  • Posts: 427
[SOLVED] TShellTreeView - redraw / refresh a node
« on: February 05, 2022, 07:01:05 pm »
Here I am yet again  ::)
I am attempting to 'redraw' a parent node after editing a child node name via the OnEdited event to re-sort the folders, code as below, original code courtesy of GetMem ......
Code: Pascal  [Select][+][-]
  1. procedure TForm1.TreeViewEdited(Sender: TObject; Node: TTreeNode; var S: string
  2.   );
  3. var
  4.   OldPath: String;
  5.   NewPath: String;
  6.   aNode:TTreeNode;  // added
  7. begin
  8.  OldPath := TShellTreeNode(Node).FullFilename;
  9.  NewPath := TShellTreeNode(Node).BasePath + S;
  10.  aNode:=Node.Parent;   // added - aNode = Parent of edited node
  11.  if TShellTreeNode(Node).IsDirectory then
  12.  begin
  13.    OldPath := AppendPathDelim(OldPath);
  14.    NewPath := AppendPathDelim(NewPath);
  15.  end;
  16. // str:=aNode.Text;
  17.  if not RenameFile(OldPath, NewPath) then
  18.  begin
  19.    S := Node.Text;
  20.    MessageDlg('Cannot rename the folder...'+sLineBreak+sLineBreak+
  21.               S, mtError, [mbOK], 0);
  22.  end
  23.  else begin
  24.    aNode.Expand(False);    // added
  25.    aNode.Expanded:=True; // added
  26.  end;
  27. end;
...Line 10 sets the aNode var to parent of the edited node, and lines 24 and 25 'should', as far as I can see, refresh the node of the selected item that was edited. But it only half does it, The renamed folder appears in it's correct sorted position, but it's also displayed at it's original position, it looks like it's overwritten an existing folder, but it's just a display glitch, if I manually close and open the folder it all displays correctly.
I keep thinking that maybe the OnEdited event is not the right place to add to, but I can't see any other logical place to add this 'Redraw' code.
« Last Edit: February 16, 2022, 03:20:51 pm by petevick »
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: TShellTreeView - redraw / refresh a node
« Reply #1 on: February 05, 2022, 07:18:11 pm »
@petevick

wp fixed the issue in main(trunk), it works without additional hacks. The changes will be available in the next release, until then you should apply the changes to your local installation and rebuild the IDE: Tools->Build Lazarus with... You can find the changes here: https://forum.lazarus.freepascal.org/index.php/topic,58161.msg433345.html#msg433345

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: TShellTreeView - redraw / refresh a node
« Reply #2 on: February 05, 2022, 07:22:34 pm »
Thanks GetMem, I'll look into that next week, off for a few days break  8)
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: TShellTreeView - redraw / refresh a node
« Reply #3 on: February 05, 2022, 08:58:45 pm »
Couldn't wait !
I've applied the fix, I edited shellctrls.pas directly, I assume that's ok. I then rebuilt the IDE, no errors, but I'm still getting the same anomaly as in my first post. See the attached gif.
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: TShellTreeView - redraw / refresh a node
« Reply #4 on: February 05, 2022, 09:11:27 pm »
@petevick
Quote
I've applied the fix, I edited shellctrls.pas directly, I assume that's ok.
Yes, that's ok.

Quote
I then rebuilt the IDE, no errors, but I'm still getting the same anomaly as in my first post. See the attached gif.
I just double checked and works fine at my side. Unfortunately I uninstalled 2.0.12, so I cannot test.



petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: TShellTreeView - redraw / refresh a node
« Reply #5 on: February 05, 2022, 09:42:23 pm »
I just double checked and works fine at my side. Unfortunately I uninstalled 2.0.12, so I cannot test.
Ok, thanks for double checking. I'll just have to carry on trying to find a work around  %)
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 13554
Re: TShellTreeView - redraw / refresh a node
« Reply #6 on: February 05, 2022, 09:57:52 pm »
Of course, the OnEdited handler still is required for the TShellTreeview. My patch only fixes the issue with double-storage of the file name and the crash resulting from this ambiguity. The renaming itself still must be applied to the real files by you.

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: TShellTreeView - redraw / refresh a node
« Reply #7 on: February 05, 2022, 11:31:36 pm »
Of course, the OnEdited handler still is required for the TShellTreeview. My patch only fixes the issue with double-storage of the file name and the crash resulting from this ambiguity. The renaming itself still must be applied to the real files by you.
thanks for taking the time to clear that up wp  ;)
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: TShellTreeView - redraw / refresh a node
« Reply #8 on: February 06, 2022, 07:59:08 am »
Well I'm totally stumped with this, if I close and open the node manually the inner folders display correctly, if I do the same thing with code I get the anomaly as shown in the gif above. It's not helping that I can't find any documentation listing node properties and their usage.
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 427
Re: TShellTreeView - redraw / refresh a node
« Reply #9 on: February 16, 2022, 03:20:13 pm »
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

 

TinyPortal © 2005-2018