18 #include <kedittoolbar.h>
25 #include <tqcombobox.h>
26 #include <tqdragobject.h>
27 #include <tqtoolbutton.h>
29 #include <tqvaluelist.h>
30 #include <tqapplication.h>
31 #include <tqtextstream.h>
33 #include <tdeaction.h>
34 #include <kstandarddirs.h>
36 #include <kicontheme.h>
37 #include <kiconloader.h>
38 #include <kinstance.h>
39 #include <tdemessagebox.h>
40 #include <kxmlguifactory.h>
41 #include <kseparator.h>
42 #include <tdeconfig.h>
43 #include <tdelistview.h>
45 #include <kpushbutton.h>
48 static const char *
const lineseparatorstring =
I18N_NOOP(
"--- line separator ---");
49 static const char *
const separatorstring =
I18N_NOOP(
"--- separator ---");
51 #define LINESEPARATORSTRING i18n(lineseparatorstring)
52 #define SEPARATORSTRING i18n(separatorstring)
54 static void dump_xml(
const TQDomDocument& doc)
57 TQTextStream ts(&str, IO_WriteOnly);
62 typedef TQValueList<TQDomElement> ToolbarList;
64 namespace KEditToolbarInternal
69 enum XmlType { Shell = 0, Part, Local, Merged };
73 m_actionCollection = 0;
77 TQDomDocument m_document;
82 ToolbarList m_barList;
85 typedef TQValueList<XmlData> XmlDataList;
87 class ToolbarItem :
public TQListViewItem
90 ToolbarItem(
TDEListView *parent,
const TQString& tag = TQString::null,
const TQString& name = TQString::null,
const TQString& statusText = TQString::null)
91 : TQListViewItem(parent),
94 m_statusText(statusText)
98 ToolbarItem(
TDEListView *parent, TQListViewItem *item,
const TQString &tag = TQString::null,
const TQString& name = TQString::null,
const TQString& statusText = TQString::null)
99 : TQListViewItem(parent, item),
102 m_statusText(statusText)
106 virtual TQString
key(
int column,
bool)
const
108 TQString s = text( column );
109 if ( s == LINESEPARATORSTRING )
111 if ( s == SEPARATORSTRING )
116 void setInternalTag(
const TQString &tag) { m_tag = tag; }
117 void setInternalName(
const TQString &name) { m_name =
name; }
118 void setStatusText(
const TQString &text) { m_statusText = text; }
119 TQString internalTag()
const {
return m_tag; }
120 TQString internalName()
const {
return m_name; }
121 TQString statusText()
const {
return m_statusText; }
125 TQString m_statusText;
128 #define TOOLBARITEMMIMETYPE "data/x-kde.toolbar.item"
129 class ToolbarItemDrag :
public TQStoredDrag
132 ToolbarItemDrag(ToolbarItem *toolbarItem,
133 TQWidget *dragSource = 0,
const char *name = 0)
134 : TQStoredDrag( TOOLBARITEMMIMETYPE, dragSource,
name )
138 TQDataStream out(data, IO_WriteOnly);
139 out << toolbarItem->internalTag();
140 out << toolbarItem->internalName();
141 out << toolbarItem->statusText();
142 out << toolbarItem->text(1);
143 setEncodedData(data);
147 static bool canDecode(TQMimeSource* e)
149 return e->provides(TOOLBARITEMMIMETYPE);
152 static bool decode(
const TQMimeSource* e, KEditToolbarInternal::ToolbarItem& item )
157 TQByteArray data = e->encodedData(TOOLBARITEMMIMETYPE);
158 if ( data.isEmpty() )
161 TQString internalTag, internalName, statusText, text;
162 TQDataStream in(data, IO_ReadOnly);
168 item.setInternalTag( internalTag );
169 item.setInternalName( internalName );
170 item.setStatusText( statusText );
171 item.setText(1, text);
180 ToolbarListView(TQWidget *parent=0,
const char *name=0)
185 virtual TQDragObject *dragObject()
187 KEditToolbarInternal::ToolbarItem *item =
dynamic_cast<KEditToolbarInternal::ToolbarItem*
>(selectedItem());
189 KEditToolbarInternal::ToolbarItemDrag *obj =
new KEditToolbarInternal::ToolbarItemDrag(item,
190 this,
"ToolbarAction drag item");
191 const TQPixmap *pm = item->pixmap(0);
193 obj->setPixmap( *pm );
199 virtual bool acceptDrag(TQDropEvent *event)
const
201 return KEditToolbarInternal::ToolbarItemDrag::canDecode( event );
206 class KEditToolbarWidgetPrivate
217 : m_collection( collection )
222 m_kdialogProcess = 0;
224 ~KEditToolbarWidgetPrivate()
228 TQString xmlFile(
const TQString& xml_file)
230 return xml_file.isNull() ? TQString(m_instance->instanceName()) +
"ui.rc" :
237 TQString loadXMLFile(
const TQString& _xml_file)
240 TQString xml_file = xmlFile(_xml_file);
243 if ( !TQDir::isRelativePath(xml_file) )
244 raw_xml = KXMLGUIFactory::readConfigFile(xml_file);
246 raw_xml = KXMLGUIFactory::readConfigFile(xml_file, m_instance);
254 ToolbarList findToolbars(TQDomNode n)
260 for( ; !n.isNull(); n = n.nextSibling() )
262 TQDomElement elem = n.toElement();
266 if (elem.tagName() == tagToolbar && elem.attribute( attrNoEdit ) !=
"true" )
269 list += findToolbars(elem.firstChild());
278 TQString toolbarName(
const KEditToolbarInternal::XmlData& xmlData,
const TQDomElement& it )
const
285 TQCString txt( it.namedItem( tagText ).toElement().text().utf8() );
287 txt = it.namedItem( tagText2 ).toElement().text().utf8();
289 name = it.attribute( attrName );
295 if ( ( xmlData.m_type == KEditToolbarInternal::XmlData::Shell ) ||
296 ( xmlData.m_type == KEditToolbarInternal::XmlData::Part ) )
298 TQString doc_name(xmlData.m_document.documentElement().attribute( attrName ));
299 name +=
" <" + doc_name +
">";
306 TQDomElement findElementForToolbarItem(
const KEditToolbarInternal::ToolbarItem* item )
const
309 for(TQDomNode n = m_currentToolbarElem.firstChild(); !n.isNull(); n = n.nextSibling())
311 TQDomElement elem = n.toElement();
312 if ((elem.attribute(attrName) == item->internalName()) &&
313 (elem.tagName() == item->internalTag()))
316 return TQDomElement();
322 static const char* s_XmlTypeToString[] = {
"Shell",
"Part",
"Local",
"Merged" };
323 KEditToolbarInternal::XmlDataList::Iterator xit = m_xmlFiles.begin();
324 for ( ; xit != m_xmlFiles.end(); ++xit )
326 kdDebug(240) <<
"KEditToolbarInternal::XmlData type " << s_XmlTypeToString[(*xit).m_type] <<
" xmlFile: " << (*xit).m_xmlFile <<
endl;
327 for( TQValueList<TQDomElement>::Iterator it = (*xit).m_barList.begin();
328 it != (*xit).m_barList.end(); ++it ) {
329 kdDebug(240) <<
" Toolbar: " << toolbarName( *xit, *it ) <<
endl;
331 if ( (*xit).m_actionCollection )
332 kdDebug(240) <<
" " << (*xit).m_actionCollection->count() <<
" actions in the collection." <<
endl;
343 KEditToolbarInternal::XmlData* m_currentXmlData;
344 TQDomElement m_currentToolbarElem;
347 TQString m_globalFile;
349 TQDomDocument m_localDoc;
352 ToolbarList m_barList;
354 KEditToolbarInternal::XmlDataList m_xmlFiles;
356 TQLabel *m_comboLabel;
358 TQLabel * m_helpArea;
364 class KEditToolbarPrivate {
375 const char *KEditToolbar::s_defaultToolbar = 0L;
378 bool global, TQWidget* parent,
const char* name)
379 :
KDialogBase(Swallow, i18n(
"Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
380 m_widget(new
KEditToolbarWidget(TQString::fromLatin1(s_defaultToolbar), collection, file, global, this))
383 d->m_global = global;
384 d->m_collection = collection;
389 const TQString& file,
bool global,
390 TQWidget* parent,
const char* name)
391 :
KDialogBase(Swallow, i18n(
"Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
395 d->m_global = global;
396 d->m_collection = collection;
401 :
KDialogBase(Swallow, i18n(
"Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
402 m_widget(new
KEditToolbarWidget(TQString::fromLatin1(s_defaultToolbar), factory, this))
405 d->m_factory = factory;
409 TQWidget* parent,
const char* name)
410 :
KDialogBase(Swallow, i18n(
"Configure Toolbars"), Default|Ok|Apply|Cancel, Ok, parent, name),
414 d->m_factory = factory;
417 void KEditToolbar::init()
419 d =
new KEditToolbarPrivate();
425 connect(m_widget, TQ_SIGNAL(enableOk(
bool)), TQ_SLOT(
acceptOK(
bool)));
429 setMinimumSize(sizeHint());
430 s_defaultToolbar = 0L;
446 if (
KMessageBox::warningContinueCancel(
this, i18n(
"Do you really want to reset all toolbars of this application to their default? The changes will be applied immediately."), i18n(
"Reset Toolbars"),i18n(
"Reset"))!=KMessageBox::Continue )
454 const TQString localPrefix =
locateLocal(
"data",
"");
455 TQPtrList<KXMLGUIClient> clients(d->m_factory->clients());
456 TQPtrListIterator<KXMLGUIClient> it( clients );
458 for( ; it.current(); ++it)
461 TQString file = client->
xmlFile();
466 if (TQDir::isRelativePath(file))
473 if (!file.startsWith(localPrefix))
477 if ( TQFile::exists( file ) )
478 if ( !TQFile::remove( file ) )
487 int slash = d->m_file.findRev(
'/')+1;
489 d->m_file = d->m_file.mid(slash);
492 if ( TQFile::exists( xml_file ) )
493 if ( !TQFile::remove( xml_file ) )
496 m_widget =
new KEditToolbarWidget(TQString::null, d->m_collection, d->m_file, d->m_global,
this);
502 connect(m_widget, TQ_SIGNAL(enableOk(
bool)), TQ_SLOT(
acceptOK(
bool)));
516 if (!m_widget->
save())
529 (void)m_widget->
save();
536 s_defaultToolbar = toolbarName;
540 const TQString& file,
541 bool global, TQWidget *parent)
543 d(new KEditToolbarWidgetPrivate(instance(), collection))
545 initNonKPart(collection, file, global);
549 setMinimumSize(sizeHint());
552 KEditToolbarWidget::KEditToolbarWidget(
const TQString& defaultToolbar,
554 const TQString& file,
bool global,
557 d(new KEditToolbarWidgetPrivate(instance(), collection))
559 initNonKPart(collection, file, global);
561 loadToolbarCombo(defaultToolbar);
563 setMinimumSize(sizeHint());
569 d(new KEditToolbarWidgetPrivate(instance(),
KXMLGUIClient::actionCollection() ))
575 setMinimumSize(sizeHint());
578 KEditToolbarWidget::KEditToolbarWidget(
const TQString& defaultToolbar,
582 d(new KEditToolbarWidgetPrivate(instance(),
KXMLGUIClient::actionCollection() ))
586 loadToolbarCombo(defaultToolbar);
588 setMinimumSize(sizeHint());
597 const TQString& file,
bool global)
604 TQString localXML = d->loadXMLFile(file);
611 KEditToolbarInternal::XmlData local;
612 local.m_xmlFile = d->xmlFile(file);
613 local.m_type = KEditToolbarInternal::XmlData::Local;
614 local.m_document.setContent(localXML);
615 elem = local.m_document.documentElement().toElement();
616 local.m_barList = d->findToolbars(elem);
617 local.m_actionCollection = collection;
618 d->m_xmlFiles.append(local);
621 KEditToolbarInternal::XmlData merge;
622 merge.m_xmlFile = TQString::null;
623 merge.m_type = KEditToolbarInternal::XmlData::Merged;
625 elem = merge.m_document.documentElement().toElement();
626 merge.m_barList = d->findToolbars(elem);
627 merge.m_actionCollection = collection;
628 d->m_xmlFiles.append(merge);
648 TQPtrListIterator<KXMLGUIClient> it( clients );
649 for( ; it.current(); ++it)
653 if (client->
xmlFile().isNull())
656 KEditToolbarInternal::XmlData data;
657 data.m_xmlFile = client->localXMLFile();
659 data.m_type = KEditToolbarInternal::XmlData::Shell;
661 data.m_type = KEditToolbarInternal::XmlData::Part;
662 data.m_document.setContent( KXMLGUIFactory::readConfigFile( client->
xmlFile(), client->
instance() ) );
663 elem = data.m_document.documentElement().toElement();
664 data.m_barList = d->findToolbars(elem);
666 d->m_xmlFiles.append(data);
682 KEditToolbarInternal::XmlDataList::Iterator it = d->m_xmlFiles.begin();
683 for ( ; it != d->m_xmlFiles.end(); ++it)
686 if ( !((*it).m_isModified) )
690 if ( (*it).m_type == KEditToolbarInternal::XmlData::Merged )
693 dump_xml((*it).m_document);
695 kdDebug(240) <<
"Saving " << (*it).m_xmlFile <<
endl;
697 KXMLGUIFactory::saveConfigFile((*it).m_document, (*it).m_xmlFile);
713 TQPtrList<KXMLGUIClient> clients(
factory()->clients());
722 client = clients.prev();
729 TQPtrListIterator<KXMLGUIClient> cit( clients );
730 for( ; cit.current(); ++cit)
734 TQString file( client->
xmlFile() );
735 if ( !file.isEmpty() )
741 if ( client == firstClient )
745 client->
setXMLFile( file, client == firstClient );
753 for( ; cit.current(); ++cit)
757 void KEditToolbarWidget::setupLayout()
760 d->m_comboLabel =
new TQLabel(i18n(
"&Toolbar:"),
this);
761 m_toolbarCombo =
new TQComboBox(
this);
762 m_toolbarCombo->setEnabled(
false);
763 d->m_comboLabel->setBuddy(m_toolbarCombo);
765 connect(m_toolbarCombo, TQ_SIGNAL(activated(
const TQString&)),
766 this, TQ_SLOT(slotToolbarSelected(
const TQString&)));
776 TQLabel *inactive_label =
new TQLabel(i18n(
"A&vailable actions:"),
this);
777 m_inactiveList =
new KEditToolbarInternal::ToolbarListView(
this);
778 m_inactiveList->setDragEnabled(
true);
779 m_inactiveList->setAcceptDrops(
true);
780 m_inactiveList->setDropVisualizer(
false);
781 m_inactiveList->setAllColumnsShowFocus(
true);
782 m_inactiveList->setMinimumSize(180, 250);
783 m_inactiveList->header()->hide();
784 m_inactiveList->addColumn(
"");
785 int column2 = m_inactiveList->addColumn(
"");
786 m_inactiveList->setSorting( column2 );
787 inactive_label->setBuddy(m_inactiveList);
788 connect(m_inactiveList, TQ_SIGNAL(selectionChanged(TQListViewItem *)),
789 this, TQ_SLOT(slotInactiveSelected(TQListViewItem *)));
790 connect(m_inactiveList, TQ_SIGNAL( doubleClicked( TQListViewItem *,
const TQPoint &,
int )),
791 this, TQ_SLOT(slotInsertButton()));
794 TQLabel *active_label =
new TQLabel(i18n(
"Curr&ent actions:"),
this);
795 m_activeList =
new KEditToolbarInternal::ToolbarListView(
this);
796 m_activeList->setDragEnabled(
true);
797 m_activeList->setAcceptDrops(
true);
798 m_activeList->setDropVisualizer(
true);
799 m_activeList->setAllColumnsShowFocus(
true);
800 m_activeList->setMinimumWidth(m_inactiveList->minimumWidth());
801 m_activeList->header()->hide();
802 m_activeList->addColumn(
"");
803 m_activeList->addColumn(
"");
804 m_activeList->setSorting(-1);
805 active_label->setBuddy(m_activeList);
807 connect(m_inactiveList, TQ_SIGNAL(dropped(
TDEListView*,TQDropEvent*,TQListViewItem*)),
808 this, TQ_SLOT(slotDropped(
TDEListView*,TQDropEvent*,TQListViewItem*)));
809 connect(m_activeList, TQ_SIGNAL(dropped(
TDEListView*,TQDropEvent*,TQListViewItem*)),
810 this, TQ_SLOT(slotDropped(
TDEListView*,TQDropEvent*,TQListViewItem*)));
811 connect(m_activeList, TQ_SIGNAL(selectionChanged(TQListViewItem *)),
812 this, TQ_SLOT(slotActiveSelected(TQListViewItem *)));
813 connect(m_activeList, TQ_SIGNAL( doubleClicked( TQListViewItem *,
const TQPoint &,
int )),
814 this, TQ_SLOT(slotRemoveButton()));
817 d->m_changeIcon =
new KPushButton( i18n(
"Change &Icon..." ),
this );
819 d->m_hasKDialog = !kdialogExe.isEmpty();
820 d->m_changeIcon->setEnabled( d->m_hasKDialog );
822 connect( d->m_changeIcon, TQ_SIGNAL( clicked() ),
823 this, TQ_SLOT( slotChangeIcon() ) );
828 m_upAction =
new TQToolButton(
this);
829 iconSet = SmallIconSet(
"go-up" );
830 m_upAction->setIconSet( iconSet );
831 m_upAction->setEnabled(
false);
832 m_upAction->setAutoRepeat(
true);
833 connect(m_upAction, TQ_SIGNAL(clicked()), TQ_SLOT(slotUpButton()));
835 m_insertAction =
new TQToolButton(
this);
836 iconSet = TQApplication::reverseLayout() ? SmallIconSet(
"back" ) : SmallIconSet(
"forward" );
837 m_insertAction->setIconSet( iconSet );
838 m_insertAction->setEnabled(
false);
839 connect(m_insertAction, TQ_SIGNAL(clicked()), TQ_SLOT(slotInsertButton()));
841 m_removeAction =
new TQToolButton(
this);
842 iconSet = TQApplication::reverseLayout() ? SmallIconSet(
"forward" ) : SmallIconSet(
"back" );
843 m_removeAction->setIconSet( iconSet );
844 m_removeAction->setEnabled(
false);
845 connect(m_removeAction, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveButton()));
847 m_downAction =
new TQToolButton(
this);
848 iconSet = SmallIconSet(
"go-down" );
849 m_downAction->setIconSet( iconSet );
850 m_downAction->setEnabled(
false);
851 m_downAction->setAutoRepeat(
true);
852 connect(m_downAction, TQ_SIGNAL(clicked()), TQ_SLOT(slotDownButton()));
854 d->m_helpArea =
new TQLabel(
this);
855 d->m_helpArea->setAlignment( TQt::WordBreak );
867 TQGridLayout *button_layout =
new TQGridLayout(5, 3, 0);
869 name_layout->addWidget(d->m_comboLabel);
870 name_layout->addWidget(m_toolbarCombo);
874 button_layout->setRowStretch( 0, 10 );
875 button_layout->addWidget(m_upAction, 1, 1);
876 button_layout->addWidget(m_removeAction, 2, 0);
877 button_layout->addWidget(m_insertAction, 2, 2);
878 button_layout->addWidget(m_downAction, 3, 1);
879 button_layout->setRowStretch( 4, 10 );
881 inactive_layout->addWidget(inactive_label);
882 inactive_layout->addWidget(m_inactiveList, 1);
884 active_layout->addWidget(active_label);
885 active_layout->addWidget(m_activeList, 1);
886 active_layout->addLayout(changeIcon_layout);
888 changeIcon_layout->addStretch( 1 );
889 changeIcon_layout->addWidget( d->m_changeIcon );
890 changeIcon_layout->addStretch( 1 );
892 list_layout->addLayout(inactive_layout);
893 list_layout->addLayout(button_layout);
894 list_layout->addLayout(active_layout);
896 top_layout->addLayout(name_layout);
897 top_layout->addWidget(d->m_comboSeparator);
898 top_layout->addLayout(list_layout,10);
899 top_layout->addWidget(d->m_helpArea);
903 void KEditToolbarWidget::loadToolbarCombo(
const TQString& defaultToolbar)
907 m_toolbarCombo->clear();
909 int defaultToolbarId = -1;
912 KEditToolbarInternal::XmlDataList::Iterator xit = d->m_xmlFiles.begin();
913 for ( ; xit != d->m_xmlFiles.end(); ++xit)
916 if ( (*xit).m_type == KEditToolbarInternal::XmlData::Local )
920 ToolbarList::Iterator it = (*xit).m_barList.begin();
921 for ( ; it != (*xit).m_barList.end(); ++it)
923 TQString
name = d->toolbarName( *xit, *it );
924 m_toolbarCombo->setEnabled(
true );
925 m_toolbarCombo->insertItem( name );
926 if (defaultToolbarId == -1 && (name == defaultToolbar || defaultToolbar == (*it).attribute( attrName )))
927 defaultToolbarId = count;
931 bool showCombo = (count > 1);
932 d->m_comboLabel->setShown(showCombo);
933 d->m_comboSeparator->setShown(showCombo);
934 m_toolbarCombo->setShown(showCombo);
935 if (defaultToolbarId == -1)
936 defaultToolbarId = 0;
938 m_toolbarCombo->setCurrentItem(defaultToolbarId);
939 slotToolbarSelected(m_toolbarCombo->currentText());
942 void KEditToolbarWidget::loadActionList(TQDomElement& elem)
951 TQString sep_name(
"separator_%1");
954 m_inactiveList->clear();
955 m_activeList->clear();
956 m_insertAction->setEnabled(
false);
957 m_removeAction->setEnabled(
false);
958 m_upAction->setEnabled(
false);
959 m_downAction->setEnabled(
false);
965 TQMap<TQString, bool> active_list;
969 TQDomNode n = elem.lastChild();
970 for( ; !n.isNull(); n = n.previousSibling() )
972 TQDomElement it = n.toElement();
973 if (it.isNull())
continue;
974 if (it.tagName() == tagSeparator)
976 KEditToolbarInternal::ToolbarItem *act =
new KEditToolbarInternal::ToolbarItem(m_activeList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
977 bool isLineSep = ( it.attribute(attrLineSeparator,
"true").lower() == TQString::fromLatin1(
"true") );
979 act->setText(1, LINESEPARATORSTRING);
981 act->setText(1, SEPARATORSTRING);
982 it.setAttribute( attrName, act->internalName() );
986 if (it.tagName() == tagMerge)
989 TQString
name = it.attribute( attrName );
990 KEditToolbarInternal::ToolbarItem *act =
new KEditToolbarInternal::ToolbarItem(m_activeList, tagMerge, name, i18n(
"This element will be replaced with all the elements of an embedded component."));
991 if (
name.isEmpty() )
992 act->setText(1, i18n(
"<Merge>"));
994 act->setText(1, i18n(
"<Merge %1>").arg(name));
998 if (it.tagName() == tagActionList)
1000 KEditToolbarInternal::ToolbarItem *act =
new KEditToolbarInternal::ToolbarItem(m_activeList, tagActionList, it.attribute(attrName), i18n(
"This is a dynamic list of actions. You can move it, but if you remove it you won't be able to re-add it.") );
1001 act->setText(1, i18n(
"ActionList: %1").arg(it.attribute(attrName)));
1013 if (it.attribute( attrName ) ==
action->name())
1016 KEditToolbarInternal::ToolbarItem *act =
new KEditToolbarInternal::ToolbarItem(m_activeList, it.tagName(),
action->name(),
action->
toolTip());
1017 act->setText(1,
action->plainText());
1019 if (!
action->icon().isEmpty()) {
1027 active_list.insert(
action->name(),
true);
1039 if (active_list.contains(
action->name())) {
1043 KEditToolbarInternal::ToolbarItem *act =
new KEditToolbarInternal::ToolbarItem(m_inactiveList, tagActionList,
action->name(),
action->
toolTip());
1044 act->setText(1,
action->plainText());
1046 if (!
action->icon().isEmpty()) {
1056 KEditToolbarInternal::ToolbarItem *act =
new KEditToolbarInternal::ToolbarItem(m_inactiveList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
1057 act->setText(1, LINESEPARATORSTRING);
1058 act =
new KEditToolbarInternal::ToolbarItem(m_inactiveList, tagSeparator, sep_name.arg(sep_num++), TQString::null);
1059 act->setText(1, SEPARATORSTRING);
1064 return d->m_collection;
1067 void KEditToolbarWidget::slotToolbarSelected(
const TQString& _text)
1070 KEditToolbarInternal::XmlDataList::Iterator xit = d->m_xmlFiles.begin();
1071 for ( ; xit != d->m_xmlFiles.end(); ++xit)
1074 ToolbarList::Iterator it = (*xit).m_barList.begin();
1075 for ( ; it != (*xit).m_barList.end(); ++it)
1077 TQString name = d->toolbarName( *xit, *it );
1079 if ( name == _text )
1082 d->m_currentXmlData = & (*xit);
1083 d->m_currentToolbarElem = (*it);
1086 loadActionList(d->m_currentToolbarElem);
1088 if ((*xit).m_type == KEditToolbarInternal::XmlData::Part || (*xit).m_type == KEditToolbarInternal::XmlData::Shell)
1096 void KEditToolbarWidget::slotInactiveSelected(TQListViewItem *item)
1098 KEditToolbarInternal::ToolbarItem* toolitem =
static_cast<KEditToolbarInternal::ToolbarItem *
>(item);
1101 m_insertAction->setEnabled(
true);
1102 TQString statusText = toolitem->statusText();
1103 d->m_helpArea->setText( statusText );
1107 m_insertAction->setEnabled(
false);
1108 d->m_helpArea->setText( TQString::null );
1112 void KEditToolbarWidget::slotActiveSelected(TQListViewItem *item)
1114 KEditToolbarInternal::ToolbarItem* toolitem =
static_cast<KEditToolbarInternal::ToolbarItem *
>(item);
1115 m_removeAction->setEnabled( item );
1118 d->m_changeIcon->setEnabled( item &&
1120 toolitem->internalTag() == tagAction );
1124 if (item->itemAbove())
1125 m_upAction->setEnabled(
true);
1127 m_upAction->setEnabled(
false);
1129 if (item->itemBelow())
1130 m_downAction->setEnabled(
true);
1132 m_downAction->setEnabled(
false);
1133 TQString statusText = toolitem->statusText();
1134 d->m_helpArea->setText( statusText );
1138 m_upAction->setEnabled(
false);
1139 m_downAction->setEnabled(
false);
1140 d->m_helpArea->setText( TQString::null );
1144 void KEditToolbarWidget::slotDropped(
TDEListView *list, TQDropEvent *e, TQListViewItem *after)
1146 KEditToolbarInternal::ToolbarItem *item =
new KEditToolbarInternal::ToolbarItem(m_inactiveList);
1147 if(!KEditToolbarInternal::ToolbarItemDrag::decode(e, *item)) {
1152 if (list == m_activeList) {
1153 if (e->source() == m_activeList) {
1155 moveActive(item, after);
1158 insertActive(item, after,
true);
1159 }
else if (list == m_inactiveList) {
1164 delete item; item = 0;
1169 slotToolbarSelected( m_toolbarCombo->currentText() );
1172 void KEditToolbarWidget::slotInsertButton()
1174 KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_inactiveList->currentItem();
1175 insertActive(item, m_activeList->currentItem(),
false);
1182 slotToolbarSelected( m_toolbarCombo->currentText() );
1185 void KEditToolbarWidget::slotRemoveButton()
1187 removeActive(
dynamic_cast<KEditToolbarInternal::ToolbarItem*
>(m_activeList->currentItem()) );
1192 slotToolbarSelected( m_toolbarCombo->currentText() );
1195 void KEditToolbarWidget::insertActive(KEditToolbarInternal::ToolbarItem *item, TQListViewItem *before,
bool prepend)
1206 TQDomElement new_item;
1208 if (item->text(1) == LINESEPARATORSTRING) {
1209 new_item =
domDocument().createElement(tagSeparator);
1210 }
else if (item->text(1) == SEPARATORSTRING) {
1211 new_item =
domDocument().createElement(tagSeparator);
1212 new_item.setAttribute(attrLineSeparator,
"false");
1214 new_item =
domDocument().createElement(tagAction);
1215 new_item.setAttribute(attrName, item->internalName());
1221 KEditToolbarInternal::ToolbarItem *act_item = (KEditToolbarInternal::ToolbarItem*)before;
1222 TQDomElement elem = d->findElementForToolbarItem( act_item );
1223 Q_ASSERT( !elem.isNull() );
1224 d->m_currentToolbarElem.insertAfter(new_item, elem);
1230 d->m_currentToolbarElem.insertBefore(new_item, d->m_currentToolbarElem.firstChild());
1232 d->m_currentToolbarElem.appendChild(new_item);
1236 d->m_currentToolbarElem.setAttribute( attrNoMerge,
"1");
1239 updateLocal(d->m_currentToolbarElem);
1242 void KEditToolbarWidget::removeActive(KEditToolbarInternal::ToolbarItem *item)
1253 TQDomElement elem = d->findElementForToolbarItem( item );
1254 if ( !elem.isNull() )
1257 d->m_currentToolbarElem.removeChild(elem);
1260 d->m_currentToolbarElem.setAttribute( attrNoMerge,
"1");
1263 updateLocal(d->m_currentToolbarElem);
1267 void KEditToolbarWidget::slotUpButton()
1269 KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_activeList->currentItem();
1272 if (!item->itemAbove())
1278 moveActive( item, item->itemAbove()->itemAbove() );
1282 void KEditToolbarWidget::moveActive( KEditToolbarInternal::ToolbarItem* item, TQListViewItem* before )
1284 TQDomElement e = d->findElementForToolbarItem( item );
1290 KEditToolbarInternal::ToolbarItem *clone =
new KEditToolbarInternal::ToolbarItem(m_activeList,
1292 item->internalTag(),
1293 item->internalName(),
1294 item->statusText());
1296 clone->setText(1, item->text(1));
1299 if( item->pixmap(0) )
1300 clone->setPixmap(0, *item->pixmap(0));
1303 m_activeList->setSelected(clone,
true);
1306 m_activeList->ensureItemVisible(clone);
1310 d->m_currentToolbarElem.insertBefore(e, d->m_currentToolbarElem.firstChild() );
1312 d->m_currentToolbarElem.insertAfter(e, d->findElementForToolbarItem( (KEditToolbarInternal::ToolbarItem*)before ));
1316 d->m_currentToolbarElem.setAttribute( attrNoMerge,
"1");
1319 updateLocal(d->m_currentToolbarElem);
1322 void KEditToolbarWidget::slotDownButton()
1324 KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_activeList->currentItem();
1327 if (!item->itemBelow())
1333 moveActive( item, item->itemBelow() );
1337 void KEditToolbarWidget::updateLocal(TQDomElement& elem)
1341 KEditToolbarInternal::XmlDataList::Iterator xit = d->m_xmlFiles.begin();
1342 for ( ; xit != d->m_xmlFiles.end(); ++xit)
1344 if ( (*xit).m_type == KEditToolbarInternal::XmlData::Merged )
1347 if ( (*xit).m_type == KEditToolbarInternal::XmlData::Shell ||
1348 (*xit).m_type == KEditToolbarInternal::XmlData::Part )
1350 if ( d->m_currentXmlData->m_xmlFile == (*xit).m_xmlFile )
1352 (*xit).m_isModified =
true;
1359 (*xit).m_isModified =
true;
1361 ToolbarList::Iterator it = (*xit).m_barList.begin();
1362 for ( ; it != (*xit).m_barList.end(); ++it)
1364 TQString
name( (*it).attribute( attrName ) );
1365 TQString tag( (*it).tagName() );
1366 if ( (tag != elem.tagName()) || (name != elem.attribute(attrName)) )
1369 TQDomElement toolbar = (*xit).m_document.documentElement().toElement();
1370 toolbar.replaceChild(elem, (*it));
1375 TQDomElement toolbar = (*xit).m_document.documentElement().toElement();
1376 toolbar.appendChild(elem);
1380 void KEditToolbarWidget::slotChangeIcon()
1387 if ( d->m_kdialogProcess && d->m_kdialogProcess->isRunning() )
1390 d->m_kdialogProcess =
new KProcIO;
1392 (*d->m_kdialogProcess) << kdialogExe;
1393 (*d->m_kdialogProcess) <<
"--embed";
1394 (*d->m_kdialogProcess) << TQString::number( (ulong)topLevelWidget()->winId() );
1395 (*d->m_kdialogProcess) <<
"--geticon";
1396 (*d->m_kdialogProcess) <<
"Toolbar";
1397 (*d->m_kdialogProcess) <<
"Actions";
1399 kdError(240) <<
"Can't run " << kdialogExe <<
endl;
1400 delete d->m_kdialogProcess;
1401 d->m_kdialogProcess = 0;
1405 m_activeList->setEnabled(
false );
1406 m_toolbarCombo->setEnabled(
false );
1408 connect( d->m_kdialogProcess, TQ_SIGNAL( processExited(
TDEProcess* ) ),
1409 this, TQ_SLOT( slotProcessExited(
TDEProcess* ) ) );
1412 void KEditToolbarWidget::slotProcessExited(
TDEProcess* )
1414 m_activeList->setEnabled(
true );
1415 m_toolbarCombo->setEnabled(
true );
1419 if (!d->m_kdialogProcess) {
1420 kdError(240) <<
"Something is wrong here! m_kdialogProcess is zero!" <<
endl;
1424 if ( !d->m_kdialogProcess->normalExit() ||
1425 d->m_kdialogProcess->exitStatus() ||
1426 d->m_kdialogProcess->readln(icon,
true) <= 0 ) {
1427 delete d->m_kdialogProcess;
1428 d->m_kdialogProcess = 0;
1432 KEditToolbarInternal::ToolbarItem *item = (KEditToolbarInternal::ToolbarItem*)m_activeList->currentItem();
1434 item->setPixmap(0, BarIcon(icon, 16));
1436 Q_ASSERT( d->m_currentXmlData->m_type != KEditToolbarInternal::XmlData::Merged );
1438 d->m_currentXmlData->m_isModified =
true;
1444 Q_ASSERT( !act_elem.isNull() );
1445 act_elem.setAttribute(
"icon", icon );
1451 delete d->m_kdialogProcess;
1452 d->m_kdialogProcess = 0;
1455 void KEditToolbar::virtual_hook(
int id,
void* data )
1456 { KDialogBase::virtual_hook(
id, data ); }
1458 void KEditToolbarWidget::virtual_hook(
int id,
void* data )
1459 { KXMLGUIClient::virtual_hook(
id, data ); }
1461 #include "kedittoolbar.moc"
A dialog base class with standard buttons and predefined layouts.
void setMainWidget(TQWidget *widget)
Sets the main user definable widget.
void enableButtonApply(bool state)
Enable or disable (gray out) the Apply button.
void enableButtonOK(bool state)
Enable or disable (gray out) the OK button.
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
Display a "warning" dialog.
Standard horizontal or vertical separator.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
virtual TQString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
virtual TDEInstance * instance() const
void setXMLGUIBuildDocument(const TQDomDocument &doc)
virtual void setXMLFile(const TQString &file, bool merge=false, bool setXMLDoc=true)
Sets the name of the rc file containing the XML for the part.
KXMLGUIFactory * factory() const
Retrieves a pointer to the KXMLGUIFactory this client is associated with (will return 0L if the clien...
virtual void setDOMDocument(const TQDomDocument &document, bool merge=false)
Sets the Document for the part, describing the layout of the GUI.
TDEAction * action(const char *name) const
Retrieves an action of the client by name.
virtual void setXML(const TQString &document, bool merge=false)
Sets the XML for the part.
void setFactory(KXMLGUIFactory *factory)
This method is called by the KXMLGUIFactory as soon as the client is added to the KXMLGUIFactory's GU...
virtual TDEActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
virtual TQDomDocument domDocument() const
KXMLGUIFactory, together with KXMLGUIClient objects, can be used to create a GUI of container widgets...
static TQDomElement findActionByName(TQDomElement &elem, const TQString &sName, bool create)
void removeClient(KXMLGUIClient *client)
Removes the GUI described by the client, by unplugging all provided actions and removing all owned co...
void addClient(KXMLGUIClient *client)
Creates the GUI described by the TQDomDocument of the client, using the client's actions,...
TQPtrList< KXMLGUIClient > clients() const
Returns a list of all clients currently added to this factory.
static TQDomElement actionPropertiesElement(TQDomDocument &doc)
A managed set of TDEAction objects.
virtual TDEAction * action(int index) const
Return the TDEAction* at position "index" in the action collection.
virtual void setWidget(TQWidget *widget)
This sets the widget to which the keyboard shortcuts should be attached.
virtual uint count() const
Returns the TDEAccel object associated with widget #.
Class to encapsulate user-driven action or event.
virtual TQIconSet iconSet(TDEIcon::Group group, int size=0) const
Get the TQIconSet from which the icons used to display this action will be chosen.
virtual TQString toolTip() const
Get the tooltip text for the action.
static TDEInstance * instance()
static const TQString & staticQString(const char *str)
TQPixmap loadIcon(const TQString &name, TDEIcon::Group group, int size=0, int state=TDEIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
TQCString instanceName() const
TDEIconLoader * iconLoader() const
This Widget extends the functionality of TQListView to honor the system wide settings for Single Clic...
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdWarning(int area=0)
kdbgstream kdError(int area=0)
kdbgstream kdDebug(int area=0)
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
TQString locateLocal(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
TQString name(StdAccel id)