public bool TryPersist(OptionKey optionKey, object value) { if (!_supportedOptions.Contains(optionKey.Option)) { value = null; return(false); } if (!_languageMap.TryGetValue(optionKey.Language, out var languageServiceGuid)) { value = null; return(false); } var languagePreferences = new LANGPREFERENCES3[1]; languagePreferences[0].guidLang = languageServiceGuid.Item1; Marshal.ThrowExceptionForHR(_textManager.GetUserPreferences4(null, languagePreferences, null)); SetValueForOption(optionKey.Option, ref languagePreferences[0], value); SetUserPreferencesMaybeAsync(languagePreferences); // Even if we didn't call back, say we completed the persist return(true); }
public void RemoveTextContainer(SourceTextContainer textContainer) { if (textContainer == null) { throw new ArgumentNullException(nameof(textContainer)); } lock (_project._gate) { if (!_sourceTextContainersToDocumentIds.TryGetValue(textContainer, out var documentId)) { throw new ArgumentException($"{nameof(textContainer)} is not a text container added to this project."); } _sourceTextContainersToDocumentIds = _sourceTextContainersToDocumentIds.RemoveKey(textContainer); // if the TextContainer had a full path provided, remove it from the map. var entry = _documentPathsToDocumentIds.Where(kv => kv.Value == documentId).FirstOrDefault(); if (entry.Key != null) { _documentPathsToDocumentIds.Remove(entry.Key); } // There are two cases: // // 1. This file is actually been pushed to the workspace, and we need to remove it (either // as a part of the active batch or immediately) // 2. It hasn't been pushed yet, but is contained in _documentsAddedInBatch if (_project._workspace.CurrentSolution.GetDocument(documentId) != null) { if (_project._activeBatchScopes > 0) { _documentsRemovedInBatch.Add(documentId); } else { _project._workspace.ApplyChangeToWorkspace(w => { w.OnDocumentClosed(documentId, new SourceTextLoader(textContainer, filePath: null)); _documentRemoveAction(w, documentId); _project._workspace.RemoveDocumentToDocumentsNotFromFiles(documentId); }); } } else { for (int i = 0; i < _documentsAddedInBatch.Count; i++) { if (_documentsAddedInBatch[i].Id == documentId) { _documentsAddedInBatch.RemoveAt(i); break; } } } } }