Skip to content

Commit

Permalink
Merge pull request #97 from PlasticSCM/1004271-visualize-list-of-bran…
Browse files Browse the repository at this point in the history
…ches

Visualize the list of branches
  • Loading branch information
juliomaqueda authored Nov 17, 2023
2 parents 6489c78 + 8d77958 commit 5026cca
Show file tree
Hide file tree
Showing 20 changed files with 1,432 additions and 7 deletions.
33 changes: 33 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlBranch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023 Unity Technologies

#pragma once

#include "CoreMinimal.h"

class FPlasticSourceControlBranch
{
public:
FPlasticSourceControlBranch() = default;
FPlasticSourceControlBranch(const FString& InName, const FString& InRepository, const FString& InCreatedBy, const FDateTime& InDate, const FString& InComment)
: Name(InName)
, Repository(InRepository)
, CreatedBy(InCreatedBy)
, Date(InDate)
, Comment(InComment)
{}
FString Name;
FString Repository;
FString CreatedBy;
FDateTime Date;
FString Comment;

void PopulateSearchString(TArray<FString>& OutStrings) const
{
OutStrings.Emplace(Name);
OutStrings.Emplace(CreatedBy);
OutStrings.Emplace(Comment);
}
};

typedef TSharedRef<class FPlasticSourceControlBranch, ESPMode::ThreadSafe> FPlasticSourceControlBranchRef;
typedef TSharedPtr<class FPlasticSourceControlBranch, ESPMode::ThreadSafe> FPlasticSourceControlBranchPtr;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2023 Unity Technologies

#include "PlasticSourceControlBranchesWindow.h"

#include "Widgets/Docking/SDockTab.h"

#include "PlasticSourceControlStyle.h"
#include "SPlasticSourceControlBranchesWidget.h"

#define LOCTEXT_NAMESPACE "PlasticSourceControlWindow"

static const FName PlasticSourceControlWindowTabName("PlasticSourceControlWindow");

void FPlasticSourceControlBranchesWindow::Register()
{
FPlasticSourceControlStyle::Initialize();
FPlasticSourceControlStyle::ReloadTextures();

FGlobalTabmanager::Get()->RegisterNomadTabSpawner(PlasticSourceControlWindowTabName, FOnSpawnTab::CreateRaw(this, &FPlasticSourceControlBranchesWindow::OnSpawnTab))
.SetDisplayName(LOCTEXT("PlasticSourceControlWindowTabTitle", "View Branches"))
.SetMenuType(ETabSpawnerMenuType::Hidden)
.SetIcon(FSlateIcon(FPlasticSourceControlStyle::Get().GetStyleSetName(), "PlasticSourceControl.PluginIcon.Small"));
}

void FPlasticSourceControlBranchesWindow::Unregister()
{
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(PlasticSourceControlWindowTabName);

FPlasticSourceControlStyle::Shutdown();
}

TSharedRef<SDockTab> FPlasticSourceControlBranchesWindow::OnSpawnTab(const FSpawnTabArgs& SpawnTabArgs)
{
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
CreateBranchesWidget().ToSharedRef()
];
}

void FPlasticSourceControlBranchesWindow::OpenTab()
{
FGlobalTabmanager::Get()->TryInvokeTab(PlasticSourceControlWindowTabName);
}

TSharedPtr<SWidget> FPlasticSourceControlBranchesWindow::CreateBranchesWidget()
{
return SNew(SPlasticSourceControlBranchesWidget);
}

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

#pragma once

#include "CoreMinimal.h"

// Nomad tab window to hold the widget with the list of branches, see SPlasticSourceControlBranchesWidget
class FPlasticSourceControlBranchesWindow
{
public:
void Register();
void Unregister();

void OpenTab();

private:
TSharedRef<class SDockTab> OnSpawnTab(const class FSpawnTabArgs& SpawnTabArgs);

TSharedPtr<SWidget> CreateBranchesWidget();
};
53 changes: 47 additions & 6 deletions Source/PlasticSourceControl/Private/PlasticSourceControlMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "PlasticSourceControlMenu.h"

#include "PlasticSourceControlBranchesWindow.h"
#include "PlasticSourceControlModule.h"
#include "PlasticSourceControlProvider.h"
#include "PlasticSourceControlOperations.h"
Expand Down Expand Up @@ -111,15 +112,21 @@ void FPlasticSourceControlMenu::ExtendRevisionControlMenu()
}
#elif ENGINE_MAJOR_VERSION == 5
const FToolMenuOwnerScoped SourceControlMenuOwner(UnityVersionControlMainMenuOwnerName);
if (UToolMenus* ToolMenus = UToolMenus::Get())

if (UToolMenu* SourceControlMenu = UToolMenus::Get()->ExtendMenu("StatusBar.ToolBar.SourceControl"))
{
if (UToolMenu* SourceControlMenu = ToolMenus->ExtendMenu("StatusBar.ToolBar.SourceControl"))
{
FToolMenuSection& Section = SourceControlMenu->AddSection("PlasticSourceControlActions", LOCTEXT("PlasticSourceControlMenuHeadingActions", "Unity Version Control"), FToolMenuInsert(NAME_None, EToolMenuInsertType::First));
FToolMenuSection& Section = SourceControlMenu->AddSection("PlasticSourceControlActions", LOCTEXT("PlasticSourceControlMenuHeadingActions", "Unity Version Control"), FToolMenuInsert(NAME_None, EToolMenuInsertType::First));

AddMenuExtension(Section);
AddMenuExtension(Section);

bHasRegistered = true;
bHasRegistered = true;
}

if (UToolMenu* ToolsMenu = UToolMenus::Get()->ExtendMenu("MainFrame.MainMenu.Tools"))
{
if (FToolMenuSection* Section = ToolsMenu->FindSection("Source Control"))
{
AddViewBranches(*Section);
}
}
#endif
Expand Down Expand Up @@ -556,6 +563,11 @@ void FPlasticSourceControlMenu::VisitLockRulesURLClicked(const FString InOrganiz
FPlatformProcess::LaunchURL(*OrganizationLockRulesURL, NULL, NULL);
}

void FPlasticSourceControlMenu::OpenBranchesWindow() const
{
FPlasticSourceControlModule::Get().GetBranchesWindow().OpenTab();
}

// Display an ongoing notification during the whole operation
void FPlasticSourceControlMenu::DisplayInProgressNotification(const FText& InOperationInProgressString)
{
Expand Down Expand Up @@ -647,6 +659,7 @@ void FPlasticSourceControlMenu::OnSourceControlOperationComplete(const FSourceCo
}
}

// TODO rework the menus with sub-menus like in the POC branch
#if ENGINE_MAJOR_VERSION == 4
void FPlasticSourceControlMenu::AddMenuExtension(FMenuBuilder& Menu)
#elif ENGINE_MAJOR_VERSION == 5
Expand Down Expand Up @@ -836,6 +849,34 @@ void FPlasticSourceControlMenu::AddMenuExtension(FToolMenuSection& Menu)
)
);
}

AddViewBranches(Menu);
}

#if ENGINE_MAJOR_VERSION == 4
void FPlasticSourceControlMenu::AddViewBranches(FMenuBuilder& Menu)
#elif ENGINE_MAJOR_VERSION == 5
void FPlasticSourceControlMenu::AddViewBranches(FToolMenuSection& Menu)
#endif
{
Menu.AddMenuEntry(
#if ENGINE_MAJOR_VERSION == 5
TEXT("PlasticBranchesWindow"),
#endif
LOCTEXT("PlasticBranchesWindow", "View Branches"),
LOCTEXT("PlasticBranchesWindowTooltip", "Open the Branches window."),
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
FSlateIcon(FAppStyle::GetAppStyleSetName(), "SourceControl.Branch"),
#elif ENGINE_MAJOR_VERSION == 5
FSlateIcon(FEditorStyle::GetStyleSetName(), "SourceControl.Branch"),
#elif ENGINE_MAJOR_VERSION == 4
FSlateIcon(FEditorStyle::GetStyleSetName(), "SourceControl.Branch"),
#endif
FUIAction(
FExecuteAction::CreateRaw(this, &FPlasticSourceControlMenu::OpenBranchesWindow),
FCanExecuteAction()
)
);
}

#if ENGINE_MAJOR_VERSION == 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FPlasticSourceControlMenu
void VisitDocsURLClicked() const;
void VisitSupportURLClicked() const;
void VisitLockRulesURLClicked(const FString InOrganizationName) const;
void OpenBranchesWindow() const;

private:
bool IsSourceControlConnected() const;
Expand All @@ -37,10 +38,12 @@ class FPlasticSourceControlMenu

#if ENGINE_MAJOR_VERSION == 4
void AddMenuExtension(FMenuBuilder& Menu);
void AddViewBranches(FMenuBuilder& Menu);

TSharedRef<class FExtender> OnExtendLevelEditorViewMenu(const TSharedRef<class FUICommandList> CommandList);
#elif ENGINE_MAJOR_VERSION == 5
void AddMenuExtension(FToolMenuSection& Menu);
void AddViewBranches(FToolMenuSection& Menu);
#endif

/** Extends the UE5 toolbar with a status bar widget to display the current branch and open the branch tab */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ void FPlasticSourceControlModule::StartupModule()

// Bind our source control provider to the editor
IModularFeatures::Get().RegisterModularFeature("SourceControl", &PlasticSourceControlProvider);

/// Register our tab Window here as it needs to be ready for the editor to reload at startup
PlasticSourceControlBranchesWindow.Register();
}

void FPlasticSourceControlModule::ShutdownModule()
{
// shut down the provider, as this module is going away
PlasticSourceControlProvider.Close();

PlasticSourceControlBranchesWindow.Unregister();

// unbind provider from editor
IModularFeatures::Get().UnregisterModularFeature("SourceControl", &PlasticSourceControlProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "PlasticSourceControlProvider.h"
#include "PlasticSourceControlWorkspaceCreation.h"

#include "PlasticSourceControlBranchesWindow.h"

/**
* PlasticSourceControl is the official Unity Version Control Plugin for Unreal Engine
*
Expand Down Expand Up @@ -36,6 +38,11 @@ class FPlasticSourceControlModule : public IModuleInterface
return PlasticSourceControlWorkspaceCreation;
}

FPlasticSourceControlBranchesWindow& GetBranchesWindow()
{
return PlasticSourceControlBranchesWindow;
}

/**
* Singleton-like access to this module's interface. This is just for convenience!
* Beware of calling this during the shutdown phase, though. Your module might have been unloaded already.
Expand All @@ -60,6 +67,8 @@ class FPlasticSourceControlModule : public IModuleInterface
/** The Plastic source control provider */
FPlasticSourceControlProvider PlasticSourceControlProvider;

FPlasticSourceControlBranchesWindow PlasticSourceControlBranchesWindow;

/** Logic to create a new workspace */
FPlasticSourceControlWorkspaceCreation PlasticSourceControlWorkspaceCreation;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "PlasticSourceControlOperations.h"

#include "PackageUtils.h"
#include "PlasticSourceControlBranch.h"
#include "PlasticSourceControlCommand.h"
#include "PlasticSourceControlModule.h"
#include "PlasticSourceControlProvider.h"
Expand Down Expand Up @@ -46,6 +47,7 @@ void IPlasticSourceControlWorker::RegisterWorkers(FPlasticSourceControlProvider&
PlasticSourceControlProvider.RegisterWorker("RevertAll", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticRevertAllWorker>));
PlasticSourceControlProvider.RegisterWorker("SwitchToPartialWorkspace", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticSwitchToPartialWorkspaceWorker>));
PlasticSourceControlProvider.RegisterWorker("Unlock", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticUnlockWorker>));
PlasticSourceControlProvider.RegisterWorker("GetBranches", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticGetBranchesWorker>));
PlasticSourceControlProvider.RegisterWorker("MakeWorkspace", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticMakeWorkspaceWorker>));
PlasticSourceControlProvider.RegisterWorker("Sync", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticSyncWorker>));
PlasticSourceControlProvider.RegisterWorker("SyncAll", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticSyncWorker>));
Expand Down Expand Up @@ -133,6 +135,16 @@ FText FPlasticUnlock::GetInProgressString() const
return LOCTEXT("SourceControl_Unlock_Release", "Releasing Lock(s)...");
}

FName FPlasticGetBranches::GetName() const
{
return "GetBranches";
}

FText FPlasticGetBranches::GetInProgressString() const
{
return LOCTEXT("SourceControl_GetBranches", "Getting the list of branches...");
}


static bool AreAllFiles(const TArray<FString>& InFiles)
{
Expand Down Expand Up @@ -1012,6 +1024,39 @@ bool FPlasticUnlockWorker::UpdateStates()
return PlasticSourceControlUtils::UpdateCachedStates(MoveTemp(States));
}


FName FPlasticGetBranchesWorker::GetName() const
{
return "GetBranches";
}

bool FPlasticGetBranchesWorker::Execute(FPlasticSourceControlCommand& InCommand)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FPlasticGetPendingChangelistsWorker::Execute);

check(InCommand.Operation->GetName() == GetName());
TSharedRef<FPlasticGetBranches, ESPMode::ThreadSafe> Operation = StaticCastSharedRef<FPlasticGetBranches>(InCommand.Operation);

{
const FDateTime& FromDate = Operation->FromDate;
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunGetBranches(FromDate, Operation->Branches, InCommand.ErrorMessages);
}

{
FString RepositoryName, ServerUrl;
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::GetWorkspaceInfo(CurrentBranchName, RepositoryName, ServerUrl, InCommand.ErrorMessages);
}

return InCommand.bCommandSuccessful;
}

bool FPlasticGetBranchesWorker::UpdateStates()
{
GetProvider().SetBranchName(MoveTemp(CurrentBranchName));

return false;
}

FName FPlasticUpdateStatusWorker::GetName() const
{
return "UpdateStatus";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#endif

class FPlasticSourceControlProvider;
typedef TSharedRef<class FPlasticSourceControlBranch, ESPMode::ThreadSafe> FPlasticSourceControlBranchRef;


/**
* Internal operation used to revert checked-out unchanged files
Expand Down Expand Up @@ -114,6 +116,25 @@ class FPlasticUnlock final : public ISourceControlOperation
};


/**
* Internal operation to list branches, aka "cm find branch"
*/
class FPlasticGetBranches final : public ISourceControlOperation
{
public:
// ISourceControlOperation interface
virtual FName GetName() const override;

virtual FText GetInProgressString() const override;

// Limit the list of branches to ones created from this date
FDateTime FromDate;

// List of branches found
TArray<FPlasticSourceControlBranchRef> Branches;
};


/** Called when first activated on a project, and then at project load time.
* Look for the root directory of the Plastic workspace (where the ".plastic/" subdirectory is located). */
class FPlasticConnectWorker final : public IPlasticSourceControlWorker
Expand Down Expand Up @@ -337,6 +358,23 @@ class FPlasticUnlockWorker final : public IPlasticSourceControlWorker
TArray<FPlasticSourceControlState> States;
};

/** list branches. */
class FPlasticGetBranchesWorker final : public IPlasticSourceControlWorker
{
public:
explicit FPlasticGetBranchesWorker(FPlasticSourceControlProvider& InSourceControlProvider)
: IPlasticSourceControlWorker(InSourceControlProvider)
{}
virtual ~FPlasticGetBranchesWorker() = default;
// IPlasticSourceControlWorker interface
virtual FName GetName() const override;
virtual bool Execute(class FPlasticSourceControlCommand& InCommand) override;
virtual bool UpdateStates() override;

// Current branch the workspace is on
FString CurrentBranchName;
};

/** Plastic update the workspace to latest changes */
class FPlasticSyncWorker final : public IPlasticSourceControlWorker
{
Expand Down
Loading

0 comments on commit 5026cca

Please sign in to comment.