summaryrefslogtreecommitdiff
authorbipolar <bipolar>2002-03-08 00:12:12 (UTC)
committer bipolar <bipolar>2002-03-08 00:12:12 (UTC)
commit11b56113b6641e0b85c6015eafab802dd7663198 (patch) (unidiff)
tree1899707c9144a342519acf9693ec69d2d4edffc7
parent50f8f55346f369787063f42c571d2dc832eb58aa (diff)
downloadopie-11b56113b6641e0b85c6015eafab802dd7663198.zip
opie-11b56113b6641e0b85c6015eafab802dd7663198.tar.gz
opie-11b56113b6641e0b85c6015eafab802dd7663198.tar.bz2
ljp: added startup option,a dn fixed save when closing with no file edited
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileSaver.cpp2
-rw-r--r--core/apps/textedit/textedit.cpp88
-rw-r--r--core/apps/textedit/textedit.h6
3 files changed, 69 insertions, 27 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp
index d78f2e8..4e80735 100644
--- a/core/apps/textedit/fileSaver.cpp
+++ b/core/apps/textedit/fileSaver.cpp
@@ -66,25 +66,25 @@ fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl
66 filePermCheck = new QCheckBox( this, "SetFilePerms" ); 66 filePermCheck = new QCheckBox( this, "SetFilePerms" );
67 filePermCheck->setText("set file permissions"); 67 filePermCheck->setText("set file permissions");
68 filePermCheck->setGeometry(10, 178, 150,17); 68 filePermCheck->setGeometry(10, 178, 150,17);
69 // signals and slots connections 69 // signals and slots connections
70 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); 70 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
71 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 71 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
72 72
73// tmpFileName=fi.FilePath(); 73// tmpFileName=fi.FilePath();
74// qDebug( tmpFileName); 74// qDebug( tmpFileName);
75 currentDir.setPath( QDir::currentDirPath() ); 75 currentDir.setPath( QDir::currentDirPath() );
76 populateList(); 76 populateList();
77 move(0,15); 77 move(0,15);
78 78 fileEdit->setFocus();
79} 79}
80 80
81fileSaver::~fileSaver() 81fileSaver::~fileSaver()
82{ 82{
83} 83}
84 84
85void fileSaver::populateList() 85void fileSaver::populateList()
86{ 86{
87 ListView->clear(); 87 ListView->clear();
88 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); 88 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden );
89 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 89 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
90 currentDir.setMatchAllDirs(TRUE); 90 currentDir.setMatchAllDirs(TRUE);
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 0f19da9..03f3a1e 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -243,25 +243,25 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
243 243
244 setToolBarsMovable( FALSE ); 244 setToolBarsMovable( FALSE );
245 245
246 setIcon( Resource::loadPixmap( "TextEditor" ) ); 246 setIcon( Resource::loadPixmap( "TextEditor" ) );
247 247
248 QPEToolBar *bar = new QPEToolBar( this ); 248 QPEToolBar *bar = new QPEToolBar( this );
249 bar->setHorizontalStretchable( TRUE ); 249 bar->setHorizontalStretchable( TRUE );
250 menu = bar; 250 menu = bar;
251 251
252 QPEMenuBar *mb = new QPEMenuBar( bar ); 252 QPEMenuBar *mb = new QPEMenuBar( bar );
253 QPopupMenu *file = new QPopupMenu( this ); 253 QPopupMenu *file = new QPopupMenu( this );
254 QPopupMenu *edit = new QPopupMenu( this ); 254 QPopupMenu *edit = new QPopupMenu( this );
255 QPopupMenu *font = new QPopupMenu( this ); 255 font = new QPopupMenu( this );
256 256
257 bar = new QPEToolBar( this ); 257 bar = new QPEToolBar( this );
258 editBar = bar; 258 editBar = bar;
259 259
260 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 260 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
261 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 261 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
262 a->addTo( bar ); 262 a->addTo( bar );
263 a->addTo( file ); 263 a->addTo( file );
264 264
265 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 265 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
266 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 266 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
267// a->addTo( bar ); 267// a->addTo( bar );
@@ -340,24 +340,30 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
340 340
341 font->insertSeparator(); 341 font->insertSeparator();
342#endif 342#endif
343 343
344 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 344 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
345 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 345 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
346 wa->setToggleAction(TRUE); 346 wa->setToggleAction(TRUE);
347 wa->addTo( font ); 347 wa->addTo( font );
348 348
349 font->insertSeparator(); 349 font->insertSeparator();
350 font->insertItem("Font", this, SLOT(changeFont()) ); 350 font->insertItem("Font", this, SLOT(changeFont()) );
351 351
352 font->insertSeparator();
353 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
354 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
355 nStart->setToggleAction(TRUE);
356 nStart->addTo( font );
357
352 mb->insertItem( tr( "File" ), file ); 358 mb->insertItem( tr( "File" ), file );
353 mb->insertItem( tr( "Edit" ), edit ); 359 mb->insertItem( tr( "Edit" ), edit );
354 mb->insertItem( tr( "View" ), font ); 360 mb->insertItem( tr( "View" ), font );
355 361
356 searchBar = new QPEToolBar(this); 362 searchBar = new QPEToolBar(this);
357 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 363 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
358 364
359 searchBar->setHorizontalStretchable( TRUE ); 365 searchBar->setHorizontalStretchable( TRUE );
360 366
361 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 367 searchEdit = new QLineEdit( searchBar, "searchEdit" );
362 searchBar->setStretchableWidget( searchEdit ); 368 searchBar->setStretchableWidget( searchEdit );
363 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 369 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
@@ -405,25 +411,32 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
405 cfg.setGroup("Font"); 411 cfg.setGroup("Font");
406 QString family = cfg.readEntry("Family", fontInfo.family()); 412 QString family = cfg.readEntry("Family", fontInfo.family());
407 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 413 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
408 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 414 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
409 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 415 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
410 416
411 defaultFont = fdb.font(family,style,i_size,charSet); 417 defaultFont = fdb.font(family,style,i_size,charSet);
412 editor->setFont( defaultFont); 418 editor->setFont( defaultFont);
413 419
414 wa->setOn(wrap); 420 wa->setOn(wrap);
415 updateCaption(); 421 updateCaption();
416 422
417 fileNew(); 423 cfg.setGroup("View");
424 if(cfg.readEntry("startNew","TRUE") == "TRUE") {
425 nStart->setOn(TRUE);
426 fileNew();
427 } else {
428 fileOpen();
429 }
430
418} 431}
419 432
420TextEdit::~TextEdit() 433TextEdit::~TextEdit()
421{ 434{
422// save(); 435// save();
423 436
424 Config cfg("TextEdit"); 437 Config cfg("TextEdit");
425 cfg.setGroup("View"); 438 cfg.setGroup("View");
426 QFont f = editor->font(); 439 QFont f = editor->font();
427 cfg.writeEntry("FontSize",f.pointSize()); 440 cfg.writeEntry("FontSize",f.pointSize());
428 cfg.writeEntry("Bold",f.bold()); 441 cfg.writeEntry("Bold",f.bold());
429 cfg.writeEntry("Italic",f.italic()); 442 cfg.writeEntry("Italic",f.italic());
@@ -688,44 +701,52 @@ void TextEdit::showEditTools()
688 if ( searchVisible ) 701 if ( searchVisible )
689 searchBar->show(); 702 searchBar->show();
690// updateCaption(); 703// updateCaption();
691 editorStack->raiseWidget( editor ); 704 editorStack->raiseWidget( editor );
692 setWState (WState_Reserved1 ); 705 setWState (WState_Reserved1 );
693} 706}
694 707
695/*! 708/*!
696 unprompted save */ 709 unprompted save */
697bool TextEdit::save() 710bool TextEdit::save()
698{ 711{
699 QString file = doc->file(); 712 QString file = doc->file();
713 qDebug(file);
700 QString name= doc->name(); 714 QString name= doc->name();
701 715 qDebug(name);
702 QString rt = editor->text(); 716 QString rt = editor->text();
703 currentFileName= name ; 717 if( !rt.isEmpty() ) {
704 qDebug("saveFile "+currentFileName); 718 if(name.isEmpty()) {
705 719 saveAs();
706 struct stat buf; 720 } else {
707 mode_t mode; 721 currentFileName= name ;
708 stat(file.latin1(), &buf); 722 qDebug("saveFile "+currentFileName);
709 mode = buf.st_mode; 723
724 struct stat buf;
725 mode_t mode;
726 stat(file.latin1(), &buf);
727 mode = buf.st_mode;
728
729 doc->setName( name);
730 FileManager fm;
731 if ( !fm.saveFile( *doc, rt ) ) {
732 return false;
733 }
734 editor->setEdited( false );
710 735
711 doc->setName( name); 736 chmod( file.latin1(), mode);
712 FileManager fm; 737 }
713 if ( !fm.saveFile( *doc, rt ) ) { 738 return true;
714 return false;
715 } 739 }
716 editor->setEdited( false ); 740 return false;
717
718 chmod( file.latin1(), mode);
719 return true;
720} 741}
721 742
722/*! 743/*!
723 prompted save */ 744 prompted save */
724bool TextEdit::saveAs() 745bool TextEdit::saveAs()
725{ 746{
726// qDebug("saveAsFile "+currentFileName); 747// qDebug("saveAsFile "+currentFileName);
727 748
728 // case of nothing to save... /// there's always something to save 749 // case of nothing to save... /// there's always something to save
729// if ( !doc )//|| !bFromDocView) 750// if ( !doc )//|| !bFromDocView)
730// { 751// {
731// qDebug("no doc"); 752// qDebug("no doc");
@@ -754,43 +775,42 @@ bool TextEdit::saveAs()
754 docname.replace( QRegExp("/"), "_" ); 775 docname.replace( QRegExp("/"), "_" );
755 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 776 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
756 if ( docname.length() > 40 ) 777 if ( docname.length() > 40 )
757 docname = docname.left(40); 778 docname = docname.left(40);
758 if ( docname.isEmpty() ) 779 if ( docname.isEmpty() )
759 docname = "Unnamed"; 780 docname = "Unnamed";
760 doc->setName(docname); 781 doc->setName(docname);
761 currentFileName=docname; 782 currentFileName=docname;
762 } 783 }
763 } 784 }
764 785
765 786
766 fileSaveDlg=new fileSaver(this,"Save File",TRUE, 0, currentFileName); 787 fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName);
767 qDebug("wanna save filename "+currentFileName); 788 qDebug("wanna save filename "+currentFileName);
768 fileSaveDlg->exec(); 789 fileSaveDlg->exec();
769 if( fileSaveDlg->result() == 1 ) { 790 if( fileSaveDlg->result() == 1 ) {
770 QString fileNm=fileSaveDlg->selectedFileName; 791 QString fileNm=fileSaveDlg->selectedFileName;
771 qDebug("saving filename "+fileNm); 792 qDebug("saving filename "+fileNm);
772 QFileInfo fi(fileNm); 793 QFileInfo fi(fileNm);
773 currentFileName=fi.fileName(); 794 currentFileName=fi.fileName();
774 if(doc) { 795 if(doc) {
775 qDebug("doclnk exists");
776// QString file = doc->file(); 796// QString file = doc->file();
777// doc->removeFiles(); 797// doc->removeFiles();
778 delete doc; 798 delete doc;
779 DocLnk nf; 799 DocLnk nf;
780 nf.setType("text/plain"); 800 nf.setType("text/plain");
781 nf.setFile( fileNm); 801 nf.setFile( fileNm);
782 doc = new DocLnk(nf); 802 doc = new DocLnk(nf);
783// editor->setText(rt); 803// editor->setText(rt);
784 qDebug("openFile doclnk "+currentFileName); 804// qDebug("openFile doclnk "+currentFileName);
785 doc->setName( currentFileName); 805 doc->setName( currentFileName);
786 updateCaption( currentFileName); 806 updateCaption( currentFileName);
787 807
788 FileManager fm; 808 FileManager fm;
789 if ( !fm.saveFile( *doc, rt ) ) { 809 if ( !fm.saveFile( *doc, rt ) ) {
790 return false; 810 return false;
791 } 811 }
792 if( fileSaveDlg->filePermCheck->isChecked() ) { 812 if( fileSaveDlg->filePermCheck->isChecked() ) {
793 filePermissions *filePerm; 813 filePermissions *filePerm;
794 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); 814 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm);
795 filePerm->exec(); 815 filePerm->exec();
796 editor->setEdited( false ); 816 editor->setEdited( false );
@@ -846,28 +866,33 @@ void TextEdit::closeEvent( QCloseEvent *e )
846 if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { 866 if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
847 e->ignore(); 867 e->ignore();
848 repaint(); 868 repaint();
849// fileRevert(); 869// fileRevert();
850 870
851 } else { 871 } else {
852 bFromDocView = FALSE; 872 bFromDocView = FALSE;
853 e->accept(); 873 e->accept();
854 } 874 }
855} 875}
856 876
857void TextEdit::accept() 877void TextEdit::accept()
858{ 878 {
859 save(); 879 QString file = doc->file();
860 close(); 880 if (file.find("_.txt",0,TRUE) ==-1)
861// fileOpen(); //godamn thats obnoxious! lemme out!!! 881 save();
882 else {
883 QFile(file).remove();
884 }
885 exit(0);
886
862} 887}
863 888
864void TextEdit::changeFont() { 889void TextEdit::changeFont() {
865 FontDatabase fdb; 890 FontDatabase fdb;
866 QFont defaultFont=editor->font(); 891 QFont defaultFont=editor->font();
867 QFontInfo fontInfo(defaultFont); 892 QFontInfo fontInfo(defaultFont);
868 Config cfg("TextEdit"); 893 Config cfg("TextEdit");
869 cfg.setGroup("Font"); 894 cfg.setGroup("Font");
870 QString family = cfg.readEntry("Family", fontInfo.family()); 895 QString family = cfg.readEntry("Family", fontInfo.family());
871 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 896 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
872 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 897 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
873 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 898 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
@@ -891,12 +916,25 @@ void TextEdit::editDelete()
891 case 0: 916 case 0:
892 if(doc) { 917 if(doc) {
893 doc->removeFiles(); 918 doc->removeFiles();
894 clear(); 919 clear();
895 setCaption( tr("Text Editor") ); 920 setCaption( tr("Text Editor") );
896 } 921 }
897 break; 922 break;
898 case 1: 923 case 1:
899 // exit 924 // exit
900 break; 925 break;
901 }; 926 };
902} 927}
928
929void TextEdit::changeStartConfig( bool b ) {
930
931 Config cfg("TextEdit");
932 cfg.setGroup("View");
933 if(b) {
934 qDebug("bool");
935 cfg.writeEntry("startNew","TRUE");
936 } else {
937 cfg.writeEntry("startNew","FALSE");
938 }
939 update();
940}
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h
index 781061a..fb58738 100644
--- a/core/apps/textedit/textedit.h
+++ b/core/apps/textedit/textedit.h
@@ -25,53 +25,57 @@
25#define QTEXTEDIT_OPEN_API 25#define QTEXTEDIT_OPEN_API
26 26
27#include "fileBrowser.h" 27#include "fileBrowser.h"
28#include "fileSaver.h" 28#include "fileSaver.h"
29 29
30#include <qpe/filemanager.h> 30#include <qpe/filemanager.h>
31 31
32#include <qmainwindow.h> 32#include <qmainwindow.h>
33#include <qmultilineedit.h> 33#include <qmultilineedit.h>
34#include <qlist.h> 34#include <qlist.h>
35#include <qmap.h> 35#include <qmap.h>
36 36
37class QAction;
37class QWidgetStack; 38class QWidgetStack;
38class QToolButton; 39class QToolButton;
39class QPopupMenu; 40class QPopupMenu;
40class QToolBar; 41class QToolBar;
41class QLineEdit; 42class QLineEdit;
42class QAction; 43class QAction;
43class FileSelector; 44class FileSelector;
44class QpeEditor; 45class QpeEditor;
46class QPopupMenu;
45 47
46class TextEdit : public QMainWindow 48class TextEdit : public QMainWindow
47{ 49{
48 Q_OBJECT 50 Q_OBJECT
49 51
50public: 52public:
51 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 53 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
52 ~TextEdit(); 54 ~TextEdit();
53 55 QPopupMenu *font;
56 QAction *nStart;
54 void openFile( const QString & ); 57 void openFile( const QString & );
55 58
56protected: 59protected:
57 void closeEvent( QCloseEvent *e ); 60 void closeEvent( QCloseEvent *e );
58 61
59private slots: 62private slots:
60 void setDocument(const QString&); 63 void setDocument(const QString&);
61 void changeFont(); 64 void changeFont();
62 void fileNew(); 65 void fileNew();
63 void fileRevert(); 66 void fileRevert();
64 void fileOpen(); 67 void fileOpen();
65 void newFileOpen(); 68 void newFileOpen();
69 void changeStartConfig(bool);
66 bool save(); 70 bool save();
67 bool saveAs(); 71 bool saveAs();
68 72
69 73
70 void editCut(); 74 void editCut();
71 void editCopy(); 75 void editCopy();
72 void editPaste(); 76 void editPaste();
73 void editFind(); 77 void editFind();
74 void editDelete(); 78 void editDelete();
75 79
76 void findNext(); 80 void findNext();
77 void findClose(); 81 void findClose();