After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 752792 - Port the codebase to use the 'Extends' keyword
Port the codebase to use the 'Extends' keyword
Status: RESOLVED FIXED
Product: gnome-documents
Classification: Core
Component: general
3.16.x
Other All
: Normal normal
: ---
Assigned To: GNOME documents maintainer(s)
GNOME documents maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-07-23 18:29 UTC by Alessandro Bono
Modified: 2015-10-12 18:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
selections: Extend objects instead of encapsulate them. (7.11 KB, patch)
2015-07-25 11:28 UTC, Alessandro Bono
none Details | Review
selections: Extend objects instead of encapsulate them (7.11 KB, patch)
2015-07-25 11:33 UTC, Alessandro Bono
none Details | Review
selections: Extend objects instead of encapsulate them (7.44 KB, patch)
2015-07-25 12:01 UTC, Alessandro Bono
committed Details | Review
embed: Extend objects instead of encapsulate them (3.83 KB, patch)
2015-07-25 12:01 UTC, Alessandro Bono
committed Details | Review
errorBox: Extend objects instead of encapsulate them (3.53 KB, patch)
2015-07-25 12:31 UTC, Alessandro Bono
committed Details | Review
mainToolbar: Extend objects instead of encapsulate them (5.08 KB, patch)
2015-07-25 12:31 UTC, Alessandro Bono
none Details | Review
mainWindow: Extend objects instead of encapsulate them (7.58 KB, patch)
2015-07-25 12:42 UTC, Alessandro Bono
none Details | Review
manager: Extend objects instead of encapsulate them (1.95 KB, patch)
2015-07-25 12:49 UTC, Alessandro Bono
committed Details | Review
password: Extend objects instead of encapsulate them (4.13 KB, patch)
2015-07-25 13:05 UTC, Alessandro Bono
committed Details | Review
places: Extend objects instead of encapsulate them (3.60 KB, patch)
2015-07-25 13:31 UTC, Alessandro Bono
committed Details | Review
mainToolbar: Extend objects instead of encapsulate them (6.59 KB, patch)
2015-07-25 14:38 UTC, Alessandro Bono
needs-work Details | Review
presentation: Extend objects instead of encapsulate them (5.63 KB, patch)
2015-07-25 15:08 UTC, Alessandro Bono
none Details | Review
presentation: Extend objects instead of encapsulate them (5.58 KB, patch)
2015-07-25 15:10 UTC, Alessandro Bono
none Details | Review
preview: Extend objects instead of encapsulate them (4.58 KB, patch)
2015-07-25 15:46 UTC, Alessandro Bono
committed Details | Review
properties: Extend objects instead of encapsulate them (3.69 KB, patch)
2015-07-25 15:59 UTC, Alessandro Bono
committed Details | Review
sharing: Extend objects instead of encapsulate them (3.94 KB, patch)
2015-07-25 16:11 UTC, Alessandro Bono
committed Details | Review
view: Extend objects instead of encapsulate them (11.83 KB, patch)
2015-07-25 16:29 UTC, Alessandro Bono
none Details | Review
mainWindow: Extend objects instead of encapsulate them (7.90 KB, patch)
2015-07-26 09:34 UTC, Alessandro Bono
committed Details | Review
presentation: Extend objects instead of encapsulate them (5.64 KB, patch)
2015-07-26 09:42 UTC, Alessandro Bono
committed Details | Review
view: Extend objects instead of encapsulate them (11.89 KB, patch)
2015-07-26 09:48 UTC, Alessandro Bono
committed Details | Review
mainToolbar: Use inheritance instead of composition (7.91 KB, patch)
2015-07-27 22:47 UTC, Alessandro Bono
committed Details | Review
edit: Use inheritance instead of composition (2.45 KB, patch)
2015-07-28 18:27 UTC, Alessandro Bono
committed Details | Review
searchbar: Use inheritance instead of composition (5.41 KB, patch)
2015-07-29 23:25 UTC, Alessandro Bono
none Details | Review
selections: Use inheritance instead of composition (4.78 KB, patch)
2015-07-31 14:08 UTC, Alessandro Bono
committed Details | Review
searchbar: Use inheritance instead of composition (6.19 KB, patch)
2015-08-03 16:22 UTC, Alessandro Bono
committed Details | Review
presentation,preview: separate JS signals from GObject signals (4.48 KB, patch)
2015-08-03 17:40 UTC, Alessandro Bono
committed Details | Review
edit,embed: remove unused lines (969 bytes, patch)
2015-08-03 17:41 UTC, Alessandro Bono
committed Details | Review
searchbar: turn destroy method into a handler for 'destroy' signal (3.07 KB, patch)
2015-08-03 18:47 UTC, Alessandro Bono
committed Details | Review
notifications: Use inheritance instead of composition (2.55 KB, patch)
2015-08-19 15:08 UTC, Alessandro Bono
committed Details | Review

Description Alessandro Bono 2015-07-23 18:29:23 UTC
Now with gjs we can use the 'Extends' keyword to inherit from a object instead of encapsulate it.
Comment 1 Alessandro Bono 2015-07-25 11:28:38 UTC
Created attachment 308120 [details] [review]
selections: Extend objects instead of encapsulate them.
Comment 2 Alessandro Bono 2015-07-25 11:33:37 UTC
Created attachment 308121 [details] [review]
selections: Extend objects instead of encapsulate them
Comment 3 Alessandro Bono 2015-07-25 12:01:14 UTC
Created attachment 308123 [details] [review]
selections: Extend objects instead of encapsulate them
Comment 4 Alessandro Bono 2015-07-25 12:01:27 UTC
Created attachment 308124 [details] [review]
embed: Extend objects instead of encapsulate them
Comment 5 Alessandro Bono 2015-07-25 12:31:11 UTC
Created attachment 308126 [details] [review]
errorBox: Extend objects instead of encapsulate them
Comment 6 Alessandro Bono 2015-07-25 12:31:38 UTC
Created attachment 308127 [details] [review]
mainToolbar: Extend objects instead of encapsulate them
Comment 7 Alessandro Bono 2015-07-25 12:42:44 UTC
Created attachment 308129 [details] [review]
mainWindow: Extend objects instead of encapsulate them
Comment 8 Alessandro Bono 2015-07-25 12:49:25 UTC
Created attachment 308130 [details] [review]
manager: Extend objects instead of encapsulate them
Comment 9 Alessandro Bono 2015-07-25 13:05:39 UTC
Created attachment 308133 [details] [review]
password: Extend objects instead of encapsulate them
Comment 10 Alessandro Bono 2015-07-25 13:31:38 UTC
Created attachment 308134 [details] [review]
places: Extend objects instead of encapsulate them
Comment 11 Alessandro Bono 2015-07-25 14:38:09 UTC
Created attachment 308136 [details] [review]
mainToolbar: Extend objects instead of encapsulate them
Comment 12 Alessandro Bono 2015-07-25 15:08:21 UTC
Created attachment 308139 [details] [review]
presentation: Extend objects instead of encapsulate them

https://bugzilla.gnome.org/show_bug.cgi?id=752792

https://bugzilla.gnome.org/show_bug.cgi?id=726450
Comment 13 Alessandro Bono 2015-07-25 15:10:33 UTC
Created attachment 308140 [details] [review]
presentation: Extend objects instead of encapsulate them
Comment 14 Alessandro Bono 2015-07-25 15:46:50 UTC
Created attachment 308142 [details] [review]
preview: Extend objects instead of encapsulate them
Comment 15 Alessandro Bono 2015-07-25 15:59:56 UTC
Created attachment 308143 [details] [review]
properties: Extend objects instead of encapsulate them
Comment 16 Alessandro Bono 2015-07-25 16:11:32 UTC
Created attachment 308144 [details] [review]
sharing: Extend objects instead of encapsulate them
Comment 17 Alessandro Bono 2015-07-25 16:29:15 UTC
Created attachment 308146 [details] [review]
view: Extend objects instead of encapsulate them
Comment 18 Alessandro Bono 2015-07-26 09:34:22 UTC
Created attachment 308166 [details] [review]
mainWindow: Extend objects instead of encapsulate them
Comment 19 Alessandro Bono 2015-07-26 09:42:41 UTC
Created attachment 308167 [details] [review]
presentation: Extend objects instead of encapsulate them
Comment 20 Alessandro Bono 2015-07-26 09:48:58 UTC
Created attachment 308168 [details] [review]
view: Extend objects instead of encapsulate them
Comment 21 Debarshi Ray 2015-07-27 13:49:16 UTC
Review of attachment 308123 [details] [review]:

Looks good to me, thanks. One small nitpick - I think "Use inheritance instead of composition" would be a more idiomatic way of describing the change.
Comment 22 Debarshi Ray 2015-07-27 14:06:38 UTC
Review of attachment 308124 [details] [review]:

Thanks. Pushed.
Comment 23 Debarshi Ray 2015-07-27 15:08:49 UTC
Review of attachment 308126 [details] [review]:

Looks good to me.
Comment 24 Debarshi Ray 2015-07-27 15:30:02 UTC
Review of attachment 308130 [details] [review]:

::: src/manager.js
@@ +182,3 @@
 const BaseModel = new Lang.Class({
     Name: 'BaseModel',
+    Extends: Gio.Menu,

I must point out the GMenu is defined as a final type in C. So, even if we can inherit Gio.Menu in JavaScript, it might be best not to do so, unless we can convince the right people that GMenu should be derivable.
Comment 25 Debarshi Ray 2015-07-27 16:08:57 UTC
Review of attachment 308136 [details] [review]:

Thanks for the patch, Alessandro.

::: src/preview.js
@@ +1015,2 @@
         this.revealer = new Gtk.Revealer({ valign: Gtk.Align.START });
+        this.revealer.add(this);

I am not so sure about this part.

The idiom for composite widgets is to inherit from the top-most widget type. In this case, it would be Gtk.Revealer. Having a member widget own the instance itself looks strange, and can lead to weird life cycle issues.

Instead, how about inheriting PreviewFullscreenToolbar from Gtk.Revealer, and having the PreviewToolbar as a member variable (say this._toolbar)? The only PreviewToolbar method that is used for PreviewFullscreenToolbar is setModel. We can add a setModel to it, which in turn calls this._toolbar.setModel.
Comment 26 Alessandro Bono 2015-07-27 22:47:12 UTC
Created attachment 308263 [details] [review]
mainToolbar: Use inheritance instead of composition
Comment 27 Debarshi Ray 2015-07-28 07:05:09 UTC
Review of attachment 308263 [details] [review]:

Looks good to me.

::: src/preview.js
@@ +1048,1 @@
     },

Thanks for catching this.
Comment 28 Debarshi Ray 2015-07-28 07:21:10 UTC
Review of attachment 308133 [details] [review]:

Perfect. Thanks Alessandro.
Comment 29 Debarshi Ray 2015-07-28 08:05:13 UTC
Review of attachment 308134 [details] [review]:

++
Comment 30 Debarshi Ray 2015-07-28 08:06:45 UTC
Review of attachment 308166 [details] [review]:

++
Comment 31 Debarshi Ray 2015-07-28 08:17:38 UTC
Review of attachment 308167 [details] [review]:

++
Comment 32 Debarshi Ray 2015-07-28 08:28:03 UTC
Review of attachment 308142 [details] [review]:

++
Comment 33 Debarshi Ray 2015-07-28 09:44:30 UTC
Review of attachment 308143 [details] [review]:

++
Comment 34 Debarshi Ray 2015-07-28 09:48:10 UTC
Review of attachment 308144 [details] [review]:

++
Comment 35 Debarshi Ray 2015-07-28 09:58:31 UTC
Review of attachment 308168 [details] [review]:

++
Comment 36 Debarshi Ray 2015-07-28 10:01:29 UTC
Thanks for all the wonderful patches.
Comment 37 Alessandro Bono 2015-07-28 18:27:06 UTC
Created attachment 308320 [details] [review]
edit: Use inheritance instead of composition
Comment 38 Debarshi Ray 2015-07-29 15:33:10 UTC
Review of attachment 308320 [details] [review]:

++
Comment 39 Alessandro Bono 2015-07-29 23:25:05 UTC
Created attachment 308419 [details] [review]
searchbar: Use inheritance instead of composition
Comment 40 Alessandro Bono 2015-07-31 14:08:05 UTC
Created attachment 308554 [details] [review]
selections: Use inheritance instead of composition
Comment 41 Debarshi Ray 2015-08-03 14:29:57 UTC
Review of attachment 308419 [details] [review]:

Thanks for the patch, Alessandro.

::: src/searchbar.js
@@ +74,3 @@
                 Application.application.disconnect(searchStateId);
                 Application.application.change_action_state('search', GLib.Variant.new('b', false));
             }));

For some reason this anonymous handler is not getting called anymore. Interestingly, if I use vfunc_destroy (to override the destroy vfunc of the widget) it gets called.

Since this is not getting called, we are not disconnecting from searchStateId, which leads to a CRITICAL if we go to the preview and toggle the search bar. :/

@@ +96,3 @@
     handleEvent: function(event) {
         // Skip if the search bar is shown and the focus is elsewhere
+        if (this.get_search_mode() && !this._searchEntry.is_focus)

this.search_mode_enabled should work, so no need to change this.

@@ +109,3 @@
 
+    reveal: function() {
+        this.set_search_mode(true);

Ditto.
Comment 42 Debarshi Ray 2015-08-03 15:56:58 UTC
(In reply to Debarshi Ray from comment #41)
> Review of attachment 308419 [details] [review] [review]:
> 
> Thanks for the patch, Alessandro.
> 
> ::: src/searchbar.js
> @@ +74,3 @@
>                  Application.application.disconnect(searchStateId);
>                  Application.application.change_action_state('search',
> GLib.Variant.new('b', false));
>              }));
> 
> For some reason this anonymous handler is not getting called anymore.
> Interestingly, if I use vfunc_destroy (to override the destroy vfunc of the
> widget) it gets called.

This is the culprit:
Signals.addSignalMethods(Searchbar.prototype);

It needs to be changed to:
Utils.addJSSignalMethods(Searchbar.prototype);

We can not use the pure gjs signal machinery to connect to GObject signals (like 'destroy'). At the same time this class adds its own pure gjs signal ('activate-result'), which can not be used with the GObject signal machinery. So, we need to use a separate set of connect/disconnect methods for these two categories.

The Application class is another example of such a hybrid class.
Comment 43 Debarshi Ray 2015-08-03 16:09:29 UTC
Review of attachment 308142 [details] [review]:

::: src/preview.js
@@ +49,3 @@
 const PreviewView = new Lang.Class({
     Name: 'PreviewView',
+    Extends: Gtk.Stack,

Now that PreviewView inherits from a GObject and also adds its own pure gjs signal ('search-changed'), we need to make the same change as comment 42.
Comment 44 Debarshi Ray 2015-08-03 16:16:04 UTC
Review of attachment 308167 [details] [review]:

::: src/presentation.js
@@ +202,3 @@
             function(widget, response) {
                 this.emit('output-activated', null);
             }));

Needs the same change as comment 42.
Comment 45 Alessandro Bono 2015-08-03 16:22:55 UTC
Created attachment 308690 [details] [review]
searchbar: Use inheritance instead of composition
Comment 46 Debarshi Ray 2015-08-03 16:45:35 UTC
Review of attachment 308263 [details] [review]:

::: src/preview.js
@@ +1008,3 @@
 const PreviewFullscreenToolbar = new Lang.Class({
     Name: 'PreviewFullscreenToolbar',
+    Extends: Gtk.Revealer,

Same as comment 42
Comment 47 Debarshi Ray 2015-08-03 16:55:50 UTC
Review of attachment 308690 [details] [review]:

Thanks, Alessandro. Looks good now.
Comment 48 Debarshi Ray 2015-08-03 17:14:27 UTC
Review of attachment 308554 [details] [review]:

++
Comment 49 Alessandro Bono 2015-08-03 17:40:54 UTC
Created attachment 308694 [details] [review]
presentation,preview: separate JS signals from GObject signals

Fallout from the composition->inheritance port
Comment 50 Alessandro Bono 2015-08-03 17:41:10 UTC
Created attachment 308695 [details] [review]
edit,embed: remove unused lines
Comment 51 Alessandro Bono 2015-08-03 18:47:15 UTC
Created attachment 308699 [details] [review]
searchbar: turn destroy method into a handler for 'destroy' signal
Comment 52 Debarshi Ray 2015-08-04 07:24:51 UTC
Review of attachment 308695 [details] [review]:

++
Comment 53 Debarshi Ray 2015-08-06 15:29:31 UTC
Review of attachment 308694 [details] [review]:

Perfect. Thanks, Alessandro.
Comment 54 Debarshi Ray 2015-08-06 15:32:19 UTC
Review of attachment 308699 [details] [review]:

++
Comment 55 Alessandro Bono 2015-08-19 15:08:27 UTC
Created attachment 309607 [details] [review]
notifications: Use inheritance instead of composition
Comment 56 Bastien Nocera 2015-09-18 16:38:34 UTC
Review of attachment 309607 [details] [review]:

Looks good, based on the status of the other patches.
Comment 57 Cosimo Cecchi 2015-09-18 16:44:09 UTC
Review of attachment 309607 [details] [review]:

Indeed, looks fine
Comment 58 Cosimo Cecchi 2015-09-18 16:47:24 UTC
Review of attachment 308130 [details] [review]:

::: src/manager.js
@@ +182,3 @@
 const BaseModel = new Lang.Class({
     Name: 'BaseModel',
+    Extends: Gio.Menu,

Extending the class in C or Javascript is very different, and there's not much that can be done AFAIK to prevent subclassing a GObject from Javascript.
I think I'm comfortable that this patch won't break things.
Comment 59 Debarshi Ray 2015-10-12 18:36:22 UTC
(In reply to Cosimo Cecchi from comment #58)
> Review of attachment 308130 [details] [review] [review]:
> 
> ::: src/manager.js
> @@ +182,3 @@
>  const BaseModel = new Lang.Class({
>      Name: 'BaseModel',
> +    Extends: Gio.Menu,
> 
> Extending the class in C or Javascript is very different, and there's not
> much that can be done AFAIK to prevent subclassing a GObject from Javascript.
> I think I'm comfortable that this patch won't break things.

Ok. Thanks for taking a look.

I pushed the last two patches to master.