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