xref: /aoo42x/main/uui/source/nameclashdlg.cxx (revision 79aad27f)
1*859212d1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*859212d1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*859212d1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*859212d1SAndrew Rist  * distributed with this work for additional information
6*859212d1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*859212d1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*859212d1SAndrew Rist  * "License"); you may not use this file except in compliance
9*859212d1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*859212d1SAndrew Rist  *
11*859212d1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*859212d1SAndrew Rist  *
13*859212d1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*859212d1SAndrew Rist  * software distributed under the License is distributed on an
15*859212d1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*859212d1SAndrew Rist  * KIND, either express or implied.  See the License for the
17*859212d1SAndrew Rist  * specific language governing permissions and limitations
18*859212d1SAndrew Rist  * under the License.
19*859212d1SAndrew Rist  *
20*859212d1SAndrew Rist  *************************************************************/
21*859212d1SAndrew Rist 
22*859212d1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "vcl/msgbox.hxx"
25cdf0e10cSrcweir #include "osl/file.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "ids.hrc"
28cdf0e10cSrcweir #include "nameclashdlg.hrc"
29cdf0e10cSrcweir #include "nameclashdlg.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // NameClashDialog ---------------------------------------------------------
32cdf0e10cSrcweir 
IMPL_LINK(NameClashDialog,ButtonHdl_Impl,PushButton *,pBtn)33cdf0e10cSrcweir IMPL_LINK( NameClashDialog, ButtonHdl_Impl, PushButton *, pBtn )
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 	long nRet = (long) ABORT;
36cdf0e10cSrcweir 	if ( &maBtnRename == pBtn )
37cdf0e10cSrcweir 	{
38cdf0e10cSrcweir 	    nRet = (long) RENAME;
39cdf0e10cSrcweir 	    rtl::OUString aNewName = maEDNewName.GetText();
40cdf0e10cSrcweir 	    if ( ( aNewName == maNewName ) || !aNewName.getLength() )
41cdf0e10cSrcweir 	    {
42cdf0e10cSrcweir 	        ErrorBox aError( NULL, WB_OK, maSameName );
43cdf0e10cSrcweir             aError.Execute();
44cdf0e10cSrcweir 	        return 1;
45cdf0e10cSrcweir 	    }
46cdf0e10cSrcweir 	    maNewName = aNewName;
47cdf0e10cSrcweir 	}
48cdf0e10cSrcweir 	else if ( &maBtnOverwrite == pBtn )
49cdf0e10cSrcweir 	    nRet = (long) OVERWRITE;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	EndDialog( nRet );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	return 1;
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // -----------------------------------------------------------------------
NameClashDialog(Window * pParent,ResMgr * pResMgr,rtl::OUString const & rTargetFolderURL,rtl::OUString const & rClashingName,rtl::OUString const & rProposedNewName,bool bAllowOverwrite)57cdf0e10cSrcweir NameClashDialog::NameClashDialog( Window* pParent, ResMgr* pResMgr,
58cdf0e10cSrcweir                                   rtl::OUString const & rTargetFolderURL,
59cdf0e10cSrcweir                                   rtl::OUString const & rClashingName,
60cdf0e10cSrcweir                                   rtl::OUString const & rProposedNewName,
61cdf0e10cSrcweir                                   bool bAllowOverwrite )
62cdf0e10cSrcweir     : ModalDialog( pParent, ResId( DLG_SIMPLE_NAME_CLASH, *pResMgr ) ),
63cdf0e10cSrcweir 	maFTMessage            ( this, ResId( FT_FILE_EXISTS_WARNING, *pResMgr ) ),
64cdf0e10cSrcweir 	maEDNewName            ( this, ResId( EDIT_NEW_NAME, *pResMgr ) ),
65cdf0e10cSrcweir 	maBtnOverwrite         ( this, ResId( BTN_OVERWRITE, *pResMgr ) ),
66cdf0e10cSrcweir 	maBtnRename            ( this, ResId( BTN_RENAME, *pResMgr ) ),
67cdf0e10cSrcweir 	maBtnCancel            ( this, ResId( BTN_CANCEL, *pResMgr ) ),
68cdf0e10cSrcweir 	maBtnHelp              ( this, ResId( BTN_HELP, *pResMgr ) ),
69cdf0e10cSrcweir 	maNewName              ( rClashingName )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	FreeResource();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	Link aLink( LINK( this, NameClashDialog, ButtonHdl_Impl ) );
74cdf0e10cSrcweir 	maBtnOverwrite.SetClickHdl( aLink );
75cdf0e10cSrcweir 	maBtnRename.SetClickHdl( aLink );
76cdf0e10cSrcweir 	maBtnCancel.SetClickHdl( aLink );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	String aInfo;
79cdf0e10cSrcweir 	if ( bAllowOverwrite )
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 	    aInfo = String( ResId( STR_RENAME_OR_REPLACE, *pResMgr ) );
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir 	else
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 	    aInfo = String( ResId( STR_NAME_CLASH_RENAME_ONLY, *pResMgr ) );
86cdf0e10cSrcweir 	    maBtnOverwrite.Hide();
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	rtl::OUString aPath;
90cdf0e10cSrcweir 	if ( osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL( rTargetFolderURL, aPath ) )
91cdf0e10cSrcweir 	    aPath = rTargetFolderURL;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	maSameName = String ( ResId( STR_SAME_NAME_USED, *pResMgr ) );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	aInfo.SearchAndReplaceAscii( "%NAME", rClashingName );
96cdf0e10cSrcweir 	aInfo.SearchAndReplaceAscii( "%FOLDER", aPath );
97cdf0e10cSrcweir 	maFTMessage.SetText( aInfo );
98cdf0e10cSrcweir 	if ( rProposedNewName.getLength() )
99cdf0e10cSrcweir 	    maEDNewName.SetText( rProposedNewName );
100cdf0e10cSrcweir 	else
101cdf0e10cSrcweir 	    maEDNewName.SetText( rClashingName );
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104