private async Task OpenNewFiles() { IReadOnlyList <StorageFile> files; try { files = await FilePickerFactory.GetFileOpenPicker().PickMultipleFilesAsync(); } catch (Exception ex) { var fileOpenErrorDialog = new FileOpenErrorDialog(filePath: null, ex.Message); await DialogManager.OpenDialogAsync(fileOpenErrorDialog, awaitPreviousDialog : false); if (!fileOpenErrorDialog.IsAborted) { NotepadsCore.FocusOnSelectedTextEditor(); } return; } if (files == null || files.Count == 0) { NotepadsCore.FocusOnSelectedTextEditor(); return; } foreach (var file in files) { await OpenFile(file); } }
private async Task <StorageFile> OpenFileUsingFileSavePicker(ITextEditor textEditor) { NotepadsCore.SwitchTo(textEditor); StorageFile file = await FilePickerFactory.GetFileSavePicker(textEditor).PickSaveFileAsync(); NotepadsCore.FocusOnTextEditor(textEditor); return(file); }
private async void OpenFileButton_Click(object sender, RoutedEventArgs e) { var file = await FilePickerFactory.GetFileOpenPicker().PickSingleFileAsync(); if (file == null) { return; } await OpenFile(file); }
private async Task <bool> Save(ITextEditor textEditor, bool saveAs, bool ignoreUnmodifiedDocument = false, bool rebuildOpenRecentItems = true) { if (textEditor == null) { return(false); } if (ignoreUnmodifiedDocument && !textEditor.IsModified) { return(true); } StorageFile file = null; try { if (textEditor.EditingFile == null || saveAs || FileSystemUtility.IsFileReadOnly(textEditor.EditingFile) || !await FileSystemUtility.FileIsWritable(textEditor.EditingFile)) { NotepadsCore.SwitchTo(textEditor); file = await FilePickerFactory.GetFileSavePicker(textEditor, saveAs).PickSaveFileAsync(); NotepadsCore.FocusOnTextEditor(textEditor); if (file == null) { return(false); // User cancelled } } else { file = textEditor.EditingFile; } await NotepadsCore.SaveContentToFileAndUpdateEditorState(textEditor, file); var success = MRUService.TryAdd(file); // Remember recently used files if (success && rebuildOpenRecentItems) { await BuildOpenRecentButtonSubItems(); } return(true); } catch (Exception ex) { var fileSaveErrorDialog = NotepadsDialogFactory.GetFileSaveErrorDialog((file == null) ? string.Empty : file.Path, ex.Message); await DialogManager.OpenDialogAsync(fileSaveErrorDialog, awaitPreviousDialog : false); if (!fileSaveErrorDialog.IsAborted) { NotepadsCore.FocusOnSelectedTextEditor(); } return(false); } }
private async Task <bool> Save(ITextEditor textEditor, bool saveAs, bool ignoreUnmodifiedDocument = false) { if (textEditor == null) { return(false); } if (ignoreUnmodifiedDocument && !textEditor.IsModified) { return(true); } StorageFile file = null; try { if (textEditor.EditingFile == null || saveAs || FileSystemUtility.IsFileReadOnly(textEditor.EditingFile) || !await FileSystemUtility.FileIsWritable(textEditor.EditingFile)) { NotepadsCore.SwitchTo(textEditor); file = await FilePickerFactory.GetFileSavePicker(textEditor, saveAs) .PickSaveFileAsync(); NotepadsCore.FocusOnTextEditor(textEditor); if (file == null) { return(false); // User cancelled } } else { file = textEditor.EditingFile; } await NotepadsCore.SaveContentToFileAndUpdateEditorState(textEditor, file); return(true); } catch (Exception ex) { var fileSaveErrorDialog = ContentDialogFactory.GetFileSaveErrorDialog((file == null) ? string.Empty : file.Path, ex.Message); await ContentDialogMaker.CreateContentDialogAsync(fileSaveErrorDialog, awaitPreviousDialog : false); NotepadsCore.FocusOnSelectedTextEditor(); return(false); } }
private async void OpenFileButton_Click(object sender, RoutedEventArgs e) { var files = await FilePickerFactory.GetFileOpenPicker().PickMultipleFilesAsync(); if (files == null || files.Count == 0) { FocusOnSelectedTextEditor(); return; } foreach (var file in files) { await OpenFile(file); } }
private async Task OpenNewFiles() { IReadOnlyList <StorageFile> files; try { var fileOpenPicker = FilePickerFactory.GetFileOpenPicker(); foreach (var type in new List <string>() { ".txt", ".md", ".markdown", ".cfg", ".config", ".cnf", ".conf", ".ini", ".log", ".json", ".yml", ".yaml", ".xml", ".xaml", ".html", ".htm", ".asp", ".aspx", ".jsp", ".jspx", ".css", ".scss", ".ps1", ".bat", ".cmd", ".vbs", ".sh", ".bashrc", ".rc", ".bash", ".c", ".cmake", ".h", ".hpp", ".cpp", ".cc", ".cs", ".m", ".mm", ".php", ".py", ".rb", ".vb", ".java", ".js", ".ts", ".lua", ".csv", }) { fileOpenPicker.FileTypeFilter.Add(type); } files = await fileOpenPicker.PickMultipleFilesAsync(); } catch (Exception ex) { var fileOpenErrorDialog = NotepadsDialogFactory.GetFileOpenErrorDialog(filePath: null, ex.Message); await DialogManager.OpenDialogAsync(fileOpenErrorDialog, awaitPreviousDialog : false); if (!fileOpenErrorDialog.IsAborted) { NotepadsCore.FocusOnSelectedTextEditor(); } return; } if (files == null || files.Count == 0) { NotepadsCore.FocusOnSelectedTextEditor(); return; } foreach (var file in files) { await OpenFile(file); } }
private async void SaveButton_Click(object sender, RoutedEventArgs e) { if (!(sender is TextEditor textEditor)) { textEditor = (Sets.SelectedItem as SetsViewItem)?.Content as TextEditor; if (textEditor == null) { return; } } StorageFile file; if (textEditor.EditingFile == null || e is SaveAsEventArgs || FileSystemUtility.IsFileReadOnly(textEditor.EditingFile) || !await FileSystemUtility.FileIsWritable(textEditor.EditingFile)) { file = await FilePickerFactory.GetFileSavePicker(e, textEditor, DefaultFileName).PickSaveFileAsync(); textEditor.Focus(FocusState.Programmatic); } else { file = textEditor.EditingFile; } if (file == null) { return; } var success = await textEditor.SaveFile(file); if (success) { if (Sets.Items != null) { foreach (SetsViewItem setsItem in Sets.Items) { if (setsItem.Content != textEditor) { continue; } setsItem.Header = file.Name; setsItem.Icon.Visibility = Visibility.Collapsed; PathIndicator.Text = textEditor.EditingFile.Path; LineEndingIndicator.Text = LineEndingUtility.GetLineEndingDisplayText(textEditor.LineEnding); EncodingIndicator.Text = textEditor.Encoding.EncodingName; break; } } ShowNotificationMessage("Saved", 2000); } else { await ContentDialogFactory.GetFileSaveErrorDialog(file).ShowAsync(); } }