Пример #1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));

            uiShell.EnableModeless(0);
            var xamlDialog = new TextDialogWindow("Razor File Name", MoveSelectionToRazorFile)
            {
                Owner = Application.Current.MainWindow
            };


            xamlDialog.HasMinimizeButton = false;
            xamlDialog.HasMaximizeButton = true;
            xamlDialog.MaxHeight         = 140;
            xamlDialog.MinHeight         = 140;
            xamlDialog.MaxWidth          = 450;
            xamlDialog.MinWidth          = 450;
            xamlDialog.Title             = "Move To New Razor File";

            xamlDialog.ActionToClose = xamlDialog.Close;

            xamlDialog.ShowDialog();
            uiShell.EnableModeless(1);
        }
Пример #2
0
        public override bool HandleEvent(Event e)
        {
            const float padding          = 5;
            const float defControlHeight = 20;
            float       maxWidth         = bounds.width - (padding * 2);
            float       currY            = bounds.yMin + padding;
            float       minX             = bounds.xMin + padding;

            FeatureAsset feature = FeatureEditorWindow.GetInstance().Feature;

            //selected section number
            Rect selSecCountRect = new Rect(minX, currY, maxWidth, defControlHeight);
            int  selectionCount  = feature.GetSelectedCount();

            GUI.Box(selSecCountRect, selectionCount + (selectionCount == 1 ? " tile selected" : " tiles selected"));

            currY += selSecCountRect.height + padding;

            //variant field label
            Rect variantFieldLabelRect = new Rect(minX, currY, maxWidth / 4, defControlHeight);

            GUI.Box(variantFieldLabelRect, "Variant");

            //variant field select button
            Rect variantSelButRect = new Rect(bounds.xMax - padding - (maxWidth / 4), currY, maxWidth / 4, defControlHeight);

            if (GUI.Button(variantSelButRect, "Select"))
            {
                string   fullPath      = EditorUtility.OpenFolderPanel("Select Variant Folder", lastSelectedFolder != "" ? lastSelectedFolder : Application.dataPath, "");
                string[] splitFullPath = fullPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                variant = splitFullPath[splitFullPath.Length - 1];
                SetVariant(variant);

                //save parent of selected folder
                lastSelectedFolder = fullPath.Substring(0,
                                                        Mathf.Max(
                                                            fullPath.LastIndexOf(Path.AltDirectorySeparatorChar),
                                                            fullPath.LastIndexOf(Path.DirectorySeparatorChar)));
            }

            //variant field text box
            Rect   variantTextRect = new Rect(minX + (maxWidth / 4), currY, maxWidth / 2, defControlHeight);
            string initialVariant  = GetVariant();

            if (initialVariant == null)
            {
                variant = MIXED_VALUES;
            }
            else
            {
                variant = initialVariant;
            }
            string newVariant = EditorGUI.TextField(variantTextRect, variant);

            if (newVariant != MIXED_VALUES && newVariant != variant)
            {
                Undo.RegisterCompleteObjectUndo(feature, "Change variant");
                feature.ForAllSelectedSections((Section s) => { s.variant = variant = newVariant; });
                EditorUtility.SetDirty(feature);
            }

            currY += defControlHeight + padding;

            //kvp add new
            Rect addNewKvpRect = new Rect(minX, currY, maxWidth, defControlHeight);

            if (GUI.Button(addNewKvpRect, "Add New Field"))
            {
                TextDialogWindow.Create((string text) => {
                    Undo.RegisterCompleteObjectUndo(feature, "Add New Field");
                    feature.ForAllSelectedSections((Section s) => { s.AddField(text); });
                    EditorUtility.SetDirty(feature);
                });
            }

            currY += defControlHeight + padding;

            //kvp scroll view
            IField[]    fields          = GetFields();
            const float fieldRectHeight = 20;

            Rect scrollViewRect   = new Rect(minX, currY, maxWidth, bounds.yMax - currY);
            Rect scrollBoundsRect = new Rect(scrollViewRect);

            scrollBoundsRect.height = (fieldRectHeight + padding) * fields.Length;
            scrollBoundsRect.width -= 20;

            kvpFieldScrollPos = GUI.BeginScrollView(scrollViewRect, kvpFieldScrollPos, scrollBoundsRect, false, true);

            Rect  fieldRect = new Rect(scrollBoundsRect);
            float startY    = fieldRect.y;

            fieldRect.height = fieldRectHeight;
            for (int i = 0; i < fields.Length; i++)
            {
                fieldRect.y = startY + (20 + padding) * i;

                Rect fieldRectPartial = new Rect(fieldRect);
                fieldRectPartial.width = fieldRect.width / 2;
                GUI.Box(fieldRectPartial, fields[i].Name);

                fieldRectPartial.x     += fieldRect.width / 2;
                fieldRectPartial.width /= 2;
                string initalValue = fields[i].Value;
                string modifiValue = EditorGUI.TextField(fieldRectPartial, initalValue);
                if (modifiValue != initalValue)
                {
                    Undo.RegisterCompleteObjectUndo(feature, $"Modified {fields[i].Name}");
                    feature.ForAllSelectedSections((Section s) => { s.SetField(fields[i].Name, modifiValue); });
                    EditorUtility.SetDirty(feature);
                }

                fieldRectPartial.x += fieldRect.width / 4;
                if (GUI.Button(fieldRectPartial, "Remove"))
                {
                    feature.ForAllSelectedSections((Section s) => { s.RemoveField(fields[i].Name); });
                }
            }

            GUI.EndScrollView(handleScrollWheel: true);

            return(bounds.Contains(e.mousePosition));
        }