class Gtk::RecentManager

Overview

Gtk::RecentManager manages and looks up recently used files.

Each recently used file is identified by its URI, and has meta-data associated to it, like the names and command lines of the applications that have registered it, the number of time each application has registered the same file, the mime type of the file and whether the file should be displayed only by the applications that have registered it.

The recently used files list is per user.

Gtk::RecentManager acts like a database of all the recently used files. You can create new Gtk::RecentManager objects, but it is more efficient to use the default manager created by GTK.

Adding a new recently used file is as simple as:

WARNING ⚠️ The following code is in c ⚠️

Gtk::RecentManager *manager;

manager = gtk_recent_manager_get_default ();
gtk_recent_manager_add_item (manager, file_uri);

The Gtk::RecentManager will try to gather all the needed information from the file itself through GIO.

Looking up the meta-data associated with a recently used file given its URI requires calling Gtk::RecentManager#lookup_item:

WARNING ⚠️ The following code is in c ⚠️

Gtk::RecentManager *manager;
Gtk::RecentInfo *info;
GError *error = NULL;

manager = gtk_recent_manager_get_default ();
info = gtk_recent_manager_lookup_item (manager, file_uri, &error);
if (error)
  {
    g_warning ("Could not find the file: %s", error->message);
    g_error_free (error);
  }
else
 {
   // Use the info object
   gtk_recent_info_unref (info);
 }

In order to retrieve the list of recently used files, you can use Gtk::RecentManager#items, which returns a list of Gtk::RecentInfo.

Note that the maximum age of the recently used files list is controllable through the [property@Gtk.Settings:gtk-recent-files-max-age] property.

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/recent_manager.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

==(other : self) ==, bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

def self.new : self #

Creates a new recent manager object.

Recent manager objects are used to handle the list of recently used resources. A Gtk::RecentManager object monitors the recently used resources list, and emits the Gtk::RecentManager::#changed signal each time something inside the list changes.

Gtk::RecentManager objects are expensive: be sure to create them only when needed. You should use Gtk::RecentManager#default instead.


[View source]
def self.new(*, filename : String | Nil = nil, size : Int32 | Nil = nil) #

[View source]

Class Method Detail

def self.default : Gtk::RecentManager #

Gets a unique instance of Gtk::RecentManager that you can share in your application without caring about memory management.


[View source]
def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def add_full(uri : String, recent_data : Gtk::RecentData) : Bool #

Adds a new resource, pointed by uri, into the recently used resources list, using the metadata specified inside the Gtk::RecentData passed in recent_data.

The passed URI will be used to identify this resource inside the list.

In order to register the new recently used resource, metadata about the resource must be passed as well as the URI; the metadata is stored in a Gtk::RecentData, which must contain the MIME type of the resource pointed by the URI; the name of the application that is registering the item, and a command line to be used when launching the item.

Optionally, a Gtk::RecentData might contain a UTF-8 string to be used when viewing the item instead of the last component of the URI; a short description of the item; whether the item should be considered private - that is, should be displayed only by the applications that have registered it.


[View source]
def add_item(uri : String) : Bool #

Adds a new resource, pointed by uri, into the recently used resources list.

This function automatically retrieves some of the needed metadata and setting other metadata to common default values; it then feeds the data to Gtk::RecentManager#add_full.

See Gtk::RecentManager#add_full if you want to explicitly define the metadata for the resource pointed by uri.


[View source]
def changed_signal #

[View source]
def filename : String #

[View source]
def filename=(value : String) : String #

[View source]
def filename=(value : Nil) : Nil #

Set #filename property to nil.


[View source]
def filename? : String | Nil #

Same as #filename, but can return nil.


[View source]
def has_item(uri : String) : Bool #

Checks whether there is a recently used resource registered with uri inside the recent manager.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def items : GLib::List #

Gets the list of recently used resources.


[View source]
def lookup_item(uri : String) : Gtk::RecentInfo | Nil #

Searches for a URI inside the recently used resources list, and returns a Gtk::RecentInfo containing information about the resource like its MIME type, or its display name.


[View source]
def move_item(uri : String, new_uri : String | Nil) : Bool #

Changes the location of a recently used resource from uri to new_uri.

Please note that this function will not affect the resource pointed by the URIs, but only the URI used in the recently used resources list.


[View source]
def purge_items : Int32 #

Purges every item from the recently used resources list.


[View source]
def remove_item(uri : String) : Bool #

Removes a resource pointed by uri from the recently used resources list handled by a recent manager.


[View source]
def size : Int32 #

[View source]