summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/mainwindow/tinykate.cpp136
-rw-r--r--noncore/apps/tinykate/mainwindow/tinykate.h5
2 files changed, 116 insertions, 25 deletions
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.cpp b/noncore/apps/tinykate/mainwindow/tinykate.cpp
index b1b88e9..e87464e 100644
--- a/noncore/apps/tinykate/mainwindow/tinykate.cpp
+++ b/noncore/apps/tinykate/mainwindow/tinykate.cpp
@@ -154,70 +154,64 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
154 154
155 mb->insertItem( editCut ); 155 mb->insertItem( editCut );
156 mb->insertItem( editCopy ); 156 mb->insertItem( editCopy );
157 mb->insertItem( editPaste ); 157 mb->insertItem( editPaste );
158 mb->insertItem( editUndo ); 158 mb->insertItem( editUndo );
159 mb->insertItem( editRedo ); 159 mb->insertItem( editRedo );
160 160
161 161
162 //Highlight management 162 //Highlight management
163 hlmenu=new QPopupMenu(this); 163 hlmenu=new QPopupMenu(this);
164 HlManager *hlm=HlManager::self(); 164 HlManager *hlm=HlManager::self();
165 for (int i=0;i<hlm->highlights();i++) 165 for (int i=0;i<hlm->highlights();i++)
166 { 166 {
167 hlmenu->insertItem(hlm->hlName(i),i); 167 hlmenu->insertItem(hlm->hlName(i),i);
168 } 168 }
169 popup->insertItem(tr("Highlighting"),hlmenu); 169 popup->insertItem(tr("Highlighting"),hlmenu);
170 170
171 171
172 utilSettings = new QAction( tr( "Settings" ), 172 utilSettings = new QAction( tr( "Settings" ),
173 Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), 173 Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
174 QString::null, 0, this, 0 ); 174 QString::null, 0, this, 0 );
175 utilSettings->addTo( popup); 175 utilSettings->addTo( popup);
176 176
177 if( qApp->argc() > 1) open(qApp->argv()[1]); 177 if( qApp->argc() > 1) open(qApp->argv()[1]);
178 else slotNew(); 178 else slotNew();
179 179
180} 180}
181 181
182TinyKate::~TinyKate( ) 182TinyKate::~TinyKate( )
183{ 183{
184 owarn << "TinyKate destructor\n" << oendl; 184 owarn << "TinyKate destructor\n" << oendl;
185 185
186 shutDown=true;
187 while (currentView!=0)
188 {
189 slotClose();
190 }
191
192 if( KGlobal::config() != 0 ) 186 if( KGlobal::config() != 0 )
193 { 187 {
194 owarn << "deleting KateConfig object..\n" << oendl; 188 owarn << "deleting KateConfig object..\n" << oendl;
195 delete KGlobal::config(); 189 delete KGlobal::config();
196 } 190 }
197} 191}
198 192
199void TinyKate::slotOpen( ) 193void TinyKate::slotOpen( )
200{ 194{
201 QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 195 QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
202 QString::null); 196 QString::null);
203 if (!filename.isEmpty()) 197 if (!filename.isEmpty())
204 { 198 {
205 open(filename); 199 open(filename);
206 } 200 }
207} 201}
208 202
209void TinyKate::open(const QString & filename) 203void TinyKate::open(const QString & filename)
210{ 204{
211 KateDocument *kd= new KateDocument(false, false, this,0,this); 205 KateDocument *kd= new KateDocument(false, false, this,0,this);
212 KTextEditor::View *kv; 206 KTextEditor::View *kv;
213 QString realFileName; 207 QString realFileName;
214 //check if filename is a .desktop file 208 //check if filename is a .desktop file
215 if ( filename.find( ".desktop", 0, true ) != -1 ) { 209 if ( filename.find( ".desktop", 0, true ) != -1 ) {
216 switch ( QMessageBox::warning( this, tr( "TinyKATE" ), 210 switch ( QMessageBox::warning( this, tr( "TinyKATE" ),
217 tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ), 211 tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ),
218 tr(".desktop File"), 212 tr(".desktop File"),
219 tr("Linked Document"), 0, 1, 1 ) ) 213 tr("Linked Document"), 0, 1, 1 ) )
220 { 214 {
221 case 0: //desktop 215 case 0: //desktop
222 realFileName = filename; 216 realFileName = filename;
223 break; 217 break;
@@ -256,86 +250,178 @@ void TinyKate::slotCurrentChanged( QWidget * view)
256 disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); 250 disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo()));
257 disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); 251 disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo()));
258 disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find())); 252 disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find()));
259 disconnect(editReplace,SIGNAL(activated()),currentView,SLOT(replace())); 253 disconnect(editReplace,SIGNAL(activated()),currentView,SLOT(replace()));
260 disconnect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine())); 254 disconnect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine()));
261 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 255 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
262 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 256 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
263 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 257 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
264 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 258 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
265 } 259 }
266 260
267 currentView=(KTextEditor::View*)view; 261 currentView=(KTextEditor::View*)view;
268 262
269 connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); 263 connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy()));
270 connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); 264 connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut()));
271 connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); 265 connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste()));
272 connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); 266 connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo()));
273 connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); 267 connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo()));
274 connect(editFind,SIGNAL(activated()),currentView,SLOT(find())); 268 connect(editFind,SIGNAL(activated()),currentView,SLOT(find()));
275 connect(editReplace,SIGNAL(activated()),currentView,SLOT(replace())); 269 connect(editReplace,SIGNAL(activated()),currentView,SLOT(replace()));
276 connect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine())); 270 connect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine()));
277 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 271 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
278 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 272 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
279 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 273 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
280 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 274 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
281 275
282} 276}
283 277
284void TinyKate::slotNew( ) 278void TinyKate::slotNew( )
285{ 279{
286 KateDocument *kd= new KateDocument(false, false, this,0,this); 280 KateDocument *kd= new KateDocument(false, false, this,0,this);
287 KTextEditor::View *kv; 281 KTextEditor::View *kv;
282
283 kd->setDocName(tr("Unnamed %1").arg(nextUnnamed++));
284 kd->setNewDoc(true);
288 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), 285 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),
289 "tinykate/tinykate", 286 "tinykate/tinykate",
290 tr("Unnamed %1").arg(nextUnnamed++)); 287 kd->docName());
291 viewCount++; 288 viewCount++;
292} 289}
293 290
294void TinyKate::slotClose( ) 291bool TinyKate::checkSave() {
292 if (currentView==0) return true;
293
294 KateView *kv = (KateView*) currentView;
295 if(kv->isModified()) {
296 KateDocument *kd = (KateDocument*) kv->document();
297 switch( QMessageBox::information( 0, (tr("TinyKATE")),
298 (tr("Do you want to save\n"
299 "changes to the document\n"
300 "%1?\n").arg(kd->docName())),
301 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
302 {
303 case 0:
304 {
305 return saveDocument();
306 }
307 break;
308
309 case 1:
310 {
311 return true;
312 }
313 break;
314
315 default:
316 {
317 return false;
318 }
319 break;
320 };
321 }
322 else {
323 return true;
324 }
325}
326
327bool TinyKate::closeDocument()
295{ 328{
296 if (currentView==0) return; 329 if (currentView==0) return true;
297 KTextEditor::View *dv=currentView; 330 KTextEditor::View *dv=currentView;
298 currentView=0; 331 if(checkSave()) {
299 tabwidget->removePage(dv); 332 currentView=0;
300 delete dv->document(); 333 tabwidget->removePage(dv);
301 viewCount--; 334 delete dv->document();
302 if ((!viewCount) && (!shutDown)) slotNew(); 335 viewCount--;
336 if ((!viewCount) && (!shutDown)) slotNew();
337 return true;
338 }
339 else
340 return false;
303} 341}
304 342
305void TinyKate::slotSave() 343void TinyKate::slotClose( )
344{
345 closeDocument();
346}
347
348bool TinyKate::saveDocument()
306{ 349{
307 // feel free to make this how you want 350 // feel free to make this how you want
308 if (currentView==0) return; 351 if (currentView==0) return false;
309 352
310 // KateView *kv = (KateView*) currentView; 353 // KateView *kv = (KateView*) currentView;
311 KateDocument *kd = (KateDocument*) currentView->document(); 354 KateDocument *kd = (KateDocument*) currentView->document();
312 // odebug << "saving file "+kd->docName() << oendl; 355 // odebug << "saving file "+kd->docName() << oendl;
313 if( kd->docName().isEmpty()) 356 if( kd->isNewDoc()) {
314 slotSaveAs(); 357 return saveDocumentAs();
358 }
315 else 359 else
316 kd->saveFile(); 360 return kd->saveFile();
361 // FIXME check result of saveFile and show message if failed?
317 // kv->save(); 362 // kv->save();
318 // kd->saveFile(); 363 // kd->saveFile();
319} 364}
320 365
321void TinyKate::slotSaveAs() 366bool TinyKate::saveDocumentAs()
322{ 367{
323 if (currentView==0) return; 368 if (currentView==0) return false;
369
370 bool result = false;
324 KateDocument *kd = (KateDocument*) currentView->document(); 371 KateDocument *kd = (KateDocument*) currentView->document();
325 372
326 QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, 373 QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL,
327 QString::null); 374 QString::null);
328 if (!filename.isEmpty()) 375 if (!filename.isEmpty())
329 { 376 {
330 odebug << "saving file "+filename << oendl; 377 odebug << "saving file "+filename << oendl;
331 QFileInfo fi(filename); 378 QFileInfo fi(filename);
379 if(fi.exists()) {
380 if ( QMessageBox::warning(this,tr("TinyKATE"),
381 tr("The file %1\n"
382 "already exists.\n\n"
383 "Are you sure you want to\n"
384 "overwrite it?")
385 .arg(fi.fileName()),
386 tr("Yes"),tr("No"),0,0,1) != 0) {
387 return false;
388 }
389 }
332 QString filenamed = fi.fileName(); 390 QString filenamed = fi.fileName();
333 kd->setDocFile( filename); 391 kd->setDocFile( filename);
334 kd->setDocName( filenamed); 392 kd->setDocName( filenamed);
335 kd->saveFile(); 393 kd->setNewDoc(false);
336 // KTextEditor::View *dv = currentView; 394 result = kd->saveFile();
337 // tabwidget->changeTab( dv, filenamed); 395 // FIXME check result of saveFile and show message if failed?
338 // need to change tab label here 396 tabwidget->changeTab( tabwidget->currentWidget(), "tinykate/tinykate", filenamed );
397 }
398 return result;
399}
400
401void TinyKate::slotSave()
402{
403 saveDocument();
404}
405
406void TinyKate::slotSaveAs()
407{
408 saveDocumentAs();
409}
410
411void TinyKate::closeEvent(QCloseEvent *e) {
412 // Close all documents
413 shutDown = true;
414 while (currentView!=0)
415 {
416 if(!closeDocument()) {
417 // User cancelled
418 shutDown=false;
419 break;
420 }
339 } 421 }
340 422
423 if(shutDown)
424 e->accept();
425 else
426 e->ignore();
341} 427}
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.h b/noncore/apps/tinykate/mainwindow/tinykate.h
index 6e95d87..7d0c588 100644
--- a/noncore/apps/tinykate/mainwindow/tinykate.h
+++ b/noncore/apps/tinykate/mainwindow/tinykate.h
@@ -19,48 +19,53 @@
19#define __TINYKATE_H__ 19#define __TINYKATE_H__
20 20
21 21
22#include <qmainwindow.h> 22#include <qmainwindow.h>
23#include <opie2/otabwidget.h> 23#include <opie2/otabwidget.h>
24#include <ktexteditor.h> 24#include <ktexteditor.h>
25 25
26class QToolButton; 26class QToolButton;
27class QAction; 27class QAction;
28class QPopupMenu; 28class QPopupMenu;
29 29
30class TinyKate : public QMainWindow 30class TinyKate : public QMainWindow
31{ 31{
32 Q_OBJECT 32 Q_OBJECT
33public: 33public:
34 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); 34 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0);
35 ~TinyKate( ); 35 ~TinyKate( );
36 static QString appName() { return QString::fromLatin1( "tinykate" ); }; 36 static QString appName() { return QString::fromLatin1( "tinykate" ); };
37 37
38 38
39public slots: 39public slots:
40 void slotNew(); 40 void slotNew();
41 void setDocument(const QString& fileref); 41 void setDocument(const QString& fileref);
42 42
43protected slots: 43protected slots:
44 void slotOpen(); 44 void slotOpen();
45 void slotClose(); 45 void slotClose();
46 void slotCurrentChanged(QWidget *); 46 void slotCurrentChanged(QWidget *);
47 void slotSave(); 47 void slotSave();
48 void slotSaveAs(); 48 void slotSaveAs();
49protected: 49protected:
50 void open(const QString&); 50 void open(const QString&);
51 bool closeDocument();
52 bool checkSave();
53 bool saveDocument();
54 bool saveDocumentAs();
55 void closeEvent(QCloseEvent *e);
51private: 56private:
52 QString currentFileName; 57 QString currentFileName;
53 Opie::Ui::OTabWidget *tabwidget; 58 Opie::Ui::OTabWidget *tabwidget;
54 KTextEditor::View *currentView; 59 KTextEditor::View *currentView;
55 bool shutDown; 60 bool shutDown;
56 61
57 QToolButton *editCopy, *editCut, *editPaste, *editUndo, *editRedo; 62 QToolButton *editCopy, *editCut, *editPaste, *editUndo, *editRedo;
58 QAction *viewIncFontSizes, *viewDecFontSizes, *utilSettings, *editFind, *editReplace, *editGotoLine; 63 QAction *viewIncFontSizes, *viewDecFontSizes, *utilSettings, *editFind, *editReplace, *editGotoLine;
59 64
60 QPopupMenu *hlmenu; 65 QPopupMenu *hlmenu;
61 uint nextUnnamed; 66 uint nextUnnamed;
62 uint viewCount; 67 uint viewCount;
63}; 68};
64 69
65 70
66#endif // __TINYKATE_H__ 71#endif // __TINYKATE_H__