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

Add a menu action to switch to partial workspace #85

Merged
merged 7 commits into from
Jul 12, 2023
57 changes: 57 additions & 0 deletions Source/PlasticSourceControl/Private/PlasticSourceControlMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,45 @@ void FPlasticSourceControlMenu::RefreshClicked()
}
}

void FPlasticSourceControlMenu::SwitchToPartialWorkspaceClicked()
{
if (!OperationInProgressNotification.IsValid())
{
// Ask the user before switching to Partial Workspace. It's not possible to switch back with local changes!
const FText DialogText(LOCTEXT("SourceControlMenu_AskSwitchToPartialWorkspace", "Switch to Gluon partial workspace?\n"
"Please note that, in order to switch back to a regular workspace you will need to undo all local changes."));
const EAppReturnType::Type Choice = FMessageDialog::Open(EAppMsgType::OkCancel, DialogText);
if (Choice == EAppReturnType::Ok)
{
// Launch a "SwitchToPartialWorkspace" Operation
FPlasticSourceControlProvider& Provider = FPlasticSourceControlModule::Get().GetProvider();
TSharedRef<FPlasticSwitchToPartialWorkspace, ESPMode::ThreadSafe> SwitchOperation = ISourceControlOperation::Create<FPlasticSwitchToPartialWorkspace>();
const ECommandResult::Type Result = Provider.Execute(SwitchOperation, TArray<FString>(), EConcurrency::Asynchronous, FSourceControlOperationComplete::CreateRaw(this, &FPlasticSourceControlMenu::OnSourceControlOperationComplete));
if (Result == ECommandResult::Succeeded)
{
// Display an ongoing notification during the whole operation
DisplayInProgressNotification(SwitchOperation->GetInProgressString());
}
else
{
// Report failure with a notification
DisplayFailureNotification(SwitchOperation->GetName());
}
}
}
else
{
FMessageLog SourceControlLog("SourceControl");
SourceControlLog.Warning(LOCTEXT("SourceControlMenu_InProgress", "Source control operation already in progress"));
SourceControlLog.Notify();
}
}

bool FPlasticSourceControlMenu::CanSwitchToPartialWorkspace() const
{
return !FPlasticSourceControlModule::Get().GetProvider().IsPartialWorkspace();
}

void FPlasticSourceControlMenu::ShowSourceControlEditorPreferences() const
{
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
Expand Down Expand Up @@ -479,6 +518,24 @@ void FPlasticSourceControlMenu::AddMenuExtension(FToolMenuSection& Menu)
)
);

Menu.AddMenuEntry(
#if ENGINE_MAJOR_VERSION == 5
"SwitchToPartialWorkspace",
#endif
LOCTEXT("SwitchToPartialWorkspace", "Switch to Gluon Partial Workspace"),
LOCTEXT("SwitchToPartialWorkspaceTooltip", "Update the workspace to a Gluon partial mode for a simplified workflow.\n"
"Allows to update and check in files individually as opposed to the whole workspace.\nIt doesn't work with branches or shelves."),
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION >= 1
FSlateIcon(FAppStyle::GetAppStyleSetName(), "GenericCommands.Cut"),
#else
FSlateIcon(FEditorStyle::GetStyleSetName(), "GenericCommands.Cut"),
#endif
FUIAction(
FExecuteAction::CreateRaw(this, &FPlasticSourceControlMenu::SwitchToPartialWorkspaceClicked),
FCanExecuteAction::CreateRaw(this, &FPlasticSourceControlMenu::CanSwitchToPartialWorkspace)
)
);

#if ENGINE_MAJOR_VERSION == 5
Menu.AddMenuEntry(
"SourceControlEditorPreferences",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FPlasticSourceControlMenu
void RevertUnchangedClicked();
void RevertAllClicked();
void RefreshClicked();
void SwitchToPartialWorkspaceClicked();
bool CanSwitchToPartialWorkspace() const;
void ShowSourceControlEditorPreferences() const;
void ShowSourceControlProjectSettings() const;
void ShowSourceControlPlasticScmProjectSettings() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void IPlasticSourceControlWorker::RegisterWorkers(FPlasticSourceControlProvider&
PlasticSourceControlProvider.RegisterWorker("Revert", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticRevertWorker>));
PlasticSourceControlProvider.RegisterWorker("RevertUnchanged", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticRevertUnchangedWorker>));
PlasticSourceControlProvider.RegisterWorker("RevertAll", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticRevertAllWorker>));
PlasticSourceControlProvider.RegisterWorker("SwitchToPartialWorkspace", FGetPlasticSourceControlWorker::CreateStatic(&InstantiateWorker<FPlasticSwitchToPartialWorkspaceWorker>));
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 @@ -103,7 +104,17 @@ FName FPlasticMakeWorkspace::GetName() const

FText FPlasticMakeWorkspace::GetInProgressString() const
{
return LOCTEXT("SourceControl_MakeWorkspace", "Create a new Repository and initialize the Workspace");
return LOCTEXT("SourceControl_MakeWorkspace", "Creating a new Repository and initializing the Workspace");
}

FName FPlasticSwitchToPartialWorkspace::GetName() const
{
return "SwitchToPartialWorkspace";
}

FText FPlasticSwitchToPartialWorkspace::GetInProgressString() const
{
return LOCTEXT("SourceControl_SwitchToPartialWorkspace", "Switching to a Partial/Gluon Workspace");
}

static bool AreAllFiles(const TArray<FString>& InFiles)
Expand Down Expand Up @@ -901,6 +912,38 @@ bool FPlasticMakeWorkspaceWorker::UpdateStates()
return false;
}

FName FPlasticSwitchToPartialWorkspaceWorker::GetName() const
{
return "SwitchToPartialWorkspace";
}

bool FPlasticSwitchToPartialWorkspaceWorker::Execute(FPlasticSourceControlCommand& InCommand)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FPlasticMakeWorkspaceWorker::Execute);

check(InCommand.Operation->GetName() == GetName());

{
TArray<FString> Parameters;
Parameters.Add(TEXT("update"));
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunCommand(TEXT("partial"), Parameters, TArray<FString>(), InCommand.InfoMessages, InCommand.ErrorMessages);
}

// Update the workspace to set the changeset number to -1 if all went well
{
TArray<FString> ProjectFiles;
ProjectFiles.Add(FPaths::ConvertRelativePathToFull(FPaths::GetProjectFilePath()));
InCommand.bCommandSuccessful = PlasticSourceControlUtils::RunUpdateStatus(ProjectFiles, PlasticSourceControlUtils::EStatusSearchType::ControlledOnly, false, InCommand.ErrorMessages, States, InCommand.ChangesetNumber, InCommand.BranchName);
}

return InCommand.bCommandSuccessful;
}

bool FPlasticSwitchToPartialWorkspaceWorker::UpdateStates()
{
return PlasticSourceControlUtils::UpdateCachedStates(MoveTemp(States));
}

FName FPlasticUpdateStatusWorker::GetName() const
{
return "UpdateStatus";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ class FPlasticMakeWorkspace final : public ISourceControlOperation
};


/**
* Internal operation used to switch to a partial workspace
*/
class FPlasticSwitchToPartialWorkspace final : public ISourceControlOperation
{
public:
// ISourceControlOperation interface
virtual FName GetName() const override;

virtual FText GetInProgressString() const override;
};


/** 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 @@ -271,6 +284,24 @@ class FPlasticMakeWorkspaceWorker final : public IPlasticSourceControlWorker
virtual bool UpdateStates() override;
};

/** Switch to Partial Workspace. */
class FPlasticSwitchToPartialWorkspaceWorker final : public IPlasticSourceControlWorker
{
public:
explicit FPlasticSwitchToPartialWorkspaceWorker(FPlasticSourceControlProvider& InSourceControlProvider)
: IPlasticSourceControlWorker(InSourceControlProvider)
{}
virtual ~FPlasticSwitchToPartialWorkspaceWorker() = default;
// IPlasticSourceControlWorker interface
virtual FName GetName() const override;
virtual bool Execute(class FPlasticSourceControlCommand& InCommand) override;
virtual bool UpdateStates() override;

public:
/** Temporary states for results */
TArray<FPlasticSourceControlState> States;
};

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