-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconfirmDialog.js
More file actions
76 lines (71 loc) · 2.13 KB
/
confirmDialog.js
File metadata and controls
76 lines (71 loc) · 2.13 KB
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
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars */
import GObject from 'gi://GObject'
import St from 'gi://St'
import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js';
import * as CheckBox from 'resource:///org/gnome/shell/ui/checkBox.js';
import * as Clutter from 'gi://Clutter';
let _openDialog
export function openConfirmDialog (title, message, subMessage, okLabel, cancelLabel, callback) {
log('dlg.openConfirmDialog')
if (!_openDialog) {
_openDialog = new ConfirmDialog()
.setContentLayout(title, message + '\n' + subMessage)
.setActionButtons(okLabel, cancelLabel, callback)
.open()
}
}
const ConfirmDialog = GObject.registerClass(
class ConfirmDialog extends ModalDialog.ModalDialog {
setContentLayout (title, desc) {
const mainBox = new St.BoxLayout({
vertical: false
})
const messageBox = new St.BoxLayout({
vertical: true
})
const subjectLabel = new St.Label({
style: 'font-weight: bold;',
// x_align: Clutter.ActorAlign.CENTER,
text: title
})
const descLabel = new St.Label({
style: 'padding-top: 12px;',
// x_align: Clutter.ActorAlign.CENTER,
text: desc
})
descLabel.clutter_text.line_wrap = true
const descScroll = new St.ScrollView()
const descBox = new St.BoxLayout({ vertical: true })
descBox.add_child(descLabel)
descScroll.add_child(descBox)
messageBox.add_child(subjectLabel)
messageBox.add_child(descScroll)
mainBox.add_child(messageBox)
this.contentLayout.add_child(mainBox)
return this
}
setActionButtons (okLabel, cancelLabel, callback) {
const buttons = [{
label: okLabel,
action: () => {
this.close()
callback && callback()
_openDialog = null
}
}]
if (cancelLabel) {
buttons.push({
label: cancelLabel,
action: () => {
this.close()
_openDialog = null
},
key: Clutter.Escape
})
}
this.setButtons(buttons)
return this
}
}
)