private void CopyToClipboard(ClipboardDataItem item)
 {
     _clipboardService.SetClipboardText(item.Data, errorItem =>
     {
         HistoryCollection.AddItem(errorItem);
     });
 }
 private void AddStringToHistoryCollection(ClipboardDataItem item)
 {
     if (!String.IsNullOrEmpty(item.Data))
     {
         HistoryCollection.AddItem(item);
     }
 }
Exemplo n.º 3
0
 public void SetClipboardText(string text, Action <ClipboardDataItem> errorCallback)
 {
     DisableNotifications();
     try
     {
         Clipboard.SetText(text);
     }
     catch (Exception ex)
     {
         var item = new ClipboardDataItem(string.Format(Resources.ClipboardException, ex.Message), true);
         errorCallback?.Invoke(item);
     }
     EnableNotifications();
 }
Exemplo n.º 4
0
        private string ApplyIndentation(string text, Dictionary <int, int> levels)
        {
            string result = string.Empty;

            string[] lines = ClipboardDataItem.GetArrayOfLines(text);

            for (int i = 0; i < lines.Length; i++)
            {
                string line    = lines[i];
                int    padSize = (levels.ContainsKey(i)) ? line.Length + (levels[i] * IndentationNumber) : 0;
                result += line.PadLeft(padSize, IndentationCharacter);
                if ((lines.Length - 1) != i)
                {
                    result += Environment.NewLine;
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        private static Dictionary <int, int> GetIndentationLevels(string text)
        {
            var levels = new Dictionary <int, int>();

            string[] lines = ClipboardDataItem.GetArrayOfLines(text);

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                // Matches everything from start of line to first non-whitespace char or end of line.
                Match match = Regex.Match(line, @"^(?<indent>([\s]{1,}))([\S]{1,}|$)");
                Group group = match.Groups["indent"];
                // Matches 1 tabulation or 4 spaces.
                MatchCollection matches = Regex.Matches(group.Value, @"([\t]{1}|[\u0020]{4})");
                if (line.Length > group.Value.Length)
                {
                    levels.Add(i, matches.Count);
                }
            }
            return(levels);
        }
Exemplo n.º 6
0
        private static string GetUniqueKey(Message message, ClipboardDataItem data)
        {
            var key = $"{message.HWnd}{message.Msg}{data.Snippet}{data.NumberOfLines}";

            return(Convert.ToBase64String(Encoding.Default.GetBytes(key)));
        }
 private void OnClipboardUpdate(ClipboardDataItem item)
 {
     AddStringToHistoryCollection(item);
 }
 private void DeleteItem(ClipboardDataItem item)
 {
     HistoryCollection.Remove(item);
 }
 private bool CanDeleteItem(ClipboardDataItem item)
 {
     return(true);
 }
 private bool CanCopyToClipboard(ClipboardDataItem item)
 {
     return(true);
 }
Exemplo n.º 11
0
        private static string RemoveIndentation(string text)
        {
            var trimmedLines = ClipboardDataItem.GetArrayOfLines(text).Select(line => line.TrimStart());

            return(string.Join(Environment.NewLine, trimmedLines));
        }