public void OnContentChanged(string[] blockIds) { if (_editor == null) { ResetWidgets(); return; } // The active block may have been removed then added again in which case // the old instance is invalid but can be restored by remapping the identifier if ((_activeBlock != null) && !_activeBlock.IsValid()) { _activeBlock = _editor.GetBlockById(_activeBlock.Id); if (_activeBlock == null) { ResetWidgets(); } } if (_activeBlock != null) { if (blockIds.Contains(_activeBlock.Id)) { _currentBlock = _activeBlock; BackupData(); UpdateData(); UpdateWidgets(UpdateCause.Edit); } } }
private void UpdateData() { if (_currentBlock == null) { _currentWords.Clear(); } else if (_currentBlock.IsValid()) { string jiixStr; try { var conf = _editor.Engine.CreateParameterSet(); conf.SetBoolean("export.jiix.strokes", false); jiixStr = _editor.Export_(_currentBlock, MimeType.JIIX, conf); } catch { // when processing is ongoing, export may fail : ignore return; } var words = new List <Word>(); var jiix = JsonValue.Parse(jiixStr) as JsonObject; var jiixWords = (JsonArray)jiix["words"]; foreach (var jiixWord_ in jiixWords) { var jiixWord = (JsonObject)jiixWord_; var label = (string)jiixWord["label"]; var candidates = new List <string>(); JsonValue jiixCandidates_; if (jiixWord.TryGetValue("candidates", out jiixCandidates_)) { var jiixCandidates = (JsonArray)jiixCandidates_; foreach (var jiixCandidate_ in jiixCandidates) { candidates.Add((string)jiixCandidate_); } } words.Add(new Word() { Label = label, Candidates = candidates, Updated = false }); } _currentWords = words; if ((_previousBlock != null) && (_currentBlock.Id == _previousBlock.Id)) { ComputeTextDifferences(_previousWords, _currentWords); } else { var count = _currentWords.Count; for (var c = 0; c < count; ++c) { var word = _currentWords[c]; word.Updated = false; _currentWords[c] = word; } } } }
private void UpdateData() { if (_currentBlock == null) { _currentWords.Clear(); } else if (_currentBlock.IsValid()) { string jiixStr; try { jiixStr = _editor.Export_(_currentBlock, MimeType.JIIX, _exportParams); } catch { // when processing is ongoing, export may fail : ignore return; } var words = new List <Word>(); var jiix = JsonValue.Parse(jiixStr) as JsonObject; var jiixWords = (JsonArray)jiix["words"]; foreach (var jiixWord_ in jiixWords) { var jiixWord = (JsonObject)jiixWord_; var label = (string)jiixWord["label"]; // in smart guide, we want everything on the same line, so we override the label with the reflow label if (jiixWord.ContainsKey("reflow-label")) { label = (string)jiixWord["reflow-label"]; } var candidates = new List <string>(); JsonValue jiixCandidates_; if (jiixWord.TryGetValue("candidates", out jiixCandidates_)) { var jiixCandidates = (JsonArray)jiixCandidates_; foreach (var jiixCandidate_ in jiixCandidates) { candidates.Add((string)jiixCandidate_); } } words.Add(new Word() { Label = label, Candidates = candidates, Updated = false }); } _currentWords = words; if ((_previousBlock != null) && (_currentBlock.Id == _previousBlock.Id)) { ComputeTextDifferences(_previousWords, _currentWords); } else { var count = _currentWords.Count; for (var c = 0; c < count; ++c) { var word = _currentWords[c]; word.Updated = false; _currentWords[c] = word; } } } }