Esempio n. 1
0
        public async Task<bool> SetEncodingAsync(Encoding encoding)
        {
            // re-interpret existing file with the specified encoding

            if (Path != null)
            {
                if (! await SavePendingChangesAsync())
                    return false;

                var text = await ReadTextAsync(Path, encoding);

                // since we re-interpret the text
                // the document would be "modified" whereas
                // it semantically contains the same text
                // 

                // setting IsEncodingChanging instructs
                // the view to ignore the modifications

                IsEncodingChanging = true;
                SetTextContent(text);
            }

            // store the current encoding for later use

            Encoding = encoding;

            // returns whether using this encoding
            // was successfull.

            return encoding.DecodedSuccessfully();
        }