Skip to content

Commit

Permalink
Some renames
Browse files Browse the repository at this point in the history
* promptForDirectory -> promptDirectory (seems more consistent)
* promptOpenMultipleFiles -> promptOpenFiles (seems less redundant)

I'm a little undecided about dropping the "Names" postfix that is used
by the Qt API. I think it might help to keep it to make it clear that
file names are returned, as opposed to some kind of file objects, but it
does also feel a little verbose.
  • Loading branch information
bjorn committed Jul 27, 2023
1 parent 70ea216 commit d73ce75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions docs/scripting-doc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ interface size {
* polygon array and then assign it to {@link MapObject.polygon}.
*/
type Polygon = point[];

/**
* A string used to show only certain types of files when prompting the user to select a file path.
*
Expand All @@ -195,6 +196,7 @@ type Polygon = point[];
* ```
*/
type FileFilter = string;

/**
* The value of a property of type 'object', which refers to a
* {@link MapObject} by its ID.
Expand Down Expand Up @@ -3941,7 +3943,7 @@ declare namespace tiled {
*
* Returns the absolute path of the chosen directory, or an empty string if the user cancels the dialog.
*/
export function promptForDirectory(defaultDir?: string, title?: string): string;
export function promptDirectory(defaultDir?: string, title?: string): string;

/**
* Shows a dialog which asks the user to choose one or more existing files.
Expand All @@ -3950,7 +3952,7 @@ declare namespace tiled {
*
* Returns an array of the absolute paths of the chosen files, or an empty array if the user cancels the dialog.
*/
export function promptOpenMultipleFiles(defaultDir?: string, filters?: string, title?: string): string[];
export function promptOpenFiles(defaultDir?: string, filters?: FileFilter, title?: string): string[];

/**
* Shows a dialog which asks the user to choose an existing file.
Expand All @@ -3959,7 +3961,7 @@ declare namespace tiled {
*
* Returns the absolute path of the chosen file, or an empty string if the user cancels the dialog.
*/
export function promptOpenFile(defaultDir?: string, filters?: string, title?: string): string;
export function promptOpenFile(defaultDir?: string, filters?: FileFilter, title?: string): string;

/**
* Shows a dialog which asks the user to choose a destination for saving a file.
Expand Down Expand Up @@ -4425,9 +4427,8 @@ declare class FileEdit extends Qt.QWidget {

/**
* When specified, only files that match the filter are shown.
* See {@link FileFilter}.
*/
filter: string;
filter: FileFilter;
}
/**
* A widget that displays an {@link Image} on your dialog.
Expand Down
4 changes: 2 additions & 2 deletions src/tiled/scriptmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ QString ScriptModule::prompt(const QString &label, const QString &text, const QS
return QInputDialog::getText(MainWindow::maybeInstance(), title, label, QLineEdit::Normal, text);
}

QString ScriptModule::promptForDirectory(const QString &defaultDir, const QString &title) const
QString ScriptModule::promptDirectory(const QString &defaultDir, const QString &title) const
{
ScriptManager::ResetBlocker blocker;
return QFileDialog::getExistingDirectory(MainWindow::maybeInstance(),
Expand All @@ -607,7 +607,7 @@ QString ScriptModule::promptForDirectory(const QString &defaultDir, const QStrin
QFileDialog::ShowDirsOnly);
}

QStringList ScriptModule::promptOpenMultipleFiles(const QString &defaultDir, const QString &filters, const QString &title) const
QStringList ScriptModule::promptOpenFiles(const QString &defaultDir, const QString &filters, const QString &title) const
{
ScriptManager::ResetBlocker blocker;
return QFileDialog::getOpenFileNames(MainWindow::maybeInstance(),
Expand Down
4 changes: 2 additions & 2 deletions src/tiled/scriptmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class ScriptModule : public QObject

Q_INVOKABLE QByteArray compress(const QByteArray &data, CompressionMethod method = Zlib, int compressionLevel = -1);
Q_INVOKABLE QByteArray decompress(const QByteArray &data, CompressionMethod method = Zlib);
Q_INVOKABLE QString promptForDirectory(const QString &defaultDir = QString(), const QString &title = QString()) const;
Q_INVOKABLE QStringList promptOpenMultipleFiles(const QString &defaultDir = QString(), const QString &filters = QString(), const QString &title = QString()) const;
Q_INVOKABLE QString promptDirectory(const QString &defaultDir = QString(), const QString &title = QString()) const;
Q_INVOKABLE QStringList promptOpenFiles(const QString &defaultDir = QString(), const QString &filters = QString(), const QString &title = QString()) const;
Q_INVOKABLE QString promptOpenFile(const QString &defaultDir = QString(), const QString &filters = QString(), const QString &title = QString()) const;
Q_INVOKABLE QString promptSaveFile(const QString &defaultDir = QString(), const QString &filters = QString(), const QString &title = QString()) const;

Expand Down

0 comments on commit d73ce75

Please sign in to comment.