From 901f35d84946ecfbcd9aa1913c251a20553546b1 Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Mon, 20 Nov 2023 21:56:58 -0500 Subject: [PATCH] Add Copy as Text command #1143 --- OneMore/AddInCommands.cs | 6 ++ OneMore/Commands/Edit/CopyAsTextCommand.cs | 77 ++++++++++++++++++++++ OneMore/OneMore.csproj | 1 + OneMore/Properties/Resources.Designer.cs | 18 +++++ OneMore/Properties/Resources.ar-SA.resx | 8 +++ OneMore/Properties/Resources.de-DE.resx | 8 +++ OneMore/Properties/Resources.es-ES.resx | 8 +++ OneMore/Properties/Resources.fr-FR.resx | 8 +++ OneMore/Properties/Resources.he-IL.resx | 8 +++ OneMore/Properties/Resources.nl-NL.resx | 8 +++ OneMore/Properties/Resources.pl-PL.resx | 8 +++ OneMore/Properties/Resources.pt-BR.resx | 8 +++ OneMore/Properties/Resources.resx | 8 +++ OneMore/Properties/Resources.zh-CN.resx | 8 +++ OneMore/Ribbon/Ribbon.xml | 6 ++ 15 files changed, 188 insertions(+) create mode 100644 OneMore/Commands/Edit/CopyAsTextCommand.cs diff --git a/OneMore/AddInCommands.cs b/OneMore/AddInCommands.cs index 6e41c523fb..2dad75ac3a 100644 --- a/OneMore/AddInCommands.cs +++ b/OneMore/AddInCommands.cs @@ -200,6 +200,12 @@ public async Task CopyAcrossCmd(IRibbonControl control) => await factory.Run(FillCells.CopyAcross); + + [Command("ribCopyAsTextButton_Label", Keys.None, "ribEditMenu")] + public async Task CopyAsTextCmd(IRibbonControl control) + => await factory.Run(); + + [Command("ribCopyDownButton_Label", Keys.None, "ribTableMenu")] public async Task CopyDownCmd(IRibbonControl control) => await factory.Run(FillCells.CopyDown); diff --git a/OneMore/Commands/Edit/CopyAsTextCommand.cs b/OneMore/Commands/Edit/CopyAsTextCommand.cs new file mode 100644 index 0000000000..3d36951867 --- /dev/null +++ b/OneMore/Commands/Edit/CopyAsTextCommand.cs @@ -0,0 +1,77 @@ +//************************************************************************************************ +// Copyright © 2023 Steven M Cohn. All rights reserved. +//************************************************************************************************ + +namespace River.OneMoreAddIn.Commands +{ + using System.Linq; + using System.Threading.Tasks; + using River.OneMoreAddIn.Models; + + + /// + /// Copy the page or selected content as plan text onto the system clipboard + /// + internal class CopyAsTextCommand : Command + { + public CopyAsTextCommand() + { + } + + + public override async Task Execute(params object[] args) + { + using var one = new OneNote(out var page, out var _); + var cursor = page.GetTextCursor(); + + if (// cursor is not null if selection range is empty + cursor != null && + // selection range is a single line containing a hyperlink + !(page.SelectionSpecial && page.SelectionScope == SelectionScope.Empty)) + { + await CopyPageAsText(one, page); + } + else + { + // if only images are selected and no text content then copy entire page... + + var other = page.Root.Descendants().Where(e => + e.Attribute("selected")?.Value == "all" && + e.Name.LocalName != "Image"); + + if (other.Any()) + { + // some text was found, maybe with one or more images + var clipboard = new ClipboardProvider(); + await clipboard.Copy(); + await clipboard.SetText(await clipboard.GetText()); + } + else + { + // no range selection or only an image was selected + await CopyPageAsText(one, page); + } + } + } + + + private async Task CopyPageAsText(OneNote one, Page page) + { + var updated = one.GetPage(OneNote.PageDetail.Basic); + var ns = updated.Root.GetNamespaceOfPrefix(OneNote.Prefix); + + updated.Root.Elements(ns + "Outline").ForEach(e => + { + e.SetAttributeValue("selected", "all"); + }); + + await one.Update(updated); + + var clipboard = new ClipboardProvider(); + await clipboard.Copy(); + await clipboard.SetText(await clipboard.GetText()); + + await one.Update(page); + } + } +} diff --git a/OneMore/OneMore.csproj b/OneMore/OneMore.csproj index 59ffaa76f9..70b20e907b 100644 --- a/OneMore/OneMore.csproj +++ b/OneMore/OneMore.csproj @@ -146,6 +146,7 @@ ColorizeDialog.cs + diff --git a/OneMore/Properties/Resources.Designer.cs b/OneMore/Properties/Resources.Designer.cs index f57f35cc66..7c5a254e79 100644 --- a/OneMore/Properties/Resources.Designer.cs +++ b/OneMore/Properties/Resources.Designer.cs @@ -6388,6 +6388,24 @@ internal static string ribCopyAsMarkdownButton_Screentip { } } + /// + /// Looks up a localized string similar to Copy as Text. + /// + internal static string ribCopyAsTextButton_Label { + get { + return ResourceManager.GetString("ribCopyAsTextButton_Label", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Copy select context as plain text. + /// + internal static string ribCopyAsTextButton_Screentip { + get { + return ResourceManager.GetString("ribCopyAsTextButton_Screentip", resourceCulture); + } + } + /// /// Looks up a localized string similar to Copy Down. /// diff --git a/OneMore/Properties/Resources.ar-SA.resx b/OneMore/Properties/Resources.ar-SA.resx index f096d51b1d..96e554186d 100644 --- a/OneMore/Properties/Resources.ar-SA.resx +++ b/OneMore/Properties/Resources.ar-SA.resx @@ -2616,6 +2616,14 @@ ISO-code then comma then language name نسخ حدد المحتوى باعتباره تخفيض السعر ribbon edit + + نسخ كنص + ribbon edit + + + انسخ السياق المحدد كنص عادي + ribbon edit + انسخ ribbon diff --git a/OneMore/Properties/Resources.de-DE.resx b/OneMore/Properties/Resources.de-DE.resx index b3b03c758e..efe230c732 100644 --- a/OneMore/Properties/Resources.de-DE.resx +++ b/OneMore/Properties/Resources.de-DE.resx @@ -2620,6 +2620,14 @@ Polaroid Kopieren Sie ausgewählte Inhalte als Markdown ribbon edit + + Als Text kopieren + ribbon edit + + + Kopieren Sie den ausgewählten Kontext als einfachen Text + ribbon edit + Abschreiben ribbon diff --git a/OneMore/Properties/Resources.es-ES.resx b/OneMore/Properties/Resources.es-ES.resx index 3388c6a2a7..1a8664ee5d 100644 --- a/OneMore/Properties/Resources.es-ES.resx +++ b/OneMore/Properties/Resources.es-ES.resx @@ -2616,6 +2616,14 @@ polaroid Copiar contenido seleccionado como descuento ribbon edit + + Copiar como texto + ribbon edit + + + Copiar el contexto seleccionado como texto sin formato + ribbon edit + Copia ribbon diff --git a/OneMore/Properties/Resources.fr-FR.resx b/OneMore/Properties/Resources.fr-FR.resx index e01dcd43a0..945784ec25 100644 --- a/OneMore/Properties/Resources.fr-FR.resx +++ b/OneMore/Properties/Resources.fr-FR.resx @@ -2612,6 +2612,14 @@ Polaroïd Copiez le contenu sélectionné en tant que démarquage ribbon edit + + Copier sous forme de texte + ribbon edit + + + Copier le contexte de sélection sous forme de texte brut + ribbon edit + Recopie ribbon diff --git a/OneMore/Properties/Resources.he-IL.resx b/OneMore/Properties/Resources.he-IL.resx index daa294502b..511bcdea2f 100644 --- a/OneMore/Properties/Resources.he-IL.resx +++ b/OneMore/Properties/Resources.he-IL.resx @@ -2637,6 +2637,14 @@ ISO-code then comma then language name העתק בחר תוכן כ- Markdown ribbon edit + + העתק כטקסט + ribbon edit + + + העתק את ההקשר של הבחירה כטקסט רגיל + ribbon edit + העתק למטה ribbon diff --git a/OneMore/Properties/Resources.nl-NL.resx b/OneMore/Properties/Resources.nl-NL.resx index 356198bc8e..bae1ad1eb5 100644 --- a/OneMore/Properties/Resources.nl-NL.resx +++ b/OneMore/Properties/Resources.nl-NL.resx @@ -2617,6 +2617,14 @@ Polaroid Kopieer geselecteerde inhoud als prijsverlaging ribbon edit + + Kopieer als tekst + ribbon edit + + + Kopieer de geselecteerde context als platte tekst + ribbon edit + Naar beneden kopiëren ribbon diff --git a/OneMore/Properties/Resources.pl-PL.resx b/OneMore/Properties/Resources.pl-PL.resx index 8564a9bae5..87b939230a 100644 --- a/OneMore/Properties/Resources.pl-PL.resx +++ b/OneMore/Properties/Resources.pl-PL.resx @@ -2629,6 +2629,14 @@ Polaroid Skopiuj wybraną zawartość jako przecenę ribbon edit + + Skopiuj jako tekst + ribbon edit + + + Skopiuj wybrany kontekst jako zwykły tekst + ribbon edit + Skopiować ribbon diff --git a/OneMore/Properties/Resources.pt-BR.resx b/OneMore/Properties/Resources.pt-BR.resx index c349460f24..3836943fcf 100644 --- a/OneMore/Properties/Resources.pt-BR.resx +++ b/OneMore/Properties/Resources.pt-BR.resx @@ -2617,6 +2617,14 @@ Polaroid. Copiar conteúdo selecionado como remarcação ribbon edit + + Copiar como texto + ribbon edit + + + Copie o contexto selecionado como texto simples + ribbon edit + Anote ribbon diff --git a/OneMore/Properties/Resources.resx b/OneMore/Properties/Resources.resx index fb0e77c2c3..59a0b2594e 100644 --- a/OneMore/Properties/Resources.resx +++ b/OneMore/Properties/Resources.resx @@ -2657,6 +2657,14 @@ Polaroid Copy select content as markdown ribbon edit + + Copy as Text + ribbon edit + + + Copy select context as plain text + ribbon edit + Copy Down ribbon table diff --git a/OneMore/Properties/Resources.zh-CN.resx b/OneMore/Properties/Resources.zh-CN.resx index ca33bf0fe4..b452dd3c51 100644 --- a/OneMore/Properties/Resources.zh-CN.resx +++ b/OneMore/Properties/Resources.zh-CN.resx @@ -2644,6 +2644,14 @@ ISO-code then comma then language name ribbon edit + + 复制为文本 + ribbon edit + + + 将选择的上下文复制为纯文本 + ribbon edit + 向下复制 diff --git a/OneMore/Ribbon/Ribbon.xml b/OneMore/Ribbon/Ribbon.xml index f31c8e875d..552982ae0c 100644 --- a/OneMore/Ribbon/Ribbon.xml +++ b/OneMore/Ribbon/Ribbon.xml @@ -293,6 +293,12 @@ getLabel="GetRibbonLabel" getScreentip="GetRibbonScreentip" onAction="CopyAsMarkdownCmd"/> +