/src/libreoffice/sc/source/ui/undo/UndoInsertSheetView.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include <undo/UndoInsertSheetView.hxx> |
11 | | #include <drwlayer.hxx> |
12 | | #include <globstr.hrc> |
13 | | #include <scresid.hxx> |
14 | | #include <document.hxx> |
15 | | #include <docsh.hxx> |
16 | | #include <tabvwsh.hxx> |
17 | | #include <undoolk.hxx> |
18 | | |
19 | | namespace sc |
20 | | { |
21 | | UndoInsertSheetView::UndoInsertSheetView(ScDocShell& rNewDocShell, SCTAB nTab, SCTAB nSheetViewTab, |
22 | | SheetViewID nSheetViewID) |
23 | 0 | : ScSimpleUndo(rNewDocShell) |
24 | 0 | , mnTab(nTab) |
25 | 0 | , mnSheetViewTab(nSheetViewTab) |
26 | 0 | , mnSheetViewID(nSheetViewID) |
27 | 0 | { |
28 | 0 | mpDrawUndo = GetSdrUndoAction(&rNewDocShell.GetDocument()); |
29 | 0 | } |
30 | | |
31 | 0 | UndoInsertSheetView::~UndoInsertSheetView() = default; |
32 | | |
33 | 0 | OUString UndoInsertSheetView::GetComment() const { return ScResId(STR_UNDO_INSERT_SHEET_VIEW); } |
34 | | |
35 | | void UndoInsertSheetView::Undo() |
36 | 0 | { |
37 | 0 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); |
38 | 0 | if (!pViewShell) |
39 | 0 | return; |
40 | | |
41 | | // Switch back to the default tab first |
42 | 0 | pViewShell->SetTabNo(mnTab); |
43 | |
|
44 | 0 | rDocShell.SetInUndo(true); |
45 | 0 | bDrawIsInUndo = true; |
46 | 0 | pViewShell->DeleteTable(mnSheetViewTab, false); |
47 | 0 | bDrawIsInUndo = false; |
48 | 0 | rDocShell.SetInUndo(false); |
49 | |
|
50 | 0 | DoSdrUndoAction(mpDrawUndo.get(), &rDocShell.GetDocument()); |
51 | |
|
52 | 0 | rDocShell.Broadcast(SfxHint(SfxHintId::ScForceSetTab)); |
53 | 0 | } |
54 | | |
55 | | void UndoInsertSheetView::Redo() |
56 | 0 | { |
57 | 0 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); |
58 | 0 | if (!pViewShell) |
59 | 0 | return; |
60 | | |
61 | 0 | RedoSdrUndoAction(mpDrawUndo.get()); |
62 | |
|
63 | 0 | rDocShell.SetInUndo(true); |
64 | 0 | bDrawIsInUndo = true; |
65 | |
|
66 | 0 | ScDocument& rDoc = rDocShell.GetDocument(); |
67 | 0 | auto[nNewID, nNewTab] = rDoc.CreateNewSheetView(mnTab); |
68 | 0 | if (nNewID != InvalidSheetViewID) |
69 | 0 | { |
70 | 0 | mnSheetViewID = nNewID; |
71 | 0 | mnSheetViewTab = nNewTab; |
72 | 0 | pViewShell->SetTabNo(mnSheetViewTab); |
73 | 0 | } |
74 | |
|
75 | 0 | bDrawIsInUndo = false; |
76 | 0 | rDocShell.SetInUndo(false); |
77 | 0 | } |
78 | | |
79 | 0 | void UndoInsertSheetView::Repeat(SfxRepeatTarget& /*rTarget*/) {} |
80 | | |
81 | 0 | bool UndoInsertSheetView::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return false; } |
82 | | |
83 | | } // end sc namespace |
84 | | |
85 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |