summaryrefslogtreecommitdiffstats
path: root/fpicker/source/office/PlacesListBox.cxx
blob: 2fc919f9b1d910d32f8fdcba5beb9f40457287a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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: */