Fossil

Check-in [ae8e24d0]
Login

Check-in [ae8e24d0]

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

Overview
Comment:Added SBS/unified diff to /fileedit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | checkin-without-checkout
Files: files | file ages | folders
SHA3-256: ae8e24d0217191c8bc3debfe2f4b5fedcbac41e0a35a589fcc8b0639d151a642
User & Date: stephan 2020-05-04 17:44:10
Context
2020-05-04
17:48
Add the submit button IDs programmatically (was previously hand-coded), to avoid them getting out of sync with their enum. ... (check-in: 032a0326 user: stephan tags: checkin-without-checkout)
17:44
Added SBS/unified diff to /fileedit. ... (check-in: ae8e24d0 user: stephan tags: checkin-without-checkout)
16:22
Style improvements and code consolidation. ... (check-in: 67a2bfb0 user: stephan tags: checkin-without-checkout)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/default_css.txt.

870
871
872
873
874
875
876
877

878
879
880
881
882
883
884
885
886
887
888
889
890
form.fileedit fieldset {
  margin: 0.5em 0 0 0;
  border-radius: 0.5em;
  border-color: inherit;
  border-width: 1px;
}
form.fileedit fieldset > legend {
  margin-left: 1em;

}
form.fileedit fieldset > div {
  margin: 0 0.25em;
}
form.fileedit fieldset > div > .input-with-label {
  padding: 0.5em;
  margin: 0.25em 0.5em;
}
form.fileedit fieldset > div > button {
  margin: 0.25em 0.5em;
}
form.fileedit input:invalid {
  border-left: 0.2em dashed red;







|
>


|


<







870
871
872
873
874
875
876
877
878
879
880
881
882
883

884
885
886
887
888
889
890
form.fileedit fieldset {
  margin: 0.5em 0 0 0;
  border-radius: 0.5em;
  border-color: inherit;
  border-width: 1px;
}
form.fileedit fieldset > legend {
  margin: 0 0 0 1em;
  padding: 0 0.5em 0 0.5em;
}
form.fileedit fieldset > div {
  margin: 0 0.25em 0.25em 0.25em;
}
form.fileedit fieldset > div > .input-with-label {

  margin: 0.25em 0.5em;
}
form.fileedit fieldset > div > button {
  margin: 0.25em 0.5em;
}
form.fileedit input:invalid {
  border-left: 0.2em dashed red;
906
907
908
909
910
911
912








913
914
915
916
917
918
919
  overflow: auto;
}
div.fileedit-preview {
  margin: 0;
  padding: 0;
}
.fileedit-preview > div:first-child {








  border-bottom: 1px dashed;
}

.input-with-label {
  border: 1px inset #808080;
  border-radius: 0.5em;
  padding: 0.25em 0.4em;







>
>
>
>
>
>
>
>







906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
  overflow: auto;
}
div.fileedit-preview {
  margin: 0;
  padding: 0;
}
.fileedit-preview > div:first-child {
  margin: 1em 0 0 0;
  border-bottom: 1px dashed;
}
div.fileedit-diff {
  margin: 0;
  padding: 0;
}
.fileedit-diff > div:first-child {
  border-bottom: 1px dashed;
}

.input-with-label {
  border: 1px inset #808080;
  border-radius: 0.5em;
  padding: 0.25em 0.4em;

Changes to src/fileedit.c.

1055
1056
1057
1058
1059
1060
1061



































1062
1063
1064
1065
1066
1067
1068
        CX("<pre>%h</pre>", zExt+1, zContent);
      }
      break;
    }
  }
  CX("</div><!--.fileedit-preview-->\n");
}




































/*
** Outputs a SELECT list from a compile-time list of integers.
** The vargs must be a list of (const char *, int) pairs, terminated
** with a single NULL. Each pair is interpreted as...
**
** If the (const char *) is NULL, it is the end of the list, else







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
        CX("<pre>%h</pre>", zExt+1, zContent);
      }
      break;
    }
  }
  CX("</div><!--.fileedit-preview-->\n");
}

/*
** Renders diffs for the /fileedit page. pContent is the
** locally-edited content.  frid is the RID of the file's blob entry
** from which pContent is based.  zManifestUuid is the checkin version
** to which RID belongs - it is purely informational, for labeling the
** diff view. isSbs is true for side-by-side diffs, false for unified.
*/
static void fileedit_render_diff(Blob * pContent, int frid,
                                 const char * zManifestUuid,
                                 int isSbs){
  Blob orig = empty_blob;
  Blob out = empty_blob;
  u64 diffFlags = DIFF_HTML | DIFF_NOTTOOBIG | DIFF_STRIP_EOLCR;

  content_get(frid, &orig);
  if(isSbs){
    diffFlags |=  DIFF_SIDEBYSIDE;
  }else{
    diffFlags |= DIFF_LINENO;
  }
  text_diff(&orig, pContent, &out, 0, diffFlags);
  CX("<div class='fileedit-diff'>");
  CX("<div>Diff <code>[%S]</code> &rarr; Local Edits</div>",
     zManifestUuid);
  if(isSbs){
    CX("%b",&out);
  }else{
    CX("<pre class='udiff'>%b</pre>",&out);
  }
  CX("</div><!--.fileedit-diff-->\n");
  blob_reset(&orig);
  blob_reset(&out);
  /* Wow, that was *easy*. */
}

/*
** Outputs a SELECT list from a compile-time list of integers.
** The vargs must be a list of (const char *, int) pairs, terminated
** with a single NULL. Each pair is interpreted as...
**
** If the (const char *) is NULL, it is the end of the list, else
1154
1155
1156
1157
1158
1159
1160
1161
1162

1163
1164
1165
1166
1167
1168
1169
**
** All other parameters are for internal use only, submitted via the
** form-submission process, and may change with any given revision of
** this code.
*/
void fileedit_page(){
  enum submit_modes {
  SUBMIT_NONE = 0, SUBMIT_SAVE = 1, SUBMIT_PREVIEW = 2,
  SUBMIT_DIFF = 3

  };
  const char * zFilename = PD("file",P("name"));
                                        /* filename. We'll accept 'name'
                                           because that param is handled
                                           specially by the core. */
  const char * zRev = P("r");           /* checkin version */
  const char * zContent = P("content"); /* file content */







|
|
>







1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
**
** All other parameters are for internal use only, submitted via the
** form-submission process, and may change with any given revision of
** this code.
*/
void fileedit_page(){
  enum submit_modes {
  SUBMIT_NONE = 0, SUBMIT_SAVE, SUBMIT_PREVIEW,
  SUBMIT_DIFF_SBS, SUBMIT_DIFF_UNIFIED,
  SUBMIT_end /* sentinel for range validation */
  };
  const char * zFilename = PD("file",P("name"));
                                        /* filename. We'll accept 'name'
                                           because that param is handled
                                           specially by the core. */
  const char * zRev = P("r");           /* checkin version */
  const char * zContent = P("content"); /* file content */
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
  if( !g.perm.Write ){
    login_needed(g.anon.Write);
    return;
  }
  db_begin_transaction();
  CheckinMiniInfo_init(&cimi);
  submitMode = atoi(PD("submit","0"));
  if(submitMode < SUBMIT_NONE || submitMode > SUBMIT_DIFF){
    submitMode = 0;
  }
  zFlagCheck = P("comment_mimetype");
  if(zFlagCheck){
    cimi.zCommentMimetype = mprintf("%s",zFlagCheck);
    zFlagCheck = 0;
  }







|







1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
  if( !g.perm.Write ){
    login_needed(g.anon.Write);
    return;
  }
  db_begin_transaction();
  CheckinMiniInfo_init(&cimi);
  submitMode = atoi(PD("submit","0"));
  if(submitMode < SUBMIT_NONE || submitMode >= SUBMIT_end){
    submitMode = 0;
  }
  zFlagCheck = P("comment_mimetype");
  if(zFlagCheck){
    cimi.zCommentMimetype = mprintf("%s",zFlagCheck);
    zFlagCheck = 0;
  }
1467
1468
1469
1470
1471
1472
1473
1474


1475
1476
1477
1478
1479
1480
1481
                             "1",
                             "If on, plain-text files (only) will get "
                             "line numbers added to the preview.",
                             previewLn);
    }
  }
  CX("<button type='submit' name='submit' value='3'>"
     "Diff (TODO)</button>");


  CX("</div></fieldset>");

  /******* End of form *******/    
  CX("</form>\n");

  /* Dynamically populate the editor... */
  if(1==loadMode || (2==loadMode && submitMode>SUBMIT_NONE)){







|
>
>







1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
                             "1",
                             "If on, plain-text files (only) will get "
                             "line numbers added to the preview.",
                             previewLn);
    }
  }
  CX("<button type='submit' name='submit' value='3'>"
     "Diff (SBS)</button>");
  CX("<button type='submit' name='submit' value='4'>"
     "Diff (Unified)</button>");
  CX("</div></fieldset>");

  /******* End of form *******/    
  CX("</form>\n");

  /* Dynamically populate the editor... */
  if(1==loadMode || (2==loadMode && submitMode>SUBMIT_NONE)){
1569
1570
1571
1572
1573
1574
1575
1576
1577


1578
1579
1580
1581
1582
1583
1584
    cimi.pMfOut = 0;
    blob_reset(&manifest);
  }else if(SUBMIT_PREVIEW==submitMode){
    int pflags = 0;
    if(previewLn) pflags |= FE_PREVIEW_LINE_NUMBERS;
    fileedit_render_preview(&cimi.fileContent, cimi.zFilename, pflags,
                            previewRenderMode, previewHtmlHeight);
  }else if(SUBMIT_DIFF==submitMode/*diff*/){
    fail((&err,"Diff mode is still TODO."));


  }else{
    /* Ignore invalid submitMode value */
    goto end_footer;
  }

end_footer:
  zContent = 0;







|
|
>
>







1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
    cimi.pMfOut = 0;
    blob_reset(&manifest);
  }else if(SUBMIT_PREVIEW==submitMode){
    int pflags = 0;
    if(previewLn) pflags |= FE_PREVIEW_LINE_NUMBERS;
    fileedit_render_preview(&cimi.fileContent, cimi.zFilename, pflags,
                            previewRenderMode, previewHtmlHeight);
  }else if(SUBMIT_DIFF_SBS==submitMode
           || SUBMIT_DIFF_UNIFIED==submitMode){
    fileedit_render_diff(&cimi.fileContent, frid, cimi.zParentUuid,
                         SUBMIT_DIFF_SBS==submitMode);
  }else{
    /* Ignore invalid submitMode value */
    goto end_footer;
  }

end_footer:
  zContent = 0;