File: DynamicNotebookView.vala

package info (click to toggle)
granite 6.2.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,768 kB
  • sloc: python: 10; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 1,569 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright 2011–2019 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

public class DynamicNotebookView : Gtk.Grid {
    construct {
        var notebook = new Granite.Widgets.DynamicNotebook ();
        notebook.expand = true;
        notebook.allow_restoring = true;

        int i;

        for (i = 1; i <= 6; i++) {
            var page = new Gtk.Label ("Page %d".printf (i));
            var tab = new Granite.Widgets.Tab (
                "Tab %d".printf (i),
                new ThemedIcon ("mail-mark-important-symbolic"),
                page
            );
            tab.tooltip = "Customizable tooltip %d".printf (i);
            notebook.insert_tab (tab, i - 1);
        }

        notebook.new_tab_requested.connect (() => {
            var page = new Gtk.Label ("Page %d".printf (i));
            var tab = new Granite.Widgets.Tab (
                "Tab %d".printf (i), new ThemedIcon ("mail-mark-important-symbolic"), page
            );
            tab.tooltip = "Customizable tooltip %d".printf (i);
            notebook.insert_tab (tab, i - 1);
            i++;
        });

        notebook.close_tab_requested.connect ((tab) => {
            tab.restore_data = ((Gtk.Label)(tab.page)).label;
            return true;
        });

        notebook.tab_restored.connect ((label, data, icon) => {
            var page = new Gtk.Label (data);
            var tab = new Granite.Widgets.Tab (label, icon, page);
            notebook.insert_tab (tab, i - 1);
        });

        add (notebook);
    }
}