From 73023a02015b8e6f059e3f9abcbeb01e89ecdc69 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 23 Sep 2024 14:06:39 +0200
Subject: [PATCH] dialogs/TextInputDialog: move parameters to struct
 TextInputDialogOptions

---
 src/QueuePage.cxx               |  3 +--
 src/SearchPage.cxx              |  2 +-
 src/dialogs/TextInputDialog.hxx | 44 ++++++++++++++++++---------------
 src/page/FindSupport.cxx        |  6 ++---
 src/save_playlist.cxx           |  3 +--
 src/screen.cxx                  |  2 +-
 6 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/src/QueuePage.cxx b/src/QueuePage.cxx
index 1954ca00..86d3fb22 100644
--- a/src/QueuePage.cxx
+++ b/src/QueuePage.cxx
@@ -307,8 +307,7 @@ handle_add_to_playlist(ScreenManager &screen, struct mpdclient &c)
 		screen,
 		_("Add"),
 		{},
-		nullptr,
-		completion,
+		{ .completion = completion },
 	};
 
 	/* add the path to the playlist */
diff --git a/src/SearchPage.cxx b/src/SearchPage.cxx
index dcd4f732..483a92e8 100644
--- a/src/SearchPage.cxx
+++ b/src/SearchPage.cxx
@@ -421,7 +421,7 @@ SearchPage::Start(struct mpdclient &c)
 	pattern = co_await TextInputDialog{
 		screen, _("Search"),
 		{},
-		&search_history,
+		{ .history = &search_history },
 	};
 
 	if (pattern.empty()) {
diff --git a/src/dialogs/TextInputDialog.hxx b/src/dialogs/TextInputDialog.hxx
index a0d8f810..38f32029 100644
--- a/src/dialogs/TextInputDialog.hxx
+++ b/src/dialogs/TextInputDialog.hxx
@@ -13,6 +13,24 @@
 
 class Completion;
 
+struct TextInputDialogOptions {
+	History *history = nullptr;
+
+	Completion *completion = nullptr;
+
+	/**
+	 * Is the input masked, i.e. characters displayed as '*'?
+	 */
+	bool masked = false;
+
+	/**
+	 * "Fragile" mode: all unknown keys cancel the dialog and
+	 * OnKey() returns false (i.e. the key can be handled by
+	 * somebody else).
+	 */
+	bool fragile = false;
+};
+
 /**
  * A #ModalDialog that asks the user to input text.
  *
@@ -39,11 +57,11 @@ class TextInputDialog final : public ModalDialog {
 	/** the screen width of the input field */
 	mutable unsigned width;
 
-	/** is the input masked, i.e. characters displayed as '*'? */
+	/** @see TextInputDialogOptions::masked */
 	const bool masked;
 
-	/** @see SetFragile() */
-	bool fragile = false;
+	/** @see TextInputDialogOptions::fragile */
+	const bool fragile;
 
 	bool ready = false;
 
@@ -67,20 +85,15 @@ public:
 	 * lifetime of this dialog
 	 *
 	 * @param _value the initial value
-	 *
-	 * @param _masked do not display the text, show asterisks
-	 * instead (for password entry)
 	 */
 	TextInputDialog(ModalDock &_dock,
 			std::string_view _prompt,
 			std::string &&_value={},
-			History *_history=nullptr,
-			Completion *_completion=nullptr,
-			bool _masked=false) noexcept
+			TextInputDialogOptions _options={}) noexcept
 		:ModalDialog(_dock), prompt(_prompt),
 		 value(std::move(_value)),
-		 history(_history), completion(_completion),
-		 masked(_masked)
+		 history(_options.history), completion(_options.completion),
+		 masked(_options.masked), fragile(_options.fragile)
 	{
 		Show();
 
@@ -96,15 +109,6 @@ public:
 		Hide();
 	}
 
-	/**
-	 * Enable "fragile" mode: all unknown keys cancel the dialog
-	 * and OnKey() returns false (i.e. the key can be handled by
-	 * somebody else).
-	 */
-	void SetFragile() noexcept {
-		fragile = true;
-	}
-
 	void SetModifiedCallback(ModifiedCallback &&_modified_callback) noexcept {
 		modified_callback = std::move(_modified_callback);
 	}
diff --git a/src/page/FindSupport.cxx b/src/page/FindSupport.cxx
index be4eb4df..9832dd3b 100644
--- a/src/page/FindSupport.cxx
+++ b/src/page/FindSupport.cxx
@@ -31,7 +31,7 @@ FindSupport::DoFind(ListWindow &lw, const ListText &text, bool reversed) noexcep
 			screen,
 			prompt,
 			std::move(value),
-			&history,
+			{ .history = &history },
 		};
 	}
 
@@ -78,10 +78,10 @@ FindSupport::Jump(ListWindow &lw,
 	TextInputDialog dialog{
 		screen,
 		JUMP_PROMPT,
+		{},
+		{ .fragile = true },
 	};
 
-	dialog.SetFragile();
-
 	dialog.SetModifiedCallback([&lw, &text, &renderer](std::string_view value) noexcept {
 		lw.Jump(text, value);
 		lw.Paint(renderer);
diff --git a/src/save_playlist.cxx b/src/save_playlist.cxx
index 668564d0..cb248c56 100644
--- a/src/save_playlist.cxx
+++ b/src/save_playlist.cxx
@@ -74,8 +74,7 @@ playlist_save(ScreenManager &screen, struct mpdclient &c,
 		filename = co_await TextInputDialog{
 			screen, _("Save queue as"),
 			{},
-			nullptr,
-			completion,
+			{ .completion = completion },
 		};
 
 		if (filename.empty())
diff --git a/src/screen.cxx b/src/screen.cxx
index 92f9a30b..4a50d4df 100644
--- a/src/screen.cxx
+++ b/src/screen.cxx
@@ -400,7 +400,7 @@ EnterPassword(ScreenManager &screen, struct mpdclient &c)
 
 	co_return co_await TextInputDialog{
 		screen, _("Password"), {},
-		nullptr, nullptr, true,
+		{ .masked = true },
 	};
 }