public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool   isSelected        = (bool)value;
            string languageParameter = parameter as string; // "English" or "Serbian"

            LanguageViewModel.Language language = LanguageViewModel.Language.English;

            if (languageParameter == null)
            {
                throw new ArgumentNullException("parameter", "Language parameter not set.");
            }

            if (isSelected)
            {
                if (languageParameter == "Serbian")
                {
                    language = LanguageViewModel.Language.Serbian;
                }
                return(language);
            }
            else
            {
                if (languageParameter == "English")
                {
                    language = LanguageViewModel.Language.Serbian;
                }
                return(language);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets saved settings from the SavedSettings.txt as a List of objects. On index 0 should be a
        /// string, on index 1 a bool value, on index 2 a TimeSpan and on index 3 Language enum. If
        /// SavedSettings.txt has been tempered with returns null.
        /// </summary>
        /// <returns>List of objects holding the settings, or null if they can't be read.</returns>
        private List <object> GetSavedSettings()
        {
            List <object> settings = new List <object>(4);

            try
            {
                // Trying to read SavedSettings.txt, which should be in format:
                // Line 1: "Last save location            = xxx" where xxx is the full path to the saved Dictionary
                // Line 2: "Open dictionary automatically = xxx" where xxx is either true or false
                // Line 3: "Automatic save interval       = xxx" where xxx is a TimeSpan
                // Line 4: "Chosen language               = xxx" where xxx is either English or Serbian
                string[] lines = File.ReadAllLines("SavedSettings.txt");
                if (lines.Length < 4)
                {
                    // SavedSettings.txt has been changed
                    return(null);
                }
                string firstLine  = lines[0];
                string secondLine = lines[1];
                string thirdLine  = lines[2];
                string fourthLine = lines[3];

                string   lastSaveLocation           = string.Empty;
                bool     openAutomatically          = false;
                TimeSpan saveInterval               = new TimeSpan(0, 0, 0);
                LanguageViewModel.Language language = LanguageViewModel.Language.English;

                try
                {
                    firstLine  = firstLine.Substring(32).Trim();
                    secondLine = secondLine.Substring(32).Trim();
                    thirdLine  = thirdLine.Substring(32).Trim();
                    fourthLine = fourthLine.Substring(32).Trim();

                    lastSaveLocation = firstLine;
                    bool.TryParse(secondLine, out openAutomatically);
                    TimeSpan.TryParse(thirdLine, out saveInterval);
                    Enum.TryParse(fourthLine, out language);
                }
                catch (ArgumentOutOfRangeException)
                {
                    // SavedSettings.txt has been changed
                    return(null);
                }

                settings.Add(lastSaveLocation);
                settings.Add(openAutomatically);
                settings.Add(saveInterval);
                settings.Add(language);
            }
            catch (FileNotFoundException)
            {
                // SavedSettings.txt deleted
                Debug.WriteLine("SavedSettings.txt file not found. Starting with default settings.");
                return(null);
            }

            return(settings);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string saveLocation = values[0] as string;

            LanguageViewModel.Language language = (LanguageViewModel.Language)values[1];
            string title = "German dictionary";

            if (language == LanguageViewModel.Language.Serbian)
            {
                title = "Recnik nemackog jezika";
            }

            if (saveLocation != null)
            {
                string fileName = Path.GetFileNameWithoutExtension(saveLocation);
                title += " - " + fileName;
            }
            return(title);
        }