20 #include <config_features.h>
42 #include <document.hxx>
44 #include <globstr.hrc>
45 #include <strings.hrc>
46 #include <docfunc.hxx>
58 using std::unique_ptr;
68 sal_uInt16 nSlot = rReq.
GetSlot();
75 case FID_TABLE_VISIBLE:
78 rDoc.
GetName( nCurrentTab, aName );
81 if( pReqArgs !=
nullptr )
84 if( pReqArgs->
HasItem( FID_TABLE_VISIBLE, &pItem ) )
85 bVisible = static_cast<const SfxBoolItem*>(pItem)->GetValue();
98 std::vector<OUString> rNames { aName };
109 SCTAB nActiveTab = -1;
114 if( pReqArgs->
HasItem( FID_TABLE_HIDE, &pItem ) )
118 std::set<SCTAB>::iterator it = rMark.
GetSelectedTabs().find(nTabNumber);
122 nActiveTab = GetViewData().GetTabNo();
127 HideTable( rMark, nActiveTab );
134 std::vector<OUString> rNames;
138 if( pReqArgs->
HasItem( FID_TABLE_SHOW, &pItem ) )
141 rNames.push_back(aName);
156 for (
SCTAB i=0;
i != nTabCount;
i++ )
161 pDlg->Insert( aTabName, bFirst );
166 std::shared_ptr<SfxRequest> pReq = std::make_shared<SfxRequest>(rReq);
167 pDlg->StartExecuteAsync([
this, pDlg, pReq](sal_Int32 nResult){
168 std::vector<OUString> sTables;
171 std::vector<sal_Int32> aSelectedRows = pDlg->GetSelectedRows();
172 for (
auto a : aSelectedRows)
174 OUString sTable = pDlg->GetEntry(
a);
176 sTables.push_back(sTable);
178 ShowTable( sTables );
189 case FID_INS_TABLE_EXT:
193 SCTAB nTabNr = nCurrentTab;
198 if ( pReqArgs !=
nullptr )
204 if ( pReqArgs->
HasItem( FN_PARAM_1, &pTabItem ) &&
205 pReqArgs->
HasItem( nSlot, &pNameItem ) )
218 if (nTabNr > nTabCount)
221 bOk = InsertTable(aName, nTabNr);
225 rReq.
Done( *pReqArgs );
233 nTabSelCount, nSlot == FID_INS_TABLE_EXT));
234 if (
RET_OK == pDlg->Execute() )
236 if (pDlg->GetTablesFromFile())
238 std::vector<SCTAB> nTabs;
240 const OUString* pStr = pDlg->GetFirstTable( &n );
243 nTabs.push_back( static_cast<SCTAB>(n) );
244 pStr = pDlg->GetNextTable( &n );
246 bool bLink = pDlg->GetTablesAsLink();
249 if(pDlg->IsTableBefore())
251 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), nTabs.data(),
256 SCTAB nTabAfter = nTabNr+1;
258 for(
SCTAB j=nCurrentTab+1;j<nTabCount;j++)
267 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), nTabs.data(),
275 if(pDlg->IsTableBefore())
277 if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
283 InsertTable( *pDlg->GetFirstTable(), nTabNr );
287 std::vector<OUString> aNames(0);
288 InsertTables( aNames, nTabNr,nCount );
293 SCTAB nTabAfter = nTabNr+1;
296 for(
SCTAB j=nSelHigh+1;j<nTabCount;j++)
307 if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
313 InsertTable( *pDlg->GetFirstTable(), nTabAfter);
317 std::vector<OUString> aNames(0);
318 InsertTables( aNames, nTabAfter,nCount);
329 case FID_TAB_MENU_RENAME:
335 if ( nSlot == FID_TAB_MENU_RENAME )
336 nSlot = FID_TAB_RENAME;
345 if ( nSlot != FID_TAB_APPEND &&
349 if( pReqArgs !=
nullptr )
355 if( pReqArgs->
HasItem( FN_PARAM_1, &pItem ) )
364 if( pReqArgs->
HasItem( nSlot, &pItem ) )
365 aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
370 bDone = AppendTable( aName );
373 bDone = RenameTable( aName, nTabNr );
379 rReq.
Done( *pReqArgs );
386 OUString aErrMsg (
ScResId( STR_INVALIDTABNAME ) );
394 aDlgTitle =
ScResId(SCSTR_APDTABLE);
400 aDlgTitle =
ScResId(SCSTR_RENAMETAB);
410 aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
414 while ( !bDone && nRet ==
RET_OK )
416 nRet = pDlg->Execute();
420 aName = pDlg->GetInputString();
425 bDone = AppendTable( aName );
428 bDone = RenameTable( aName, nTabNr );
441 #if HAVE_FEATURE_SCRIPTING
448 VclMessageType::Warning, VclButtonsType::Ok, aErrMsg));
466 bool bCpy =
false, bUseCurrentDocument =
false;
470 if( pReqArgs !=
nullptr )
476 if( pReqArgs->
HasItem( FN_PARAM_3, &pItem ) )
477 bUseCurrentDocument = static_cast<const SfxBoolItem*>(pItem)->GetValue();
479 if (bUseCurrentDocument)
480 aDocName = GetViewData().GetDocShell()->GetTitle();
481 else if(pReqArgs->
HasItem( FID_TAB_MOVE, &pItem ))
482 aDocName = static_cast<const SfxStringItem*>(pItem)->GetValue();
484 if( pReqArgs->
HasItem( FN_PARAM_1, &pItem ) )
488 if ( nTab >= nTableCount )
491 if( pReqArgs->
HasItem( FN_PARAM_2, &pItem ) )
492 bCpy = static_cast<const SfxBoolItem*>(pItem)->GetValue();
494 if (!aDocName.isEmpty())
528 if ( bDoIt && nTab >= nTableCount )
533 OUString aDefaultName;
542 ScMarkData& rMark = GetViewData().GetMarkData();
545 if(nTableCount==nTabSelCount)
547 pDlg->SetForceCopyTable();
552 pDlg->EnableRenameTable(nTabSelCount == 1);
554 if ( pDlg->Execute() ==
RET_OK )
556 nDoc = pDlg->GetSelectedDocument();
557 nTab = pDlg->GetSelectedTable();
558 bCpy = pDlg->GetCopyTable();
559 bool bRna = pDlg->GetRenameTable();
563 pDlg->GetTabNameString( aTabName );
567 OUString aFoundDocName;
576 ErrorMessage(STR_READONLYERR);
583 SCTAB nBasicTab = ( nTab <=
MAXTAB ) ? (nTab+1) : nTab;
593 MoveTable( nDoc, nTab, bCpy, &aTabName );
598 case FID_TAB_DUPLICATE:
602 OUString aDocName = GetViewData().GetDocShell()->GetTitle();
630 MoveTable( nDoc, nTab + 1, bCpy );
634 case FID_DELETE_TABLE:
636 bool bHasIndex = (pReqArgs !=
nullptr);
639 SCTAB nTabNr = nCurrentTab;
643 if (pReqArgs->
HasItem(FID_DELETE_TABLE, &pItem))
653 bool bDoIt = bHasIndex;
656 bool bTabWithPivotTable =
false;
663 for (
const SCTAB nSelTab : rSelectedTabs)
666 for (
size_t i = 0;
i < nCount; ++
i)
671 bTabWithPivotTable =
true;
673 if (bTabWithPivotTable)
679 if (bTabWithPivotTable)
682 VclMessageType::Question, VclButtonsType::YesNo,
683 ScResId(STR_QUERY_PIVOTTABLE_DELTAB)));
684 xQueryBox->set_default_response(
RET_NO);
687 bDoIt = (
RET_YES == xQueryBox->run());
692 VclMessageType::Question, VclButtonsType::YesNo,
694 xQueryBox->set_default_response(
RET_YES);
697 bDoIt = (
RET_YES == xQueryBox->run());
703 SCTAB nNewTab = nCurrentTab;
704 std::vector<SCTAB> TheTabs;
709 TheTabs.push_back(nTabNr);
710 if (nNewTab > nTabNr && nNewTab > 0)
716 bool bTabFlag =
false;
718 for (
SCTAB i = 0;
i < nTabCount;
i++)
722 TheTabs.push_back(
i);
724 if (nNewTab ==
i &&
i+1 < nTabCount)
730 if (nNewTab >= nTabCount - static_cast<SCTAB>(TheTabs.size()))
735 DeleteTables(TheTabs);
754 OUString aUndo =
ScResId( STR_UNDO_TAB_RTL );
757 for (
const auto& rTab : rMark)
767 case FID_TAB_TOGGLE_GRID:
771 SfxBindings& rBindings = GetViewFrame()->GetBindings();
780 case FID_TAB_SET_TAB_BG_COLOR:
781 case FID_TAB_MENU_SET_TAB_BG_COLOR:
783 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
784 nSlot = FID_TAB_SET_TAB_BG_COLOR;
794 if( pReqArgs !=
nullptr )
800 if( pReqArgs->
HasItem( nSlot, &pItem ) )
801 aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
803 if ( nTabSelCount > 1 )
805 std::unique_ptr<ScUndoTabColorInfo::List>
807 for (
const auto& rTab : rMark)
813 pTabColorList->push_back(aTabColorInfo);
816 bDone = SetTabBgColor( *pTabColorList );
820 bDone = SetTabBgColor( aColor, nCurrentTab );
824 rReq.
Done( *pReqArgs );
836 ScResId(SCSTR_SET_TAB_BG_COLOR),
837 ScResId(SCSTR_NO_TAB_BG_COLOR),
839 while ( !bDone && nRet ==
RET_OK )
841 nRet = pDlg->Execute();
844 Color aSelectedColor;
845 pDlg->GetSelectedColor(aSelectedColor);
846 std::unique_ptr<ScUndoTabColorInfo::List>
848 if ( nTabSelCount > 1 )
850 for (
const auto& rTab : rMark)
856 pTabColorList->push_back(aTabColorInfo);
859 bDone = SetTabBgColor( *pTabColorList );
863 bDone = SetTabBgColor( aSelectedColor, nCurrentTab );
875 #if HAVE_FEATURE_SCRIPTING
889 uno::Reference<container::XNameReplace> xEvents(
new ScSheetEventsObj( pDocSh, nCurrentTab ) );
890 uno::Reference<frame::XFrame>
xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
894 if ( pDialog->Execute() ==
RET_OK )
900 case FID_TOGGLEHIDDENCOLROW:
909 OSL_FAIL(
"unknown message for ViewShell");
919 ScMarkData& rMark = GetViewData().GetMarkData();
933 case FID_TABLE_VISIBLE:
941 for (
SCTAB i=0;
i < nTabCount && nVis<nTabSelCount + 1;
i++ )
951 bool bHasHidden =
false;
952 for (
SCTAB i=0;
i < nTabCount && !bHasHidden;
i++ )
960 case FID_DELETE_TABLE:
967 for (
SCTAB i=0;
i < nTabCount && nVis<2;
i++ )
973 || nTabSelCount == nTabCount)
980 case FID_INS_TABLE_EXT:
984 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->
IsDocShared() ) )
995 case FID_TAB_DUPLICATE:
1005 case FID_TAB_MENU_RENAME:
1012 case FID_TAB_RENAME:
1015 rDoc.
GetName( nTab, aTabName );
1031 case FID_TAB_MENU_SET_TAB_BG_COLOR:
1040 case FID_TAB_SET_TAB_BG_COLOR:
1047 case FID_TAB_TOGGLE_GRID:
SC_DLLPUBLIC bool IsDocProtected() const
ScMarkData & GetMarkData()
constexpr OStringLiteral HID_SC_RENAME_NAME
ScDocShell * GetDocShell() const
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
OUString ScResId(TranslateId aId)
SC_DLLPUBLIC size_t GetCount() const
OUString GetTitle(sal_uInt16 nMaxLen=0) const
static SvxAbstractDialogFactory * Create()
Reference< XFrame > xFrame
virtual VclPtr< AbstractScStringInputDlg > CreateScStringInputDlg(weld::Window *pParent, const OUString &rTitle, const OUString &rEditTitle, const OUString &rDefault, const OString &rHelpId, const OString &rEditHelpId)=0
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
virtual VclPtr< AbstractScInsertTableDlg > CreateScInsertTableDlg(weld::Window *pParent, ScViewData &rViewData, SCTAB nTabCount, bool bFromFile)=0
void Done(bool bRemove=false)
ScDocument & GetDocument() const
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
const MarkedTabsType & GetSelectedTabs() const
virtual SfxUndoManager * GetUndoManager() override
static void Error(ErrCode, const OUString &rMsg={})
#define ERRCODE_BASIC_SETPROP_FAILED
SC_DLLPUBLIC SCTAB GetTableCount() const
SCTAB GetSelectCount() const
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
ScChangeTrack * GetChangeTrack() const
ScTabViewShell * GetViewShell() const
void SetTabNo(SCTAB nNewTab)
const SCTAB SC_TAB_APPEND
SC_DLLPUBLIC bool HasPivotTable() const
virtual VclPtr< AbstractScMoveTableDlg > CreateScMoveTableDlg(weld::Window *pParent, const OUString &rDefault)=0
virtual VclPtr< AbstractScTabBgColorDlg > CreateScTabBgColorDlg(weld::Window *pParent, const OUString &rTitle, const OUString &rTabBgColorNoColorText, const Color &rDefaultColor)=0
virtual VclPtr< AbstractScShowTabDlg > CreateScShowTabDlg(weld::Window *pParent)=0
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
void SelectOneTable(SCTAB nTab)
void GetStateTable(SfxItemSet &rSet)
virtual VclPtr< VclAbstractDialog > CreateSvxMacroAssignDlg(weld::Window *_pParent, const css::uno::Reference< css::frame::XFrame > &_rxDocumentFrame, const bool _bUnoDialogMode, const css::uno::Reference< css::container::XNameReplace > &_rxEvents, const sal_uInt16 _nInitiallySelectedEvent)=0
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
bool SetLayoutRTL(SCTAB nTab, bool bRTL)
void DisableItem(sal_uInt16 nWhich)
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
bool IsDocEditable() const
SCTAB GetLastSelected() const
const ScSheetSourceDesc * GetSheetDesc() const
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
const ScDocument & GetDocument() const
void ExecuteTable(SfxRequest &rReq)
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
void SetDocumentModified()
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
void AppendItem(const SfxPoolItem &)
void SetShowGrid(bool bShow)
static SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
bool GetTableSelect(SCTAB nTab) const
std::set< SCTAB > MarkedTabsType
This class contains authoritative information on the internal reference used as the data source for d...
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
Create before modifications of the document and destroy thereafter.
::std::vector< ScUndoTabColorInfo > List
constexpr OStringLiteral HID_SC_APPEND_NAME
ViewShellId GetViewShellId() const override