Skip to content

Commit

Permalink
Pull request #115: Let the user know that the copy-button was clicked
Browse files Browse the repository at this point in the history
Merge in PAC/chatbook from bugfix/NA_CopyIndicator to main

* commit 'fa5885e41af09d4008a8c7d57486d8545145a691':
  Another attempt at using RemovalConditions->{"MouseExit"} for copy tooltip.
  Delete the copied notification after a short delay
  Let the user know that the copy-button was clicked
  • Loading branch information
Kevin Daily authored and rhennigan committed Dec 3, 2024
2 parents ff48e5f + fa5885e commit 0a0cb94
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 48 additions & 2 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -893,16 +893,62 @@ insertCodeInUserNotebook[ chatNB_NotebookObject, code_String, evaluate_ ] :=

insertCodeInUserNotebook // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*attachCopiedTooltip*)
attachCopiedTooltip // beginDefinition;

attachCopiedTooltip[ ] :=
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;

(* ::**************************************************************************************************************:: *)
(* ::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;

(* ::**************************************************************************************************************:: *)
Expand Down

0 comments on commit 0a0cb94

Please sign in to comment.