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 <sal/config.h>
21 #include <sal/log.hxx>
23 #include <vcl/commandinfoprovider.hxx>
24 #include <vcl/event.hxx>
25 #include <vcl/weld.hxx>
26 #include <vcl/svapp.hxx>
28 #include <sfx2/sfxsids.hrc>
29 #include <svl/stritem.hxx>
30 #include <tools/diagnose_ex.h>
34 #include <strings.hrc>
37 #include <SvxToolbarConfigPage.hxx>
38 #include <SvxConfigPageHelper.hxx>
39 #include <dialmgr.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include <com/sun/star/ui/ImageType.hpp>
44 #include <dlgname.hxx>
46 SvxToolbarConfigPage::SvxToolbarConfigPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
47 : SvxConfigPage(pPage
, pController
, rSet
)
49 m_xGearBtn
= m_xBuilder
->weld_menu_button("toolbargearbtn");
51 m_xContainer
->set_help_id(HID_SVX_CONFIG_TOOLBAR
);
53 m_xContentsListBox
.reset(new SvxToolbarEntriesListBox(m_xBuilder
->weld_tree_view("toolcontents"), this));
54 std::vector
<int> aWidths
;
55 weld::TreeView
& rTreeView
= m_xContentsListBox
->get_widget();
56 Size
aSize(m_xFunctions
->get_size_request());
57 rTreeView
.set_size_request(aSize
.Width(), aSize
.Height());
59 int nExpectedSize
= 16;
61 int nStandardImageColWidth
= rTreeView
.get_checkbox_column_width();
62 int nMargin
= nStandardImageColWidth
- nExpectedSize
;
66 if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_LARGE
)
68 else if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_32
)
71 int nImageColWidth
= nExpectedSize
+ nMargin
;
73 aWidths
.push_back(nStandardImageColWidth
);
74 aWidths
.push_back(nImageColWidth
);
75 rTreeView
.set_column_fixed_widths(aWidths
);
77 rTreeView
.set_hexpand(true);
78 rTreeView
.set_vexpand(true);
79 rTreeView
.set_help_id( HID_SVX_CONFIG_TOOLBAR_CONTENTS
);
82 rTreeView
.connect_changed(
83 LINK( this, SvxToolbarConfigPage
, SelectToolbarEntry
) );
85 rTreeView
.connect_model_changed(LINK(this, SvxToolbarConfigPage
, ListModifiedHdl
));
87 m_xTopLevelListBox
->set_help_id ( HID_SVX_TOPLEVELLISTBOX
);
88 m_xSaveInListBox
->set_help_id( HID_SVX_SAVE_IN
);
89 m_xMoveUpButton
->set_help_id( HID_SVX_UP_TOOLBAR_ITEM
);
90 m_xMoveDownButton
->set_help_id( HID_SVX_DOWN_TOOLBAR_ITEM
);
91 m_xDescriptionField
->set_help_id ( HID_SVX_DESCFIELD
);
93 m_xCommandCategoryListBox
->connect_changed(
94 LINK( this, SvxToolbarConfigPage
, SelectCategory
) );
96 m_xGearBtn
->connect_selected(
97 LINK( this, SvxToolbarConfigPage
, GearHdl
) );
99 m_xMoveUpButton
->connect_clicked( LINK( this, SvxToolbarConfigPage
, MoveHdl
) );
100 m_xMoveDownButton
->connect_clicked( LINK( this, SvxToolbarConfigPage
, MoveHdl
) );
101 // Always enable Up and Down buttons
102 // added for issue i53677 by shizhoubo
103 m_xMoveDownButton
->set_sensitive(true);
104 m_xMoveUpButton
->set_sensitive(true);
106 m_xAddCommandButton
->connect_clicked( LINK( this, SvxToolbarConfigPage
, AddCommandHdl
) );
107 m_xRemoveCommandButton
->connect_clicked( LINK( this, SvxToolbarConfigPage
, RemoveCommandHdl
) );
109 m_xInsertBtn
->connect_selected(
110 LINK( this, SvxToolbarConfigPage
, InsertHdl
) );
111 m_xModifyBtn
->connect_selected(
112 LINK( this, SvxToolbarConfigPage
, ModifyItemHdl
) );
113 m_xResetBtn
->connect_clicked(
114 LINK( this, SvxToolbarConfigPage
, ResetToolbarHdl
) );
116 // "Insert Submenu" is irrelevant to the toolbars
117 m_xInsertBtn
->remove_item("insertsubmenu");
119 // Gear menu's "Move" action is irrelevant to the toolbars
120 m_xGearBtn
->set_item_sensitive("toolbar_gear_move", false);
122 // default toolbar to select is standardbar unless a different one
123 // has been passed in
124 m_aURLToSelect
= ITEM_TOOLBAR_URL
;
125 m_aURLToSelect
+= "standardbar";
127 const SfxPoolItem
* pItem
=
128 rSet
.GetItem( rSet
.GetPool()->GetWhich( SID_CONFIG
) );
132 OUString text
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
133 if (text
.startsWith( ITEM_TOOLBAR_URL
))
135 m_aURLToSelect
= text
.copy( 0 );
140 IMPL_LINK_NOARG(SvxToolbarConfigPage
, ListModifiedHdl
, weld::TreeView
&, void)
142 // regenerate with the current ordering within the list
143 SvxEntries
* pEntries
= GetTopLevelSelection()->GetEntries();
146 for (int i
= 0; i
< m_xContentsListBox
->n_children(); ++i
)
147 pEntries
->push_back(reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(i
).toInt64()));
149 GetSaveInData()->SetModified();
150 GetTopLevelSelection()->SetModified();
152 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
154 static_cast<ToolbarSaveInData
*>(GetSaveInData())->ApplyToolbar( pToolbar
);
157 SvxToolbarConfigPage::~SvxToolbarConfigPage()
159 for (int i
= 0, nCount
= m_xSaveInListBox
->get_count(); i
< nCount
; ++i
)
161 ToolbarSaveInData
* pData
=
162 reinterpret_cast<ToolbarSaveInData
*>(m_xSaveInListBox
->get_id(i
).toInt64());
165 m_xSaveInListBox
->clear();
168 void SvxToolbarConfigPage::DeleteSelectedTopLevel()
170 const sal_Int32 nSelectionPos
= m_xTopLevelListBox
->get_active();
171 ToolbarSaveInData
* pSaveInData
= static_cast<ToolbarSaveInData
*>( GetSaveInData() );
172 pSaveInData
->RemoveToolbar( GetTopLevelSelection() );
174 int nCount
= m_xTopLevelListBox
->get_count();
177 // select next entry after the one being deleted
178 // selection position is indexed from 0 so need to
179 // subtract one from the entry count
180 if (nSelectionPos
!= nCount
- 1)
182 m_xTopLevelListBox
->set_active(nSelectionPos
+ 1);
186 m_xTopLevelListBox
->set_active(nSelectionPos
- 1);
190 // and now remove the entry
191 m_xTopLevelListBox
->remove(nSelectionPos
);
195 ReloadTopLevelListBox();
199 void SvxToolbarConfigPage::DeleteSelectedContent()
201 int nActEntry
= m_xContentsListBox
->get_selected_index();
205 // get currently selected entry
206 SvxConfigEntry
* pEntry
=
207 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
209 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
211 // remove entry from the list for this toolbar
212 SvxConfigPageHelper::RemoveEntry( pToolbar
->GetEntries(), pEntry
);
214 // remove toolbar entry from UI
215 m_xContentsListBox
->remove(nActEntry
);
217 // delete data for toolbar entry
220 static_cast<ToolbarSaveInData
*>(GetSaveInData())->ApplyToolbar( pToolbar
);
221 UpdateButtonStates();
223 // if this is the last entry in the toolbar and it is a user
224 // defined toolbar pop up a dialog asking the user if they
225 // want to delete the toolbar
226 if ( m_xContentsListBox
->n_children() == 0 &&
227 GetTopLevelSelection()->IsDeletable() )
229 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
230 VclMessageType::Question
, VclButtonsType::YesNo
,
231 CuiResId(RID_SXVSTR_CONFIRM_DELETE_TOOLBAR
)));
232 if (xQueryBox
->run() == RET_YES
)
234 DeleteSelectedTopLevel();
240 IMPL_LINK( SvxToolbarConfigPage
, MoveHdl
, weld::Button
&, rButton
, void )
242 MoveEntry(&rButton
== m_xMoveUpButton
.get());
245 void SvxToolbarConfigPage::MoveEntry( bool bMoveUp
)
247 SvxConfigPage::MoveEntry( bMoveUp
);
249 // Apply change to currently selected toolbar
250 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
252 static_cast<ToolbarSaveInData
*>(GetSaveInData())->ApplyToolbar( pToolbar
);
255 SAL_WARN( "cui.customize", "SvxToolbarConfigPage::MoveEntry(): no entry" );
256 UpdateButtonStates();
260 void SvxToolbarConfigPage::Init()
262 // ensure that the UI is cleared before populating it
263 m_xTopLevelListBox
->clear();
264 m_xContentsListBox
->clear();
266 ReloadTopLevelListBox();
269 if ( !m_aURLToSelect
.isEmpty() )
271 for (sal_Int32 i
= 0, nCount
= m_xTopLevelListBox
->get_count(); i
< nCount
; ++i
)
273 SvxConfigEntry
* pData
=
274 reinterpret_cast<SvxConfigEntry
*>(m_xTopLevelListBox
->get_id(i
).toInt64());
276 if ( pData
->GetCommand().equals( m_aURLToSelect
) )
283 // in future select the default toolbar: Standard
284 m_aURLToSelect
= ITEM_TOOLBAR_URL
;
285 m_aURLToSelect
+= "standardbar";
288 m_xTopLevelListBox
->set_active(nPos
);
291 m_xCommandCategoryListBox
->Init(
292 comphelper::getProcessComponentContext(),
294 vcl::CommandInfoProvider::GetModuleIdentifier(m_xFrame
));
295 m_xCommandCategoryListBox
->categorySelected(m_xFunctions
.get(), OUString(), GetSaveInData());
298 SaveInData
* SvxToolbarConfigPage::CreateSaveInData(
299 const css::uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgMgr
,
300 const css::uno::Reference
< css::ui::XUIConfigurationManager
>& xParentCfgMgr
,
301 const OUString
& aModuleId
,
304 return static_cast< SaveInData
* >(
305 new ToolbarSaveInData( xCfgMgr
, xParentCfgMgr
, aModuleId
, bDocConfig
));
308 IMPL_LINK_NOARG(SvxToolbarConfigPage
, SelectToolbarEntry
, weld::TreeView
&, void)
310 UpdateButtonStates();
313 IMPL_LINK( SvxToolbarConfigPage
, GearHdl
, const OString
&, rIdent
, void )
315 SvxConfigEntry
* pCurrentToolbar
= GetTopLevelSelection();
317 if (rIdent
== "toolbar_gear_add")
319 OUString prefix
= CuiResId( RID_SVXSTR_NEW_TOOLBAR
);
322 SvxConfigPageHelper::generateCustomName( prefix
, GetSaveInData()->GetEntries() );
325 SvxConfigPageHelper::generateCustomURL( GetSaveInData()->GetEntries() );
327 SvxNewToolbarDialog
aNameDialog(GetFrameWeld(), aNewName
);
329 // Reflect the actual m_xSaveInListBox into the new toolbar dialog
330 for (int i
= 0, nCount
= m_xSaveInListBox
->get_count(); i
< nCount
; ++i
)
331 aNameDialog
.m_xSaveInListBox
->append_text(m_xSaveInListBox
->get_text(i
));
333 aNameDialog
.m_xSaveInListBox
->set_active(m_xSaveInListBox
->get_active());
335 if (aNameDialog
.run() == RET_OK
)
337 aNewName
= aNameDialog
.GetName();
339 // Where to save the new toolbar? (i.e. Modulewise or documentwise)
340 int nInsertPos
= aNameDialog
.m_xSaveInListBox
->get_active();
342 ToolbarSaveInData
* pData
=
343 reinterpret_cast<ToolbarSaveInData
*>(
344 m_xSaveInListBox
->get_id(nInsertPos
).toInt64() );
346 if ( GetSaveInData() != pData
)
348 m_xSaveInListBox
->set_active(nInsertPos
);
349 SelectSaveInLocation(*m_xSaveInListBox
);
352 SvxConfigEntry
* pToolbar
=
353 new SvxConfigEntry( aNewName
, aNewURL
, true, false );
355 pToolbar
->SetUserDefined();
358 pData
->CreateToolbar( pToolbar
);
360 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pToolbar
)));
361 m_xTopLevelListBox
->append(sId
, pToolbar
->GetName());
362 m_xTopLevelListBox
->set_active_id(sId
);
365 pData
->SetModified();
368 else if (rIdent
== "toolbar_gear_delete")
370 if ( pCurrentToolbar
&& pCurrentToolbar
->IsDeletable() )
372 DeleteSelectedTopLevel();
373 UpdateButtonStates();
376 else if (rIdent
== "toolbar_gear_rename")
378 sal_Int32 nSelectionPos
= m_xTopLevelListBox
->get_active();
379 SvxConfigEntry
* pToolbar
=
380 reinterpret_cast<SvxConfigEntry
*>(m_xTopLevelListBox
->get_id(nSelectionPos
).toInt64());
381 ToolbarSaveInData
* pSaveInData
= static_cast<ToolbarSaveInData
*>( GetSaveInData() );
384 OUString
sCurrentName( SvxConfigPageHelper::stripHotKey( pToolbar
->GetName() ) );
385 OUString sDesc
= CuiResId( RID_SVXSTR_LABEL_NEW_NAME
);
387 SvxNameDialog
aNameDialog(GetFrameWeld(), sCurrentName
, sDesc
);
388 aNameDialog
.set_help_id(HID_SVX_CONFIG_RENAME_TOOLBAR
);
389 aNameDialog
.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR
));
391 if ( aNameDialog
.run() == RET_OK
)
393 OUString sNewName
= aNameDialog
.GetName();
395 if (sCurrentName
== sNewName
)
398 pToolbar
->SetName( sNewName
);
399 pSaveInData
->ApplyToolbar( pToolbar
);
401 // have to use remove and insert to change the name
402 m_xTopLevelListBox
->remove(nSelectionPos
);
403 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pToolbar
)));
404 m_xTopLevelListBox
->insert(nSelectionPos
, sNewName
, &sId
, nullptr, nullptr);
405 m_xTopLevelListBox
->set_active_id(sId
);
408 else if (rIdent
== "toolbar_gear_iconOnly" || rIdent
== "toolbar_gear_textOnly" || rIdent
== "toolbar_gear_iconAndText")
410 ToolbarSaveInData
* pSaveInData
= static_cast<ToolbarSaveInData
*>( GetSaveInData() );
412 if (pCurrentToolbar
== nullptr || pSaveInData
== nullptr)
414 SAL_WARN("cui.customize", "NULL toolbar or savein data");
418 sal_Int32 nStyle
= 0;
419 if (rIdent
== "toolbar_gear_iconOnly")
421 else if (rIdent
== "toolbar_gear_textOnly")
423 else if (rIdent
== "toolbar_gear_iconAndText")
426 pCurrentToolbar
->SetStyle( nStyle
);
427 pSaveInData
->SetSystemStyle( m_xFrame
, pCurrentToolbar
->GetCommand(), nStyle
);
433 //This block should never be reached
434 SAL_WARN("cui.customize", "Unknown gear menu option: " << rIdent
);
439 IMPL_LINK_NOARG( SvxToolbarConfigPage
, SelectCategory
, weld::ComboBox
&, void )
441 OUString
aSearchTerm(m_xSearchEdit
->get_text());
443 m_xCommandCategoryListBox
->categorySelected(m_xFunctions
.get(), aSearchTerm
, GetSaveInData());
446 IMPL_LINK_NOARG( SvxToolbarConfigPage
, AddCommandHdl
, weld::Button
&, void )
451 IMPL_LINK_NOARG( SvxToolbarConfigPage
, RemoveCommandHdl
, weld::Button
&, void )
453 DeleteSelectedContent();
456 IMPL_LINK(SvxToolbarConfigPage
, InsertHdl
, const OString
&, rIdent
, void)
458 if (rIdent
== "insertseparator")
460 // Get the currently selected toolbar
461 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
463 SvxConfigEntry
* pNewEntryData
= new SvxConfigEntry
;
464 pNewEntryData
->SetUserDefined();
466 int nPos
= AppendEntry(pNewEntryData
, -1);
467 InsertEntryIntoUI(pNewEntryData
, nPos
, 1);
469 static_cast<ToolbarSaveInData
*>( GetSaveInData())->ApplyToolbar( pToolbar
);
471 UpdateButtonStates();
475 //This block should never be reached
476 SAL_WARN("cui.customize", "Unknown insert option: " << rIdent
);
481 IMPL_LINK(SvxToolbarConfigPage
, ModifyItemHdl
, const OString
&, rIdent
, void)
483 bool bNeedsApply
= false;
485 // get currently selected toolbar
486 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
488 if (rIdent
.isEmpty() || pToolbar
== nullptr)
490 SAL_WARN("cui.customize", "No toolbar selected, or empty rIdent!");
494 if (rIdent
== "renameItem")
496 int nActEntry
= m_xContentsListBox
->get_selected_index();
497 SvxConfigEntry
* pEntry
=
498 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
500 OUString
aNewName( SvxConfigPageHelper::stripHotKey( pEntry
->GetName() ) );
501 OUString aDesc
= CuiResId( RID_SVXSTR_LABEL_NEW_NAME
);
503 SvxNameDialog
aNameDialog(GetFrameWeld(), aNewName
, aDesc
);
504 aNameDialog
.set_help_id(HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM
);
505 aNameDialog
.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR
));
507 if (aNameDialog
.run() == RET_OK
)
509 aNewName
= aNameDialog
.GetName();
511 if( aNewName
.isEmpty() ) // tdf#80758 - Accelerator character ("~") is passed as
512 pEntry
->SetName( "~" ); // the button name in case of empty values.
514 pEntry
->SetName( aNewName
);
516 m_xContentsListBox
->set_text(nActEntry
, aNewName
, 2);
520 else if (rIdent
== "changeIcon")
522 int nActEntry
= m_xContentsListBox
->get_selected_index();
523 SvxConfigEntry
* pEntry
=
524 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
526 SvxIconSelectorDialog
aIconDialog(GetFrameWeld(),
527 GetSaveInData()->GetImageManager(),
528 GetSaveInData()->GetParentImageManager());
530 if (aIconDialog
.run() == RET_OK
)
532 css::uno::Reference
< css::graphic::XGraphic
> newgraphic
=
533 aIconDialog
.GetSelectedIcon();
535 if ( newgraphic
.is() )
537 css::uno::Sequence
< css::uno::Reference
< css::graphic::XGraphic
> >
540 css::uno::Sequence
<OUString
> aURLSeq
{ pEntry
->GetCommand() };
542 if ( !pEntry
->GetBackupGraphic().is() )
544 css::uno::Reference
< css::graphic::XGraphic
> backup
=
545 SvxConfigPageHelper::GetGraphic(GetSaveInData()->GetImageManager(),
550 pEntry
->SetBackupGraphic(backup
);
554 aGraphicSeq
[ 0 ] = newgraphic
;
557 GetSaveInData()->GetImageManager()->replaceImages(
558 SvxConfigPageHelper::GetImageType(), aURLSeq
, aGraphicSeq
);
560 m_xContentsListBox
->remove(nActEntry
);
562 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pEntry
)));
563 m_xContentsListBox
->insert(nActEntry
, sId
);
564 m_xContentsListBox
->set_toggle(nActEntry
, pEntry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
565 InsertEntryIntoUI(pEntry
, nActEntry
, 1);
567 m_xContentsListBox
->select(nActEntry
);
568 m_xContentsListBox
->scroll_to_row(nActEntry
);
570 GetSaveInData()->PersistChanges(
571 GetSaveInData()->GetImageManager() );
573 catch ( const css::uno::Exception
&)
575 TOOLS_WARN_EXCEPTION("cui.customize", "Error replacing image");
580 else if (rIdent
== "resetIcon")
582 int nActEntry
= m_xContentsListBox
->get_selected_index();
583 SvxConfigEntry
* pEntry
=
584 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
586 css::uno::Reference
< css::graphic::XGraphic
> backup
=
587 pEntry
->GetBackupGraphic();
589 css::uno::Sequence
< css::uno::Reference
< css::graphic::XGraphic
> >
591 aGraphicSeq
[ 0 ] = backup
;
593 css::uno::Sequence
<OUString
> aURLSeq
{ pEntry
->GetCommand() };
597 GetSaveInData()->GetImageManager()->replaceImages(
598 SvxConfigPageHelper::GetImageType(), aURLSeq
, aGraphicSeq
);
600 m_xContentsListBox
->remove(nActEntry
);
602 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pEntry
)));
603 m_xContentsListBox
->insert(nActEntry
, sId
);
604 m_xContentsListBox
->set_toggle(nActEntry
, pEntry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
605 InsertEntryIntoUI(pEntry
, nActEntry
, 1);
607 m_xContentsListBox
->select(nActEntry
);
608 m_xContentsListBox
->scroll_to_row(nActEntry
);
610 // reset backup in entry
611 pEntry
->SetBackupGraphic(
612 css::uno::Reference
< css::graphic::XGraphic
>() );
614 GetSaveInData()->PersistChanges(
615 GetSaveInData()->GetImageManager() );
617 catch ( const css::uno::Exception
& )
619 TOOLS_WARN_EXCEPTION("cui.customize", "Error resetting image");
622 else if (rIdent
== "restoreItem")
624 int nActEntry
= m_xContentsListBox
->get_selected_index();
625 SvxConfigEntry
* pEntry
=
626 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
628 ToolbarSaveInData
* pSaveInData
=
629 static_cast<ToolbarSaveInData
*>( GetSaveInData() );
631 OUString aSystemName
=
632 pSaveInData
->GetSystemUIName( pEntry
->GetCommand() );
634 if ( !pEntry
->GetName().equals( aSystemName
) )
636 pEntry
->SetName( aSystemName
);
637 m_xContentsListBox
->set_text(
638 nActEntry
, SvxConfigPageHelper::stripHotKey(aSystemName
), 2);
642 css::uno::Sequence
<OUString
> aURLSeq
{ pEntry
->GetCommand() };
646 GetSaveInData()->GetImageManager()->removeImages(
647 SvxConfigPageHelper::GetImageType(), aURLSeq
);
649 // reset backup in entry
650 pEntry
->SetBackupGraphic(
651 css::uno::Reference
< css::graphic::XGraphic
>() );
653 GetSaveInData()->PersistChanges(
654 GetSaveInData()->GetImageManager() );
656 m_xContentsListBox
->remove(nActEntry
);
658 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pEntry
)));
659 m_xContentsListBox
->insert(nActEntry
, sId
);
660 m_xContentsListBox
->set_toggle(nActEntry
,
661 pEntry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
662 InsertEntryIntoUI(pEntry
, nActEntry
, 1);
664 m_xContentsListBox
->select(nActEntry
);
665 m_xContentsListBox
->scroll_to_row(nActEntry
);
669 catch ( const css::uno::Exception
& )
671 TOOLS_WARN_EXCEPTION("cui.customize", "Error restoring image");
676 //This block should never be reached
677 SAL_WARN("cui.customize", "Unknown insert option: " << rIdent
);
683 static_cast<ToolbarSaveInData
*>( GetSaveInData())->ApplyToolbar( pToolbar
);
684 UpdateButtonStates();
688 IMPL_LINK_NOARG(SvxToolbarConfigPage
, ResetToolbarHdl
, weld::Button
&, void)
690 sal_Int32 nSelectionPos
= m_xTopLevelListBox
->get_active();
692 SvxConfigEntry
* pToolbar
=
693 reinterpret_cast<SvxConfigEntry
*>(m_xTopLevelListBox
->get_id(nSelectionPos
).toInt64());
695 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
696 VclMessageType::Question
, VclButtonsType::YesNo
,
697 CuiResId(RID_SVXSTR_CONFIRM_RESTORE_DEFAULT
)));
698 if (xQueryBox
->run() == RET_YES
)
700 ToolbarSaveInData
* pSaveInData
=
701 static_cast<ToolbarSaveInData
*>(GetSaveInData());
703 pSaveInData
->RestoreToolbar( pToolbar
);
709 void SvxToolbarConfigPage::UpdateButtonStates()
711 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
712 int selection
= m_xContentsListBox
->get_selected_index();
715 selection
!= -1 && reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(selection
).toInt64())->IsSeparator();
716 bool bIsValidSelection
=
717 !(m_xContentsListBox
->n_children() == 0 || selection
== -1);
719 m_xMoveUpButton
->set_sensitive( bIsValidSelection
);
720 m_xMoveDownButton
->set_sensitive( bIsValidSelection
);
722 m_xRemoveCommandButton
->set_sensitive( bIsValidSelection
);
724 m_xModifyBtn
->set_sensitive( bIsValidSelection
&& !bIsSeparator
);
726 // Handle the gear button
727 // "toolbar_gear_add" option is always enabled
728 m_xGearBtn
->set_item_sensitive("toolbar_gear_delete", pToolbar
&& pToolbar
->IsDeletable());
729 m_xGearBtn
->set_item_sensitive("toolbar_gear_rename", pToolbar
&& pToolbar
->IsRenamable());
732 short SvxToolbarConfigPage::QueryReset()
734 OUString msg
= CuiResId( RID_SVXSTR_CONFIRM_TOOLBAR_RESET
);
736 OUString saveInName
= m_xSaveInListBox
->get_active_text();
738 OUString label
= SvxConfigPageHelper::replaceSaveInName( msg
, saveInName
);
740 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
741 VclMessageType::Question
, VclButtonsType::YesNo
,
743 return xQueryBox
->run();
746 void SvxToolbarConfigPage::SelectElement()
748 m_xContentsListBox
->clear();
750 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
751 if ( pToolbar
== nullptr )
753 //TODO: Disable related buttons
754 m_xInsertBtn
->set_sensitive( false );
755 m_xResetBtn
->set_sensitive( false );
756 m_xGearBtn
->set_sensitive( false );
762 m_xInsertBtn
->set_sensitive(true);
763 m_xResetBtn
->set_sensitive(true);
764 m_xGearBtn
->set_sensitive(true);
767 switch (pToolbar
->GetStyle())
771 m_xGearBtn
->set_item_active("toolbar_gear_iconOnly", true);
776 m_xGearBtn
->set_item_active("toolbar_gear_textOnly", true);
781 m_xGearBtn
->set_item_active("toolbar_gear_iconAndText", true);
787 SvxEntries
* pEntries
= pToolbar
->GetEntries();
788 for (auto const& entry
: *pEntries
)
790 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(entry
)));
791 m_xContentsListBox
->insert(i
, sId
);
792 if (entry
->IsBinding() && !entry
->IsSeparator())
793 m_xContentsListBox
->set_toggle(i
, entry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
794 InsertEntryIntoUI(entry
, i
, 1);
798 UpdateButtonStates();
801 void SvxToolbarConfigPage::AddFunction(int nTarget
)
803 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
805 if (pToolbar
== nullptr)
808 // Add the command to the contents listbox of the selected toolbar
810 SvxConfigPage::AddFunction(nTarget
, true/*bAllowDuplicates*/);
812 if (nNewLBEntry
== -1)
815 SvxConfigEntry
* pEntry
= reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nNewLBEntry
).toInt64());
817 if ( pEntry
->IsBinding() ) //TODO sep ?
819 pEntry
->SetVisible(true);
820 m_xContentsListBox
->set_toggle(nNewLBEntry
, TRISTATE_TRUE
, 0);
823 InsertEntryIntoUI(pEntry
, nNewLBEntry
, 1);
825 // Changes are not visible on the toolbar until this point
826 // TODO: Figure out a way to show the changes on the toolbar, but revert if
827 // the dialog is closed by pressing "Cancel"
828 // get currently selected toolbar and apply change
829 if ( pToolbar
!= nullptr )
831 static_cast<ToolbarSaveInData
*>( GetSaveInData() )->ApplyToolbar( pToolbar
);
835 SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(std::unique_ptr
<weld::TreeView
> xParent
, SvxToolbarConfigPage
* pPg
)
836 : SvxMenuEntriesListBox(std::move(xParent
), pPg
)
838 m_xControl
->connect_toggled(LINK(this, SvxToolbarEntriesListBox
, CheckButtonHdl
));
839 m_xControl
->connect_key_press(Link
<const KeyEvent
&, bool>()); //acknowledge we first remove the old one
840 m_xControl
->connect_key_press(LINK(this, SvxToolbarEntriesListBox
, KeyInputHdl
)); // then add the new one
843 SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox()
847 void SvxToolbarEntriesListBox::ChangedVisibility(int nRow
)
849 SvxConfigEntry
* pEntryData
=
850 reinterpret_cast<SvxConfigEntry
*>(m_xControl
->get_id(nRow
).toInt64());
852 if (pEntryData
->IsBinding())
854 pEntryData
->SetVisible(m_xControl
->get_toggle(nRow
, 0) == TRISTATE_TRUE
);
856 SvxConfigEntry
* pToolbar
= m_pPage
->GetTopLevelSelection();
858 ToolbarSaveInData
* pToolbarSaveInData
= static_cast<ToolbarSaveInData
*>(
859 m_pPage
->GetSaveInData() );
861 pToolbarSaveInData
->ApplyToolbar( pToolbar
);
865 IMPL_LINK(SvxToolbarEntriesListBox
, CheckButtonHdl
, const row_col
&, rRowCol
, void)
867 ChangedVisibility(rRowCol
.first
);
870 IMPL_LINK(SvxToolbarEntriesListBox
, KeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
872 // space key will change visibility of toolbar items
873 if ( rKeyEvent
.GetKeyCode() == KEY_SPACE
)
875 int nRow
= m_xControl
->get_selected_index();
876 SvxConfigEntry
* pEntryData
= reinterpret_cast<SvxConfigEntry
*>(m_xControl
->get_id(nRow
).toInt64());
877 if (pEntryData
->IsBinding() && !pEntryData
->IsSeparator())
879 m_xControl
->set_toggle(nRow
, m_xControl
->get_toggle(nRow
, 0) == TRISTATE_TRUE
? TRISTATE_FALSE
: TRISTATE_TRUE
, 0);
880 ChangedVisibility(nRow
);
884 return SvxMenuEntriesListBox::KeyInputHdl(rKeyEvent
);
887 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */