Marko Pintera 11 лет назад
Родитель
Сommit
a125169305

+ 0 - 4
BansheeCore/Source/BsCoreApplication.cpp

@@ -65,10 +65,6 @@ namespace BansheeEngine
 	{
 		signal(SIGABRT, handleAbort);
 
-		Vector<Path> outPaths;
-		Platform::openBrowseDialog((FileDialogType)((UINT32)FileDialogType::OpenFile | (UINT32)FileDialogType::Multiselect), "D:\\Downloads", L"*.exe", outPaths);
-
-
 		UINT32 numWorkerThreads = BS_THREAD_HARDWARE_CONCURRENCY - 1; // Number of cores while excluding current thread.
 
 		Platform::_startUp();

+ 37 - 0
MBansheeEditor/BrowseDialog.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    public static class BrowseDialog
+    {
+        public static bool OpenFile(string defaultPath, string filterList, bool allowMultiselect, out string[] outPaths)
+        {
+            return Internal_OpenFile(defaultPath, filterList, allowMultiselect, out outPaths);
+        }
+
+        public static bool OpenFolder(string defaultPath, string filterList, out string outPath)
+        {
+            return Internal_OpenFolder(defaultPath, filterList, out outPath);
+        }
+
+        public static bool SaveFile(string defaultPath, string filterList, out string outPath)
+        {
+            return Internal_SaveFile(defaultPath, filterList, out outPath);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_OpenFile(string defaultPath, string filterList, bool allowMultiselect, out string[] outPaths);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_OpenFolder(string defaultPath, string filterList, out string outPath);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_SaveFile(string defaultPath, string filterList, out string outPath);
+    }
+}

+ 1 - 0
MBansheeEditor/MBansheeEditor.csproj

@@ -39,6 +39,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="BrowseDialog.cs" />
     <Compile Include="DbgCustomInspector.cs" />
     <Compile Include="DbgEditorWindow.cs" />
     <Compile Include="DbgGizmo.cs" />

+ 18 - 0
SBansheeEditor/Include/BsScriptBrowseDialog.h

@@ -0,0 +1,18 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BED_EXPORT ScriptBrowseDialog : public ScriptObject<ScriptBrowseDialog>
+	{
+	public:
+		SCRIPT_OBJ(BansheeEditorAssemblyName, "BansheeEditor", "BrowseDialog")
+
+	private:
+		static bool internal_OpenFile(MonoString* defaultFolder, MonoString* filterList, bool allowMultiselect, MonoArray** outPaths);
+		static bool internal_OpenFolder(MonoString* defaultFolder, MonoString* filterList, MonoString** outPath);
+		static bool internal_SaveFile(MonoString* defaultFolder, MonoString* filterList, MonoString** outPath);
+	};
+}

+ 2 - 0
SBansheeEditor/SBansheeEditor.vcxproj

@@ -236,6 +236,7 @@
     <ClInclude Include="Include\BsGUIGameObjectField.h" />
     <ClInclude Include="Include\BsGUIPanelContainer.h" />
     <ClInclude Include="Include\BsGUIResourceField.h" />
+    <ClInclude Include="Include\BsScriptBrowseDialog.h" />
     <ClInclude Include="Include\BsScriptEditorPrerequisites.h" />
     <ClInclude Include="Include\BsScriptEditorSettings.h" />
     <ClInclude Include="Include\BsScriptEditorUtility.h" />
@@ -272,6 +273,7 @@
     <ClCompile Include="Source\BsGUIGameObjectField.cpp" />
     <ClCompile Include="Source\BsGUIPanelContainer.cpp" />
     <ClCompile Include="Source\BsGUIResourceField.cpp" />
+    <ClCompile Include="Source\BsScriptBrowseDialog.cpp" />
     <ClCompile Include="Source\BsScriptEditorPlugin.cpp" />
     <ClCompile Include="Source\BsScriptEditorSettings.cpp" />
     <ClCompile Include="Source\BsScriptEditorUtility.cpp" />

+ 6 - 0
SBansheeEditor/SBansheeEditor.vcxproj.filters

@@ -117,6 +117,9 @@
     <ClInclude Include="Include\BsScriptModalWindow.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptBrowseDialog.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptEditorPlugin.cpp">
@@ -221,5 +224,8 @@
     <ClCompile Include="Source\BsScriptModalWindow.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptBrowseDialog.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 95 - 0
SBansheeEditor/Source/BsScriptBrowseDialog.cpp

@@ -0,0 +1,95 @@
+#include "BsScriptBrowseDialog.h"
+#include "BsScriptMeta.h"
+#include "BsMonoClass.h"
+#include "BsPlatform.h"
+#include "BsMonoUtil.h"
+#include "BsPath.h"
+
+namespace BansheeEngine
+{
+	void ScriptBrowseDialog::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_OpenFile", &ScriptBrowseDialog::internal_OpenFile);
+		metaData.scriptClass->addInternalCall("Internal_OpenFolder", &ScriptBrowseDialog::internal_OpenFolder);
+		metaData.scriptClass->addInternalCall("Internal_SaveFile", &ScriptBrowseDialog::internal_SaveFile);
+	}
+
+	bool ScriptBrowseDialog::internal_OpenFile(MonoString* defaultFolder, MonoString* filterList, bool allowMultiselect, MonoArray** outPaths)
+	{
+		Path defaultFolderNative = MonoUtil::monoToWString(defaultFolder);
+		WString filterListNative = MonoUtil::monoToWString(filterList);
+		
+		FileDialogType type = (FileDialogType)((UINT32)FileDialogType::OpenFile | (UINT32)FileDialogType::Multiselect);
+
+		Vector<Path> paths;
+		if (Platform::openBrowseDialog(type, defaultFolderNative, filterListNative, paths))
+		{
+			MonoArray* pathArray = mono_array_new(MonoManager::instance().getDomain(),
+				mono_get_string_class(), (UINT32)paths.size());
+
+			for (UINT32 i = 0; i < (UINT32)paths.size(); i++)
+			{
+				MonoString* monoString = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), paths[i].toWString());
+
+				void* elemAddr = mono_array_addr_with_size(pathArray, sizeof(MonoString*), i);
+				memcpy(elemAddr, &monoString, sizeof(MonoString*));
+			}
+
+			*outPaths = pathArray;
+			return true;
+		}
+		else
+		{
+			*outPaths = nullptr;
+			return false;
+		}
+	}
+
+	bool ScriptBrowseDialog::internal_OpenFolder(MonoString* defaultFolder, MonoString* filterList, MonoString** outPath)
+	{
+		Path defaultFolderNative = MonoUtil::monoToWString(defaultFolder);
+		WString filterListNative = MonoUtil::monoToWString(filterList);
+
+		FileDialogType type = FileDialogType::OpenFolder;
+
+		Vector<Path> paths;
+		if (Platform::openBrowseDialog(type, defaultFolderNative, filterListNative, paths))
+		{
+			if (paths.size() > 0)
+				*outPath = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), paths[0].toWString());
+			else
+				*outPath = nullptr;
+
+			return true;
+		}
+		else
+		{
+			*outPath = nullptr;
+			return false;
+		}
+	}
+
+	bool ScriptBrowseDialog::internal_SaveFile(MonoString* defaultFolder, MonoString* filterList, MonoString** outPath)
+	{
+		Path defaultFolderNative = MonoUtil::monoToWString(defaultFolder);
+		WString filterListNative = MonoUtil::monoToWString(filterList);
+
+		FileDialogType type = FileDialogType::Save;
+
+		Vector<Path> paths;
+		if (Platform::openBrowseDialog(type, defaultFolderNative, filterListNative, paths))
+		{
+			if (paths.size() > 0)
+				*outPath = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), paths[0].toWString());
+			else
+				*outPath = nullptr;
+
+			return true;
+		}
+		else
+		{
+			*outPath = nullptr;
+			return false;
+		}
+	}
+}

+ 0 - 2
TODO.txt

@@ -7,8 +7,6 @@ Possibly set up automatic refresh in debug mode after initialization? As an ad-h
 
 <<<<<Simple stuff>>>>>>
 
-Test file/folder open/save dialog
-
 C#:
 Dialog.Show(title, text, btn1 text, btn1 callback, btn2 text, btn2 callback, btn3 text, btn3 callback)