public void Insert(IClipboardItem item) { if (item != null && !items.Contains(item)) { items.Add(item); } }
private ICommandResult Set(CommandContext context) { string indexText = context.GetParameterValue(ClipboardConstants.PARAMETER_INDEX); if (string.IsNullOrWhiteSpace(indexText)) { indexText = "0"; } if (!int.TryParse(indexText, out int index)) { return(new ErrorTextResult("Invalid index.")); } IClipboardItem item = service.SetClipboardFromHistory(service.HistoryCount - index); if (item == null) { return(new ErrorTextResult($"An item with index {index} hasn't been found.")); } MarkdownBuilder itemBuilder = new MarkdownBuilder(); itemBuilder.CodeBlock(string.Empty, item.Content); return(new ItemsResult(ViewItem.AsMarkdown(itemBuilder.ToString()))); }
private void HandleSelectedItem(ItemAction action) { if (ClipDataManager.Instance.Items.Count == 0 || ListBoxClipboardItems.SelectedIndex == -1) { return; } IClipboardItem selectedItem = ListBoxClipboardItems.SelectedItem as IClipboardItem; if (selectedItem == null) { return; } switch (action) { case ItemAction.ItemCopy: if (!ClipDataManager.Instance.CopyDataToClipboard(selectedItem)) { MessageBox.Show(ClipDataManager.Instance.Status, $"{Title}: Copy to clipboard failed", MessageBoxButton.OK, MessageBoxImage.Error); } break; case ItemAction.ItemFileCopy: if (selectedItem.Type == DataKind.PlainText && ClippySettings.Instance.UseClipboardFiles) { if (!ClipDataManager.Instance.WriteDataToFile(selectedItem.Index)) { MessageBox.Show( $"Saving failed: {Environment.NewLine}{ClipDataManager.Instance.Status}", $"{Title} - Save content to file...", MessageBoxButton.OK, MessageBoxImage.Error); } } break; case ItemAction.ItemEdit: ContentViewWindow contentViewWindow = new ContentViewWindow(selectedItem); contentViewWindow.ShowDialog(); if (contentViewWindow.ContentChanged) { ListBoxClipboardItems.Items.Refresh(); } break; case ItemAction.ItemDelete: ClipDataManager.Instance.RemoveItem(selectedItem.Index); break; default: break; } }
/// <summary> /// Assigns source identification details to a serialized item (i.e. that came from a KO document). /// </summary> /// <param name="item"></param> /// <param name="guid"></param> /// <param name="selectionDocumentInstanceUid"></param> public static void AssignSourceInfo(this IClipboardItem item, Guid guid, string selectionDocumentInstanceUid) { var metadata = item.ExtensionData.GetOrCreate <KeyImageItemMetaData>(); metadata.Changes = false; metadata.Guid = guid; metadata.KoSopInstanceUid = selectionDocumentInstanceUid; metadata.OriginalItem = item; }
/// <summary> /// Gets the identification Guid of a serialized item (i.e. that came from a KO document). /// Throws exception if item is not previously serialized. /// </summary> /// <param name="item"></param> /// <returns></returns> public static Guid GetGuid(this IClipboardItem item) { var guid = item.ExtensionData.GetOrCreate <KeyImageItemMetaData>().Guid; if (!guid.HasValue) { throw new InvalidOperationException("Item has not been serialized yet"); } return(guid.Value); }
/// <summary> /// Gets the selection document instance UID of a serialized item (i.e. the SOP instance UID of the source KO document). /// Throws exception if item is not previously serialized. /// </summary> /// <param name="item"></param> /// <returns></returns> public static string GetSelectionDocumentInstanceUid(this IClipboardItem item) { var sopInstanceUid = item.ExtensionData.GetOrCreate <KeyImageItemMetaData>().KoSopInstanceUid; if (sopInstanceUid == null) { throw new InvalidOperationException("Item has not been serialized yet"); } return(sopInstanceUid); }
/// <summary> /// Copies the data of the given item to the clipboard /// </summary> /// <param name="index">Index of the clipboard item</param> /// <returns></returns> public bool CopyDataToClipboard(long index) { IClipboardItem matchingItem = m_items.FirstOrDefault(i => i.Index == index); if (matchingItem == null) { m_status = $" Failed to copy data to the clipboard. No item with index '{index}' found."; return(false); } return(CopyDataToClipboard(matchingItem)); }
private ICommandResult History(CommandContext context) { if (context.HasOption(ClipboardConstants.OPTION_CLEAR)) { service.ClearHistory(); return(new TextResult("Clipboard history has been cleared.")); } var builder = ImmutableList <ViewItem> .Empty.ToBuilder(); foreach (string argStrIndex in context.GetParameterValues(ClipboardConstants.PARAMETER_INDEX)) { if (!int.TryParse(argStrIndex, out int argIndex)) { continue; } IClipboardItem item = service.GetHistoryItem(argIndex); if (item == null) { continue; } MarkdownBuilder itemBuilder = new MarkdownBuilder(); itemBuilder.Header(argIndex.ToString(), 3); itemBuilder.CodeBlock(string.Empty, item.Content); builder.Add(ViewItem.AsMarkdown(itemBuilder.ToString())); } if (builder.Count > 0) { return(new ItemsResult(builder.ToImmutable())); } int index = 0; foreach (IClipboardItem item in service.GetHistory()) { MarkdownBuilder itemBuilder = new MarkdownBuilder(); itemBuilder.Header((++index).ToString(), 3); itemBuilder.CodeBlock(string.Empty, item.Thumbnail); builder.Add(ViewItem.AsMarkdown(itemBuilder.ToString())); } if (builder.Count <= 0) { return(new TextResult("Clipboard history is empty.")); } return(new ItemsResult(builder.ToImmutable())); }
private void ModifyClipboard(IClipboardItem item) { if (Configuration.SimplifyText && System.Windows.Forms.Clipboard.ContainsText()) { System.Windows.Forms.Clipboard.Clear(); System.Windows.Forms.Clipboard.SetText(item.Content); } else if (Configuration.ConvertFilesToPaths && System.Windows.Forms.Clipboard.ContainsFileDropList()) { System.Windows.Forms.Clipboard.Clear(); System.Windows.Forms.Clipboard.SetText(item.Content); } }
public static bool RevertKeyImage(this IClipboardItem item, KeyImageInformation context) { var guid = GetGuid(item); if (context != null && IsSerialized(item)) { var clipboardItems = context.Items; var result = clipboardItems.Where(k => IsSerialized(k) && GetGuid(k) == guid).Select((k, i) => new { k.Item, Index = i, MetaData = k.ExtensionData.GetOrCreate <KeyImageItemMetaData>() }).FirstOrDefault(); if (result != null) { clipboardItems[result.Index] = result.MetaData.OriginalItem; return(true); } } return(false); }
private void SaveClipboardItem(IClipboardItem item) { if (history.Contains(item)) { return; } history.Add(item); if (history.Count > HISTORY_SIZE) { IClipboardItem itemToDelete = history[0]; historySet.Remove(itemToDelete); history.RemoveAt(0); } }
private void ClipboardItemView_ClickHandler(object sender, ItemAction action, ClipboardItemEventArgs e) { IClipboardItem currentItem = ((FrameworkElement)sender).DataContext as IClipboardItem; if (currentItem != null) { switch (action) { case ItemAction.ItemCopy: if (!ClipDataManager.Instance.CopyDataToClipboard(currentItem)) { MessageBox.Show(ClipDataManager.Instance.Status, $"{Title}: Copy to clipboard failed", MessageBoxButton.OK, MessageBoxImage.Error); } break; case ItemAction.ItemFileCopy: if (!ClipDataManager.Instance.WriteDataToFile(currentItem.Index)) { MessageBox.Show( "Saving failed: " + Environment.NewLine + ClipDataManager.Instance.Status, Title + " - Save content to file...", MessageBoxButton.OK, MessageBoxImage.Error); } break; case ItemAction.ItemEdit: ContentViewWindow contentViewWindow = new ContentViewWindow(currentItem); contentViewWindow.ShowDialog(); if (contentViewWindow.ContentChanged) { ListBoxClipboardItems.Items.Refresh(); } break; case ItemAction.ItemDelete: ClipDataManager.Instance.RemoveItem(currentItem.Index); break; default: break; } } }
public bool WriteDataToFile(long index) { IClipboardItem matchingItem = m_items.FirstOrDefault(i => i.Index == index); if (matchingItem == null) { m_status = $" Failed to write data to file. No item with index '{index}' found."; return(false); } if (matchingItem.Type != DataKind.PlainText) { m_status = $"Failed to get data from file. Item type '{matchingItem.Type}' not supported."; return(false); } string text = ((PlainTextItem)matchingItem).GetText(); return(WriteTextToFile(text)); }
public IClipboardItem SetClipboardFromHistory(int index) { index = history.Count - 1 - index; if (index < 0 || index >= history.Count) { return(null); } if (monitor.InvokeRequired) { return((IClipboardItem)monitor.Invoke((Func <IClipboardItem>)(() => SetClipboardFromHistory(index)))); } IClipboardItem item = history[index]; System.Windows.Forms.Clipboard.Clear(); System.Windows.Forms.Clipboard.SetText(item.Content); return(item); }
public ContentViewWindow(IClipboardItem item) { m_item = item; InitializeComponent(); ContentChanged = false; bool saveFlag = ClippySettings.Instance.SaveWindowLayoutState; TitleLabel.Text = m_item.Title; switch (m_item.Type) { case DataKind.PlainText: TextEditorPage textEditor = new TextEditorPage(((PlainTextItem)m_item).GetText()); textEditor.FontComboBox.IsEnabled = false; textEditor.FontComboBox.Visibility = Visibility.Collapsed; if (saveFlag) { textEditor.SetFontSize(ClippySettings.Instance.FontSize); } ContentFrame.Navigate(textEditor); break; case DataKind.Image: ContentFrame.Navigate(new ImageViewerPage(((ImageItem)m_item).GetImage())); break; case DataKind.Undefined: throw new InvalidOperationException("Undefined clipboard item type"); default: throw new InvalidOperationException("Unkown clipboard item type"); } if (saveFlag) { ClippySettings.Instance.RestoreWindowLayout(this); } }
/// <summary> /// Removes the item with the given index from the list /// </summary> public bool RemoveItem(long index) { if (m_items == null || m_items.Count == 0) { m_status = $"Removed no item with index '{index}'. List is empty"; return(false); } IClipboardItem matchingItem = m_items.FirstOrDefault(i => i.Index == index); if (matchingItem == null) { m_status = $"No item with index '{index}' found to remove"; return(false); } ClipboardItemEventArgs args = new ClipboardItemEventArgs(matchingItem); m_items.Remove(matchingItem); ItemsChanged(ItemsChangeType.ItemRemoved, args); m_status = $"Removed item with index '{index}'"; return(true); }
private void HandleClipboardChanged(object sender, EventArgs e) { IClipboardItem item = null; if (System.Windows.Forms.Clipboard.ContainsText()) { item = new ClipboardItem(System.Windows.Forms.Clipboard.GetText()); } if (System.Windows.Forms.Clipboard.ContainsFileDropList()) { item = new ClipboardItem(ToFileList(System.Windows.Forms.Clipboard.GetFileDropList())); } if (item == null || item.Hash == 0 || item.Content.Length > 16384) { return; } SaveClipboardItem(item); ModifyClipboard(item); }
public static void Clear() { item = null; }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { ClipboardItem = DataContext as IClipboardItem; UpdateCopyFileButtonVisibility(); }
public ClipboardItemEventArgs(IClipboardItem item) { ItemIndex = item.Index; ItemName = item.Title; ItemType = item.Type; }
public static void Clear() { item = null; }
public PasteCommand(IDiagram diagram) { _diagram = diagram; _elements = Clipboard.Item; }
/// <summary> /// Copies the data of the given item to the clipboard /// </summary> public bool CopyDataToClipboard(IClipboardItem itemToCopy) { if (!itemToCopy.HasData) { m_status = $" Failed to copy data to the clipboard. Given item has no data"; return(false); } bool clipboardBlocked = false; switch (itemToCopy.Type) { case DataKind.PlainText: try { Clipboard.SetText(((PlainTextItem)itemToCopy).GetText()); } catch (Exception) { try { FreeAndClearClipboard(); Clipboard.SetText(((PlainTextItem)itemToCopy).GetText()); } catch (Exception) { clipboardBlocked = true; } } break; case DataKind.Image: try { Clipboard.SetImage(((ImageItem)itemToCopy).GetImage()); } catch (Exception) { try { FreeAndClearClipboard(); Clipboard.SetImage(((ImageItem)itemToCopy).GetImage()); } catch (Exception) { clipboardBlocked = true; } } break; default: m_status = $" Failed to copy data to the clipboard. Unsupported item type: {itemToCopy.Type.ToString()}"; return(false); } if (clipboardBlocked) { string blockingWindow = StaticHelper.GetOpenClipboardWindowInfo(); m_status = $" Failed to copy data to the clipboard. Cliboard is blocked by another process: {blockingWindow}"; return(false); } return(true); }
/// <summary> /// Gets whether or not the item has previously been serialized to a KO document. /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool IsSerialized(this IClipboardItem item) { return(item.ExtensionData.GetOrCreate <KeyImageItemMetaData>().Guid.HasValue); }
/// <summary> /// Gets a value indicating whether or not the item has unserialized changes. /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool HasChanges(this IClipboardItem item) { return(item.ExtensionData.GetOrCreate <KeyImageItemMetaData>().Changes); }
/// <summary> /// Flags an item as having unserialized changes. /// </summary> /// <param name="item"></param> public static void FlagHasChanges(this IClipboardItem item) { item.ExtensionData.GetOrCreate <KeyImageItemMetaData>().Changes = true; }
private static bool CanRevertItem(IClipboardItem item) { return(item.IsSerialized() && item.HasChanges()); }
public bool Equals(IClipboardItem other) { return(other != null && Hash == other.Hash); }