Example #1
0
        public string SaveLayout(string layoutName, string data)
        {
            Validate.IsNotNullAndNotWhiteSpace(layoutName, nameof(layoutName));
            layoutName = LayoutManagementUtilities.NormalizeName(layoutName);
            var keyValuePair = CachedInfo.FirstOrDefault(kvp => kvp.Value != null &&
                                                         string.Equals(kvp.Value.Name, layoutName, StringComparison.CurrentCultureIgnoreCase));

            var flag = !string.IsNullOrEmpty(keyValuePair.Key);
            var key  = flag ? keyValuePair.Key : LayoutManagementUtilities.GenerateKey();

            var info = new WindowLayout(layoutName, flag ? keyValuePair.Value.Position : CachedInfo.Count, key, data, true);

            if (!flag)
            {
                InsertSettingsModel(info, true);
            }
            else
            {
                RemoveAllModels();
                var list = CachedInfo;
                list.RemoveAt(info.Position);
                list.Add(new KeyValuePair <string, WindowLayout>(info.Key, info));
                foreach (var valuePair in list.OrderBy(x => x.Value.Position))
                {
                    InsertSettingsModel(valuePair.Value, true);
                }
            }

            OnSettingsChanged();
            return(key);
        }
Example #2
0
        public void ManageWindowLayoutsInternal(
            Func <IEnumerable <KeyValuePair <string, WindowLayout> >, IEnumerable <KeyValuePair <string, WindowLayout> > >
            layoutTransformation)
        {
            var keyValuePairs = LayoutManagementUtilities.EnumerateLayoutKeyInfo(_layoutStore);
            var newLayouts    = layoutTransformation(keyValuePairs);

            _layoutStore.UpdateStore(newLayouts);
        }
Example #3
0
 private bool ValidateLayoutName(string name, out bool hadNameConflict)
 {
     name            = LayoutManagementUtilities.NormalizeName(name);
     hadNameConflict = false;
     if (LayoutManagementUtilities.IsUniqueName(name, _layoutStore))
     {
         return(true);
     }
     hadNameConflict = true;
     return(LayoutManagementDialogUserInput.TryGetOverwriteLayoutConfirmation(name));
 }
Example #4
0
        private int GetDefaultLayoutNameIndex(string defaultNameFormat)
        {
            var    num = 0;
            string name;

            do
            {
                ++num;
                name = string.Format(CultureInfo.CurrentUICulture, defaultNameFormat, new object[]
                {
                    num
                });
            } while (num < 11 && !LayoutManagementUtilities.IsUniqueName(name, _layoutStore));
            return(num);
        }
Example #5
0
        public void SaveWindowLayout()
        {
            var layoutNameFormat       = WindowManagement_Resources.SaveLayoutCommandDefinitionMessageBox_Default;
            var defaultLayoutNameIndex = GetDefaultLayoutNameIndex(layoutNameFormat);
            var defaultName            = string.Format(CultureInfo.CurrentUICulture, layoutNameFormat, new object[]
            {
                defaultLayoutNameIndex
            });
            var hadNameConflict = false;

            if (!LayoutManagementDialogUserInput.TryGetSavedLayoutName(defaultName,
                                                                       name => ValidateLayoutName(name, out hadNameConflict), out var layoutName))
            {
                return;
            }
            SaveWindowLayoutInternal(LayoutManagementUtilities.NormalizeName(layoutName), hadNameConflict);
        }
Example #6
0
        private bool TryApplyWindowLayout(string name, int index)
        {
            var layoutDataAt = GetLayoutDataAt(index);

            SetStatusBarMessage(WindowManagement_Resources.ApplyLayoutStartedStatusFormat, name);

            try
            {
                using (var stream = LayoutManagementUtilities.ConvertLayoutPayloadToStream(layoutDataAt))
                {
                    _layoutSystem.RestoreFrameLayoutCollection(stream);
                }
            }
            catch
            {
                SetStatusBarMessage(WindowManagement_Resources.ApplyLayoutErrorStatusFormat, name);
                return(false);
            }
            SetStatusBarMessage(WindowManagement_Resources.ApplyLayoutCompletedStatusFormat, name);
            return(true);
        }