NSOpenPanel preselect multiple files - objective-c

While there is quite a few questions about how to preselect a file on NSOpenPanel, they set openPanel.directoryURL to the path of the target file. However NSOpenPanel can allow for multiple files to be selected via the openPanel.allowsMultipleSelection property. Is there a way to preselect multiple files?
The intuitive way would be to set openPanel.urls but that is read-only.

Related

Folder property of File Search Launch Condition: how to specify custom folder under [TARGETDIR]?

I'm trying to set a file search launch condition for my installer. I need it to search for a specified file in a subfolder of my [TARGETDIR] folder.
I tried setting the Folder property to:
[TARGETDIR]/Subfolder
[TARGETDIR]Subfolder
[TARGETDIR]Subfolder/
[TARGETDIR]/Subfolder/
[TARGETDIR]/"Subfolder"
None of the above solutions worked. The file located in subfolder never gets found. It works if I only specify [TARGETDIR] with the Depth property set to 1, but I would rather specify directly the directory to search.
I found a similar question here, but there is no answer.
What is the correct way to set the Folder property to work with a custom folder ?
The difficulty here is that TARGETDIR is not set until later than the search is done, so it has no value yet. Even if if it did have a value, it's what is changed by the browse dialog that can change where the user installs thet app (see the property window of Application Folder in File System on Target Machine).
This means you must use standard folder properties in your search. If you want to search what you think may be where the file is installed, then use:
[ProgramFilesFolder]SomeFolder\SomeOtherFolder
or something similar if your assumed value of TARGETDIR is in Program Files x86.

How to use the OpenFileDialog in one specific folder

im having problems with the OpenFileDialog. I use it for select an image in my project. The problem is that i need (well, i want) limit the access to only one and speficic folder (for example c:\secretProyect\images ). Is it possible?
You can't do that with the standard OpenFileDialog. You can create a custom OpenFileDialog yourself, maybe using a ListView to list the files under the secret path.
Or you can check the file after OpenFileDialog returns, and reject if the user select files from forbidden passages.

Cocoa: Is there a way to delete a few files at once?

Is there a way similar to removeItemAtPath: that allows removing of a few files at once? It should not all the files in a directory but can be a few of them only. E.g. you feed the method a few file paths in an array.
Create a collection of the items you wish to delete, loop over the collection and delete them the same way you'd delete a single file.

list view files in .NET

Can anybody tell how to list view opened files in VB.NET.
The opened files should be seen in list view at the left part of GUI.
You can manually track open files, for example, by keeping a collection that contains their names. Once a new file is open, a new item containing the file path is added to the collection. When a specific file is closed, that item is removed from the collection.
Note: The collection I am talking about can have different data for specific files, not only file paths.
Given you have that collection, you can easily bind it to a ListView control.

How do I put a listing of files into a menu?

I have a folder with .txt files in it. How can i make my menuitem get those .txt files and put the filenames in the menuitem, so that it creates a list of all .txt files in that folder.
So when i put a .txt in the folder the program automatically creates the menu item.
Does someone knows how to do this, or perhaps an example?
Unless you're using ASP.Net, you're looking for the FileSystemWatcher and Directory classes.
Basically, you need to call Directory.GetFiles and loop through the results creating MenuItems.
Then, handle the FileSystemWatcher events and either rebuild the menu from scratch (simpler) or update the appropriate item (faster)