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/msgbox.hxx"
21 #include "osl/file.hxx"
24 #include "nameclashdlg.hrc"
25 #include "nameclashdlg.hxx"
27 // NameClashDialog ---------------------------------------------------------
29 IMPL_LINK( NameClashDialog
, ButtonHdl_Impl
, PushButton
*, pBtn
)
31 long nRet
= (long) ABORT
;
32 if ( &maBtnRename
== pBtn
)
35 rtl::OUString aNewName
= maEDNewName
.GetText();
36 if ( ( aNewName
== maNewName
) || aNewName
.isEmpty() )
38 ErrorBox
aError( NULL
, WB_OK
, maSameName
);
44 else if ( &maBtnOverwrite
== pBtn
)
45 nRet
= (long) OVERWRITE
;
52 // -----------------------------------------------------------------------
53 NameClashDialog::NameClashDialog( Window
* pParent
, ResMgr
* pResMgr
,
54 rtl::OUString
const & rTargetFolderURL
,
55 rtl::OUString
const & rClashingName
,
56 rtl::OUString
const & rProposedNewName
,
57 bool bAllowOverwrite
)
58 : ModalDialog( pParent
, ResId( DLG_SIMPLE_NAME_CLASH
, *pResMgr
) ),
59 maFTMessage ( this, ResId( FT_FILE_EXISTS_WARNING
, *pResMgr
) ),
60 maEDNewName ( this, ResId( EDIT_NEW_NAME
, *pResMgr
) ),
61 maBtnOverwrite ( this, ResId( BTN_OVERWRITE
, *pResMgr
) ),
62 maBtnRename ( this, ResId( BTN_RENAME
, *pResMgr
) ),
63 maBtnCancel ( this, ResId( BTN_CANCEL
, *pResMgr
) ),
64 maBtnHelp ( this, ResId( BTN_HELP
, *pResMgr
) ),
65 maNewName ( rClashingName
)
69 Link
aLink( LINK( this, NameClashDialog
, ButtonHdl_Impl
) );
70 maBtnOverwrite
.SetClickHdl( aLink
);
71 maBtnRename
.SetClickHdl( aLink
);
72 maBtnCancel
.SetClickHdl( aLink
);
75 if ( bAllowOverwrite
)
77 aInfo
= ResId(STR_RENAME_OR_REPLACE
, *pResMgr
).toString();
81 aInfo
= ResId(STR_NAME_CLASH_RENAME_ONLY
, *pResMgr
).toString();
82 maBtnOverwrite
.Hide();
86 if ( osl::FileBase::E_None
!= osl::FileBase::getSystemPathFromFileURL( rTargetFolderURL
, aPath
) )
87 aPath
= rTargetFolderURL
;
89 maSameName
= ResId(STR_SAME_NAME_USED
, *pResMgr
).toString();
91 aInfo
.SearchAndReplaceAscii( "%NAME", rClashingName
);
92 aInfo
.SearchAndReplaceAscii( "%FOLDER", aPath
);
93 maFTMessage
.SetText( aInfo
);
94 if ( !rProposedNewName
.isEmpty() )
95 maEDNewName
.SetText( rProposedNewName
);
97 maEDNewName
.SetText( rClashingName
);
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */