Skip to content

Commit

Permalink
Merge pull request #106 from PlasticSCM/1003908-open-desktop-app
Browse files Browse the repository at this point in the history
Implement FPlasticSourceControlMenu::OpenDeskoptApp()
  • Loading branch information
juliomaqueda committed Jan 19, 2024
2 parents ad7a249 + 38f8bdd commit 15d87f9
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
Binary file added Resources/gluon.ico
Binary file not shown.
47 changes: 45 additions & 2 deletions Source/PlasticSourceControl/Private/PlasticSourceControlMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include "PlasticSourceControlBranchesWindow.h"
#include "PlasticSourceControlModule.h"
#include "PlasticSourceControlProvider.h"
#include "PlasticSourceControlOperations.h"
#include "PlasticSourceControlProvider.h"
#include "PlasticSourceControlStyle.h"
#include "PlasticSourceControlUtils.h"
#include "SPlasticSourceControlStatusBar.h"

#include "ISourceControlModule.h"
Expand All @@ -14,9 +16,10 @@

#include "ContentBrowserMenuContexts.h"
#include "Interfaces/IPluginManager.h"
#include "Modules/ModuleManager.h"
#include "HAL/PlatformProcess.h"
#include "LevelEditor.h"
#include "Misc/MessageDialog.h"
#include "Modules/ModuleManager.h"
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
#include "Styling/AppStyle.h"
#else
Expand Down Expand Up @@ -529,6 +532,21 @@ void FPlasticSourceControlMenu::VisitLockRulesURLClicked(const FString InOrganiz
FPlatformProcess::LaunchURL(*OrganizationLockRulesURL, NULL, NULL);
}

void FPlasticSourceControlMenu::OpenDeskoptApp() const
{
const FString DesktopAppPath = PlasticSourceControlUtils::FindDesktopApplicationPath();
const FString CommandLineArguments = FString::Printf(TEXT("--wk=\"%s\""), *FPlasticSourceControlModule::Get().GetProvider().GetPathToWorkspaceRoot());

UE_LOG(LogSourceControl, Log, TEXT("Opening the Desktop application (%s %s)"), *DesktopAppPath, *CommandLineArguments);

FProcHandle Proc = FPlatformProcess::CreateProc(*DesktopAppPath, *CommandLineArguments, true, false, false, nullptr, 0, nullptr, nullptr, nullptr);
if (!Proc.IsValid())
{
UE_LOG(LogSourceControl, Error, TEXT("Opening the Desktop application (%s %s) failed."), *DesktopAppPath, *CommandLineArguments);
FPlatformProcess::CloseProc(Proc);
}
}

void FPlasticSourceControlMenu::OpenBranchesWindow() const
{
FPlasticSourceControlModule::Get().GetBranchesWindow().OpenTab();
Expand Down Expand Up @@ -566,6 +584,8 @@ void FPlasticSourceControlMenu::AddMenuExtension(FMenuBuilder& Menu)
void FPlasticSourceControlMenu::AddMenuExtension(FToolMenuSection& Menu)
#endif
{
FPlasticSourceControlProvider& Provider = FPlasticSourceControlModule::Get().GetProvider();

Menu.AddMenuEntry(
#if ENGINE_MAJOR_VERSION == 5
"PlasticSync",
Expand Down Expand Up @@ -750,6 +770,29 @@ void FPlasticSourceControlMenu::AddMenuExtension(FToolMenuSection& Menu)
);
}

Menu.AddMenuEntry(
#if ENGINE_MAJOR_VERSION == 5
"PlasticDesktopApp",
TAttribute<FText>::CreateLambda([&Provider]()
{
return Provider.IsPartialWorkspace() ? LOCTEXT("PlasticGluon", "Open in Gluon") : LOCTEXT("PlasticDesktopApp", "Open in Desktop App");
}),
TAttribute<FText>::CreateLambda([&Provider]()
{
return Provider.IsPartialWorkspace() ? LOCTEXT("PlasticDesktopAppTooltip", "Open the workspace in Unity Version Control Gluon Application.") : LOCTEXT("PlasticGluonTooltip", "Open the workspace in Unity Version Control Desktop Application.");
}),
TAttribute<FSlateIcon>::CreateLambda([&Provider]()
{
return FSlateIcon(FPlasticSourceControlStyle::Get().GetStyleSetName(), Provider.IsPartialWorkspace() ? "PlasticSourceControl.GluonIcon.Small" : "PlasticSourceControl.PluginIcon.Small");
}),
#else
Provider.IsPartialWorkspace() ? LOCTEXT("PlasticGluon", "Open in Gluon") : LOCTEXT("PlasticDesktopApp", "Open in Desktop App"),
Provider.IsPartialWorkspace() ? LOCTEXT("PlasticDesktopAppTooltip", "Open the workspace in Unity Version Control Gluon Application.") : LOCTEXT("PlasticGluonTooltip", "Open the workspace in Unity Version Control Desktop Application."),
FSlateIcon(FPlasticSourceControlStyle::Get().GetStyleSetName(), Provider.IsPartialWorkspace() ? "PlasticSourceControl.GluonIcon.Small" : "PlasticSourceControl.PluginIcon.Small"),
#endif
FUIAction(FExecuteAction::CreateRaw(this, &FPlasticSourceControlMenu::OpenDeskoptApp))
);

AddViewBranches(Menu);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FPlasticSourceControlMenu
void VisitDocsURLClicked() const;
void VisitSupportURLClicked() const;
void VisitLockRulesURLClicked(const FString InOrganizationName) const;
void OpenDeskoptApp() const;
void OpenBranchesWindow() const;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ TSharedRef<FSlateStyleSet> FPlasticSourceControlStyle::Create()
Style->SetContentRoot(FPlasticSourceControlModule::GetPlugin()->GetBaseDir() / TEXT("Resources"));

Style->Set("PlasticSourceControl.PluginIcon.Small", new FSlateImageBrush(FPlasticSourceControlStyle::InContent("Icon128", ".png"), Icon16x16));
Style->Set("PlasticSourceControl.GluonIcon.Small", new FSlateImageBrush(FPlasticSourceControlStyle::InContent("gluon", ".ico"), Icon16x16));

return Style;
}
Expand Down
34 changes: 34 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#include "PlasticSourceControlChangelistState.h"
#endif

#if PLATFORM_WINDOWS
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/WindowsPlatformMisc.h"
#undef GetUserName
#endif

namespace PlasticSourceControlUtils
{

Expand Down Expand Up @@ -58,6 +64,34 @@ FString FindPlasticBinaryPath()
#endif
}

FString FindDesktopApplicationPath()
{
FString DesktopAppPath;

#if PLATFORM_WINDOWS
// On Windows, use the registry to find the install location
FString InstallLocation = TEXT("C:/Program Files/PlasticSCM5");
if (FWindowsPlatformMisc::QueryRegKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Unity Software Inc.\\Unity DevOps Version Control"), TEXT("Location"), InstallLocation))
{
FPaths::NormalizeDirectoryName(InstallLocation);
}

const TCHAR* PlasticExe = TEXT("client/plastic.exe");
const TCHAR* GluonExe = TEXT("client/gluon.exe");
DesktopAppPath = FPaths::Combine(InstallLocation, FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#elif PLATFORM_MAC
const TCHAR* PlasticExe = "/Applications/PlasticSCM.app/Contents/MacOS/macplasticx";
const TCHAR* GluonExe = "/Applications/Gluon.app/Contents/MacOS/macgluonx";
DesktopAppPath = FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#elif PLATFORM_LINUX
const TCHAR* PlasticExe = "/usr/bin/plasticgui ";
const TCHAR* GluonExe = "/usr/bin/gluon";
DesktopAppPath = FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace() ? GluonExe : PlasticExe);
#endif

return DesktopAppPath;
}

// Find the root of the workspace, looking from the provided path and upward in its parent directories.
bool GetWorkspacePath(const FString& InPath, FString& OutWorkspaceRoot)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ bool RunCommand(const FString& InCommand, const TArray<FString>& InParameters, c
*/
FString FindPlasticBinaryPath();

/**
* Find the path to the Desktop Application: uses the registry on Windows.
*/
FString FindDesktopApplicationPath();

/**
* Find the root of the Plastic workspace, looking from the GameDir and upward in its parent directories
* @param InPathToGameDir The path to the Game Directory
Expand Down

0 comments on commit 15d87f9

Please sign in to comment.