From 8ebc4efe294408d7e2ed40a90495507136fa0ace Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Thu, 9 Apr 2015 12:12:23 +0100 Subject: [PATCH] Add undo support on import. Use notifications instead of logging. #8 --- .../Fungus/Flowchart/Editor/LanguageEditor.cs | 20 ++++++++++++-- Assets/Fungus/Flowchart/Scripts/Language.cs | 27 ++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Assets/Fungus/Flowchart/Editor/LanguageEditor.cs b/Assets/Fungus/Flowchart/Editor/LanguageEditor.cs index 8afc0f41..885ec7b5 100644 --- a/Assets/Fungus/Flowchart/Editor/LanguageEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/LanguageEditor.cs @@ -59,6 +59,8 @@ namespace Fungus string csvData = language.GetCSVData(); File.WriteAllText(path, csvData); AssetDatabase.Refresh(); + + ShowNotification(language); } public virtual void ExportStandardText(Language language) @@ -72,8 +74,10 @@ namespace Fungus string textData = language.GetStandardText(); File.WriteAllText(path, textData); AssetDatabase.Refresh(); - } + ShowNotification(language); + } + public virtual void ImportStandardText(Language language) { string path = EditorUtility.OpenFilePanel("Import Standard Text", "Assets/", "txt"); @@ -83,7 +87,19 @@ namespace Fungus } string textData = File.ReadAllText(path); - language.SetStandardText(textData); + language.SetStandardText(textData); + + ShowNotification(language); + } + + protected virtual void ShowNotification(Language language) + { + EditorWindow window = EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart"); + if (window != null) + { + window.ShowNotification(new GUIContent(language.notificationText)); + language.notificationText = ""; + } } } diff --git a/Assets/Fungus/Flowchart/Scripts/Language.cs b/Assets/Fungus/Flowchart/Scripts/Language.cs index 4c9e601a..940f2299 100644 --- a/Assets/Fungus/Flowchart/Scripts/Language.cs +++ b/Assets/Fungus/Flowchart/Scripts/Language.cs @@ -1,4 +1,7 @@ using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif using System; using System.Collections; using System.Collections.Generic; @@ -35,6 +38,12 @@ namespace Fungus */ public TextAsset localizationFile; + /** + * Stores any notification message from export / import methods. + */ + [NonSerialized] + public string notificationText = ""; + public virtual void Start() { if (activeLanguage.Length > 0 && @@ -102,7 +111,7 @@ namespace Fungus rowCount++; } - Debug.Log("Exported " + rowCount + " localization text items."); + notificationText = "Exported " + rowCount + " localization text items."; return csvData; } @@ -364,6 +373,10 @@ namespace Fungus if (say.itemId == itemId && say.storyText != newText) { + #if UNITY_EDITOR + Undo.RecordObject(say, "Set Text"); + #endif + say.storyText = newText; return true; } @@ -393,6 +406,10 @@ namespace Fungus if (menu.itemId == itemId && menu.text != newText) { + #if UNITY_EDITOR + Undo.RecordObject(menu, "Set Text"); + #endif + menu.text = newText; return true; } @@ -416,6 +433,10 @@ namespace Fungus if (character != null && character.nameText != newText) { + #if UNITY_EDITOR + Undo.RecordObject(character, "Set Text"); + #endif + character.nameText = newText; return true; } @@ -449,7 +470,7 @@ namespace Fungus rowCount++; } - Debug.Log("Exported " + rowCount + " standard text items."); + notificationText = "Exported " + rowCount + " standard text items."; return textData; } @@ -512,7 +533,7 @@ namespace Fungus } } - Debug.Log("Updated " + updatedCount + " standard text items."); + notificationText = "Updated " + updatedCount + " standard text items."; } }