1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "PlacesListBox.hxx"
11 #include <svtools/PlaceEditDialog.hxx>
13 #include <bitmaps.hlst>
15 PlacesListBox::PlacesListBox(std::unique_ptr
<weld::TreeView
> xControl
,
16 std::unique_ptr
<weld::Button
> xAdd
,
17 std::unique_ptr
<weld::Button
> xDel
,
18 SvtFileDialog
* pFileDlg
)
20 , mxImpl(std::move(xControl
))
21 , mxAddBtn(std::move(xAdd
))
22 , mxDelBtn(std::move(xDel
))
26 Size
aSize(mxImpl
->get_approximate_digit_width() * 18,
27 mxImpl
->get_height_rows(9));
28 mxImpl
->set_size_request(aSize
.Width(), aSize
.Height());
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
));
35 PlacesListBox::~PlacesListBox( )
39 void PlacesListBox::AppendPlace( const PlacePtr
& pPlace
)
41 maPlaces
.push_back( pPlace
);
42 mxImpl
->append_text(pPlace
->GetName());
43 mxImpl
->set_image(maPlaces
.size() - 1, getEntryIcon(pPlace
));
45 if(pPlace
->IsEditable()) {
51 bool PlacesListBox::IsUpdated() {
59 void PlacesListBox::RemovePlace( sal_uInt16 nPos
)
61 if ( nPos
< maPlaces
.size() )
63 if(maPlaces
[nPos
]->IsEditable()) {
67 maPlaces
.erase( maPlaces
.begin() + nPos
);
72 void PlacesListBox::RemoveSelectedPlace() {
73 RemovePlace(mxImpl
->get_cursor_index());
76 void PlacesListBox::SetAddHdl( const Link
<weld::Button
&,void>& rHdl
)
78 mxAddBtn
->connect_clicked( rHdl
);
81 void PlacesListBox::SetDelHdl( const Link
<weld::Button
&,void>& rHdl
)
83 mxDelBtn
->connect_clicked( rHdl
);
86 void PlacesListBox::SetDelEnabled( bool enabled
)
88 mxDelBtn
->set_sensitive( enabled
);
91 OUString
PlacesListBox::getEntryIcon( const PlacePtr
& pPlace
)
93 OUString theImage
= BMP_FILEDLG_PLACE_LOCAL
;
94 if ( !pPlace
->IsLocal( ) )
95 theImage
= BMP_FILEDLG_PLACE_REMOTE
;
99 IMPL_LINK_NOARG( PlacesListBox
, Selection
, weld::TreeView
&, void )
101 sal_uInt32 nSelected
= mxImpl
->get_cursor_index();
102 PlacePtr pPlace
= maPlaces
[nSelected
];
104 if (pPlace
->IsEditable())
105 mpDlg
->RemovablePlaceSelected();
107 mpDlg
->RemovablePlaceSelected(false);
112 IMPL_LINK_NOARG( PlacesListBox
, DoubleClick
, weld::TreeView
&, bool )
114 sal_uInt16 nSelected
= mxImpl
->get_cursor_index();
115 PlacePtr pPlace
= maPlaces
[nSelected
];
116 if ( !pPlace
->IsEditable() || pPlace
->IsLocal( ) )
118 PlaceEditDialog
aDlg(mpDlg
->getDialog(), pPlace
);
119 short aRetCode
= aDlg
.run();
124 pPlace
->SetName ( aDlg
.GetServerName() );
125 pPlace
->SetUrl( aDlg
.GetServerUrl() );
131 RemovePlace(nSelected
);
140 IMPL_LINK(PlacesListBox
, QueryTooltipHdl
, const weld::TreeIter
&, rIter
, OUString
)
142 const OUString sText
= mxImpl
->get_text(rIter
);
143 for (const auto& pPlace
: maPlaces
)
145 if (pPlace
->GetName() == sText
)
146 return pPlace
->GetUrlObject().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous
);
151 void PlacesListBox::updateView( )
153 sal_uInt32 nSelected
= mxImpl
->get_cursor_index();
154 PlacePtr pPlace
= maPlaces
[nSelected
];
155 mpDlg
->OpenURL_Impl( pPlace
->GetUrl( ) );
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */