// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using System.Windows; using Flow.Launcher.Plugin; using Flow.Plugin.WindowsSettings.Classes; using Flow.Plugin.WindowsSettings.Properties; namespace Flow.Plugin.WindowsSettings.Helper { /// /// Helper class to easier work with context menu entries /// internal static class ContextMenuHelper { /// /// Return a list with all context menu entries for the given /// Symbols taken from /// /// The result for the context menu entires /// The name of the this assembly /// A list with context menu entries internal static List GetContextMenu(in Result result, in string assemblyName) { if (result?.ContextData is not WindowsSetting entry) { return new List(0); } var list = new List(1) { new() { Action = _ => TryToCopyToClipBoard(entry.Command), Title = $"{Resources.CopyCommand} (Ctrl+C)", }, }; return list; } /// /// Copy the given text to the clipboard /// /// The text to copy to the clipboard /// The text successful copy to the clipboard, otherwise private static bool TryToCopyToClipBoard(in string text) { try { Clipboard.Clear(); Clipboard.SetText(text); return true; } catch (Exception exception) { Log.Exception("Can't copy to clipboard", exception, typeof(Main)); return false; } } } }