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

Append Unreal ContentBrowser Folder Context Menu? #59

Open
Ruka1998 opened this issue Mar 20, 2024 · 7 comments
Open

Append Unreal ContentBrowser Folder Context Menu? #59

Ruka1998 opened this issue Mar 20, 2024 · 7 comments
Labels
enhancement New feature or request unreal

Comments

@Ruka1998
Copy link

Ruka1998 commented Mar 20, 2024

FolderContextAppend

parent_path: ContentBrowser.FolderContextMenu


label: FolderContextMenu # also tried ContentBrowser.FolderContextMenu
items:
- label: TA Tool
  separator: True
  
- label: SyncToAssetByPath
  command: from utility.sync_to_asset_by_path import SyncToAssetByPath;SyncToAssetByPath()
  
- label: CheckAssets
  command: from utility.asset_check import CheckAssets;CheckAssets()

Better to have no submenu here.

@Ruka1998
Copy link
Author

Hey, I find a way listed as follows, but not sure is this a proper solution to this problem.

_abstract.py
......
elif self.items:  # submenu
+   if self.label == self._get_parent_app_node_name(parent_app_node=parent_app_node):
+      for item in self.items:
+          item.setup(parent_app_node=parent_app_node)
+   else:
       self.app_node = self._setup_sub_menu(parent_app_node=parent_app_node)
           for item in self.items:
                item.setup(parent_app_node=self.app_node)
......
+@abstractmethod
+def _get_parent_app_node_name(self, parent_app_node=None):
+    """get the default parent name for the root node, optional method"""
+    pass


unreal.py
+def _get_parent_app_node_name(self, parent_app_node: unreal.ToolMenu = None):
+    return parent_app_node.menu_name if parent_app_node else ""

@hannesdelbeke
Copy link
Owner

hannesdelbeke commented Mar 20, 2024

Hi, thank you for taking the time to post this issue.
I don't understand what is going on exactly, could you explain a bit more in detail what is going on, and what the issue is?
And how you think it should be instead.

@Ruka1998
Copy link
Author

Ruka1998 commented Mar 20, 2024

Sorry for not explaining clearly. What I hope to achieve is to directly place a MenuEntry under the root directory ContentBrowserFolderContext by configuring YAML, rather than as a SubMenuEntry.

Specifically, let's say I have a MenuEntry called AssetCheck. Its location should be ContentBrowserFolderContext->AssetCheck instead of ContentBrowserFolderContext->AnyLabel->AssetCheck.

So in the previous response, I modified the setup() method in abstract.py to ensure that in the implementation of unreal.py, it checks whether each label in items matches a specific unreal.ToolMenu's menu_name. If they match, the parent of that item is set to a specific unreal.ToolMenu.

@hannesdelbeke
Copy link
Owner

hannesdelbeke commented Mar 20, 2024

ah i see, so you want to add several menu items to an existing menu.
instead of a submenu.

i think this needs some more thought, since I can't think on what the YAML would look like for now.

should be something like this probably

existing parent
- child menuitem
- child menuitem

but i believe the current setup is to only support this

existing parent
- sub menu
  - child menuitem
  - child menuitem

i wonder if something like this would work

- label: TA Tool
  separator: True
  parent_path: ContentBrowser.FolderContextMenu
  
- label: SyncToAssetByPath
  command: from utility.sync_to_asset_by_path import SyncToAssetByPath;SyncToAssetByPath()
  parent_path: ContentBrowser.FolderContextMenu
  
- label: CheckAssets
  command: from utility.asset_check import CheckAssets;CheckAssets()
  parent_path: ContentBrowser.FolderContextMenu

@Ruka1998
Copy link
Author

Thanks for your reply, I've tried your yaml, but got this error:

LogPython: Error: Traceback (most recent call last):
LogPython: Error:   File "<string>", line 14, in <module>
LogPython: Error:   File "F:\BHD_Dev\EngineSource\Engine\Binaries\ThirdParty\Python3\Win64\lib\site-packages\unimenu\core.py", line 138, in setup
LogPython: Error:     menu_node = load(arg, app)
LogPython: Error:   File "F:\BHD_Dev\EngineSource\Engine\Binaries\ThirdParty\Python3\Win64\lib\site-packages\unimenu\core.py", line 121, in load
LogPython: Error:     return app.menu_node_class.load(arg)
LogPython: Error:   File "F:\BHD_Dev\EngineSource\Engine\Binaries\ThirdParty\Python3\Win64\lib\site-packages\unimenu\apps\_abstract.py", line 176, in load
LogPython: Error:     return cls.load_config(arg)
LogPython: Error:   File "F:\BHD_Dev\EngineSource\Engine\Binaries\ThirdParty\Python3\Win64\lib\site-packages\unimenu\apps\_abstract.py", line 189, in load_config
LogPython: Error:     menu_node = cls(**data)
LogPython: Error: TypeError: unimenu.apps.unreal.MenuNodeUnreal() argument after ** must be a mapping, not list

@hannesdelbeke
Copy link
Owner

hannesdelbeke commented Mar 20, 2024

ye because it's an array and expects dict. i need to look into that tbh
you can put items: and then indent everything

items:
- entry1
- entry2

but then i assume it ll also expect a label, will prob have to update the code


also if i remember, separator was a special case in unreal. which might make all of this more complex 😅
think it's this PR #48
if we're lucky it will just work though

@hannesdelbeke
Copy link
Owner

Hey, I find a way listed as follows, but not sure is this a proper solution to this problem

Can you put this code in a PR, i can have a look at it. but atm I don't have time.
I recently stumbled in a similar issue in Maya so will try find a solution that works for everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unreal
Projects
None yet
Development

No branches or pull requests

2 participants