LibreOffice Module fpicker (master) 1
PlacesListBox.cxx
Go to the documentation of this file.
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 "PlacesListBox.hxx"
12
13#include <bitmaps.hlst>
14
15PlacesListBox::PlacesListBox(std::unique_ptr<weld::TreeView> xControl,
16 std::unique_ptr<weld::Button> xAdd,
17 std::unique_ptr<weld::Button> xDel,
18 SvtFileDialog* pFileDlg)
19 : mpDlg(pFileDlg)
20 , mxImpl(std::move(xControl))
21 , mxAddBtn(std::move(xAdd))
22 , mxDelBtn(std::move(xDel))
23 , mnNbEditables(0)
24 , mbUpdated( false )
25{
26 Size aSize(mxImpl->get_approximate_digit_width() * 18,
27 mxImpl->get_height_rows(9));
28 mxImpl->set_size_request(aSize.Width(), aSize.Height());
29
30 mxImpl->connect_changed( LINK( this, PlacesListBox, Selection ) );
31 mxImpl->connect_row_activated( LINK( this, PlacesListBox, DoubleClick ) ) ;
32 mxImpl->connect_query_tooltip(LINK(this, PlacesListBox, QueryTooltipHdl));
33}
34
36{
37}
38
40{
41 maPlaces.push_back( pPlace );
42 mxImpl->append_text(pPlace->GetName());
43 mxImpl->set_image(maPlaces.size() - 1, getEntryIcon(pPlace));
44
45 if(pPlace->IsEditable()) {
47 mbUpdated = true;
48 }
49}
50
52 if(mbUpdated) {
53 mbUpdated = false;
54 return true;
55 }
56 return false;
57}
58
59void PlacesListBox::RemovePlace( sal_uInt16 nPos )
60{
61 if ( nPos < maPlaces.size() )
62 {
63 if(maPlaces[nPos]->IsEditable()) {
65 mbUpdated = true;
66 }
67 maPlaces.erase( maPlaces.begin() + nPos );
68 mxImpl->remove(nPos);
69 }
70}
71
73 RemovePlace(mxImpl->get_cursor_index());
74}
75
77{
78 mxAddBtn->connect_clicked( rHdl );
79}
80
82{
83 mxDelBtn->connect_clicked( rHdl );
84}
85
86void PlacesListBox::SetDelEnabled( bool enabled )
87{
88 mxDelBtn->set_sensitive( enabled );
89}
90
91OUString PlacesListBox::getEntryIcon( const PlacePtr& pPlace )
92{
93 OUString theImage = BMP_FILEDLG_PLACE_LOCAL;
94 if ( !pPlace->IsLocal( ) )
95 theImage = BMP_FILEDLG_PLACE_REMOTE;
96 return theImage;
97}
98
100{
101 sal_uInt32 nSelected = mxImpl->get_cursor_index();
102 PlacePtr pPlace = maPlaces[nSelected];
103
104 if (pPlace->IsEditable())
105 mpDlg->RemovablePlaceSelected();
106 else
107 mpDlg->RemovablePlaceSelected(false);
108
109 updateView();
110}
111
113{
114 sal_uInt16 nSelected = mxImpl->get_cursor_index();
115 PlacePtr pPlace = maPlaces[nSelected];
116 if ( !pPlace->IsEditable() || pPlace->IsLocal( ) )
117 return true;
118 PlaceEditDialog aDlg(mpDlg->getDialog(), pPlace);
119 short aRetCode = aDlg.run();
120 switch (aRetCode)
121 {
122 case RET_OK :
123 {
124 pPlace->SetName ( aDlg.GetServerName() );
125 pPlace->SetUrl( aDlg.GetServerUrl() );
126 mbUpdated = true;
127 break;
128 }
129 case RET_NO :
130 {
131 RemovePlace(nSelected);
132 break;
133 }
134 default:
135 break;
136 }
137 return true;
138}
139
140IMPL_LINK(PlacesListBox, QueryTooltipHdl, const weld::TreeIter&, rIter, OUString)
141{
142 const OUString sText = mxImpl->get_text(rIter);
143 for (const auto& pPlace : maPlaces)
144 {
145 if (pPlace->GetName() == sText)
146 return pPlace->GetUrlObject().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
147 }
148 return OUString();
149}
150
152{
153 sal_uInt32 nSelected = mxImpl->get_cursor_index();
154 PlacePtr pPlace = maPlaces[nSelected];
155 mpDlg->OpenURL_Impl( pPlace->GetUrl( ) );
156}
157
158/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK(PlacesListBox, QueryTooltipHdl, const weld::TreeIter &, rIter, OUString)
IMPL_LINK_NOARG(PlacesListBox, Selection, weld::TreeView &, void)
std::shared_ptr< Place > PlacePtr
ListBox to handle Places.
std::unique_ptr< weld::Button > mxAddBtn
void AppendPlace(const PlacePtr &pPlace)
SvtFileDialog * mpDlg
void RemoveSelectedPlace()
std::unique_ptr< weld::Button > mxDelBtn
void RemovePlace(sal_uInt16 nPos)
void SetAddHdl(const Link< weld::Button &, void > &rHdl)
PlacesListBox(std::unique_ptr< weld::TreeView > xTreeView, std::unique_ptr< weld::Button > xAddBtn, std::unique_ptr< weld::Button > xDelBtn, SvtFileDialog *pFileDlg)
void SetDelHdl(const Link< weld::Button &, void > &rHdl)
std::unique_ptr< weld::TreeView > mxImpl
std::vector< PlacePtr > maPlaces
void SetDelEnabled(bool enabled)
static OUString getEntryIcon(const PlacePtr &pPlace)
sal_Int32 mnNbEditables
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void OpenURL_Impl(const OUString &rURL)
Definition: iodlg.cxx:1694
sal_uInt16 nPos
RET_OK
RET_NO