From 3dc8fdbdf5260728585216169900c19798c5ae3d Mon Sep 17 00:00:00 2001 From: rstat1 Date: Thu, 30 Jan 2020 20:09:39 -0500 Subject: [PATCH] No more are you sure boxes (#4101) ## Summary of the Pull Request So this PR adds a profile setting called "confirmCloseAllTabs", that allows one to enable or disable the "Do you want close all tabs?" dialog that appears when you close a window with multiple open tabs. It current defaults to "true". Also adds a checkbox to that dialog that also sets "confirmCloseAllTabs" ## References ## PR Checklist * [x] Closes #3883 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments I added a checkbox to the close dialog to set this setting, but I'm not sure how to best go about actually changing the setting from code; am open to suggestions, as to how it should be done, or if I should also just remove it and stick with the profile setting. ## Validation Steps Performed 1. Set "confirmCloseAllTabs" to false in my profile.json file. 2. Opened a 2nd tab. 3. Closed the window 4. Observed that there was no confirmation before the window closed. 5. Set "confirmCloseAllTabs" to true 6. Repeat steps 2 and 3 7. Observe that there was a confirmation before the window closed. --- doc/cascadia/SettingsSchema.md | 1 + doc/cascadia/profiles.schema.json | 5 +++++ src/cascadia/TerminalApp/GlobalAppSettings.cpp | 16 ++++++++++++++++ src/cascadia/TerminalApp/GlobalAppSettings.h | 4 ++++ src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- src/cascadia/TerminalApp/defaults.json | 1 + 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/cascadia/SettingsSchema.md b/doc/cascadia/SettingsSchema.md index 53622113d..04028569f 100644 --- a/doc/cascadia/SettingsSchema.md +++ b/doc/cascadia/SettingsSchema.md @@ -19,6 +19,7 @@ Properties listed below affect the entire window, regardless of the profile sett | `snapToGridOnResize` | Optional | Boolean | `false` | When set to `true`, the window will snap to the nearest character boundary on resize. When `false`, the window will resize "smoothly" | | `tabWidthMode` | Optional | String | `equal` | Sets the width of the tabs. Possible values: `"equal"`, `"titleLength"` | | `wordDelimiters` | Optional | String |  /\()"'-:,.;<>~!@#$%^&*|+=[]{}~?│
_(`│` is `U+2502 BOX DRAWINGS LIGHT VERTICAL`)_ | Determines the delimiters used in a double click selection. | +| `confirmCloseAllTabs` | Optional | Boolean | `true` | When set to `true` closing a window with multiple tabs open WILL require confirmation. When set to `false` closing a window with multiple tabs open WILL NOT require confirmation. | ## Profiles Properties listed below are specific to each unique profile. diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index d7365cf77..b1278d2ea 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -355,6 +355,11 @@ "default": " ./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?│", "description": "Determines the delimiters used in a double click selection.", "type": "string" + }, + "confirmCloseAllTabs": { + "default": true, + "description": " When set to `true` closing a window with multiple tabs open WILL require confirmation. When set to `false` closing a window with multiple tabs open WILL NOT require confirmation.", + "type":"boolean" } }, "required": [ diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.cpp b/src/cascadia/TerminalApp/GlobalAppSettings.cpp index 7c41ba6ea..9284da908 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalApp/GlobalAppSettings.cpp @@ -33,6 +33,7 @@ static constexpr std::string_view ShowTabsInTitlebarKey{ "showTabsInTitlebar" }; static constexpr std::string_view WordDelimitersKey{ "wordDelimiters" }; static constexpr std::string_view CopyOnSelectKey{ "copyOnSelect" }; static constexpr std::string_view LaunchModeKey{ "launchMode" }; +static constexpr std::string_view ConfirmCloseAllKey{ "confirmCloseAllTabs" }; static constexpr std::string_view SnapToGridOnResizeKey{ "snapToGridOnResize" }; static constexpr std::wstring_view DefaultLaunchModeValue{ L"default" }; static constexpr std::wstring_view MaximizedLaunchModeValue{ L"maximized" }; @@ -45,6 +46,7 @@ GlobalAppSettings::GlobalAppSettings() : _colorSchemes{}, _defaultProfile{}, _alwaysShowTabs{ true }, + _confirmCloseAllTabs{ true }, _initialRows{ DEFAULT_ROWS }, _initialCols{ DEFAULT_COLS }, _rowsToScroll{ DEFAULT_ROWSTOSCROLL }, @@ -158,6 +160,15 @@ void GlobalAppSettings::SetLaunchMode(const LaunchMode launchMode) { _launchMode = launchMode; } +bool GlobalAppSettings::GetConfirmCloseAllTabs() const noexcept +{ + return _confirmCloseAllTabs; +} + +void GlobalAppSettings::SetConfirmCloseAllTabs(const bool confirmCloseAllTabs) noexcept +{ + _confirmCloseAllTabs = confirmCloseAllTabs; +} #pragma region ExperimentalSettings bool GlobalAppSettings::GetShowTabsInTitlebar() const noexcept @@ -223,6 +234,7 @@ Json::Value GlobalAppSettings::ToJson() const jsonObject[JsonKey(RequestedThemeKey)] = winrt::to_string(_SerializeTheme(_requestedTheme)); jsonObject[JsonKey(TabWidthModeKey)] = winrt::to_string(_SerializeTabWidthMode(_tabWidthMode)); jsonObject[JsonKey(KeybindingsKey)] = _keybindings->ToJson(); + jsonObject[JsonKey(ConfirmCloseAllKey)] = _confirmCloseAllTabs; jsonObject[JsonKey(SnapToGridOnResizeKey)] = _SnapToGridOnResize; return jsonObject; @@ -253,6 +265,10 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) { _alwaysShowTabs = alwaysShowTabs.asBool(); } + if (auto confirmCloseAllTabs{ json[JsonKey(ConfirmCloseAllKey)] }) + { + _confirmCloseAllTabs = confirmCloseAllTabs.asBool(); + } if (auto initialRows{ json[JsonKey(InitialRowsKey)] }) { _initialRows = initialRows.asInt(); diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.h b/src/cascadia/TerminalApp/GlobalAppSettings.h index 4831a62c5..738aace24 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.h +++ b/src/cascadia/TerminalApp/GlobalAppSettings.h @@ -50,6 +50,9 @@ public: bool GetShowTitleInTitlebar() const noexcept; void SetShowTitleInTitlebar(const bool showTitleInTitlebar) noexcept; + bool GetConfirmCloseAllTabs() const noexcept; + void SetConfirmCloseAllTabs(const bool confirmCloseAllTabs) noexcept; + void SetRequestedTheme(const winrt::Windows::UI::Xaml::ElementTheme requestedTheme) noexcept; void SetTabWidthMode(const winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode tabWidthMode); @@ -99,6 +102,7 @@ private: bool _showStatusline; bool _alwaysShowTabs; bool _showTitleInTitlebar; + bool _confirmCloseAllTabs; bool _showTabsInTitlebar; std::wstring _wordDelimiters; diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 2b27ce8a0..bc85e5da2 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -997,7 +997,7 @@ namespace winrt::TerminalApp::implementation // than one tab opened, show a warning dialog. void TerminalPage::CloseWindow() { - if (_tabs.size() > 1) + if (_tabs.size() > 1 && _settings->GlobalSettings().GetConfirmCloseAllTabs()) { _ShowCloseWarningDialog(); } diff --git a/src/cascadia/TerminalApp/defaults.json b/src/cascadia/TerminalApp/defaults.json index 14a84fb1d..eae4b27c6 100644 --- a/src/cascadia/TerminalApp/defaults.json +++ b/src/cascadia/TerminalApp/defaults.json @@ -10,6 +10,7 @@ "tabWidthMode": "equal", "snapToGridOnResize": false, "wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502", + "confirmCloseAllTabs": true, "profiles": [