1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/file.hxx>
21 #include <unotools/resmgr.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
25 #include <strings.hrc>
26 #include "nameclashdlg.hxx"
28 // NameClashDialog ---------------------------------------------------------
30 IMPL_LINK(NameClashDialog
, ButtonHdl_Impl
, weld::Button
&, rBtn
, void)
32 tools::Long nRet
= tools::Long(ABORT
);
33 if (m_xBtnRename
.get() == &rBtn
)
35 nRet
= tools::Long(RENAME
);
36 OUString aNewName
= m_xEDNewName
->get_text();
37 if ( ( aNewName
== m_aNewName
) || aNewName
.isEmpty() )
39 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_xDialog
.get(),
40 VclMessageType::Warning
, VclButtonsType::Ok
,
45 m_aNewName
= aNewName
;
47 else if (m_xBtnOverwrite
.get() == &rBtn
)
48 nRet
= tools::Long(OVERWRITE
);
50 m_xDialog
->response(nRet
);
54 NameClashDialog::NameClashDialog( weld::Window
* pParent
, const std::locale
& rResLocale
,
55 OUString
const & rTargetFolderURL
,
56 OUString
const & rClashingName
,
57 OUString
const & rProposedNewName
,
58 bool bAllowOverwrite
)
59 : GenericDialogController(pParent
, "uui/ui/simplenameclash.ui", "SimpleNameClashDialog")
60 , m_aNewName(rClashingName
)
61 , m_xFTMessage(m_xBuilder
->weld_label("warning"))
62 , m_xEDNewName(m_xBuilder
->weld_entry("newname"))
63 , m_xBtnOverwrite(m_xBuilder
->weld_button("replace"))
64 , m_xBtnRename(m_xBuilder
->weld_button("rename"))
65 , m_xBtnCancel(m_xBuilder
->weld_button("cancel"))
67 Link
<weld::Button
&,void> aLink( LINK( this, NameClashDialog
, ButtonHdl_Impl
) );
68 m_xBtnOverwrite
->connect_clicked( aLink
);
69 m_xBtnRename
->connect_clicked( aLink
);
70 m_xBtnCancel
->connect_clicked( aLink
);
73 if ( bAllowOverwrite
)
75 aInfo
= Translate::get(STR_RENAME_OR_REPLACE
, rResLocale
);
79 aInfo
= Translate::get(STR_NAME_CLASH_RENAME_ONLY
, rResLocale
);
80 m_xBtnOverwrite
->hide();
84 if ( osl::FileBase::E_None
!= osl::FileBase::getSystemPathFromFileURL( rTargetFolderURL
, aPath
) )
85 aPath
= rTargetFolderURL
;
87 m_aSameName
= Translate::get(STR_SAME_NAME_USED
, rResLocale
);
89 aInfo
= aInfo
.replaceFirst( "%NAME", rClashingName
);
90 aInfo
= aInfo
.replaceFirst( "%FOLDER", aPath
);
91 m_xFTMessage
->set_label(aInfo
);
92 if ( !rProposedNewName
.isEmpty() )
93 m_xEDNewName
->set_text( rProposedNewName
);
95 m_xEDNewName
->set_text( rClashingName
);
98 NameClashDialog::~NameClashDialog()
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */