<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5RC4] Possible problem in native dialog addon? </title>
		<link>http://www.allegro.cc/forums/view/606122</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 26 Jan 2011 15:54:45 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am not sure if this is a problem in the native dialog addon or not, but the file chooser isn&#39;t displaying the way I expected.</p><div class="source-code snippet"><div class="inner"><pre>fileDialog <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_native_file_dialog"><span class="a">al_create_native_file_dialog</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a><span class="k2">(</span><span class="s">"data/maps/"</span><span class="k2">)</span>, <span class="s">"Select Map"</span>, NULL, ALLEGRO_FILECHOOSER_FOLDER<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

According to the documentation, this should allow me to choose a folder rather than a file.  Am I just doing something wrong here or is this just not supported on windows?  Also, I use another file chooser dialog earlier in my program, and it works fine there except for a few things.  For instance, the filter passed was &quot;*.jpg;*.bmp;*.png&quot;.  When the dialog comes up, however, it acts as if *.* were the filter.  Also, the dialog title doesn&#39;t seem to be used.  </p><p>I wasn&#39;t sure if this was a problem with the addon or my code, so I posted it here.  I tried testing in Ubuntu 10.10 also, but as I run it in VMWare, I get <br />XWindow errors creating a display, which is probably due my setup.  My windows testing is also inside VMWare running Windows XP.</p><p>WG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Wed, 19 Jan 2011 09:05:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Windows has a folder selector. Allegro probably doesn&#39;t support it.</p><p>Side note: your <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a><span class="k2">(</span><span class="k2">)</span></span> is a memory leak. The function would probably be more useful if it just accepted a <span class="source-code"><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span></span>, as it&#39;s easy to convert a path to it via <span class="source-code"><a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a></span>...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 19 Jan 2011 10:20:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Looking at the native dialog add-on code it seems that filters are ignored in Windows. Also, folder select is not implemented. I have some experience working with Windows file selectors so I could easily create a patch to address both these issues. I won&#39;t be able to do it until tomorrow, though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Wed, 19 Jan 2011 10:55:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, thanks to both of you for that.  I&#39;m reinstalling Ubuntu right now so that I can try to do more of my work in Linux first, then move to Windows to test.  Since I have a lot more luck compiling SVN code in linux than in Windows.  Knowing that the windows code is simply not there does help a lot and can lead me in the right direction for what I was doing.  As far as the memory leak, I did wonder about that but that line of code was added as a test situation only, so I had planned to fix it later by actually using al_create_path and al_destroy_path.  I do agree that for the native file dialogs, a c style string could be more useful.</p><p>Thanks again</p><p>WG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Wed, 19 Jan 2011 11:15:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I didn&#39;t get as far with this as I wanted today. Everything is working now except the filtering. I should be able to get this done on Friday.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Thu, 20 Jan 2011 07:39:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That would be really awesome... converted 2/3 of my pc&#39;s today to Linux, am debating trying to run windows XP in vmware for linux or something similar.</p><p>Still might switch my pc back to windows.</p><p>wg
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Thu, 20 Jan 2011 16:36:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve attached the patch. This patch makes the following improvements to the Windows native file chooser:</p><ul><li><p>Use Windows&#39; folder selector when using the ALLEGRO_FILECHOOSER_FOLDER flag.</p></li><li><p>Implement patterns <span class="ref"><sup>[<a href="#">1</a>]</sup></span>.</p></li><li><p>Display the title of the dialog that the user specified instead of Windows&#39; default.</p></li></ul><p>
</p><div class="ref-block"><h2>References</h2><ol><li>The patterns are implemented as two filters. One called &quot;All Supported Files&quot; will include all types except *.* the user specified. The other called &quot;All Files&quot; will include *.* if the user specified *.* in their patterns. Otherwise only the &quot;All Supported Types&quot; will be shown. If the user specified NULL for patterns then &quot;All Files&quot; will be shown.</li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Sat, 22 Jan 2011 00:40:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I haven&#39;t looked at the patch yet, but could you change the first parameter from an <span class="source-code">ALLEGRO_PATH<span class="k3">*</span></span> to a <span class="source-code"><span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span></span> while you&#39;re at it? Everybody on [AD] agreed that it should be that way.</p><p>Edit: If that affects multiple platforms, then you can just ignore me, and we&#39;ll add it after your patch.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 22 Jan 2011 00:55:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks, I&#39;ll take it from here.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sun, 23 Jan 2011 05:42:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I had one more question about how the native dialog works when using the folder chooser.  It worked fine in Linux.  The only problem I had was that I expected the entire path to be directory components with a NULL filename and extension.  What I found, however, was that the folder which was chosen is considered the &quot;filename&quot; component.  Is this the intended mode?  It really is not a big deal, but it does require changing the way you deal with the path returned by the file dialog.</p><p>WG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Tue, 25 Jan 2011 01:57:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think the Folder select dialog should be creating its ALLEGRO_PATH with <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a></span> or appending a &#39;/&#39; to the end of the path to make sure the code parses it as a dir.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 25 Jan 2011 02:15:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not at the linux machine right now but I will test it again later.  Last time I tested I was able to select the directory and the path was something like this:</p><p>/home/name/game/maps/worldmap</p><p>Since each map has a jpg image with the same name as the folder, to load the<br />image, I used <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_path_component"><span class="a">al_get_path_component</span></a><span class="k2">(</span>path,<span class="k3">-</span><span class="n">1</span><span class="k2">)</span></span> to store &quot;worldmap&quot; and <br />add /worldmap.jpg to a string.  Unfortunately, the path component being returned <br />was maps rather than worldmap.  The &quot;worldmap&quot; portion of the path was returned by <br />calling <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_path_filename"><span class="a">al_get_path_filename</span></a><span class="k2">(</span>path<span class="k2">)</span></span></p><p>WG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Tue, 25 Jan 2011 02:22:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, the ALLEGRO_PATH path parsing assumes a path without a slash at the end is pointing to a file. It doesn&#39;t do any detection to see if it might exist or not or what type it might be.</p><p>The solution would be to get the Folder Select dialog to create its ALLEGRO_PATH with <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a></span> instead of <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a></span> because the former creates the path as a directory with no filename components, even if the path doesn&#39;t have a trailing slash.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 25 Jan 2011 02:31:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, ok.. I misunderstood what you meant the first time.  So the key to making it work properly is to do this:</p><div class="source-code snippet"><div class="inner"><pre>start<span class="k3">=</span><a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a><span class="k2">(</span>path<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

and then pass that starting path to the file chooser dialog?</p><p>Thanks for clarifying that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Tue, 25 Jan 2011 02:40:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That may also help. I was thinking you were saying that the path that <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_native_file_dialog_path"><span class="a">al_get_native_file_dialog_path</span></a></span> was returning was &quot;wrong&quot;, and if so, the folder chooser should be using <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a></span> if it isn&#39;t already.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 25 Jan 2011 03:10:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wanted to drop a note about something I noticed tonight when I was working.  There is an inconsistency with the documentation and the actual way the libary works in the filesystem code.</p><p>According to both the manual on A.cc and at docs.liballeg.org, al_make_directory should:</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Creates a new directory on the filesystem. This function also creates any parent directories as needed.</p><p>Returns true on success (including if the directory already exists), otherwise returns false on error. Fills in Allegro&#39;s errno to indicate the error.
</p></div></div><p>

However, the following code shows that if the directory already exists, the function will return false rather than true.  This caused me quite some trouble today before I actually thought of testing for the true return value.  Was this changed a while back?</p><div class="source-code snippet"><div class="inner"><pre>  returnValue <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_make_directory"><span class="a">al_make_directory</span></a><span class="k2">(</span><span class="s">"monsters"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>


I was using this code to return false on a file saving routine:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_make_directory"><span class="a">al_make_directory</span></a><span class="k2">(</span><span class="s">"monsters"</span><span class="k2">)</span>
 <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
</pre></div></div><p>

After finding out about the true return values, I had to change that code to this:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_change_directory"><span class="a">al_change_directory</span></a><span class="k2">(</span><span class="s">"data"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_change_directory"><span class="a">al_change_directory</span></a><span class="k2">(</span><span class="s">"monsters"</span><span class="k2">)</span>
 <a href="http://www.allegro.cc/manual/al_make_directory"><span class="a">al_make_directory</span></a><span class="k2">(</span><span class="s">"monsters"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">else</span>
 <a href="http://www.allegro.cc/manual/al_change_directory"><span class="a">al_change_directory</span></a><span class="k2">(</span><span class="s">".."</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_change_directory"><span class="a">al_change_directory</span></a><span class="k2">(</span><span class="s">".."</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Also, since the data directory already exists, when the monsters directory did not, this command failed every time as well:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_make_directory"><span class="a">al_make_directory</span></a><span class="k2">(</span><span class="s">"data/monsters"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

I assume this is because al_make_directory tries to make the parent directories as well, and since it is returning false because data already exists, it does not create the monsters directory.</p><p>Just wanted to mention that in case it wasn&#39;t an intentional change.</p><p>WG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Wed, 26 Jan 2011 15:54:45 +0000</pubDate>
	</item>
</rss>
