示例#1
0
        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;
            }
        }
示例#2
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;
                }
            }
        }