Download

Show/hide window from plugin?

I’m trying to setup a toggle button to hide/show the World Outliner window using a c++ plugin

this is the code to create the toolbar button, when pressed it shows a text message at PluginButtonClicked()

ExpandedEditor.h

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"

class FToolBarBuilder;
class FMenuBuilder;

class FExpandedEditorModule : public IModuleInterface
{
public:

	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;
	
	/** This function will be bound to Command. */
	void PluginButtonClicked();
	
private:

	void RegisterMenus();


private:
	TSharedPtr<class FUICommandList> PluginCommands;
};

ExpandedEditor.cpp

// Copyright Epic Games, Inc. All Rights Reserved.

#include "ExpandedEditor.h"
#include "ExpandedEditorStyle.h"
#include "ExpandedEditorCommands.h"
#include "Misc/MessageDialog.h"
#include "ToolMenus.h"

static const FName ExpandedEditorTabName("My Toolbar Button");

#define LOCTEXT_NAMESPACE "FExpandedEditorModule"

void FExpandedEditorModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
	
	FExpandedEditorStyle::Initialize();
	FExpandedEditorStyle::ReloadTextures();

	FExpandedEditorCommands::Register();
	
	PluginCommands = MakeShareable(new FUICommandList);

	PluginCommands->MapAction(
		FExpandedEditorCommands::Get().PluginAction,
		FExecuteAction::CreateRaw(this, &FExpandedEditorModule::PluginButtonClicked),
		FCanExecuteAction());

	UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateRaw(this, &FExpandedEditorModule::RegisterMenus));
}

void FExpandedEditorModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.

	UToolMenus::UnRegisterStartupCallback(this);

	UToolMenus::UnregisterOwner(this);

	FExpandedEditorStyle::Shutdown();

	FExpandedEditorCommands::Unregister();
}

void FExpandedEditorModule::PluginButtonClicked()
{
	// Put your "OnButtonClicked" stuff here
	FText DialogText = FText::Format(
							LOCTEXT("PluginButtonDialogText", "Add code to {0} in {1} to override this button's actions"),
							FText::FromString(TEXT("FExpandedEditorModule::PluginButtonClicked()")),
							FText::FromString(TEXT("ExpandedEditor.cpp"))
					   );
	FMessageDialog::Open(EAppMsgType::Ok, DialogText);
}

void FExpandedEditorModule::RegisterMenus()
{
	// Owner will be used for cleanup in call to UToolMenus::UnregisterOwner
	FToolMenuOwnerScoped OwnerScoped(this);

	{
		UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Window");
		{
			FToolMenuSection& Section = Menu->FindOrAddSection("WindowLayout");
			Section.AddMenuEntryWithCommandList(FExpandedEditorCommands::Get().PluginAction, PluginCommands);
		}
	}

	{
		UToolMenu* ToolbarMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar");
		{
			FToolMenuSection& Section = ToolbarMenu->FindOrAddSection("Settings");
			{
				FToolMenuEntry& Entry = Section.AddEntry(FToolMenuEntry::InitToolBarButton(FExpandedEditorCommands::Get().PluginAction));
				Entry.SetCommandList(PluginCommands);
			}
		}
	}
}

#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FExpandedEditorModule, ExpandedEditor)

I don’t know how to invoke the close button on the World Outliner tab (to hide/close it)

// get World Outliner tab and invoke close button
// ...?

nor do I know how to invoke the menu item to show it again

// get menu
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Window");

// find menu item and invoke the command
// ...?

any clue about what classes or methods do I have to use?