diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index f746c123..83f38dee 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1054,9 +1054,12 @@ static void documentWasChanged_DocumentWidget_(iDocumentWidget *d) { | |||
1054 | 1054 | ||
1055 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { | 1055 | void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) { |
1056 | setUrl_GmDocument(d->doc, d->mod.url); | 1056 | setUrl_GmDocument(d->doc, d->mod.url); |
1057 | const int docWidth = documentWidth_DocumentWidget_(d); | ||
1058 | const int outsideMargin = (width_Widget(d) - docWidth) / 2; | ||
1057 | setSource_GmDocument(d->doc, | 1059 | setSource_GmDocument(d->doc, |
1058 | source, | 1060 | source, |
1059 | documentWidth_DocumentWidget_(d), | 1061 | docWidth, |
1062 | outsideMargin, | ||
1060 | isFinished_GmRequest(d->request) ? final_GmDocumentUpdate | 1063 | isFinished_GmRequest(d->request) ? final_GmDocumentUpdate |
1061 | : partial_GmDocumentUpdate); | 1064 | : partial_GmDocumentUpdate); |
1062 | documentWasChanged_DocumentWidget_(d); | 1065 | documentWasChanged_DocumentWidget_(d); |
@@ -1165,13 +1168,25 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode | |||
1165 | iString *key = collectNew_String(); | 1168 | iString *key = collectNew_String(); |
1166 | toString_Sym(SDLK_s, KMOD_PRIMARY, key); | 1169 | toString_Sym(SDLK_s, KMOD_PRIMARY, key); |
1167 | appendFormat_String(src, "\n```\n%s\n```\n", cstr_String(meta)); | 1170 | appendFormat_String(src, "\n```\n%s\n```\n", cstr_String(meta)); |
1168 | makeFooterButtons_DocumentWidget_( | 1171 | const char *mtype = mediaTypeFromFileExtension_String(d->mod.url); |
1169 | d, | 1172 | iArray items; |
1170 | (iMenuItem[]){ { translateCStr_Lang(download_Icon " " saveToDownloads_Label), | 1173 | init_Array(&items, sizeof(iMenuItem)); |
1171 | 0, | 1174 | if (iCmpStr(mtype, "application/octet-stream")) { |
1172 | 0, | 1175 | pushBack_Array( |
1173 | "document.save" } }, | 1176 | &items, |
1174 | 1); | 1177 | &(iMenuItem){ translateCStr_Lang(format_CStr("View as \"%s\"", mtype)), |
1178 | SDLK_RETURN, | ||
1179 | 0, | ||
1180 | format_CStr("document.setmediatype mime:%s", mtype) }); | ||
1181 | } | ||
1182 | pushBack_Array( | ||
1183 | &items, | ||
1184 | &(iMenuItem){ translateCStr_Lang(download_Icon " " saveToDownloads_Label), | ||
1185 | 0, | ||
1186 | 0, | ||
1187 | "document.save" }); | ||
1188 | makeFooterButtons_DocumentWidget_(d, data_Array(&items), size_Array(&items)); | ||
1189 | deinit_Array(&items); | ||
1175 | break; | 1190 | break; |
1176 | } | 1191 | } |
1177 | default: | 1192 | default: |
@@ -2254,7 +2269,7 @@ static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumen | |||
2254 | /* TODO: First *fully* visible run? */ | 2269 | /* TODO: First *fully* visible run? */ |
2255 | voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); | 2270 | voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); |
2256 | } | 2271 | } |
2257 | setWidth_GmDocument(d->doc, newWidth); | 2272 | setWidth_GmDocument(d->doc, newWidth, (width_Widget(d) - newWidth) / 2); |
2258 | documentRunsInvalidated_DocumentWidget_(d); | 2273 | documentRunsInvalidated_DocumentWidget_(d); |
2259 | if (runLoc && !keepCenter) { | 2274 | if (runLoc && !keepCenter) { |
2260 | run = findRunAtLoc_GmDocument(d->doc, runLoc); | 2275 | run = findRunAtLoc_GmDocument(d->doc, runLoc); |
@@ -3173,6 +3188,10 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
3173 | document_App() == d) { | 3188 | document_App() == d) { |
3174 | return handleSwipe_DocumentWidget_(d, cmd); | 3189 | return handleSwipe_DocumentWidget_(d, cmd); |
3175 | } | 3190 | } |
3191 | else if (equal_Command(cmd, "document.setmediatype") && document_App() == d) { | ||
3192 | setUrlAndSource_DocumentWidget(d, d->mod.url, string_Command(cmd, "mime"), &d->sourceContent); | ||
3193 | return iTrue; | ||
3194 | } | ||
3176 | return iFalse; | 3195 | return iFalse; |
3177 | } | 3196 | } |
3178 | 3197 | ||