tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / namedlg / namepast.cxx
blobb31a4fbd09957b79647b185a73eb6dc695da7043
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <namepast.hxx>
23 #include <docsh.hxx>
24 #include <rangenam.hxx>
25 #include <viewdata.hxx>
26 #include <scui_def.hxx>
27 #include <globstr.hrc>
28 #include <scresid.hxx>
29 #include <compiler.hxx>
31 ScNamePasteDlg::ScNamePasteDlg(weld::Window* pParent, ScDocShell* pShell)
32 : GenericDialogController(pParent, u"modules/scalc/ui/insertname.ui"_ustr,
33 u"InsertNameDialog"_ustr)
34 , m_xBtnPasteAll(m_xBuilder->weld_button(u"pasteall"_ustr))
35 , m_xBtnPaste(m_xBuilder->weld_button(u"paste"_ustr))
36 , m_xBtnClose(m_xBuilder->weld_button(u"close"_ustr))
38 ScDocument& rDoc = pShell->GetDocument();
39 m_aSheetSep = OUString(rDoc.GetSheetSeparator());
40 std::map<OUString, ScRangeName*> aCopyMap;
41 rDoc.GetRangeNameMap(aCopyMap);
42 for (const auto & [ aTemp, pName ] : aCopyMap)
44 m_RangeMap.insert(std::make_pair(aTemp, *pName));
47 ScAddress aPos;
48 if (ScViewData* pViewData = ScDocShell::GetViewData())
49 aPos = ScAddress(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
51 std::unique_ptr<weld::TreeView> xTreeView(m_xBuilder->weld_tree_view(u"ctrl"_ustr));
52 xTreeView->set_size_request(xTreeView->get_approximate_digit_width() * 75,
53 xTreeView->get_height_rows(10));
54 m_xTable.reset(new ScRangeManagerTable(std::move(xTreeView), m_RangeMap, aPos));
56 m_xBtnPaste->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
57 m_xBtnPasteAll->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
58 m_xBtnClose->connect_clicked(LINK(this, ScNamePasteDlg, ButtonHdl));
60 if (!m_xTable->n_children())
62 m_xBtnPaste->set_sensitive(false);
63 m_xBtnPasteAll->set_sensitive(false);
67 ScNamePasteDlg::~ScNamePasteDlg() {}
69 IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button&, rButton, void)
71 if (&rButton == m_xBtnPasteAll.get())
73 m_xDialog->response(BTN_PASTE_LIST);
75 else if (&rButton == m_xBtnPaste.get())
77 const OUString aGlobalScope(ScResId(STR_GLOBAL_SCOPE));
78 std::vector<ScRangeNameLine> aSelectedLines = m_xTable->GetSelectedEntries();
79 for (const auto& rLine : aSelectedLines)
81 if (rLine.aScope == aGlobalScope)
82 maSelectedNames.push_back(rLine.aName);
83 else
85 OUString aSheet(rLine.aScope);
86 ScCompiler::CheckTabQuotes(aSheet);
87 maSelectedNames.push_back(aSheet + m_aSheetSep + rLine.aName);
90 m_xDialog->response(BTN_PASTE_NAME);
92 else if (&rButton == m_xBtnClose.get())
94 m_xDialog->response(BTN_PASTE_CLOSE);
98 const std::vector<OUString>& ScNamePasteDlg::GetSelectedNames() const { return maSelectedNames; }
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */