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 m_xDropTargetHelper
.reset(new SvxConfigPageFunctionDropTarget(*this, m_xContentsListBox
->get_widget()));
56 std::vector
<int> aWidths
;
57 weld::TreeView
& rTreeView
= m_xContentsListBox
->get_widget();
58 Size
aSize(m_xFunctions
->get_size_request());
59 rTreeView
.set_size_request(aSize
.Width(), aSize
.Height());
61 int nExpectedSize
= 16;
63 int nStandardImageColWidth
= rTreeView
.get_checkbox_column_width();
64 int nMargin
= nStandardImageColWidth
- nExpectedSize
;
68 if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_LARGE
)
70 else if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_32
)
73 int nImageColWidth
= nExpectedSize
+ nMargin
;
75 aWidths
.push_back(nStandardImageColWidth
);
76 aWidths
.push_back(nImageColWidth
);
77 rTreeView
.set_column_fixed_widths(aWidths
);
79 rTreeView
.set_hexpand(true);
80 rTreeView
.set_vexpand(true);
81 rTreeView
.set_help_id( HID_SVX_CONFIG_TOOLBAR_CONTENTS
);
84 rTreeView
.connect_changed(
85 LINK( this, SvxToolbarConfigPage
, SelectToolbarEntry
) );
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 void SvxToolbarConfigPage::ListModified()
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(),
293 m_xFrame
, m_aModuleId
);
294 m_xCommandCategoryListBox
->categorySelected(m_xFunctions
.get(), OUString(), GetSaveInData());
297 SaveInData
* SvxToolbarConfigPage::CreateSaveInData(
298 const css::uno::Reference
< css::ui::XUIConfigurationManager
>& xCfgMgr
,
299 const css::uno::Reference
< css::ui::XUIConfigurationManager
>& xParentCfgMgr
,
300 const OUString
& aModuleId
,
303 return static_cast< SaveInData
* >(
304 new ToolbarSaveInData( xCfgMgr
, xParentCfgMgr
, aModuleId
, bDocConfig
));
307 IMPL_LINK_NOARG(SvxToolbarConfigPage
, SelectToolbarEntry
, weld::TreeView
&, void)
309 UpdateButtonStates();
312 IMPL_LINK( SvxToolbarConfigPage
, GearHdl
, const OString
&, rIdent
, void )
314 SvxConfigEntry
* pCurrentToolbar
= GetTopLevelSelection();
316 if (rIdent
== "toolbar_gear_add")
318 OUString prefix
= CuiResId( RID_SVXSTR_NEW_TOOLBAR
);
321 SvxConfigPageHelper::generateCustomName( prefix
, GetSaveInData()->GetEntries() );
324 SvxConfigPageHelper::generateCustomURL( GetSaveInData()->GetEntries() );
326 SvxNewToolbarDialog
aNameDialog(GetFrameWeld(), aNewName
);
328 // Reflect the actual m_xSaveInListBox into the new toolbar dialog
329 for (int i
= 0, nCount
= m_xSaveInListBox
->get_count(); i
< nCount
; ++i
)
330 aNameDialog
.m_xSaveInListBox
->append_text(m_xSaveInListBox
->get_text(i
));
332 aNameDialog
.m_xSaveInListBox
->set_active(m_xSaveInListBox
->get_active());
334 if (aNameDialog
.run() == RET_OK
)
336 aNewName
= aNameDialog
.GetName();
338 // Where to save the new toolbar? (i.e. Modulewise or documentwise)
339 int nInsertPos
= aNameDialog
.m_xSaveInListBox
->get_active();
341 ToolbarSaveInData
* pData
=
342 reinterpret_cast<ToolbarSaveInData
*>(
343 m_xSaveInListBox
->get_id(nInsertPos
).toInt64() );
345 if ( GetSaveInData() != pData
)
347 m_xSaveInListBox
->set_active(nInsertPos
);
348 SelectSaveInLocation(*m_xSaveInListBox
);
351 SvxConfigEntry
* pToolbar
=
352 new SvxConfigEntry( aNewName
, aNewURL
, true, false );
354 pToolbar
->SetUserDefined();
357 pData
->CreateToolbar( pToolbar
);
359 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pToolbar
)));
360 m_xTopLevelListBox
->append(sId
, pToolbar
->GetName());
361 m_xTopLevelListBox
->set_active_id(sId
);
364 pData
->SetModified();
367 else if (rIdent
== "toolbar_gear_delete")
369 if ( pCurrentToolbar
&& pCurrentToolbar
->IsDeletable() )
371 DeleteSelectedTopLevel();
372 UpdateButtonStates();
375 else if (rIdent
== "toolbar_gear_rename")
377 sal_Int32 nSelectionPos
= m_xTopLevelListBox
->get_active();
378 SvxConfigEntry
* pToolbar
=
379 reinterpret_cast<SvxConfigEntry
*>(m_xTopLevelListBox
->get_id(nSelectionPos
).toInt64());
380 ToolbarSaveInData
* pSaveInData
= static_cast<ToolbarSaveInData
*>( GetSaveInData() );
383 OUString
sCurrentName( SvxConfigPageHelper::stripHotKey( pToolbar
->GetName() ) );
384 OUString sDesc
= CuiResId( RID_SVXSTR_LABEL_NEW_NAME
);
386 SvxNameDialog
aNameDialog(GetFrameWeld(), sCurrentName
, sDesc
);
387 aNameDialog
.set_help_id(HID_SVX_CONFIG_RENAME_TOOLBAR
);
388 aNameDialog
.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR
));
390 if ( aNameDialog
.run() == RET_OK
)
392 OUString sNewName
= aNameDialog
.GetName();
394 if (sCurrentName
== sNewName
)
397 pToolbar
->SetName( sNewName
);
398 pSaveInData
->ApplyToolbar( pToolbar
);
400 // have to use remove and insert to change the name
401 m_xTopLevelListBox
->remove(nSelectionPos
);
402 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pToolbar
)));
403 m_xTopLevelListBox
->insert(nSelectionPos
, sNewName
, &sId
, nullptr, nullptr);
404 m_xTopLevelListBox
->set_active_id(sId
);
407 else if (rIdent
== "toolbar_gear_iconOnly" || rIdent
== "toolbar_gear_textOnly" || rIdent
== "toolbar_gear_iconAndText")
409 ToolbarSaveInData
* pSaveInData
= static_cast<ToolbarSaveInData
*>( GetSaveInData() );
411 if (pCurrentToolbar
== nullptr || pSaveInData
== nullptr)
413 SAL_WARN("cui.customize", "NULL toolbar or savein data");
417 sal_Int32 nStyle
= 0;
418 if (rIdent
== "toolbar_gear_iconOnly")
420 else if (rIdent
== "toolbar_gear_textOnly")
422 else if (rIdent
== "toolbar_gear_iconAndText")
425 pCurrentToolbar
->SetStyle( nStyle
);
426 pSaveInData
->SetSystemStyle( m_xFrame
, pCurrentToolbar
->GetCommand(), nStyle
);
432 //This block should never be reached
433 SAL_WARN("cui.customize", "Unknown gear menu option: " << rIdent
);
438 IMPL_LINK_NOARG( SvxToolbarConfigPage
, SelectCategory
, weld::ComboBox
&, void )
440 OUString
aSearchTerm(m_xSearchEdit
->get_text());
442 m_xCommandCategoryListBox
->categorySelected(m_xFunctions
.get(), aSearchTerm
, GetSaveInData());
445 IMPL_LINK_NOARG( SvxToolbarConfigPage
, AddCommandHdl
, weld::Button
&, void )
450 IMPL_LINK_NOARG( SvxToolbarConfigPage
, RemoveCommandHdl
, weld::Button
&, void )
452 DeleteSelectedContent();
455 IMPL_LINK(SvxToolbarConfigPage
, InsertHdl
, const OString
&, rIdent
, void)
457 if (rIdent
== "insertseparator")
459 // Get the currently selected toolbar
460 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
462 SvxConfigEntry
* pNewEntryData
= new SvxConfigEntry
;
463 pNewEntryData
->SetUserDefined();
465 int nPos
= AppendEntry(pNewEntryData
, -1);
466 InsertEntryIntoUI(pNewEntryData
, m_xContentsListBox
->get_widget(), nPos
, 1);
468 static_cast<ToolbarSaveInData
*>( GetSaveInData())->ApplyToolbar( pToolbar
);
470 UpdateButtonStates();
474 //This block should never be reached
475 SAL_WARN("cui.customize", "Unknown insert option: " << rIdent
);
480 IMPL_LINK(SvxToolbarConfigPage
, ModifyItemHdl
, const OString
&, rIdent
, void)
482 bool bNeedsApply
= false;
484 // get currently selected toolbar
485 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
487 if (rIdent
.isEmpty() || pToolbar
== nullptr)
489 SAL_WARN("cui.customize", "No toolbar selected, or empty rIdent!");
493 if (rIdent
== "renameItem")
495 int nActEntry
= m_xContentsListBox
->get_selected_index();
496 SvxConfigEntry
* pEntry
=
497 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
499 OUString
aNewName( SvxConfigPageHelper::stripHotKey( pEntry
->GetName() ) );
500 OUString aDesc
= CuiResId( RID_SVXSTR_LABEL_NEW_NAME
);
502 SvxNameDialog
aNameDialog(GetFrameWeld(), aNewName
, aDesc
);
503 aNameDialog
.set_help_id(HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM
);
504 aNameDialog
.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR
));
506 if (aNameDialog
.run() == RET_OK
)
508 aNewName
= aNameDialog
.GetName();
510 if( aNewName
.isEmpty() ) // tdf#80758 - Accelerator character ("~") is passed as
511 pEntry
->SetName( "~" ); // the button name in case of empty values.
513 pEntry
->SetName( aNewName
);
515 m_xContentsListBox
->set_text(nActEntry
, aNewName
, 2);
519 else if (rIdent
== "changeIcon")
521 int nActEntry
= m_xContentsListBox
->get_selected_index();
522 SvxConfigEntry
* pEntry
=
523 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
525 SvxIconSelectorDialog
aIconDialog(GetFrameWeld(),
526 GetSaveInData()->GetImageManager(),
527 GetSaveInData()->GetParentImageManager());
529 if (aIconDialog
.run() == RET_OK
)
531 css::uno::Reference
< css::graphic::XGraphic
> newgraphic
=
532 aIconDialog
.GetSelectedIcon();
534 if ( newgraphic
.is() )
536 css::uno::Sequence
< css::uno::Reference
< css::graphic::XGraphic
> >
539 css::uno::Sequence
<OUString
> aURLSeq
{ pEntry
->GetCommand() };
541 if ( !pEntry
->GetBackupGraphic().is() )
543 css::uno::Reference
< css::graphic::XGraphic
> backup
=
544 SvxConfigPageHelper::GetGraphic(GetSaveInData()->GetImageManager(),
549 pEntry
->SetBackupGraphic(backup
);
553 aGraphicSeq
[ 0 ] = newgraphic
;
556 GetSaveInData()->GetImageManager()->replaceImages(
557 SvxConfigPageHelper::GetImageType(), aURLSeq
, aGraphicSeq
);
559 m_xContentsListBox
->remove(nActEntry
);
561 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pEntry
)));
562 m_xContentsListBox
->insert(nActEntry
, sId
);
563 m_xContentsListBox
->set_toggle(nActEntry
, pEntry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
564 InsertEntryIntoUI(pEntry
, m_xContentsListBox
->get_widget(), nActEntry
, 1);
566 m_xContentsListBox
->select(nActEntry
);
567 m_xContentsListBox
->scroll_to_row(nActEntry
);
569 GetSaveInData()->PersistChanges(
570 GetSaveInData()->GetImageManager() );
572 catch ( const css::uno::Exception
&)
574 TOOLS_WARN_EXCEPTION("cui.customize", "Error replacing image");
579 else if (rIdent
== "resetIcon")
581 int nActEntry
= m_xContentsListBox
->get_selected_index();
582 SvxConfigEntry
* pEntry
=
583 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
585 css::uno::Reference
< css::graphic::XGraphic
> backup
=
586 pEntry
->GetBackupGraphic();
588 css::uno::Sequence
< css::uno::Reference
< css::graphic::XGraphic
> >
590 aGraphicSeq
[ 0 ] = backup
;
592 css::uno::Sequence
<OUString
> aURLSeq
{ pEntry
->GetCommand() };
596 GetSaveInData()->GetImageManager()->replaceImages(
597 SvxConfigPageHelper::GetImageType(), aURLSeq
, aGraphicSeq
);
599 m_xContentsListBox
->remove(nActEntry
);
601 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pEntry
)));
602 m_xContentsListBox
->insert(nActEntry
, sId
);
603 m_xContentsListBox
->set_toggle(nActEntry
, pEntry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
604 InsertEntryIntoUI(pEntry
, m_xContentsListBox
->get_widget(), nActEntry
, 1);
606 m_xContentsListBox
->select(nActEntry
);
607 m_xContentsListBox
->scroll_to_row(nActEntry
);
609 // reset backup in entry
610 pEntry
->SetBackupGraphic(
611 css::uno::Reference
< css::graphic::XGraphic
>() );
613 GetSaveInData()->PersistChanges(
614 GetSaveInData()->GetImageManager() );
616 catch ( const css::uno::Exception
& )
618 TOOLS_WARN_EXCEPTION("cui.customize", "Error resetting image");
621 else if (rIdent
== "restoreItem")
623 int nActEntry
= m_xContentsListBox
->get_selected_index();
624 SvxConfigEntry
* pEntry
=
625 reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nActEntry
).toInt64());
627 ToolbarSaveInData
* pSaveInData
=
628 static_cast<ToolbarSaveInData
*>( GetSaveInData() );
630 OUString aSystemName
=
631 pSaveInData
->GetSystemUIName( pEntry
->GetCommand() );
633 if ( !pEntry
->GetName().equals( aSystemName
) )
635 pEntry
->SetName( aSystemName
);
636 m_xContentsListBox
->set_text(
637 nActEntry
, SvxConfigPageHelper::stripHotKey(aSystemName
), 2);
641 css::uno::Sequence
<OUString
> aURLSeq
{ pEntry
->GetCommand() };
645 GetSaveInData()->GetImageManager()->removeImages(
646 SvxConfigPageHelper::GetImageType(), aURLSeq
);
648 // reset backup in entry
649 pEntry
->SetBackupGraphic(
650 css::uno::Reference
< css::graphic::XGraphic
>() );
652 GetSaveInData()->PersistChanges(
653 GetSaveInData()->GetImageManager() );
655 m_xContentsListBox
->remove(nActEntry
);
657 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(pEntry
)));
658 m_xContentsListBox
->insert(nActEntry
, sId
);
659 m_xContentsListBox
->set_toggle(nActEntry
,
660 pEntry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
661 InsertEntryIntoUI(pEntry
, m_xContentsListBox
->get_widget(), nActEntry
, 1);
663 m_xContentsListBox
->select(nActEntry
);
664 m_xContentsListBox
->scroll_to_row(nActEntry
);
668 catch ( const css::uno::Exception
& )
670 TOOLS_WARN_EXCEPTION("cui.customize", "Error restoring image");
675 //This block should never be reached
676 SAL_WARN("cui.customize", "Unknown insert option: " << rIdent
);
682 static_cast<ToolbarSaveInData
*>( GetSaveInData())->ApplyToolbar( pToolbar
);
683 UpdateButtonStates();
687 IMPL_LINK_NOARG(SvxToolbarConfigPage
, ResetToolbarHdl
, weld::Button
&, void)
689 sal_Int32 nSelectionPos
= m_xTopLevelListBox
->get_active();
691 SvxConfigEntry
* pToolbar
=
692 reinterpret_cast<SvxConfigEntry
*>(m_xTopLevelListBox
->get_id(nSelectionPos
).toInt64());
694 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
695 VclMessageType::Question
, VclButtonsType::YesNo
,
696 CuiResId(RID_SVXSTR_CONFIRM_RESTORE_DEFAULT
)));
697 if (xQueryBox
->run() == RET_YES
)
699 ToolbarSaveInData
* pSaveInData
=
700 static_cast<ToolbarSaveInData
*>(GetSaveInData());
702 pSaveInData
->RestoreToolbar( pToolbar
);
708 void SvxToolbarConfigPage::UpdateButtonStates()
710 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
711 int selection
= m_xContentsListBox
->get_selected_index();
714 selection
!= -1 && reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(selection
).toInt64())->IsSeparator();
715 bool bIsValidSelection
=
716 !(m_xContentsListBox
->n_children() == 0 || selection
== -1);
718 m_xMoveUpButton
->set_sensitive( bIsValidSelection
);
719 m_xMoveDownButton
->set_sensitive( bIsValidSelection
);
721 m_xRemoveCommandButton
->set_sensitive( bIsValidSelection
);
723 m_xModifyBtn
->set_sensitive( bIsValidSelection
&& !bIsSeparator
);
725 // Handle the gear button
726 // "toolbar_gear_add" option is always enabled
727 m_xGearBtn
->set_item_sensitive("toolbar_gear_delete", pToolbar
&& pToolbar
->IsDeletable());
728 m_xGearBtn
->set_item_sensitive("toolbar_gear_rename", pToolbar
&& pToolbar
->IsRenamable());
731 short SvxToolbarConfigPage::QueryReset()
733 OUString msg
= CuiResId( RID_SVXSTR_CONFIRM_TOOLBAR_RESET
);
735 OUString saveInName
= m_xSaveInListBox
->get_active_text();
737 OUString label
= SvxConfigPageHelper::replaceSaveInName( msg
, saveInName
);
739 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
740 VclMessageType::Question
, VclButtonsType::YesNo
,
742 return xQueryBox
->run();
745 void SvxToolbarConfigPage::SelectElement()
747 m_xContentsListBox
->clear();
749 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
750 if ( pToolbar
== nullptr )
752 //TODO: Disable related buttons
753 m_xInsertBtn
->set_sensitive( false );
754 m_xResetBtn
->set_sensitive( false );
755 m_xGearBtn
->set_sensitive( false );
761 m_xInsertBtn
->set_sensitive(true);
762 m_xResetBtn
->set_sensitive(true);
763 m_xGearBtn
->set_sensitive(true);
766 switch (pToolbar
->GetStyle())
770 m_xGearBtn
->set_item_active("toolbar_gear_iconOnly", true);
775 m_xGearBtn
->set_item_active("toolbar_gear_textOnly", true);
780 m_xGearBtn
->set_item_active("toolbar_gear_iconAndText", true);
786 SvxEntries
* pEntries
= pToolbar
->GetEntries();
787 for (auto const& entry
: *pEntries
)
789 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(entry
)));
790 m_xContentsListBox
->insert(i
, sId
);
791 if (entry
->IsBinding() && !entry
->IsSeparator())
792 m_xContentsListBox
->set_toggle(i
, entry
->IsVisible() ? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
793 InsertEntryIntoUI(entry
, m_xContentsListBox
->get_widget(), i
, 1);
797 UpdateButtonStates();
800 void SvxToolbarConfigPage::AddFunction(int nTarget
)
802 SvxConfigEntry
* pToolbar
= GetTopLevelSelection();
804 if (pToolbar
== nullptr)
807 // Add the command to the contents listbox of the selected toolbar
809 SvxConfigPage::AddFunction(nTarget
, true/*bAllowDuplicates*/);
811 if (nNewLBEntry
== -1)
814 SvxConfigEntry
* pEntry
= reinterpret_cast<SvxConfigEntry
*>(m_xContentsListBox
->get_id(nNewLBEntry
).toInt64());
816 if ( pEntry
->IsBinding() ) //TODO sep ?
818 pEntry
->SetVisible(true);
819 m_xContentsListBox
->set_toggle(nNewLBEntry
, TRISTATE_TRUE
, 0);
822 InsertEntryIntoUI(pEntry
, m_xContentsListBox
->get_widget(), nNewLBEntry
, 1);
824 // Changes are not visible on the toolbar until this point
825 // TODO: Figure out a way to show the changes on the toolbar, but revert if
826 // the dialog is closed by pressing "Cancel"
827 // get currently selected toolbar and apply change
828 if ( pToolbar
!= nullptr )
830 static_cast<ToolbarSaveInData
*>( GetSaveInData() )->ApplyToolbar( pToolbar
);
834 SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(std::unique_ptr
<weld::TreeView
> xParent
, SvxToolbarConfigPage
* pPg
)
835 : SvxMenuEntriesListBox(std::move(xParent
), pPg
)
837 m_xControl
->connect_toggled(LINK(this, SvxToolbarEntriesListBox
, CheckButtonHdl
));
838 m_xControl
->connect_key_press(Link
<const KeyEvent
&, bool>()); //acknowledge we first remove the old one
839 m_xControl
->connect_key_press(LINK(this, SvxToolbarEntriesListBox
, KeyInputHdl
)); // then add the new one
842 SvxToolbarEntriesListBox::~SvxToolbarEntriesListBox()
846 void SvxToolbarEntriesListBox::ChangedVisibility(int nRow
)
848 SvxConfigEntry
* pEntryData
=
849 reinterpret_cast<SvxConfigEntry
*>(m_xControl
->get_id(nRow
).toInt64());
851 if (pEntryData
->IsBinding())
853 pEntryData
->SetVisible(m_xControl
->get_toggle(nRow
, 0) == TRISTATE_TRUE
);
855 SvxConfigEntry
* pToolbar
= m_pPage
->GetTopLevelSelection();
857 ToolbarSaveInData
* pToolbarSaveInData
= static_cast<ToolbarSaveInData
*>(
858 m_pPage
->GetSaveInData() );
860 pToolbarSaveInData
->ApplyToolbar( pToolbar
);
864 IMPL_LINK(SvxToolbarEntriesListBox
, CheckButtonHdl
, const row_col
&, rRowCol
, void)
866 ChangedVisibility(rRowCol
.first
);
869 IMPL_LINK(SvxToolbarEntriesListBox
, KeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
871 // space key will change visibility of toolbar items
872 if ( rKeyEvent
.GetKeyCode() == KEY_SPACE
)
874 int nRow
= m_xControl
->get_selected_index();
875 SvxConfigEntry
* pEntryData
= reinterpret_cast<SvxConfigEntry
*>(m_xControl
->get_id(nRow
).toInt64());
876 if (pEntryData
->IsBinding() && !pEntryData
->IsSeparator())
878 m_xControl
->set_toggle(nRow
, m_xControl
->get_toggle(nRow
, 0) == TRISTATE_TRUE
? TRISTATE_FALSE
: TRISTATE_TRUE
, 0);
879 ChangedVisibility(nRow
);
883 return SvxMenuEntriesListBox::KeyInputHdl(rKeyEvent
);
886 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */