| 123 | } |
| 124 | |
| 125 | pub fn toggle_bulk_mode(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 126 | if self.bulk_mode { |
| 127 | let text = self |
| 128 | .bulk_editor |
| 129 | .as_ref() |
| 130 | .map(|editor| editor.read(cx).text().to_string()) |
| 131 | .unwrap_or_default(); |
| 132 | self.replace_from_bulk_entries(parse_bulk_kv(&text), window, cx); |
| 133 | self.bulk_mode = false; |
| 134 | } else { |
| 135 | let text = serialize_bulk_kv(&self.rows_as_bulk_entries(cx)); |
| 136 | self.ensure_bulk_editor(window, cx); |
| 137 | if let Some(ref editor) = self.bulk_editor { |
| 138 | editor.update(cx, |state, cx| { |
| 139 | state.set_value(text, window, cx); |
| 140 | }); |
| 141 | } |
| 142 | self.bulk_mode = true; |
| 143 | } |
| 144 | cx.notify(); |
| 145 | } |
| 146 | |
| 147 | pub fn add_row(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 148 | let completion_engine = self.completion_engine.clone(); |
| 149 | let key_input = cx.new(|cx| { |
| 150 | configure_completion( |
| 151 | InputState::new(window, cx).placeholder("Key"), |
| 152 | completion_engine.as_ref(), |
| 153 | CompletionContext::FormName, |
| 154 | ) |
| 155 | }); |
| 156 | let completion_engine = self.completion_engine.clone(); |
| 157 | let value_input = cx.new(|cx| { |
| 158 | configure_completion( |
| 159 | InputState::new(window, cx).placeholder("Value"), |
| 160 | completion_engine.as_ref(), |
| 161 | CompletionContext::FormValue, |
| 162 | ) |
| 163 | }); |
| 164 | |
| 165 | self.rows.push(FormDataRow { |
| 166 | key_input, |
| 167 | value_input, |