private void AddItem([NotNull] string displayText, [NotNull] string textToCopy, Image image, char?hotkey) { if (hotkey.HasValue) { int position = displayText.IndexOf(hotkey.Value.ToString(), StringComparison.InvariantCultureIgnoreCase); if (position >= 0) { displayText = displayText.Insert(position, "&"); } } else { displayText = PrependItemNumber(displayText); } var item = new ToolStripMenuItem { Text = displayText.TrimEnd('\r', '\n'), ShowShortcutKeys = true, Image = image }; item.Click += delegate { ClipboardUtil.TrySetText(textToCopy); }; DropDownItems.Add(item); }
void otpCopyToolStripItem_Click(object sender, EventArgs e) { PwEntry entry; if (this.GetSelectedSingleEntry(out entry)) { if (!entry.Strings.Exists(OtpAuthData.StringDictionaryKey)) { if (MessageBox.Show("Must configure TOTP on this entry. Do you want to do this now?", "Not Configured", MessageBoxButtons.YesNo) == DialogResult.Yes) { ShowOneTimePasswords form = new ShowOneTimePasswords(entry, host); form.ShowDialog(); } } else { var data = OtpAuthData.FromString(entry.Strings.Get(OtpAuthData.StringDictionaryKey).ReadString()); var totp = new Totp(data.Key, step: data.Step, mode: data.OtpHashMode, totpSize: data.Size); var text = totp.ComputeTotp().ToString().PadLeft(data.Size, '0'); if (ClipboardUtil.CopyAndMinimize(new KeePassLib.Security.ProtectedString(true, text), true, this.host.MainWindow, entry, this.host.Database)) { this.host.MainWindow.StartClipboardCountdown(); } } } }
protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes) { PPMouse.Coordinates coordinates = PPMouse.RightClickCoordinates; DocumentWindow activeWindow = this.GetCurrentWindow(); float positionX = 0; float positionY = 0; if (activeWindow.ActivePane.ViewType == PpViewType.ppViewSlide) { int xref = activeWindow.PointsToScreenPixelsX(100) - activeWindow.PointsToScreenPixelsX(0); int yref = activeWindow.PointsToScreenPixelsY(100) - activeWindow.PointsToScreenPixelsY(0); positionX = ((coordinates.X - activeWindow.PointsToScreenPixelsX(0)) / xref) * 100; positionY = ((coordinates.Y - activeWindow.PointsToScreenPixelsY(0)) / yref) * 100; } ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide); if (pastingShapes == null) { Logger.Log("PasteLab: Could not paste clipboard contents."); MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle); return(null); } return(PasteAtCursorPosition.Execute(presentation, slide, pastingShapes, positionX, positionY)); }
private void ExecuteBlurAction(string feature, Selection selection, Models.PowerPointPresentation pres, Models.PowerPointSlide slide, int percentage) { ClipboardUtil.RestoreClipboardAfterAction(() => { switch (feature) { case EffectsLabText.BlurrinessFeatureSelected: EffectsLabBlur.ExecuteBlurSelected(slide, selection, percentage); break; case EffectsLabText.BlurrinessFeatureRemainder: EffectsLabBlur.ExecuteBlurRemainder(slide, selection, percentage); break; case EffectsLabText.BlurrinessFeatureBackground: EffectsLabBlur.ExecuteBlurBackground(slide, selection, percentage); break; default: Logger.Log(feature + " does not exist!", Common.Logger.LogType.Error); break; } return(ClipboardUtil.ClipboardRestoreSuccess); }, pres, slide); }
private void DoCopyTriggers(ListViewItem[] vTriggers) { if (vTriggers == null) { return; } try { ClipboardUtil.Clear(); if (vTriggers.Length == 0) { return; } EcasTriggerContainer v = new EcasTriggerContainer(); for (int iTrigger = 0; iTrigger < vTriggers.Length; ++iTrigger) { v.Triggers.Add(vTriggers[iTrigger].Tag as EcasTrigger); } using (MemoryStream ms = new MemoryStream()) { XmlUtilEx.Serialize <EcasTriggerContainer>(ms, v); ClipboardUtil.Copy(StrUtil.Utf8.GetString(ms.ToArray()), false, false, null, null, this.Handle); } } catch (Exception ex) { MessageService.ShowWarning(ex); } }
private void OnCtxToolsPasteTriggers(object sender, EventArgs e) { try { string strData = ClipboardUtil.GetText(); byte[] pbData = StrUtil.Utf8.GetBytes(strData); MemoryStream ms = new MemoryStream(pbData, false); EcasTriggerContainer c = XmlUtilEx.Deserialize <EcasTriggerContainer>(ms); ms.Close(); foreach (EcasTrigger t in c.Triggers) { if (m_triggers.FindObjectByUuid(t.Uuid) != null) { t.Uuid = new PwUuid(true); } m_triggers.TriggerCollection.Add(t); } } catch (Exception ex) { MessageService.ShowWarning(ex); } UpdateTriggerListEx(true); }
private void FieldAction(ToolStripMenuItem Item, string FieldName, FIELD_ACTION action) { if (Item == null) { return; } PwEntry Entry = (PwEntry)Item.Tag; if (Entry == null) { return; } SetLastOne(Item); if (FieldName == PwDefs.PasswordField && PwDefs.IsTanEntry(Entry)) { Entry.ExpiryTime = DateTime.Now; Entry.Expires = true; Host.MainWindow.RefreshEntriesList(); Host.MainWindow.UpdateUI(false, null, false, null, false, null, true); } if (action == FIELD_ACTION.CLIPBOARD_COPY) { ClipboardUtil.CopyAndMinimize(Entry.Strings.GetSafe(FieldName), true, Program.Config.MainWindow.MinimizeAfterClipboardCopy ? Host.MainWindow : null, Entry, Host.MainWindow.DocumentManager.ActiveDatabase); Host.MainWindow.StartClipboardCountdown(); } else if (action == FIELD_ACTION.DRAG_DROP) { Item.DoDragDrop(Entry.Strings.ReadSafe(FieldName), DragDropEffects.Copy); } }
private static string PerformClipboardCopy(string strText, SprContext ctx, uint uRecursionLevel) { string str = strText; int iStart; List <string> lParams; SprContext ctxData = ((ctx != null) ? ctx.WithoutContentTransformations() : null); while (ParseAndRemovePlhWithParams(ref str, ctxData, uRecursionLevel, @"{CLIPBOARD-SET:", out iStart, out lParams, true)) { if (lParams.Count < 1) { continue; } try { ClipboardUtil.Copy(lParams[0] ?? string.Empty, false, true, null, null, IntPtr.Zero); } catch (Exception) { Debug.Assert(false); } } return(str); }
public static void Execute(PowerPointPresentation pres, PowerPointSlide slide, ShapeRange pastingShapes, float slideWidth, float slideHeight) { pastingShapes = ShapeUtil.GetShapesWhenTypeNotMatches(slide, pastingShapes, Microsoft.Office.Core.MsoShapeType.msoPlaceholder); if (pastingShapes.Count == 0) { return; } Shape pastingShape = pastingShapes[1]; if (pastingShapes.Count > 1) { pastingShape = pastingShapes.Group(); } // Temporary house the latest clipboard shapes ShapeRange origClipboardShapes = ClipboardUtil.PasteShapesFromClipboard(pres, slide); // Compression of large image(s) Shape shapeToFitSlide = GraphicsUtil.CompressImageInShape(pastingShape, slide); // Bring the same original shapes back into clipboard, preserving original size origClipboardShapes.Cut(); shapeToFitSlide.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue; PPShape ppShapeToFitSlide = new PPShape(shapeToFitSlide); ResizeShape(ppShapeToFitSlide, slideWidth, slideHeight); ppShapeToFitSlide.VisualCenter = new System.Drawing.PointF(slideWidth / 2, slideHeight / 2); }
protected override void CopyCommand(RowObject rowObject) { if (ClipboardUtil.CopyAndMinimize(rowObject.Value, true, mMainForm, Entry, Database)) { mMainForm.StartClipboardCountdown(); } }
protected override ShapeRange ExecutePasteAction(string ribbonId, PowerPointPresentation presentation, PowerPointSlide slide, ShapeRange selectedShapes, ShapeRange selectedChildShapes) { if (selectedShapes.Count <= 0) { Logger.Log("PasteIntoGroup failed. No valid shape is selected."); return(null); } if (selectedShapes.Count == 1 && !ShapeUtil.IsAGroup(selectedShapes[1])) { Logger.Log("PasteIntoGroup failed. Selection is only a single shape."); return(null); } ShapeRange pastingShapes = ClipboardUtil.PasteShapesFromClipboard(presentation, slide); if (pastingShapes == null) { Logger.Log("PasteLab: Could not paste clipboard contents."); MessageBox.Show(PasteLabText.ErrorPaste, PasteLabText.ErrorDialogTitle); return(null); } return(PasteIntoGroup.Execute(presentation, slide, selectedShapes, pastingShapes)); }
protected void OnCopyUri(string id) { if (string.IsNullOrEmpty(id) || SelectedItem == null) { return; } if (id == "address") { ClipboardUtil.SetText(SelectedItem.Payment.Address); } else if (id == "amount") { ClipboardUtil.SetText((SelectedItem.Payment.Amount / Math.Pow(10, 8)).ToString("0.00000000")); } else if (id == "label") { PaymentToMarkConverter converter = new PaymentToMarkConverter(); var mark = converter.Convert(SelectedItem.Payment, typeof(object), null, new System.Globalization.CultureInfo(1033)); if (mark != null) { ClipboardUtil.SetText(mark.ToString()); } } else if (id == "txid") { ClipboardUtil.SetText(SelectedItem.Payment.TxId); } }
/// <summary> /// Insert shape which is copied from `templatedShape` to slide /// Precondition: shapeName must not exist in slide before applying the method /// </summary> /// <param name="slide"></param> /// <param name="templatedShape">Shape whose format is to be copied over</param> /// <param name="shapeName"></param> /// <param name="text"></param> /// <returns>the copied shape</returns> public static Shape InsertTemplatedShapeToSlide(PowerPointSlide slide, Shape templatedShape, string shapeName, string text) { float slideWidth = PowerPointPresentation.Current.SlideWidth; float slideHeight = PowerPointPresentation.Current.SlideHeight; PowerPointPresentation pres = ActionFrameworkExtensions.GetCurrentPresentation(); Shape copiedShape; // templatedShape and its associated animations are duplicated if (templatedShape == null) { throw new Exception("Templated shape is null"); } try { copiedShape = ClipboardUtil.RestoreClipboardAfterAction(() => { return(slide.Shapes.SafeCopyPlaceholder(templatedShape)); }, pres, slide); } catch { throw new Exception("Error copy and paste shape."); } if (copiedShape == null) { throw new Exception("Copied shape is null"); } copiedShape.Name = shapeName; copiedShape.TextFrame.TextRange.Text = text; copiedShape.TextFrame.WordWrap = MsoTriState.msoTrue; copiedShape.TextFrame.AutoSize = PpAutoSize.ppAutoSizeShapeToFitText; // copy shape to the default callout / caption position if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CalloutIdentifier) { copiedShape.Left = 10; copiedShape.Top = 10; copiedShape.TextEffect.Alignment = MsoTextEffectAlignment.msoTextEffectAlignmentLeft; } else if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CaptionIdentifier) { copiedShape.Left = 0; copiedShape.Top = slideHeight - 100; copiedShape.Width = slideWidth; copiedShape.Height = 100; copiedShape.Top = slideHeight - copiedShape.Height; copiedShape.TextEffect.Alignment = MsoTextEffectAlignment.msoTextEffectAlignmentCentered; } // remove associated animation with copiedShape because we only want the shape to be copied. slide.RemoveAnimationsForShape(copiedShape); if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CaptionIdentifier) { copiedShape.Top = slideHeight - copiedShape.Height; } return(copiedShape); }
private void copyParentHashToolStripMenuItem_Click(object sender, EventArgs e) { if (Warnings is not null && Warnings.SelectedRows.Count != 0 && Warnings.SelectedRows[0].DataBoundItem is not null) { var lostObject = (LostObject)Warnings.SelectedRows[0].DataBoundItem; ClipboardUtil.TrySetText(lostObject.Parent?.ToString()); } }
protected override bool GetEnabled(string ribbonId) { Selection currentSelection = this.GetCurrentSelection(); return(!ClipboardUtil.IsClipboardEmpty() && ShapeUtil.IsSelectionSingleShape(currentSelection) && !ShapeUtil.HasPlaceholderInSelection(currentSelection)); }
protected override void CopyCommand(RowObject rowObject) { if (!IsMultiValuedField(rowObject) && ClipboardUtil.CopyAndMinimize(rowObject.Value, true, mMainForm, Entries.First(), Database)) { mMainForm.StartClipboardCountdown(); } }
private void copyFilenameToClipboardToolStripMenuItem_Click(object sender, EventArgs e) { if (tvGitTree.SelectedNode?.Tag is GitItem gitItem) { var fileName = _fullPathResolver.Resolve(gitItem.FileName); ClipboardUtil.TrySetText(fileName.ToNativePath()); } }
private void buttonCopyTotp_Click(object sender, EventArgs e) { if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, this.totp.ComputeTotp().ToString().PadLeft(data.Size, '0')), true, this.host.MainWindow, entry, this.host.Database)) { this.host.MainWindow.StartClipboardCountdown(); } this.Close(); }
/// <summary> /// Saves shape in storage /// Returns a key to find the shape by, /// or null if the shape cannot be copied /// </summary> /// <param name="shape"></param> /// <param name="formats">Required for msoPlaceholder</param> /// <returns>identifier of copied shape</returns> public string CopyShape(Shape shape, Format[] formats) { #pragma warning disable 618 PowerPointPresentation pres = PowerPointPresentation.Current; PowerPointSlide slide = PowerPointCurrentPresentationInfo.CurrentSlide; Shape copiedShape = null; if (shape.Type == MsoShapeType.msoPlaceholder) { ClipboardUtil.RestoreClipboardAfterAction(() => { copiedShape = ShapeUtil.CopyMsoPlaceHolder(formats, shape, GetTemplateShapes()); return(ClipboardUtil.ClipboardRestoreSuccess); }, pres, slide); } else { try { ClipboardUtil.RestoreClipboardAfterAction(() => { copiedShape = Slides[0].Shapes.SafeCopyPlaceholder(shape); return(ClipboardUtil.ClipboardRestoreSuccess); }, pres, slide); } catch { copiedShape = null; } } #pragma warning restore 618 if (copiedShape == null) { return(null); } string shapeKey = nextKey.ToString(); nextKey++; copiedShape.Name = shapeKey; #pragma warning disable 618 if (Globals.ThisAddIn.IsApplicationVersion2013()) { // sync glow, 2013 gives the wrong Glow.Fill color after copying the shape SyncFormats(shape, copiedShape, _glowFormats); // sync shape fill, 2013 gives the wrong fill color after copying the shape SyncFormats(shape, copiedShape, _fillFormats); // backup artistic effects for 2013 // ForceSave() will make artistic effect permanent on the shapes for 2013 and no longer retrievable List <MsoPictureEffectType> extractedEffects = ArtisticEffectFormat.GetArtisticEffects(copiedShape); _backupArtisticEffects.Add(shapeKey, extractedEffects); } #pragma warning restore 618 ForceSave(); return(shapeKey); }
private void CopyPassword(SearchResult searchResult) { if (ClipboardUtil.Copy(searchResult.Entry.Strings.ReadSafe(PwDefs.PasswordField), true, true, searchResult.Entry, mMainForm.DocumentManager.SafeFindContainerOf(searchResult.Entry), IntPtr.Zero)) { mMainForm.StartClipboardCountdown(); } }
private bool CopyCharToClipboard(char character) { return(ClipboardUtil.CopyAndMinimize( character.ToString(), false, this, null, null)); }
private bool CopyToClipboard(String characters) { return(ClipboardUtil.CopyAndMinimize( characters, false, this, null, null)); }
private void OnCommand(string msg) { PayUrlPageMode mode; if (!Enum.TryParse(msg, out mode)) { return; } switch (mode) { case PayUrlPageMode.CreateUrl: OnCreate(); break; case PayUrlPageMode.CopyAddress: if (SelectedItem != null) { ClipboardUtil.SetText(SelectedItem.Address); } break; case PayUrlPageMode.CopyLabel: if (SelectedItem == null) { return; } if (string.IsNullOrEmpty(SelectedItem.Tag)) { ShowMessage(LanguageService.Default.GetLanguageValue("Error_EmptyTag")); } else { ClipboardUtil.SetText(SelectedItem.Tag); } break; case PayUrlPageMode.Delete: OnDelete(); break; case PayUrlPageMode.Edit: OnEdit(); break; case PayUrlPageMode.Choose: OnChoose(); break; case PayUrlPageMode.Export: OnExport(); break; default: break; } }
private void buttonCopy_Click(object sender, EventArgs e) { var otp = _yaotp.ComputeOtp(); if (ClipboardUtil.Copy(otp, false, true, _entry, _host.Database, IntPtr.Zero)) { _host.MainWindow.StartClipboardCountdown(); } }
/// <summary> /// 设置剪切板 /// </summary> /// <param name="text"></param> public void SetClip(string text) { if (string.IsNullOrWhiteSpace(text)) { return; } ClipboardUtil.SetClip(text); }
private void OnAutoTypeFilterCompilePre(object sender, AutoTypeEventArgs autoTypeEventArgs) { Regex replacer = new Regex(Regex.Escape(mPlaceholder), RegexOptions.IgnoreCase); autoTypeEventArgs.Sequence = replacer.Replace(autoTypeEventArgs.Sequence, match => { var clip = ClipboardUtil.GetText(); return(BracketReplace(clip)); }); }
private void CopyToClipboard(Func <GitBlameCommit, string> formatter) { var commit = GetBlameCommit(); if (commit is null) { return; } ClipboardUtil.TrySetText(formatter(commit)); }
private void rtbRevisionHeader_KeyDown(object sender, KeyEventArgs e) { if (!e.Control || e.KeyCode != Keys.C || sender is not RichTextBox rtb) { return; } // Override RichTextBox Ctrl-c handling to copy plain text ClipboardUtil.TrySetText(rtb.GetSelectionPlainText()); e.Handled = true; }
private void CopyTextAndHtml(IEnumerable <IEditor> editors, IDataObject dataObj) { var textExporter = new PlainTextExporter(); dataObj.SetData(DataFormats.UnicodeText, textExporter.ExportText(editors)); var htmlExporter = new HtmlExporter(); var html = htmlExporter.ExportHtml(editors); dataObj.SetData(DataFormats.Html, ClipboardUtil.GetCFHtmlMemoryStream(html)); }
private void OnCopyUrl(object sender, EventArgs e) { if (string.IsNullOrEmpty(sURL)) { return; } if (ClipboardUtil.CopyAndMinimize(sURL, true, this, PasswordChangeAssistantExt.SelectedEntry, Program.MainForm.ActiveDatabase)) { Program.MainForm.StartClipboardCountdown(); } }