sc: move part of sheet view creation into ScDocument
Instead of setting up in ScViewFunc, just create everything needed for adding a sheet view inside ScDocument::CreateNewSheetView. This will limit the functions we need to expose to the outside of ScDocument. Change-Id: Ie8c432b175e7bbb55fc5ae3c6fe3a2b822e6d619 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189914 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
committed by
Tomaž Vajngerl
parent
eb514bdac8
commit
9e062392a7
@@ -16,6 +16,9 @@ typedef sal_Int32 SheetViewID;
|
||||
|
||||
/** Defines the value to identify the default view of the sheet */
|
||||
constexpr SheetViewID DefaultSheetViewID = -1;
|
||||
|
||||
/** Invalid sheet view ID */
|
||||
constexpr SheetViewID InvalidSheetViewID = SAL_MIN_INT32;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
+1
-1
@@ -2397,7 +2397,7 @@ public:
|
||||
/* Sheet View */
|
||||
|
||||
/** Creates a new sheet view for the table, using the sheet view table */
|
||||
sal_Int32 CreateNewSheetView(SCTAB nMainTable, SCTAB nSheetViewTable);
|
||||
std::pair<sc::SheetViewID, SCTAB> CreateNewSheetView(SCTAB nTab);
|
||||
|
||||
/** Return the sheet view table for the ID */
|
||||
SCTAB GetSheetViewNumber(SCTAB nTab, sc::SheetViewID nID);
|
||||
|
||||
@@ -1132,20 +1132,24 @@ void ScDocument::SetSheetView(SCTAB nTab, bool bSheetView)
|
||||
}
|
||||
}
|
||||
|
||||
sc::SheetViewID ScDocument::CreateNewSheetView(SCTAB nMainTable, SCTAB nSheetViewTable)
|
||||
{
|
||||
if (ScTable* pTable = FetchTable(nMainTable))
|
||||
{
|
||||
if (pTable->IsSheetView())
|
||||
return -1;
|
||||
|
||||
if (ScTable* pSheetViewTable = FetchTable(nSheetViewTable))
|
||||
std::pair<sc::SheetViewID, SCTAB> ScDocument::CreateNewSheetView(SCTAB nTab)
|
||||
{
|
||||
if (ScTable* pTable = FetchTable(nTab))
|
||||
{
|
||||
SCTAB nSheetViewTab = nTab + 1;
|
||||
if (CopyTab(nTab, nSheetViewTab))
|
||||
{
|
||||
auto nSheetViewID = pTable->GetSheetViewManager()->create(pSheetViewTable);
|
||||
return nSheetViewID;
|
||||
if (ScTable* pSheetViewTable = FetchTable(nSheetViewTab))
|
||||
{
|
||||
auto nSheetViewID = pTable->GetSheetViewManager()->create(pSheetViewTable);
|
||||
pSheetViewTable->SetVisible(false);
|
||||
pSheetViewTable->SetSheetView(true);
|
||||
return { nSheetViewID, nSheetViewTab };
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return { sc::InvalidSheetViewID, -1 };
|
||||
}
|
||||
|
||||
bool ScDocument::HasSheetViews(SCTAB nTab) const
|
||||
|
||||
@@ -2066,25 +2066,26 @@ void ScViewFunc::MakeNewSheetView()
|
||||
SCTAB nTab = GetViewData().GetTabNumber();
|
||||
ScDocument& rDocument = GetViewData().GetDocument();
|
||||
|
||||
SCTAB nSheetViewTab = nTab + 1;
|
||||
if (rDocument.CopyTab(nTab, nSheetViewTab))
|
||||
auto[nSheetViewID, nSheetViewTab] = rDocument.CreateNewSheetView(nTab);
|
||||
|
||||
if (nSheetViewID == sc::InvalidSheetViewID)
|
||||
{
|
||||
GetViewData().GetDocShell().Broadcast(ScTablesHint(SC_TAB_INSERTED, nSheetViewTab));
|
||||
SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScTablesChanged));
|
||||
|
||||
// Add and register the created sheet view
|
||||
rDocument.SetSheetView(nSheetViewTab, true);
|
||||
sc::SheetViewID nSheetViewID = rDocument.CreateNewSheetView(nTab, nSheetViewTab);
|
||||
GetViewData().SetSheetViewID(nSheetViewID);
|
||||
|
||||
// Update
|
||||
GetViewData().SetTabNo(nSheetViewTab); // force add the sheet view tab
|
||||
GetViewData().SetTabNo(nTab); // then change back to the current tab
|
||||
|
||||
ScDocShell& rDocSh = GetViewData().GetDocShell();
|
||||
rDocSh.PostPaintGridAll();
|
||||
PaintExtras(); // update Tab Control
|
||||
SAL_WARN("sc", "Sheet view couldn't be created");
|
||||
return;
|
||||
}
|
||||
|
||||
GetViewData().SetSheetViewID(nSheetViewID);
|
||||
|
||||
// Update
|
||||
GetViewData().SetTabNo(nSheetViewTab); // force add the sheet view tab
|
||||
GetViewData().SetTabNo(nTab); // then change back to the current tab
|
||||
|
||||
ScDocShell& rDocSh = GetViewData().GetDocShell();
|
||||
rDocSh.PostPaintGridAll();
|
||||
PaintExtras(); // update Tab Control
|
||||
|
||||
GetViewData().GetDocShell().Broadcast(ScTablesHint(SC_TAB_INSERTED, nSheetViewTab));
|
||||
SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScTablesChanged));
|
||||
}
|
||||
|
||||
void ScViewFunc::RemoveCurrentSheetView()
|
||||
|
||||
Reference in New Issue
Block a user