chooser: refuse to edit a session of an unregistered kind
This commit is contained in:
1 parent
14f1421b2b
commit
79c33b25c5
1 file changed
+15
-1
+15
-1
@@ -470,7 +470,7 @@ void form_rebuild(Chooser& c, SourceKind& kind, const SourceConfig& initial) {
|
|||||||
c.form_cfg.description.empty() ? nullptr : c.form_cfg.description.c_str());
|
c.form_cfg.description.empty() ? nullptr : c.form_cfg.description.c_str());
|
||||||
c.form_cfg.write(initial);
|
c.form_cfg.write(initial);
|
||||||
c.form_cfg.on_change([&c] {
|
c.form_cfg.on_change([&c] {
|
||||||
if (c.form_connect != nullptr) {
|
if (c.form_connect != nullptr && c.form_cfg.valid) {
|
||||||
gtk_widget_set_sensitive(c.form_connect, c.form_cfg.valid() ? TRUE : FALSE);
|
gtk_widget_set_sensitive(c.form_connect, c.form_cfg.valid() ? TRUE : FALSE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -570,6 +570,18 @@ void open_form(Chooser& c, int edit_index = -1) {
|
|||||||
edit_index >= 0 && static_cast<std::size_t>(edit_index) < c.known.size()
|
edit_index >= 0 && static_cast<std::size_t>(edit_index) < c.known.size()
|
||||||
? &c.known[static_cast<std::size_t>(edit_index)]
|
? &c.known[static_cast<std::size_t>(edit_index)]
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
// An edit of a session whose kind is not registered is refused: the form would rebuild as the first
|
||||||
|
// kind, and Save would rewrite the file as that kind and delete the original.
|
||||||
|
if (src != nullptr && !src->kind.empty()) {
|
||||||
|
bool known_kind = false;
|
||||||
|
for (SourceKind* k : kinds()) known_kind = known_kind || k->id() == src->kind;
|
||||||
|
if (!known_kind) {
|
||||||
|
std::fprintf(stderr, "[sources] cannot edit %s: source kind '%s' is not registered\n",
|
||||||
|
src->config.c_str(), src->kind.c_str());
|
||||||
|
std::fflush(stderr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
c.edit_host = src != nullptr ? src->host : std::string();
|
c.edit_host = src != nullptr ? src->host : std::string();
|
||||||
c.edit_port = src != nullptr ? src->port : 0;
|
c.edit_port = src != nullptr ? src->port : 0;
|
||||||
c.edit_config = src != nullptr ? src->config : std::string();
|
c.edit_config = src != nullptr ? src->config : std::string();
|
||||||
@@ -668,6 +680,8 @@ void open_form(Chooser& c, int edit_index = -1) {
|
|||||||
ch.form_cfg_rows.clear();
|
ch.form_cfg_rows.clear();
|
||||||
ch.form_kind_row = nullptr;
|
ch.form_kind_row = nullptr;
|
||||||
ch.form_source_group = nullptr;
|
ch.form_source_group = nullptr;
|
||||||
|
ch.form_connect = nullptr;
|
||||||
|
ch.form_kinds.clear();
|
||||||
}),
|
}),
|
||||||
&c);
|
&c);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user