moving document related code from AtomToolsMainWindow to AtomToolsDocumentMainWindow
adding virtual function stubs to customize actions Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <AtomToolsFramework/Window/AtomToolsMainWindow.h>
|
||||
#include <QMenuBar>
|
||||
#include <QStatusBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@@ -26,6 +27,10 @@ namespace AtomToolsFramework
|
||||
m_statusMessage = new QLabel(statusBar());
|
||||
statusBar()->addPermanentWidget(m_statusMessage, 1);
|
||||
|
||||
auto menuBar = new QMenuBar(this);
|
||||
menuBar->setObjectName("MenuBar");
|
||||
setMenuBar(menuBar);
|
||||
|
||||
auto centralWidget = new QWidget(this);
|
||||
auto centralWidgetLayout = new QVBoxLayout(centralWidget);
|
||||
centralWidgetLayout->setMargin(0);
|
||||
@@ -108,145 +113,6 @@ namespace AtomToolsFramework
|
||||
return names;
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::CreateMenu()
|
||||
{
|
||||
auto menuBar = new QMenuBar(this);
|
||||
menuBar->setObjectName("MenuBar");
|
||||
setMenuBar(menuBar);
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::CreateTabBar()
|
||||
{
|
||||
m_tabWidget = new AzQtComponents::TabWidget(centralWidget());
|
||||
m_tabWidget->setObjectName("TabWidget");
|
||||
m_tabWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
|
||||
m_tabWidget->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// The tab bar should only be visible if it has active documents
|
||||
m_tabWidget->setVisible(false);
|
||||
m_tabWidget->setTabBarAutoHide(false);
|
||||
m_tabWidget->setMovable(true);
|
||||
m_tabWidget->setTabsClosable(true);
|
||||
m_tabWidget->setUsesScrollButtons(true);
|
||||
|
||||
// Add context menu for right-clicking on tabs
|
||||
m_tabWidget->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
||||
connect(
|
||||
m_tabWidget, &QWidget::customContextMenuRequested, this,
|
||||
[this]()
|
||||
{
|
||||
OpenTabContextMenu();
|
||||
});
|
||||
|
||||
centralWidget()->layout()->addWidget(m_tabWidget);
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::AddTabForDocumentId(
|
||||
const AZ::Uuid& documentId, const AZStd::string& label, const AZStd::string& toolTip, AZStd::function<QWidget*()> widgetCreator)
|
||||
{
|
||||
// Blocking signals from the tab bar so the currentChanged signal is not sent while a document is already being opened.
|
||||
// This prevents the OnDocumentOpened notification from being sent recursively.
|
||||
const QSignalBlocker blocker(m_tabWidget);
|
||||
|
||||
// If a tab for this document already exists then select it instead of creating a new one
|
||||
for (int tabIndex = 0; tabIndex < m_tabWidget->count(); ++tabIndex)
|
||||
{
|
||||
if (documentId == GetDocumentIdFromTab(tabIndex))
|
||||
{
|
||||
m_tabWidget->setCurrentIndex(tabIndex);
|
||||
m_tabWidget->repaint();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const int tabIndex = m_tabWidget->addTab(widgetCreator(), label.c_str());
|
||||
|
||||
// The user can manually reorder tabs which will invalidate any association by index.
|
||||
// We need to store the document ID with the tab using the tab instead of a separate mapping.
|
||||
m_tabWidget->tabBar()->setTabData(tabIndex, QVariant(documentId.ToString<QString>()));
|
||||
m_tabWidget->setTabToolTip(tabIndex, toolTip.c_str());
|
||||
m_tabWidget->setCurrentIndex(tabIndex);
|
||||
m_tabWidget->setVisible(true);
|
||||
m_tabWidget->repaint();
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::RemoveTabForDocumentId(const AZ::Uuid& documentId)
|
||||
{
|
||||
// We are not blocking signals here because we want closing tabs to close the associated document
|
||||
// and automatically select the next document.
|
||||
for (int tabIndex = 0; tabIndex < m_tabWidget->count(); ++tabIndex)
|
||||
{
|
||||
if (documentId == GetDocumentIdFromTab(tabIndex))
|
||||
{
|
||||
m_tabWidget->removeTab(tabIndex);
|
||||
m_tabWidget->setVisible(m_tabWidget->count() > 0);
|
||||
m_tabWidget->repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::UpdateTabForDocumentId(
|
||||
const AZ::Uuid& documentId, const AZStd::string& label, const AZStd::string& toolTip, bool isModified)
|
||||
{
|
||||
// Whenever a document is opened, saved, or modified we need to update the tab label
|
||||
if (!documentId.IsNull())
|
||||
{
|
||||
// Because tab order and indexes can change from user interactions, we cannot store a map
|
||||
// between a tab index and document ID.
|
||||
// We must iterate over all of the tabs to find the one associated with this document.
|
||||
for (int tabIndex = 0; tabIndex < m_tabWidget->count(); ++tabIndex)
|
||||
{
|
||||
if (documentId == GetDocumentIdFromTab(tabIndex))
|
||||
{
|
||||
// We use an asterisk prepended to the file name to denote modified document
|
||||
// Appending is standard and preferred but the tabs elide from the
|
||||
// end (instead of middle) and cut it off
|
||||
const AZStd::string modifiedLabel = isModified ? "* " + label : label;
|
||||
m_tabWidget->setTabText(tabIndex, modifiedLabel.c_str());
|
||||
m_tabWidget->setTabToolTip(tabIndex, toolTip.c_str());
|
||||
m_tabWidget->repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Uuid AtomToolsMainWindow::GetDocumentIdFromTab(const int tabIndex) const
|
||||
{
|
||||
const QVariant tabData = m_tabWidget->tabBar()->tabData(tabIndex);
|
||||
if (!tabData.isNull())
|
||||
{
|
||||
// We need to be able to convert between a UUID and a string to store and retrieve a document ID from the tab bar
|
||||
const QString documentIdString = tabData.toString();
|
||||
const QByteArray documentIdBytes = documentIdString.toUtf8();
|
||||
const AZ::Uuid documentId(documentIdBytes.data(), documentIdBytes.size());
|
||||
return documentId;
|
||||
}
|
||||
return AZ::Uuid::CreateNull();
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::OpenTabContextMenu()
|
||||
{
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::SelectPreviousTab()
|
||||
{
|
||||
if (m_tabWidget->count() > 1)
|
||||
{
|
||||
// Adding count to wrap around when index <= 0
|
||||
m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + m_tabWidget->count() - 1) % m_tabWidget->count());
|
||||
}
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::SelectNextTab()
|
||||
{
|
||||
if (m_tabWidget->count() > 1)
|
||||
{
|
||||
m_tabWidget->setCurrentIndex((m_tabWidget->currentIndex() + 1) % m_tabWidget->count());
|
||||
}
|
||||
}
|
||||
|
||||
void AtomToolsMainWindow::SetStatusMessage(const QString& message)
|
||||
{
|
||||
m_statusMessage->setText(QString("<font color=\"White\">%1</font>").arg(message));
|
||||
|
||||
Reference in New Issue
Block a user