Integrating latest 47acbe8

This commit is contained in:
alexpete
2021-03-25 13:57:57 -07:00
parent 448c549698
commit 75dc720198
10312 changed files with 2711566 additions and 671451 deletions
@@ -32,6 +32,10 @@ namespace ScriptCanvasEditor
{
namespace Widget
{
////////////////
// GraphTabBar
////////////////
GraphTabBar::GraphTabBar(QWidget* parent /*= nullptr*/)
: AzQtComponents::TabBar(parent)
{
@@ -45,47 +49,46 @@ namespace ScriptCanvasEditor
connect(this, &QTabBar::customContextMenuRequested, this, &GraphTabBar::OnContextMenu);
}
void GraphTabBar::RemoveAllBars()
void GraphTabBar::AddGraphTab(const AZ::Data::AssetId& assetId)
{
for (int i = count() - 1; i >= 0; --i)
{
Q_EMIT TabCloseNoButton(i);
}
InsertGraphTab(count(), assetId);
}
void GraphTabBar::SetTabText(int tabIndex, const QString& path, Tracker::ScriptCanvasFileState fileState)
int GraphTabBar::InsertGraphTab(int tabIndex, const AZ::Data::AssetId& assetId)
{
if (tabIndex >= 0 && tabIndex < count())
if (!SelectTab(assetId))
{
const char* fileStateTag = "";
switch (fileState)
AZStd::shared_ptr<ScriptCanvasMemoryAsset> memoryAsset;
AssetTrackerRequestBus::BroadcastResult(memoryAsset, &AssetTrackerRequests::GetAsset, assetId);
if (memoryAsset)
{
case Tracker::ScriptCanvasFileState::NEW:
fileStateTag = "^";
break;
case Tracker::ScriptCanvasFileState::MODIFIED:
fileStateTag = "*";
break;
default:
break;
ScriptCanvas::AssetDescription assetDescription = memoryAsset->GetAsset().Get()->GetAssetDescription();
QIcon tabIcon = QIcon(assetDescription.GetIconPathImpl());
int newTabIndex = qobject_cast<AzQtComponents::TabWidget*>(parent())->insertTab(tabIndex, new QWidget(), tabIcon, "");
CanvasWidget* canvasWidget = memoryAsset->CreateView(this);
canvasWidget->SetDefaultBorderColor(assetDescription.GetDisplayColorImpl());
AZStd::string tabName;
AzFramework::StringFunc::Path::GetFileName(memoryAsset->GetAbsolutePath().c_str(), tabName);
ConfigureTab(newTabIndex, assetId, tabName);
// new graphs will need to use their in-memory assetid which we'll need to update
// upon saving the asset
if (!memoryAsset->GetFileAssetId().IsValid())
{
setTabData(newTabIndex, QVariant::fromValue(memoryAsset->GetId()));
}
return newTabIndex;
}
setTabText(tabIndex, QString("%1%2").arg(path).arg(fileStateTag));
}
}
void GraphTabBar::tabInserted(int index)
{
AzQtComponents::TabBar::tabInserted(index);
Q_EMIT TabInserted(index);
}
void GraphTabBar::tabRemoved(int index)
{
AzQtComponents::TabBar::tabRemoved(index);
Q_EMIT TabRemoved(index);
return -1;
}
bool GraphTabBar::SelectTab(const AZ::Data::AssetId& assetId)
@@ -99,6 +102,29 @@ namespace ScriptCanvasEditor
return false;
}
void GraphTabBar::ConfigureTab(int tabIndex, AZ::Data::AssetId fileAssetId, const AZStd::string& tabName)
{
if (fileAssetId.IsValid())
{
QVariant tabDataVariant = tabData(tabIndex);
if (tabDataVariant.isValid())
{
auto tabAssetId = tabDataVariant.value<AZ::Data::AssetId>();
MemoryAssetNotificationBus::MultiHandler::BusDisconnect(tabAssetId);
}
setTabData(tabIndex, QVariant::fromValue(fileAssetId));
MemoryAssetNotificationBus::MultiHandler::BusConnect(fileAssetId);
}
Tracker::ScriptCanvasFileState fileState = Tracker::ScriptCanvasFileState::INVALID;
AssetTrackerRequestBus::BroadcastResult(fileState, &AssetTrackerRequests::GetFileState, fileAssetId);
SetTabText(tabIndex, tabName.c_str(), fileState);
}
int GraphTabBar::FindTab(const AZ::Data::AssetId& assetId) const
{
for (int tabIndex = 0; tabIndex < count(); ++tabIndex)
@@ -128,88 +154,33 @@ namespace ScriptCanvasEditor
return AZ::Data::AssetId();
}
void GraphTabBar::AddGraphTab(const AZ::Data::AssetId& assetId)
{
InsertGraphTab(count(), assetId);
}
int GraphTabBar::InsertGraphTab(int tabIndex, const AZ::Data::AssetId& assetId)
{
if (!SelectTab(assetId))
{
AZStd::shared_ptr<ScriptCanvasMemoryAsset> memoryAsset;
AssetTrackerRequestBus::BroadcastResult(memoryAsset, &AssetTrackerRequests::GetAsset, assetId);
if (memoryAsset)
{
ScriptCanvas::AssetDescription assetDescription = memoryAsset->GetAsset().Get()->GetAssetDescription();
QIcon tabIcon = QIcon(assetDescription.GetIconPathImpl());
int newTabIndex = qobject_cast<AzQtComponents::TabWidget*>(parent())->insertTab(tabIndex, new QWidget(), tabIcon, "");
CanvasWidget* canvasWidget = memoryAsset->CreateView(this);
canvasWidget->SetDefaultBorderColor(assetDescription.GetDisplayColorImpl());
auto fileState = memoryAsset->GetFileState();
AZStd::string tabName;
AzFramework::StringFunc::Path::GetFileName(memoryAsset->GetAbsolutePath().c_str(), tabName);
// For opened graphs we need to use their file assetId
if (memoryAsset->GetFileAssetId().IsValid())
{
setTabData(newTabIndex, QVariant::fromValue(memoryAsset->GetFileAssetId()));
}
else
{
// new graphs will need to use their in-memory assetid which we'll need to update
// upon saving the asset
setTabData(newTabIndex, QVariant::fromValue(memoryAsset->GetId()));
}
SetTabText(newTabIndex, tabName.data(), fileState);
return newTabIndex;
}
}
return -1;
}
void GraphTabBar::currentChangedTab(int index)
{
if (index < 0)
{
return;
}
QVariant tab = tabData(index);
if (!tab.isValid())
{
return;
}
auto assetId = tab.value<AZ::Data::AssetId>();
ScriptCanvasEditor::GeneralRequestBus::Broadcast(&ScriptCanvasEditor::GeneralRequests::OnChangeActiveGraphTab, assetId);
}
void GraphTabBar::CloseTab(int index)
{
if (index >= 0 && index < count())
{
QVariant tab = tabData(index);
if (tab.isValid())
QVariant tabdata = tabData(index);
if (tabdata.isValid())
{
auto tabAssetId = tab.value<AZ::Data::AssetId>();
auto tabAssetId = tabdata.value<AZ::Data::AssetId>();
MemoryAssetNotificationBus::MultiHandler::BusDisconnect(tabAssetId);
AssetTrackerRequestBus::Broadcast(&AssetTrackerRequests::ClearView, tabAssetId);
}
qobject_cast<AzQtComponents::TabWidget*>(parent())->removeTab(index);
}
}
void GraphTabBar::CloseAllTabs()
{
for (int i = count() - 1; i >= 0; --i)
{
Q_EMIT TabCloseNoButton(i);
}
MemoryAssetNotificationBus::MultiHandler::BusDisconnect();
}
void GraphTabBar::OnContextMenu(const QPoint& point)
{
QPoint screenPoint = mapToGlobal(point);
@@ -218,10 +189,10 @@ namespace ScriptCanvasEditor
bool hasValidTab = (tabIndex >= 0);
bool isModified = false;
QVariant tab = tabData(tabIndex);
if (tab.isValid())
QVariant tabdata = tabData(tabIndex);
if (tabdata.isValid())
{
auto tabAssetId = tab.value<AZ::Data::AssetId>();
auto tabAssetId = tabdata.value<AZ::Data::AssetId>();
Tracker::ScriptCanvasFileState fileState;
AssetTrackerRequestBus::BroadcastResult(fileState , &AssetTrackerRequests::GetFileState, tabAssetId);
@@ -252,7 +223,15 @@ namespace ScriptCanvasEditor
{
if (action == saveAction)
{
Q_EMIT SaveTab(tabIndex);
if (tabIndex != currentIndex())
{
m_signalSaveOnChangeTo = tabIndex;
setCurrentIndex(tabIndex);
}
else
{
Q_EMIT SaveTab(tabIndex);
}
}
else if (action == closeAction)
{
@@ -260,11 +239,11 @@ namespace ScriptCanvasEditor
}
else if (action == closeAllAction)
{
Q_EMIT CloseAllTabs();
Q_EMIT CloseAllTabsSignal();
}
else if (action == closeAllButThis)
{
Q_EMIT CloseAllTabsBut(tabIndex);
Q_EMIT CloseAllTabsButSignal(tabIndex);
}
else if (action == fullPathAction)
{
@@ -289,16 +268,91 @@ namespace ScriptCanvasEditor
AzQtComponents::TabBar::mouseReleaseEvent(event);
}
void GraphTabBar::OnFileStateChanged(Tracker::ScriptCanvasFileState fileState)
{
const AZ::Data::AssetId* fileAssetId = MemoryAssetNotificationBus::GetCurrentBusId();
if (fileAssetId)
{
SetFileState((*fileAssetId), fileState);
if (FindTab((*fileAssetId)) == currentIndex())
{
Q_EMIT OnActiveFileStateChanged();
}
}
}
void GraphTabBar::SetTabText(int tabIndex, const QString& path, Tracker::ScriptCanvasFileState fileState)
{
if (tabIndex >= 0 && tabIndex < count())
{
const char* fileStateTag = "";
switch (fileState)
{
case Tracker::ScriptCanvasFileState::NEW:
fileStateTag = "^";
break;
case Tracker::ScriptCanvasFileState::SOURCE_REMOVED:
case Tracker::ScriptCanvasFileState::MODIFIED:
fileStateTag = "*";
break;
default:
break;
}
setTabText(tabIndex, QString("%1%2").arg(path).arg(fileStateTag));
}
}
void GraphTabBar::tabInserted(int index)
{
AzQtComponents::TabBar::tabInserted(index);
Q_EMIT TabInserted(index);
}
void GraphTabBar::tabRemoved(int index)
{
AzQtComponents::TabBar::tabRemoved(index);
Q_EMIT TabRemoved(index);
}
void GraphTabBar::currentChangedTab(int index)
{
if (index < 0)
{
return;
}
QVariant tabdata = tabData(index);
if (!tabdata.isValid())
{
return;
}
auto assetId = tabdata.value<AZ::Data::AssetId>();
ScriptCanvasEditor::GeneralRequestBus::Broadcast(&ScriptCanvasEditor::GeneralRequests::OnChangeActiveGraphTab, assetId);
if (m_signalSaveOnChangeTo >= 0 && m_signalSaveOnChangeTo == index)
{
m_signalSaveOnChangeTo = -1;
Q_EMIT SaveTab(m_signalSaveOnChangeTo);
}
}
void GraphTabBar::SetFileState(AZ::Data::AssetId assetId, Tracker::ScriptCanvasFileState fileState)
{
int index = FindTab(assetId);
if (index >= 0 && index < count())
{
QVariant tab = tabData(index);
if (tab.isValid())
QVariant tabdata = tabData(index);
if (tabdata.isValid())
{
auto tabAssetId = tab.value<AZ::Data::AssetId>();
auto tabAssetId = tabdata.value<AZ::Data::AssetId>();
AZStd::string tabName;
AssetTrackerRequestBus::BroadcastResult(tabName, &AssetTrackerRequests::GetTabName, tabAssetId);