Merge lp:~elementary-apps/granite/dynamicnotebook into lp:~elementary-pantheon/granite/granite

Proposed by Rico Tzschichholz
Status: Work in progress
Proposed branch: lp:~elementary-apps/granite/dynamicnotebook
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 323 lines (+147/-73)
1 file modified
lib/Widgets/DynamicNotebook.vala (+147/-73)
To merge this branch: bzr merge lp:~elementary-apps/granite/dynamicnotebook
Reviewer Review Type Date Requested Status
Cody Garver (community) Needs Information
Tom Beckmann Pending
Review via email: mp+157874@code.launchpad.net

Description of the change

Just here to see a nice diff against trunk.

To post a comment you must log in.
559. By Rico Tzschichholz

Move dummy new_window callback for tab

Revision history for this message
Cody Garver (codygarver) wrote :

What's the hold up here?

Revision history for this message
David Gomes (davidgomes) wrote :

It's not perfect yet. I've been wanting to work on time but I still didn't have enough free time.

Revision history for this message
Cody Garver (codygarver) wrote :

Should the status of this branch be Rejected now that xapantu has got a DN fix in trunk?

review: Needs Information
Revision history for this message
xapantu (xapantu) wrote :

This branch does not fix the same bug, while my code just fixed the current bug, this is a larger refactoring of the way the DynamicNotebook works, which is interesting since this way is much more logical. The tab_moved signal is really not practical (the only good point in it is that everything can be handled with one signal, but I am not sure it is a very good idea).

Unmerged revisions

559. By Rico Tzschichholz

Move dummy new_window callback for tab

558. By Rico Tzschichholz

Avoid breaking ABI/API

557. By Tom Beckmann

Do proper signal handling fixing detaching tabs

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/Widgets/DynamicNotebook.vala'
--- lib/Widgets/DynamicNotebook.vala 2013-04-05 07:11:07 +0000
+++ lib/Widgets/DynamicNotebook.vala 2013-04-10 09:31:27 +0000
@@ -314,13 +314,40 @@
314 private int tab_width = 150;314 private int tab_width = 150;
315 private int max_tab_width = 150;315 private int max_tab_width = 150;
316316
317 /**
318 * A new tab was added
319 * @param tab the new Tab
320 */
317 public signal void tab_added (Tab tab);321 public signal void tab_added (Tab tab);
322
323 /**
324 * A new tab was added
325 * Note: The return value has no meaning!
326 * @param tab the removed Tab
327 */
318 public signal bool tab_removed (Tab tab);328 public signal bool tab_removed (Tab tab);
319 Tab? old_tab; //stores a reference for tab_switched329
330 unowned Tab? old_tab; //stores a reference for tab_switched
320 public signal void tab_switched (Tab? old_tab, Tab new_tab);331 public signal void tab_switched (Tab? old_tab, Tab new_tab);
332
333 //FIXME can be removed on API cleaning
334 /**
335 * Connect to tab_create_window and tab_reordered instead
336 */
337 [Deprecated (since=0.2)]
321 public signal void tab_moved (Tab tab, int new_pos, bool new_window, int x, int y);338 public signal void tab_moved (Tab tab, int new_pos, bool new_window, int x, int y);
339
322 public signal void tab_duplicated (Tab duplicated_tab);340 public signal void tab_duplicated (Tab duplicated_tab);
323341
342 public signal void tab_reordered (Tab tab, int new_pos);
343
344 /**
345 * A tab was detached. You're supposed to connect to this signal
346 * and return the notebook this tab should be added or null, if
347 * you want to handle adding it manually
348 */
349 public signal DynamicNotebook? tab_detached (Tab tab, int x, int y);
350
324 private static const string CLOSE_BUTTON_STYLE = """351 private static const string CLOSE_BUTTON_STYLE = """
325 * {352 * {
326 -GtkButton-default-border : 0;353 -GtkButton-default-border : 0;
@@ -366,14 +393,12 @@
366 new_tab_m.activate.connect (() => {393 new_tab_m.activate.connect (() => {
367 var t = new Tab ();394 var t = new Tab ();
368 notebook.page = (int) this.insert_tab (t, -1);395 notebook.page = (int) this.insert_tab (t, -1);
369 this.tab_added (t);
370 });396 });
371397
372 this.button_press_event.connect ((e) => {398 this.button_press_event.connect ((e) => {
373 if (e.type == Gdk.EventType.2BUTTON_PRESS && e.button == 1) {399 if (e.type == Gdk.EventType.2BUTTON_PRESS && e.button == 1) {
374 var t = new Tab ();400 var t = new Tab ();
375 notebook.page = (int) this.insert_tab (t, -1);401 notebook.page = (int) this.insert_tab (t, -1);
376 this.tab_added (t);
377 } else if (e.button == 3) {402 } else if (e.button == 3) {
378 menu.popup (null, null, null, 3, e.time);403 menu.popup (null, null, null, 3, e.time);
379 }404 }
@@ -393,7 +418,6 @@
393 add.clicked.connect ( () => {418 add.clicked.connect ( () => {
394 var t = new Tab ();419 var t = new Tab ();
395 notebook.page = (int) this.insert_tab (t, -1);420 notebook.page = (int) this.insert_tab (t, -1);
396 this.tab_added (t);
397 });421 });
398422
399 this.size_allocate.connect (() => {423 this.size_allocate.connect (() => {
@@ -416,7 +440,6 @@
416 case Gdk.Key.@T:440 case Gdk.Key.@T:
417 if ((e.state & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK) {441 if ((e.state & Gdk.ModifierType.CONTROL_MASK) == Gdk.ModifierType.CONTROL_MASK) {
418 var t = new Tab ();442 var t = new Tab ();
419 this.tab_added (t);
420 notebook.page = (int) this.insert_tab (t, -1);443 notebook.page = (int) this.insert_tab (t, -1);
421 return true;444 return true;
422 }445 }
@@ -467,35 +490,80 @@
467 return false;490 return false;
468 });491 });
469492
493 notebook.page_added.connect (on_page_added);
494 notebook.page_removed.connect (on_page_removed);
470 notebook.switch_page.connect (on_switch_page);495 notebook.switch_page.connect (on_switch_page);
471 notebook.page_reordered.connect (on_page_reordered);496 notebook.page_reordered.connect (on_page_reordered);
472 notebook.create_window.connect (on_create_window);497 notebook.create_window.connect (on_create_window);
473 }498 }
474499
475 ~Notebook () {500 ~Notebook () {
501 notebook.page_added.disconnect (on_page_added);
502 notebook.page_removed.disconnect (on_page_removed);
476 notebook.switch_page.disconnect (on_switch_page);503 notebook.switch_page.disconnect (on_switch_page);
477 notebook.page_reordered.disconnect (on_page_reordered);504 notebook.page_reordered.disconnect (on_page_reordered);
478 notebook.create_window.disconnect (on_create_window);505 notebook.create_window.disconnect (on_create_window);
479 }506 }
480507
481 void on_switch_page (Gtk.Widget page, uint pagenum) {508 void on_switch_page (Gtk.Notebook notebook, Gtk.Widget page, uint pagenum) {
482 var new_tab = notebook.get_tab_label (page) as Tab;509 unowned Tab? new_tab = notebook.get_tab_label (page) as Tab;
510 if (new_tab == null)
511 return;
483512
484 tab_switched (old_tab, new_tab);513 unowned Tab? current_tab = old_tab as Tab;
485 old_tab = new_tab;514 old_tab = new_tab;
486 }515
487516 tab_switched (current_tab, new_tab);
488 void on_page_reordered (Gtk.Widget page, uint pagenum) {517 }
489 tab_moved (notebook.get_tab_label (page) as Tab, (int) pagenum, false, -1, -1);518
519 void on_page_reordered (Gtk.Notebook notebook, Gtk.Widget page, uint pagenum) {
520 unowned Tab? tab = notebook.get_tab_label (page) as Tab;
521 if (tab == null)
522 return;
523
524 //FIXME must be removed on API cleaning
525 if (Signal.has_handler_pending (this, Signal.lookup ("tab-moved", typeof (DynamicNotebook)), 0, true)) {
526 // Filled up with dummy values to preserve API
527 tab_moved (tab, (int)pagenum, false, 0, 0);
528 return;
529 }
530
531 tab_reordered (tab, (int)pagenum);
532 }
533
534 void on_page_removed (Gtk.Notebook notebook, Gtk.Widget page, uint pagenum) {
535 unowned Tab? tab = page as Tab;
536 if (tab == null)
537 return;
538
539 disconnect_tab_signals (tab);
540 tab_removed (tab);
541 }
542
543 void on_page_added (Gtk.Notebook notebook, Gtk.Widget page, uint pagenum) {
544 unowned Tab? tab = notebook.get_tab_label (page) as Tab;
545 if (tab == null)
546 return;
547
548 connect_tab_signals (tab);
549 tab_added (tab);
490 }550 }
491551
492 unowned Gtk.Notebook on_create_window (Gtk.Widget page, int x, int y) {552 unowned Gtk.Notebook on_create_window (Gtk.Widget page, int x, int y) {
493 var tab = notebook.get_tab_label (page) as Tab;553 Tab? tab = notebook.get_tab_label (page) as Tab;
494 notebook.remove_page (notebook.page_num (tab.page_container));554 if (tab == null)
495 tab.page_container.destroy ();555 return null;
496556
497 tab_moved (tab, 0, true, x, y);557 remove_tab (tab);
498 return null;558
559 //FIXME must be removed on API cleaning
560 if (Signal.has_handler_pending (this, Signal.lookup ("tab-moved", typeof (DynamicNotebook)), 0, true)) {
561 tab_moved (tab, 0, true, x, y);
562 return null;
563 }
564
565 var new_notebook = tab_detached (notebook.get_tab_label (page) as Tab, x, y);
566 return new_notebook != null ? new_notebook.notebook : null;
499 }567 }
500568
501 private void recalc_size () {569 private void recalc_size () {
@@ -516,25 +584,19 @@
516 }584 }
517585
518 public void remove_tab (Tab tab) {586 public void remove_tab (Tab tab) {
519 if (Signal.has_handler_pending (this, Signal.lookup ("tab-removed", typeof (DynamicNotebook)), 0, true)) {
520 var sure = tab_removed (tab);
521 if (!sure)
522 return;
523 }
524
525 var pos = get_tab_position (tab);587 var pos = get_tab_position (tab);
526 if (pos != -1)588 if (pos < 0)
527 notebook.remove_page (pos);589 return;
528 tab.page_container.destroy ();590
591 notebook.remove_page (pos);
529 }592 }
530593
531 public void next_page () {594 public void next_page () {
532 this.notebook.page = this.notebook.page + 1 >= this.notebook.get_n_pages () ? this.notebook.page = 0 : this.notebook.page + 1;595 notebook.next_page ();
533 }596 }
534597
535 public void previous_page () {598 public void previous_page () {
536 this.notebook.page = this.notebook.page - 1 < 0 ?599 notebook.prev_page ();
537 this.notebook.page = this.notebook.get_n_pages () - 1 : this.notebook.page - 1;
538 }600 }
539601
540 public override void show () {602 public override void show () {
@@ -558,7 +620,6 @@
558620
559 public void set_tab_position (Tab tab, int position) {621 public void set_tab_position (Tab tab, int position) {
560 notebook.reorder_child (tab.page_container, position);622 notebook.reorder_child (tab.page_container, position);
561 tab_moved (tab, position, false, -1, -1);
562 }623 }
563624
564 public Tab? get_tab_by_index (int index) {625 public Tab? get_tab_by_index (int index) {
@@ -576,15 +637,6 @@
576 public uint insert_tab (Tab tab, int index) {637 public uint insert_tab (Tab tab, int index) {
577 return_if_fail (tabs.index (tab) < 0);638 return_if_fail (tabs.index (tab) < 0);
578639
579 var i = 0;
580 if (index == -1)
581 i = this.notebook.insert_page (tab.page_container, tab, this.notebook.get_n_pages ());
582 else
583 i = this.notebook.insert_page (tab.page_container, tab, index);
584
585 this.notebook.set_tab_reorderable (tab.page_container, this.allow_drag);
586 this.notebook.set_tab_detachable (tab.page_container, this.allow_new_window);
587
588 tab._icon.visible = show_icons;640 tab._icon.visible = show_icons;
589 tab.duplicate_m.visible = allow_duplication;641 tab.duplicate_m.visible = allow_duplication;
590 tab.new_window_m.visible = allow_new_window;642 tab.new_window_m.visible = allow_new_window;
@@ -592,41 +644,63 @@
592 tab.width_request = tab_width;644 tab.width_request = tab_width;
593 tab.close.get_style_context ().add_provider (button_fix,645 tab.close.get_style_context ().add_provider (button_fix,
594 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);646 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
595647 tab.close.visible = tabs_closable;
596 tab.closed.connect ( () => {648
597 remove_tab (tab);649 uint i = 0;
598 });650 if (index == -1)
599651 i = notebook.insert_page (tab.page_container, tab, notebook.get_n_pages ());
600 tab.close_others.connect ( () => {652 else
601 var num = 0; //save num, in case a tab refused to close so we don't end up in an infinite loop653 i = notebook.insert_page (tab.page_container, tab, index);
602654
603 for (var j = 0; j < tabs.length (); j++) {655 notebook.set_tab_reorderable (tab.page_container, allow_drag);
604 if (tab != tabs.nth_data (j)) {656 notebook.set_tab_detachable (tab.page_container, allow_new_window);
605 tabs.nth_data (j).closed ();657
606 if (num == n_tabs) break;658 recalc_size ();
607 j--;
608 }
609
610 num = n_tabs;
611 }
612 });
613
614 tab.new_window.connect (() => {
615 notebook.remove_page (notebook.page_num (tab.page_container));
616 tab.page_container.destroy ();
617 tab_moved (tab, 0, true, 0, 0);
618 });
619
620 tab.duplicate.connect (() => {
621 tab_duplicated (tab);
622 });
623
624 this.recalc_size ();
625
626 if (!tabs_closable)
627 tab.close.visible = false;
628659
629 return i;660 return i;
630 }661 }
662
663 void connect_tab_signals (Tab tab) {
664 tab.closed.connect (on_tab_closed);
665 tab.close_others.connect (on_close_others);
666 tab.new_window.connect (on_tab_new_window);
667 tab.duplicate.connect (on_tab_duplicated);
668 }
669
670 void disconnect_tab_signals (Tab tab) {
671 tab.closed.disconnect (on_tab_closed);
672 tab.close_others.disconnect (on_close_others);
673 tab.new_window.disconnect (on_tab_new_window);
674 tab.duplicate.disconnect (on_tab_duplicated);
675 }
676
677 void on_tab_duplicated (Tab tab) {
678 tab_duplicated (tab);
679 }
680
681 void on_tab_new_window (Tab tab) {
682 //notebook.remove_page (notebook.page_num (tab.page_container));
683 //tab.page_container.destroy ();
684 //notebook.create_window (tab.page_container, -1, -1);
685 }
686
687 void on_tab_closed (Tab tab) {
688 remove_tab (tab);
689 }
690
691 void on_close_others (Tab tab) {
692 var num = 0; //save num, in case a tab refused to close so we don't end up in an infinite loop
693
694 for (var j = 0; j < tabs.length (); j++) {
695 unowned Tab t = tabs.nth_data (j);
696 if (tab != t) {
697 t.closed ();
698 if (num == n_tabs) break;
699 j--;
700 }
701
702 num = n_tabs;
703 }
704 }
631 }705 }
632}706}

Subscribers

People subscribed via source and target branches