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