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

[Lona Studio] Update the "add" menu when new components are created #338

Closed
dabbott opened this issue Mar 12, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@dabbott
Copy link
Collaborator

commented Mar 12, 2019

Summary

The "add" menu is used to add new instances of components, "layers", to the current component's layer hierarchy.

Currently the "add" menu only scans for custom components when the UI is instantiated. This means that when new components are created, moved, or deleted, it can become stale:

Screen_Shot_2019-03-12_at_10_27_51_AM

This is pretty annoying, and usually requires restarting the app to fix. Let's make it so that the menu updates automatically. We want it to look like this (which is how it looks if you restart the app):

Screen Shot 2019-03-12 at 10 37 50 AM

Proposed Implementation

There are several steps involved, but most should reuse existing mechanisms in place for firing and responding to events.

  1. I think we should add a new event, specifically to handle filesystem-level component changes, e.g. components being created, moved, deleted. We could call the event something like onChange:fileSystem:components. Events are defined here:

    enum LonaPluginActivationEvent: String, Decodable {

  2. I think the simplest place to trigger the event is whenever the FileNavigator detects a change. For example, we could trigger it here to catch file deletions:

    fileNavigator.onDeleteFile = { path, options in
    We would also want to add handlers for onCreateFile and onMoveFile (which will need to be propagated up from the fileTree through fileNavigator, just like onDeleteFile). As an example of triggering events, see
    LonaPlugins.current.trigger(eventType: .onSaveComponent)

  3. Now we can subscribe to this new event from within the LayerListHeader. Here's the call that populates the menu that needs to be re-run

    let menu = NSMenu(items: ComponentMenu.menuItems())
    We can subscribe to our new event in init and unsubscribe in a deinit block. The file navigator demonstrates how to handle subscriptions
    private var subscriptions: [() -> Void] = []
    deinit {
    subscriptions.forEach({ sub in sub() })
    }

We might run into issues along the way and have to change the plan, but let's start with this. Let me know if you run into anything weird!

@klymenkoo

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2019

I'd like to work on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.