Exemplo n.º 1
0
        static DocumentWindow CreateWindowImpl(DocumentInstance document, object obj, bool openAsSettings)
        {
            Type type;

            if (openAsSettings)
            {
                type = typeof(ObjectSettingsWindow);
            }
            else if (document.SpecialMode == "TextEditor")
            {
                type = EditorAssemblyInterface.Instance.GetTypeByName("NeoAxis.Editor.TextEditorDocumentWindow");                  // typeof( TextEditorDocumentWindow );
            }
            else
            {
                type = GetDocumentWindowClass(obj) ?? GetWindowClassFromFileName(document.RealFileName) ?? typeof(DocumentWindow);
            }

            DocumentWindow window;

            if (typeof(CanvasBasedEditor).IsAssignableFrom(type))
            {
                var editor  = (CanvasBasedEditor)Activator.CreateInstance(type);
                var window2 = new DocumentWindowWithViewport_CanvasBasedEditor(editor);
                editor.owner = window2;
                window       = window2;
            }
            else
            {
                window = (DocumentWindow)Activator.CreateInstance(type);
            }

            window.InitDocumentWindow(document, obj, openAsSettings, null);
            return(window);
        }
Exemplo n.º 2
0
        // window config support.
        internal static DockWindow CreateWindow(DocumentInstance document)
        {
            DockWindow window = null;

            if (document.IsEditorDocumentConfigurationExist)
            {
                try
                {
                    window = new WorkspaceWindow(EditorForm.Instance);
                    ((WorkspaceWindow)window).InitFromConfig(document);
                    //Log.Info( $"Layout for '{document.Name}' restored from config!" );
                }
                catch (Exception exc)                  //TODO: use more specific exc type.
                {
                    //!!!!
                    Log.Info($"Warning: Layout for '{document.Name}' doesnt restored.");
                    Log.Info(exc.Message);

                    if (window != null)
                    {
                        window.Dispose();
                    }

                    // just create window without workspace.
                    window = CreateWindowImpl(document, document.ResultObject, false);
                }
            }
            else
            {
                //create document window
                window = CreateWindowImpl(document, document.ResultObject, false);
            }

            return(window);
        }
Exemplo n.º 3
0
        public static DocumentInstance OpenStore(bool openBasicContent = false)
        {
            //select already opened
            var w = FindWindow <StoreDocumentWindow>();

            if (w != null)
            {
                SelectDockWindow(w);
                if (openBasicContent)
                {
                    w.LoadURL(StoreDocumentWindow.homeURLBasicContent);
                }
                return(w.Document);
            }

            var document = new DocumentInstance("", null, "");

            Documents.Add(document);

            var window = new StoreDocumentWindow();

            window.InitDocumentWindow(document, null, false, null);
            if (openBasicContent)
            {
                window.StartURL = StoreDocumentWindow.homeURLBasicContent;
            }

            EditorForm.Instance.WorkspaceController.AddDockWindow(window, false, true);

            return(document);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="title"></param>
        /// <param name="select"></param>
        /// <param name="readOnly"></param>
        /// <param name="highlightingScheme">This is the prefix for file path. Specify \'CSharp\'. 'Base\Tools\Highlighting\{CSharp}Dark.xshd'</param>
        /// <returns></returns>
        public static DocumentInstance OpenTextAsDocument(string text, string title, bool select, bool readOnly = false, string highlightingScheme = "", int selectLine = 0)          //RangeFrom = 0, int selectRangeTo = 0 )
        {
            //!!!!TODO: check for already opened

            var document = new DocumentInstance("", null, "");

            Documents.Add(document);

            var type   = EditorAssemblyInterface.Instance.GetTypeByName("NeoAxis.Editor.TextEditorDocumentWindow");
            var window = (DocumentWindow)Activator.CreateInstance(type);
            //TextEditorDocumentWindow window = new TextEditorDocumentWindow();

            var windowTypeSpecificOptions = new Dictionary <string, object>();

            windowTypeSpecificOptions["ReadOnly"]           = readOnly;
            windowTypeSpecificOptions["HighlightingScheme"] = highlightingScheme;
            windowTypeSpecificOptions["SelectLine"]         = selectLine;
            //windowTypeSpecificOptions[ "SelectRange" ] = new RangeI( selectRangeFrom, selectRangeTo );

            window.InitDocumentWindow(document, null, false, windowTypeSpecificOptions);
            window.PropertySet("Data", text);              //window.Data = text;
            window.WindowTitle = title;

            EditorForm.Instance.WorkspaceController.AddDockWindow(window, false, select);

            return(document);
        }
Exemplo n.º 5
0
        bool ContainsNotFloatingWindows(DocumentInstance document)
        {
            foreach (var documentWindow in EditorAPI.GetAllDocumentWindowsOfDocument(document))
            {
                bool foundFloating = false;

                Control c = documentWindow;
                while (c != null)
                {
                    if (c is KryptonFloatingWindow)
                    {
                        foundFloating = true;
                        break;
                    }

                    c = c.Parent;
                }

                if (!foundFloating)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        public static DocumentInstance OpenPackages(string selectPackage)
        {
            //select already opened
            var w = FindWindow <PackagesWindow>();

            if (w != null)
            {
                SelectDockWindow(w);
                if (!string.IsNullOrEmpty(selectPackage))
                {
                    w.NeedSelectPackage(selectPackage);
                }
                return(w.Document);
            }

            var document = new DocumentInstance("", null, "");

            Documents.Add(document);

            var window = new PackagesWindow();

            window.InitDocumentWindow(document, null, false, null);

            EditorForm.Instance.WorkspaceController.AddDockWindow(window, false, true);

            if (!string.IsNullOrEmpty(selectPackage))
            {
                window.NeedSelectPackage(selectPackage);
            }

            return(document);
        }
Exemplo n.º 7
0
        ////!!!! rename: OpenSetResourceWindow
        //public void ShowSetResourceWindow( DocumentWindow documentWindow, object[] selectedObjects, Metadata.Property property, object[] propertyIndexes, bool readOnly )
        ////, Metadata.TypeInfo demandedType, bool allowNull )
        //{
        //	var window = new SetResourceWindow();
        //	window.documentWindow = documentWindow;
        //	window.initData = new SetResourceWindow.InitDataClass();
        //	window.initData.selectedObjects = selectedObjects;
        //	window.initData.property = property;
        //	window.initData.propertyIndexes = propertyIndexes;
        //	window.initData.readOnly = readOnly;

        //	//!!!!начальное положение, настройки. везде так

        //	workspaceController.AddDockWindow( window, true, true );
        //}

        //!!!!надо закрывать все окна, когда документ закрывается. или как-то так
        //!!!! rename: OpenObjectSettingsWindow
        public static DocumentWindow ShowObjectSettingsWindow(DocumentInstance document, object obj, bool canUseAlreadyOpened)
        {
            //!!!!если ссылка настроена, то нельзя редактировать

            //check already opened
            if (canUseAlreadyOpened)
            {
                var openedWindow = EditorForm.Instance.WorkspaceController.FindWindowRecursive(document, obj, typeof(ObjectSettingsWindow));
                if (openedWindow != null)
                {
                    EditorForm.Instance.WorkspaceController.SelectDockWindow(openedWindow);
                    return(openedWindow);
                }
            }

            //!!!!указывать OK, Cancel или просто Close

            var window = new ObjectSettingsWindow();

            window.InitDocumentWindow(document, obj, true, null);

            //!!!!

            EditorForm.Instance.WorkspaceController.AddDockWindow(window, true, true);

            return(window);
        }
Exemplo n.º 8
0
        //!!!!если надо, то как EditorAction
        //public static void ShowObjectDetailsAsDocument( object obj )
        //{
        //	List<string> lines = new List<string>( 256 );

        //	lines.Add( obj.ToString() );
        //	lines.Add( "" );
        //	lines.Add( "----------------------------------------------------------------------------------------------------" );

        //	lines.Add( "Inheritance Hierarchy" );
        //	lines.Add( "" );

        //	var type = MetadataManager.MetadataGetType( obj );
        //	int step = 0;
        //	do
        //	{
        //		lines.Add( new string( ' ', step * 3 ) + type.ToString() );

        //		step++;
        //		type = type.BaseType;
        //	} while( type != null );

        //	//lines.Add( "Type \'" + MetadataManager.MetadataGetType( obj ).ToString() + "\'" );
        //	//lines.Add( ".NET type \'" + obj.GetType().ToString() + "\'" );
        //	lines.Add( "" );
        //	lines.Add( "----------------------------------------------------------------------------------------------------" );
        //	lines.Add( "" );

        //	foreach( var member in MetadataManager.MetadataGetMembers( obj ) )
        //	{
        //		Metadata.Method method = member as Metadata.Method;
        //		if( method != null )
        //		{
        //			lines.Add( method.Signature );
        //			lines.Add( "    " + method.ToString() );
        //			lines.Add( "" );
        //		}
        //	}

        //	lines.Add( "----------------------------------------------------------------------------------------------------" );
        //	lines.Add( "" );

        //	foreach( var member in MetadataManager.MetadataGetMembers( obj ) )
        //	{
        //		Metadata.Event evt = member as Metadata.Event;
        //		if( evt != null )
        //		{
        //			lines.Add( evt.Signature );
        //			lines.Add( "    " + evt.ToString() );
        //			lines.Add( "" );
        //		}
        //	}

        //	lines.Add( "----------------------------------------------------------------------------------------------------" );
        //	lines.Add( "" );

        //	foreach( var member in MetadataManager.MetadataGetMembers( obj ) )
        //	{
        //		Metadata.Property prop = member as Metadata.Property;
        //		if( prop != null )
        //		{
        //			lines.Add( prop.Signature );
        //			lines.Add( "    " + prop.ToString() );
        //			lines.Add( "" );
        //		}
        //	}

        //	//lines.Add( "Type: " + MetadataManager.MetadataGetType( obj ).ToString() );
        //	//lines.Add( "Net type: " + obj.GetType().ToString() );
        //	//lines.Add( "" );
        //	//lines.Add( "ToString(): " + obj.ToString() );
        //	//lines.Add( "" );
        //	//lines.Add( "----------------------------------------------------------------------------------------------------" );
        //	//lines.Add( "Metadata:" );



        //	//!!!!!!
        //	//if( component != null )
        //	//{
        //	//	List<string> list = new List<string>();

        //	//	var members = component.MetadataGetMembers( true );

        //	//	list.Add( component.ToString() );

        //	//	list.Add( "" );
        //	//	list.Add( "Events:" );
        //	//	foreach( var m in members )
        //	//	{
        //	//		var evn = m as Metadata.Event;
        //	//		if( evn != null )
        //	//			list.Add( evn.ToString() + " - " + evn.Signature );
        //	//	}

        //	//	list.Add( "" );
        //	//	list.Add( "Properties:" );
        //	//	foreach( var m in members )
        //	//	{
        //	//		var p = m as Metadata.Property;
        //	//		if( p != null )
        //	//			list.Add( p.ToString() + " - " + p.Signature );
        //	//	}

        //	//	list.Add( "" );
        //	//	list.Add( "Methods:" );
        //	//	foreach( var m in members )
        //	//	{
        //	//		var method = m as Metadata.Method;
        //	//		if( method != null )
        //	//			list.Add( method.ToString() + " - " + method.Signature );
        //	//	}

        //	//	//!!!!!!log out
        //	//	{
        //	//		Log.Info( "" );
        //	//		Log.Info( "" );
        //	//		Log.Info( "---------------------------------- START -------------------------------------" );

        //	//		foreach( var t in list )
        //	//			Log.Info( t );

        //	//		Log.Info( "----------------------------------- END --------------------------------------" );
        //	//	}

        //	//	viewport.GuiRenderer.AddTextLines( list, new Vec2( .03, .1 ), EHorizontalAlign.Left, EVerticalAlign.Top, 0,
        //	//		new ColorValue( 1, 1, 0 ) );
        //	//}

        //	StringBuilder text = new StringBuilder();
        //	foreach( var line in lines )
        //		text.Append( line + "\r\n" );
        //	EditorForm.Instance.OpenTextAsDocument( text.ToString(), MetadataManager.MetadataGetType( obj ).ToString(), true );
        //}

        public static void SetPropertyReference(DocumentInstance document, object /* Component*/[] objects, Metadata.Property property, object[] indexers, string[] referenceValues)
        {
            var netType        = property.Type.GetNetType();
            var underlyingType = ReferenceUtility.GetUnderlyingType(netType);

            var undoItems = new List <UndoActionPropertiesChange.Item>();

            //!!!!try, catch? где еще

            for (int n = 0; n < objects.Length; n++)
            {
                var obj = objects[n];

                var value    = ReferenceUtility.MakeReference(underlyingType, null, referenceValues[n]);
                var oldValue = (IReference)property.GetValue(obj, indexers);

                //bool change = true;
                //if( /*skipSame && */oldValue != null && value.GetByReference == oldValue.GetByReference )
                //	change = false;

                if (!value.Equals(oldValue))
                {
                    property.SetValue(obj, value, indexers);
                    undoItems.Add(new UndoActionPropertiesChange.Item(obj, property, oldValue, indexers));
                }
            }

            //undo
            if (undoItems.Count != 0)
            {
                var action = new UndoActionPropertiesChange(undoItems.ToArray());
                document.UndoSystem.CommitAction(action);
                document.Modified = true;
            }
        }
Exemplo n.º 9
0
        public override void InitDocumentWindow(DocumentInstance document, object objectOfWindow, bool openAsSettings, Dictionary <string, object> windowTypeSpecificOptions)
        {
            base.InitDocumentWindow(document, objectOfWindow, openAsSettings, windowTypeSpecificOptions);

            if (objectsBrowser1 != null)
            {
                objectsBrowser1.Init(this, objectOfWindow, /*null, */ null);
            }

            //!!!!
            //special for Project Settings
            if (document.SpecialMode == "ProjectSettingsUserMode")
            {
                ReadOnlyHierarchy = true;
            }

            if (document.SpecialMode != "ProjectSettingsUserMode")
            {
                kryptonButtonApply.Enabled = false;
                kryptonButtonApply.Visible = false;
            }

            if (document.SpecialMode == "ProjectSettingsUserMode")
            {
                objectsBrowser1.OverrideItemText += ObjectsBrowser1_OverrideItemText;
            }
        }
Exemplo n.º 10
0
        //

        public UndoActionComponentMove(DocumentInstance document, Component obj, Component oldParent, int oldIndex)
        {
            this.document = document;
            this.obj      = obj;

            dataToRestore.parent      = oldParent;
            dataToRestore.insertIndex = oldIndex;
        }
Exemplo n.º 11
0
        public void InitFromConfig(DocumentInstance document)
        {
            Init(document);

            var config = document.ResultComponent.EditorDocumentConfiguration;

            workspaceController.LoadLayoutFromString(config);
        }
Exemplo n.º 12
0
 public virtual void InitDocumentWindow(DocumentInstance document, object objectOfWindow, bool openAsSettings, Dictionary <string, object> windowTypeSpecificOptions)
 {
     this.document       = document;
     this.objectOfWindow = objectOfWindow;
     this.openAsSettings = openAsSettings;
     if (windowTypeSpecificOptions != null)
     {
         this.windowTypeSpecificOptions = windowTypeSpecificOptions;
     }
 }
Exemplo n.º 13
0
        public void Init(DocumentInstance document)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            Document = document;
            UpdateWindowTitle();
        }
Exemplo n.º 14
0
        static internal DocumentInstance CreateDocument(string realFileName, string specialMode = "")
        {
            if (specialMode == "TextEditor")
            {
                var document = new DocumentInstance(realFileName, null, specialMode);
                Documents.Add(document);
                return(document);
            }

            string virtualFileName = VirtualPathUtility.GetVirtualPathByReal(realFileName);

            if (!string.IsNullOrEmpty(virtualFileName) && IsDocumentFileSupport(virtualFileName))
            {
                Resource.Instance resourceIns = null;

                var ext = Path.GetExtension(virtualFileName).ToLower();
                if (ext != "" && ext[0] == '.')
                {
                    ext = ext.Substring(1);
                }
                if (ResourceManager.GetTypeByFileExtension(ext) != null)
                {
                    //unload resource if it file was deleted
                    {
                        var res = ResourceManager.GetByName(virtualFileName);
                        if (res != null && res.FileWasDeleted)
                        {
                            res.Dispose();
                        }
                    }

                    //!!!!!good?
                    //!!!!wait

                    resourceIns = ResourceManager.LoadSeparateInstance(virtualFileName, true, true, null);
                    //resourceIns = ResourceManager.LoadResource( virtualFileName, true );

                    if (resourceIns == null)
                    {
                        return(null);
                    }
                }

                var document = new DocumentInstance(realFileName, resourceIns, specialMode);
                Documents.Add(document);

                return(document);
            }

            return(null);
        }
Exemplo n.º 15
0
        public static List <DocumentWindow> GetAllDocumentWindowsOfDocument(DocumentInstance document)
        {
            var result = new List <DocumentWindow>();

            foreach (var dockWindow in EditorForm.Instance.WorkspaceController.GetDockWindowsRecursive())
            {
                var window = dockWindow as DocumentWindow;
                if (window != null && window.Document == document)
                {
                    result.Add(window);
                }
            }

            return(result);
        }
        public override void InitDocumentWindow(DocumentInstance document, object objectOfWindow, bool openAsSettings, Dictionary <string, object> windowTypeSpecificOptions)
        {
            base.InitDocumentWindow(document, objectOfWindow, openAsSettings, windowTypeSpecificOptions);

            document.SaveEvent += Document_SaveEvent;

            if (!string.IsNullOrEmpty(HighlightingScheme))
            {
                UpdateHighlightingScheme();
            }

            if (ReadOnly)
            {
                avalonTextEditor.Editor.IsReadOnly = ReadOnly;
            }
        }
Exemplo n.º 17
0
        private void Document_SaveEvent(DocumentInstance document, string saveAsFileName, ref bool handled, ref bool result)
        {
            if (Destroyed)
            {
                return;
            }

            if (!scriptEditorControl.GetCode(out var text))
            {
                Log.Warning("Unable to get code from control.");
                result  = false;
                handled = true;
                return;
            }

            try
            {
                if (!string.IsNullOrEmpty(saveAsFileName))
                {
                    File.WriteAllText(saveAsFileName, text);
                }
                else
                {
                    File.WriteAllText(document.RealFileName, text);
                }

                //using( var writer = File.CreateText( saveAsFileName ) )
                //{
                //	for( int lineIndex = 0; lineIndex < text.Lines.Count - 1; ++lineIndex )
                //		writer.WriteLine( text.Lines[ lineIndex ].ToString() );
                //	writer.Write( text.Lines[ text.Lines.Count - 1 ].ToString() );
                //}

                result = true;
            }
            catch (Exception e)
            {
                Log.Warning(e.Message);
                result = false;
            }

            //var saveResult = scriptEditorControl.SaveScript();

            handled = true;
            //result = saveResult;
        }
Exemplo n.º 18
0
        public static void CloseAllDocumentWindowsOnSecondLevelWithDeletedObjects(DocumentInstance document)
        {
            var toClose = new List <DocumentWindow>();

            foreach (var dockWindow in EditorForm.Instance.WorkspaceController.GetDockWindowsRecursive())
            {
                var window = dockWindow as DocumentWindow;
                if (window != null && window.Document == document && window.IsWindowInWorkspace && window.ObjectOfWindow != document.ResultObject && window.ObjectOfWindowIsDeleted)
                {
                    toClose.Add(window);
                }
            }

            foreach (var window in toClose)
            {
                window.Close();
            }
        }
Exemplo n.º 19
0
        /////////////////////////////////////

        public ComponentTypeSettingsForm(DocumentInstance document, Component component)
        {
            this.document  = document;
            this.component = component;

            InitializeComponent();

            if (EditorUtility.IsDesignerHosted(this))
            {
                return;
            }

            hierarchicalContainer1.OverrideGroupDisplayName += HierarchicalContainer1_OverrideGroupDisplayName;

            DarkThemeUtility.ApplyToForm(this);

            Text = EditorLocalization.Translate("TypeSettingsForm", Text);
            EditorLocalization.TranslateForm("TypeSettingsForm", this);
        }
Exemplo n.º 20
0
        static internal DocumentWindow CreateWindowImpl(DocumentInstance document, string objectPath, bool openAsSettings)
        {
            object obj = null;

            if (string.IsNullOrEmpty(objectPath))
            {
                obj = document.ResultComponent;                 // root component
            }
            else
            {
                obj = document.ResultComponent.Components.GetByPath(objectPath);
                if (obj == null)
                {
                    throw new Exception($"Object with path '{objectPath}' for window '{document.Name}' not found.");
                }
            }

            return(CreateWindowImpl(document, obj, openAsSettings));
        }
Exemplo n.º 21
0
        public static void ShowTips()
        {
            var wc         = EditorForm.Instance.WorkspaceController;
            var tipsWindow = wc.FindWindow <TipsWindow>();

            if (tipsWindow != null)
            {
                wc.SelectDockWindow(tipsWindow);
            }
            else
            {
                var document = new DocumentInstance("", null, "");
                Documents.Add(document);

                var window = new TipsWindow();
                window.InitDocumentWindow(document, null, false, null);

                wc.AddDockWindow(window, true, true);
            }
        }
Exemplo n.º 22
0
        static DocumentWindow CreateWindowImpl(DocumentInstance document, object obj, bool openAsSettings)
        {
            Type type = null;

            if (openAsSettings)
            {
                type = typeof(ObjectSettingsWindow);
            }
            else if (document.SpecialMode == "TextEditor")
            {
                type = EditorAssemblyInterface.Instance.GetTypeByName("NeoAxis.Editor.TextEditorDocumentWindow");                  // typeof( TextEditorDocumentWindow );
            }
            else
            {
                type = GetDocumentWindowClass(obj) ?? GetWindowClassFromFileName(document.RealFileName) ?? typeof(DocumentWindow);
            }

            var window = (DocumentWindow)Activator.CreateInstance(type);

            window.InitDocumentWindow(document, obj, openAsSettings, null);
            return(window);
        }
Exemplo n.º 23
0
        public static DocumentInstance OpenStartPage()
        {
            //select already opened
            var w = FindWindow <StartPageWindow>();

            if (w != null)
            {
                SelectDockWindow(w);
                return(w.Document);
            }

            var document = new DocumentInstance("", null, "");

            Documents.Add(document);

            var window = new StartPageWindow();

            window.InitDocumentWindow(document, null, false, null);

            EditorForm.Instance.WorkspaceController.AddDockWindow(window, false, true);

            return(document);
        }
        private void Document_SaveEvent(DocumentInstance document, string saveAsFileName, ref bool handled, ref bool result)
        {
            if (Destroyed)
            {
                return;
            }

            var realFileName = Document.RealFileName;

            if (!string.IsNullOrEmpty(realFileName))
            {
                handled = true;
                try
                {
                    File.WriteAllText(realFileName, Data);
                    result = true;
                }
                catch (Exception e)
                {
                    Log.Error($"Unable to write file \'{realFileName}\'. " + e.Message);
                    result = false;
                }
            }
        }
Exemplo n.º 25
0
        //

        public UndoActionComponentCreateDelete(DocumentInstance document, ICollection <Component> objects, bool create)         //, bool callDeleteObjects )
        {
            this.document = document;
            this.objects  = new List <Component>(objects);
            this.create   = create;

            //sort objects by parent index
            if (!create)
            {
                CollectionUtility.InsertionSort(this.objects, delegate(Component c1, Component c2)
                {
                    if (c1.Parent != null && c1.Parent == c2.Parent)
                    {
                        return(c1.Parent.Components.IndexOf(c1) - c2.Parent.Components.IndexOf(c2));
                    }
                    return(0);
                });
            }

            if (!create)             //&& callDeleteObjects )
            {
                DeleteObjects();
            }
        }
Exemplo n.º 26
0
 public ScriptDocumentForCSharpFile(DocumentInstance document)
 {
     this.document = document;
 }
Exemplo n.º 27
0
        public static DocumentWindow OpenDocumentWindowForObject(DocumentInstance document, object obj)          //, bool canUseAlreadyOpened )
        {
            if (!IsDocumentObjectSupport(obj))
            {
                return(null);
            }

            //another document or no document
            {
                var objectToDocument = GetDocumentByObject(obj);
                if (objectToDocument == null || objectToDocument != document)
                {
                    var component = obj as Component;
                    if (component != null)
                    {
                        var fileName = ComponentUtility.GetOwnedFileNameOfComponent(component);
                        if (!string.IsNullOrEmpty(fileName))
                        {
                            var realFileName = VirtualPathUtility.GetRealPathByVirtual(fileName);

                            if (IsDocumentFileSupport(realFileName))
                            {
                                var documentWindow = OpenFileAsDocument(realFileName, true, true) as DocumentWindow;
                                if (documentWindow != null)
                                {
                                    var newDocument = documentWindow.Document;
                                    var newObject   = newDocument.ResultComponent.Components[component.GetPathFromRoot()];
                                    if (newObject != null)
                                    {
                                        return(OpenDocumentWindowForObject(newDocument, newObject));
                                    }
                                }

                                return(null);
                            }
                        }
                    }

                    return(null);
                }
            }

            //check for already opened
            var canUseAlreadyOpened = !EditorForm.ModifierKeys.HasFlag(Keys.Shift);

            if (canUseAlreadyOpened)
            {
                var openedWindow = EditorForm.Instance.WorkspaceController.FindWindowRecursive(document, obj);
                if (openedWindow != null)
                {
                    EditorForm.Instance.WorkspaceController.SelectDockWindow(openedWindow);
                    return(openedWindow);
                }
            }

            //create document window
            var window = CreateWindowImpl(document, obj, false);

            //!!!!
            bool floatingWindow = false;
            bool select         = true;

            EditorForm.Instance.WorkspaceController.AddDockWindow(window, floatingWindow, select);

            return(window);
        }
Exemplo n.º 28
0
 public IDocumentWindow FindWindow(DocumentInstance doc)
 {
     return(FindWindow <IDocumentWindow>(w => w.Document == doc));
 }
Exemplo n.º 29
0
        public static void PerformOverridePropertySetValue(HCItemProperty.PropertySetValueData data)
        {
            OverridePropertySetValue?.Invoke(data);

            var property = data.itemProperty.Property;

            //Transform: Position, Rotation, Scale
            if (data.parentItemProperty != null && ReferenceUtility.GetUnreferencedType(data.parentItemProperty.Property.Type.GetNetType()) == typeof(Transform))
            {
                for (int n = 0; n < data.itemProperty.ControlledObjects.Length; n++)
                {
                    var old = data.itemProperty.ControlledObjects[n];
                    if (property.Name == "Position")
                    {
                        data.itemProperty.ControlledObjects[n] = old.GetType().GetMethod("UpdatePosition").Invoke(old, new object[] { data.value });
                    }
                    else if (property.Name == "Rotation")
                    {
                        data.itemProperty.ControlledObjects[n] = old.GetType().GetMethod("UpdateRotation").Invoke(old, new object[] { data.value });
                    }
                    else if (property.Name == "Scale")
                    {
                        data.itemProperty.ControlledObjects[n] = old.GetType().GetMethod("UpdateScale").Invoke(old, new object[] { data.value });
                    }
                }

                data.setValueHandled = true;
            }

            //array: Length
            if (property.Name == "Length")
            {
                var ownerType = property.Owner as Metadata.TypeInfo;
                if (ownerType != null && ownerType.GetNetType() == typeof(Array))                   // HCItemProperty.IsOneDimensionArray( ownerType.GetNetType() ) )
                {
                    int newLength = (int)data.unrefValue;

                    for (int nCollectedObject = 0; nCollectedObject < data.parentItemProperty.ControlledObjects.Length; nCollectedObject++)
                    {
                        var array = (IList)ReferenceUtility.GetUnreferencedValue(data.itemProperty.ControlledObjects[nCollectedObject]);
                        if (array != null && array.Count != newLength)
                        {
                            var newArray = Array.CreateInstance(array.GetType().GetElementType(), newLength);
                            Array.Copy((Array)array, newArray, Math.Min(newLength, array.Count));

                            //!!!!multiselection. вместе undo все

                            data.parentItemProperty.SetValue(newArray, data.addUndo);
                        }
                    }

                    data.setValueHandled             = true;
                    data.addUndoHandled              = true;
                    data.updateParentPropertyHandled = true;
                }
            }

            //List: Count
            if (property.Name == "Count")
            {
                var ownerType = property.Owner as Metadata.TypeInfo;
                if (ownerType != null && HCItemProperty.IsListType(ownerType.GetNetType()))
                {
                    int newCount = (int)data.unrefValue;

                    for (int nCollectedObject = 0; nCollectedObject < data.parentItemProperty.ControlledObjects.Length; nCollectedObject++)
                    {
                        var list = (IList)ReferenceUtility.GetUnreferencedValue(data.itemProperty.ControlledObjects[nCollectedObject]);
                        if (list != null)
                        {
                            if (newCount < list.Count)
                            {
                                //remove items

                                if (!data.addUndoHandled && data.addUndo && data.itemProperty.Owner.DocumentWindow?.Document != null)
                                {
                                    //remove with undo

                                    var indexes = new List <int>();
                                    for (int n = newCount; n < list.Count; n++)
                                    {
                                        indexes.Add(n);
                                    }
                                    var undoAction = new UndoActionListAddRemove(list, indexes, false);

                                    DocumentInstance document = data.itemProperty.Owner.DocumentWindow.Document;
                                    document.UndoSystem.CommitAction(undoAction);
                                    document.Modified = true;
                                }
                                else
                                {
                                    //remove without undo
                                    while (list.Count > newCount)
                                    {
                                        list.RemoveAt(list.Count - 1);
                                    }
                                }
                            }
                            else if (newCount > list.Count)
                            {
                                //add items

                                var indexes = new List <int>();
                                for (int n = list.Count; n < newCount; n++)
                                {
                                    indexes.Add(n);
                                }

                                var elementType = list.GetType().GetGenericArguments()[0];
                                while (list.Count < newCount)
                                {
                                    object itemValue     = null;
                                    var    referenceList = list as IReferenceList;
                                    if (referenceList != null)
                                    {
                                        itemValue = Activator.CreateInstance(referenceList.GetItemType());                                          // referenceList.CreateItemValue();
                                    }
                                    else if (elementType.IsValueType)
                                    {
                                        itemValue = Activator.CreateInstance(elementType);
                                    }
                                    list.Add(itemValue);
                                }

                                //undo
                                if (!data.addUndoHandled && data.addUndo && data.itemProperty.Owner.DocumentWindow?.Document != null)
                                {
                                    var undoAction = new UndoActionListAddRemove(list, indexes, true);

                                    DocumentInstance document = data.itemProperty.Owner.DocumentWindow.Document;
                                    document.UndoSystem.CommitAction(undoAction);
                                    document.Modified = true;
                                }
                            }
                        }
                    }

                    data.setValueHandled             = true;
                    data.addUndoHandled              = true;
                    data.updateParentPropertyHandled = true;
                }
            }
        }
 public override void InitDocumentWindow(DocumentInstance document, object objectOfWindow, bool openAsSettings, Dictionary <string, object> windowTypeSpecificOptions)
 {
     base.InitDocumentWindow(document, objectOfWindow, openAsSettings, windowTypeSpecificOptions);
 }