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/.
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 <sal/config.h>
22 #include <string_view>
24 #include "fileview.hxx"
25 #include "iodlgimp.hxx"
26 #include <tools/debug.hxx>
27 #include <tools/urlobj.hxx>
28 #include <svtools/inettbc.hxx>
30 #include <svtools/imagemgr.hxx>
31 #include <svl/svlresid.hxx>
32 #include <svl/svl.hrc>
35 using namespace ::com::sun::star::uno
;
37 SvtFileDialogFilter_Impl::SvtFileDialogFilter_Impl( OUString aName
, OUString aType
)
38 : m_aName(std::move( aName
))
39 , m_aType(std::move( aType
))
41 m_aType
= m_aType
.toAsciiLowerCase();
44 SvtFileDialogFilter_Impl::~SvtFileDialogFilter_Impl()
49 SvtUpButton_Impl::SvtUpButton_Impl(std::unique_ptr
<weld::Toolbar
> xToolbar
,
50 std::unique_ptr
<weld::Menu
> xMenu
,
52 : m_xToolbar(std::move(xToolbar
))
53 , m_xMenu(std::move(xMenu
))
56 m_xToolbar
->set_item_menu(u
"up_btn"_ustr
, m_xMenu
.get());
57 m_xToolbar
->connect_clicked(LINK(this, SvtUpButton_Impl
, ClickHdl
));
58 m_xMenu
->connect_activate(LINK(this, SvtUpButton_Impl
, SelectHdl
));
61 void SvtUpButton_Impl::FillURLMenu()
63 SvtFileView
* pBox
= m_pDlg
->GetView();
65 sal_uInt16 nItemId
= 1;
70 // determine parent levels
71 INetURLObject
aObject( pBox
->GetViewURL() );
72 sal_Int32 nCount
= aObject
.getSegmentCount();
74 ::svtools::VolumeInfo
aVolInfo( true /* volume */, false /* remote */,
75 false /* removable */, false /* floppy */,
76 false /* compact disk */ );
77 OUString
aVolumeImage( SvFileInformationManager::GetFolderImageId( aVolInfo
) );
81 aObject
.removeSegment();
82 OUString
aParentURL(aObject
.GetMainURL(INetURLObject::DecodeMechanism::NONE
));
86 if (nCount
== 1) // adjust the title of the top level entry (the workspace)
87 aTitle
= SvlResId(STR_SVT_MIMETYPE_CNT_FSYSBOX
);
88 else if (!m_pDlg
->ContentGetTitle(aParentURL
, aTitle
) || aTitle
.isEmpty())
89 aTitle
= aObject
.getName();
91 OUString aImage
= ( nCount
> 1 ) // if nCount == 1 means workplace, which detects the wrong image
92 ? SvFileInformationManager::GetImageId( aObject
) : aVolumeImage
;
94 m_xMenu
->append(OUString::number(nItemId
), aTitle
, aImage
);
95 aURLs
.push_back(aParentURL
);
102 IMPL_LINK(SvtUpButton_Impl
, SelectHdl
, const OUString
&, rId
, void)
104 sal_uInt32 nId
= rId
.toUInt32();
108 assert( nId
<= aURLs
.size() && "SvtUpButton_Impl: wrong index" );
110 m_pDlg
->OpenURL_Impl(aURLs
[nId
]);
114 IMPL_LINK_NOARG(SvtUpButton_Impl
, ClickHdl
, const OUString
&, void)
116 m_pDlg
->PrevLevel_Impl();
119 // SvtExpFileDlg_Impl
120 SvtExpFileDlg_Impl::SvtExpFileDlg_Impl()
121 : m_pCurFilter( nullptr )
122 , m_eMode( FILEDLG_MODE_OPEN
)
123 , m_eDlgType( FILEDLG_TYPE_FILEDLG
)
124 , m_nStyle( PickerFlags::NONE
)
125 , m_aFilterIdle("fpicker SvtExpFileDlg_Impl m_aFilterIdle")
126 , m_bDoubleClick( false )
127 , m_bMultiSelection( false )
131 SvtExpFileDlg_Impl::~SvtExpFileDlg_Impl()
135 void SvtExpFileDlg_Impl::SetStandardDir( const OUString
& _rDir
)
138 if (m_aStdDir
.isEmpty())
139 m_aStdDir
= "file:///";
143 OUString
lcl_DecoratedFilter( std::u16string_view _rOriginalFilter
)
145 return "<" + OUString::Concat(_rOriginalFilter
) + ">";
149 void SvtExpFileDlg_Impl::SetCurFilter( SvtFileDialogFilter_Impl
const * pFilter
, const OUString
& rDisplayName
)
151 assert(pFilter
&& "SvtExpFileDlg_Impl::SetCurFilter: invalid filter!");
152 DBG_ASSERT( ( rDisplayName
== pFilter
->GetName() )
153 || ( rDisplayName
== lcl_DecoratedFilter( pFilter
->GetName() ) ),
154 "SvtExpFileDlg_Impl::SetCurFilter: arguments are inconsistent!" );
156 m_pCurFilter
= pFilter
;
157 m_sCurrentFilterDisplayName
= rDisplayName
;
160 void SvtExpFileDlg_Impl::InsertFilterListEntry(const SvtFileDialogFilter_Impl
* pFilterDesc
)
162 // insert and set user data
163 OUString
sId(weld::toId(pFilterDesc
));
164 const OUString
& sName
= pFilterDesc
->GetName();
165 if (pFilterDesc
->isGroupSeparator())
166 m_xLbFilter
->append_separator(sId
);
168 m_xLbFilter
->append(sId
, sName
);
171 void SvtExpFileDlg_Impl::InitFilterList( )
173 // clear the current list
174 m_xLbFilter
->clear();
177 sal_uInt16 nPos
= m_aFilter
.size();
179 // search for the first entry which is no group separator
180 while ( nPos
-- && m_aFilter
[ nPos
]->isGroupSeparator() )
183 // add all following entries
184 while ( static_cast<sal_Int16
>(nPos
) >= 0 )
185 InsertFilterListEntry( m_aFilter
[ nPos
-- ].get() );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */