How can I mimic the behavior of a path breadcrumb item? (icon, style, click behavior, etc)

I'm working on a plugin to create a specialized view reminiscent of the default path "breadcrumb" view at the top of the workspace.

My plugin currently comes up with a set of VirtualFile objects. I'd simply like to create a UI component that matches the behavior of the breadcrumb.

I was thinking that I might be able to simply instantiate a BreadcrumbsPsiItem or a BreadcrumbsItem of some sort and drop it into a JPanel but rooting through the code didn't immediately reveal an easy way of doing this.

Julian

0
Avatar
Konstantin Bulenkov

Hello Julian,
  you should subscribe to Message Bus and listen File Editor events (extend FileEditorManagerAdapter). Then override fileOpened method and insert your panel as top component into editor. Example is here BreadcrumbsLoaderComponent

0
Avatar
Permanently deleted user

Thanks Konstantin, what you've described will be very useful.

What is the best way of creating the component that looks and feels like a breadcrumb item.

Given a container I'd like to call something like container.add(new BreadcrumbItemComponent(myVirtualFile))

The expected behavior would then be (inside my container wherever it ends up being rendered) a button that has a full set of click and right click behaviors. Furthermore, it should have an icon depending on the type of VirtualFile being referenced. (assuming VirtualFile encodes this sort of information.. if it doesn't, I can probably figure out how to get a PSIFile instead).

It occurs to me that the tab headings have a very similar component.. I'll look into how these are doing it and hope that whatever they're using will support folders as well.

0

请先登录再写评论。