コード例 #1
0
        public static KeyboardShortcuts_Settings GetDefaultKeyboardShortcuts_Settings()
        {
            KeyboardShortcuts_Settings settings = new KeyboardShortcuts_Settings();

            if (MenuNameDefaultShortcutDictionary != null && MenuNameDefaultShortcutDictionary.Count > 0)
            {
                settings.MenuNameDictionary = new Dictionary <string, KeyboardShortcut>();
                foreach (string name in MenuNameDefaultShortcutDictionary.Keys)
                {
                    settings.MenuNameDictionary.Add(name, MenuNameDefaultShortcutDictionary[name].Copy());
                }
            }
            else
            {
                settings.MenuNameDictionary = new Dictionary <string, KeyboardShortcut>();
            }

            if (settings.KeyboardShortcutsDescription != null)
            {
                settings.KeyboardShortcutsDescription.Clear();
            }
            settings.KeyboardShortcutsDescription = new Dictionary <string, KeyboardShortcut>();
            settings.UserFriendlyNameDirectory    = new Dictionary <Keys, string>();
            settings.PopulateKeyboardShortcutsDictionary();
            settings.PopulateUserFriendlyNamesForKeyboardKeys();
            settings.SettingsName = "Default";

            return(settings);
        }
コード例 #2
0
        /// <summary>
        /// Read the settings from the settings file; missing values are replaced with defaults.
        /// </summary>
        /// <remarks>Errors are silently ignored and default settings are returned.</remarks>
        public static KeyboardShortcuts_Settings GetKeyboardShortcuts_Settings()
        {
            KeyboardShortcuts_Settings settings = new KeyboardShortcuts_Settings();

            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForDomain();

            try
            {
                IsolatedStorageFileStream stream =
                    new IsolatedStorageFileStream(SETTINGS_FILE_NAME, FileMode.Open, FileAccess.Read, file);
                SoapFormatter soap = new SoapFormatter();
                settings = (KeyboardShortcuts_Settings)soap.Deserialize(stream);
                stream.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Keyboard shortcut setting  file : " + ex.ToString());
                if (ex is System.IO.FileNotFoundException)
                {
                    return(GetDefaultKeyboardShortcuts_Settings());
                }
            }

            settings.MenuNameDictionary = new Dictionary <string, KeyboardShortcut>();
            for (int i = 0; i < settings.MenuKeyboardShortCutsList.Length; i++)
            {
                settings.MenuNameDictionary.Add(settings.MenuKeyboardShortCutsList[i].Description, settings.MenuKeyboardShortCutsList[i]);
            }
            settings.KeyboardShortcutsDescription = new Dictionary <string, KeyboardShortcut>();

            settings.PopulateKeyboardShortcutsDictionary();


            return(settings);
        }
コード例 #3
0
        public bool Compare(KeyboardShortcuts_Settings shortcuts)
        {
            if (this.KeyboardShortcutsDescription.Count > 0 &&
                shortcuts != null && shortcuts.KeyboardShortcutsDescription.Count > 0)
            {
                foreach (string desc in this.KeyboardShortcutsDescription.Keys)
                {
                    if (!shortcuts.KeyboardShortcutsDescription.ContainsKey(desc))
                    {
                        return(false);
                    }

                    if (shortcuts.KeyboardShortcutsDescription[desc].Value != this.KeyboardShortcutsDescription[desc].Value)
                    {
                        return(false);
                    }
                }
                // if it does not returns due to any of the mismatch above then both of the instances have the same value
                return(true);
            }
            return(false);
        }
コード例 #4
0
        public static KeyboardShortcuts_Settings GetKeyboardShortcuts_SettingsFromFile(string filePath)
        {
            KeyboardShortcuts_Settings settings = new KeyboardShortcuts_Settings();
            FileStream stream = null;

            try
            {
                stream = new FileStream(filePath, FileMode.OpenOrCreate);

                SoapFormatter soap = new SoapFormatter();
                settings = (KeyboardShortcuts_Settings)soap.Deserialize(stream);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Keyboard shortcut setting  file : " + ex.ToString());
                if (ex is System.IO.FileNotFoundException)
                {
                    return(GetDefaultKeyboardShortcuts_Settings());
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
            settings.MenuNameDictionary = new Dictionary <string, KeyboardShortcut>();
            for (int i = 0; i < settings.MenuKeyboardShortCutsList.Length; i++)
            {
                settings.MenuNameDictionary.Add(settings.MenuKeyboardShortCutsList[i].Description, settings.MenuKeyboardShortCutsList[i]);
            }
            settings.KeyboardShortcutsDescription = new Dictionary <string, KeyboardShortcut>();

            settings.PopulateKeyboardShortcutsDictionary();

            return(settings);
        }