xref: /aoo42x/main/uui/source/nameclashdlg.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "vcl/msgbox.hxx"
29*cdf0e10cSrcweir #include "osl/file.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "ids.hrc"
32*cdf0e10cSrcweir #include "nameclashdlg.hrc"
33*cdf0e10cSrcweir #include "nameclashdlg.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // NameClashDialog ---------------------------------------------------------
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir IMPL_LINK( NameClashDialog, ButtonHdl_Impl, PushButton *, pBtn )
38*cdf0e10cSrcweir {
39*cdf0e10cSrcweir 	long nRet = (long) ABORT;
40*cdf0e10cSrcweir 	if ( &maBtnRename == pBtn )
41*cdf0e10cSrcweir 	{
42*cdf0e10cSrcweir 	    nRet = (long) RENAME;
43*cdf0e10cSrcweir 	    rtl::OUString aNewName = maEDNewName.GetText();
44*cdf0e10cSrcweir 	    if ( ( aNewName == maNewName ) || !aNewName.getLength() )
45*cdf0e10cSrcweir 	    {
46*cdf0e10cSrcweir 	        ErrorBox aError( NULL, WB_OK, maSameName );
47*cdf0e10cSrcweir             aError.Execute();
48*cdf0e10cSrcweir 	        return 1;
49*cdf0e10cSrcweir 	    }
50*cdf0e10cSrcweir 	    maNewName = aNewName;
51*cdf0e10cSrcweir 	}
52*cdf0e10cSrcweir 	else if ( &maBtnOverwrite == pBtn )
53*cdf0e10cSrcweir 	    nRet = (long) OVERWRITE;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 	EndDialog( nRet );
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 	return 1;
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // -----------------------------------------------------------------------
61*cdf0e10cSrcweir NameClashDialog::NameClashDialog( Window* pParent, ResMgr* pResMgr,
62*cdf0e10cSrcweir                                   rtl::OUString const & rTargetFolderURL,
63*cdf0e10cSrcweir                                   rtl::OUString const & rClashingName,
64*cdf0e10cSrcweir                                   rtl::OUString const & rProposedNewName,
65*cdf0e10cSrcweir                                   bool bAllowOverwrite )
66*cdf0e10cSrcweir     : ModalDialog( pParent, ResId( DLG_SIMPLE_NAME_CLASH, *pResMgr ) ),
67*cdf0e10cSrcweir 	maFTMessage            ( this, ResId( FT_FILE_EXISTS_WARNING, *pResMgr ) ),
68*cdf0e10cSrcweir 	maEDNewName            ( this, ResId( EDIT_NEW_NAME, *pResMgr ) ),
69*cdf0e10cSrcweir 	maBtnOverwrite         ( this, ResId( BTN_OVERWRITE, *pResMgr ) ),
70*cdf0e10cSrcweir 	maBtnRename            ( this, ResId( BTN_RENAME, *pResMgr ) ),
71*cdf0e10cSrcweir 	maBtnCancel            ( this, ResId( BTN_CANCEL, *pResMgr ) ),
72*cdf0e10cSrcweir 	maBtnHelp              ( this, ResId( BTN_HELP, *pResMgr ) ),
73*cdf0e10cSrcweir 	maNewName              ( rClashingName )
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	FreeResource();
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	Link aLink( LINK( this, NameClashDialog, ButtonHdl_Impl ) );
78*cdf0e10cSrcweir 	maBtnOverwrite.SetClickHdl( aLink );
79*cdf0e10cSrcweir 	maBtnRename.SetClickHdl( aLink );
80*cdf0e10cSrcweir 	maBtnCancel.SetClickHdl( aLink );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	String aInfo;
83*cdf0e10cSrcweir 	if ( bAllowOverwrite )
84*cdf0e10cSrcweir 	{
85*cdf0e10cSrcweir 	    aInfo = String( ResId( STR_RENAME_OR_REPLACE, *pResMgr ) );
86*cdf0e10cSrcweir 	}
87*cdf0e10cSrcweir 	else
88*cdf0e10cSrcweir 	{
89*cdf0e10cSrcweir 	    aInfo = String( ResId( STR_NAME_CLASH_RENAME_ONLY, *pResMgr ) );
90*cdf0e10cSrcweir 	    maBtnOverwrite.Hide();
91*cdf0e10cSrcweir 	}
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	rtl::OUString aPath;
94*cdf0e10cSrcweir 	if ( osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL( rTargetFolderURL, aPath ) )
95*cdf0e10cSrcweir 	    aPath = rTargetFolderURL;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	maSameName = String ( ResId( STR_SAME_NAME_USED, *pResMgr ) );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 	aInfo.SearchAndReplaceAscii( "%NAME", rClashingName );
100*cdf0e10cSrcweir 	aInfo.SearchAndReplaceAscii( "%FOLDER", aPath );
101*cdf0e10cSrcweir 	maFTMessage.SetText( aInfo );
102*cdf0e10cSrcweir 	if ( rProposedNewName.getLength() )
103*cdf0e10cSrcweir 	    maEDNewName.SetText( rProposedNewName );
104*cdf0e10cSrcweir 	else
105*cdf0e10cSrcweir 	    maEDNewName.SetText( rClashingName );
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108