Skip to content

Commit b560e91

Browse files
committed
Adds attributes for controlling the window created via dialog()
Fixes #2947
1 parent 843fa38 commit b560e91

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/scripting-api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,8 @@ unlike in GUI, where row numbers start from 1 by default.
11031103
- '.style' - Qt style sheet for dialog
11041104
- '.height', '.width', '.x', '.y' - dialog geometry
11051105
- '.label' - dialog message (can contain basic HTML)
1106+
- '.modal' - set to true to make the dialog modal (to avoid other CopyQ windows to get input focus)
1107+
- '.onTop' - set to true for the dialog to stay above other windows
11061108

11071109
:returns: Value or values from accepted dialog or ``undefined`` if dialog
11081110
was canceled.

src/scriptable/scriptableproxy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,10 @@ int ScriptableProxy::inputDialog(const NamedValueList &values)
21182118
createAndSetWidget<QLabel>("text", value.value, parent);
21192119
else if (value.name == ".defaultChoice")
21202120
inputDialog.defaultChoice = value.value.toString();
2121+
else if (value.name == ".modal")
2122+
dialog.setModal(value.value.toBool());
2123+
else if (value.name == ".onTop")
2124+
dialog.setWindowFlag(Qt::WindowStaysOnTopHint, value.value.toBool());
21212125
else
21222126
widgets.append( createWidget(value.name, value.value, &inputDialog) );
21232127
}

src/tests/tests_scripts.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ void Tests::commandDialog()
376376
[&]() { RUN(WITH_TIMEOUT "dialog('.title', 'Remove Items', '.label', 'Remove all items?') === true", "true\n"); },
377377
[&]() { RUN(Args() << "keys" << "focus::QPushButton in dialog_Remove Items:QDialog" << "ENTER", ""); }
378378
);
379+
380+
RUN(Args() << "keys" << clipboardBrowserId, "");
381+
const QByteArray script2 = R"(
382+
dialog(
383+
'.modal', true,
384+
'.onTop', true,
385+
'text', 'DEFAULT',
386+
)
387+
)";
388+
runMultiple(
389+
[&]() { RUN(WITH_TIMEOUT + script2, "DEFAULT\n"); },
390+
[&]() { RUN(Args() << "keys" << "focus::QLineEdit in :QDialog" << "ENTER", ""); }
391+
);
379392
}
380393

381394
void Tests::commandDialogCloseOnDisconnect()

0 commit comments

Comments
 (0)