Skip to content

Commit

Permalink
Merge pull request #554 from WolframResearch/feature/insert-cell-styl…
Browse files Browse the repository at this point in the history
…e-menu-to-cloud-toolbar

Add an "Insert Chat Cell" menu to the cloud toolbar
  • Loading branch information
rhennigan authored Jan 22, 2024
2 parents 5548522 + a647aa6 commit 77f7ecc
Showing 1 changed file with 85 additions and 29 deletions.
114 changes: 85 additions & 29 deletions Source/Chatbook/CloudToolbar.wl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ $notebookTypeLabelOptions = Sequence[
FontWeight -> "DemiBold"
];

$buttonHeight = 20;
$menuItemIconSize = { 20, 20 };

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Docked Cell Contents*)
Expand All @@ -41,57 +44,110 @@ makeChatCloudDockedCellContents[ ] := Grid[
{
Item[ $cloudChatBanner, Alignment -> Left ],
Item[ "", ItemSize -> Fit ],
cloudCellInsertMenu[ ],
cloudPreferencesButton[ ]
}
},
Alignment -> { Left, Baseline },
Spacings -> { 2, 0 },
BaseStyle -> { "Text", FontSize -> 14, FontColor -> GrayLevel[ 0.4 ] },
Alignment -> { Left, Center },
Spacings -> { 0.7, 0 },
BaseStyle -> { "Text", FontSize -> 14 },
FrameStyle -> Directive[ Thickness[ 2 ], GrayLevel[ 0.9 ] ]
];

makeChatCloudDockedCellContents // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*cloudPreferencesButton*)
cloudPreferencesButton // beginDefinition;
(*cloudCellInsertMenu*)
cloudCellInsertMenu // beginDefinition;

cloudCellInsertMenu[ ] := ActionMenu[
toolbarButtonLabel @ Row @ { "Insert Chat Cell", Spacer[ 5 ], RawBoxes @ TemplateBox[ { }, "ChatInputIcon" ] },
{
insertStyleMenuItem[ "ChatInputIcon", "ChatInput", "'" ],
insertStyleMenuItem[ "SideChatIcon", "SideChat", "' '" ],
insertStyleMenuItem[ "ChatSystemIcon", "ChatSystemInput", "' ' '" ],
Delimiter,
insertStyleMenuItem[ None, "ChatDelimiter", "~" ],
insertStyleMenuItem[ None, "ChatBlockDivider", "~ ~" ]
},
FrameMargins -> { { 0, 0 }, { 0, 0 } }
];

cloudPreferencesButton[ ] := Enclose[
Module[ { iconTemplate, colorTemplate, buttonLabel, mouseover, buttonIcon, button },
cloudCellInsertMenu // endDefinition;

iconTemplate = ConfirmMatch[
chatbookIcon[ "ToolManagerCog", False ],
RawBoxes @ TemplateBox[ { }, __ ],
"IconTemplate"
];
(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*toolbarButtonLabel*)
toolbarButtonLabel // beginDefinition;

toolbarButtonLabel[ label_ ] := Pane[
label,
ImageSize -> { Automatic, $buttonHeight },
Alignment -> { Center, Baseline },
FrameMargins -> { { 8, 0 }, { 2, 2 } }
];

colorTemplate = ConfirmMatch[
Insert[ iconTemplate, #, { 1, 1, 1 } ],
RawBoxes @ TemplateBox[ { _? ColorQ }, __ ],
"Colorize"
] &;
toolbarButtonLabel // endDefinition;

buttonLabel = Grid[
{ { Style[ "Chat Settings", FontColor -> # ], colorTemplate @ # } },
Alignment -> { Left, Baseline }
] &;
(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*insertStyleMenuItem*)
insertStyleMenuItem // beginDefinition;

mouseover = Mouseover[ buttonLabel @ GrayLevel[ 0.25 ], buttonLabel @ Hue[ 0.59, 0.9, 0.93 ] ];
insertStyleMenuItem[ icon_String, style_, shortcut_ ] :=
insertStyleMenuItem[ chatbookIcon[ icon, False ], style, shortcut ];

buttonIcon = DeleteCases[
mouseover (*/. HoldPattern[ ImageSize -> _ ] :> ImageSize -> { 22, 22 }*),
BaselinePosition -> _,
Infinity
];
insertStyleMenuItem[ None, style_, shortcut_ ] :=
insertStyleMenuItem[ Spacer[ 0 ], style, shortcut ];

button = Button[ buttonIcon, toggleCloudPreferences @ EvaluationNotebook[ ], Method -> "Queued" ];
insertStyleMenuItem[ icon_, style_, shortcut_ ] :=
Grid[
{ {
Pane[ icon, ImageSize -> $menuItemIconSize ],
Item[ style, ItemSize -> 12 ],
Style[ shortcut, FontColor -> GrayLevel[ 0.75 ] ]
} },
Alignment -> { { Center, Left, Right }, Center }
] :> insertCellStyle @ style;

cloudPreferencesButton[ ] = Pane[ button, FrameMargins -> { { 0, 10 }, { 0, 0 } } ]
insertStyleMenuItem // endDefinition;

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

insertCellStyle[ style_String ] :=
insertCellStyle[ style, EvaluationNotebook[ ] ];

insertCellStyle[ style_String, nbo_NotebookObject ] := Enclose[
Module[ { tag, cell, cellObject },
tag = ConfirmBy[ CreateUUID[ ], StringQ, "UUID" ];
cell = Cell[ "", style, CellTags -> tag ];
SelectionMove[ nbo, After, Notebook ];
NotebookWrite[ nbo, cell ];
cellObject = ConfirmMatch[ First[ Cells[ nbo, CellTags -> tag ], $Failed ], _CellObject, "CellObject" ];
If[ style =!= "ChatDelimiter", SelectionMove[ cellObject, Before, CellContents ] ];
SetOptions[ cellObject, CellTags -> Inherited ];
cellObject
],
throwInternalFailure
];

insertCellStyle // endDefinition;

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

cloudPreferencesButton[ ] := Button[
toolbarButtonLabel @ Row @ { "Chat Settings", Spacer[ 5 ], RawBoxes @ TemplateBox[ { }, "AdvancedSettings" ] },
toggleCloudPreferences @ EvaluationNotebook[ ],
FrameMargins -> { { 0, 4 }, { 0, 0 } }
];

cloudPreferencesButton // endDefinition;

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

0 comments on commit 77f7ecc

Please sign in to comment.