DTEDITORSAVECONTENTSTOFILE(3)
β¨ NAME β¨
DtEditorSaveContentsToFile β library call: save the contents of a DtEditor widget to a file. πΎβ¨
β¨ SYNOPSIS β¨
#include &<Dt/Editor.h>
DtEditorErrorCode DtEditorSaveContentsToFile(
Widget widget,
char *fileName,
Boolean overwriteIfExists,
Boolean hardCarriageReturns,
Boolean markContentsAsSaved);
β¨ DESCRIPTION β¨
Okay bestie, so DtEditorSaveContentsToFile takes the entire contents of your DtEditor widget and saves them to a file. You can optionally replace soft line feeds β aka word wraps β with <newline>s. π
If the file does not exist and the directory has the correct write permissions, the file gets created. If the file does exist and overwriteIfExists is set to True, the fileβs contents get overwritten. If the file or its directory does not have the correct write permissions, an error is returned. No cap, permissions matter.
The DtEditor widget is lowkey tracking whether its contents have changed since they were last saved or retrieved. If markContentsAsSaved is set to False, a copy of the data is saved without affecting whether DtEditorCheckForUnsavedChanges(3) reports that there are unsaved changes. Thatβs the move when the app needs to save a copy of the contents to a temporary file. π§
The Arguments, Bestie
widgetβ the DtEditor widget ID. Thatβs the main character right there.fileNameβ the pathname of the file, relative to the local system. πoverwriteIfExistsβ if set toTrue, it causesDtEditorSaveContentsToFileto save the widget contents even though the file specified byfileNameexists and has correct write permissions. If set toFalse,DtEditorSaveContentsToFilereturnsDtEDITOR_WRITABLE_FILE.hardCarriageReturnsβ if set toTrue, it indicates that the widget should replace any soft line feeds (word wraps) with<newline>s when saving the data. If set toFalse, any line wrapped because it reaches the right edge of the window is saved as one complete line.markContentsAsSavedβ when set toTrue, it causes the DtEditor widget to mark that all changes made to date have been saved. When set toFalse, the DtEditor widget does not change its status regarding unsaved changes. And if an error arises during the save, the status does not change, regardless of the value ofmarkContentsAsSaved. Important vibe check.
For a complete definition of the DtEditor widget and its associated resources, see DtEditor(3).
β¨ RETURN VALUE β¨
Upon successful completion, DtEditorSaveContentsToFile returns DtEDITOR_NO_ERRORS. Otherwise, if it cannot save the data to the file, the function returns one of these values:
DtEDITOR_INVALID_FILENAMEβ no file was specified.DtEDITOR_UNWRITABLE_FILEβ the application does not have write permission for the file or directory.DtEDITOR_CHAR_SPECIAL_FILEβ the file is a device-special file.DtEDITOR_BLOCK_MODE_FILEβ the file is a block-mode device.DtEDITOR_NO_FILE_ACCESSβ the file cannot be accessed.DtEDITOR_SAVE_FAILEDβ the contents could not be saved for an unspecified reason.DtEDITOR_WRITABLE_FILEβ the named files exist and theoverwriteIfExistsargument is set toFalse.
β¨ EXAMPLES β¨
This code segment saves the contents of a DtEditor widget to the local file Foo, substituting <newline>s for soft line feeds. It also indicates that all changes to the contents of the widget have been saved. Copy it exactly, bestie: π
Widget editor;
DtEditorErrorCode status;
char *fname = "Foo";
Boolean overwrite = False,
hardReturns = True,
markContentsAsSaved = True;
status = DtEditorSaveContentsToFile(editor, fname, overwrite,
hardReturns, markContentsAsSaved);
switch(status)
{
case DtEDITOR_NO_ERRORS:
break;
case DtEDITOR_WRITABLE_FILE:
printf("Save failed. The file already exists.0);
break;
default:
printf("Could not save contents.0);
break;
}
β¨ APPLICATION USAGE β¨
Your app should use DtEditorGetContents(3) to retrieve the data into a memory buffer, rather than a disk file. Memory buffer is the vibe here. π§ π
β¨ SEE ALSO β¨
Dt/Editor.h-DtEditor(5)DtEditor(3)DtEditorAppend(3)DtEditorAppendFromFile(3)DtEditorCheckForUnsavedChanges(3)DtEditorGetContents(3)DtEditorInsert(3)DtEditorInsertFromFile(3)DtEditorReplace(3)DtEditorReplaceFromFile(3)DtEditorSetContentsFromFile(3)DtEditorSetContents(3)
β¨ Cute footer sign-off: this is the DtEditorSav...tentsToFile(library call) page, and no version or date is listed β so thatβs the whole footer vibe, bestie. π
π«Ά
π¦ where this page comes from
- nixos 26.05: cde 2.5.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms