Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Circuit Editor Instances. #11

Closed
RomainBL opened this issue Jun 2, 2014 · 4 comments
Closed

Multiple Circuit Editor Instances. #11

RomainBL opened this issue Jun 2, 2014 · 4 comments

Comments

@RomainBL
Copy link

RomainBL commented Jun 2, 2014

Hello,

Thanks for sharing your great work.

I would like to use multiple instance of the circuit editor and each of these instances will edit a different file extension but using the same schema (I know it’s a bit weird). The circuit editor will be a generic nodal editor.

The first approach was to simply instantiate multiple CircuitEditor but quickly I realized the use of a lot of static in the code (Command, Schema, EditorInfo...). I started to convert or move these static variables. I think I nearly succeed. The last problem where I struggle is the possibility to have one file extension per circuit editor instance. Also, I found other static variable which I don’t know if I need to change it (like Direct2D variable s_gfx.)

The second approach was to duplicate the circuit editor project, but I don’t want to go that way.

Do you have a better solution in mind ? or any advices ?

@Ron2
Copy link
Member

Ron2 commented Jun 2, 2014

Hello, I'm glad to hear that you're diving into ATF and we hope it proves useful to you!

The editors in general, like CircuitEditor, are designed to be instantiated once per application session, and they work with the current editing context (which is usually a document). The IDocumentClient interface specifies the kinds of document file extensions that your app knows about. In most cases, the editor deals with just one kind of document, and so it's convenient for the editor to implement IDocumentClient. But in your case, the circuit editor should not implement IDocumentClient, and you should implement it separately, multiple times, once for each file extension, and export each IDocumentClient so that the IDocumentRegistry can find it. We happen to do this in the CodeEditor sample app:

            // create a document client for each file type
            m_txtDocumentClient = new DocumentClient(this, ".txt");
            m_csDocumentClient = new DocumentClient(this, ".cs");
            m_luaDocumentClient = new DocumentClient(this, ".lua");
            m_nutDocumentClient = new DocumentClient(this, ".nut");
            m_pyDocumentClient = new DocumentClient(this, ".py");
            m_xmlDocumentClient = new DocumentClient(this, ".xml");
            m_daeDocumentClient = new DocumentClient(this, ".dae");
            m_cgDocumentClient = new DocumentClient(this, ".cg");

...
        [Export(typeof(IDocumentClient))]
        private DocumentClient m_txtDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_csDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_luaDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_nutDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_pyDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_xmlDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_daeDocumentClient;

        [Export(typeof(IDocumentClient))]
        private DocumentClient m_cgDocumentClient;

I chatted with a coworker here, Shen, and he says that Santa Monica Studios had to do something very similar to what you're doing, where the circuit editor would open and save two kinds of circuit documents that used the same schema, but with two different file extensions. One file extension is for a "master" circuit document and another is for sub-circuits that are referenced by the master one.

--Ron

@Ron2
Copy link
Member

Ron2 commented Jun 2, 2014

I should have mentioned that you can also make a single IDocumentClient handle multiple extensions. There's a constructor of DocumentClientInfo() that can accept an array of string extensions. We do this in the ModelViewer and SimpleDomEditor sample apps.

            string[] exts = { ".atgi", ".dae" };
            m_info = new DocumentClientInfo("3D Model", exts, null, null, false);

I think you would use a single IDocumentClient that supports multiple extensions if you want the user to be able to convert one file type into another, in the Save As menu. Ctrl+N will probably behave differently, too, to ask the user what type of file they want to create. When opening a file, all the possible extensions are listed in a drop-down list.

You would use multiple IDocumentClients to have a 'New' sub-menu in the File menu that lets the user choose which type of new document to create in the menu. When saving or save-as, the user won't be able to change the file type.

@RomainBL
Copy link
Author

RomainBL commented Jun 4, 2014

Thanks for your answer.

What we finally did is for each circuit editor instance we have a specific Editor Class which derived from the main Editor Class. The member EditorInfo is now a non-static variable initialized in the constructor.

[ImportingConstructor]
public Editor(
        ...
    string extension)
        {
           EditorInfo = new DocumentClientInfo(CircuitDocument.GetDocumentType(extension), extension, null, null);
        ...
      }

The static initialization of the File Extension in the Schema loader have been removed

//            Schema.circuitDocumentType.Type.SetTag(Editor.EditorInfo);

Now we can have multiple Circuit Editor Instance, each of them manages a specific file extension but all the instances have the same schema.

@Ron2
Copy link
Member

Ron2 commented Jun 10, 2014

Sounds good! Glad you found a good solution. All of the code in the sample apps is intended to be copied and modified by our clients, so that's perfectly normal that you had to modify that Editor class.

@Ron2 Ron2 closed this as completed Jun 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants