Skip to main content
added 3229 characters in body
Source Link
Mike Honeychurch
  • 37.8k
  • 3
  • 87
  • 161

Edit - adding a date and time stamp

In reply to @rm -f question, adding a date and time was far more complicated than I expected. Firstly I don't think a cell label is the place for this because labels can easily be removed by clicking on them and pressing delete. Also these comment styles are based on text cells rather than input. So placing a date stamp as a cell frame labels seemed a better way to go.

For a few years I have been using a palette button for pasting a date and time into a notebook. I cannot remember the source of the code to give attribution -- it may have been Mathgroup or it may have been from someone at Wolfram. The problem was how to use that code in a stylesheet. Functions in stylesheets are associated with ButtonFunction, Counterfunction, InterpetationFunction etc. In other words they occur where a function is expected. So I decided to modify the code and use it in a button

The code below works by adding a button to the cell frame. This button contains a modified version of the palette button I have been using. The trick was to get it to work in a cell frame. After much trial and error it seemed that the best way to do this was to have a button that replaced itself with the date and time stamp. Note I have used Append in the code. SetOption and CurrentValue did not work for reasons I do not understand.

 Cell[StyleData["Mike", StyleDefinitions -> StyleData["Text"]],
 CellFrame->{{4, 0}, {0, 0}},
 CellMargins->{{66, 10}, {7, 7}},
  CellFrameLabels->{{
    PaneBox[
     StyleBox["Mike", 12, FontFamily -> "Arial", Bold], ImageSize -> 60, Alignment -> {Center, Center}], Inherited}, {
    Cell[
     BoxData[
      ButtonBox[
       StyleBox[
        RowBox[{"date", " ", "stamp"}], FontFamily -> "Helvetica", FontColor -> GrayLevel[0]], Active -> True, Appearance -> {Automatic, "DialogBox"}, 
       ButtonFunction :> Module[{dy, hr, mn, tmp}, {dy, hr, mn} = Map[(LinkWrite[
              First[$FrontEnd], 
              FrontEnd`Value[#]]; LinkRead[
              First[$FrontEnd]])& , {"DateLong", "Hour", "Minute"}]; SelectionMove[
           InputNotebook[], All, ButtonCell];
          Set[tmp,NotebookRead[
             InputNotebook[]]];
           NotebookWrite[
          InputNotebook[], 
           Append[tmp, CellFrameLabels->{{PaneBox[
     StyleBox["Mike", 12, FontFamily -> "Arial", Bold], ImageSize -> 60, Alignment -> {Center, Center}],Inherited},{Cell[
          TextData[{ dy, " at ", hr, ":", mn}], 
          "Text", Background->None,FontFamily -> "Arial",FontSize->9],Inherited}}]]
           ], Evaluator -> Automatic]]], Inherited}},
 MenuSortingValue->2,
 StyleMenuListing->True,
 FontFamily->"Helvetica",
 FontColor->RGBColor[0.266667, 0.172549, 0.0823529],
 Background->RGBColor[0.94, 0.91, 0.88]]

Here is a grab of a cell using "Mike" style.

enter image description here

Now a grab after pressing the "date stamp" button

enter image description here

Edit - adding a date and time stamp

In reply to @rm -f question, adding a date and time was far more complicated than I expected. Firstly I don't think a cell label is the place for this because labels can easily be removed by clicking on them and pressing delete. Also these comment styles are based on text cells rather than input. So placing a date stamp as a cell frame labels seemed a better way to go.

For a few years I have been using a palette button for pasting a date and time into a notebook. I cannot remember the source of the code to give attribution -- it may have been Mathgroup or it may have been from someone at Wolfram. The problem was how to use that code in a stylesheet. Functions in stylesheets are associated with ButtonFunction, Counterfunction, InterpetationFunction etc. In other words they occur where a function is expected. So I decided to modify the code and use it in a button

The code below works by adding a button to the cell frame. This button contains a modified version of the palette button I have been using. The trick was to get it to work in a cell frame. After much trial and error it seemed that the best way to do this was to have a button that replaced itself with the date and time stamp. Note I have used Append in the code. SetOption and CurrentValue did not work for reasons I do not understand.

 Cell[StyleData["Mike", StyleDefinitions -> StyleData["Text"]],
 CellFrame->{{4, 0}, {0, 0}},
 CellMargins->{{66, 10}, {7, 7}},
  CellFrameLabels->{{
    PaneBox[
     StyleBox["Mike", 12, FontFamily -> "Arial", Bold], ImageSize -> 60, Alignment -> {Center, Center}], Inherited}, {
    Cell[
     BoxData[
      ButtonBox[
       StyleBox[
        RowBox[{"date", " ", "stamp"}], FontFamily -> "Helvetica", FontColor -> GrayLevel[0]], Active -> True, Appearance -> {Automatic, "DialogBox"}, 
       ButtonFunction :> Module[{dy, hr, mn, tmp}, {dy, hr, mn} = Map[(LinkWrite[
              First[$FrontEnd], 
              FrontEnd`Value[#]]; LinkRead[
              First[$FrontEnd]])& , {"DateLong", "Hour", "Minute"}]; SelectionMove[
           InputNotebook[], All, ButtonCell];
          Set[tmp,NotebookRead[
             InputNotebook[]]];
           NotebookWrite[
          InputNotebook[], 
           Append[tmp, CellFrameLabels->{{PaneBox[
     StyleBox["Mike", 12, FontFamily -> "Arial", Bold], ImageSize -> 60, Alignment -> {Center, Center}],Inherited},{Cell[
          TextData[{ dy, " at ", hr, ":", mn}], 
          "Text", Background->None,FontFamily -> "Arial",FontSize->9],Inherited}}]]
           ], Evaluator -> Automatic]]], Inherited}},
 MenuSortingValue->2,
 StyleMenuListing->True,
 FontFamily->"Helvetica",
 FontColor->RGBColor[0.266667, 0.172549, 0.0823529],
 Background->RGBColor[0.94, 0.91, 0.88]]

Here is a grab of a cell using "Mike" style.

enter image description here

Now a grab after pressing the "date stamp" button

enter image description here

Source Link
Mike Honeychurch
  • 37.8k
  • 3
  • 87
  • 161

FWIW here are some styles I use when collaborating -- i.e. I am doing the programming but others are commenting on outcomes and providing feedback:

enter image description here

The basic cell style is:

Cell[StyleData["Mike", StyleDefinitions -> StyleData["Text"]],
 CellFrame->{{4, 0}, {0, 0}},
 CellMargins->{{66, 10}, {7, 7}},
 CellFrameLabels->{{
    PaneBox[
     StyleBox["Mike", 12, FontFamily -> Arial, Bold], ImageSize -> 60, 
     Alignment -> {Center, Center}], Inherited}, {Inherited, Inherited}},
 MenuSortingValue->2,
 StyleMenuListing->True,
 FontFamily->"Helvetica",
 FontColor->RGBColor[0.266667, 0.172549, 0.0823529],
 Background->RGBColor[0.94, 0.91, 0.88]]

This might be useful to some people -- you might want to add date and time stamps to discussions. Example usage

enter image description here