Tabbed Notebooks
Tabbed Notebooks
Useful for creating richer Mathematica interfaces
Can create tabs in a single notebook, cache these tabs, add tabs, etc.
Create an autoupdating package by evaluating the cell below:
Can create tabs in a single notebook, cache these tabs, add tabs, etc.
Create an autoupdating package by evaluating the cell below:
SetOptions[EvaluationNotebook[],AutoGeneratedPackageAutomatic]
The package as it stands is somewhat sparse, but nicer interfaces can be built from the exposed components.
Note that the package needs to be loaded for any tabbing to work, so you’ll need to set an auto-load of some sort to restore state.
Code
Code
BeginPackage["NotebookTabbing`"];
Exposed Interface
Exposed Interface
Formatting
Formatting
Caches
Caches
Tab Objects
Tab Objects
Docked Cell Interface
Docked Cell Interface
Docked Tab Editing
Docked Tab Editing
Saving and Opening
Saving and Opening
Info
Info
Begin["`Private`"];
Internals
Internals
Formatting
Formatting
Caches
Caches
Tab Objects
Tab Objects
TabObject[notebook:_NotebookObject|Automatic:Automatic,name_,tag_,ops___]:=With[{nb:=Replace[notebook,AutomaticEvaluationNotebook[]]},Interpretation[DynamicWrapper[Graphics[{Dynamic@If[($ActiveNotebookTab[nb]===tag),$TabBackgroundActive,$TabBackgroundInactive],Dynamic@If[($ActiveNotebookTab[nb]===tag),EdgeForm@$TabBorderActive,EdgeForm@$TabBorderInactive],$TabShape,{Dynamic@If[($ActiveNotebookTab[nb]===tag),$TabForegroundActive,$TabForegroundInactive],Inset[name,Scaled[{.2,0}],{Left,Bottom}]}},ImageMargins{{0,0},{0,3}},ImagePadding{{0,0},{0,3}},PlotRangePaddingNone,ops],If[DownValues[SwitchTabs]==={},CloudGet@"https://www.wolframcloud.com/objects/user-affd7b1c-ecb6-4ccc-8cc4-4d107e2bf04a/NotebookTabbing.m"]],tag]];
SwitchTabs::nonb="NotebookObject `` does not exist";SwitchTabs[notebook_NotebookObject,tab_]:=If[$ActiveNotebookTab[notebook]=!=tab,(*Cachecurrentstate*)Replace[$NotebookCache[notebook],_MissingSet[$NotebookCache[notebook],<||>]];With[{nb=NotebookGet@notebook},If[nb=!=$Failed,Replace[$ActiveNotebookTab[notebook],Except[Missing["KeyAbsent",notebook]]Set[$NotebookCache[notebook][$ActiveNotebookTab[notebook]],Compress@First@nb]];(*Setnewtab*)$ActiveNotebookTab[notebook]=tab;(*Insertcachednotebookvaluesintonotebook*)NotebookPut[ReplacePart[NotebookGet@notebook,1Uncompress@Replace[$NotebookCache[notebook][tab],_MissingSet[$NotebookCache[notebook][tab],Compress@{}]]],notebook],Message[SwitchTabs::nonb,notebook];$Failed]];tab];SwitchTabs[Automatic,tab_]:=SwitchTabs[EvaluationNotebook[],tab]
TabButton[notebook:_NotebookObject|Automatic:Automatic,name_,tag_,command_:SwitchTabs]:=EventHandler[TabObject[notebook,name,tag],"MouseClicked"(If[command===SwitchTabs&&DownValues[SwitchTabs]==={},CloudGet@"https://www.wolframcloud.com/objects/user-affd7b1c-ecb6-4ccc-8cc4-4d107e2bf04a/NotebookTabbing.m"];command[notebook,tag])];
Docked Cell Interface
Docked Cell Interface
Docked Tab Editing
Docked Tab Editing
Saving Opening
Saving Opening
Info
Info
Testing
Testing