private void PasteFavorites() { int Index = SelectedIndex; ClipItem Clip = fFavorites[Index]; fMainForm.Paste(Clip); }
private void MFUDrawItem(object sender, DrawItemEventArgs e) { if (e.Index != -1 && e.Index < fMFU.Count) { Graphics g = e.Graphics; ClipItem Clip = fMFU[e.Index]; Clip.Draw(g, e.Bounds, e.State, e.Font); g.Dispose(); } }
/// <summary> /// clip item is select event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClipItem_Selected(object sender, ClipItem.ClipItemEventArgs e) { var currentItem = sender as ClipItem; if (null != this._selectedClipItem) { this._selectedClipItem.IsSelected = false; } this._selectedClipItem = currentItem; }
private void MFUMeasureItem(object sender, MeasureItemEventArgs e) { if (e.Index != -1 && e.Index < fMFU.Count) { ClipItem Clip = fMFU[e.Index]; int W = e.ItemWidth, H = e.ItemHeight; Clip.Measure(e, Font, ref W, ref H); e.ItemWidth = W; e.ItemHeight = H; } }
private static void CopyToEditor() { ClipItem item = new ClipItem(ContentType.File); foreach (var guiD in Selection.assetGUIDs) { string path = AssetDatabase.GUIDToAssetPath(guiD); item.Values.Add(PathUtil.AssetPath2FullPath(path)); } CopyClipboardItem(item); Debug.Log("已复制" + Selection.assetGUIDs.Length + "条数据,可在其他 Unity 编辑器里粘贴!"); }
public void MoveDown() { int Index = SelectedIndex; if (Index != -1 && Index < (Items.Count - 1)) { ClipItem Clip = fMFU[Index]; fMFU.RemoveAt(Index); fMFU.Insert(Index + 1, Clip); SelectedIndex = Index + 1; } Refresh(); }
public void MoveUp() { int Index = SelectedIndex; if (Index > 0) { ClipItem Clip = fMFU[Index]; fMFU.RemoveAt(Index); fMFU.Insert(Index - 1, Clip); SelectedIndex = Index - 1; } Refresh(); }
private void MFUDragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) { ClipItem Clip = new ClipItem((string)(e.Data.GetData(DataFormats.Text)), true); // add the selected string to bottom of list fMFU.Add(Clip); Items.Add(e.Data.GetData(DataFormats.Text)); //Refresh Refresh(); } }
private static readonly string KeyAutoRefresh = "kAutoRefresh"; // 请勿修改 public static void CopyClipboardItem(ClipItem item) { BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, item); TextEditor te = new TextEditor { text = Convert.ToBase64String(stream.ToArray()) }; te.OnFocus(); te.Copy(); } }
private void CopyFileImage(ClipItem item) { Bitmap img = Bitmap.FromFile(item.Content) as Bitmap; var source = Imaging.CreateBitmapSourceFromHBitmap( img.GetHbitmap() , IntPtr.Zero , System.Windows.Int32Rect.Empty , BitmapSizeOptions.FromWidthAndHeight(img.Width, img.Height)); Clipboard.SetImage(source); img.Dispose(); }
private void ClipsDragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) { if (!fMainForm.fFromClips && !fMainForm.fFromFavorites && !fMainForm.fFromMFU) { ClipItem Clip = new ClipItem((string)(e.Data.GetData(DataFormats.Text)), true); // add the selected string to bottom of list fClips.Add(Clip); Items.Add(e.Data.GetData(DataFormats.Text)); } if (fMainForm.fFromFavorites) { int IndexItem = fMainForm.fIndexToDragFromFavorites; if (IndexItem >= 0 && IndexItem < fMainForm.listBoxFavorites.Items.Count) { int Index = 0; try { Index = int.Parse((string)e.Data.GetData(DataFormats.Text)); } catch (Exception) { Console.WriteLine("Erreur de parsing"); } ClipItem Clip = fMainForm.listBoxFavorites.fFavorites[Index]; fClips.Add(Clip); Items.Add(fClips.Count.ToString()); } fMainForm.fFromFavorites = false; } //Refresh Refresh(); } #if ADVANCED_DRAG_AND_DROP Point p = Cursor.Position; Win32Point wp; wp.x = p.X; wp.y = p.Y; IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper(); dropHelper.Drop((ComIDataObject)e.Data, ref wp, (int)e.Effect); #endif }
private void CopyCommandExecute(ClipItem item) { if (item.Content == null) { return; } if (item.IsFile) { if (File.Exists(item.Content)) { switch (Path.GetExtension(item.Content).ToLower()) { case ".jpg": case ".jpeg": case ".png": case ".gif": case ".bmp": CopyFileImage(item); break; case ".txt": case ".log": case ".cfg": case ".csv": case ".html": case ".xaml": case ".xml": case ".md": case ".tex": case ".sql": case ".ini": CopyFileText(item); break; default: CopyFileDrop(item); break; } } } else { Clipboard.SetText(item.Content); } }
private static void CopyAsPackage() { string[] assetPaths = new string[Selection.assetGUIDs.Length]; for (int i = 0; i < Selection.assetGUIDs.Length; i++) { assetPaths[i] = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[i]); } string outPath = Path.Combine(Application.temporaryCachePath, Random.Range(0, 1024) + ".unitypackage"); AssetDatabase.ExportPackage(assetPaths, outPath, ExportPackageOptions.Recurse | ExportPackageOptions.IncludeDependencies); ClipItem item = new ClipItem(ContentType.Package); item.Values.Add(outPath); CopyClipboardItem(item); Debug.Log("已导出选中资源!可直接粘贴至任意Assets目录!"); }
public MainViewModel() { LoadSettings(); CopyCommand = new RelayCommand <ClipItem>(CopyCommandExecute); AddCommand = new RelayCommand(o => { SelectedItem = new ClipItem(); ClipItems.Add(SelectedItem); }); RemoveCommand = new RelayCommand(o => { ClipItems.Remove(SelectedItem); }, o => SelectedItem != null); ToggleAlwaysOnTopCommand = new RelayCommand <Window>(wnd => { wnd.Topmost = Settings.Default.AlwaysOnTop; }); }
/// <summary> /// Handles when the clipboard has changed by adding the item to the list if it doesn't already exist /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void OnClipboardChanged(object sender, ClipboardChangedEventArgs e) { if (!IsBoardEnabled) return; // Check to see that the board is accepting new items if (IsSendingToClipboard) return; // Check to make sure we aren't setting data on the clipboard from Korkboard if (AlreadyExists(e.Data)) // Check to see if the item already exists { SelectedItem = GetItemForData(e.Data); return; } string format = ClipItem.GetFormat(e.Data); if ( (!Settings.IsTextCopyEnabled && format.CompareEx(DataFormats.Text)) || (!Settings.IsFileCopyEnabled && format.CompareEx(ClipItem.FileList)) || (!Settings.IsImageCopyEnabled && format.CompareEx(ClipItem.BitmapSourceFormat))) { SelectedItem = null; return; } // Trim the list if necessary if (Settings.ItemNumberLimit > 0 && BoardPanel.Children.Count > Settings.ItemNumberLimit) PopItemOffStack(); // Create the clip item ClipItem ci = new ClipItem(e.Data); ci.MouseLeftButtonUp += OnClipItemClicked; ci.IsPinnedChanged += OnIsPinnedChanged; int i = 0; for (i = 0; i < BoardPanel.Children.Count; i++) { ClipItem child = BoardPanel.Children[i] as ClipItem; if (child != null && !child.IsPinned) break; } BoardPanel.Children.Insert(i, ci); // Make it look like the trashbin is full TrashBinIcon.IsSelected = false; // Set the current item as "selected" SelectedItem = ci; }
private void CopyFileText(ClipItem item) { Clipboard.SetText(File.ReadAllText(item.Content)); }
private void CopyFileDrop(ClipItem item) { var data = Clipboard.GetData(System.Windows.DataFormats.FileDrop); Clipboard.SetData(System.Windows.DataFormats.FileDrop, new string[] { item.Content }); }
/// <summary> /// initialize /// </summary> private void Initialize() { this._settings = AppData.GetInstance(); this._items = this._settings.Items; this.ContentRendered += (sender, e) => { this.SetWindowsState(true); }; // set window position if (0 <= this._settings.Pos.X && (this._settings.Pos.X + this.Width) < SystemParameters.VirtualScreenWidth) { this.Left = this._settings.Pos.X; } if (0 <= this._settings.Pos.Y && (this._settings.Pos.Y + this.Height) < SystemParameters.VirtualScreenHeight) { this.Top = this._settings.Pos.Y; } // initialize tab this.cTab.TabSelected += Tab_TabSelected; this._currentTab = AppData.GetInstance().SelectedTab; this.cTab.SelectTab(this._currentTab); // initalize saved data while (this._items.Count < Constant.TabCount) { this._items.Add(new List <string>()); } foreach (var items in this._items) { while (items.Count < Constant.ItemCount) { items.Add(""); } } // create grid item for (int i = 0; i < Constant.ItemCount; i++) { this.cContainer.RowDefinitions.Add(new RowDefinition()); // add label var text = new TextBlock(); text.Text = (i + 1).ToString(); text.Width = 20; text.VerticalAlignment = VerticalAlignment.Center; text.TextAlignment = TextAlignment.Center; text.FontSize = 14; Grid.SetRow(text, i + GridOffset); Grid.SetColumn(text, 0); this.cContainer.Children.Add(text); // add clip item var clipItem = new ClipItem(); clipItem.ClipItemSelected += ClipItem_Selected; clipItem.Text = this._items[this._currentTab][i]; Grid.SetRow(clipItem, i + GridOffset); Grid.SetColumn(clipItem, 1); this.cContainer.Children.Add(clipItem); this._clipItems.Add(clipItem); } // set title var fullname = typeof(App).Assembly.Location; var info = System.Diagnostics.FileVersionInfo.GetVersionInfo(fullname); this.Title = $"MyClipBoard({info.FileVersion})"; // register hot key this._hotkey.Register(ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt, Key.P, (_, __) => { if (!this.ShowInTaskbar) { this.SetWindowsState(false); } else { if (this.WindowState == WindowState.Minimized) { this.WindowState = WindowState.Normal; } this.Activate(); } } ); // set up notify icon this._notifyIcon.Text = "MyClipBoard"; this._notifyIcon.Icon = new System.Drawing.Icon("app.ico"); var menu = new System.Windows.Forms.ContextMenuStrip(); var menuItemShow = new System.Windows.Forms.ToolStripMenuItem { Text = "show" }; menuItemShow.Click += this.NotifyMenuShow_Click; menu.Items.Add(menuItemShow); var menuItemExit = new System.Windows.Forms.ToolStripMenuItem { Text = "exit" }; menuItemExit.Click += this.NotifyMenuExit_Click; menu.Items.Add(menuItemExit); this._notifyIcon.ContextMenuStrip = menu; this._notifyIcon.Visible = false; }