gtkd-developers/GtkD

Use signals as final methods in interfaces

Rogni opened this issue · 2 comments

Rogni commented

Currently signals in ListModelIF are generated as virtual methods

connect:

gulong addOnItemsChanged(void delegate(uint, uint, uint, ListModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0);

emit:
public void itemsChanged(uint position, uint removed, uint added);

and implementation of signals defined in mixin template ListModelT. It is required to implement signal methods in the derived classes.

        void itemsChanged(uint position, uint removed, uint added) {
            g_list_model_items_changed(getListModelStruct(), position, removed, added);
        }

        gulong addOnItemsChanged(void delegate(uint, uint, uint, ListModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
        {
            return Signals.connect(this, "items-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
        }

https://github.com/Rogni/ExampleContactsBook/blob/8ed1193ba5a5048b0a6a71cdef42ff10f7034aea/src/controllers/ContactListController.d#L84-L91

I suggest to move implementation of signal methods from mixin template to interface as final methods

Rogni commented

also maybe need generate

GListModel* getListModelStruct(bool transferOwnership = false) {
            return cast(GListModel*) getStruct;
}

as final method

Probably all functions that are not part of the GTK interface should be final functions in the D interface.