Fossil SCM

Further enhancements to Skin processing. Provide the ability to save the current Skin using a name.

drh 2015-01-23 23:32 trunk
Commit e5a4206341a5371faf3fcad4b08a58380a660cc3
1 file changed +70 -2
+70 -2
--- src/skins.c
+++ src/skins.c
@@ -66,10 +66,22 @@
6666
free(z);
6767
z = 0;
6868
}
6969
return z;
7070
}
71
+
72
+/*
73
+** Return true if there exists a skin name "zSkinName".
74
+*/
75
+static int skinExists(const char *zSkinName){
76
+ int i;
77
+ if( zSkinName==0 ) return 0;
78
+ for(i=0; i<sizeof(aBuiltinSkin)/sizeof(aBuiltinSkin[0]); i++){
79
+ if( fossil_strcmp(zSkinName, aBuiltinSkin[i].zDesc)==0 ) return 1;
80
+ }
81
+ return db_exists("SELECT 1 FROM config WHERE name='skin:%q'", zSkinName);
82
+}
7183
7284
/*
7385
** Construct and return an string of SQL statements that represents
7486
** a "skin" setting. If zName==0 then return the skin currently
7587
** installed. Otherwise, return one of the built-in skins designated
@@ -110,21 +122,27 @@
110122
** Return FALSE to continue with the main Skins page.
111123
*/
112124
static int skinRename(void){
113125
const char *zOldName;
114126
const char *zNewName;
127
+ int ex = 0;
115128
if( P("rename")==0 ) return 0;
116129
zOldName = P("sn");
117130
zNewName = P("newname");
118131
if( zOldName==0 ) return 0;
119
- if( zNewName==0 || zNewName[0]==0 ){
132
+ if( zNewName==0 || zNewName[0]==0 || (ex = skinExists(zNewName))!=0 ){
133
+ if( zNewName==0 ) zNewName = zOldName;
120134
style_header("Rename A Skin");
135
+ if( ex ){
136
+ @ <p><span class="generalError">There is already another skin
137
+ @ named "%h(zNewName)". Choose a different name.</span></p>
138
+ }
121139
@ <form action="%s(g.zTop)/setup_skin" method="post"><div>
122140
@ <table border="0"><tr>
123141
@ <tr><td align="right">Current name:<td align="left"><b>%h(zOldName)</b>
124142
@ <tr><td align="right">New name:<td align="left">
125
- @ <input type="text" size="35" name="newname" value="%h(zOldName)">
143
+ @ <input type="text" size="35" name="newname" value="%h(zNewName)">
126144
@ <tr><td><td>
127145
@ <input type="hidden" name="sn" value="%h(zOldName)">
128146
@ <input type="submit" name="rename" value="Rename">
129147
@ <input type="submit" name="canren" value="Cancel">
130148
@ </table>
@@ -137,10 +155,49 @@
137155
"UPDATE config SET name='skin:%q' WHERE name='skin:%q';",
138156
zNewName, zOldName
139157
);
140158
return 0;
141159
}
160
+
161
+/*
162
+** Respond to a Save button press. Return TRUE if a dialog was painted.
163
+** Return FALSE to continue with the main Skins page.
164
+*/
165
+static int skinSave(const char *zCurrent){
166
+ const char *zNewName;
167
+ int ex = 0;
168
+ if( P("save")==0 ) return 0;
169
+ zNewName = P("svname");
170
+ if( zNewName && zNewName[0]!=0 ){
171
+ }
172
+ if( zNewName==0 || zNewName[0]==0 || (ex = skinExists(zNewName))!=0 ){
173
+ if( zNewName==0 ) zNewName = "";
174
+ style_header("Save Current Skin");
175
+ if( ex ){
176
+ @ <p><span class="generalError">There is already another skin
177
+ @ named "%h(zNewName)". Choose a different name.</span></p>
178
+ }
179
+ @ <form action="%s(g.zTop)/setup_skin" method="post"><div>
180
+ @ <table border="0"><tr>
181
+ @ <tr><td align="right">Name for this skin:<td align="left">
182
+ @ <input type="text" size="35" name="svname" value="%h(zNewName)">
183
+ @ <tr><td><td>
184
+ @ <input type="submit" name="save" value="Save">
185
+ @ <input type="submit" name="cansave" value="Cancel">
186
+ @ </table>
187
+ login_insert_csrf_secret();
188
+ @ </div></form>
189
+ style_footer();
190
+ return 1;
191
+ }
192
+ db_multi_exec(
193
+ "INSERT OR IGNORE INTO config(name, value, mtime)"
194
+ "VALUES('skin:%q',%Q,now())",
195
+ zNewName, zCurrent
196
+ );
197
+ return 0;
198
+}
142199
143200
/*
144201
** WEBPAGE: setup_skin
145202
*/
146203
void setup_skin(void){
@@ -148,10 +205,11 @@
148205
char *zName;
149206
char *zErr = 0;
150207
const char *zCurrent = 0; /* Current skin */
151208
int i; /* Loop counter */
152209
Stmt q;
210
+ int seenCurrent = 0;
153211
154212
login_check_credentials();
155213
if( !g.perm.Setup ){
156214
login_needed();
157215
}
@@ -177,10 +235,11 @@
177235
}
178236
if( P("del2")!=0 && (zName = skinVarName(P("sn"), 1))!=0 ){
179237
db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
180238
}
181239
if( skinRename() ) return;
240
+ if( skinSave(zCurrent) ) return;
182241
183242
/* The user pressed one of the "Install" buttons. */
184243
if( P("load") && (z = P("sn"))!=0 && z[0] ){
185244
int seen = 0;
186245
@@ -235,10 +294,11 @@
235294
for(i=0; i<sizeof(aBuiltinSkin)/sizeof(aBuiltinSkin[0]); i++){
236295
z = aBuiltinSkin[i].zDesc;
237296
@ <tr><td>%d(i+1).<td>%h(z)<td>&nbsp;&nbsp;<td>
238297
if( fossil_strcmp(aBuiltinSkin[i].zSQL, zCurrent)==0 ){
239298
@ (Currently In Use)
299
+ seenCurrent = 1;
240300
}else{
241301
@ <form action="%s(g.zTop)/setup_skin" method="post">
242302
@ <input type="hidden" name="sn" value="%h(z)" />
243303
@ <input type="submit" name="load" value="Install" />
244304
@ </form>
@@ -256,18 +316,26 @@
256316
i++;
257317
@ <tr><td>%d(i).<td>%h(zN)<td>&nbsp;&nbsp;<td>
258318
@ <form action="%s(g.zTop)/setup_skin" method="post">
259319
if( fossil_strcmp(zV, zCurrent)==0 ){
260320
@ (Currently In Use)
321
+ seenCurrent = 1;
261322
}else{
262323
@ <input type="submit" name="load" value="Install">
263324
@ <input type="submit" name="del1" value="Delete">
264325
}
265326
@ <input type="submit" name="rename" value="Rename">
266327
@ <input type="hidden" name="sn" value="%h(zN)">
267328
@ </form></tr>
268329
}
269330
db_finalize(&q);
331
+ if( !seenCurrent ){
332
+ i++;
333
+ @ <tr><td>%d(i).<td><i>Current Configuration</i><td>&nbsp;&nbsp;<td>
334
+ @ <form action="%s(g.zTop)/setup_skin" method="post">
335
+ @ <input type="submit" name="save" value="Save">
336
+ @ </form>
337
+ }
270338
@ </table>
271339
style_footer();
272340
db_end_transaction(0);
273341
}
274342
--- src/skins.c
+++ src/skins.c
@@ -66,10 +66,22 @@
66 free(z);
67 z = 0;
68 }
69 return z;
70 }
 
 
 
 
 
 
 
 
 
 
 
 
71
72 /*
73 ** Construct and return an string of SQL statements that represents
74 ** a "skin" setting. If zName==0 then return the skin currently
75 ** installed. Otherwise, return one of the built-in skins designated
@@ -110,21 +122,27 @@
110 ** Return FALSE to continue with the main Skins page.
111 */
112 static int skinRename(void){
113 const char *zOldName;
114 const char *zNewName;
 
115 if( P("rename")==0 ) return 0;
116 zOldName = P("sn");
117 zNewName = P("newname");
118 if( zOldName==0 ) return 0;
119 if( zNewName==0 || zNewName[0]==0 ){
 
120 style_header("Rename A Skin");
 
 
 
 
121 @ <form action="%s(g.zTop)/setup_skin" method="post"><div>
122 @ <table border="0"><tr>
123 @ <tr><td align="right">Current name:<td align="left"><b>%h(zOldName)</b>
124 @ <tr><td align="right">New name:<td align="left">
125 @ <input type="text" size="35" name="newname" value="%h(zOldName)">
126 @ <tr><td><td>
127 @ <input type="hidden" name="sn" value="%h(zOldName)">
128 @ <input type="submit" name="rename" value="Rename">
129 @ <input type="submit" name="canren" value="Cancel">
130 @ </table>
@@ -137,10 +155,49 @@
137 "UPDATE config SET name='skin:%q' WHERE name='skin:%q';",
138 zNewName, zOldName
139 );
140 return 0;
141 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
143 /*
144 ** WEBPAGE: setup_skin
145 */
146 void setup_skin(void){
@@ -148,10 +205,11 @@
148 char *zName;
149 char *zErr = 0;
150 const char *zCurrent = 0; /* Current skin */
151 int i; /* Loop counter */
152 Stmt q;
 
153
154 login_check_credentials();
155 if( !g.perm.Setup ){
156 login_needed();
157 }
@@ -177,10 +235,11 @@
177 }
178 if( P("del2")!=0 && (zName = skinVarName(P("sn"), 1))!=0 ){
179 db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
180 }
181 if( skinRename() ) return;
 
182
183 /* The user pressed one of the "Install" buttons. */
184 if( P("load") && (z = P("sn"))!=0 && z[0] ){
185 int seen = 0;
186
@@ -235,10 +294,11 @@
235 for(i=0; i<sizeof(aBuiltinSkin)/sizeof(aBuiltinSkin[0]); i++){
236 z = aBuiltinSkin[i].zDesc;
237 @ <tr><td>%d(i+1).<td>%h(z)<td>&nbsp;&nbsp;<td>
238 if( fossil_strcmp(aBuiltinSkin[i].zSQL, zCurrent)==0 ){
239 @ (Currently In Use)
 
240 }else{
241 @ <form action="%s(g.zTop)/setup_skin" method="post">
242 @ <input type="hidden" name="sn" value="%h(z)" />
243 @ <input type="submit" name="load" value="Install" />
244 @ </form>
@@ -256,18 +316,26 @@
256 i++;
257 @ <tr><td>%d(i).<td>%h(zN)<td>&nbsp;&nbsp;<td>
258 @ <form action="%s(g.zTop)/setup_skin" method="post">
259 if( fossil_strcmp(zV, zCurrent)==0 ){
260 @ (Currently In Use)
 
261 }else{
262 @ <input type="submit" name="load" value="Install">
263 @ <input type="submit" name="del1" value="Delete">
264 }
265 @ <input type="submit" name="rename" value="Rename">
266 @ <input type="hidden" name="sn" value="%h(zN)">
267 @ </form></tr>
268 }
269 db_finalize(&q);
 
 
 
 
 
 
 
270 @ </table>
271 style_footer();
272 db_end_transaction(0);
273 }
274
--- src/skins.c
+++ src/skins.c
@@ -66,10 +66,22 @@
66 free(z);
67 z = 0;
68 }
69 return z;
70 }
71
72 /*
73 ** Return true if there exists a skin name "zSkinName".
74 */
75 static int skinExists(const char *zSkinName){
76 int i;
77 if( zSkinName==0 ) return 0;
78 for(i=0; i<sizeof(aBuiltinSkin)/sizeof(aBuiltinSkin[0]); i++){
79 if( fossil_strcmp(zSkinName, aBuiltinSkin[i].zDesc)==0 ) return 1;
80 }
81 return db_exists("SELECT 1 FROM config WHERE name='skin:%q'", zSkinName);
82 }
83
84 /*
85 ** Construct and return an string of SQL statements that represents
86 ** a "skin" setting. If zName==0 then return the skin currently
87 ** installed. Otherwise, return one of the built-in skins designated
@@ -110,21 +122,27 @@
122 ** Return FALSE to continue with the main Skins page.
123 */
124 static int skinRename(void){
125 const char *zOldName;
126 const char *zNewName;
127 int ex = 0;
128 if( P("rename")==0 ) return 0;
129 zOldName = P("sn");
130 zNewName = P("newname");
131 if( zOldName==0 ) return 0;
132 if( zNewName==0 || zNewName[0]==0 || (ex = skinExists(zNewName))!=0 ){
133 if( zNewName==0 ) zNewName = zOldName;
134 style_header("Rename A Skin");
135 if( ex ){
136 @ <p><span class="generalError">There is already another skin
137 @ named "%h(zNewName)". Choose a different name.</span></p>
138 }
139 @ <form action="%s(g.zTop)/setup_skin" method="post"><div>
140 @ <table border="0"><tr>
141 @ <tr><td align="right">Current name:<td align="left"><b>%h(zOldName)</b>
142 @ <tr><td align="right">New name:<td align="left">
143 @ <input type="text" size="35" name="newname" value="%h(zNewName)">
144 @ <tr><td><td>
145 @ <input type="hidden" name="sn" value="%h(zOldName)">
146 @ <input type="submit" name="rename" value="Rename">
147 @ <input type="submit" name="canren" value="Cancel">
148 @ </table>
@@ -137,10 +155,49 @@
155 "UPDATE config SET name='skin:%q' WHERE name='skin:%q';",
156 zNewName, zOldName
157 );
158 return 0;
159 }
160
161 /*
162 ** Respond to a Save button press. Return TRUE if a dialog was painted.
163 ** Return FALSE to continue with the main Skins page.
164 */
165 static int skinSave(const char *zCurrent){
166 const char *zNewName;
167 int ex = 0;
168 if( P("save")==0 ) return 0;
169 zNewName = P("svname");
170 if( zNewName && zNewName[0]!=0 ){
171 }
172 if( zNewName==0 || zNewName[0]==0 || (ex = skinExists(zNewName))!=0 ){
173 if( zNewName==0 ) zNewName = "";
174 style_header("Save Current Skin");
175 if( ex ){
176 @ <p><span class="generalError">There is already another skin
177 @ named "%h(zNewName)". Choose a different name.</span></p>
178 }
179 @ <form action="%s(g.zTop)/setup_skin" method="post"><div>
180 @ <table border="0"><tr>
181 @ <tr><td align="right">Name for this skin:<td align="left">
182 @ <input type="text" size="35" name="svname" value="%h(zNewName)">
183 @ <tr><td><td>
184 @ <input type="submit" name="save" value="Save">
185 @ <input type="submit" name="cansave" value="Cancel">
186 @ </table>
187 login_insert_csrf_secret();
188 @ </div></form>
189 style_footer();
190 return 1;
191 }
192 db_multi_exec(
193 "INSERT OR IGNORE INTO config(name, value, mtime)"
194 "VALUES('skin:%q',%Q,now())",
195 zNewName, zCurrent
196 );
197 return 0;
198 }
199
200 /*
201 ** WEBPAGE: setup_skin
202 */
203 void setup_skin(void){
@@ -148,10 +205,11 @@
205 char *zName;
206 char *zErr = 0;
207 const char *zCurrent = 0; /* Current skin */
208 int i; /* Loop counter */
209 Stmt q;
210 int seenCurrent = 0;
211
212 login_check_credentials();
213 if( !g.perm.Setup ){
214 login_needed();
215 }
@@ -177,10 +235,11 @@
235 }
236 if( P("del2")!=0 && (zName = skinVarName(P("sn"), 1))!=0 ){
237 db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
238 }
239 if( skinRename() ) return;
240 if( skinSave(zCurrent) ) return;
241
242 /* The user pressed one of the "Install" buttons. */
243 if( P("load") && (z = P("sn"))!=0 && z[0] ){
244 int seen = 0;
245
@@ -235,10 +294,11 @@
294 for(i=0; i<sizeof(aBuiltinSkin)/sizeof(aBuiltinSkin[0]); i++){
295 z = aBuiltinSkin[i].zDesc;
296 @ <tr><td>%d(i+1).<td>%h(z)<td>&nbsp;&nbsp;<td>
297 if( fossil_strcmp(aBuiltinSkin[i].zSQL, zCurrent)==0 ){
298 @ (Currently In Use)
299 seenCurrent = 1;
300 }else{
301 @ <form action="%s(g.zTop)/setup_skin" method="post">
302 @ <input type="hidden" name="sn" value="%h(z)" />
303 @ <input type="submit" name="load" value="Install" />
304 @ </form>
@@ -256,18 +316,26 @@
316 i++;
317 @ <tr><td>%d(i).<td>%h(zN)<td>&nbsp;&nbsp;<td>
318 @ <form action="%s(g.zTop)/setup_skin" method="post">
319 if( fossil_strcmp(zV, zCurrent)==0 ){
320 @ (Currently In Use)
321 seenCurrent = 1;
322 }else{
323 @ <input type="submit" name="load" value="Install">
324 @ <input type="submit" name="del1" value="Delete">
325 }
326 @ <input type="submit" name="rename" value="Rename">
327 @ <input type="hidden" name="sn" value="%h(zN)">
328 @ </form></tr>
329 }
330 db_finalize(&q);
331 if( !seenCurrent ){
332 i++;
333 @ <tr><td>%d(i).<td><i>Current Configuration</i><td>&nbsp;&nbsp;<td>
334 @ <form action="%s(g.zTop)/setup_skin" method="post">
335 @ <input type="submit" name="save" value="Save">
336 @ </form>
337 }
338 @ </table>
339 style_footer();
340 db_end_transaction(0);
341 }
342

Keyboard Shortcuts

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