Use correct object
[LibreOffice.git] / cui / source / options / optbasic.cxx
blob3b105f27d16deb70d8cf36f0a46b7376bcbe17c8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "optbasic.hxx"
21 #include <basic/codecompletecache.hxx>
22 #include <officecfg/Office/BasicIDE.hxx>
24 SvxBasicIDEOptionsPage::SvxBasicIDEOptionsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
25 : SfxTabPage(pPage, pController, u"cui/ui/optbasicidepage.ui"_ustr, u"OptBasicIDEPage"_ustr, &rSet)
26 , m_xCodeCompleteChk(m_xBuilder->weld_check_button(u"codecomplete_enable"_ustr))
27 , m_xAutocloseProcChk(m_xBuilder->weld_check_button(u"autoclose_proc"_ustr))
28 , m_xAutocloseParenChk(m_xBuilder->weld_check_button(u"autoclose_paren"_ustr))
29 , m_xAutocloseQuotesChk(m_xBuilder->weld_check_button(u"autoclose_quotes"_ustr))
30 , m_xAutoCorrectChk(m_xBuilder->weld_check_button(u"autocorrect"_ustr))
31 , m_xUseExtendedTypesChk(m_xBuilder->weld_check_button(u"extendedtypes_enable"_ustr))
33 LoadConfig();
36 SvxBasicIDEOptionsPage::~SvxBasicIDEOptionsPage()
40 void SvxBasicIDEOptionsPage::LoadConfig()
42 m_xCodeCompleteChk->set_active( officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get() );
43 m_xCodeCompleteChk->set_sensitive( !officecfg::Office::BasicIDE::Autocomplete::CodeComplete::isReadOnly() );
44 m_xAutocloseProcChk->set_active( officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get() );
45 m_xAutocloseProcChk->set_sensitive( !officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::isReadOnly() );
46 m_xAutocloseQuotesChk->set_active( officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get() );
47 m_xAutocloseQuotesChk->set_sensitive( !officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::isReadOnly() );
48 m_xAutocloseParenChk->set_active( officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get() );
49 m_xAutocloseParenChk->set_sensitive( !officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::isReadOnly() );
50 m_xAutoCorrectChk->set_active( officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get() );
51 m_xAutoCorrectChk->set_sensitive( !officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::isReadOnly() );
52 m_xUseExtendedTypesChk->set_active( officecfg::Office::BasicIDE::Autocomplete::UseExtended::get() );
53 m_xUseExtendedTypesChk->set_sensitive( !officecfg::Office::BasicIDE::Autocomplete::UseExtended::isReadOnly() );
56 OUString SvxBasicIDEOptionsPage::GetAllStrings()
58 OUString sAllStrings;
59 OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"label3"_ustr };
61 for (const auto& label : labels)
63 if (const auto pString = m_xBuilder->weld_label(label))
64 sAllStrings += pString->get_label() + " ";
67 OUString checkButton[] = { u"codecomplete_enable"_ustr, u"autocorrect"_ustr, u"autoclose_quotes"_ustr,
68 u"autoclose_paren"_ustr, u"autoclose_proc"_ustr, u"extendedtypes_enable"_ustr };
70 for (const auto& check : checkButton)
72 if (const auto pString = m_xBuilder->weld_check_button(check))
73 sAllStrings += pString->get_label() + " ";
76 return sAllStrings.replaceAll("_", "");
79 bool SvxBasicIDEOptionsPage::FillItemSet( SfxItemSet* /*rCoreSet*/ )
81 bool bModified = false;
82 std::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create() );
84 if( m_xAutocloseProcChk->get_state_changed_from_saved() )
86 officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::set( m_xAutocloseProcChk->get_active(), batch );
87 CodeCompleteOptions::SetProcedureAutoCompleteOn( m_xAutocloseProcChk->get_active() );
88 bModified = true;
91 if( m_xCodeCompleteChk->get_state_changed_from_saved() )
93 //std::shared_ptr< comphelper::ConfigurationChanges > batch( comphelper::ConfigurationChanges::create() );
94 officecfg::Office::BasicIDE::Autocomplete::CodeComplete::set( m_xCodeCompleteChk->get_active(), batch );
95 CodeCompleteOptions::SetCodeCompleteOn( m_xCodeCompleteChk->get_active() );
96 bModified = true;
99 if( m_xUseExtendedTypesChk->get_state_changed_from_saved() )
101 officecfg::Office::BasicIDE::Autocomplete::UseExtended::set( m_xUseExtendedTypesChk->get_active(), batch );
102 CodeCompleteOptions::SetExtendedTypeDeclaration( m_xUseExtendedTypesChk->get_active() );
103 bModified = true;
106 if( m_xAutocloseParenChk->get_state_changed_from_saved() )
108 officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::set( m_xAutocloseParenChk->get_active(), batch );
109 CodeCompleteOptions::SetAutoCloseParenthesisOn( m_xAutocloseParenChk->get_active() );
110 bModified = true;
113 if( m_xAutocloseQuotesChk->get_state_changed_from_saved() )
115 officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::set( m_xAutocloseQuotesChk->get_active(), batch );
116 CodeCompleteOptions::SetAutoCloseQuotesOn( m_xAutocloseQuotesChk->get_active() );
117 bModified = true;
120 if( m_xAutoCorrectChk->get_state_changed_from_saved() )
122 officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::set( m_xAutoCorrectChk->get_active(), batch );
123 CodeCompleteOptions::SetAutoCorrectOn( m_xAutoCorrectChk->get_active() );
124 bModified = true;
127 if( bModified )
128 batch->commit();
130 return bModified;
133 void SvxBasicIDEOptionsPage::Reset( const SfxItemSet* /*rSet*/ )
135 LoadConfig();
136 m_xCodeCompleteChk->save_state();
137 m_xAutocloseProcChk->save_state();
138 m_xAutocloseQuotesChk->save_state();
139 m_xAutocloseParenChk->save_state();
140 m_xAutoCorrectChk->save_state();
141 m_xUseExtendedTypesChk->save_state();
144 std::unique_ptr<SfxTabPage> SvxBasicIDEOptionsPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
146 return std::make_unique<SvxBasicIDEOptionsPage>(pPage, pController, *rAttrSet);
149 void SvxBasicIDEOptionsPage::FillUserData()
151 SetUserData( OUString() );
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */