diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /fpicker/source/office/PlacesListBox.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fpicker/source/office/PlacesListBox.cxx')
-rw-r--r-- | fpicker/source/office/PlacesListBox.cxx | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/fpicker/source/office/PlacesListBox.cxx b/fpicker/source/office/PlacesListBox.cxx new file mode 100644 index 000000000..2fc919f9b --- /dev/null +++ b/fpicker/source/office/PlacesListBox.cxx @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "PlacesListBox.hxx" +#include <svtools/PlaceEditDialog.hxx> + +#include <vcl/event.hxx> +#include <bitmaps.hlst> + +PlacesListBox::PlacesListBox(std::unique_ptr<weld::TreeView> xControl, + std::unique_ptr<weld::Button> xAdd, + std::unique_ptr<weld::Button> xDel, + SvtFileDialog* pFileDlg) + : maPlaces( ) + , mpDlg(pFileDlg) + , mxImpl(std::move(xControl)) + , mxAddBtn(std::move(xAdd)) + , mxDelBtn(std::move(xDel)) + , mnNbEditables(0) + , mbUpdated( false ) +{ + Size aSize(mxImpl->get_approximate_digit_width() * 18, + mxImpl->get_height_rows(9)); + mxImpl->set_size_request(aSize.Width(), aSize.Height()); + + mxImpl->connect_changed( LINK( this, PlacesListBox, Selection ) ); + mxImpl->connect_row_activated( LINK( this, PlacesListBox, DoubleClick ) ) ; +} + +PlacesListBox::~PlacesListBox( ) +{ +} + +void PlacesListBox::AppendPlace( const PlacePtr& pPlace ) +{ + maPlaces.push_back( pPlace ); + mxImpl->append_text(pPlace->GetName()); + mxImpl->set_image(maPlaces.size() - 1, getEntryIcon(pPlace)); + + if(pPlace->IsEditable()) { + ++mnNbEditables; + mbUpdated = true; + } +} + +bool PlacesListBox::IsUpdated() { + if(mbUpdated) { + mbUpdated = false; + return true; + } + return false; +} + +void PlacesListBox::RemovePlace( sal_uInt16 nPos ) +{ + if ( nPos < maPlaces.size() ) + { + if(maPlaces[nPos]->IsEditable()) { + --mnNbEditables; + mbUpdated = true; + } + maPlaces.erase( maPlaces.begin() + nPos ); + mxImpl->remove(nPos); + } +} + +void PlacesListBox::RemoveSelectedPlace() { + RemovePlace(mxImpl->get_cursor_index()); +} + +void PlacesListBox::SetAddHdl( const Link<weld::Button&,void>& rHdl ) +{ + mxAddBtn->connect_clicked( rHdl ); +} + +void PlacesListBox::SetDelHdl( const Link<weld::Button&,void>& rHdl ) +{ + mxDelBtn->connect_clicked( rHdl ); +} + +void PlacesListBox::SetDelEnabled( bool enabled ) +{ + mxDelBtn->set_sensitive( enabled ); +} + +OUString PlacesListBox::getEntryIcon( const PlacePtr& pPlace ) +{ + OUString theImage = BMP_FILEDLG_PLACE_LOCAL; + if ( !pPlace->IsLocal( ) ) + theImage = BMP_FILEDLG_PLACE_REMOTE; + return theImage; +} + +IMPL_LINK_NOARG( PlacesListBox, Selection, weld::TreeView&, void ) +{ + sal_uInt32 nSelected = mxImpl->get_cursor_index(); + PlacePtr pPlace = maPlaces[nSelected]; + + if (pPlace->IsEditable()) + mpDlg->RemovablePlaceSelected(); + else + mpDlg->RemovablePlaceSelected(false); + + updateView(); +} + +IMPL_LINK_NOARG( PlacesListBox, DoubleClick, weld::TreeView&, bool ) +{ + sal_uInt16 nSelected = mxImpl->get_cursor_index(); + PlacePtr pPlace = maPlaces[nSelected]; + if ( pPlace->IsEditable() && !pPlace->IsLocal( ) ) + { + PlaceEditDialog aDlg(mpDlg->getDialog(), pPlace); + short aRetCode = aDlg.run(); + switch (aRetCode) + { + case RET_OK : + { + pPlace->SetName ( aDlg.GetServerName() ); + pPlace->SetUrl( aDlg.GetServerUrl() ); + mbUpdated = true; + break; + } + case RET_NO : + { + RemovePlace(nSelected); + break; + } + default: + break; + } + } + return true; +} + +void PlacesListBox::updateView( ) +{ + sal_uInt32 nSelected = mxImpl->get_cursor_index(); + PlacePtr pPlace = maPlaces[nSelected]; + mpDlg->OpenURL_Impl( pPlace->GetUrl( ) ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |