Message Boards Message Boards

0
|
1323 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Dynamic 2-state toggle Button toggles forward but does not return

Posted 2 years ago

I had this working fine this morning, but I proceeded to refactor, and somehow I cannot get it to toggle like before. It does initialize, and it does go from state-1 to state-2 but not back to state-1. That's what I cannot figure out. If you have any suggestions, please help.

ClearAll[autosave];
Options[autosave]={"ButtonOptions"->{}};
autosave(bgs_:{Darker[Blue],Darker[Green]},cols_:{White,White},labs_:{"AutoSave","Saving"},size_:{75,25},opts:OptionsPattern[]):=Module[{state:=CurrentValue[EvaluationNotebook[],NotebookAutoSave],flip:=SetOptions[EvaluationNotebook[],NotebookAutoSave->If[TrueQ[state],False,True]]},toggle(flp_:True):=(If[TrueQ[flp],flip];col=If[TrueQ[state],Last[cols],First[cols]];label=If[TrueQ[state],Last[labs],First[labs]];bg=If[TrueQ[state],Last[bgs],First[bgs]]);Dynamic[Button[label,toggle(),BaseStyle->col,Background->Dynamic[bg],ImageSize->size,Sequence@@OptionValue["ButtonOptions"]],Initialization:>toggle(False)]];
autosave()
CurrentValue[EvaluationNotebook[],NotebookAutoSave]=False
POSTED BY: Jules Manson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract