示例#1
0
        private static void OnModeChangeLayouts(ModeChangedArgs args)
        {
            // Prevent double loading the default/last layout already done by the WindowLayout system.
            if (args.prevIndex == -1)
            {
                return;
            }

            if (HasCapability(ModeCapability.LayoutSwitching, true))
            {
                WindowLayout.SaveCurrentLayoutPerMode(GetModeId(args.prevIndex));

                try
                {
                    if (args.nextIndex != 0 || args.prevIndex == -1 || HasCapability(args.prevIndex, ModeCapability.LayoutSwitching, true))
                    {
                        // Load the last valid layout for this mode
                        WindowLayout.LoadCurrentModeLayout(keepMainWindow: true);
                    }
                }
                catch (Exception)
                {
                    // Error while loading layout. Load the default layout for current mode.
                    WindowLayout.LoadDefaultLayout();
                }
            }

            if (HasCapability(ModeCapability.LayoutWindowMenu, true))
            {
                WindowLayout.ReloadWindowLayoutMenu();
                EditorUtility.Internal_UpdateAllMenus();
            }
        }
示例#2
0
        void OnGUI()
        {
            if (m_Paths == null)
            {
                InitializePaths();
            }
            m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos);
            foreach (string path in m_Paths)
            {
                string name = Path.GetFileNameWithoutExtension(path);
                if (name.Length > k_MaxLayoutNameLength)
                {
                    name = name.Substring(0, k_MaxLayoutNameLength) + "...";
                }
                if (GUILayout.Button(name))
                {
                    if (Toolbar.lastLoadedLayoutName == name)
                    {
                        Toolbar.lastLoadedLayoutName = null;
                    }

                    File.Delete(path);
                    WindowLayout.ReloadWindowLayoutMenu();
                    EditorUtility.Internal_UpdateAllMenus();
                    ShortcutIntegration.instance.RebuildShortcuts();
                    InitializePaths();
                }
            }

            EditorGUILayout.EndScrollView();
        }
示例#3
0
        private static void OnModeChangeLayouts(ModeChangedArgs args)
        {
            // Prevent double loading the default/last layout already done by the WindowLayout system.
            if (args.prevIndex == -1)
            {
                return;
            }

            if (!HasCapability(ModeCapability.LayoutSwitching, true))
            {
                return;
            }

            WindowLayout.SaveCurrentLayoutPerMode(GetModeId(args.prevIndex));

            try
            {
                // Load the last valid layout for this mode
                WindowLayout.LoadDefaultWindowPreferences();
            }
            catch (Exception)
            {
                // Error while loading layout. Load the default layout for current mode.
                WindowLayout.LoadDefaultLayout();
            }

            WindowLayout.ReloadWindowLayoutMenu();
        }
示例#4
0
        void OnGUI()
        {
            GUILayout.Space(5);
            Event evt      = Event.current;
            bool  hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter);

            GUI.SetNextControlName("m_PreferencesName");
            EditorGUI.BeginChangeCheck();
            s_LayoutName = EditorGUILayout.TextField(s_LayoutName);
            if (EditorGUI.EndChangeCheck())
            {
                UpdateCurrentInvalidChars();
            }

            if (!m_DidFocus)
            {
                m_DidFocus = true;
                EditorGUI.FocusTextInControl("m_PreferencesName");
            }

            if (s_CurrentInvalidChars.Length != 0)
            {
                EditorGUILayout.HelpBox(string.Format(s_InvalidCharsFormatString, s_CurrentInvalidChars), MessageType.Warning);
                minSize = new Vector2(k_Width, k_Height + k_HelpBoxHeight);
            }
            else
            {
                minSize = new Vector2(k_Width, k_Height);
            }

            bool canSaveLayout = s_LayoutName.Length > 0 && s_CurrentInvalidChars.Length == 0;

            EditorGUI.BeginDisabled(!canSaveLayout);

            if (GUILayout.Button("Save") || hitEnter && canSaveLayout)
            {
                Close();

                if (!Directory.Exists(WindowLayout.layoutsModePreferencesPath))
                {
                    Directory.CreateDirectory(WindowLayout.layoutsModePreferencesPath);
                }

                string path = Path.Combine(WindowLayout.layoutsModePreferencesPath, s_LayoutName + ".wlt");
                Toolbar.lastLoadedLayoutName = s_LayoutName;
                WindowLayout.SaveWindowLayout(path);
                WindowLayout.ReloadWindowLayoutMenu();
                EditorUtility.Internal_UpdateAllMenus();
                ShortcutIntegration.instance.RebuildShortcuts();
                GUIUtility.ExitGUI();
            }
            else
            {
                m_DidFocus = false;
            }

            EditorGUI.EndDisabled();
        }
示例#5
0
        private static void OnModeChangeLayouts(ModeChangedArgs args)
        {
            // Prevent double loading the default/last layout already done by the WindowLayout system.
            if (args.prevIndex == -1)
            {
                return;
            }

            if (!HasCapability(ModeCapability.LayoutSwitching, true))
            {
                return;
            }

            // Save previous mode layout
            var prevLayoutPath = Path.Combine(Application.temporaryCachePath, $"{k_ModeLayoutKeyName}-{GetModeId(args.prevIndex)}.wlt");

            WindowLayout.SaveWindowLayout(prevLayoutPath);

            // Load exiting layout if available
            var modeLayoutPath = Path.Combine(Application.temporaryCachePath, $"{k_ModeLayoutKeyName}-{GetModeId(args.nextIndex)}.wlt");

            if (File.Exists(modeLayoutPath))
            {
                WindowLayout.LoadWindowLayout(modeLayoutPath, false, false);
            }
            else
            {
                var layouts = GetModeDataSection(args.nextIndex, k_LayoutsSectionName) as IList <object>;
                if (layouts != null && layouts.Count > 0)
                {
                    var layoutPath = layouts[0] as string;
                    if (layoutPath != null)
                    {
                        WindowLayout.LoadWindowLayout(layoutPath, false, false);
                    }
                }
            }

            WindowLayout.ReloadWindowLayoutMenu();
        }