CtkFileChooserButton

CtkFileChooserButton — A button to launch a file selection dialog

Functions

Properties

CtkFileChooser * dialog Write / Construct Only
char * title Read / Write
int width-chars Read / Write

Signals

void file-set Run First

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkContainer
                ╰── CtkBox
                    ╰── CtkFileChooserButton

Implemented Interfaces

CtkFileChooserButton implements AtkImplementorIface, CtkBuildable, CtkOrientable and CtkFileChooser.

Includes

#include <ctk/ctk.h>

Description

The CtkFileChooserButton is a widget that lets the user select a file. It implements the CtkFileChooser interface. Visually, it is a file name with a button to bring up a CtkFileChooserDialog. The user can then use that dialog to change the file associated with that button. This widget does not support setting the “select-multiple” property to TRUE.

Create a button to let the user select a file in /etc

1
2
3
4
5
6
7
8
{
  CtkWidget *button;

  button = ctk_file_chooser_button_new (_("Select a file"),
                                        CTK_FILE_CHOOSER_ACTION_OPEN);
  ctk_file_chooser_set_current_folder (CTK_FILE_CHOOSER (button),
                                       "/etc");
}

The CtkFileChooserButton supports the CtkFileChooserActions CTK_FILE_CHOOSER_ACTION_OPEN and CTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.

The CtkFileChooserButton will ellipsize the label, and will thus request little horizontal space. To give the button more space, you should call ctk_widget_get_preferred_size(), ctk_file_chooser_button_set_width_chars(), or pack the button in such a way that other interface elements give space to the widget.

CSS nodes

CtkFileChooserButton has a CSS node with name “filechooserbutton”, containing a subnode for the internal button with name “button” and style class “.file”.

Functions

ctk_file_chooser_button_new ()

CtkWidget *
ctk_file_chooser_button_new (const gchar *title,
                             CtkFileChooserAction action);

Creates a new file-selecting button widget.

Parameters

title

the title of the browse dialog.

 

action

the open mode for the widget.

 

Returns

a new button widget.

Since: 2.6


ctk_file_chooser_button_new_with_dialog ()

CtkWidget *
ctk_file_chooser_button_new_with_dialog
                               (CtkWidget *dialog);

Creates a CtkFileChooserButton widget which uses dialog as its file-picking window.

Note that dialog must be a CtkDialog (or subclass) which implements the CtkFileChooser interface and must not have CTK_DIALOG_DESTROY_WITH_PARENT set.

Also note that the dialog needs to have its confirmative button added with response CTK_RESPONSE_ACCEPT or CTK_RESPONSE_OK in order for the button to take over the file selected in the dialog.

Parameters

dialog

the widget to use as dialog.

[type Ctk.Dialog]

Returns

a new button widget.

Since: 2.6


ctk_file_chooser_button_get_title ()

const gchar *
ctk_file_chooser_button_get_title (CtkFileChooserButton *button);

Retrieves the title of the browse dialog used by button . The returned value should not be modified or freed.

Parameters

button

the button widget to examine.

 

Returns

a pointer to the browse dialog’s title.

Since: 2.6


ctk_file_chooser_button_set_title ()

void
ctk_file_chooser_button_set_title (CtkFileChooserButton *button,
                                   const gchar *title);

Modifies the title of the browse dialog used by button .

Parameters

button

the button widget to modify.

 

title

the new browse dialog title.

 

Since: 2.6


ctk_file_chooser_button_get_width_chars ()

gint
ctk_file_chooser_button_get_width_chars
                               (CtkFileChooserButton *button);

Retrieves the width in characters of the button widget’s entry and/or label.

Parameters

button

the button widget to examine.

 

Returns

an integer width (in characters) that the button will use to size itself.

Since: 2.6


ctk_file_chooser_button_set_width_chars ()

void
ctk_file_chooser_button_set_width_chars
                               (CtkFileChooserButton *button,
                                gint n_chars);

Sets the width (in characters) that button will use to n_chars .

Parameters

button

the button widget to examine.

 

n_chars

the new width, in characters.

 

Since: 2.6


ctk_file_chooser_button_get_focus_on_click ()

gboolean
ctk_file_chooser_button_get_focus_on_click
                               (CtkFileChooserButton *button);

ctk_file_chooser_button_get_focus_on_click has been deprecated since version 3.20 and should not be used in newly-written code.

Use ctk_widget_get_focus_on_click() instead

Returns whether the button grabs focus when it is clicked with the mouse. See ctk_file_chooser_button_set_focus_on_click().

Parameters

button

a CtkFileChooserButton

 

Returns

TRUE if the button grabs focus when it is clicked with the mouse.

Since: 2.10


ctk_file_chooser_button_set_focus_on_click ()

void
ctk_file_chooser_button_set_focus_on_click
                               (CtkFileChooserButton *button,
                                gboolean focus_on_click);

ctk_file_chooser_button_set_focus_on_click has been deprecated since version 3.20 and should not be used in newly-written code.

Use ctk_widget_set_focus_on_click() instead

Sets whether the button will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don’t want the keyboard focus removed from the main area of the application.

Parameters

button

a CtkFileChooserButton

 

focus_on_click

whether the button grabs focus when clicked with the mouse

 

Since: 2.10

Types and Values

struct CtkFileChooserButton

struct CtkFileChooserButton;

struct CtkFileChooserButtonClass

struct CtkFileChooserButtonClass {
  CtkBoxClass parent_class;

  void (* file_set) (CtkFileChooserButton *fc);
};

Members

file_set ()

Signal emitted when the user selects a file.

 

Property Details

The “dialog” property

  “dialog”                   CtkFileChooser *

Instance of the CtkFileChooserDialog associated with the button.

Owner: CtkFileChooserButton

Flags: Write / Construct Only

Since: 2.6


The “title” property

  “title”                    char *

Title to put on the CtkFileChooserDialog associated with the button.

Owner: CtkFileChooserButton

Flags: Read / Write

Default value: "Select a File"

Since: 2.6


The “width-chars” property

  “width-chars”              int

The width of the entry and label inside the button, in characters.

Owner: CtkFileChooserButton

Flags: Read / Write

Allowed values: >= -1

Default value: -1

Since: 2.6

Signal Details

The “file-set” signal

void
user_function (CtkFileChooserButton *widget,
               gpointer              user_data)

The ::file-set signal is emitted when the user selects a file.

Note that this signal is only emitted when the user changes the file.

Parameters

widget

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First

Since: 2.12

See Also

CtkFileChooserDialog