x


How can I put a list of filenames into an editor menu?

The EditorGUILayout.Popup method displays a drop-down menu so the user can select from a list of strings. However, any slashes in the option strings are converted into another level of child menu. This is cool when you want nested menus, not so cool when you're trying to give the user a list of filenames to choose from.

Is there a way to prevent this behaviour? Or other suggestions on how to easily throw a drop-down menu into my EditorWindow?

more ▼

asked Feb 08 '11 at 02:11 AM

yoyo gravatar image

yoyo
6.4k 25 39 84

Ah, I can pass an array of GUIContents, doesn't have to be strings. I'll try that in the morning, pretty sure it will work.

Feb 08 '11 at 02:17 AM yoyo
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Turns out backslashes work fine, so I'm converting front-slashes to backslashes for use as menu options, then converting the result back to front-slashes when I use the filename (redundant under Windows, where either slash works for the file system API's, but needed on Mac).

I did notice a few times when backslashes seemed NOT to work, but I believe this was because my editor window class was not being fully reinitialized as I was modifying its code and recompiling. (Seems odd, but I'm not going to bother investigating.)

more ▼

answered Feb 08 '11 at 05:41 PM

yoyo gravatar image

yoyo
6.4k 25 39 84

A backslash will not work on OS X (as far as accessing files goes).

Feb 08 '11 at 08:15 PM Eric5h5

Good to know, edited accordingly.

Feb 08 '11 at 09:33 PM yoyo
(comments are locked)
10|3000 characters needed characters left

An array of GUIContents won't work either, alas. You can replace "/" with "" instead (i.e, the fraction slash character with a space before and after, instead of the standard slash).

more ▼

answered Feb 08 '11 at 02:32 AM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

+1 for knowing it wouldn't work :-( ... but I can't give you credit for the right answer because I don't have that slash on my keyboard, and while I was able to convert my editor to UTF-8 and copy-paste into my code, the slash turns into an "a" with an accent over it when I drop the menu.

Feb 08 '11 at 04:58 PM yoyo

This is what appears -- "". (Note that I'm on a Windows PC.)

Feb 08 '11 at 04:59 PM yoyo

That's too bad; works fine on OS X, and it's standard Unicode, so I don't know what the problem would be.

Feb 08 '11 at 08:16 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1665
x69
x58
x36

asked: Feb 08 '11 at 02:11 AM

Seen: 1277 times

Last Updated: Feb 08 '11 at 02:11 AM