Example #1
0
        private void LoadLayoutFromSettings(MRUAdditionalData data, bool resetLayoutIfFailed = true)
        {
            if (data == null)
            {
                return;
            }

            var layout = isInEditorLayout ? data.DockingLayoutEditors : data.DockingLayout;

            BindableSelectedItemsControl.DisableBindings = true;
            try
            {
                // This exception is normal and will trigger a reset of the layout, since no layout can be loaded from the settings file.
                if (GameStudioInternalSettings.CurrentLayoutVersion != data.DockingLayoutVersion)
                {
                    throw new InvalidOperationException("Layout is out of date, need reset.");
                }

                // This exception is normal and will trigger a reset of the layout, since no layout can be loaded from the settings file.
                if (string.IsNullOrWhiteSpace(layout))
                {
                    throw new InvalidOperationException("No layout available in the settings file.");
                }

                ApplyDockingLayout(layout);
            }
            catch (Exception)
            {
                if (!resetLayoutIfFailed)
                {
                    return;
                }

                // Erase saved layout if we're unable to load it.
                if (GameStudioInternalSettings.CurrentLayoutVersion != data.DockingLayoutVersion)
                {
                    mruDataCollection.ResetAllLayouts(session.SessionFilePath);
                }
                else if (isInEditorLayout)
                {
                    mruDataCollection.ResetEditorsLayout(session.SessionFilePath);
                }
                else
                {
                    mruDataCollection.ResetLayout(session.SessionFilePath);
                }
                // And attempt to load the reset layout.
                LoadLayoutFromSettings(mruDataCollection.GetData(session.SessionFilePath), false);
            }
            finally
            {
                BindableSelectedItemsControl.DisableBindings = false;
            }
        }
        private void UpdateDataPrivate(MRUAdditionalData data)
        {
            if (!IsDataValid(data))
            {
                return;
            }

            // Remove it if it was already in the list
            mruList.RemoveWhere(x => string.Equals(x.FilePath, data.FilePath, StringComparison.OrdinalIgnoreCase));
            // Add again
            mruList.Add(data);
        }
        private MRUAdditionalData GetOrCreateDataPrivate(UFile filePath, bool createIfNotExist = true)
        {
            var data = mruList.FirstOrDefault(m => string.Equals(m?.FilePath, filePath, StringComparison.OrdinalIgnoreCase));

            if (data == null && createIfNotExist)
            {
                data = new MRUAdditionalData(filePath)
                {
                    DockingLayout        = GameStudioInternalSettings.DefaultLayout,
                    DockingLayoutEditors = GameStudioInternalSettings.DefaultEditorLayout,
                };
                mruList.Insert(0, data);
            }
            return(data);
        }
        public void UpdateData(MRUAdditionalData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            // Ensure we are properly synchronized with the file.
            LoadFromSettings();

            UpdateDataPrivate(data);

            // Save immediately
            SaveToSettings();
        }
 private static bool IsDataValid(MRUAdditionalData data)
 {
     return(data?.FilePath != null);
 }