Skip to content

Commit

Permalink
Added SE relevant folders to open&save dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
THDigi committed Nov 4, 2022
1 parent 4ea076d commit 2b29deb
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions EditorUI_Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
Expand All @@ -10,6 +11,7 @@
using Sandbox;
using Sandbox.Game.Gui;
using Sandbox.Graphics.GUI;
using VRage.FileSystem;
using VRage.Game;
using VRage.ObjectBuilders;
using VRage.Render.Particles;
Expand Down Expand Up @@ -162,6 +164,22 @@ public static string GetDescriptionAttrib(Type type, string memberName)
return attrib.Description;
}

static IEnumerable<string> FileDialogPlaces()
{
// shows up in reverse order for some reason
yield return MyFileSystem.ContentPath;
yield return Path.Combine(MyFileSystem.UserDataPath, "ParticleEditor");
yield return MyFileSystem.ModsPath;
}

static Form GetMainForm()
{
if(Application.OpenForms.Count > 0)
return Application.OpenForms[0];
else
return new Form { TopMost = true };
}

public static void FileDialog<TDialog>(string title, string directory, string filter, Action<string> callback) where TDialog : FileDialog, new()
{
Thread thread = new Thread(new ThreadStart(() =>
Expand All @@ -170,22 +188,17 @@ public static string GetDescriptionAttrib(Type type, string memberName)
{
using(TDialog dialog = new TDialog())
{
if(directory != null && Directory.Exists(directory))
dialog.InitialDirectory = directory;

dialog.Title = title;
dialog.Filter = filter;
dialog.RestoreDirectory = true;
dialog.AddExtension = true;
dialog.AutoUpgradeEnabled = true;

Form GetMainForm()
{
if(Application.OpenForms.Count > 0)
return Application.OpenForms[0];
else
return new Form { TopMost = true };
}
if(directory != null && Directory.Exists(directory))
dialog.InitialDirectory = directory;

foreach(string folder in FileDialogPlaces())
dialog.CustomPlaces.Add(folder);

if(dialog.ShowDialog(GetMainForm()) == DialogResult.OK)
{
Expand All @@ -210,23 +223,18 @@ public static void OpenMultipleFilesDialog(string title, string directory, strin
{
using(OpenFileDialog dialog = new OpenFileDialog())
{
if(directory != null && Directory.Exists(directory))
dialog.InitialDirectory = directory;

dialog.Title = title;
dialog.Filter = filter;
dialog.RestoreDirectory = true;
dialog.AddExtension = true;
dialog.AutoUpgradeEnabled = true;
dialog.Multiselect = true;

Form GetMainForm()
{
if(Application.OpenForms.Count > 0)
return Application.OpenForms[0];
else
return new Form { TopMost = true };
}
if(directory != null && Directory.Exists(directory))
dialog.InitialDirectory = directory;

foreach(string folder in FileDialogPlaces())
dialog.CustomPlaces.Add(folder);

if(dialog.ShowDialog(GetMainForm()) == DialogResult.OK)
{
Expand Down

0 comments on commit 2b29deb

Please sign in to comment.