示例#1
0
        /// <summary>
        /// Tries to open and load a source code file
        /// </summary>
        /// <param name="favorite">Whether to immediately mark the item as favorite</param>
        private async Task TryLoadTextFromFileAsync(bool favorite)
        {
            AnalyticsService.Log(EventNames.PickFileRequest);

            if (!(await FilesService.TryPickOpenFileAsync(".bfs") is IFile file))
            {
                return;
            }

            if (FilesManagerService.TrySwitchTo(file))
            {
                AnalyticsService.Log(EventNames.SwitchToFile);

                return;
            }

            AnalyticsService.Log(EventNames.LoadPickedFile, (nameof(CodeMetadata.IsFavorited), favorite.ToString()));

            if (await SourceCode.TryLoadFromEditableFileAsync(file) is SourceCode code)
            {
                // Set the favorite state, if requested
                if (favorite)
                {
                    code.Metadata.IsFavorited = true;

                    await code.TrySaveAsync();
                }

                Code = code;

                _ = FilesHistoryService.LogOrUpdateActivityAsync(code.File !);

                CodeLoaded?.Invoke(this, Code.Content);
            }
        }
示例#2
0
        /// <summary>
        /// Loads an empty source code
        /// </summary>
        private void LoadNewFile()
        {
            Code = SourceCode.CreateEmpty();

            _ = FilesHistoryService.DismissCurrentActivityAsync();

            CodeLoaded?.Invoke(this, Code.Content);
        }
示例#3
0
        /// <summary>
        /// Tries to open and load a source code file
        /// </summary>
        /// <param name="file">The file to open</param>
        private async Task TryLoadTextFromFileAsync(IFile file)
        {
            if (await SourceCode.TryLoadFromEditableFileAsync(file) is SourceCode code)
            {
                Code = code;

                _ = FilesHistoryService.LogOrUpdateActivityAsync(code.File !);

                CodeLoaded?.Invoke(this, Code.Content);
            }
        }
示例#4
0
        /// <summary>
        /// Loads a specific <see cref="SourceCode"/> instance
        /// </summary>
        /// <param name="code">The source code to load</param>
        private void LoadSourceCode(SourceCode code)
        {
            AnalyticsService.Log(EventNames.LoadLibrarySourceCode);

            if (!(code.File is null) &&
                FilesManagerService.TrySwitchTo(code.File))
            {
                AnalyticsService.Log(EventNames.SwitchToFile);

                return;
            }

            Code = code;

            if (!(code.File is null))
            {
                _ = FilesHistoryService.LogOrUpdateActivityAsync(code.File);
            }

            CodeLoaded?.Invoke(this, Code.Content);
        }