From cc1fe788ae8fefb97b2c1e3a3d164c548a367bd2 Mon Sep 17 00:00:00 2001 From: Kevin Daily Date: Mon, 2 Dec 2024 11:59:28 -0800 Subject: [PATCH 1/3] Let the user know that the copy-button was clicked --- Source/Chatbook/Formatting.wl | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Source/Chatbook/Formatting.wl b/Source/Chatbook/Formatting.wl index 7a587426..19283aab 100644 --- a/Source/Chatbook/Formatting.wl +++ b/Source/Chatbook/Formatting.wl @@ -893,16 +893,45 @@ insertCodeInUserNotebook[ chatNB_NotebookObject, code_String, evaluate_ ] := insertCodeInUserNotebook // endDefinition; +(* ::**************************************************************************************************************:: *) +(* ::Subsubsection::Closed:: *) +(*attachCopiedTooltip*) +attachCopiedTooltip // beginDefinition; +(* option 1: can only achieve MouseExit if we cover the button with an invisible Pane after mouse-click *) +(* attachCopiedTooltip[ ] := + AttachCell[ + EvaluationBox[ ], + Cell[ BoxData[ + PaneBox[ + TemplateBox[ { "Copied" }, "ClickToCopyTooltip" ], + Alignment -> { Center, Bottom }, + FrameMargins -> 0, + ImageSize -> { All, 60 } + ] + ] ], + { Center, Bottom }, Offset[ { 0, -7 }, Automatic ], { Center, Center }, + RemovalConditions -> { "MouseExit" } + ]; *) +(* option 2 *) +attachCopiedTooltip[ ] := + AttachCell[ + EvaluationBox[ ], + Cell[ BoxData[ TemplateBox[ { "Copied" }, "ClickToCopyTooltip" ] ] ], + { Center, Bottom }, Offset[ { 0, 5 }, Automatic ], { Center, Top }, + RemovalConditions -> { "MouseClickOutside" } + ]; +attachCopiedTooltip // endDefinition; + (* ::**************************************************************************************************************:: *) (* ::Subsubsection::Closed:: *) (*copyCodeBlock*) copyCodeBlock // beginDefinition; copyCodeBlock[ cell_CellObject ] := copyCodeBlock @ getCodeBlockContent @ cell; -copyCodeBlock[ code_String ] := CopyToClipboard @ code; +copyCodeBlock[ code_String ] := (CopyToClipboard @ code; attachCopiedTooltip[ ]); copyCodeBlock[ Cell[ BoxData[ cell_Cell, ___ ] ] ] := copyCodeBlock @ cell; copyCodeBlock[ Cell[ code_String, ___ ] ] := copyCodeBlock @ code; copyCodeBlock[ cell0_Cell ] := With[ { cell = getCodeBlockContent @ cell0 }, copyCodeBlock @ cell /; cell =!= cell0 ]; -copyCodeBlock[ cell_Cell ] := CopyToClipboard @ cell; +copyCodeBlock[ cell_Cell ] := (CopyToClipboard @ cell; attachCopiedTooltip[ ]); copyCodeBlock // endDefinition; (* ::**************************************************************************************************************:: *) From f459e04bf125e308f4914d3733a0984648338697 Mon Sep 17 00:00:00 2001 From: Kevin Daily Date: Mon, 2 Dec 2024 14:15:59 -0800 Subject: [PATCH 2/3] Delete the copied notification after a short delay --- Source/Chatbook/Formatting.wl | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/Source/Chatbook/Formatting.wl b/Source/Chatbook/Formatting.wl index 19283aab..b5fdeb4f 100644 --- a/Source/Chatbook/Formatting.wl +++ b/Source/Chatbook/Formatting.wl @@ -897,29 +897,20 @@ insertCodeInUserNotebook // endDefinition; (* ::Subsubsection::Closed:: *) (*attachCopiedTooltip*) attachCopiedTooltip // beginDefinition; -(* option 1: can only achieve MouseExit if we cover the button with an invisible Pane after mouse-click *) -(* attachCopiedTooltip[ ] := - AttachCell[ - EvaluationBox[ ], - Cell[ BoxData[ - PaneBox[ - TemplateBox[ { "Copied" }, "ClickToCopyTooltip" ], - Alignment -> { Center, Bottom }, - FrameMargins -> 0, - ImageSize -> { All, 60 } - ] - ] ], - { Center, Bottom }, Offset[ { 0, -7 }, Automatic ], { Center, Center }, - RemovalConditions -> { "MouseExit" } - ]; *) -(* option 2 *) + attachCopiedTooltip[ ] := - AttachCell[ - EvaluationBox[ ], - Cell[ BoxData[ TemplateBox[ { "Copied" }, "ClickToCopyTooltip" ] ] ], - { Center, Bottom }, Offset[ { 0, 5 }, Automatic ], { Center, Top }, - RemovalConditions -> { "MouseClickOutside" } - ]; +With[ + { + cellObj = AttachCell[ + EvaluationBox[ ], + Cell[ BoxData[ TemplateBox[ { "Copied" }, "ClickToCopyTooltip" ] ] ], + { Center, Bottom }, Offset[ { 0, 5 }, Automatic ], { Center, Top }, + RemovalConditions -> { "MouseClickOutside" } + ] + }, + SessionSubmit @ ScheduledTask[ NotebookDelete @ cellObj, { 1.2 } ] +]; + attachCopiedTooltip // endDefinition; (* ::**************************************************************************************************************:: *) From fa5885e41af09d4008a8c7d57486d8545145a691 Mon Sep 17 00:00:00 2001 From: John Fultz Date: Mon, 2 Dec 2024 17:32:05 -0600 Subject: [PATCH 3/3] Another attempt at using RemovalConditions->{"MouseExit"} for copy tooltip. Also, reduce the horizontal size of the tooltip by 50 points. It was built for a wider purpose which is unnecessary here, and the wider appearance was being horizontally cropped in the NA interface. --- .../Bitmaps/Chatbook/CopyTooltip.9.png | Bin 0 -> 1480 bytes Source/Chatbook/Formatting.wl | 48 ++++++++++++++---- 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 FrontEnd/SystemResources/Bitmaps/Chatbook/CopyTooltip.9.png diff --git a/FrontEnd/SystemResources/Bitmaps/Chatbook/CopyTooltip.9.png b/FrontEnd/SystemResources/Bitmaps/Chatbook/CopyTooltip.9.png new file mode 100644 index 0000000000000000000000000000000000000000..ea5800df67ba41625ddee250d648cf79ea515e84 GIT binary patch literal 1480 zcmV;(1vmPMP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+HFtK4MQOa{CA3ufPjaNWBYtbH|Y2UHBDdBOO)f_ zK+||V&vXlLrliFx8bA(h+PFKZw6J2PHtz|vUCUQJO=INUrSfGMTfbj*!-`yg1`#hJ zvBA0MHta#dOV4}ZefM*(^)l$}=fr+6Y5hF?e=f!-$fkZPlNp-xnw)w-VJe0b55OBU z4kmqg958bmEIOozF~GyF-6KIl*dudm7C0|c@hTs#V^-rkZ>}L+Y>bUW zO#lD@32;bRa{vGf6951U69E94oEQKA06cU>SaefwW^{L9a%BKRa%Ew3Wn>_CX>@2H zbZBKDS8r@)a$#*COkr+kbzx^^AUYs-cXuv#Z)|3AVQnsBZ*5$nriB0i03mcmSad^j zWnpw_Z*Cw|X>DZyGB7eUIx#XjFft%9HaayjIx;k{KsLqz00byWL_t(|UhSMqPUAoj zhV8a_2oMV%8zfL>hs2TtOfJECILQ!k1THY*CR~6e5)uoTAR!jOf;Yi-=KpKl83QIJ z35gp|St{A>M_jJ2tGfCDejA&o+q)LDo1@VsG$OOP(ZsstqKMb^-%H+^q5o6Pjg!NGw5v63kh zjumG)eR)V(FS1s)-UJW%d31DSrl+R`(CO(ZJxaVNExai0b%Te=Z&MMv7mW}dIw!EEBv zIc_u>(sk&xu})O8|3nFRwn3s3TES;aB175V-|r+cYinyhK`EpXDh5KBK|&LvsR$7E z%-PvlkY=30`ue&+BCLG)k+L#7K~J_Rqq)`Ps#+~41a6m$W?ySuy4W}Mce0Ps!U zO(6|p@*bb1Cp|no1V|#nR;wj|2n-v$2om-f>e6#s zh2(;LxZJ**LK?*CJwD5ELiF82bPGa23J8mW&D`AF78t%%dJ_vU{;4tJFBn<(9JwHFA3uSzOlRd?H zQzr#4b*WMrmMZt10tq2bU{Dz1P-fOA<*Tc!H$!yVCXE;xJV#&<6b0c zl4ciDL3IN4e zfg52&Jf5GQj|gdDVIjh|#6y8}cz771wg@0j3*%TOwlI&ckkT4NFgzqE0820<8)F}% z91|3dqt(^b;Xva0F}wPOQ^AV@=lBC+D>-c_U!M^G0000 { "MouseClickOutside" } - ] - }, - SessionSubmit @ ScheduledTask[ NotebookDelete @ cellObj, { 1.2 } ] -]; + AttachCell[ + EvaluationBox[ ], + Cell[ BoxData[ + PaneBox[ + PanelBox[ + GridBox[{{PaneBox[ + DynamicBox[ + StyleBox[ + FEPrivate`ImportImage[ + FrontEnd`FileName[{"Typeset", "ClickToCopy"}, "Checkmark.png"]], + Magnification -> 0.5`]], + BaselinePosition -> Scaled[0.1`] -> Baseline], + DynamicBox[ + ToBoxes[FEPrivate`FrontEndResource["FEStrings", + "clicktocopyDoneTooltip"], StandardForm]]}}, + GridBoxAlignment -> {"Columns" -> {{Left}}, "Rows" -> {{Baseline}}}, + GridBoxItemSize -> {"Columns" -> {{Automatic}}, + "Rows" -> {{Automatic}}}, + GridBoxSpacings -> {"Columns" -> {{0.3`}}, "Rows" -> {{0}}}], + Alignment -> Center, + Appearance -> {"Default" -> + FrontEnd`FileName[{"Chatbook"}, "CopyTooltip.9.png"]}, ImageSize -> {100, Automatic}, + FrameMargins -> {{0, 0}, {0, 0}}, + BaseStyle -> {LineBreakWithin -> Automatic, + LinebreakAdjustments -> {1.`, 10, 1, 0, 1}, LineIndent -> 0, + Hyphenation -> False, + HyphenationOptions -> {"HyphenationCharacter" -> "\[Null]"}, + FontFamily -> "Source Sans Pro", FontSize -> 12, + FontColor -> GrayLevel[0.5]}], + Alignment -> { Center, Bottom }, + FrameMargins -> 0, + ImageSize -> { All, 60 } + ] + ] ], + { Center, Bottom }, Offset[ { 0, -7 }, Automatic ], { Center, Center }, + RemovalConditions -> { "MouseExit" } + ]; attachCopiedTooltip // endDefinition;