LibreOffice Module sfx2 (master) 1
srchdlg.cxx
Go to the documentation of this file.
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
21#include <srchdlg.hxx>
22#include <comphelper/string.hxx>
23
24#include <tools/debug.hxx>
26#include <o3tl/string_view.hxx>
27#include <utility>
28
29using namespace ::com::sun::star::uno;
30
31
32namespace sfx2 {
33
34#define MAX_SAVE_COUNT sal_uInt16(10)
35
36
37// SearchDialog
38
39
40SearchDialog::SearchDialog(weld::Window* pWindow, OUString aConfigName)
41 : GenericDialogController(pWindow, "sfx/ui/searchdialog.ui", "SearchDialog")
42 , m_sConfigName(std::move(aConfigName))
43 , m_xSearchEdit(m_xBuilder->weld_combo_box("searchterm"))
44 , m_xWholeWordsBox(m_xBuilder->weld_check_button("wholewords"))
45 , m_xMatchCaseBox(m_xBuilder->weld_check_button("matchcase"))
46 , m_xWrapAroundBox(m_xBuilder->weld_check_button("wrap"))
47 , m_xBackwardsBox(m_xBuilder->weld_check_button("backwards"))
48 , m_xFindBtn(m_xBuilder->weld_button("ok"))
49{
50 // set handler
51 m_xFindBtn->connect_clicked(LINK(this, SearchDialog, FindHdl));
52 // load config: old search strings and the status of the check boxes
53 LoadConfig();
54 // the search edit should have the focus
55 m_xSearchEdit->grab_focus();
56}
57
59{
60 SaveConfig();
61}
62
64{
65 SvtViewOptions aViewOpt( EViewType::Dialog, m_sConfigName );
66 if ( aViewOpt.Exists() )
67 {
68 Any aUserItem = aViewOpt.GetUserItem( "UserItem" );
69 OUString sUserData;
70 if ( aUserItem >>= sUserData )
71 {
72 DBG_ASSERT( comphelper::string::getTokenCount(sUserData, ';') == 5, "invalid config data" );
73 sal_Int32 nIdx = 0;
74 OUString sSearchText = sUserData.getToken( 0, ';', nIdx );
75 m_xWholeWordsBox->set_active( o3tl::toInt32(o3tl::getToken(sUserData, 0, ';', nIdx )) == 1 );
76 m_xMatchCaseBox->set_active( o3tl::toInt32(o3tl::getToken(sUserData, 0, ';', nIdx )) == 1 );
77 m_xWrapAroundBox->set_active( o3tl::toInt32(o3tl::getToken(sUserData, 0, ';', nIdx )) == 1 );
78 m_xBackwardsBox->set_active( o3tl::toInt32(o3tl::getToken(sUserData, 0, ';', nIdx )) == 1 );
79
80 nIdx = 0;
81 while ( nIdx != -1 )
82 m_xSearchEdit->append_text(sSearchText.getToken( 0, '\t', nIdx));
83 m_xSearchEdit->set_active(0);
84 }
85 }
86 else
87 m_xWrapAroundBox->set_active(true);
88}
89
91{
92 SvtViewOptions aViewOpt( EViewType::Dialog, m_sConfigName );
93 OUString sUserData;
94 int i = 0, nCount = std::min(m_xSearchEdit->get_count(), static_cast<int>(MAX_SAVE_COUNT));
95 for ( ; i < nCount; ++i )
96 {
97 sUserData += m_xSearchEdit->get_text(i) + "\t";
98 }
99 sUserData = comphelper::string::stripStart(sUserData, '\t') + ";" +
100 OUString::number( m_xWholeWordsBox->get_active() ? 1 : 0 ) + ";" +
101 OUString::number( m_xMatchCaseBox->get_active() ? 1 : 0 ) + ";" +
102 OUString::number( m_xWrapAroundBox->get_active() ? 1 : 0 ) + ";" +
103 OUString::number( m_xBackwardsBox->get_active() ? 1 : 0 );
104
105 Any aUserItem( sUserData );
106 aViewOpt.SetUserItem( "UserItem", aUserItem );
107}
108
110{
111 OUString sSrchTxt = m_xSearchEdit->get_active_text();
112 auto nPos = m_xSearchEdit->find_text(sSrchTxt);
113 if (nPos != 0)
114 {
115 if (nPos != -1)
116 m_xSearchEdit->remove(nPos);
117 m_xSearchEdit->insert_text(0, sSrchTxt);
118 }
119 m_aFindHdl.Call( *this );
120}
121
123{
124 m_xSearchEdit->select_entry_region(0, -1);
125 m_xSearchEdit->grab_focus();
126}
127
128void SearchDialog::runAsync(const std::shared_ptr<SearchDialog>& rController)
129{
130 weld::DialogController::runAsync(rController, [=](sal_Int32 /*nResult*/){ rController->m_aCloseHdl.Call(nullptr); });
131}
132
133} // namespace sfx2
134
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Any GetUserItem(const OUString &sName) const
void SetUserItem(const OUString &sName, const css::uno::Any &aValue)
bool Exists() const
SearchDialog(weld::Window *pWindow, OUString aConfigName)
Definition: srchdlg.cxx:40
std::unique_ptr< weld::CheckButton > m_xBackwardsBox
Definition: srchdlg.hxx:42
std::unique_ptr< weld::CheckButton > m_xMatchCaseBox
Definition: srchdlg.hxx:40
std::unique_ptr< weld::ComboBox > m_xSearchEdit
Definition: srchdlg.hxx:38
OUString m_sConfigName
Definition: srchdlg.hxx:36
virtual ~SearchDialog() override
Definition: srchdlg.cxx:58
void SetFocusOnEdit()
Definition: srchdlg.cxx:122
std::unique_ptr< weld::CheckButton > m_xWrapAroundBox
Definition: srchdlg.hxx:41
static void runAsync(const std::shared_ptr< SearchDialog > &rController)
Definition: srchdlg.cxx:128
std::unique_ptr< weld::Button > m_xFindBtn
Definition: srchdlg.hxx:43
std::unique_ptr< weld::CheckButton > m_xWholeWordsBox
Definition: srchdlg.hxx:39
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
int nCount
#define DBG_ASSERT(sCon, aError)
sal_uInt16 nPos
Definition: linksrc.cxx:118
OString stripStart(const OString &rIn, char c)
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
int i
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
IMPL_LINK_NOARG(SvDDELinkEditDialog, EditHdl_Impl, weld::Entry &, void)
Definition: impldde.cxx:91
#define MAX_SAVE_COUNT
Definition: srchdlg.cxx:34