Пример #1
0
        private void InitializeTabControls()
        {
            _applicationState.Initializing = true;
            if (!_logicManager.HasExistingDatabase)
            {
                _applicationState.DatabaseLoaded = false;
                _applicationState.DatabaseExists = false;
            }
            else
            {
                _applicationState.DatabaseExists = true;
            }

            // Dispose current Tab controls
            foreach (TabPage tabPage in tabControlNotepad.TabPages)
            {
                foreach (Control tabPageControl in tabPage.Controls)
                {
                    tabPageControl.Dispose();
                }
                tabPage.Dispose();
            }

            tabControlNotepad.TabPages.Clear();


            for (int index = 0; index < _logicManager.PageCount; index++)
            {
                var tabPageControl = new MemoTabPageControl("MemoTabPageControl", index)
                {
                    Dock = DockStyle.Fill
                };
                var tabPage = new TabPage(_logicManager.GetTabPageLabel(index));
                tabPageControl.TabTextDataChanged += tabPageControl_TabTextDataChanged;

                tabPage.Controls.Add(tabPageControl);

                if (ControlHelper.GetChildControlByName(tabPageControl, tabPageControl.TabPageControlTextboxName) is RichTextBox richTextBox)
                {
                    SecureMemoFontSettings fontSettings = _appSettingsService.Settings.FontSettings;
                    richTextBox.Font              = new Font(fontSettings.FontFamily, fontSettings.FontSize, fontSettings.Style);
                    richTextBox.Text              = _logicManager.GetTabPageText(index);
                    richTextBox.ContextMenuStrip  = contextMenuTextArea;
                    richTextBox.SelectionChanged += RichTextBox_SelectionChanged;
                }

                tabControlNotepad.TabPages.Add(tabPage);
            }

            tabControlNotepad.SelectedIndex       = _logicManager.ActivePageIndex;
            _applicationState.Initializing        = false;
            _applicationState.FontSettingsChanged = false;
            UpdateApplicationState();
        }
Пример #2
0
        public static SecureMemoAppSettings GetDefaultSettings()
        {
            var appSettings = new SecureMemoAppSettings {
                AlwaysOntop = ALLWAYS_ONTOP, ApplicationSaltValue = CreateApplicationSalt(), DefaultEmptyTabPages = EMPTY_TAB_PAGES
            };
            var fontSettings = new SecureMemoFontSettings {
                FontFamily = new FontFamily("Courier New"), FontSize = 9.75f, Style = FontStyle.Regular
            };

            fontSettings.FontFamilyName       = fontSettings.FontFamily.GetName(0);
            appSettings.FontSettings          = fontSettings;
            appSettings.MainWindowHeight      = WIN_HEIGHT;
            appSettings.MainWindowWith        = WIN_WIDTH;
            appSettings.PasswordDerivedString = null;

            return(appSettings);
        }
Пример #3
0
        public static SecureMemoAppSettings GetDefaultSettings()
        {
            var appSettings = new SecureMemoAppSettings {
                AlwaysOnTop = AllwaysOnTop, ApplicationSaltValue = CreateApplicationSalt(), DefaultEmptyTabPages = EmptyTabPages
            };
            var fontSettings = new SecureMemoFontSettings {
                FontFamilyName = "Arial", FontSize = 12f, Style = FontStyle.Regular
            };

            fontSettings.FontFamilyName       = fontSettings.FontFamily.GetName(0);
            appSettings.FontSettings          = fontSettings;
            appSettings.MainWindowHeight      = WinHeight;
            appSettings.MainWindowWith        = WinWidth;
            appSettings.PasswordDerivedString = null;

            return(appSettings);
        }
Пример #4
0
        private void InitializeTabControls()
        {
            _applicationState.Initializing = true;
            if (!_memoStorageService.DatabaseExists())
            {
                _applicationState.DatabaseLoaded = false;
                _applicationState.DatabaseExists = false;
            }
            else
            {
                _applicationState.DatabaseExists = true;
            }

            // Create tab pages
            tabControlNotepad.TabPages.Clear();
            foreach (int tabPageIndex in _tabPageDataCollection.TabPageDictionary.Keys)
            {
                TabPageData tabPageData    = _tabPageDataCollection.TabPageDictionary[tabPageIndex];
                var         tabPageControl = new MemoTabPageControl("MemoTabPageControl", tabPageIndex)
                {
                    Dock = DockStyle.Fill
                };
                var tabPage = new TabPage(tabPageData.TabPageLabel);
                tabPageControl.TabTextDataChanged += tabPageControl_TabTextDataChanged;

                tabPage.Controls.Add(tabPageControl);
                var richTextBox = ControlHelper.GetChildControlByName(tabPageControl, tabPageControl.TabPageControlTextboxName) as RichTextBox;

                if (richTextBox != null)
                {
                    SecureMemoFontSettings fontSettings = _appSettingsService.Settings.FontSettings;
                    richTextBox.Font              = new Font(fontSettings.FontFamily, fontSettings.FontSize, fontSettings.Style);
                    richTextBox.Text              = tabPageData.TabPageText;
                    richTextBox.ContextMenuStrip  = contextMenuTextArea;
                    richTextBox.SelectionChanged += RichTextBox_SelectionChanged;
                }

                tabControlNotepad.TabPages.Add(tabPage);
            }

            tabControlNotepad.SelectedIndex = _tabPageDataCollection.ActiveTabIndex;
            _applicationState.Initializing  = false;
            UpdateApplicationState();
        }
        public void LoadSettings()
        {
            try
            {
                if (!File.Exists(_iniConfigFilePath))
                {
                    SaveSettings();
                    return;
                }

                if (!_iniConfigFileManager.LoadConfigFile(_iniConfigFilePath))
                {
                    throw new Exception("Unable to load application settings");
                }

                int winSize;
                int screenWidth  = Screen.PrimaryScreen.WorkingArea.Width;
                int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;

                IniConfigFileSection generalConfigFileSection = _iniConfigFileManager.ConfigurationData.ConfigSections["General"];
                Settings.DefaultEmptyTabPages  = int.Parse(generalConfigFileSection.ConfigItems["DefaultEmptyTabPages"]);
                Settings.ApplicationSaltValue  = generalConfigFileSection.ConfigItems["ApplicationSaltValue"];
                Settings.PasswordDerivedString = generalConfigFileSection.ConfigItems["PasswordDerivedString"];
                Settings.AlwaysOntop           = bool.Parse(generalConfigFileSection.ConfigItems["AlwaysOntop"]);

                if (int.TryParse(generalConfigFileSection.ConfigItems["MainWindowWith"], out winSize))
                {
                    Settings.MainWindowWith = winSize;
                }

                if (int.TryParse(generalConfigFileSection.ConfigItems["MainWindowHeight"], out winSize))
                {
                    Settings.MainWindowHeight = winSize;
                }

                if (Settings.MainWindowWith < _defaultAppSettings.MainWindowWith)
                {
                    Settings.MainWindowWith = _defaultAppSettings.MainWindowWith;
                }

                if (Settings.MainWindowWith > screenWidth)
                {
                    Settings.MainWindowWith = screenWidth;
                }

                if (Settings.MainWindowHeight < _defaultAppSettings.MainWindowHeight)
                {
                    Settings.MainWindowHeight = _defaultAppSettings.MainWindowHeight;
                }

                if (Settings.MainWindowHeight > screenHeight)
                {
                    Settings.MainWindowHeight = screenHeight;
                }

                if (Settings.ApplicationSaltValue == null || Settings.ApplicationSaltValue.Length != 1024)
                {
                    throw new Exception("ApplicationSaltValue Length must be 1024 characters");
                }

                // Shared Database folder
                bool useSharedSyncFolder = false;
                if (generalConfigFileSection.ConfigItems["UseSharedSyncFolder"] != null)
                {
                    bool.TryParse(generalConfigFileSection.ConfigItems["UseSharedSyncFolder"], out useSharedSyncFolder);
                }

                Settings.UseSharedSyncFolder = useSharedSyncFolder;
                Settings.SyncFolderPath      = generalConfigFileSection.ConfigItems["SyncFolderPath"];

                // Font settings
                IniConfigFileSection value;
                if (_iniConfigFileManager.ConfigurationData.ConfigSections.TryGetValue("FontSettings", out value))
                {
                    IniConfigFileSection fontConfigFileSection = value;
                    var fontSettings = new SecureMemoFontSettings
                    {
                        FontSize       = Convert.ToSingle(fontConfigFileSection.ConfigItems["FontSize"]),
                        FontFamilyName = fontConfigFileSection.ConfigItems["FontFamilyName"],
                        Style          = (FontStyle)Enum.Parse(typeof(FontStyle), fontConfigFileSection.ConfigItems["Style"])
                    };
                    fontSettings.FontFamily = new Font(fontConfigFileSection.ConfigItems["FontFamily"], fontSettings.FontSize, fontSettings.Style).FontFamily;

                    Settings.FontSettings = fontSettings;
                }
                else
                {
                    Settings.FontSettings = _defaultAppSettings.FontSettings;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to load application settings");
                throw;
            }
        }
Пример #6
0
 public FormSettings(AppSettingsService appSettingsService)
 {
     _fontSettings       = appSettingsService.Settings.FontSettings;
     _appSettingsService = appSettingsService;
     InitializeComponent();
 }