Recent

Author Topic: [SOLVED] Limiting Search in TSelectDirectory  (Read 347 times)

Badger

  • Full Member
  • ***
  • Posts: 170
[SOLVED] Limiting Search in TSelectDirectory
« on: May 09, 2026, 09:46:36 am »
I'm adding a backup capability to an application.  I want the user to select from one of the past backup folders which, in turn, contain files and directories which will be transferred to the program.
 My problem is that when the backup directories are displayed in SelectDirectory, the user can double click on a backup directory and display/select a sub directory.  This would really stuff up subsequent directory/file transfer.
Is there any way to stop the SelectDirectory opening sub directories?
« Last Edit: May 19, 2026, 11:58:15 pm by Badger »
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 11 Lazarus v4.6  FPC 3.2.2   x86_64-win64-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 7774
Re: Limiting Search in TSelectDirectory
« Reply #1 on: May 09, 2026, 03:09:21 pm »
For your needs you could use the ShellTreeView which is on the Misc Tab.

With that, you could filter the incoming to monitor the user actions and only show the branch of folders but not select them etc.

There is an accompanied ShellListview if you wish to show more details that work together but you don't need to use both.
P.S.
 There is a known problem from my end anyways in using the OS-Icons for the Icons in the display, I don't use that feature since it makes 64 bit apps run dry on the icon list and then stops generating any icons for the list, in fact it must be causing a resource leak in windows because I need to restart windows to  get it back. I just don't use that part.

Jamie
The only true wisdom is knowing you know nothing

Badger

  • Full Member
  • ***
  • Posts: 170
Re: Limiting Search in TSelectDirectory
« Reply #2 on: May 11, 2026, 04:25:57 am »
My original approach was to use the function  SelectDirectory(....) However, I then tried using the TSelectDirectory object.  This has an option - ofNoChangeDir which, in the notes simply says "Do not change the current directory".  I tried setting this but it didn't prevent me from entering sub-directories.  Have I misinterpreted the action of this option or is there a problem with it?
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 11 Lazarus v4.6  FPC 3.2.2   x86_64-win64-win32/win64

dsiders

  • Hero Member
  • *****
  • Posts: 1635
Re: Limiting Search in TSelectDirectory
« Reply #3 on: May 11, 2026, 05:29:01 am »
My original approach was to use the function  SelectDirectory(....) However, I then tried using the TSelectDirectory object.  This has an option - ofNoChangeDir which, in the notes simply says "Do not change the current directory".  I tried setting this but it didn't prevent me from entering sub-directories.  Have I misinterpreted the action of this option or is there a problem with it?

The only widget sets which implement ofNoChangeDir are Windows and GTK1. And you say it's not working on Windows.

Perhaps you could use FileUtil.FindAllDirectories as the basis for your own dialog.
« Last Edit: May 11, 2026, 06:10:51 am by dsiders »

Bart

  • Hero Member
  • *****
  • Posts: 5731
    • Bart en Mariska's Webstek
Re: Limiting Search in TSelectDirectory
« Reply #4 on: May 11, 2026, 06:45:22 pm »
TBH: ofNoChangeDir in a dialog to selct a directory makes no sense at all to me.

I would guess (but MS doesn't document this, at least not in it's page about FileOpenDialogOptions) that setting FOS_PICKFOLDERS (which makes the dialog a TSelectDirectoryDialog) disables FOS_NOCHANGEDIR.

Bart

Badger

  • Full Member
  • ***
  • Posts: 170
Re: [SOLVED] Limiting Search in TSelectDirectory
« Reply #5 on: May 20, 2026, 12:02:10 am »
I have worked around it. Because all the directories are named "Backup Created ....." i wrote code looping until the user had that phrase in the return. Not elegant but it worked.
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 11 Lazarus v4.6  FPC 3.2.2   x86_64-win64-win32/win64

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1596
    • Lebeau Software
Re: Limiting Search in TSelectDirectory
« Reply #6 on: May 20, 2026, 12:25:30 am »
I then tried using the TSelectDirectory object.  This has an option - ofNoChangeDir which, in the notes simply says "Do not change the current directory".  I tried setting this but it didn't prevent me from entering sub-directories.

Correct, because that is not what it's meant for.

Have I misinterpreted the action of this option or is there a problem with it?

You have misinterpreted it, but that's understandable because it is documented poorly.

When the user accepts the dialog, by default it changes the calling process's Current Working Directory to be the selected directory.  The ofNoChangeDir option prevents it from doing that.

More accurately, the dialog actively manipulates the CWD while the user is navigating, and the ofNoChangeDir option simply restores the original CWD when the dialog is closed.

To accomplish what you want, you can use the TSelectDirectoryDialog.OnCanClose event to prevent the user from accepting an unacceptable folder when closing the dialog. It can't stop the user from navigating to such folders inside the dialog - that takes more work. You can use the TSelectDirectoryDialog.OnFolderChange and TSelectDirectoryDialog.OnSelection events to enable/disable the dialog's OK button, based on which folder the user selects/enters.

TBH: ofNoChangeDir in a dialog to selct a directory makes no sense at all to me.

It makes perfect sense, once you understand what it's actually doing.

I would guess ... that setting FOS_PICKFOLDERS (which makes the dialog a TSelectDirectoryDialog) disables FOS_NOCHANGEDIR.

No, it does not. Those options are not mutually exclusive. A FOS_PICKFOLDERS dialog still manipulates the CWD while active, and FOS_NOCHANGEDIR restores the original CWD when the dialog is closed.
« Last Edit: May 20, 2026, 01:18:54 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

jamie

  • Hero Member
  • *****
  • Posts: 7774
Re: [SOLVED] Limiting Search in TSelectDirectory
« Reply #7 on: May 20, 2026, 01:32:11 am »
This is why the "TShellTreeView" works well because you can reject incoming folders or files before it gets added.

 The "OnAddItem" if memory serves.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018