1 #include <editorchooser.h>
2 #include <editorchooser.moc>
4 #include <tqcombobox.h>
7 #include <tqstringlist.h>
11 #include <tdeapplication.h>
14 #include "editorchooser_ui.h"
20 class PrivateEditorChooser
23 PrivateEditorChooser()
26 ~PrivateEditorChooser(){}
28 EditorChooser_UI *chooser;
29 TQStringList ElementNames;
30 TQStringList elements;
35 EditorChooser::EditorChooser(TQWidget *parent,
const char *name) :
36 TQWidget (parent,name)
38 d =
new PrivateEditorChooser ();
41 TQGridLayout *grid =
new TQGridLayout(
this, 1, 1 );
44 d->chooser =
new EditorChooser_UI (
this, name);
46 grid->addWidget( d->chooser, 0, 0);
49 TDETrader::OfferList offers = TDETrader::self()->query(
"text/plain",
"'KTextEditor/Document' in ServiceTypes");
50 TDEConfig *config=
new TDEConfig(
"default_components");
51 config->setGroup(
"KTextEditor");
52 TQString editor = config->readPathEntry(
"embeddedEditor");
54 if (editor.isEmpty()) editor=
"katepart";
56 for (TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
58 if ((*it)->desktopEntryName().contains(editor))
60 d->chooser->editorCombo->insertItem(TQString(i18n(
"System Default (%1)").arg((*it)->name())));
65 for (TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
67 d->chooser->editorCombo->insertItem((*it)->name());
68 d->elements.append((*it)->desktopEntryName());
70 d->chooser->editorCombo->setCurrentItem(0);
73 EditorChooser:: ~EditorChooser(){
77 void EditorChooser::readAppSetting(
const TQString& postfix){
78 TDEConfig *cfg=kapp->config();
79 TQString previousGroup=cfg->group();
80 cfg->setGroup(
"KTEXTEDITOR:"+postfix);
81 TQString editor=cfg->readPathEntry(
"editor");
82 if (editor.isEmpty()) d->chooser->editorCombo->setCurrentItem(0);
85 int idx=d->elements.findIndex(editor);
87 d->chooser->editorCombo->setCurrentItem(idx);
89 cfg->setGroup(previousGroup);
92 void EditorChooser::writeAppSetting(
const TQString& postfix){
93 TDEConfig *cfg=kapp->config();
94 TQString previousGroup=cfg->group();
95 cfg->setGroup(
"KTEXTEDITOR:"+postfix);
96 cfg->writeEntry(
"DEVELOPER_INFO",
"NEVER TRY TO USE VALUES FROM THAT GROUP, THEY ARE SUBJECT TO CHANGES");
97 cfg->writePathEntry(
"editor", (d->chooser->editorCombo->currentItem()==0) ?
98 TQString::null : (*d->elements.at(d->chooser->editorCombo->currentItem()-1)));
100 cfg->setGroup(previousGroup);
104 KTextEditor::Document *EditorChooser::createDocument(TQObject *parent,
const char* name,
const TQString& postfix,
bool fallBackToKatePart){
108 TDEConfig *cfg=kapp->config();
109 TQString previousGroup=cfg->group();
110 cfg->setGroup(
"KTEXTEDITOR:"+postfix);
111 TQString editor=cfg->readPathEntry(
"editor");
112 cfg->setGroup(previousGroup);
113 if (editor.isEmpty())
115 TDEConfig *config=
new TDEConfig(
"default_components");
116 config->setGroup(
"KTextEditor");
117 editor = config->readPathEntry(
"embeddedEditor",
"katepart");
121 KService::Ptr serv=KService::serviceByDesktopName(editor);
124 tmpDoc=KTextEditor::createDocument(serv->library().latin1(),parent,name);
125 if (tmpDoc)
return tmpDoc;
127 if (fallBackToKatePart)
128 return KTextEditor::createDocument(
"libkatepart",parent,name);
133 KTextEditor::Editor *EditorChooser::createEditor(TQWidget *parentWidget,TQObject *parent,
const char* widgetName,
134 const char* name,
const TQString& postfix,
bool fallBackToKatePart){
138 TDEConfig *cfg=kapp->config();
139 TQString previousGroup=cfg->group();
140 cfg->setGroup(
"KTEXTEDITOR:"+postfix);
141 TQString editor=cfg->readPathEntry(
"editor");
142 cfg->setGroup(previousGroup);
143 if (editor.isEmpty())
145 TDEConfig *config=
new TDEConfig(
"default_components");
146 config->setGroup(
"KTextEditor");
147 editor = config->readPathEntry(
"embeddedEditor",
"katepart");
151 KService::Ptr serv=KService::serviceByDesktopName(editor);
154 tmpEd=KTextEditor::createEditor(serv->library().latin1(),parentWidget,widgetName,parent,name);
155 if (tmpEd)
return tmpEd;
157 if (fallBackToKatePart)
158 return KTextEditor::createEditor(
"libkatepart",parentWidget,widgetName,parent,name);
The main class representing a text document.
This is a simplfied version of the Document & View classes Usage: Load it, merge it's gui + be happy ...
KTextEditor is KDE's standard text editing KPart interface.