-
Notifications
You must be signed in to change notification settings - Fork 15
/
layout_selector.rb
172 lines (149 loc) · 4.72 KB
/
layout_selector.rb
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Copyright (c) [2018] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require "yast"
require "ui/dialog"
require_relative "../keyboard_layout_loader"
require_relative "../keyboard_layout"
Yast.import "GetInstArgs"
Yast.import "Mode"
Yast.import "Popup"
Yast.import "Stage"
Yast.import "UI"
Yast.import "Wizard"
module Y2Keyboard
module Dialogs
# Main dialog where the layouts are listed and can be selected.
class LayoutSelector < UI::Dialog
def initialize
textdomain "country"
@keyboard_layouts = KeyboardLayout.all
@keyboard_layouts.sort! { |a, b| Yast.strcoll(a.description, b.description) }
@previous_selected_layout = KeyboardLayout.current_layout
end
# First boot using Wizard, so we need here in firstboot set
# wizard content instead of opening dialog. bsc#1183162
def create_dialog
return super unless Yast::Stage.firstboot
args = Yast::GetInstArgs.argmap
Yast::Wizard.SetContents(heading, dialog_content, help_text,
args.fetch("enable_back", true), args.fetch("enable_next", true))
# SetContents always return nil, so return always true here
true
end
# First boot using Wizard, so do not close anything. bsc#1183162
def close_dialog
return super unless Yast::Stage.firstboot
true
end
def dialog_options
Opt(:decorated, :defaultsize)
end
def dialog_content
VBox(
HBox(
HWeight(20, HStretch()),
HWeight(50, layout_selection_box),
HWeight(20, HStretch())
),
Yast::Stage.firstboot ? Empty() : footer
)
end
def heading
_("System Keyboard Configuration")
end
def layout_selection_box
VBox(
Yast::Stage.firstboot ? Empty() : Left(Heading(heading)),
SelectionBox(
Id(:layout_list),
Opt(:notify),
_("&Keyboard Layout"),
map_layout_items
),
Yast::Mode.config ? HBox() : InputField(Opt(:hstretch), _("&Test"))
)
end
def map_layout_items
@keyboard_layouts.map do |layout|
Item(
Id(layout.code),
layout.description,
layout.code == @previous_selected_layout.code
)
end
end
def accept_handler
selected_layout.apply_layout
finish_dialog(:accept)
end
def next_handler
selected_layout.apply_layout
finish_dialog(:next)
end
def back_handler
finish_dialog(:back)
end
def cancel_handler
if !Yast::Mode.config # not in AY configuration module
KeyboardLayoutLoader.load_layout(@previous_selected_layout)
end
finish_dialog(:abort)
end
def abort_handler
cancel_handler if Yast::Popup.ConfirmAbort(:painless)
end
def layout_list_handler
if !Yast::Mode.config # not in AY configuration module
KeyboardLayoutLoader.load_layout(selected_layout)
end
end
def selected_layout
selected = Yast::UI.QueryWidget(:layout_list, :CurrentItem)
@keyboard_layouts.find { |x| x.code == selected }
end
def help_handler
Yast::Popup.LongText(
_("Help"),
RichText(help_text),
40,
20
)
end
# Text to display when the help button is pressed
#
# @return [String]
def help_text
# TRANSLATORS: help text
_("\n<p><big><b>Keyboard Configuration</b></big></p>" \
"<p>\nChoose the <b>Keyboard Layout</b> to use for " \
"installation and in the installed system.<br>" \
"Test the layout in <b>Test</b>.</p>")
end
def footer
HBox(
HSpacing(),
Left(PushButton(Id(:help), Opt(:key_F1, :help), Yast::Label.HelpButton)),
PushButton(Id(:cancel), Yast::Label.CancelButton),
PushButton(Id(:accept), Yast::Label.AcceptButton),
HSpacing()
)
end
end
end
end