• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • interfaces
 

interfaces

  • interfaces
  • tdetexteditor
editorchooser.cpp
1 #include <editorchooser.h>
2 #include <editorchooser.moc>
3 
4 #include <tqcombobox.h>
5 #include <ktrader.h>
6 #include <tdeconfig.h>
7 #include <tqstringlist.h>
8 #include <kservice.h>
9 #include <tdelocale.h>
10 #include <tqlabel.h>
11 #include <tdeapplication.h>
12 #include <tqlayout.h>
13 
14 #include "editorchooser_ui.h"
15 
16 using namespace KTextEditor;
17 
18 namespace KTextEditor
19 {
20  class PrivateEditorChooser
21  {
22  public:
23  PrivateEditorChooser()
24  {
25  }
26  ~PrivateEditorChooser(){}
27  // Data Members
28  EditorChooser_UI *chooser;
29  TQStringList ElementNames;
30  TQStringList elements;
31  };
32 
33 }
34 
35 EditorChooser::EditorChooser(TQWidget *parent,const char *name) :
36  TQWidget (parent,name)
37  {
38  d = new PrivateEditorChooser ();
39 
40  // sizemanagment
41  TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
42 
43 
44  d->chooser = new EditorChooser_UI (this, name);
45 
46  grid->addWidget( d->chooser, 0, 0);
47 
48 
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");
53 
54  if (editor.isEmpty()) editor="katepart";
55 
56  for (TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
57  {
58  if ((*it)->desktopEntryName().contains(editor))
59  {
60  d->chooser->editorCombo->insertItem(TQString(i18n("System Default (%1)").arg((*it)->name())));
61  break;
62  }
63  }
64 
65  for (TDETrader::OfferList::Iterator it = offers.begin(); it != offers.end(); ++it)
66  {
67  d->chooser->editorCombo->insertItem((*it)->name());
68  d->elements.append((*it)->desktopEntryName());
69  }
70  d->chooser->editorCombo->setCurrentItem(0);
71 }
72 
73 EditorChooser:: ~EditorChooser(){
74  delete d;
75 }
76 
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);
83  else
84  {
85  int idx=d->elements.findIndex(editor);
86  idx=idx+1;
87  d->chooser->editorCombo->setCurrentItem(idx);
88  }
89  cfg->setGroup(previousGroup);
90 }
91 
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)));
99  cfg->sync();
100  cfg->setGroup(previousGroup);
101 
102 }
103 
104 KTextEditor::Document *EditorChooser::createDocument(TQObject *parent,const char* name, const TQString& postfix,bool fallBackToKatePart){
105 
106  KTextEditor::Document *tmpDoc=0;
107 
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())
114  {
115  TDEConfig *config=new TDEConfig("default_components");
116  config->setGroup("KTextEditor");
117  editor = config->readPathEntry("embeddedEditor", "katepart");
118  delete config;
119  }
120 
121  KService::Ptr serv=KService::serviceByDesktopName(editor);
122  if (serv)
123  {
124  tmpDoc=KTextEditor::createDocument(serv->library().latin1(),parent,name);
125  if (tmpDoc) return tmpDoc;
126  }
127  if (fallBackToKatePart)
128  return KTextEditor::createDocument("libkatepart",parent,name);
129 
130  return 0;
131 }
132 
133 KTextEditor::Editor *EditorChooser::createEditor(TQWidget *parentWidget,TQObject *parent,const char* widgetName,
134  const char* name,const TQString& postfix,bool fallBackToKatePart){
135 
136  KTextEditor::Editor *tmpEd=0;
137 
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())
144  {
145  TDEConfig *config=new TDEConfig("default_components");
146  config->setGroup("KTextEditor");
147  editor = config->readPathEntry("embeddedEditor", "katepart");
148  delete config;
149  }
150 
151  KService::Ptr serv=KService::serviceByDesktopName(editor);
152  if (serv)
153  {
154  tmpEd=KTextEditor::createEditor(serv->library().latin1(),parentWidget,widgetName,parent,name);
155  if (tmpEd) return tmpEd;
156  }
157  if (fallBackToKatePart)
158  return KTextEditor::createEditor("libkatepart",parentWidget,widgetName,parent,name);
159 
160  return 0;
161 }
162 
KTextEditor::Document
The main class representing a text document.
Definition: document.h:32
KTextEditor::Editor
This is a simplfied version of the Document & View classes Usage: Load it, merge it's gui + be happy ...
Definition: editor.h:40
TDEConfigBase::writePathEntry
void writePathEntry(const TQString &pKey, const TQString &path, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TDEConfigBase::group
TQString group() const
TDEConfigBase::sync
virtual void sync()
TDEConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TDEConfigBase::readPathEntry
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
TDEConfigBase::setGroup
void setGroup(const TQString &group)
TDEConfig
KTextEditor
KTextEditor is KDE's standard text editing KPart interface.
Definition: blockselectiondcopinterface.h:10
TDEStdAccel::name
TQString name(StdAccel id)
tdelocale.h

interfaces

Skip menu "interfaces"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

interfaces

Skip menu "interfaces"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for interfaces by doxygen 1.9.1
This website is maintained by Timothy Pearson.