Skip to content

Commit

Permalink
Merge pull request #95 from PlasticSCM/1003832-display-current-branch
Browse files Browse the repository at this point in the history
Displaying the name of the current branch in the status bar
  • Loading branch information
SRombautsU authored Oct 30, 2023
2 parents 7bccb8a + d9c6429 commit af67247
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "PlasticSourceControlModule.h"
#include "PlasticSourceControlProvider.h"
#include "PlasticSourceControlOperations.h"
#include "SPlasticSourceControlStatusBar.h"

#include "ISourceControlModule.h"
#include "ISourceControlOperation.h"
Expand Down Expand Up @@ -37,6 +38,7 @@

FName FPlasticSourceControlMenu::UnityVersionControlMainMenuOwnerName = TEXT("UnityVersionControlMenu");
FName FPlasticSourceControlMenu::UnityVersionControlAssetContextLocksMenuOwnerName = TEXT("UnityVersionControlContextLocksMenu");
FName FPlasticSourceControlMenu::UnityVersionControlStatusBarMenuOwnerName = TEXT("UnityVersionControlStatusBarMenu");

void FPlasticSourceControlMenu::Register()
{
Expand All @@ -48,6 +50,8 @@ void FPlasticSourceControlMenu::Register()
// Register the menu extensions with the level editor
ExtendRevisionControlMenu();
ExtendAssetContextMenu();

ExtendToolbarWithStatusBarWidget();
}

void FPlasticSourceControlMenu::Unregister()
Expand All @@ -73,11 +77,25 @@ void FPlasticSourceControlMenu::Unregister()
{
ToolMenus->UnregisterOwnerByName(UnityVersionControlMainMenuOwnerName);
ToolMenus->UnregisterOwnerByName(UnityVersionControlAssetContextLocksMenuOwnerName);
ToolMenus->UnregisterOwnerByName(UnityVersionControlStatusBarMenuOwnerName);
bHasRegistered = false;
}
#endif
}

void FPlasticSourceControlMenu::ExtendToolbarWithStatusBarWidget()
{
#if ENGINE_MAJOR_VERSION == 5
const FToolMenuOwnerScoped SourceControlMenuOwner(UnityVersionControlStatusBarMenuOwnerName);

UToolMenu* ToolbarMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.StatusBar.ToolBar");
FToolMenuSection& Section = ToolbarMenu->AddSection("Unity Version Control", FText::GetEmpty(), FToolMenuInsert("SourceControl", EToolMenuInsertType::Before));

Section.AddEntry(
FToolMenuEntry::InitWidget("UnityVersionControlStatusBar", SNew(SPlasticSourceControlStatusBar), FText::GetEmpty(), true, false)
);
#endif
}

void FPlasticSourceControlMenu::ExtendRevisionControlMenu()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class FPlasticSourceControlMenu
void AddMenuExtension(FToolMenuSection& Menu);
#endif

/** Extends the UE5 toolbar with a status bar widget to display the current branch and open the branch tab */
void ExtendToolbarWithStatusBarWidget();

/** Extends the main Revision Control menu from the toolbar at the bottom-right. */
void ExtendRevisionControlMenu();
/** Extends the content browser asset context menu with Admin revision control options. */
Expand Down Expand Up @@ -77,6 +80,8 @@ class FPlasticSourceControlMenu
static FName UnityVersionControlMainMenuOwnerName;
/** Name of the asset context menu extension for admin actions over Locks */
static FName UnityVersionControlAssetContextLocksMenuOwnerName;
/** Name of status bar extension to display the current branch */
static FName UnityVersionControlStatusBarMenuOwnerName;

/** Delegates called when a source control operation has completed */
void OnSyncAllOperationComplete(const FSourceControlOperationRef& InOperation, ECommandResult::Type InResult);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2023 Unity Technologies

#include "SPlasticSourceControlStatusBar.h"

#include "PlasticSourceControlModule.h"

#include "Runtime/Launch/Resources/Version.h"
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
#include "Styling/AppStyle.h"
#else
#include "EditorStyleSet.h"
#endif
#include "Styling\SlateTypes.h"

#define LOCTEXT_NAMESPACE "PlasticSourceControl"

void SPlasticSourceControlStatusBar::Construct(const FArguments& InArgs)
{
ChildSlot
[
SNew(SButton)
.ContentPadding(FMargin(6.0f, 0.0f))
.ToolTipText(LOCTEXT("PlasticBranches_Tooltip", "Current branch"))
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
.ButtonStyle(FAppStyle::Get(), "SimpleButton")
#else
.ButtonStyle(FEditorStyle::Get(), "SimpleButton")
#endif
.OnClicked(this, &SPlasticSourceControlStatusBar::OnClicked)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
[
SNew(SImage)
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
.Image(FAppStyle::GetBrush("SourceControl.Branch"))
#else
.Image(FEditorStyle::GetBrush("SourceControl.Branch"))
#endif
]
+ SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
.Padding(FMargin(5, 0, 0, 0))
[
SNew(STextBlock)
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
.TextStyle(&FAppStyle::Get().GetWidgetStyle<FTextBlockStyle>("NormalText"))
#else
.TextStyle(&FEditorStyle::Get().GetWidgetStyle<FTextBlockStyle>("NormalText"))
#endif
.Text_Lambda([this]() { return GetStatusBarText(); })
]
]
];
}

FText SPlasticSourceControlStatusBar::GetStatusBarText() const
{;
return FText::FromString(FPlasticSourceControlModule::Get().GetProvider().GetBranchName());
}

FReply SPlasticSourceControlStatusBar::OnClicked()
{
return FReply::Handled();
}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2023 Unity Technologies

#pragma once

#include "CoreMinimal.h"

#include "Widgets/SCompoundWidget.h"

/**
* Status bar displaying the name of the current branch
*/
class SPlasticSourceControlStatusBar : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SPlasticSourceControlStatusBar) {}
SLATE_END_ARGS()

void Construct(const FArguments& InArgs);

private:
FText GetStatusBarText() const;

FReply OnClicked();
};

0 comments on commit af67247

Please sign in to comment.