From 6fb0a12fd3353c49db5e0d85afe53e57ca3ec6ee Mon Sep 17 00:00:00 2001 From: nakst <> Date: Wed, 30 Mar 2022 20:49:57 +0100 Subject: [PATCH] desktop: add option to save files without extensions by default --- desktop/desktop.cpp | 10 ++++++++++ desktop/settings.cpp | 13 +++++++++++++ shared/strings.cpp | 3 +++ 3 files changed, 26 insertions(+) diff --git a/desktop/desktop.cpp b/desktop/desktop.cpp index 0e82c9a..0382219 100644 --- a/desktop/desktop.cpp +++ b/desktop/desktop.cpp @@ -2253,6 +2253,16 @@ void ApplicationInstanceRequestSave(ApplicationInstance *instance, const char *n m.tabOperation.id = instance->embeddedWindowID; if (!instance->documentID) { + if (!EsSystemConfigurationReadInteger(EsLiteral("general"), EsLiteral("save_with_file_extensions"))) { + for (intptr_t i = newNameBytes - 1; i >= 0; i--) { + if (newName[i] == '.') { + // Remove the file extension from the default new file name. + newNameBytes = i; + break; + } + } + } + size_t folderBytes; char *folder = EsSystemConfigurationReadString(EsLiteral("paths"), EsLiteral("default_user_documents"), &folderBytes); char *name = (char *) EsHeapAllocate(folderBytes + newNameBytes + 32, false); diff --git a/desktop/settings.cpp b/desktop/settings.cpp index d77213f..cbc02e7 100644 --- a/desktop/settings.cpp +++ b/desktop/settings.cpp @@ -171,6 +171,7 @@ void SettingsLoadDefaults() { SettingsPutValue("general", "enable_hover_state", EsLiteral("1"), nullptr, nullptr, true, false); SettingsPutValue("general", "enable_animations", EsLiteral("1"), nullptr, nullptr, true, false); SettingsPutValue("general", "keyboard_layout", EsLiteral("us"), nullptr, nullptr, true, false); + SettingsPutValue("general", "save_with_file_extensions", EsLiteral("1"), nullptr, nullptr, true, false); SettingsPutValue("paths", "default_user_documents", EsLiteral("0:/"), nullptr, nullptr, true, false); } @@ -683,6 +684,17 @@ void SettingsPageDisplay(EsElement *element, SettingsPage *page) { 100, 400, INTERFACE_STRING(CommonUnitPercent), 0.05, 5); } +void SettingsPageFiles(EsElement *element, SettingsPage *page) { + // TODO. + + EsPanel *content = EsPanelCreate(element, ES_CELL_FILL | ES_PANEL_V_SCROLL_AUTO | ES_PANEL_H_SCROLL_AUTO, EsStyleIntern(&styleSettingsGroupContainer)); + EsPanel *container = EsPanelCreate(content, ES_PANEL_VERTICAL, EsStyleIntern(&styleSettingsGroupContainer2)); + SettingsAddTitle(container, page); + + EsPanel *table = EsPanelCreate(container, ES_CELL_H_FILL, EsStyleIntern(&styleSettingsCheckboxGroup)); + SettingsAddCheckbox(table, INTERFACE_STRING(DesktopSettingsFilesSaveWithFileExtension), 'X', "general", "save_with_file_extensions"); +} + int SettingsColorButtonMessage(EsElement *element, EsMessage *message) { if (message->type == ES_MSG_PAINT_BACKGROUND) { // HACK This assumes a lot about the workings of the radiobox style... @@ -868,6 +880,7 @@ SettingsPage settingsPages[] = { // { INTERFACE_STRING(DesktopSettingsAccessibility), ES_ICON_PREFERENCES_DESKTOP_ACCESSIBILITY, SettingsPageUnimplemented, 'A' }, // TODO. // { INTERFACE_STRING(DesktopSettingsDateAndTime), ES_ICON_PREFERENCES_SYSTEM_TIME, SettingsPageUnimplemented, 'C' }, // TODO. { INTERFACE_STRING(DesktopSettingsDisplay), ES_ICON_PREFERENCES_DESKTOP_DISPLAY, SettingsPageDisplay, 'D' }, + { INTERFACE_STRING(DesktopSettingsFiles), ES_ICON_USER_HOME_OPEN, SettingsPageFiles, 'S' }, { INTERFACE_STRING(DesktopSettingsKeyboard), ES_ICON_INPUT_KEYBOARD, SettingsPageKeyboard, 'E' }, // { INTERFACE_STRING(DesktopSettingsLocalisation), ES_ICON_PREFERENCES_DESKTOP_LOCALE, SettingsPageUnimplemented, 'F' }, // TODO. { INTERFACE_STRING(DesktopSettingsMouse), ES_ICON_INPUT_MOUSE, SettingsPageMouse, 'G' }, diff --git a/shared/strings.cpp b/shared/strings.cpp index bcec63d..7feab4e 100644 --- a/shared/strings.cpp +++ b/shared/strings.cpp @@ -146,6 +146,7 @@ DEFINE_INTERFACE_STRING(DesktopSettingsApplications, "Applications"); DEFINE_INTERFACE_STRING(DesktopSettingsDateAndTime, "Date and time"); DEFINE_INTERFACE_STRING(DesktopSettingsDevices, "Devices"); DEFINE_INTERFACE_STRING(DesktopSettingsDisplay, "Display"); +DEFINE_INTERFACE_STRING(DesktopSettingsFiles, "Files"); DEFINE_INTERFACE_STRING(DesktopSettingsKeyboard, "Keyboard"); DEFINE_INTERFACE_STRING(DesktopSettingsLocalisation, "Localisation"); DEFINE_INTERFACE_STRING(DesktopSettingsMouse, "Mouse"); @@ -183,6 +184,8 @@ DEFINE_INTERFACE_STRING(DesktopSettingsThemeEnableHoverState, "Highlight the ite DEFINE_INTERFACE_STRING(DesktopSettingsThemeEnableAnimations, "Animate the user interface"); DEFINE_INTERFACE_STRING(DesktopSettingsThemeWallpaper, "Wallpaper:"); +DEFINE_INTERFACE_STRING(DesktopSettingsFilesSaveWithFileExtension, "Automatically add a file extension when creating files"); + // File operations. DEFINE_INTERFACE_STRING(FileCannotSave, "The document was not saved.");