Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <vcl/layout.hxx>
21 : #include <osl/file.hxx>
22 :
23 : #include "ids.hrc"
24 : #include "nameclashdlg.hxx"
25 :
26 : // NameClashDialog ---------------------------------------------------------
27 :
28 0 : IMPL_LINK( NameClashDialog, ButtonHdl_Impl, PushButton *, pBtn )
29 : {
30 0 : long nRet = (long) ABORT;
31 0 : if ( m_pBtnRename == pBtn )
32 : {
33 0 : nRet = (long) RENAME;
34 0 : OUString aNewName = m_pEDNewName->GetText();
35 0 : if ( ( aNewName == maNewName ) || aNewName.isEmpty() )
36 : {
37 0 : ScopedVclPtrInstance< MessageDialog > aError(nullptr, maSameName);
38 0 : aError->Execute();
39 0 : return 1;
40 : }
41 0 : maNewName = aNewName;
42 : }
43 0 : else if ( m_pBtnOverwrite == pBtn )
44 0 : nRet = (long) OVERWRITE;
45 :
46 0 : EndDialog( nRet );
47 :
48 0 : return 1;
49 : }
50 :
51 :
52 0 : NameClashDialog::NameClashDialog( vcl::Window* pParent, ResMgr* pResMgr,
53 : OUString const & rTargetFolderURL,
54 : OUString const & rClashingName,
55 : OUString const & rProposedNewName,
56 : bool bAllowOverwrite )
57 : : ModalDialog( pParent, "SimpleNameClashDialog", "uui/ui/simplenameclash.ui" ),
58 0 : maNewName ( rClashingName )
59 : {
60 0 : get(m_pFTMessage, "warning");
61 0 : get(m_pEDNewName, "newname");
62 0 : get(m_pBtnOverwrite, "replace");
63 0 : get(m_pBtnRename, "rename");
64 0 : get(m_pBtnCancel, "cancel");
65 :
66 0 : Link<> aLink( LINK( this, NameClashDialog, ButtonHdl_Impl ) );
67 0 : m_pBtnOverwrite->SetClickHdl( aLink );
68 0 : m_pBtnRename->SetClickHdl( aLink );
69 0 : m_pBtnCancel->SetClickHdl( aLink );
70 :
71 0 : OUString aInfo;
72 0 : if ( bAllowOverwrite )
73 : {
74 0 : aInfo = ResId(STR_RENAME_OR_REPLACE, *pResMgr).toString();
75 : }
76 : else
77 : {
78 0 : aInfo = ResId(STR_NAME_CLASH_RENAME_ONLY, *pResMgr).toString();
79 0 : m_pBtnOverwrite->Hide();
80 : }
81 :
82 0 : OUString aPath;
83 0 : if ( osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL( rTargetFolderURL, aPath ) )
84 0 : aPath = rTargetFolderURL;
85 :
86 0 : maSameName = ResId(STR_SAME_NAME_USED, *pResMgr).toString();
87 :
88 0 : aInfo = aInfo.replaceFirst( "%NAME", rClashingName );
89 0 : aInfo = aInfo.replaceFirst( "%FOLDER", aPath );
90 0 : m_pFTMessage->SetText( aInfo );
91 0 : if ( !rProposedNewName.isEmpty() )
92 0 : m_pEDNewName->SetText( rProposedNewName );
93 : else
94 0 : m_pEDNewName->SetText( rClashingName );
95 0 : }
96 :
97 0 : NameClashDialog::~NameClashDialog()
98 : {
99 0 : disposeOnce();
100 0 : }
101 :
102 0 : void NameClashDialog::dispose()
103 : {
104 0 : m_pFTMessage.clear();
105 0 : m_pEDNewName.clear();
106 0 : m_pBtnOverwrite.clear();
107 0 : m_pBtnRename.clear();
108 0 : m_pBtnCancel.clear();
109 0 : ModalDialog::dispose();
110 159 : }
111 :
112 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|