Skip to content

Commit

Permalink
#3163 doc: add script function documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
  • Loading branch information
pbek committed Nov 26, 2024
1 parent 8c1786e commit 3e3dd16
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/services/scriptingservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,15 @@ QString ScriptingService::inputDialogGetMultiLineText(const QString &title, cons
#endif
}

/**
* Opens a dialog to show the differences between two texts and lets the user edit the result
*
* @param title {QString} title of the dialog
* @param label {QString} label text of the dialog
* @param text1 {QString} first text
* @param text2 {QString} second text
* @return
*/
QString ScriptingService::textDiffDialog(const QString &title, const QString &label,
const QString &text1, const QString &text2) {
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("scripting/") %
Expand Down
31 changes: 31 additions & 0 deletions webpage/src/scripting/methods-and-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,37 @@ var result = script.inputDialogGetMultiLineText(
script.log(result);
```

Opening a dialog to show the differences between two texts
----------------------------------------------------------

### Method call and parameters
```cpp
/**
* Opens a dialog to show the differences between two texts and lets the user edit the result
*
* @param title {QString} title of the dialog
* @param label {QString} label text of the dialog
* @param text1 {QString} first text
* @param text2 {QString} second text
* @return
*/
QString ScriptingService::textDiffDialog(const QString &title, const QString &label,
const QString &text1, const QString &text2);
```
`text2` is the text you will be able to edit in the dialog.
An empty string will be returned, if `Cancel` was clicked or `Escape` was pressed.
### Example
```js
const text = script.noteTextEditSelectedText();
const aiPrompt = "Translate the text to English";
const aiResult = script.aiComplete(aiPrompt + ":\n\n" + text);
var result = script.textDiffDialog("AI Text Tool", "Resulting text", text, aiResult);
script.log(result);
```

Checking if a file exists
-------------------------

Expand Down

0 comments on commit 3e3dd16

Please sign in to comment.