Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/dialog/inputdlg.cxx
Line
Count
Source
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
10
#include <inputdlg.hxx>
11
12
InputDialog::InputDialog(weld::Widget* pParent, const OUString& rLabelText)
13
0
    : GenericDialogController(pParent, u"sfx/ui/inputdialog.ui"_ustr, u"InputDialog"_ustr)
14
0
    , m_xEntry(m_xBuilder->weld_entry(u"entry"_ustr))
15
0
    , m_xLabel(m_xBuilder->weld_label(u"label"_ustr))
16
0
    , m_xHelp(m_xBuilder->weld_button(u"help"_ustr))
17
0
    , m_xOk(m_xBuilder->weld_button(u"ok"_ustr))
18
0
{
19
0
    m_xLabel->set_label(rLabelText);
20
0
}
21
22
0
void InputDialog::HideHelpBtn() { m_xHelp->hide(); }
23
24
0
OUString InputDialog::GetEntryText() const { return m_xEntry->get_text(); }
25
26
void InputDialog::SetEntryText(const OUString& rStr)
27
0
{
28
0
    m_xEntry->set_text(rStr);
29
0
    m_xEntry->set_position(-1);
30
0
}
31
32
void InputDialog::SetEntryMessageType(weld::EntryMessageType aType)
33
0
{
34
0
    m_xEntry->set_message_type(aType);
35
0
    if (aType == weld::EntryMessageType::Error)
36
0
    {
37
0
        m_xEntry->select_region(0, -1);
38
0
        m_xEntry->grab_focus();
39
0
        m_xOk->set_sensitive(false);
40
0
    }
41
0
    else
42
0
    {
43
0
        m_xOk->set_sensitive(true);
44
0
        SetTooltip(u""_ustr);
45
0
    }
46
0
}
47
48
void InputDialog::SetTooltip(const OUString& rStr)
49
0
{
50
0
    m_xEntry->set_tooltip_text(rStr);
51
0
    m_xOk->set_tooltip_text(rStr);
52
0
}
53
54
void InputDialog::setCheckEntry(const std::function<bool(OUString)>& rFunc)
55
0
{
56
0
    mCheckEntry = rFunc;
57
0
    m_xEntry->connect_changed(LINK(this, InputDialog, EntryChangedHdl));
58
0
}
59
60
IMPL_LINK_NOARG(InputDialog, EntryChangedHdl, weld::Entry&, void)
61
0
{
62
0
    if (mCheckEntry(m_xEntry->get_text()))
63
0
        SetEntryMessageType(weld::EntryMessageType::Normal);
64
0
    else
65
0
        SetEntryMessageType(weld::EntryMessageType::Error);
66
0
}
67
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */