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");
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){
79 TQString previousGroup=cfg->
group();
80 cfg->
setGroup(
"KTEXTEDITOR:"+postfix);
82 if (editor.isEmpty()) d->chooser->editorCombo->setCurrentItem(0);
85 int idx=d->elements.findIndex(editor);
87 d->chooser->editorCombo->setCurrentItem(idx);
92 void EditorChooser::writeAppSetting(
const TQString& postfix){
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)));
104 KTextEditor::Document *EditorChooser::createDocument(TQObject *parent,
const char* name,
const TQString& postfix,
bool fallBackToKatePart){
109 TQString previousGroup=cfg->
group();
110 cfg->
setGroup(
"KTEXTEDITOR:"+postfix);
113 if (editor.isEmpty())
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){
139 TQString previousGroup=cfg->
group();
140 cfg->
setGroup(
"KTEXTEDITOR:"+postfix);
143 if (editor.isEmpty())
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 ...
void writePathEntry(const TQString &pKey, const TQString &path, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
void setGroup(const TQString &group)
KTextEditor is KDE's standard text editing KPart interface.
TQString name(StdAccel id)