summaryrefslogtreecommitdiff
path: root/test/smoke-tests/action-buttons.js
blob: 7997793354660013a6278803a3f48eded6cc8da4 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2013 Endless Mobile, Inc.

const Lang = imports.lang;
const Endless = imports.gi.Endless;
const Gtk = imports.gi.Gtk;

const TEST_APPLICATION_ID = 'com.endlessm.example.test-action-buttons';

const TestApplication = new Lang.Class ({
    Name: 'TestApplication',
    Extends: Endless.Application,

    vfunc_startup: function() {
        this.parent();

        this._page = new Gtk.Grid ();
        
        this._content = new Gtk.Grid ({
            hexpand: true,
            halign: Gtk.Align.CENTER,
            vexpand: true,
            valign: Gtk.Align.CENTER});

        this._darkSwitch = new Gtk.Switch ({active: false});
        this._darkSwitch.connect ('notify::active', Lang.bind (this, function (active) {
            if (this._darkSwitch.get_active()) {
                this._menu_panel.get_style_context().add_class('dark');
            } else {
                this._menu_panel.get_style_context().remove_class('dark');
            }
        }));
        this._content.attach(new Gtk.Label ({label: 'Dark action menu'}), 0, 0, 1, 1);
        this._content.attach(this._darkSwitch, 1, 0, 1, 1);

        this._content.attach (new Endless.ActionButton({
            name: 'LEFT',
            'icon-id': 'object-select-symbolic',
            label: 'LEFT',
            'label-position': Gtk.PositionType.LEFT
        }), 0, 1, 1, 1);
        this._content.attach (new Endless.ActionButton({
            name: 'TOP',
            'icon-id': 'object-select-symbolic',
            label: 'TOP',
            'label-position': Gtk.PositionType.TOP
        }), 1, 1, 1, 1);
        this._content.attach (new Endless.ActionButton({
            name: 'BOTTOM',
            'icon-id': 'object-select-symbolic',
            label: 'BOTTOM',
            'label-position': Gtk.PositionType.BOTTOM
        }), 0, 2, 1, 1);
        this._content.attach (new Endless.ActionButton({
            name: 'RIGHT',
            'icon-id': 'object-select-symbolic',
            label: 'RIGHT',
            'label-position': Gtk.PositionType.RIGHT
        }), 1, 2, 1, 1);
        
        this._menu = new Endless.ActionMenu ();
        
        // put the ActionMenu in a panel, as GtkGrid doesn't expand if none of its children want to
        this._menu_panel = new Gtk.Frame ({name: 'menu'});
        this._menu_panel.add (this._menu);
        this._menu_panel.set_hexpand (true);
        this._menu_panel.set_vexpand (true);

        // the ActionMenu takes 1/6 of the width
        this._page.set_column_homogeneous (true);
        this._page.attach (this._content, 0, 0, 5, 1);
        this._page.attach (this._menu_panel, 5, 0, 1, 1);
        
        this._menu.add_action ({
            name: 'select',
            'icon-name': 'object-select-symbolic',
            label: 'select stuff',
            'is-important': true },
            Lang.bind(this, function () {
        	var md = new Gtk.MessageDialog({modal:true, title:"Information",
        	    message_type:Gtk.MessageType.INFO,
        	    buttons:Gtk.ButtonsType.OK, text:"Select button pressed!"});
        	md.run();
        	md.destroy();
            }));

        this._menu.add_action ({
            name: 'delete',
            'icon-name': 'edit-delete-symbolic',
            label: 'delete stuff',
            'is-important': false });

        this._menu.add_action ({
            name: 'smile',
            'icon-name': 'face-smile-symbolic',
            label: 'smile',
            'is-important': false });

        this._menu.add_action ({
            name: 'sadface',
            'icon-name': 'face-sad-symbolic',
            label: 'sadface',
            'is-important': false });

        this._pm = new Endless.PageManager();
        this._pm.add(this._page, { name: "page" });
        
        let provider = new Gtk.CssProvider ();
        provider.load_from_path ('./test/smoke-tests/eosactionbutton.css');
        
        this._window = new Endless.Window({
            application: this,
            border_width: 1,
            page_manager: this._pm
        });
        
        let context = new Gtk.StyleContext();
        context.add_provider_for_screen(this._window.get_screen(),
                                        provider,
                                        Gtk.STYLE_PROVIDER_PRIORITY_USER);
        
        this._window.show_all();
    },

    _onButtonClicked: function () {
        this._window.destroy();
    },
});

let app = new TestApplication({ application_id: TEST_APPLICATION_ID,
                                flags: 0 });
app.run(ARGV);