Example #1
0
        private async System.Threading.Tasks.Task ActivateAsync(IActivatedEventArgs e)
        {
            if (!(Window.Current.Content is Frame rootFrame))
            {
                rootFrame = CreateRootFrame(e);
                Window.Current.Content = rootFrame;
            }

            ThemeSettingsService.Initialize();
            EditorSettingsService.Initialize();

            var appLaunchSettings = new Dictionary <string, string>()
            {
                {
                    "UseWindowsTheme", ThemeSettingsService.UseWindowsTheme.ToString()
                },
                {
                    "ThemeMode", ThemeSettingsService.ThemeMode.ToString()
                },
                {
                    "UseWindowsAccentColor", ThemeSettingsService.UseWindowsAccentColor.ToString()
                },
                {
                    "AppBackgroundTintOpacity", $"{(int) (ThemeSettingsService.AppBackgroundPanelTintOpacity * 100.0)}"
                },
                {
                    "ShowStatusBar", EditorSettingsService.ShowStatusBar.ToString()
                },
                {
                    "EditorDefaultLineEnding", EditorSettingsService.EditorDefaultLineEnding.ToString()
                },
                {
                    "EditorDefaultEncoding", EncodingUtility.GetEncodingName(EditorSettingsService.EditorDefaultEncoding)
                },
                {
                    "EditorDefaultTabIndents", EditorSettingsService.EditorDefaultTabIndents.ToString()
                },
                {
                    "EditorDefaultDecoding", EncodingUtility.GetEncodingName(EditorSettingsService.EditorDefaultDecoding)
                },
                {
                    "EditorFontFamily", EditorSettingsService.EditorFontFamily
                },
                {
                    "EditorFontSize", EditorSettingsService.EditorFontSize.ToString()
                },
                {
                    "IsSessionSnapshotEnabled", EditorSettingsService.IsSessionSnapshotEnabled.ToString()
                },
            };

            LoggingService.LogInfo($"AppLaunchSettings: {string.Join(";", appLaunchSettings.Select(x => x.Key + "=" + x.Value).ToArray())}");
            Analytics.TrackEvent("AppLaunch_Settings", appLaunchSettings);

            await ActivationService.ActivateAsync(rootFrame, e);

            Window.Current.Activate();
            ExtendAcrylicIntoTitleBar();
        }
 private void UpdateEncodingIndicator(Encoding encoding)
 {
     if (StatusBar == null)
     {
         return;
     }
     EncodingIndicator.Text = EncodingUtility.GetEncodingName(encoding);
 }
        private void AddEncodingItem(Encoding encoding, MenuFlyoutSubItem reopenWithEncoding, MenuFlyoutSubItem saveWithEncoding)
        {
            const int EncodingMenuFlyoutItemHeight   = 30;
            const int EncodingMenuFlyoutItemFontSize = 14;

            var reopenWithEncodingItem =
                new MenuFlyoutItem()
            {
                Text          = EncodingUtility.GetEncodingName(encoding),
                FlowDirection = FlowDirection.LeftToRight,
                Height        = EncodingMenuFlyoutItemHeight,
                FontSize      = EncodingMenuFlyoutItemFontSize
            };

            reopenWithEncodingItem.Click += async(sender, args) =>
            {
                var selectedTextEditor = NotepadsCore.GetSelectedTextEditor();
                if (selectedTextEditor != null)
                {
                    try
                    {
                        await selectedTextEditor.ReloadFromEditingFile(encoding);

                        NotificationCenter.Instance.PostNotification(
                            _resourceLoader.GetString("TextEditor_NotificationMsg_FileReloaded"), 1500);
                    }
                    catch (Exception ex)
                    {
                        var fileOpenErrorDialog = NotepadsDialogFactory.GetFileOpenErrorDialog(selectedTextEditor.EditingFilePath, ex.Message);
                        await DialogManager.OpenDialogAsync(fileOpenErrorDialog, awaitPreviousDialog : false);

                        if (!fileOpenErrorDialog.IsAborted)
                        {
                            NotepadsCore.FocusOnSelectedTextEditor();
                        }
                    }
                }
            };
            reopenWithEncoding.Items?.Add(reopenWithEncodingItem);

            var saveWithEncodingItem =
                new MenuFlyoutItem()
            {
                Text          = EncodingUtility.GetEncodingName(encoding),
                FlowDirection = FlowDirection.LeftToRight,
                Height        = EncodingMenuFlyoutItemHeight,
                FontSize      = EncodingMenuFlyoutItemFontSize
            };

            saveWithEncodingItem.Click += (sender, args) =>
            {
                NotepadsCore.GetSelectedTextEditor()?.TryChangeEncoding(encoding);
            };
            saveWithEncoding.Items?.Add(saveWithEncodingItem);
        }
Example #4
0
        private async System.Threading.Tasks.Task ActivateAsync(IActivatedEventArgs e)
        {
            bool rootFrameCreated = false;

            if (!(Window.Current.Content is Frame rootFrame))
            {
                rootFrame = CreateRootFrame(e);
                Window.Current.Content = rootFrame;
                rootFrameCreated       = true;

                ThemeSettingsService.Initialize();
                EditorSettingsService.Initialize();
            }

            var appLaunchSettings = new Dictionary <string, string>()
            {
                { "OSArchitecture", SystemInformation.OperatingSystemArchitecture.ToString() },
                { "UseWindowsTheme", ThemeSettingsService.UseWindowsTheme.ToString() },
                { "ThemeMode", ThemeSettingsService.ThemeMode.ToString() },
                { "UseWindowsAccentColor", ThemeSettingsService.UseWindowsAccentColor.ToString() },
                { "AppBackgroundTintOpacity", $"{(int) (ThemeSettingsService.AppBackgroundPanelTintOpacity * 100.0)}" },
                { "ShowStatusBar", EditorSettingsService.ShowStatusBar.ToString() },
                { "EditorDefaultLineEnding", EditorSettingsService.EditorDefaultLineEnding.ToString() },
                { "EditorDefaultEncoding", EncodingUtility.GetEncodingName(EditorSettingsService.EditorDefaultEncoding) },
                { "EditorDefaultTabIndents", EditorSettingsService.EditorDefaultTabIndents.ToString() },
                { "EditorDefaultDecoding", EditorSettingsService.EditorDefaultDecoding == null ? "Auto" : EncodingUtility.GetEncodingName(EditorSettingsService.EditorDefaultDecoding) },
                { "EditorFontFamily", EditorSettingsService.EditorFontFamily },
                { "EditorFontSize", EditorSettingsService.EditorFontSize.ToString() },
                { "IsSessionSnapshotEnabled", EditorSettingsService.IsSessionSnapshotEnabled.ToString() },
                { "IsShadowWindow", (!IsFirstInstance && !IsGameBarWidget).ToString() },
                { "IsGameBarWidget", IsGameBarWidget.ToString() },
                { "AlwaysOpenNewWindow", EditorSettingsService.AlwaysOpenNewWindow.ToString() },
                { "IsHighlightMisspelledWordsEnabled", EditorSettingsService.IsHighlightMisspelledWordsEnabled.ToString() },
                { "IsLineHighlighterEnabled", EditorSettingsService.IsLineHighlighterEnabled.ToString() },
                { "EditorDefaultSearchEngine", EditorSettingsService.EditorDefaultSearchEngine.ToString() }
            };

            LoggingService.LogInfo($"AppLaunchSettings: {string.Join(";", appLaunchSettings.Select(x => x.Key + "=" + x.Value).ToArray())}");
            Analytics.TrackEvent("AppLaunch_Settings", appLaunchSettings);

            try
            {
                await ActivationService.ActivateAsync(rootFrame, e);
            }
            catch (Exception ex)
            {
                throw new Exception("AppFailedToActivate", ex);
            }

            if (rootFrameCreated)
            {
                Window.Current.Activate();
                ExtendAcrylicIntoTitleBar();
            }
        }
Example #5
0
        private async Task ActivateAsync(IActivatedEventArgs e)
        {
            bool rootFrameCreated = false;

            if (!(Window.Current.Content is Frame rootFrame))
            {
                rootFrame = CreateRootFrame(e);
                Window.Current.Content = rootFrame;
                rootFrameCreated       = true;

                ThemeSettingsService.Initialize();
                AppSettingsService.Initialize();
            }

            var appLaunchSettings = new Dictionary <string, string>()
            {
                { "OSArchitecture", SystemInformation.OperatingSystemArchitecture.ToString() },
                { "OSVersion", $"{SystemInformation.OperatingSystemVersion.Major}.{SystemInformation.OperatingSystemVersion.Minor}.{SystemInformation.OperatingSystemVersion.Build}" },
                { "UseWindowsTheme", ThemeSettingsService.UseWindowsTheme.ToString() },
                { "ThemeMode", ThemeSettingsService.ThemeMode.ToString() },
                { "UseWindowsAccentColor", ThemeSettingsService.UseWindowsAccentColor.ToString() },
                { "AppBackgroundTintOpacity", $"{(int) (ThemeSettingsService.AppBackgroundPanelTintOpacity * 10.0) * 10}" },
                { "ShowStatusBar", AppSettingsService.ShowStatusBar.ToString() },
                { "IsSessionSnapshotEnabled", AppSettingsService.IsSessionSnapshotEnabled.ToString() },
                { "IsShadowWindow", (!IsPrimaryInstance && !IsGameBarWidget).ToString() },
                { "IsGameBarWidget", IsGameBarWidget.ToString() },
                { "AlwaysOpenNewWindow", AppSettingsService.AlwaysOpenNewWindow.ToString() },
                { "IsHighlightMisspelledWordsEnabled", AppSettingsService.IsHighlightMisspelledWordsEnabled.ToString() },
                { "IsSmartCopyEnabled", AppSettingsService.IsSmartCopyEnabled.ToString() }
            };

            LoggingService.LogInfo($"[{nameof(App)}] Launch settings: \n{string.Join("\n", appLaunchSettings.Select(x => x.Key + "=" + x.Value).ToArray())}.");
            Analytics.TrackEvent("AppLaunch_Settings", appLaunchSettings);

            var appLaunchEditorSettings = new Dictionary <string, string>()
            {
                { "EditorDefaultLineEnding", AppSettingsService.EditorDefaultLineEnding.ToString() },
                { "EditorDefaultEncoding", EncodingUtility.GetEncodingName(AppSettingsService.EditorDefaultEncoding) },
                { "EditorDefaultTabIndents", AppSettingsService.EditorDefaultTabIndents.ToString() },
                { "EditorDefaultDecoding", AppSettingsService.EditorDefaultDecoding == null ? "Auto" : EncodingUtility.GetEncodingName(AppSettingsService.EditorDefaultDecoding) },
                { "EditorFontFamily", AppSettingsService.EditorFontFamily },
                { "EditorFontSize", AppSettingsService.EditorFontSize.ToString() },
                { "EditorFontStyle", AppSettingsService.EditorFontStyle.ToString() },
                { "EditorFontWeight", AppSettingsService.EditorFontWeight.Weight.ToString() },
                { "EditorDefaultSearchEngine", AppSettingsService.EditorDefaultSearchEngine.ToString() },
                { "DisplayLineHighlighter", AppSettingsService.EditorDisplayLineHighlighter.ToString() },
                { "DisplayLineNumbers", AppSettingsService.EditorDisplayLineNumbers.ToString() },
            };

            LoggingService.LogInfo($"[{nameof(App)}] Editor settings: \n{string.Join("\n", appLaunchEditorSettings.Select(x => x.Key + "=" + x.Value).ToArray())}.");
            Analytics.TrackEvent("AppLaunch_Editor_Settings", appLaunchEditorSettings);

            try
            {
                await ActivationService.ActivateAsync(rootFrame, e);
            }
            catch (Exception ex)
            {
                var diagnosticInfo = new Dictionary <string, string>()
                {
                    { "Message", ex?.Message },
                    { "Exception", ex?.ToString() },
                };
                Analytics.TrackEvent("AppFailedToActivate", diagnosticInfo);
                Crashes.TrackError(ex, diagnosticInfo);
                throw;
            }

            if (rootFrameCreated)
            {
                ExtendViewIntoTitleBar();
                Window.Current.Activate();
            }
        }
Example #6
0
 public override void WriteJson(JsonWriter writer, Encoding value, JsonSerializer serializer)
 {
     writer.WriteValue(EncodingUtility.GetEncodingName(value));
 }