public void PrepareForInsertionMode()
 {
     Cut.Visibility  = Visibility.Collapsed;
     Copy.Visibility = Visibility.Collapsed;
     RightToLeftReadingOrder.Visibility = !string.IsNullOrEmpty(_textEditor.GetText()) ? Visibility.Visible : Visibility.Collapsed;
     WebSearch.Visibility = Visibility.Collapsed;
     Share.Text           = _resourceLoader.GetString("TextEditor_ContextFlyout_ShareButtonDisplayText");
 }
Beispiel #2
0
        private async Task <TextEditorSessionDataV1> BuildTextEditorSessionData(ITextEditor textEditor)
        {
            TextEditorSessionDataV1 textEditorData = new TextEditorSessionDataV1
            {
                Id = textEditor.Id,
            };

            if (textEditor.EditingFile != null)
            {
                // Add the opened file to FutureAccessList so we can access it next launch
                var futureAccessToken = ToToken(textEditor.Id);
                await FileSystemUtility.TryAddOrReplaceTokenInFutureAccessList(futureAccessToken, textEditor.EditingFile);

                textEditorData.EditingFileFutureAccessToken = futureAccessToken;
                textEditorData.EditingFileName = textEditor.EditingFileName;
                textEditorData.EditingFilePath = textEditor.EditingFilePath;
            }

            if (textEditor.IsModified)
            {
                if (textEditor.EditingFile != null)
                {
                    // Persist the last save known to the app, which might not be up-to-date (if the file was modified outside the app)
                    var lastSavedBackupFile = await SessionUtility.CreateNewFileInBackupFolderAsync(
                        ToToken(textEditor.Id) + "-LastSaved",
                        CreationCollisionOption.ReplaceExisting,
                        _backupFolderName);

                    if (!await BackupTextAsync(textEditor.LastSavedSnapshot.Content,
                                               textEditor.LastSavedSnapshot.Encoding,
                                               textEditor.LastSavedSnapshot.LineEnding,
                                               lastSavedBackupFile))
                    {
                        return(null); // Error: Failed to write backup text to file
                    }

                    textEditorData.LastSavedBackupFilePath = lastSavedBackupFile.Path;
                }

                if (textEditor.EditingFile == null ||
                    !string.Equals(textEditor.LastSavedSnapshot.Content, textEditor.GetText()))
                {
                    // Persist pending changes relative to the last save
                    var pendingBackupFile = await SessionUtility.CreateNewFileInBackupFolderAsync(
                        ToToken(textEditor.Id) + "-Pending",
                        CreationCollisionOption.ReplaceExisting,
                        _backupFolderName);

                    if (!await BackupTextAsync(textEditor.GetText(),
                                               textEditor.LastSavedSnapshot.Encoding,
                                               textEditor.LastSavedSnapshot.LineEnding,
                                               pendingBackupFile))
                    {
                        return(null); // Error: Failed to write backup text to file
                    }

                    textEditorData.PendingBackupFilePath = pendingBackupFile.Path;
                }
            }

            textEditorData.StateMetaData = textEditor.GetTextEditorStateMetaData();

            return(textEditorData);
        }