Fossil

Check-in [bd81a5f601]
Login

Check-in [bd81a5f601]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added option to render HTML previews inline, as opposed to in an iframe. Layout improvements in the preview/diff/commit tabs.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | fileedit-ajaxify
Files: files | file ages | folders
SHA3-256: bd81a5f60129963d6756613881904db7c45e045016bc4ee12d2abd26bc2d8c96
User & Date: stephan 2020-05-05 22:18:03.922
Context
2020-05-05
23:31
Added missing checks for negative result value from symbolic_name_to_rid() (indicating an ambiguous name). ... (check-in: d8c21f2f09 user: stephan tags: fileedit-ajaxify)
22:18
Added option to render HTML previews inline, as opposed to in an iframe. Layout improvements in the preview/diff/commit tabs. ... (check-in: bd81a5f601 user: stephan tags: fileedit-ajaxify)
21:49
Temporarily(?) removed the editor font size adjustment dropdown, as it currently has no proper home in the new layout. ... (check-in: 413a0ce83f user: stephan tags: fileedit-ajaxify)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/default_css.txt.
987
988
989
990
991
992
993

994
995
996
997
998
999
1000
}
.font-size-175 {
  font-size: 175%;
}
.font-size-200 {
  font-size: 200%;
}

.tab-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.tab-container > #fossil-status-bar {







>







987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
}
.font-size-175 {
  font-size: 175%;
}
.font-size-200 {
  font-size: 200%;
}

.tab-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.tab-container > #fossil-status-bar {
1027
1028
1029
1030
1031
1032
1033
1034




































  align-self: baseline;
}
.tab-container > .tab-bar > button.selected {
  font-style: italic;
  font-weight: bold;
  margin: 0 0.5em;
  text-decoration: underline;
}












































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
  align-self: baseline;
}
.tab-container > .tab-bar > button.selected {
  font-style: italic;
  font-weight: bold;
  margin: 0 0.5em;
  text-decoration: underline;
}
.tab-container > .tabs > .tab-panel > .fileedit-options {
  margin-top: 0;
  border: none;
  border-radius: 0;
  border-bottom-width: 1px;
  border-bottom-style: dotted;
}
.tab-container > .tabs > .tab-panel > .fileedit-options > button {
  vertical-align: middle;
  margin: 0.5em;
}
.flex-container {
    display: flex;
}
.flex-container.row {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}
.flex-container.row.stretch {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    margin: 0;
}
.flex-container.column {
    flex-direction: column;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}
.flex-container.column.stretch {
    align-items: stretch;
    margin: 0;
}
Changes to src/fileedit.c.
904
905
906
907
908
909
910
911

912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
enum fileedit_render_preview_flags {
FE_PREVIEW_LINE_NUMBERS = 1
};
enum fileedit_render_modes {
/* GUESS must be 0. All others have unspecified values. */
FE_RENDER_GUESS = 0,
FE_RENDER_PLAIN_TEXT,
FE_RENDER_HTML,

FE_RENDER_WIKI
};

static int fileedit_render_mode_for_mimetype(const char * zMimetype){
  int rc = FE_RENDER_PLAIN_TEXT;
  if( zMimetype ){
    if( fossil_strcmp(zMimetype, "text/html")==0 ){
      rc = FE_RENDER_HTML;
    }else if( fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0
              || fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
      rc = FE_RENDER_WIKI;
    }
  }
  return rc;
}







|
>







|







904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
enum fileedit_render_preview_flags {
FE_PREVIEW_LINE_NUMBERS = 1
};
enum fileedit_render_modes {
/* GUESS must be 0. All others have unspecified values. */
FE_RENDER_GUESS = 0,
FE_RENDER_PLAIN_TEXT,
FE_RENDER_HTML_IFRAME,
FE_RENDER_HTML_INLINE,
FE_RENDER_WIKI
};

static int fileedit_render_mode_for_mimetype(const char * zMimetype){
  int rc = FE_RENDER_PLAIN_TEXT;
  if( zMimetype ){
    if( fossil_strcmp(zMimetype, "text/html")==0 ){
      rc = FE_RENDER_HTML_IFRAME;
    }else if( fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0
              || fossil_strcmp(zMimetype, "text/x-markdown")==0 ){
      rc = FE_RENDER_WIKI;
    }
  }
  return rc;
}
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950




951
952
953
954
955
956
957
                                    int nIframeHeightEm){
  const char * zMime;
  zMime = mimetype_from_name(zFilename);
  if(FE_RENDER_GUESS==renderMode){
    renderMode = fileedit_render_mode_for_mimetype(zMime);
  }
  switch(renderMode){
    case FE_RENDER_HTML:{
      char * z64 = encode64(blob_str(pContent), blob_size(pContent));
      CX("<iframe width='100%%' frameborder='0' "
         "marginwidth='0' style='height:%dem' "
         "marginheight='0' sandbox='allow-same-origin' "
         "id='ifm1' src='data:text/html;base64,%z'"
         "></iframe>",
         nIframeHeightEm ? nIframeHeightEm : 40,
         z64);
      break;




    }
    case FE_RENDER_WIKI:
      wiki_render_by_mimetype(pContent, zMime);
      break;
    default:{
      const char *zExt = strrchr(zFilename,'.');
      const char *zContent = blob_str(pContent);







|









>
>
>
>







935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
                                    int nIframeHeightEm){
  const char * zMime;
  zMime = mimetype_from_name(zFilename);
  if(FE_RENDER_GUESS==renderMode){
    renderMode = fileedit_render_mode_for_mimetype(zMime);
  }
  switch(renderMode){
    case FE_RENDER_HTML_IFRAME:{
      char * z64 = encode64(blob_str(pContent), blob_size(pContent));
      CX("<iframe width='100%%' frameborder='0' "
         "marginwidth='0' style='height:%dem' "
         "marginheight='0' sandbox='allow-same-origin' "
         "id='ifm1' src='data:text/html;base64,%z'"
         "></iframe>",
         nIframeHeightEm ? nIframeHeightEm : 40,
         z64);
      break;
    }
    case FE_RENDER_HTML_INLINE:{
      CX("%b",pContent);
      break;
    }
    case FE_RENDER_WIKI:
      wiki_render_by_mimetype(pContent, zMime);
      break;
    default:{
      const char *zExt = strrchr(zFilename,'.');
      const char *zContent = blob_str(pContent);
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609

1610
1611
1612
1613
1614
1615
1616
1617


1618
1619
1620
1621
1622

1623
1624
1625
1626
1627
1628
1629
  /****** Preview tab ******/
  {
    CX("<div id='fileedit-tab-preview' "
       "data-tab-parent='fileedit-tabs' "
       "data-tab-label='Preview'"
       ">");

    CX("<fieldset class='fileedit-options'>"
       "<legend>Preview...</legend><div>");
    
    CX("<div class='preview-controls'>");
    CX("<button>Refresh</button>");
    /* Default preview rendering mode selection... */
    previewRenderMode = fileedit_render_mode_for_mimetype(zFileMime);
    style_select_list_int("select-preview-mode",
                          "preview_render_mode",
                          "Preview Mode",
                          "Preview mode format.",
                          previewRenderMode,
                          "Guess", FE_RENDER_GUESS,
                          "Wiki/Markdown", FE_RENDER_WIKI,
                          "HTML (iframe)", FE_RENDER_HTML,

                          "Plain Text", FE_RENDER_PLAIN_TEXT,
                          NULL);
    /*
    ** Set up a JS-side mapping of the FE_RENDER_xyz values.  This is
    ** used for dynamically toggling certain UI components on and off.
    */
    blob_appendf(&endScript, "fossil.page.previewModes={"
                 "guess: %d, %d: 'guess', wiki: %d, %d: 'wiki',"


                 "html: %d, %d: 'html', text: %d, %d: 'text'"
                 "};\n",
                 FE_RENDER_GUESS, FE_RENDER_GUESS,
                 FE_RENDER_WIKI, FE_RENDER_WIKI,
                 FE_RENDER_HTML, FE_RENDER_HTML,

                 FE_RENDER_PLAIN_TEXT, FE_RENDER_PLAIN_TEXT);
    /* Allow selection of HTML preview iframe height */
    previewHtmlHeight = atoi(PD("preview_html_ems","0"));
    if(!previewHtmlHeight){
      previewHtmlHeight = 40;
    }
    style_select_list_int("select-preview-html-ems",







|
<
<
<










|
>



|




>
>
|



|
>







1593
1594
1595
1596
1597
1598
1599
1600



1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
  /****** Preview tab ******/
  {
    CX("<div id='fileedit-tab-preview' "
       "data-tab-parent='fileedit-tabs' "
       "data-tab-label='Preview'"
       ">");

    CX("<div class='fileedit-options flex-container row'>");



    CX("<button>Refresh</button>");
    /* Default preview rendering mode selection... */
    previewRenderMode = fileedit_render_mode_for_mimetype(zFileMime);
    style_select_list_int("select-preview-mode",
                          "preview_render_mode",
                          "Preview Mode",
                          "Preview mode format.",
                          previewRenderMode,
                          "Guess", FE_RENDER_GUESS,
                          "Wiki/Markdown", FE_RENDER_WIKI,
                          "HTML (iframe)", FE_RENDER_HTML_IFRAME,
                          "HTML (inline)", FE_RENDER_HTML_INLINE,
                          "Plain Text", FE_RENDER_PLAIN_TEXT,
                          NULL);
    /*
    ** Set up a JS-side mapping of the FE_RENDER_xyz values. This is
    ** used for dynamically toggling certain UI components on and off.
    */
    blob_appendf(&endScript, "fossil.page.previewModes={"
                 "guess: %d, %d: 'guess', wiki: %d, %d: 'wiki',"
                 "htmlIframe: %d, %d: 'htmlIframe', "
                 "htmlInline: %d, %d: 'htmlInline', "
                 "text: %d, %d: 'text'"
                 "};\n",
                 FE_RENDER_GUESS, FE_RENDER_GUESS,
                 FE_RENDER_WIKI, FE_RENDER_WIKI,
                 FE_RENDER_HTML_IFRAME, FE_RENDER_HTML_IFRAME,
                 FE_RENDER_HTML_INLINE, FE_RENDER_HTML_INLINE,
                 FE_RENDER_PLAIN_TEXT, FE_RENDER_PLAIN_TEXT);
    /* Allow selection of HTML preview iframe height */
    previewHtmlHeight = atoi(PD("preview_html_ems","0"));
    if(!previewHtmlHeight){
      previewHtmlHeight = 40;
    }
    style_select_list_int("select-preview-html-ems",
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656


1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
    style_labeled_checkbox("cb-line-numbers",
                           "preview_ln",
                           "Add line numbers to plain-text previews?",
                           "1",
                           "If on, plain-text files (only) will get "
                           "line numbers added to the preview.",
                           P("preview_ln")!=0);
    CX("</div></fieldset>"/*.fileedit-options*/);
    CX("<div id='fileedit-tab-preview-wrapper'></div>");
    CX("</div>"/*#fileedit-tab-preview*/);
  }

  /****** Diff tab ******/
  {
    CX("<div id='fileedit-tab-diff' "
       "data-tab-parent='fileedit-tabs' "
       "data-tab-label='Diff'"
       ">");


    CX("<div id='fileedit-tab-diff-buttons'>"
       "<button class='sbs'>Side-by-side</button>"
       "<button class='unified'>Unified</button>"
       "</div>");
    CX("<div id='fileedit-tab-diff-wrapper'>"
       "Diffs will be shown here."
       "</div>");
    CX("</div>");
  }


  /****** Commit ******/
  CX("<div id='fileedit-tab-commit' "
     "data-tab-parent='fileedit-tabs' "
     "data-tab-label='Commit'"
     ">");

  {
    /******* Flags/options *******/
    CX("<fieldset class='fileedit-options'>"
       "<legend>Options</legend><div>"
       /* Chrome does not sanely lay out multiple
       ** fieldset children after the <legend>, so
       ** a containing div is necessary. */);
    style_labeled_checkbox("cb-dry-run",
                           "dry_run", "Dry-run?", "1",
                           "In dry-run mode, the Save button performs "
                           "all work needed for saving but then rolls "
                           "back the transaction, and thus does not "
                           "really save.",
                           1);







|










>
>
|






|











|
<
<
<
<







1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684




1685
1686
1687
1688
1689
1690
1691
    style_labeled_checkbox("cb-line-numbers",
                           "preview_ln",
                           "Add line numbers to plain-text previews?",
                           "1",
                           "If on, plain-text files (only) will get "
                           "line numbers added to the preview.",
                           P("preview_ln")!=0);
    CX("</div>"/*.fileedit-options*/);
    CX("<div id='fileedit-tab-preview-wrapper'></div>");
    CX("</div>"/*#fileedit-tab-preview*/);
  }

  /****** Diff tab ******/
  {
    CX("<div id='fileedit-tab-diff' "
       "data-tab-parent='fileedit-tabs' "
       "data-tab-label='Diff'"
       ">");

    CX("<div class='fileedit-options flex-container row' "
       "id='fileedit-tab-diff-buttons'>"
       "<button class='sbs'>Side-by-side</button>"
       "<button class='unified'>Unified</button>"
       "</div>");
    CX("<div id='fileedit-tab-diff-wrapper'>"
       "Diffs will be shown here."
       "</div>");
    CX("</div>"/*#fileedit-tab-diff*/);
  }


  /****** Commit ******/
  CX("<div id='fileedit-tab-commit' "
     "data-tab-parent='fileedit-tabs' "
     "data-tab-label='Commit'"
     ">");

  {
    /******* Flags/options *******/
    CX("<div class='fileedit-options flex-container row'>");




    style_labeled_checkbox("cb-dry-run",
                           "dry_run", "Dry-run?", "1",
                           "In dry-run mode, the Save button performs "
                           "all work needed for saving but then rolls "
                           "back the transaction, and thus does not "
                           "really save.",
                           1);
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
                          "editor_font_size", "Editor Font Size",
                          NULL/*tooltip*/,
                          100,
                          "100%", 100, "125%", 125,
                          "150%", 150, "175%", 175,
                          "200%", 200, NULL);
#endif
    CX("</div></fieldset>"/*checkboxes*/);
  }

  { /******* Comment *******/
    CX("<fieldset class='fileedit-options'>"
       "<legend>Message (required)</legend><div>");
    CX("<input type='text' name='comment' "
       "id='fileedit-comment'>");
    /* ^^^ adding the 'required' attribute means we cannot even
       submit for PREVIEW mode if it's empty :/. */
    if(blob_size(&cimi.comment)){
      blob_appendf(&endScript,
                   "document.querySelector('#fileedit-comment').value="
                   "\"%h\";\n", blob_str(&cimi.comment));
    }
    CX("</input>\n");
    CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup "
       "syntax.</div>\n"/*TODO: select for fossil/md/plain text*/);
    CX("</div></fieldset>\n"/*commit comment*/);
    CX("<div>"
       "<button id='fileedit-btn-commit'>Commit</button>"
       "</div>\n");
    CX("<div id='fileedit-manifest'></div>\n");
  }

  CX("</div>"/*#fileedit-tab-commit*/);
  







|


















|







1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
                          "editor_font_size", "Editor Font Size",
                          NULL/*tooltip*/,
                          100,
                          "100%", 100, "125%", 125,
                          "150%", 150, "175%", 175,
                          "200%", 200, NULL);
#endif
    CX("</div>"/*checkboxes*/);
  }

  { /******* Comment *******/
    CX("<fieldset class='fileedit-options'>"
       "<legend>Message (required)</legend><div>");
    CX("<input type='text' name='comment' "
       "id='fileedit-comment'>");
    /* ^^^ adding the 'required' attribute means we cannot even
       submit for PREVIEW mode if it's empty :/. */
    if(blob_size(&cimi.comment)){
      blob_appendf(&endScript,
                   "document.querySelector('#fileedit-comment').value="
                   "\"%h\";\n", blob_str(&cimi.comment));
    }
    CX("</input>\n");
    CX("<div class='fileedit-hint'>Comments use the Fossil wiki markup "
       "syntax.</div>\n"/*TODO: select for fossil/md/plain text*/);
    CX("</div></fieldset>\n"/*commit comment*/);
    CX("<div class='flex-container row'>"
       "<button id='fileedit-btn-commit'>Commit</button>"
       "</div>\n");
    CX("<div id='fileedit-manifest'></div>\n");
  }

  CX("</div>"/*#fileedit-tab-commit*/);
  
Changes to src/fossil.page.fileedit.js.
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        const mode = e.target.value,
              name = P.previewModes[mode],
              hide = [], unhide = [];
        if('guess'===name){
          unhide.push(P.e.cbLineNumbersWrap,
                      P.e.selectHtmlEmsWrap);
        }else{
          if('text'!==name) hide.push(P.e.cbLineNumbersWrap);
          else unhide.push(P.e.cbLineNumbersWrap);
          if('html'!==name) hide.push(P.e.selectHtmlEmsWrap);
          else unhide.push(P.e.selectHtmlEmsWrap);
        }
        hide.forEach((e)=>e.classList.add('hidden'));
        unhide.forEach((e)=>e.classList.remove('hidden'));
      }, false
    );
    selectPreviewMode.dispatchEvent(
      // Force UI update







|
|
|
|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        const mode = e.target.value,
              name = P.previewModes[mode],
              hide = [], unhide = [];
        if('guess'===name){
          unhide.push(P.e.cbLineNumbersWrap,
                      P.e.selectHtmlEmsWrap);
        }else{
          if('text'===name) unhide.push(P.e.cbLineNumbersWrap);
          else hide.push(P.e.cbLineNumbersWrap);
          if('htmlIframe'===name) unhide.push(P.e.selectHtmlEmsWrap);
          else hide.push(P.e.selectHtmlEmsWrap);
        }
        hide.forEach((e)=>e.classList.add('hidden'));
        unhide.forEach((e)=>e.classList.remove('hidden'));
      }, false
    );
    selectPreviewMode.dispatchEvent(
      // Force UI update