Giter Site home page Giter Site logo

Multiple Circuit Editor Instances. about atf HOT 4 CLOSED

sonywws avatar sonywws commented on June 10, 2024
Multiple Circuit Editor Instances.

from atf.

Comments (4)

Ron2 avatar Ron2 commented on June 10, 2024

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

from atf.

Ron2 avatar Ron2 commented on June 10, 2024

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.

from atf.

RomainBL avatar RomainBL commented on June 10, 2024

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.

from atf.

Ron2 avatar Ron2 commented on June 10, 2024

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.

from atf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.