Diffstat (limited to 'noncore/apps/tinykate/tinykate.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index 3c9a637..9865c35 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp | |||
@@ -1,52 +1,57 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | tinykate.cpp | 2 | tinykate.cpp |
3 | Tiny KATE mainwindow | 3 | Tiny KATE mainwindow |
4 | ------------------- | 4 | ------------------- |
5 | begin : November 2002 | 5 | begin : November 2002 |
6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | 6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free softwaSre; you can redistribute it and/or modify * | 11 | * This program is free softwaSre; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation. * | 13 | * the Free Software Foundation. * |
14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * | 14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include <qaction.h> | ||
18 | #include <qtoolbutton.h> | ||
19 | #include <qmenubar.h> | ||
20 | #include <qpe/resource.h> | ||
21 | #include <qpe/qpeapplication.h> | ||
22 | 17 | ||
18 | #include "tinykate.h" | ||
19 | |||
20 | #include "katedocument.h" | ||
21 | #include "kglobal.h" | ||
22 | |||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
23 | #include <opie2/ofiledialog.h> | 25 | #include <opie2/ofiledialog.h> |
26 | #include <qpe/resource.h> | ||
27 | #include <qpe/qpeapplication.h> | ||
24 | 28 | ||
25 | #include "tinykate.h" | 29 | /* QT */ |
30 | #include <qaction.h> | ||
31 | #include <qtoolbutton.h> | ||
32 | #include <qmenubar.h> | ||
26 | 33 | ||
27 | #include <katedocument.h> | ||
28 | #include <kglobal.h> | ||
29 | 34 | ||
30 | using namespace Opie::Ui; | 35 | using namespace Opie::Ui; |
31 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 36 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
32 | QMainWindow( parent, name, f ) | 37 | QMainWindow( parent, name, f ) |
33 | { | 38 | { |
34 | shutDown=false; | 39 | shutDown=false; |
35 | nextUnnamed=0; | 40 | nextUnnamed=0; |
36 | currentView=0; | 41 | currentView=0; |
37 | viewCount=0; | 42 | viewCount=0; |
38 | setCaption(tr("TinyKATE")); | 43 | setCaption(tr("TinyKATE")); |
39 | KGlobal::setAppName("TinyKATE"); | 44 | KGlobal::setAppName("TinyKATE"); |
40 | 45 | ||
41 | QMenuBar *mb = new QMenuBar( this ); | 46 | QMenuBar *mb = new QMenuBar( this ); |
42 | mb->setMargin( 0 ); | 47 | mb->setMargin( 0 ); |
43 | 48 | ||
44 | tabwidget=new OTabWidget(this); | 49 | tabwidget=new OTabWidget(this); |
45 | setCentralWidget(tabwidget); | 50 | setCentralWidget(tabwidget); |
46 | connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*))); | 51 | connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*))); |
47 | 52 | ||
48 | //FILE ACTIONS | 53 | //FILE ACTIONS |
49 | QPopupMenu *popup = new QPopupMenu( this ); | 54 | QPopupMenu *popup = new QPopupMenu( this ); |
50 | 55 | ||
51 | // Action for creating a new document | 56 | // Action for creating a new document |
52 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 57 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
@@ -131,78 +136,78 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
131 | mb->insertItem( editUndo ); | 136 | mb->insertItem( editUndo ); |
132 | mb->insertItem( editRedo ); | 137 | mb->insertItem( editRedo ); |
133 | 138 | ||
134 | 139 | ||
135 | //Highlight management | 140 | //Highlight management |
136 | hlmenu=new QPopupMenu(this); | 141 | hlmenu=new QPopupMenu(this); |
137 | HlManager *hlm=HlManager::self(); | 142 | HlManager *hlm=HlManager::self(); |
138 | for (int i=0;i<hlm->highlights();i++) | 143 | for (int i=0;i<hlm->highlights();i++) |
139 | { | 144 | { |
140 | hlmenu->insertItem(hlm->hlName(i),i); | 145 | hlmenu->insertItem(hlm->hlName(i),i); |
141 | } | 146 | } |
142 | popup->insertItem(tr("Highlighting"),hlmenu); | 147 | popup->insertItem(tr("Highlighting"),hlmenu); |
143 | 148 | ||
144 | 149 | ||
145 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); | 150 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); |
146 | utilSettings->addTo( popup); | 151 | utilSettings->addTo( popup); |
147 | 152 | ||
148 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 153 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
149 | else slotNew(); | 154 | else slotNew(); |
150 | 155 | ||
151 | } | 156 | } |
152 | 157 | ||
153 | TinyKate::~TinyKate( ) | 158 | TinyKate::~TinyKate( ) |
154 | { | 159 | { |
155 | qWarning("TinyKate destructor\n"); | 160 | owarn << "TinyKate destructor\n" << oendl; |
156 | 161 | ||
157 | shutDown=true; | 162 | shutDown=true; |
158 | while (currentView!=0) { | 163 | while (currentView!=0) { |
159 | slotClose(); | 164 | slotClose(); |
160 | } | 165 | } |
161 | 166 | ||
162 | if( KGlobal::config() != 0 ) { | 167 | if( KGlobal::config() != 0 ) { |
163 | qWarning("deleting KateConfig object..\n"); | 168 | owarn << "deleting KateConfig object..\n" << oendl; |
164 | delete KGlobal::config(); | 169 | delete KGlobal::config(); |
165 | } | 170 | } |
166 | } | 171 | } |
167 | 172 | ||
168 | void TinyKate::slotOpen( ) | 173 | void TinyKate::slotOpen( ) |
169 | { | 174 | { |
170 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 175 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
171 | QString::null); | 176 | QString::null); |
172 | if (!filename.isEmpty()) { | 177 | if (!filename.isEmpty()) { |
173 | open(filename); | 178 | open(filename); |
174 | } | 179 | } |
175 | } | 180 | } |
176 | 181 | ||
177 | void TinyKate::open(const QString & filename) | 182 | void TinyKate::open(const QString & filename) |
178 | { | 183 | { |
179 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 184 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
180 | KTextEditor::View *kv; | 185 | KTextEditor::View *kv; |
181 | QFileInfo fi(filename); | 186 | QFileInfo fi(filename); |
182 | QString filenamed = fi.fileName(); | 187 | QString filenamed = fi.fileName(); |
183 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); | 188 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); |
184 | qDebug(filename); | 189 | odebug << filename << oendl; |
185 | 190 | ||
186 | kd->setDocName( filenamed); | 191 | kd->setDocName( filenamed); |
187 | kd->open( filename ); | 192 | kd->open( filename ); |
188 | viewCount++; | 193 | viewCount++; |
189 | } | 194 | } |
190 | 195 | ||
191 | void TinyKate::setDocument(const QString& fileref) | 196 | void TinyKate::setDocument(const QString& fileref) |
192 | { | 197 | { |
193 | open( fileref ); | 198 | open( fileref ); |
194 | } | 199 | } |
195 | 200 | ||
196 | void TinyKate::slotCurrentChanged( QWidget * view) | 201 | void TinyKate::slotCurrentChanged( QWidget * view) |
197 | { | 202 | { |
198 | if (currentView) { | 203 | if (currentView) { |
199 | 204 | ||
200 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 205 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
201 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 206 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
202 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 207 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
203 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 208 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
204 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 209 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
205 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 210 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
206 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 211 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
207 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 212 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
208 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 213 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
@@ -228,52 +233,52 @@ void TinyKate::slotNew( ) | |||
228 | KTextEditor::View *kv; | 233 | KTextEditor::View *kv; |
229 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), | 234 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), |
230 | "tinykate/tinykate", | 235 | "tinykate/tinykate", |
231 | tr("Unnamed %1").arg(nextUnnamed++)); | 236 | tr("Unnamed %1").arg(nextUnnamed++)); |
232 | viewCount++; | 237 | viewCount++; |
233 | } | 238 | } |
234 | 239 | ||
235 | void TinyKate::slotClose( ) | 240 | void TinyKate::slotClose( ) |
236 | { | 241 | { |
237 | if (currentView==0) return; | 242 | if (currentView==0) return; |
238 | KTextEditor::View *dv=currentView; | 243 | KTextEditor::View *dv=currentView; |
239 | currentView=0; | 244 | currentView=0; |
240 | tabwidget->removePage(dv); | 245 | tabwidget->removePage(dv); |
241 | delete dv->document(); | 246 | delete dv->document(); |
242 | viewCount--; | 247 | viewCount--; |
243 | if ((!viewCount) && (!shutDown)) slotNew(); | 248 | if ((!viewCount) && (!shutDown)) slotNew(); |
244 | } | 249 | } |
245 | 250 | ||
246 | void TinyKate::slotSave() { | 251 | void TinyKate::slotSave() { |
247 | // feel free to make this how you want | 252 | // feel free to make this how you want |
248 | if (currentView==0) return; | 253 | if (currentView==0) return; |
249 | 254 | ||
250 | // KateView *kv = (KateView*) currentView; | 255 | // KateView *kv = (KateView*) currentView; |
251 | KateDocument *kd = (KateDocument*) currentView->document(); | 256 | KateDocument *kd = (KateDocument*) currentView->document(); |
252 | // qDebug("saving file "+kd->docName()); | 257 | // odebug << "saving file "+kd->docName() << oendl; |
253 | if( kd->docName().isEmpty()) | 258 | if( kd->docName().isEmpty()) |
254 | slotSaveAs(); | 259 | slotSaveAs(); |
255 | else | 260 | else |
256 | kd->saveFile(); | 261 | kd->saveFile(); |
257 | // kv->save(); | 262 | // kv->save(); |
258 | // kd->saveFile(); | 263 | // kd->saveFile(); |
259 | } | 264 | } |
260 | 265 | ||
261 | void TinyKate::slotSaveAs() { | 266 | void TinyKate::slotSaveAs() { |
262 | if (currentView==0) return; | 267 | if (currentView==0) return; |
263 | KateDocument *kd = (KateDocument*) currentView->document(); | 268 | KateDocument *kd = (KateDocument*) currentView->document(); |
264 | 269 | ||
265 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, | 270 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
266 | QString::null); | 271 | QString::null); |
267 | if (!filename.isEmpty()) { | 272 | if (!filename.isEmpty()) { |
268 | qDebug("saving file "+filename); | 273 | odebug << "saving file "+filename << oendl; |
269 | QFileInfo fi(filename); | 274 | QFileInfo fi(filename); |
270 | QString filenamed = fi.fileName(); | 275 | QString filenamed = fi.fileName(); |
271 | kd->setDocFile( filename); | 276 | kd->setDocFile( filename); |
272 | kd->setDocName( filenamed); | 277 | kd->setDocName( filenamed); |
273 | kd->saveFile(); | 278 | kd->saveFile(); |
274 | // KTextEditor::View *dv = currentView; | 279 | // KTextEditor::View *dv = currentView; |
275 | // tabwidget->changeTab( dv, filenamed); | 280 | // tabwidget->changeTab( dv, filenamed); |
276 | // need to change tab label here | 281 | // need to change tab label here |
277 | } | 282 | } |
278 | 283 | ||
279 | } | 284 | } |