beannaich Posted December 18, 2011 Share Posted December 18, 2011 Hello, I have a file type I want to load, but it depends on an external palette file. This would have to be selected by the user, so I decided that for now I would just make a quick OpenFileDialog. When I do this, however, I get an error about the STAThreadAttribute used by Windows forms applications.. So I tested with a generic Form, and the form opens just fine. Here's my question: Can you utilize OpenFileDialog during the FileType.OnLoad override? And if not, what suggestions can be made for navigating to an external palette file so a special file format can be loaded and rendered properly? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted December 18, 2011 Share Posted December 18, 2011 No. Do not do this. Your plugin will be removed from the forum if you do this. The FileType plugin system was not designed for a scenario like this. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
beannaich Posted December 18, 2011 Author Share Posted December 18, 2011 Why is that not allowed? To be honest, I wasn't planning on making this available to the public, since the file type is very obscure. This was going to be for use by me and some of my friends in the game modding community. Am I to believe that there is absolutely no way to load this file type because it relies on an external palette file? Respectfully, that seems kind of lame. There are save widgets.. Why not load widgets? Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted December 18, 2011 Share Posted December 18, 2011 The FileType system doesn't have accommodations for showing UI during the Load process, and it can cause problems (like the kind you're seeing) because it's all done on a background thread. The reason this isn't in place isn't because it would be useful, but because none of the built-in file types had a need for it and I didn't want to ship something I didn't have confidence in. But if you just want it for yourself or a private group of friends then that's fine. You can probably do it with something like ... using System.Threading; ManualResetEvent doneEvent = new ManualResetEvent(false); DialogResult dialogResult = DialogResult.Cancel; string fileName = null; Exception error = null; Thread dialogThread = new Thread( delegate() { try { using (OpenFileDialog dialog = new ...) { ... set properties on dialog ... dialogResult = dialog.ShowDialog(); fileName = dialog.FileName; ... etc. as needed ... } } catch (Exception ex) { error = ex; } finally { doneEvent.Set(); } }); dialogThread.TrySetApartmentState(ApartmentState.STA); // This is the key dialogThread.Start(); doneEvent.WaitOne(); Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.