public async Task <bool> OpenFile(StorageFile file) { try { var openedEditor = NotepadsCore.GetTextEditor(file); if (openedEditor != null) { NotepadsCore.SwitchTo(openedEditor); NotificationCenter.Instance.PostNotification( _resourceLoader.GetString("TextEditor_NotificationMsg_FileAlreadyOpened"), 2500); return(false); } var editor = await NotepadsCore.CreateTextEditor(Guid.NewGuid(), file); NotepadsCore.OpenTextEditor(editor); NotepadsCore.FocusOnSelectedTextEditor(); return(true); } catch (Exception ex) { var fileOpenErrorDialog = NotepadsDialogFactory.GetFileOpenErrorDialog(file.Path, ex.Message); await DialogManager.OpenDialogAsync(fileOpenErrorDialog, awaitPreviousDialog : false); if (!fileOpenErrorDialog.IsAborted) { NotepadsCore.FocusOnSelectedTextEditor(); } return(false); } }
public async Task <bool> OpenFile(StorageFile file, bool rebuildOpenRecentItems = true) { try { if (file == null) { return(false); } var openedEditor = NotepadsCore.GetTextEditor(file); if (openedEditor != null) { NotepadsCore.SwitchTo(openedEditor); NotificationCenter.Instance.PostNotification( _resourceLoader.GetString("TextEditor_NotificationMsg_FileAlreadyOpened"), 2500); return(false); } var editor = await NotepadsCore.CreateTextEditor(Guid.NewGuid(), file); NotepadsCore.OpenTextEditor(editor); NotepadsCore.FocusOnSelectedTextEditor(); var success = MRUService.TryAdd(file); // Remember recently used files if (success && rebuildOpenRecentItems) { await BuildOpenRecentButtonSubItems(); } TrackFileExtensionIfNotSupported(file); return(true); } catch (Exception ex) { var fileOpenErrorDialog = new FileOpenErrorDialog(file.Path, ex.Message); await DialogManager.OpenDialogAsync(fileOpenErrorDialog, awaitPreviousDialog : false); if (!fileOpenErrorDialog.IsAborted) { NotepadsCore.FocusOnSelectedTextEditor(); } return(false); } }