LibreOffice Module cui (master)  1
SvxToolbarConfigPage.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 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
24 #include <vcl/event.hxx>
25 #include <vcl/weld.hxx>
26 #include <vcl/svapp.hxx>
27 
28 #include <sfx2/sfxsids.hrc>
29 #include <svl/stritem.hxx>
30 #include <tools/diagnose_ex.h>
31 
32 #include <algorithm>
33 #include <helpids.h>
34 #include <strings.hrc>
35 
36 #include <cfg.hxx>
37 #include <SvxToolbarConfigPage.hxx>
38 #include <SvxConfigPageHelper.hxx>
39 #include <dialmgr.hxx>
40 
42 #include <com/sun/star/ui/ImageType.hpp>
43 
44 #include <dlgname.hxx>
45 
47  : SvxConfigPage(pParent, rSet)
48 {
49  m_xGearBtn = m_xBuilder->weld_menu_button("toolbargearbtn");
50  m_xGearBtn->show();
52 
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());
58 
59  int nExpectedSize = 16;
60 
61  int nStandardImageColWidth = rTreeView.get_checkbox_column_width();
62  int nMargin = nStandardImageColWidth - nExpectedSize;
63  if (nMargin < 16)
64  nMargin = 16;
65 
66  if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_LARGE)
67  nExpectedSize = 24;
68  else if (SvxConfigPageHelper::GetImageType() & css::ui::ImageType::SIZE_32)
69  nExpectedSize = 32;
70 
71  int nImageColWidth = nExpectedSize + nMargin;
72 
73  aWidths.push_back(nStandardImageColWidth);
74  aWidths.push_back(nImageColWidth);
75  rTreeView.set_column_fixed_widths(aWidths);
76 
77  rTreeView.set_hexpand(true);
78  rTreeView.set_vexpand(true);
80  rTreeView.show();
81 
82  rTreeView.connect_changed(
83  LINK( this, SvxToolbarConfigPage, SelectToolbarEntry ) );
84 
85  rTreeView.connect_model_changed(LINK(this, SvxToolbarConfigPage, ListModifiedHdl));
86 
88  m_xSaveInListBox->set_help_id( HID_SVX_SAVE_IN );
91  m_xDescriptionField->set_help_id ( HID_SVX_DESCFIELD );
92 
93  m_xCommandCategoryListBox->connect_changed(
94  LINK( this, SvxToolbarConfigPage, SelectCategory ) );
95 
96  m_xGearBtn->connect_selected(
97  LINK( this, SvxToolbarConfigPage, GearHdl ) );
98 
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);
105 
106  m_xAddCommandButton->connect_clicked( LINK( this, SvxToolbarConfigPage, AddCommandHdl ) );
107  m_xRemoveCommandButton->connect_clicked( LINK( this, SvxToolbarConfigPage, RemoveCommandHdl ) );
108 
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 ) );
115 
116  // "Insert Submenu" is irrelevant to the toolbars
117  m_xInsertBtn->remove_item("insertsubmenu");
118 
119  // Gear menu's "Move" action is irrelevant to the toolbars
120  m_xGearBtn->set_item_sensitive("toolbar_gear_move", false);
121 
122  // default toolbar to select is standardbar unless a different one
123  // has been passed in
125  m_aURLToSelect += "standardbar";
126 
127  const SfxPoolItem* pItem =
128  rSet.GetItem( rSet.GetPool()->GetWhich( SID_CONFIG ) );
129 
130  if ( pItem )
131  {
132  OUString text = static_cast<const SfxStringItem*>(pItem)->GetValue();
133  if (text.startsWith( ITEM_TOOLBAR_URL ))
134  {
135  m_aURLToSelect = text.copy( 0 );
136  }
137  }
138 }
139 
141 {
142  // regenerate with the current ordering within the list
143  SvxEntries* pEntries = GetTopLevelSelection()->GetEntries();
144  pEntries->clear();
145 
146  for (int i = 0; i < m_xContentsListBox->n_children(); ++i)
147  pEntries->push_back(reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(i).toInt64()));
148 
149  GetSaveInData()->SetModified();
150  GetTopLevelSelection()->SetModified();
151 
152  SvxConfigEntry* pToolbar = GetTopLevelSelection();
153  if ( pToolbar )
154  static_cast<ToolbarSaveInData*>(GetSaveInData())->ApplyToolbar( pToolbar );
155 }
156 
158 {
159  disposeOnce();
160 }
161 
163 {
164  for (int i = 0, nCount = m_xSaveInListBox->get_count(); i < nCount; ++i)
165  {
166  ToolbarSaveInData* pData =
167  reinterpret_cast<ToolbarSaveInData*>(m_xSaveInListBox->get_id(i).toInt64());
168  delete pData;
169  }
170  m_xSaveInListBox->clear();
171 
173 }
174 
176 {
177  const sal_Int32 nSelectionPos = m_xTopLevelListBox->get_active();
178  ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() );
179  pSaveInData->RemoveToolbar( GetTopLevelSelection() );
180 
181  int nCount = m_xTopLevelListBox->get_count();
182  if (nCount > 1)
183  {
184  // select next entry after the one being deleted
185  // selection position is indexed from 0 so need to
186  // subtract one from the entry count
187  if (nSelectionPos != nCount - 1)
188  {
189  m_xTopLevelListBox->set_active(nSelectionPos + 1);
190  }
191  else
192  {
193  m_xTopLevelListBox->set_active(nSelectionPos - 1);
194  }
195  SelectElement();
196 
197  // and now remove the entry
198  m_xTopLevelListBox->remove(nSelectionPos);
199  }
200  else
201  {
203  }
204 }
205 
207 {
208  int nActEntry = m_xContentsListBox->get_selected_index();
209 
210  if (nActEntry != -1)
211  {
212  // get currently selected entry
213  SvxConfigEntry* pEntry =
214  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64());
215 
216  SvxConfigEntry* pToolbar = GetTopLevelSelection();
217 
218  // remove entry from the list for this toolbar
219  SvxConfigPageHelper::RemoveEntry( pToolbar->GetEntries(), pEntry );
220 
221  // remove toolbar entry from UI
222  m_xContentsListBox->remove(nActEntry);
223 
224  // delete data for toolbar entry
225  delete pEntry;
226 
227  static_cast<ToolbarSaveInData*>(GetSaveInData())->ApplyToolbar( pToolbar );
229 
230  // if this is the last entry in the toolbar and it is a user
231  // defined toolbar pop up a dialog asking the user if they
232  // want to delete the toolbar
233  if ( m_xContentsListBox->n_children() == 0 &&
235  {
236  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(),
237  VclMessageType::Question, VclButtonsType::YesNo,
238  CuiResId(RID_SXVSTR_CONFIRM_DELETE_TOOLBAR)));
239  if (xQueryBox->run() == RET_YES)
240  {
242  }
243  }
244  }
245 }
246 
247 IMPL_LINK( SvxToolbarConfigPage, MoveHdl, weld::Button&, rButton, void )
248 {
249  MoveEntry(&rButton == m_xMoveUpButton.get());
250 }
251 
253 {
254  SvxConfigPage::MoveEntry( bMoveUp );
255 
256  // Apply change to currently selected toolbar
257  SvxConfigEntry* pToolbar = GetTopLevelSelection();
258  if ( pToolbar )
259  static_cast<ToolbarSaveInData*>(GetSaveInData())->ApplyToolbar( pToolbar );
260  else
261  {
262  SAL_WARN( "cui.customize", "SvxToolbarConfigPage::MoveEntry(): no entry" );
264  }
265 }
266 
268 {
269  // ensure that the UI is cleared before populating it
270  m_xTopLevelListBox->clear();
271  m_xContentsListBox->clear();
272 
274 
275  sal_Int32 nPos = 0;
276  if ( !m_aURLToSelect.isEmpty() )
277  {
278  for (sal_Int32 i = 0, nCount = m_xTopLevelListBox->get_count(); i < nCount; ++i)
279  {
280  SvxConfigEntry* pData =
281  reinterpret_cast<SvxConfigEntry*>(m_xTopLevelListBox->get_id(i).toInt64());
282 
283  if ( pData->GetCommand().equals( m_aURLToSelect ) )
284  {
285  nPos = i;
286  break;
287  }
288  }
289 
290  // in future select the default toolbar: Standard
292  m_aURLToSelect += "standardbar";
293  }
294 
295  m_xTopLevelListBox->set_active(nPos);
296  SelectElement();
297 
300  m_xFrame,
302  m_xCommandCategoryListBox->categorySelected(m_xFunctions.get(), OUString(), GetSaveInData());
303 }
304 
306  const css::uno::Reference< css::ui::XUIConfigurationManager >& xCfgMgr,
307  const css::uno::Reference< css::ui::XUIConfigurationManager >& xParentCfgMgr,
308  const OUString& aModuleId,
309  bool bDocConfig )
310 {
311  return static_cast< SaveInData* >(
312  new ToolbarSaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bDocConfig ));
313 }
314 
316 {
317  UpdateButtonStates();
318 }
319 
320 IMPL_LINK( SvxToolbarConfigPage, GearHdl, const OString&, rIdent, void )
321 {
322  SvxConfigEntry* pCurrentToolbar = GetTopLevelSelection();
323 
324  if (rIdent == "toolbar_gear_add")
325  {
326  OUString prefix = CuiResId( RID_SVXSTR_NEW_TOOLBAR );
327 
328  OUString aNewName =
329  SvxConfigPageHelper::generateCustomName( prefix, GetSaveInData()->GetEntries() );
330 
331  OUString aNewURL =
332  SvxConfigPageHelper::generateCustomURL( GetSaveInData()->GetEntries() );
333 
334  SvxNewToolbarDialog aNameDialog(GetDialogFrameWeld(), aNewName);
335 
336  // Reflect the actual m_xSaveInListBox into the new toolbar dialog
337  for (int i = 0, nCount = m_xSaveInListBox->get_count(); i < nCount; ++i)
338  aNameDialog.m_xSaveInListBox->append_text(m_xSaveInListBox->get_text(i));
339 
340  aNameDialog.m_xSaveInListBox->set_active(m_xSaveInListBox->get_active());
341 
342  if (aNameDialog.run() == RET_OK)
343  {
344  aNewName = aNameDialog.GetName();
345 
346  // Where to save the new toolbar? (i.e. Modulewise or documentwise)
347  int nInsertPos = aNameDialog.m_xSaveInListBox->get_active();
348 
349  ToolbarSaveInData* pData =
350  reinterpret_cast<ToolbarSaveInData*>(
351  m_xSaveInListBox->get_id(nInsertPos).toInt64() );
352 
353  if ( GetSaveInData() != pData )
354  {
355  m_xSaveInListBox->set_active(nInsertPos);
356  SelectSaveInLocation(*m_xSaveInListBox);
357  }
358 
359  SvxConfigEntry* pToolbar =
360  new SvxConfigEntry( aNewName, aNewURL, true, false );
361 
362  pToolbar->SetUserDefined();
363  pToolbar->SetMain();
364 
365  pData->CreateToolbar( pToolbar );
366 
367  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pToolbar)));
368  m_xTopLevelListBox->append(sId, pToolbar->GetName());
369  m_xTopLevelListBox->set_active_id(sId);
370  SelectElement();
371 
372  pData->SetModified();
373  }
374  }
375  else if (rIdent == "toolbar_gear_delete")
376  {
377  if ( pCurrentToolbar && pCurrentToolbar->IsDeletable() )
378  {
379  DeleteSelectedTopLevel();
380  UpdateButtonStates();
381  }
382  }
383  else if (rIdent == "toolbar_gear_rename")
384  {
385  sal_Int32 nSelectionPos = m_xTopLevelListBox->get_active();
386  SvxConfigEntry* pToolbar =
387  reinterpret_cast<SvxConfigEntry*>(m_xTopLevelListBox->get_id(nSelectionPos).toInt64());
388  ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() );
389 
390  //Rename the toolbar
391  OUString sCurrentName( SvxConfigPageHelper::stripHotKey( pToolbar->GetName() ) );
392  OUString sDesc = CuiResId( RID_SVXSTR_LABEL_NEW_NAME );
393 
394  SvxNameDialog aNameDialog(GetDialogFrameWeld(), sCurrentName, sDesc);
396  aNameDialog.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR));
397 
398  if ( aNameDialog.run() == RET_OK )
399  {
400  OUString sNewName = aNameDialog.GetName();
401 
402  if (sCurrentName == sNewName)
403  return;
404 
405  pToolbar->SetName( sNewName );
406  pSaveInData->ApplyToolbar( pToolbar );
407 
408  // have to use remove and insert to change the name
409  m_xTopLevelListBox->remove(nSelectionPos);
410  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pToolbar)));
411  m_xTopLevelListBox->insert(nSelectionPos, sNewName, &sId, nullptr, nullptr);
412  m_xTopLevelListBox->set_active_id(sId);
413  }
414  }
415  else if (rIdent == "toolbar_gear_iconOnly" || rIdent == "toolbar_gear_textOnly" || rIdent == "toolbar_gear_iconAndText")
416  {
417  ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() );
418 
419  if (pCurrentToolbar == nullptr || pSaveInData == nullptr)
420  {
421  SAL_WARN("cui.customize", "NULL toolbar or savein data");
422  return;
423  }
424 
425  sal_Int32 nStyle = 0;
426  if (rIdent == "toolbar_gear_iconOnly")
427  nStyle = 0;
428  else if (rIdent == "toolbar_gear_textOnly")
429  nStyle = 1;
430  else if (rIdent == "toolbar_gear_iconAndText")
431  nStyle = 2;
432 
433  pCurrentToolbar->SetStyle( nStyle );
434  pSaveInData->SetSystemStyle( m_xFrame, pCurrentToolbar->GetCommand(), nStyle );
435 
436  SelectElement();
437  }
438  else
439  {
440  //This block should never be reached
441  SAL_WARN("cui.customize", "Unknown gear menu option: " << rIdent);
442  return;
443  }
444 }
445 
447 {
448  OUString aSearchTerm(m_xSearchEdit->get_text());
449 
450  m_xCommandCategoryListBox->categorySelected(m_xFunctions.get(), aSearchTerm, GetSaveInData());
451 }
452 
454 {
455  AddFunction();
456 }
457 
459 {
460  DeleteSelectedContent();
461 }
462 
463 IMPL_LINK(SvxToolbarConfigPage, InsertHdl, const OString&, rIdent, void)
464 {
465  if (rIdent == "insertseparator")
466  {
467  // Get the currently selected toolbar
468  SvxConfigEntry* pToolbar = GetTopLevelSelection();
469 
470  SvxConfigEntry* pNewEntryData = new SvxConfigEntry;
471  pNewEntryData->SetUserDefined();
472 
473  int nPos = InsertEntry(pNewEntryData, -1);
474  InsertEntryIntoUI(pNewEntryData, nPos, 1);
475 
476  static_cast<ToolbarSaveInData*>( GetSaveInData())->ApplyToolbar( pToolbar );
477 
478  UpdateButtonStates();
479  }
480  else
481  {
482  //This block should never be reached
483  SAL_WARN("cui.customize", "Unknown insert option: " << rIdent);
484  return;
485  }
486 }
487 
488 IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void)
489 {
490  bool bNeedsApply = false;
491 
492  // get currently selected toolbar
493  SvxConfigEntry* pToolbar = GetTopLevelSelection();
494 
495  if (rIdent.isEmpty() || pToolbar == nullptr)
496  {
497  SAL_WARN("cui.customize", "No toolbar selected, or empty rIdent!");
498  return;
499  }
500 
501  if (rIdent == "renameItem")
502  {
503  int nActEntry = m_xContentsListBox->get_selected_index();
504  SvxConfigEntry* pEntry =
505  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64());
506 
507  OUString aNewName( SvxConfigPageHelper::stripHotKey( pEntry->GetName() ) );
508  OUString aDesc = CuiResId( RID_SVXSTR_LABEL_NEW_NAME );
509 
510  SvxNameDialog aNameDialog(GetDialogFrameWeld(), aNewName, aDesc);
512  aNameDialog.set_title(CuiResId(RID_SVXSTR_RENAME_TOOLBAR));
513 
514  if (aNameDialog.run() == RET_OK)
515  {
516  aNewName = aNameDialog.GetName();
517 
518  if( aNewName.isEmpty() ) // tdf#80758 - Accelerator character ("~") is passed as
519  pEntry->SetName( "~" ); // the button name in case of empty values.
520  else
521  pEntry->SetName( aNewName );
522 
523  m_xContentsListBox->set_text(nActEntry, aNewName, 2);
524  bNeedsApply = true;
525  }
526  }
527  else if (rIdent == "changeIcon")
528  {
529  int nActEntry = m_xContentsListBox->get_selected_index();
530  SvxConfigEntry* pEntry =
531  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64());
532 
533  SvxIconSelectorDialog aIconDialog(GetDialogFrameWeld(),
534  GetSaveInData()->GetImageManager(),
535  GetSaveInData()->GetParentImageManager());
536 
537  if (aIconDialog.run() == RET_OK)
538  {
539  css::uno::Reference< css::graphic::XGraphic > newgraphic =
540  aIconDialog.GetSelectedIcon();
541 
542  if ( newgraphic.is() )
543  {
544  css::uno::Sequence< css::uno::Reference< css::graphic::XGraphic > >
545  aGraphicSeq( 1 );
546 
547  css::uno::Sequence<OUString> aURLSeq { pEntry->GetCommand() };
548 
549  if ( !pEntry->GetBackupGraphic().is() )
550  {
551  css::uno::Reference< css::graphic::XGraphic > backup =
552  SvxConfigPageHelper::GetGraphic(GetSaveInData()->GetImageManager(),
553  aURLSeq[0]);
554 
555  if ( backup.is() )
556  {
557  pEntry->SetBackupGraphic(backup);
558  }
559  }
560 
561  aGraphicSeq[ 0 ] = newgraphic;
562  try
563  {
564  GetSaveInData()->GetImageManager()->replaceImages(
565  SvxConfigPageHelper::GetImageType(), aURLSeq, aGraphicSeq );
566 
567  m_xContentsListBox->remove(nActEntry);
568 
569  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry)));
570  m_xContentsListBox->insert(nActEntry, sId);
571  m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
572  InsertEntryIntoUI(pEntry, nActEntry, 1);
573 
574  m_xContentsListBox->select(nActEntry);
575  m_xContentsListBox->scroll_to_row(nActEntry);
576 
577  GetSaveInData()->PersistChanges(
578  GetSaveInData()->GetImageManager() );
579  }
580  catch ( const css::uno::Exception&)
581  {
582  TOOLS_WARN_EXCEPTION("cui.customize", "Error replacing image");
583  }
584  }
585  }
586  }
587  else if (rIdent == "resetIcon")
588  {
589  int nActEntry = m_xContentsListBox->get_selected_index();
590  SvxConfigEntry* pEntry =
591  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64());
592 
593  css::uno::Reference< css::graphic::XGraphic > backup =
594  pEntry->GetBackupGraphic();
595 
596  css::uno::Sequence< css::uno::Reference< css::graphic::XGraphic > >
597  aGraphicSeq( 1 );
598  aGraphicSeq[ 0 ] = backup;
599 
600  css::uno::Sequence<OUString> aURLSeq { pEntry->GetCommand() };
601 
602  try
603  {
604  GetSaveInData()->GetImageManager()->replaceImages(
605  SvxConfigPageHelper::GetImageType(), aURLSeq, aGraphicSeq );
606 
607  m_xContentsListBox->remove(nActEntry);
608 
609  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry)));
610  m_xContentsListBox->insert(nActEntry, sId);
611  m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
612  InsertEntryIntoUI(pEntry, nActEntry, 1);
613 
614  m_xContentsListBox->select(nActEntry);
615  m_xContentsListBox->scroll_to_row(nActEntry);
616 
617  // reset backup in entry
618  pEntry->SetBackupGraphic(
619  css::uno::Reference< css::graphic::XGraphic >() );
620 
621  GetSaveInData()->PersistChanges(
622  GetSaveInData()->GetImageManager() );
623  }
624  catch ( const css::uno::Exception& )
625  {
626  TOOLS_WARN_EXCEPTION("cui.customize", "Error resetting image");
627  }
628  }
629  else if (rIdent == "restoreItem")
630  {
631  int nActEntry = m_xContentsListBox->get_selected_index();
632  SvxConfigEntry* pEntry =
633  reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nActEntry).toInt64());
634 
635  ToolbarSaveInData* pSaveInData =
636  static_cast<ToolbarSaveInData*>( GetSaveInData() );
637 
638  OUString aSystemName =
639  pSaveInData->GetSystemUIName( pEntry->GetCommand() );
640 
641  if ( !pEntry->GetName().equals( aSystemName ) )
642  {
643  pEntry->SetName( aSystemName );
644  m_xContentsListBox->set_text(
645  nActEntry, SvxConfigPageHelper::stripHotKey(aSystemName), 2);
646  bNeedsApply = true;
647  }
648 
649  css::uno::Sequence<OUString> aURLSeq { pEntry->GetCommand() };
650 
651  try
652  {
653  GetSaveInData()->GetImageManager()->removeImages(
655 
656  // reset backup in entry
657  pEntry->SetBackupGraphic(
658  css::uno::Reference< css::graphic::XGraphic >() );
659 
660  GetSaveInData()->PersistChanges(
661  GetSaveInData()->GetImageManager() );
662 
663  m_xContentsListBox->remove(nActEntry);
664 
665  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry)));
666  m_xContentsListBox->insert(nActEntry, sId);
667  m_xContentsListBox->set_toggle(nActEntry,
668  pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
669  InsertEntryIntoUI(pEntry, nActEntry, 1);
670 
671  m_xContentsListBox->select(nActEntry);
672  m_xContentsListBox->scroll_to_row(nActEntry);
673 
674  bNeedsApply = true;
675  }
676  catch ( const css::uno::Exception& )
677  {
678  TOOLS_WARN_EXCEPTION("cui.customize", "Error restoring image");
679  }
680  }
681  else
682  {
683  //This block should never be reached
684  SAL_WARN("cui.customize", "Unknown insert option: " << rIdent);
685  return;
686  }
687 
688  if ( bNeedsApply )
689  {
690  static_cast<ToolbarSaveInData*>( GetSaveInData())->ApplyToolbar( pToolbar );
691  UpdateButtonStates();
692  }
693 }
694 
696 {
697  sal_Int32 nSelectionPos = m_xTopLevelListBox->get_active();
698 
699  SvxConfigEntry* pToolbar =
700  reinterpret_cast<SvxConfigEntry*>(m_xTopLevelListBox->get_id(nSelectionPos).toInt64());
701 
702  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(),
703  VclMessageType::Question, VclButtonsType::YesNo,
704  CuiResId(RID_SVXSTR_CONFIRM_RESTORE_DEFAULT)));
705  if (xQueryBox->run() == RET_YES)
706  {
707  ToolbarSaveInData* pSaveInData =
708  static_cast<ToolbarSaveInData*>(GetSaveInData());
709 
710  pSaveInData->RestoreToolbar( pToolbar );
711 
712  SelectElement();
713  }
714 }
715 
717 {
718  SvxConfigEntry* pToolbar = GetTopLevelSelection();
719  int selection = m_xContentsListBox->get_selected_index();
720 
721  bool bIsSeparator =
722  selection != -1 && reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(selection).toInt64())->IsSeparator();
723  bool bIsValidSelection =
724  !(m_xContentsListBox->n_children() == 0 || selection == -1);
725 
726  m_xMoveUpButton->set_sensitive( bIsValidSelection );
727  m_xMoveDownButton->set_sensitive( bIsValidSelection );
728 
729  m_xRemoveCommandButton->set_sensitive( bIsValidSelection );
730 
731  m_xModifyBtn->set_sensitive( bIsValidSelection && !bIsSeparator );
732 
733  // Handle the gear button
734  // "toolbar_gear_add" option is always enabled
735  m_xGearBtn->set_item_sensitive("toolbar_gear_delete", pToolbar && pToolbar->IsDeletable());
736  m_xGearBtn->set_item_sensitive("toolbar_gear_rename", pToolbar && pToolbar->IsRenamable());
737 }
738 
740 {
741  OUString msg = CuiResId( RID_SVXSTR_CONFIRM_TOOLBAR_RESET );
742 
743  OUString saveInName = m_xSaveInListBox->get_active_text();
744 
745  OUString label = SvxConfigPageHelper::replaceSaveInName( msg, saveInName );
746 
747  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetDialogFrameWeld(),
748  VclMessageType::Question, VclButtonsType::YesNo,
749  label));
750  return xQueryBox->run();
751 }
752 
754 {
755  m_xContentsListBox->clear();
756 
757  SvxConfigEntry* pToolbar = GetTopLevelSelection();
758  if ( pToolbar == nullptr )
759  {
760  //TODO: Disable related buttons
761  m_xInsertBtn->set_sensitive( false );
762  m_xResetBtn->set_sensitive( false );
763  m_xGearBtn->set_sensitive( false );
764 
765  return;
766  }
767  else
768  {
769  m_xInsertBtn->set_sensitive(true);
770  m_xResetBtn->set_sensitive(true);
771  m_xGearBtn->set_sensitive(true);
772  }
773 
774  switch (pToolbar->GetStyle())
775  {
776  case 0:
777  {
778  m_xGearBtn->set_item_active("toolbar_gear_iconOnly", true);
779  break;
780  }
781  case 1:
782  {
783  m_xGearBtn->set_item_active("toolbar_gear_textOnly", true);
784  break;
785  }
786  case 2:
787  {
788  m_xGearBtn->set_item_active("toolbar_gear_iconAndText", true);
789  break;
790  }
791  }
792 
793  int i = 0;
794  SvxEntries* pEntries = pToolbar->GetEntries();
795  for (auto const& entry : *pEntries)
796  {
797  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(entry)));
798  m_xContentsListBox->insert(i, sId);
799  if (entry->IsBinding() && !entry->IsSeparator())
800  m_xContentsListBox->set_toggle(i, entry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
801  InsertEntryIntoUI(entry, i, 1);
802  ++i;
803  }
804 
806 }
807 
809 {
810  SvxConfigEntry* pToolbar = GetTopLevelSelection();
811 
812  if (pToolbar == nullptr)
813  return;
814 
815  // Add the command to the contents listbox of the selected toolbar
816  int nNewLBEntry =
817  SvxConfigPage::AddFunction(nTarget, true/*bAllowDuplicates*/);
818 
819  if (nNewLBEntry == -1)
820  return;
821 
822  SvxConfigEntry* pEntry = reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nNewLBEntry).toInt64());
823 
824  if ( pEntry->IsBinding() ) //TODO sep ?
825  {
826  pEntry->SetVisible(true);
827  m_xContentsListBox->set_toggle(nNewLBEntry, TRISTATE_TRUE, 0);
828  }
829 
830  InsertEntryIntoUI(pEntry, nNewLBEntry, 1);
831 
832  // Changes are not visible on the toolbar until this point
833  // TODO: Figure out a way to show the changes on the toolbar, but revert if
834  // the dialog is closed by pressing "Cancel"
835  // get currently selected toolbar and apply change
836  if ( pToolbar != nullptr )
837  {
838  static_cast<ToolbarSaveInData*>( GetSaveInData() )->ApplyToolbar( pToolbar );
839  }
840 }
841 
842 SvxToolbarEntriesListBox::SvxToolbarEntriesListBox(std::unique_ptr<weld::TreeView> xParent, SvxToolbarConfigPage* pPg)
843  : SvxMenuEntriesListBox(std::move(xParent), pPg)
844 {
845  m_xControl->connect_toggled(LINK(this, SvxToolbarEntriesListBox, CheckButtonHdl));
846  m_xControl->connect_key_press(Link<const KeyEvent&, bool>()); //acknowledge we first remove the old one
847  m_xControl->connect_key_press(LINK(this, SvxToolbarEntriesListBox, KeyInputHdl)); // then add the new one
848 }
849 
851 {
852 }
853 
855 {
856  SvxConfigEntry* pEntryData =
857  reinterpret_cast<SvxConfigEntry*>(m_xControl->get_id(nRow).toInt64());
858 
859  if (pEntryData->IsBinding())
860  {
861  pEntryData->SetVisible(m_xControl->get_toggle(nRow, 0) == TRISTATE_TRUE);
862 
864 
865  ToolbarSaveInData* pToolbarSaveInData = static_cast<ToolbarSaveInData*>(
866  pPage->GetSaveInData() );
867 
868  pToolbarSaveInData->ApplyToolbar( pToolbar );
869  }
870 }
871 
872 IMPL_LINK(SvxToolbarEntriesListBox, CheckButtonHdl, const row_col&, rRowCol, void)
873 {
874  ChangedVisibility(rRowCol.first);
875 }
876 
877 IMPL_LINK(SvxToolbarEntriesListBox, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
878 {
879  // space key will change visibility of toolbar items
880  if ( rKeyEvent.GetKeyCode() == KEY_SPACE )
881  {
882  int nRow = m_xControl->get_selected_index();
883  SvxConfigEntry* pEntryData = reinterpret_cast<SvxConfigEntry*>(m_xControl->get_id(nRow).toInt64());
884  if (pEntryData->IsBinding() && !pEntryData->IsSeparator())
885  {
886  m_xControl->set_toggle(nRow, m_xControl->get_toggle(nRow, 0) == TRISTATE_TRUE ? TRISTATE_FALSE : TRISTATE_TRUE, 0);
887  ChangedVisibility(nRow);
888  }
889  return true;
890  }
891  return SvxMenuEntriesListBox::KeyInputHdl(rKeyEvent);
892 }
893 
894 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void RemoveToolbar(SvxConfigEntry *pToolbar)
Definition: cfg.cxx:2457
std::unique_ptr< CuiConfigFunctionListBox > m_xFunctions
Definition: cfg.hxx:373
SvxEntries * GetEntries() const
Definition: cfg.hxx:287
std::unique_ptr< weld::Button > m_xResetBtn
Definition: cfg.hxx:400
void AddFunction(int nTarget=-1)
void set_title(const OUString &rTitle)
const OUString & GetName() const
Definition: cfg.hxx:275
static OUString generateCustomURL(SvxEntries *entries)
Generates a custom resource URL for a new toolbar.
std::unique_ptr< weld::MenuButton > m_xModifyBtn
Definition: cfg.hxx:398
bool IsVisible() const
Definition: cfg.hxx:304
std::unique_ptr< CommandCategoryListBox > m_xCommandCategoryListBox
Definition: cfg.hxx:372
OUString m_aURLToSelect
the ResourceURL to select when opening the dialog
Definition: cfg.hxx:366
SvxToolbarConfigPage(TabPageParent pParent, const SfxItemSet &rItemSet)
virtual ~SvxToolbarConfigPage() override
#define KEY_SPACE
static OUString stripHotKey(const OUString &str)
std::string GetValue
OUString GetSystemUIName(const OUString &rResourceURL)
Definition: cfg.cxx:2040
css::uno::Reference< css::frame::XFrame > m_xFrame
Definition: cfg.hxx:368
SvxConfigEntry * GetTopLevelSelection()
Definition: cfg.hxx:467
static sal_Int16 GetImageType()
std::unique_ptr< weld::Button > m_xRemoveCommandButton
Definition: cfg.hxx:404
void SetBackupGraphic(css::uno::Reference< css::graphic::XGraphic > const &graphic)
Definition: cfg.hxx:306
virtual void MoveEntry(bool bMoveUp)
Definition: cfg.cxx:1628
void connect_model_changed(const Link< TreeView &, void > &rLink)
void InsertEntryIntoUI(SvxConfigEntry *pNewEntryData, int nPos, int nStartCol)
Definition: cfg.cxx:1525
OUString GetName() const
Definition: dlgname.hxx:39
std::unique_ptr< SvxMenuEntriesListBox > m_xContentsListBox
Definition: cfg.hxx:390
TRISTATE_TRUE
void ReloadTopLevelListBox(SvxConfigEntry const *pSelection=nullptr)
Definition: cfg.cxx:1333
Dialog for editing a name.
Definition: dlgname.hxx:25
static css::uno::Reference< css::graphic::XGraphic > GetGraphic(const css::uno::Reference< css::ui::XImageManager > &xImageManager, const OUString &rCommandURL)
#define HID_SVX_CONFIG_TOOLBAR_CONTENTS
Definition: helpids.h:28
std::vector< SvxConfigEntry * > SvxEntries
Definition: cfg.hxx:59
std::unique_ptr< weld::ComboBox > m_xTopLevelListBox
Definition: cfg.hxx:387
const OUString & GetCommand() const
Definition: cfg.hxx:273
void DeleteSelectedContent() override
#define HID_SVX_CONFIG_RENAME_TOOLBAR
Definition: helpids.h:35
void connect_changed(const Link< TreeView &, void > &rLink)
RET_YES
virtual void show()=0
bool IsBinding() const
Definition: cfg.hxx:284
std::unique_ptr< weld::TreeView > m_xControl
Definition: cfg.hxx:319
static void RemoveEntry(SvxEntries *pEntries, SvxConfigEntry const *pChildEntry)
virtual void set_column_fixed_widths(const std::vector< int > &rWidths)=0
void SetName(const OUString &rStr)
Definition: cfg.hxx:276
void SetMain()
Definition: cfg.hxx:290
virtual void set_help_id(const OString &rName)=0
virtual void set_vexpand(bool bExpand)=0
virtual void dispose() override
SaveInData * CreateSaveInData(const css::uno::Reference< css::ui::XUIConfigurationManager > &, const css::uno::Reference< css::ui::XUIConfigurationManager > &, const OUString &aModuleId, bool docConfig) override
static OUString generateCustomName(const OUString &prefix, SvxEntries *entries, sal_Int32 suffix=1)
static OUString replaceSaveInName(const OUString &rMessage, const OUString &rSaveInName)
virtual void SelectElement() override
bool IsDeletable()
Definition: cfg.cxx:1881
VclPtr< SvxConfigPage > pPage
Definition: cfg.hxx:321
IMPL_LINK(SvxToolbarConfigPage, MoveHdl, weld::Button &, rButton, void)
#define TOOLS_WARN_EXCEPTION(area, stream)
void SetSystemStyle(const OUString &rResourceURL, sal_Int32 nStyle)
Definition: cfg.cxx:2001
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
weld::Window * GetDialogFrameWeld() const
const css::uno::Reference< css::graphic::XGraphic > & GetBackupGraphic()
Definition: cfg.hxx:309
std::unique_ptr< weld::Builder > m_xBuilder
void SetUserDefined(bool bOn=true)
Definition: cfg.hxx:281
#define HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM
Definition: helpids.h:36
#define HID_SVX_TOPLEVELLISTBOX
Definition: helpids.h:40
int i
TRISTATE_FALSE
std::unique_ptr< weld::ComboBox > m_xSaveInListBox
Definition: cfg.hxx:574
void SetVisible(bool b)
Definition: cfg.hxx:303
void SetStyle(sal_Int32 style)
Definition: cfg.hxx:313
virtual void set_hexpand(bool bExpand)=0
static const char ITEM_TOOLBAR_URL[]
Definition: cfg.hxx:52
void set_help_id(const OString &rHelpId)
SfxItemPool * GetPool() const
#define HID_SVX_CONFIG_TOOLBAR
Definition: helpids.h:27
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
std::unique_ptr< weld::MenuButton > m_xInsertBtn
Definition: cfg.hxx:397
OUString GetName()
Definition: cfg.hxx:579
bool IsRenamable()
Definition: cfg.cxx:1886
int get_checkbox_column_width() const
sal_Int32 GetStyle() const
Definition: cfg.hxx:312
void RestoreToolbar(SvxConfigEntry *pToolbar)
Definition: cfg.cxx:2480
void UpdateButtonStates() override
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
void SetModified(bool bValue=true)
Definition: cfg.hxx:123
int AddFunction(int nTarget, bool bAllowDuplicates)
Definition: cfg.cxx:1408
RET_OK
virtual short run()
Reference< XComponentContext > getProcessComponentContext()
void CreateToolbar(SvxConfigEntry *pToolbar)
Definition: cfg.cxx:2430
#define HID_SVX_SAVE_IN
Definition: helpids.h:39
virtual ~SvxToolbarEntriesListBox() override
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
std::unique_ptr< weld::ComboBox > m_xSaveInListBox
Definition: cfg.hxx:395
void ApplyToolbar(css::uno::Reference< css::container::XIndexContainer > const &rNewToolbarBar, css::uno::Reference< css::lang::XSingleComponentFactory > &rFactory, SvxConfigEntry const *pToolbar)
def text(shape, st)
std::unique_ptr< weld::TextView > m_xDescriptionField
Definition: cfg.hxx:378
std::unique_ptr< weld::Button > m_xMoveDownButton
Definition: cfg.hxx:393
#define SAL_WARN(area, stream)
#define HID_SVX_DOWN_TOOLBAR_ITEM
Definition: helpids.h:38
css::uno::Reference< css::graphic::XGraphic > GetSelectedIcon()
Definition: cfg.cxx:2800
void DeleteSelectedTopLevel() override
bool IsSeparator() const
Definition: cfg.hxx:285
virtual void dispose() override
std::unique_ptr< weld::Button > m_xMoveUpButton
Definition: cfg.hxx:392
def label(st)
#define HID_SVX_DESCFIELD
Definition: helpids.h:41
std::unique_ptr< weld::MenuButton > m_xGearBtn
Definition: cfg.hxx:389
virtual void set_size_request(int nWidth, int nHeight)=0
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
sal_Int32 nPos
void MoveEntry(bool bMoveUp) override
SvxToolbarEntriesListBox(std::unique_ptr< weld::TreeView > xControl, SvxToolbarConfigPage *pPg)
SaveInData * GetSaveInData()
Definition: cfg.hxx:452
IMPL_LINK_NOARG(SvxToolbarConfigPage, ListModifiedHdl, weld::TreeView &, void)
#define HID_SVX_UP_TOOLBAR_ITEM
Definition: helpids.h:37
std::unique_ptr< weld::Button > m_xAddCommandButton
Definition: cfg.hxx:403
std::unique_ptr< weld::Container > m_xContainer
OUString sId