Skip to content

Commit

Permalink
dialogs/TextInputDialog: move parameters to struct TextInputDialogOpt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
MaxKellermann committed Sep 23, 2024
1 parent eb6a1e9 commit 73023a0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/QueuePage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/SearchPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ SearchPage::Start(struct mpdclient &c)
pattern = co_await TextInputDialog{
screen, _("Search"),
{},
&search_history,
{ .history = &search_history },
};

if (pattern.empty()) {
Expand Down
44 changes: 24 additions & 20 deletions src/dialogs/TextInputDialog.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;

Expand All @@ -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();

Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/page/FindSupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FindSupport::DoFind(ListWindow &lw, const ListText &text, bool reversed) noexcep
screen,
prompt,
std::move(value),
&history,
{ .history = &history },
};
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/save_playlist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/screen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ EnterPassword(ScreenManager &screen, struct mpdclient &c)

co_return co_await TextInputDialog{
screen, _("Password"), {},
nullptr, nullptr, true,
{ .masked = true },
};
}

Expand Down

0 comments on commit 73023a0

Please sign in to comment.