Skip to content

Commit

Permalink
docs: Review the Document and Project API
Browse files Browse the repository at this point in the history
Update the documentation a bit.

Related to KDAB#54
  • Loading branch information
narnaud committed Jul 3, 2024
1 parent f7fc1c0 commit fad1d7b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions docs/API/script/document.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ A document is a file loaded by Knut and that can be used in script (either to ge

#### <a name="errorString"></a>string **errorString**

Returns the error string if an error occurred while loading the document, otherwise returns an empty string.

#### <a name="exists"></a>bool **exists**

Returns true if the document is a file on the disk, otherwise returns false.
Expand Down
21 changes: 13 additions & 8 deletions docs/API/script/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Script
||**[closeAll](#closeAll)**()|
|[Document](../script/document.md) |**[get](#get)**(string fileName)|
|[Document](../script/document.md) |**[open](#open)**(string fileName)|
||**[openPrevious](#openPrevious)**(int index)|
||**[openPrevious](#openPrevious)**(int index = 1)|
||**[saveAllDocuments](#saveAllDocuments)**()|

## Detailed Description
Expand Down Expand Up @@ -77,18 +77,23 @@ Close all documents. If the document has some changes, save the changes.

#### <a name="get"></a>[Document](../script/document.md) **get**(string fileName)

Get the document for the given `fileName`. If the document is not opened yet, open it. If the document already
exists, returns the same instance, a document can't be open twice. If the fileName is relative, use the root path as
the base.
Gets the document for the given `fileName`. If the document is not opened yet, open it. If the document
is already opened, returns the same instance, a document can't be open twice. If the fileName is relative, use the
root path as the base.

*Note:* this command does not change the current document.
If the document does not exist, creates a new document (but don't save it yet).

!!! note
This command does not change the current document.

#### <a name="open"></a>[Document](../script/document.md) **open**(string fileName)

Opens a document for the given `fileName` and make it current. If the document already exists, returns the same
instance, a document can't be open twice. If the fileName is relative, use the root path as the base.
Opens or creates a document for the given `fileName` and make it current. If the document is already opened, returns
the same instance, a document can't be open twice. If the fileName is relative, use the root path as the base.

If the document does not exist, creates a new document (but don't save it yet).

#### <a name="openPrevious"></a>**openPrevious**(int index)
#### <a name="openPrevious"></a>**openPrevious**(int index = 1)

Open a previously opened document. `index` is the position of this document in the last opened document.

Expand Down
1 change: 1 addition & 0 deletions src/core/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Core {
*/
/*!
* \qmlproperty string Document::errorString
* Returns the error string if an error occurred while loading the document, otherwise returns an empty string.
*/
/*!
* \qmlproperty bool Document::hasChanged
Expand Down
19 changes: 12 additions & 7 deletions src/core/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,14 @@ Document *Project::getDocument(QString fileName, bool moveToBack)

/*!
* \qmlmethod Document Project::get(string fileName)
* Get the document for the given `fileName`. If the document is not opened yet, open it. If the document already
* exists, returns the same instance, a document can't be open twice. If the fileName is relative, use the root path as
* the base.
* Gets the document for the given `fileName`. If the document is not opened yet, open it. If the document
* is already opened, returns the same instance, a document can't be open twice. If the fileName is relative, use the
* root path as the base.
*
* *Note:* this command does not change the current document.
* If the document does not exist, creates a new document (but don't save it yet).
*
* !!! note
* This command does not change the current document.
*/
Document *Project::get(const QString &fileName)
{
Expand All @@ -312,8 +315,10 @@ Document *Project::get(const QString &fileName)

/*!
* \qmlmethod Document Project::open(string fileName)
* Opens a document for the given `fileName` and make it current. If the document already exists, returns the same
* instance, a document can't be open twice. If the fileName is relative, use the root path as the base.
* Opens or creates a document for the given `fileName` and make it current. If the document is already opened, returns
* the same instance, a document can't be open twice. If the fileName is relative, use the root path as the base.
*
* If the document does not exist, creates a new document (but don't save it yet).
*/
Document *Project::open(const QString &fileName)
{
Expand Down Expand Up @@ -360,7 +365,7 @@ void Project::saveAllDocuments()
}

/*!
* \qmlmethod Project::openPrevious(int index)
* \qmlmethod Project::openPrevious(int index = 1)
* Open a previously opened document. `index` is the position of this document in the last opened document.
*
* `document.openPrevious(1)` (the default) opens the last document, like Ctrl+Tab in any editors.
Expand Down

0 comments on commit fad1d7b

Please sign in to comment.