Gtk4-tutorial/gfm/tfetextview_doc.md

181 lines
3.7 KiB
Markdown
Raw Normal View History

# TfeTextView API reference
2021-02-03 15:04:08 +01:00
## Description
TfeTextView is a child object of GtkTextView.
If its contents comes from a file, it holds the pointer to the GFile.
Otherwise, the pointer is NULL.
## Hierarchy
```
GObject -- GInitiallyUnowned -- GtkWidget -- GtkTextView -- TfeTextView
```
## Ancestors
- GtkTextView
- GtkWidget
- GInitiallyUnowned
- GObject
2021-02-03 15:04:08 +01:00
## Constructors
- [tfe_text_view_new ()](../src/tfetextview/#tfe_text_view_new)
- [tfe_text_view_new_with_file ()](../src/tfetextview/#tfe_text_view_new_with_file)
## Instance methods
- [tfe_text_view_get_file ()](../src/tfetextview/#tfe_text_view_get_file)
- [tfe_text_view_open ()](../src/tfetextview/#tfe_text_view_open)
- [tfe_text_view_save ()](../src/tfetextview/#tfe_text_view_save)
- [tfe_text_view_saveas ()](../src/tfetextview/#tfe_text_view_saveas)
2021-02-03 15:04:08 +01:00
## Signals
- [Tfe.TextView::change-file](../src/tfetextview/#change-file)
- [Tfe.TextView::open-response](../src/tfetextview/#open-response)
2021-02-03 15:04:08 +01:00
## API for constructors, instance methods and signals
2021-02-03 15:04:08 +01:00
**constructors**
2021-02-03 15:04:08 +01:00
### tfe_text_view_new()
2021-02-03 15:04:08 +01:00
```
GtkWidget *
tfe_text_view_new (void);
```
2021-02-03 15:04:08 +01:00
Creates a new TfeTextView instance and returns the pointer to it as GtkWidget.
If an error happens, it returns `NULL`.
2021-02-03 15:04:08 +01:00
Return value
2021-02-03 15:04:08 +01:00
- a new TfeTextView.
### tfe_text_view_new_with_file()
```
GtkWidget *
tfe_text_view_new_with_file (GFile *file);
```
Creates a new TfeTextView, reads the contents of the `file` and set it to the GtkTextBuffer corresponds to the newly created TfeTextView.
Then returns the pointer to the TfeTextView as GtkWidget.
If an error happens, it returns `NULL`.
Parameters
2021-02-03 15:04:08 +01:00
- file: a GFile
Return value
2021-02-03 15:04:08 +01:00
- a new TfeTextView.
**Instance methods**
2021-02-03 15:04:08 +01:00
### tfe_text_view_get_file()
2021-02-03 15:04:08 +01:00
```
2021-02-03 15:04:08 +01:00
GFile *
tfe_text_view_get_file (TfeTextView *tv);
```
2021-02-03 15:04:08 +01:00
Returns the copy of the GFile in the TfeTextView.
Parameters
- tv: a TfeTextView
Return value
- the pointer to the GFile
### tfe_text_view_open()
2021-02-03 15:04:08 +01:00
```
2021-02-03 15:04:08 +01:00
void
tfe_text_view_open (TfeTextView *tv, GtkWidget *win);
```
2021-02-03 15:04:08 +01:00
Shows a file chooser dialog so that a user can choose a file to read.
Then, read the file and set the buffer with the contents.
This function doesn't return the I/O status.
2021-02-03 15:04:08 +01:00
Instead, the status is informed by `open-response` signal.
The caller needs to set a handler to this signal in advance.
parameters
- tv: a TfeTextView
2021-04-20 15:03:23 +02:00
- win: the top level window
2021-02-03 15:04:08 +01:00
### tfe_text_view_save()
2021-02-03 15:04:08 +01:00
```
2021-02-03 15:04:08 +01:00
void
tfe_text_view_save (TfeTextView *tv);
```
2021-02-03 15:04:08 +01:00
Saves the contents of the buffer to the file.
2021-02-03 15:04:08 +01:00
If `tv` holds a GFile, it is used.
Otherwise, this function shows a file chooser dialog so that the user can choose a file to save.
2021-02-03 15:04:08 +01:00
Parameters
- tv: a TfeTextView
### tfe_text_view_saveas()
2021-02-03 15:04:08 +01:00
```
2021-02-03 15:04:08 +01:00
void
tfe_text_view_saveas (TfeTextView *tv);
```
2021-02-03 15:04:08 +01:00
Saves the contents of the buffer to a file.
This function shows file chooser dialog so that a user can choose a file to save.
2021-02-03 15:04:08 +01:00
Parameters
- tv: a TfeTextView
**Signals**
2021-02-03 15:04:08 +01:00
### change-file
```
2021-02-03 15:04:08 +01:00
void
user_function (TfeTextView *tv,
gpointer user_data)
```
2021-02-03 15:04:08 +01:00
Emitted when the GFile in the TfeTextView object is changed.
The signal is emitted when:
2021-04-20 15:03:23 +02:00
- a new file is opened and read
- a user chooses a file with the file chooser dialog and save the contents.
2021-02-03 15:04:08 +01:00
### open-response
```
2021-02-03 15:04:08 +01:00
void
user_function (TfeTextView *tv,
TfeTextViewOpenResponseType response-id,
gpointer user_data)
```
2021-02-03 15:04:08 +01:00
2021-06-18 15:35:20 +02:00
Emitted after the user calls `tfe_text_view_open`.
This signal informs the status of file I/O operation.
**Enumerations**
### TfeTextViewOpenResponseType
Predefined values for the response id given by `open-response` signal.
Members:
- TFE_OPEN_RESPONSE_SUCCESS: The file is successfully opened.
- TFE_OPEN_RESPONSE_CANCEL: Reading file is canceled by the user.
- TFE_OPEN_RESPONSE_ERROR: An error happened during the opening or reading process.