<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Default filename for al_create_native_file_dialog()?</title>
		<link>http://www.allegro.cc/forums/view/611100</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 22 Sep 2012 07:34:24 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was doing more work on my editor, actually editing a level, testing new graphics when I forgot the name of the level that I had loaded.  I didn&#39;t want to overwrite the wrong filename.  It occurred to me that I needed Allegro 5&#39;s dialog to remember the file that was loaded so when I went to save it again, it would be already there in the selection box by default under Windows 7.</p><p>I added in code which basically, should do this from what I read in the docs.</p><p>Something like this...
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename <span class="k3">=</span> <span class="s">"c:\develop\projects\deluxe pacman 2\level02.dp2"</span><span class="k2">;</span>
file_dialog <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>filename, <span class="s">"Load Level"</span>, <span class="s">"*.dp2"</span>,
                                          ALLEGRO_FILECHOOSER_FILE_MUST_EXIST<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

My code is actually slightly different, but this is essentially it.  The dialog works, but doesn&#39;t have the filename by default.  It will navigate to the folder but the file doesn&#39;t show up. It shows all files ending in *.dp2 okay and I can select and save as usual.  Is there any way I can do this?  Do I need to learn how to do this myself?  I am just about ready to start reading on how to get windows dialogs up to do this and abandon all attempts at portability, but I would rather not.  I also thought of making my own interface, which is starting to seem easier, but I have to re-invent the wheel.</p><p>I tried some other things but then ran into problems with the different file types used, ALLEGRO_PATH, const char * as opposed to char * etc... so very annoying.  I miss the simplicity of Allegro 4.</p><p>Something like: <span class="source-code"><a href="http://www.allegro.cc/manual/file_select_ex"><span class="a">file_select_ex</span></a><span class="k2">(</span><span class="k2">)</span></span> which worked perfectly this way.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sat, 22 Sep 2012 03:42:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure if the Windows version supports that properly. The Windows part of that add-on hasn&#39;t been given much love.</p><p>But that said, using single back slashes in a C-string is a no-no, so you should at least double them up or use forward slashes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 22 Sep 2012 06:47:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611100/966525#target">Matthew Leverton</a> said:</div><div class="quote"><p>But that said, using single back slashes in a C-string is a no-no, so you should at least double them up or use forward slashes.</p></div></div><p>

Yeah, actually, I just quickly typed that part in by hand, I don&#39;t normally type out backslashes.  I guess I should have copied/pasted code instead. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>My actual full save function is:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="c">// returns true if saved properly</span>
<span class="number">  2</span><span class="k1">bool</span> savemap<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display, LEVEL <span class="k3">*</span>level<span class="k2">)</span>
<span class="number">  3</span><span class="k2">{</span>
<span class="number">  4</span>   <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  5</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_FILECHOOSER"><span class="a">ALLEGRO_FILECHOOSER</span></a> <span class="k3">*</span>file_dialog <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span>   <span class="c">/// TODO: Search folder for levels and set the filename to the next available level #</span>
<span class="number">  8</span>   file_dialog <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><span class="s">".//"</span>, <span class="s">"Save Level"</span>, <span class="s">"*.dp2"</span>,
<span class="number">  9</span>                                              ALLEGRO_FILECHOOSER_SAVE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>   <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>file_dialog<span class="k2">)</span> <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>   <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_show_native_file_dialog"><span class="a">al_show_native_file_dialog</span></a><span class="k2">(</span>display, file_dialog<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 13</span>      <span class="k1">if</span><span class="k2">(</span>file_dialog<span class="k2">)</span> <a href="http://www.allegro.cc/manual/al_destroy_native_file_dialog"><span class="a">al_destroy_native_file_dialog</span></a><span class="k2">(</span>file_dialog<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>      <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 15</span>   <span class="k2">}</span>
<span class="number"> 16</span>
<span class="number"> 17</span>   filename <span class="k3">=</span> <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 class="k2">(</span>file_dialog, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>
<span class="number"> 19</span>   FILE <span class="k3">*</span>file <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 20</span>
<span class="number"> 21</span>   file <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span>filename, <span class="s">"wb"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_371.html" target="_blank">fwrite</a><span class="k2">(</span>level-&gt;map_id, <span class="k1">sizeof</span><span class="k2">(</span><span class="k1">char</span><span class="k2">)</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_764.html" target="_blank">strlen</a><span class="k2">(</span>level-&gt;map_id<span class="k2">)</span>, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>
<span class="number"> 25</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;map_ver, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;validated, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 27</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;line_set, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;player.x, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;player.y, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>   <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">4</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 31</span>      <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;ghost<span class="k2">[</span>i<span class="k2">]</span>.x, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>      <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;ghost<span class="k2">[</span>i<span class="k2">]</span>.y, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 33</span>   <span class="k2">}</span>
<span class="number"> 34</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;pickup.x, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 35</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;pickup.y, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 36</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;background, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 37</span>   <span class="k1">for</span><span class="k2">(</span><span class="k1">unsigned</span> <span class="k1">char</span> y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> y <span class="k3">&lt;</span> MAPY<span class="k2">;</span> y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 38</span>      <span class="k1">for</span><span class="k2">(</span><span class="k1">unsigned</span> <span class="k1">char</span> x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> x <span class="k3">&lt;</span> MAPX<span class="k2">;</span> x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 39</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;map<span class="k2">[</span>y<span class="k2">]</span><span class="k2">[</span>x<span class="k2">]</span>.tile, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 40</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;map<span class="k2">[</span>y<span class="k2">]</span><span class="k2">[</span>x<span class="k2">]</span>.is_pill, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 41</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_347.html" target="_blank">fputc</a><span class="k2">(</span>level-&gt;map<span class="k2">[</span>y<span class="k2">]</span><span class="k2">[</span>x<span class="k2">]</span>.is_powerpill, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 42</span>      <span class="k2">}</span>
<span class="number"> 43</span>   <span class="k2">}</span>
<span class="number"> 44</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_371.html" target="_blank">fwrite</a><span class="k2">(</span><span class="k3">&amp;</span>level-&gt;pills, <span class="k1">sizeof</span><span class="k2">(</span><span class="k1">unsigned</span> <span class="k1">short</span><span class="k2">)</span>, <span class="n">1</span>, file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 45</span>
<span class="number"> 46</span>   <span class="c">// never forget to close the file</span>
<span class="number"> 47</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_308.html" target="_blank">fclose</a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 48</span>
<span class="number"> 49</span>   <span class="k1">if</span><span class="k2">(</span>file_dialog<span class="k2">)</span> <a href="http://www.allegro.cc/manual/al_destroy_native_file_dialog"><span class="a">al_destroy_native_file_dialog</span></a><span class="k2">(</span>file_dialog<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 50</span>
<span class="number"> 51</span>   <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 52</span><span class="k2">}</span>
</div></div><p>

Currently it just goes to the default local folder to save, works well.  I was thinking of changing the &quot;.//&quot; part (I copied that from someone on here, seems to work) so that it uses the <span class="source-code">filename</span> variable, one that would be passed to this function, and it would contain the full path to the last loaded level (or default level name, eventually the function will scan for the next best name if there are none yet) and then the dialog would show the filename in it.</p><p>I have seen this in programs like Winamp, if you save your playlist, at first you have to select a filename, but once it is selected the next time you save it, the filename is there already set.  I don&#39;t know how they do it.  I&#39;ll have to look around and see what I can come up with I guess.  I just figured it wouldn&#39;t do any harm to ask. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>This is the dialog that Winamp uses with the previously selected filename already in place.  I&#39;m not sure how to get the same thing up, I&#39;ve not programmed the Windows API much, but I&#39;ll look into it.<br /><span class="remote-thumbnail"><span class="json">{"name":"606625","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/a\/ba6f8bfa67feb076b4c5859cead7c36d.png","w":624,"h":474,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/a\/ba6f8bfa67feb076b4c5859cead7c36d"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/b/a/ba6f8bfa67feb076b4c5859cead7c36d-240.jpg" alt="606625" width="240" height="182" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Sat, 22 Sep 2012 07:34:24 +0000</pubDate>
	</item>
</rss>
