using System; using System.Threading; //using System.Windows.Forms; namespace Gwen.Platform { /// /// Platform-agnostic utility functions. /// public static class Neutral { private static DateTime m_LastTime; private static float m_CurrentTime; /* /// /// Changes the mouse cursor. /// /// Cursor type. public static void SetCursor(Cursor cursor) { Cursor.Current = cursor; } */ /// /// Gets text from clipboard. /// /// Clipboard text. public static String GetClipboardText() { // code from http://forums.getpaint.net/index.php?/topic/13712-trouble-accessing-the-clipboard/page__view__findpost__p__226140 String ret = String.Empty; /* Thread staThread = new Thread( () => { try { if (!Clipboard.ContainsText()) return; ret = Clipboard.GetText(); } catch (Exception) { return; } }); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); staThread.Join(); // at this point either you have clipboard data or an exception */ return ret; } /// /// Sets the clipboard text. /// /// Text to set. /// True if succeeded. public static bool SetClipboardText(String text) { bool ret = false; /* Thread staThread = new Thread( () => { try { Clipboard.SetText(text); ret = true; } catch (Exception) { return; } }); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); staThread.Join(); // at this point either you have clipboard data or an exception */ return ret; } /// /// Gets time since last measurement. /// /// Time interval in seconds. public static float GetTimeInSeconds() { var time = DateTime.UtcNow; var diff = time - m_LastTime; var seconds = diff.TotalSeconds; if (seconds > 0.1) seconds = 0.1; m_CurrentTime += (float)seconds; m_LastTime = time; return m_CurrentTime; } /// /// Displays an open file dialog. /// /// Dialog title. /// Initial path. /// File extension filter. /// Callback that is executed after the dialog completes. /// True if succeeded. public static bool FileOpen(String title, String startPath, String extension, Action callback) { /* var dialog = new OpenFileDialog { Title = title, InitialDirectory = startPath, DefaultExt = @"*.*", Filter = extension, CheckPathExists = true, Multiselect = false }; if (dialog.ShowDialog() == DialogResult.OK) { if (callback != null) { callback(dialog.FileName); } } else { if (callback != null) { callback(String.Empty); } return false; } return true; */ return false; } /// /// Displays a save file dialog. /// /// Dialog title. /// Initial path. /// File extension filter. /// Callback that is executed after the dialog completes. /// True if succeeded. public static bool FileSave(String title, String startPath, String extension, Action callback) { /* var dialog = new SaveFileDialog { Title = title, InitialDirectory = startPath, DefaultExt = @"*.*", Filter = extension, CheckPathExists = true, OverwritePrompt = true }; if (dialog.ShowDialog() == DialogResult.OK) { if (callback != null) { callback(dialog.FileName); } } else { if (callback != null) { callback(String.Empty); } return false; } return true; */ return false; } } }