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
173
174
|
# File '../../src/include/sudo/dialog-cmnd.rb', line 30
def AddEditCmndAliasDialog(what)
caption = ""
ca = Sudo.GetCmndAliases2
it = Ops.get(ca, Sudo.GetItem, {})
alias_members = []
name = ""
items = []
if what == "Add"
caption = _("New Command Alias")
elsif what == "Edit"
alias_members = Ops.get_list(it, "mem", [])
name = Ops.get_string(it, "name", "")
caption = _("Existing Command Alias")
end
contents = VBox(
Left(InputField(Id("cmnd_alias_name"), _("Alias Name (in CAPITALS)"))),
Left(Label(_("Command Names or Directories in the Alias"))),
Table(
Id("cmnd_alias_members"),
Header(_("Command"), _("Parameters")),
[]
),
Left(
HBox(
PushButton(
Id("add_command"),
Opt(:key_F3),
Ops.add(Ops.add(" ", Label.AddButton), " ")
),
PushButton(
Id("edit_command"),
Opt(:key_F4),
Ops.add(Ops.add(" ", Label.EditButton), " ")
),
PushButton(
Id("remove_command"),
Opt(:key_F5),
Ops.add(Ops.add(" ", Label.DeleteButton), " ")
)
)
)
)
Wizard.SetContentsButtons(
caption,
contents,
Ops.get_string(@HELPS, "command_alias", ""),
Label.CancelButton,
Label.OKButton
)
Wizard.HideAbortButton
UI.ChangeWidget(
Id("cmnd_alias_name"),
:ValidChars,
"_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
RedrawCmndAlias(name, alias_members)
ret = nil
while true
ret = UI.UserInput
if ret == :next
new_alias = Builtins.toupper(
Convert.to_string(UI.QueryWidget(Id("cmnd_alias_name"), :Value))
)
if new_alias == ""
Popup.Error(_("Alias name must not be empty."))
UI.SetFocus(Id("cmnd_alias_name"))
next
end
if name != new_alias
if Sudo.SearchAlias2(new_alias, Sudo.GetCmndAliases2)
Popup.Error(
Builtins.sformat(
_("Alias with name %1 already exists"),
new_alias
)
)
UI.SetFocus(Id("cmnd_alias_name"))
next
end
end
if alias_members == []
Popup.Error(_("Alias must have at least one member."))
UI.SetFocus(Id("cmnd_alias_members"))
next
end
Ops.set(it, "name", new_alias)
Ops.set(it, "mem", alias_members)
Sudo.SetCmndAlias(Sudo.GetItem, it)
Sudo.SetModified
break
elsif ret == :back
break
elsif ret == "add_command"
new_member = AddCommandDialog("", "")
if new_member != "" && !Builtins.contains(alias_members, new_member)
alias_members = Builtins.add(alias_members, new_member)
RedrawCmndAlias("", alias_members)
end
elsif ret == "edit_command"
current_item = Convert.to_integer(
UI.QueryWidget(Id("cmnd_alias_members"), :CurrentItem)
)
it2 = Convert.to_term(
UI.QueryWidget(Id("cmnd_alias_members"), term(:Item, current_item))
)
new_member = AddCommandDialog(
Ops.get_string(it2, 1, ""),
Ops.get_string(it2, 2, "")
)
Ops.set(alias_members, current_item, new_member)
RedrawCmndAlias("", alias_members)
elsif ret == "remove_command"
current_item = Convert.to_integer(
UI.QueryWidget(Id("cmnd_alias_members"), :CurrentItem)
)
alias_members = Builtins.remove(alias_members, current_item)
RedrawCmndAlias("", alias_members)
else
Builtins.y2error("unexpected retcode: %1", ret)
next
end
end
@initial_screen = "cmnd_aliases"
Wizard.RestoreNextButton
deep_copy(ret)
end
|