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 <vcl/layout.hxx>
21 #include <osl/file.hxx>
24 #include "nameclashdlg.hxx"
26 // NameClashDialog ---------------------------------------------------------
28 IMPL_LINK( NameClashDialog
, ButtonHdl_Impl
, PushButton
*, pBtn
)
30 long nRet
= (long) ABORT
;
31 if ( m_pBtnRename
== pBtn
)
34 OUString aNewName
= m_pEDNewName
->GetText();
35 if ( ( aNewName
== maNewName
) || aNewName
.isEmpty() )
37 ScopedVclPtrInstance
< MessageDialog
> aError(nullptr, maSameName
);
43 else if ( m_pBtnOverwrite
== pBtn
)
44 nRet
= (long) OVERWRITE
;
52 NameClashDialog::NameClashDialog( vcl::Window
* pParent
, ResMgr
* pResMgr
,
53 OUString
const & rTargetFolderURL
,
54 OUString
const & rClashingName
,
55 OUString
const & rProposedNewName
,
56 bool bAllowOverwrite
)
57 : ModalDialog( pParent
, "SimpleNameClashDialog", "uui/ui/simplenameclash.ui" ),
58 maNewName ( rClashingName
)
60 get(m_pFTMessage
, "warning");
61 get(m_pEDNewName
, "newname");
62 get(m_pBtnOverwrite
, "replace");
63 get(m_pBtnRename
, "rename");
64 get(m_pBtnCancel
, "cancel");
66 Link
<> aLink( LINK( this, NameClashDialog
, ButtonHdl_Impl
) );
67 m_pBtnOverwrite
->SetClickHdl( aLink
);
68 m_pBtnRename
->SetClickHdl( aLink
);
69 m_pBtnCancel
->SetClickHdl( aLink
);
72 if ( bAllowOverwrite
)
74 aInfo
= ResId(STR_RENAME_OR_REPLACE
, *pResMgr
).toString();
78 aInfo
= ResId(STR_NAME_CLASH_RENAME_ONLY
, *pResMgr
).toString();
79 m_pBtnOverwrite
->Hide();
83 if ( osl::FileBase::E_None
!= osl::FileBase::getSystemPathFromFileURL( rTargetFolderURL
, aPath
) )
84 aPath
= rTargetFolderURL
;
86 maSameName
= ResId(STR_SAME_NAME_USED
, *pResMgr
).toString();
88 aInfo
= aInfo
.replaceFirst( "%NAME", rClashingName
);
89 aInfo
= aInfo
.replaceFirst( "%FOLDER", aPath
);
90 m_pFTMessage
->SetText( aInfo
);
91 if ( !rProposedNewName
.isEmpty() )
92 m_pEDNewName
->SetText( rProposedNewName
);
94 m_pEDNewName
->SetText( rClashingName
);
97 NameClashDialog::~NameClashDialog()
102 void NameClashDialog::dispose()
104 m_pFTMessage
.clear();
105 m_pEDNewName
.clear();
106 m_pBtnOverwrite
.clear();
107 m_pBtnRename
.clear();
108 m_pBtnCancel
.clear();
109 ModalDialog::dispose();
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */