Fossil SCM

Improvements to the skin editor.

drh 2018-08-31 13:05 trunk
Commit bd2bf81c352f67940f1cfbb8556ff94c65858680a61f9393fbd5536a5f262338
1 file changed +20 -9
+20 -9
--- src/skins.c
+++ src/skins.c
@@ -703,18 +703,21 @@
703703
/* 1 */ { "footer", "Page Footer", "Footer", },
704704
/* 2 */ { "header", "Page Header", "Header", },
705705
/* 3 */ { "details", "Display Details", "Details", },
706706
};
707707
const char *zBasis; /* The baseline file */
708
+ const char *zOrig; /* Original content prior to editing */
708709
const char *zContent; /* Content after editing */
710
+ const char *zDflt; /* Default content */
709711
char *zDraft; /* Which draft: "draft%d" */
710712
char *zKey; /* CONFIG table key name: "draft%d-%s" */
711713
char *zTitle; /* Title of this page */
712714
const char *zFile; /* One of "css", "footer", "header", "details" */
713715
int iSkin; /* draft number. 1..9 */
714716
int ii; /* Index in aSkinAttr[] of this file */
715717
int j; /* Loop counter */
718
+ int isRevert = 0; /* True if Revert-to-Baseline was pressed */
716719
717720
login_check_credentials();
718721
719722
/* Figure out which skin we are editing */
720723
iSkin = atoi(PD("sk","1"));
@@ -745,33 +748,41 @@
745748
zFile = aSkinAttr[ii].zFile;
746749
zDraft = mprintf("draft%d", iSkin);
747750
zKey = mprintf("draft%d-%s", iSkin, zFile);
748751
zTitle = mprintf("%s for Draft%d", aSkinAttr[ii].zTitle, iSkin);
749752
zBasis = PD("basis","current");
753
+ zDflt = skin_file_content(zBasis, zFile);
754
+ zOrig = db_get(zKey, zDflt);
755
+ zContent = PD(zFile,zOrig);
756
+ if( P("revert")!=0 && cgi_csrf_safe(0) ){
757
+ zContent = zDflt;
758
+ isRevert = 1;
759
+ }
750760
751761
db_begin_transaction();
752762
style_header("%s", zTitle);
753763
for(j=0; j<count(aSkinAttr); j++){
754
- if( j==ii ) continue;
755764
style_submenu_element(aSkinAttr[j].zSubmenu,
756765
"%R/setup_skinedit?w=%d&basis=%h&sk=%d",j,zBasis,iSkin);
757766
}
758767
@ <form action="%s(g.zTop)/setup_skinedit" method="post"><div>
759768
login_insert_csrf_secret();
760769
@ <input type='hidden' name='w' value='%d(ii)'>
761770
@ <input type='hidden' name='sk' value='%d(iSkin)'>
762771
@ <h2>Edit %s(zTitle):</h2>
763
- zContent = textarea_attribute(
764
- "", /* Text label */
765
- 10, 80, /* Height and width of the edit area */
766
- zKey, /* Name of CONFIG table entry */
767
- zFile, /* CGI query parameter name */
768
- skin_file_content(zBasis, zFile), /* Default value of the text */
769
- 0 /* Disabled flag */
770
- );
772
+ if( P("submit") && cgi_csrf_safe(0) && strcmp(zOrig,zContent)!=0 ){
773
+ db_set(zKey, zContent, 0);
774
+ }
775
+ @ <textarea name="%s(zFile)" rows="10" cols="80">\
776
+ @ %h(zContent)</textarea>
771777
@ <br />
772778
@ <input type="submit" name="submit" value="Apply Changes" />
779
+ if( isRevert ){
780
+ @ &larr; Press to complete reversion to "%s(zBasis)"
781
+ }else if( fossil_strcmp(zContent,zDflt)!=0 ){
782
+ @ <input type="submit" name="revert" value='Revert To "%s(zBasis)"' />
783
+ }
773784
@ <hr />
774785
@ Baseline: \
775786
skin_emit_skin_selector("basis", zBasis, zDraft);
776787
@ <input type="submit" name="diff" value="Unified Diff" />
777788
@ <input type="submit" name="sbsdiff" value="Side-by-Side Diff" />
778789
--- src/skins.c
+++ src/skins.c
@@ -703,18 +703,21 @@
703 /* 1 */ { "footer", "Page Footer", "Footer", },
704 /* 2 */ { "header", "Page Header", "Header", },
705 /* 3 */ { "details", "Display Details", "Details", },
706 };
707 const char *zBasis; /* The baseline file */
 
708 const char *zContent; /* Content after editing */
 
709 char *zDraft; /* Which draft: "draft%d" */
710 char *zKey; /* CONFIG table key name: "draft%d-%s" */
711 char *zTitle; /* Title of this page */
712 const char *zFile; /* One of "css", "footer", "header", "details" */
713 int iSkin; /* draft number. 1..9 */
714 int ii; /* Index in aSkinAttr[] of this file */
715 int j; /* Loop counter */
 
716
717 login_check_credentials();
718
719 /* Figure out which skin we are editing */
720 iSkin = atoi(PD("sk","1"));
@@ -745,33 +748,41 @@
745 zFile = aSkinAttr[ii].zFile;
746 zDraft = mprintf("draft%d", iSkin);
747 zKey = mprintf("draft%d-%s", iSkin, zFile);
748 zTitle = mprintf("%s for Draft%d", aSkinAttr[ii].zTitle, iSkin);
749 zBasis = PD("basis","current");
 
 
 
 
 
 
 
750
751 db_begin_transaction();
752 style_header("%s", zTitle);
753 for(j=0; j<count(aSkinAttr); j++){
754 if( j==ii ) continue;
755 style_submenu_element(aSkinAttr[j].zSubmenu,
756 "%R/setup_skinedit?w=%d&basis=%h&sk=%d",j,zBasis,iSkin);
757 }
758 @ <form action="%s(g.zTop)/setup_skinedit" method="post"><div>
759 login_insert_csrf_secret();
760 @ <input type='hidden' name='w' value='%d(ii)'>
761 @ <input type='hidden' name='sk' value='%d(iSkin)'>
762 @ <h2>Edit %s(zTitle):</h2>
763 zContent = textarea_attribute(
764 "", /* Text label */
765 10, 80, /* Height and width of the edit area */
766 zKey, /* Name of CONFIG table entry */
767 zFile, /* CGI query parameter name */
768 skin_file_content(zBasis, zFile), /* Default value of the text */
769 0 /* Disabled flag */
770 );
771 @ <br />
772 @ <input type="submit" name="submit" value="Apply Changes" />
 
 
 
 
 
773 @ <hr />
774 @ Baseline: \
775 skin_emit_skin_selector("basis", zBasis, zDraft);
776 @ <input type="submit" name="diff" value="Unified Diff" />
777 @ <input type="submit" name="sbsdiff" value="Side-by-Side Diff" />
778
--- src/skins.c
+++ src/skins.c
@@ -703,18 +703,21 @@
703 /* 1 */ { "footer", "Page Footer", "Footer", },
704 /* 2 */ { "header", "Page Header", "Header", },
705 /* 3 */ { "details", "Display Details", "Details", },
706 };
707 const char *zBasis; /* The baseline file */
708 const char *zOrig; /* Original content prior to editing */
709 const char *zContent; /* Content after editing */
710 const char *zDflt; /* Default content */
711 char *zDraft; /* Which draft: "draft%d" */
712 char *zKey; /* CONFIG table key name: "draft%d-%s" */
713 char *zTitle; /* Title of this page */
714 const char *zFile; /* One of "css", "footer", "header", "details" */
715 int iSkin; /* draft number. 1..9 */
716 int ii; /* Index in aSkinAttr[] of this file */
717 int j; /* Loop counter */
718 int isRevert = 0; /* True if Revert-to-Baseline was pressed */
719
720 login_check_credentials();
721
722 /* Figure out which skin we are editing */
723 iSkin = atoi(PD("sk","1"));
@@ -745,33 +748,41 @@
748 zFile = aSkinAttr[ii].zFile;
749 zDraft = mprintf("draft%d", iSkin);
750 zKey = mprintf("draft%d-%s", iSkin, zFile);
751 zTitle = mprintf("%s for Draft%d", aSkinAttr[ii].zTitle, iSkin);
752 zBasis = PD("basis","current");
753 zDflt = skin_file_content(zBasis, zFile);
754 zOrig = db_get(zKey, zDflt);
755 zContent = PD(zFile,zOrig);
756 if( P("revert")!=0 && cgi_csrf_safe(0) ){
757 zContent = zDflt;
758 isRevert = 1;
759 }
760
761 db_begin_transaction();
762 style_header("%s", zTitle);
763 for(j=0; j<count(aSkinAttr); j++){
 
764 style_submenu_element(aSkinAttr[j].zSubmenu,
765 "%R/setup_skinedit?w=%d&basis=%h&sk=%d",j,zBasis,iSkin);
766 }
767 @ <form action="%s(g.zTop)/setup_skinedit" method="post"><div>
768 login_insert_csrf_secret();
769 @ <input type='hidden' name='w' value='%d(ii)'>
770 @ <input type='hidden' name='sk' value='%d(iSkin)'>
771 @ <h2>Edit %s(zTitle):</h2>
772 if( P("submit") && cgi_csrf_safe(0) && strcmp(zOrig,zContent)!=0 ){
773 db_set(zKey, zContent, 0);
774 }
775 @ <textarea name="%s(zFile)" rows="10" cols="80">\
776 @ %h(zContent)</textarea>
 
 
 
777 @ <br />
778 @ <input type="submit" name="submit" value="Apply Changes" />
779 if( isRevert ){
780 @ &larr; Press to complete reversion to "%s(zBasis)"
781 }else if( fossil_strcmp(zContent,zDflt)!=0 ){
782 @ <input type="submit" name="revert" value='Revert To "%s(zBasis)"' />
783 }
784 @ <hr />
785 @ Baseline: \
786 skin_emit_skin_selector("basis", zBasis, zDraft);
787 @ <input type="submit" name="diff" value="Unified Diff" />
788 @ <input type="submit" name="sbsdiff" value="Side-by-Side Diff" />
789

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button