Avoid potential negative array index access to cached text.
[LibreOffice.git] / extensions / source / abpilot / tableselectionpage.cxx
blobabf8e582967aaf61fbe885984b7300ec84395b66
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 #include "tableselectionpage.hxx"
21 #include "abptypes.hxx"
22 #include "addresssettings.hxx"
23 #include "abspilot.hxx"
24 #include <tools/debug.hxx>
27 namespace abp
30 TableSelectionPage::TableSelectionPage(weld::Container* pPage, OAddressBookSourcePilot* pController)
31 : AddressBookSourcePage(pPage, pController, "modules/sabpilot/ui/selecttablepage.ui", "SelectTablePage")
32 , m_xTableList(m_xBuilder->weld_tree_view("table"))
34 m_xTableList->connect_changed( LINK( this, TableSelectionPage, OnTableSelected ) );
35 m_xTableList->connect_row_activated( LINK( this, TableSelectionPage, OnTableDoubleClicked ) );
38 TableSelectionPage::~TableSelectionPage()
42 void TableSelectionPage::Activate()
44 AddressBookSourcePage::Activate();
46 m_xTableList->grab_focus();
49 void TableSelectionPage::initializePage()
51 AddressBookSourcePage::initializePage();
53 const AddressSettings& rSettings = getSettings();
55 m_xTableList->clear();
57 // get the table names
58 const StringBag& aTableNames = getDialog()->getDataSource().getTableNames();
59 DBG_ASSERT( aTableNames.size() > 1, "TableSelectionPage::initializePage: to be called for more than one table only!");
60 // this page should never bother the user if there is 1 or less tables.
62 // fill the list
63 for (auto const& tableName : aTableNames)
64 m_xTableList->append_text(tableName);
66 // initially select the proper table
67 m_xTableList->select_text(rSettings.sSelectedTable);
70 IMPL_LINK_NOARG( TableSelectionPage, OnTableDoubleClicked, weld::TreeView&, bool )
72 if (m_xTableList->count_selected_rows() == 1)
73 getDialog()->travelNext();
74 return true;
77 IMPL_LINK_NOARG( TableSelectionPage, OnTableSelected, weld::TreeView&, void )
79 updateDialogTravelUI();
82 bool TableSelectionPage::commitPage( ::vcl::WizardTypes::CommitPageReason _eReason )
84 if (!AddressBookSourcePage::commitPage(_eReason))
85 return false;
87 AddressSettings& rSettings = getSettings();
88 rSettings.sSelectedTable = m_xTableList->get_selected_text();
90 return true;
93 bool TableSelectionPage::canAdvance() const
95 return AddressBookSourcePage::canAdvance()
96 && (m_xTableList->count_selected_rows() > 0);
99 } // namespace abp
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */