2
* CustomMessageDialog.vala
4
* Copyright 2016 Tony George <teejeetech@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29
using TeeJee.FileSystem;
30
using TeeJee.JsonHelper;
31
using TeeJee.ProcessHelper;
32
using TeeJee.GtkHelper;
36
public class CustomMessageDialog : Gtk.Dialog {
37
private Gtk.Box vbox_main;
38
private Gtk.Label lbl_msg;
39
private Gtk.ScrolledWindow sw_msg;
40
private Gtk.Button btn_ok;
41
private Gtk.Button btn_cancel;
42
private Gtk.Button btn_yes;
43
private Gtk.Button btn_no;
45
private string msg_title;
46
private string msg_body;
47
private Gtk.MessageType msg_type;
48
private Gtk.ButtonsType buttons_type;
50
public CustomMessageDialog(
51
string _msg_title, string _msg_body,
52
Gtk.MessageType _msg_type, Window? parent, Gtk.ButtonsType _buttons_type) {
54
set_transient_for(parent);
57
msg_title = _msg_title;
60
buttons_type = _buttons_type;
66
if (lbl_msg.get_allocated_height() > 400){
67
sw_msg.vscrollbar_policy = PolicyType.AUTOMATIC;
68
sw_msg.set_size_request(-1,400);
69
lbl_msg.margin_right = 25;
72
sw_msg.vscrollbar_policy = PolicyType.NEVER;
76
public void init_window () {
79
window_position = WindowPosition.CENTER_ON_PARENT;
80
icon = get_app_icon(16);
83
skip_taskbar_hint = true;
84
skip_pager_hint = true;
87
vbox_main = get_content_area () as Gtk.Box;
91
var hbox_contents = new Box (Orientation.HORIZONTAL, 6);
92
hbox_contents.margin = 6;
93
vbox_main.add (hbox_contents);
95
string icon_name = "gtk-dialog-info";
98
case Gtk.MessageType.INFO:
99
icon_name = "gtk-dialog-info";
101
case Gtk.MessageType.WARNING:
102
icon_name = "gtk-dialog-warning";
104
case Gtk.MessageType.QUESTION:
105
icon_name = "gtk-dialog-question";
107
case Gtk.MessageType.ERROR:
108
icon_name = "gtk-dialog-error";
112
// image ----------------
114
var img = new Image.from_icon_name(icon_name, Gtk.IconSize.DIALOG);
115
img.margin_right = 12;
116
hbox_contents.add(img);
118
// label -------------------
120
var text = "<span weight=\"bold\" size=\"x-large\">%s</span>\n\n%s".printf(
121
escape_html(msg_title),
122
escape_html(msg_body));
123
lbl_msg = new Gtk.Label(text);
124
lbl_msg.xalign = (float) 0.0;
125
lbl_msg.max_width_chars = 70;
127
lbl_msg.wrap_mode = Pango.WrapMode.WORD_CHAR;
128
lbl_msg.use_markup = true;
131
sw_msg = new ScrolledWindow(null, null);
132
//sw_msg.set_shadow_type (ShadowType.ETCHED_IN);
133
sw_msg.add (lbl_msg);
134
sw_msg.expand = true;
135
sw_msg.hscrollbar_policy = PolicyType.NEVER;
136
sw_msg.vscrollbar_policy = PolicyType.AUTOMATIC;
137
//sw_msg.set_size_request();
138
hbox_contents.add(sw_msg);
140
// actions -------------------------
142
var action_area = get_action_area () as Gtk.Box;
143
action_area.margin_top = 12;
145
switch(buttons_type){
146
case Gtk.ButtonsType.OK:
147
btn_ok = (Gtk.Button) add_button ("_Ok", Gtk.ResponseType.OK);
149
case Gtk.ButtonsType.OK_CANCEL:
150
btn_ok = (Gtk.Button) add_button ("_Ok", Gtk.ResponseType.OK);
151
btn_cancel = (Gtk.Button) add_button ("_Cancel", Gtk.ResponseType.CANCEL);
153
case Gtk.ButtonsType.YES_NO:
154
btn_yes = (Gtk.Button) add_button ("_Yes", Gtk.ResponseType.YES);
155
btn_no = (Gtk.Button) add_button ("_No", Gtk.ResponseType.NO);