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