author | bipolar <bipolar> | 2002-03-08 00:12:12 (UTC) |
---|---|---|
committer | bipolar <bipolar> | 2002-03-08 00:12:12 (UTC) |
commit | 11b56113b6641e0b85c6015eafab802dd7663198 (patch) (unidiff) | |
tree | 1899707c9144a342519acf9693ec69d2d4edffc7 | |
parent | 50f8f55346f369787063f42c571d2dc832eb58aa (diff) | |
download | opie-11b56113b6641e0b85c6015eafab802dd7663198.zip opie-11b56113b6641e0b85c6015eafab802dd7663198.tar.gz opie-11b56113b6641e0b85c6015eafab802dd7663198.tar.bz2 |
ljp: added startup option,a dn fixed save when closing with no file edited
-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 2 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 88 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 6 |
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 | |||
@@ -1,202 +1,202 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** copyright 2001 ljp ljp@llornkcor.com | 2 | ** copyright 2001 ljp ljp@llornkcor.com |
3 | ** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp | 3 | ** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ****************************************************************************/ | 13 | ****************************************************************************/ |
14 | #include "fileSaver.h" | 14 | #include "fileSaver.h" |
15 | #include <qpe/config.h> | 15 | #include <qpe/config.h> |
16 | #include <qpe/resource.h> | 16 | #include <qpe/resource.h> |
17 | 17 | ||
18 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
19 | #include <qlistview.h> | 19 | #include <qlistview.h> |
20 | #include <qpushbutton.h> | 20 | #include <qpushbutton.h> |
21 | #include <qfile.h> | 21 | #include <qfile.h> |
22 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
23 | #include <qlineedit.h> | 23 | #include <qlineedit.h> |
24 | #include <qcheckbox.h> | 24 | #include <qcheckbox.h> |
25 | 25 | ||
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | 27 | ||
28 | fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) | 28 | fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) |
29 | : QDialog( parent, name, modal, fl ) | 29 | : QDialog( parent, name, modal, fl ) |
30 | { | 30 | { |
31 | if ( !name ) | 31 | if ( !name ) |
32 | setName( "fileSaver" ); | 32 | setName( "fileSaver" ); |
33 | resize( 240, 280 ); | 33 | resize( 240, 280 ); |
34 | setCaption(tr( name ) ); | 34 | setCaption(tr( name ) ); |
35 | QFileInfo fi(currentFileName); | 35 | QFileInfo fi(currentFileName); |
36 | QString tmpFileName=fi.fileName(); | 36 | QString tmpFileName=fi.fileName(); |
37 | // qDebug( tmpFileName); | 37 | // qDebug( tmpFileName); |
38 | dirLabel = new QLabel(this, "DirLabel"); | 38 | dirLabel = new QLabel(this, "DirLabel"); |
39 | dirLabel->setText(currentDir.canonicalPath()); | 39 | dirLabel->setText(currentDir.canonicalPath()); |
40 | dirLabel->setGeometry(10,20,230,15); | 40 | dirLabel->setGeometry(10,20,230,15); |
41 | 41 | ||
42 | QPushButton *homeButton; | 42 | QPushButton *homeButton; |
43 | homeButton = new QPushButton(Resource::loadIconSet("home"),"",this,"homeButton"); | 43 | homeButton = new QPushButton(Resource::loadIconSet("home"),"",this,"homeButton"); |
44 | homeButton->setGeometry(200,4,25,25); | 44 | homeButton->setGeometry(200,4,25,25); |
45 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); | 45 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); |
46 | 46 | ||
47 | ListView = new QListView( this, "ListView" ); | 47 | ListView = new QListView( this, "ListView" ); |
48 | ListView->addColumn( tr( "Name" ) ); | 48 | ListView->addColumn( tr( "Name" ) ); |
49 | ListView->setColumnWidth(0,140); | 49 | ListView->setColumnWidth(0,140); |
50 | ListView->setSorting( 2, FALSE); | 50 | ListView->setSorting( 2, FALSE); |
51 | ListView->addColumn( tr( "Size" ) ); | 51 | ListView->addColumn( tr( "Size" ) ); |
52 | ListView->setColumnWidth(1,59); | 52 | ListView->setColumnWidth(1,59); |
53 | ListView->setColumnWidthMode(0,QListView::Manual); | 53 | ListView->setColumnWidthMode(0,QListView::Manual); |
54 | ListView->setColumnAlignment(1,QListView::AlignRight); | 54 | ListView->setColumnAlignment(1,QListView::AlignRight); |
55 | // ListView->setMultiSelection(true); | 55 | // ListView->setMultiSelection(true); |
56 | // ListView->setSelectionMode(QListView::Extended); | 56 | // ListView->setSelectionMode(QListView::Extended); |
57 | 57 | ||
58 | ListView->setAllColumnsShowFocus( TRUE ); | 58 | ListView->setAllColumnsShowFocus( TRUE ); |
59 | ListView->setGeometry( QRect( 10,35,220,125)); | 59 | ListView->setGeometry( QRect( 10,35,220,125)); |
60 | 60 | ||
61 | fileEdit= new QLineEdit(this); | 61 | fileEdit= new QLineEdit(this); |
62 | fileEdit->setGeometry( QRect( 10, 162, 205, 17)); | 62 | fileEdit->setGeometry( QRect( 10, 162, 205, 17)); |
63 | 63 | ||
64 | fileEdit->setText( tmpFileName); | 64 | fileEdit->setText( tmpFileName); |
65 | 65 | ||
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 | ||
81 | fileSaver::~fileSaver() | 81 | fileSaver::~fileSaver() |
82 | { | 82 | { |
83 | } | 83 | } |
84 | 84 | ||
85 | void fileSaver::populateList() | 85 | void 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); |
91 | 91 | ||
92 | currentDir.setNameFilter("*"); | 92 | currentDir.setNameFilter("*"); |
93 | QString fileL, fileS; | 93 | QString fileL, fileS; |
94 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 94 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
95 | QFileInfoListIterator it(*list); | 95 | QFileInfoListIterator it(*list); |
96 | QFileInfo *fi; | 96 | QFileInfo *fi; |
97 | while ( (fi=it.current()) ) { | 97 | while ( (fi=it.current()) ) { |
98 | 98 | ||
99 | if (fi->isSymLink() ){ | 99 | if (fi->isSymLink() ){ |
100 | QString symLink=fi->readLink(); | 100 | QString symLink=fi->readLink(); |
101 | // qDebug("Symlink detected "+symLink); | 101 | // qDebug("Symlink detected "+symLink); |
102 | QFileInfo sym( symLink); | 102 | QFileInfo sym( symLink); |
103 | fileS.sprintf( "%10li", sym.size() ); | 103 | fileS.sprintf( "%10li", sym.size() ); |
104 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | 104 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); |
105 | 105 | ||
106 | } else { | 106 | } else { |
107 | // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 107 | // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
108 | fileS.sprintf( "%10li", fi->size() ); | 108 | fileS.sprintf( "%10li", fi->size() ); |
109 | fileL.sprintf( "%s",fi->fileName().data() ); | 109 | fileL.sprintf( "%s",fi->fileName().data() ); |
110 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 110 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
111 | fileL+="/"; | 111 | fileL+="/"; |
112 | // qDebug(currentDir.canonicalPath()+fileL); | 112 | // qDebug(currentDir.canonicalPath()+fileL); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | item= new QListViewItem( ListView,fileL,fileS ); | 115 | item= new QListViewItem( ListView,fileL,fileS ); |
116 | ++it; | 116 | ++it; |
117 | } | 117 | } |
118 | ListView->setSorting( 2, FALSE); | 118 | ListView->setSorting( 2, FALSE); |
119 | dirLabel->setText(currentDir.canonicalPath()); | 119 | dirLabel->setText(currentDir.canonicalPath()); |
120 | 120 | ||
121 | 121 | ||
122 | } | 122 | } |
123 | 123 | ||
124 | void fileSaver::upDir() | 124 | void fileSaver::upDir() |
125 | { | 125 | { |
126 | // qDebug(currentDir.canonicalPath()); | 126 | // qDebug(currentDir.canonicalPath()); |
127 | } | 127 | } |
128 | 128 | ||
129 | void fileSaver::listDoubleClicked(QListViewItem *selectedItem) | 129 | void fileSaver::listDoubleClicked(QListViewItem *selectedItem) |
130 | { | 130 | { |
131 | } | 131 | } |
132 | 132 | ||
133 | void fileSaver::listClicked(QListViewItem *selectedItem) | 133 | void fileSaver::listClicked(QListViewItem *selectedItem) |
134 | { | 134 | { |
135 | QString strItem=selectedItem->text(0); | 135 | QString strItem=selectedItem->text(0); |
136 | QString strSize=selectedItem->text(1); | 136 | QString strSize=selectedItem->text(1); |
137 | // qDebug("strItem is "+strItem); | 137 | // qDebug("strItem is "+strItem); |
138 | strSize.stripWhiteSpace(); | 138 | strSize.stripWhiteSpace(); |
139 | // qDebug(strSize); | 139 | // qDebug(strSize); |
140 | 140 | ||
141 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | 141 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink |
142 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); | 142 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); |
143 | // qDebug("strItem symlink is "+strItem2); | 143 | // qDebug("strItem symlink is "+strItem2); |
144 | if(QDir(strItem2).exists() ) { | 144 | if(QDir(strItem2).exists() ) { |
145 | currentDir.cd(strItem2, TRUE); | 145 | currentDir.cd(strItem2, TRUE); |
146 | populateList(); | 146 | populateList(); |
147 | } | 147 | } |
148 | } else { // not a symlink | 148 | } else { // not a symlink |
149 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | 149 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { |
150 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | 150 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { |
151 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 151 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
152 | currentDir.cd(strItem,FALSE); | 152 | currentDir.cd(strItem,FALSE); |
153 | // qDebug("Path is "+strItem); | 153 | // qDebug("Path is "+strItem); |
154 | populateList(); | 154 | populateList(); |
155 | } else { | 155 | } else { |
156 | currentDir.cdUp(); | 156 | currentDir.cdUp(); |
157 | populateList(); | 157 | populateList(); |
158 | } | 158 | } |
159 | if(QDir(strItem).exists()){ | 159 | if(QDir(strItem).exists()){ |
160 | currentDir.cd(strItem, TRUE); | 160 | currentDir.cd(strItem, TRUE); |
161 | populateList(); | 161 | populateList(); |
162 | } | 162 | } |
163 | } // else | 163 | } // else |
164 | // if( QFile::exists(strItem ) ) { | 164 | // if( QFile::exists(strItem ) ) { |
165 | // qDebug("We found our files!!"); | 165 | // qDebug("We found our files!!"); |
166 | 166 | ||
167 | // OnOK(); | 167 | // OnOK(); |
168 | } //end not symlink | 168 | } //end not symlink |
169 | chdir(strItem.latin1()); | 169 | chdir(strItem.latin1()); |
170 | 170 | ||
171 | 171 | ||
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | void fileSaver::closeEvent( QCloseEvent *e ) | 175 | void fileSaver::closeEvent( QCloseEvent *e ) |
176 | { | 176 | { |
177 | if(e->isAccepted()) { | 177 | if(e->isAccepted()) { |
178 | e->accept(); | 178 | e->accept(); |
179 | } else { | 179 | } else { |
180 | qDebug("not accepted"); | 180 | qDebug("not accepted"); |
181 | done(-1); | 181 | done(-1); |
182 | } | 182 | } |
183 | } | 183 | } |
184 | 184 | ||
185 | void fileSaver::accept() { | 185 | void fileSaver::accept() { |
186 | selectedFileName = fileEdit->text(); | 186 | selectedFileName = fileEdit->text(); |
187 | QString path = currentDir.canonicalPath()+"/" + selectedFileName; | 187 | QString path = currentDir.canonicalPath()+"/" + selectedFileName; |
188 | if( path.find("//",0,TRUE) ==-1 ) { | 188 | if( path.find("//",0,TRUE) ==-1 ) { |
189 | selectedFileName = path; | 189 | selectedFileName = path; |
190 | } else { | 190 | } else { |
191 | selectedFileName = currentDir.canonicalPath()+selectedFileName; | 191 | selectedFileName = currentDir.canonicalPath()+selectedFileName; |
192 | } | 192 | } |
193 | qDebug("going to save "+selectedFileName); | 193 | qDebug("going to save "+selectedFileName); |
194 | done(1); | 194 | done(1); |
195 | } | 195 | } |
196 | 196 | ||
197 | void fileSaver::homeButtonPushed() { | 197 | void fileSaver::homeButtonPushed() { |
198 | chdir( QDir::homeDirPath().latin1() ); | 198 | chdir( QDir::homeDirPath().latin1() ); |
199 | currentDir.cd( QDir::homeDirPath(), TRUE); | 199 | currentDir.cd( QDir::homeDirPath(), TRUE); |
200 | populateList(); | 200 | populateList(); |
201 | update(); | 201 | update(); |
202 | } | 202 | } |
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 | |||
@@ -63,840 +63,878 @@ static char * filesave_xpm[] = { | |||
63 | "# c #9E9E9E", | 63 | "# c #9E9E9E", |
64 | "$ c #525252", | 64 | "$ c #525252", |
65 | "% c #929292", | 65 | "% c #929292", |
66 | "& c #676767", | 66 | "& c #676767", |
67 | "* c #848484", | 67 | "* c #848484", |
68 | "= c #666666", | 68 | "= c #666666", |
69 | "- c #D8D8D8", | 69 | "- c #D8D8D8", |
70 | "; c #FFFFFF", | 70 | "; c #FFFFFF", |
71 | "> c #DBDBDB", | 71 | "> c #DBDBDB", |
72 | ", c #636363", | 72 | ", c #636363", |
73 | "' c #989898", | 73 | "' c #989898", |
74 | ") c #2D2D2D", | 74 | ") c #2D2D2D", |
75 | "! c #909090", | 75 | "! c #909090", |
76 | "~ c #AEAEAE", | 76 | "~ c #AEAEAE", |
77 | "{ c #EAEAEA", | 77 | "{ c #EAEAEA", |
78 | "] c #575757", | 78 | "] c #575757", |
79 | "^ c #585858", | 79 | "^ c #585858", |
80 | "/ c #8A8A8A", | 80 | "/ c #8A8A8A", |
81 | "( c #828282", | 81 | "( c #828282", |
82 | "_ c #6F6F6F", | 82 | "_ c #6F6F6F", |
83 | ": c #C9C9C9", | 83 | ": c #C9C9C9", |
84 | "< c #050505", | 84 | "< c #050505", |
85 | "[ c #292929", | 85 | "[ c #292929", |
86 | "} c #777777", | 86 | "} c #777777", |
87 | "| c #616161", | 87 | "| c #616161", |
88 | "1 c #3A3A3A", | 88 | "1 c #3A3A3A", |
89 | "2 c #BEBEBE", | 89 | "2 c #BEBEBE", |
90 | "3 c #2C2C2C", | 90 | "3 c #2C2C2C", |
91 | "4 c #7C7C7C", | 91 | "4 c #7C7C7C", |
92 | "5 c #F6F6F6", | 92 | "5 c #F6F6F6", |
93 | "6 c #FCFCFC", | 93 | "6 c #FCFCFC", |
94 | "7 c #6B6B6B", | 94 | "7 c #6B6B6B", |
95 | "8 c #959595", | 95 | "8 c #959595", |
96 | "9 c #4F4F4F", | 96 | "9 c #4F4F4F", |
97 | "0 c #808080", | 97 | "0 c #808080", |
98 | "a c #767676", | 98 | "a c #767676", |
99 | "b c #818181", | 99 | "b c #818181", |
100 | "c c #B8B8B8", | 100 | "c c #B8B8B8", |
101 | "d c #FBFBFB", | 101 | "d c #FBFBFB", |
102 | "e c #F9F9F9", | 102 | "e c #F9F9F9", |
103 | "f c #CCCCCC", | 103 | "f c #CCCCCC", |
104 | "g c #030303", | 104 | "g c #030303", |
105 | "h c #737373", | 105 | "h c #737373", |
106 | "i c #7A7A7A", | 106 | "i c #7A7A7A", |
107 | "j c #7E7E7E", | 107 | "j c #7E7E7E", |
108 | "k c #6A6A6A", | 108 | "k c #6A6A6A", |
109 | "l c #FAFAFA", | 109 | "l c #FAFAFA", |
110 | "m c #505050", | 110 | "m c #505050", |
111 | "n c #9D9D9D", | 111 | "n c #9D9D9D", |
112 | "o c #333333", | 112 | "o c #333333", |
113 | "p c #7B7B7B", | 113 | "p c #7B7B7B", |
114 | "q c #787878", | 114 | "q c #787878", |
115 | "r c #696969", | 115 | "r c #696969", |
116 | "s c #494949", | 116 | "s c #494949", |
117 | "t c #555555", | 117 | "t c #555555", |
118 | "u c #949494", | 118 | "u c #949494", |
119 | "v c #E6E6E6", | 119 | "v c #E6E6E6", |
120 | "w c #424242", | 120 | "w c #424242", |
121 | "x c #515151", | 121 | "x c #515151", |
122 | "y c #535353", | 122 | "y c #535353", |
123 | "z c #3E3E3E", | 123 | "z c #3E3E3E", |
124 | "A c #D4D4D4", | 124 | "A c #D4D4D4", |
125 | "B c #0C0C0C", | 125 | "B c #0C0C0C", |
126 | "C c #353535", | 126 | "C c #353535", |
127 | "D c #474747", | 127 | "D c #474747", |
128 | "E c #ECECEC", | 128 | "E c #ECECEC", |
129 | "F c #919191", | 129 | "F c #919191", |
130 | "G c #7D7D7D", | 130 | "G c #7D7D7D", |
131 | "H c #000000", | 131 | "H c #000000", |
132 | "I c #404040", | 132 | "I c #404040", |
133 | "J c #858585", | 133 | "J c #858585", |
134 | "K c #323232", | 134 | "K c #323232", |
135 | "L c #D0D0D0", | 135 | "L c #D0D0D0", |
136 | "M c #1C1C1C", | 136 | "M c #1C1C1C", |
137 | " ...+ ", | 137 | " ...+ ", |
138 | " @#$%&..+ ", | 138 | " @#$%&..+ ", |
139 | " .*=-;;>,..+ ", | 139 | " .*=-;;>,..+ ", |
140 | " ')!~;;;;;;{]..", | 140 | " ')!~;;;;;;{]..", |
141 | " ^/(-;;;;;;;_:<", | 141 | " ^/(-;;;;;;;_:<", |
142 | " [}|;;;;;;;{12$", | 142 | " [}|;;;;;;;{12$", |
143 | " #34-55;;;;678$+", | 143 | " #34-55;;;;678$+", |
144 | " 90ab=c;dd;e1fg ", | 144 | " 90ab=c;dd;e1fg ", |
145 | " [ahij((kbl0mn$ ", | 145 | " [ahij((kbl0mn$ ", |
146 | " op^q^^7r&]s/$+ ", | 146 | " op^q^^7r&]s/$+ ", |
147 | "@btu;vbwxy]zAB ", | 147 | "@btu;vbwxy]zAB ", |
148 | "CzDEvEv;;DssF$ ", | 148 | "CzDEvEv;;DssF$ ", |
149 | "G.H{E{E{IxsJ$+ ", | 149 | "G.H{E{E{IxsJ$+ ", |
150 | " +...vEKxzLM ", | 150 | " +...vEKxzLM ", |
151 | " +...z]n$ ", | 151 | " +...z]n$ ", |
152 | " +... "}; | 152 | " +... "}; |
153 | 153 | ||
154 | 154 | ||
155 | #if QT_VERSION < 300 | 155 | #if QT_VERSION < 300 |
156 | 156 | ||
157 | class QpeEditor : public QMultiLineEdit | 157 | class QpeEditor : public QMultiLineEdit |
158 | { | 158 | { |
159 | // Q_OBJECT | 159 | // Q_OBJECT |
160 | public: | 160 | public: |
161 | QpeEditor( QWidget *parent, const char * name = 0 ) | 161 | QpeEditor( QWidget *parent, const char * name = 0 ) |
162 | : QMultiLineEdit( parent, name ) | 162 | : QMultiLineEdit( parent, name ) |
163 | { | 163 | { |
164 | clearTableFlags(); | 164 | clearTableFlags(); |
165 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 165 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
166 | } | 166 | } |
167 | 167 | ||
168 | //public slots: | 168 | //public slots: |
169 | void find( const QString &txt, bool caseSensitive, | 169 | void find( const QString &txt, bool caseSensitive, |
170 | bool backwards ); | 170 | bool backwards ); |
171 | /* | 171 | /* |
172 | signals: | 172 | signals: |
173 | void notFound(); | 173 | void notFound(); |
174 | void searchWrapped(); | 174 | void searchWrapped(); |
175 | */ | 175 | */ |
176 | 176 | ||
177 | private: | 177 | private: |
178 | 178 | ||
179 | }; | 179 | }; |
180 | 180 | ||
181 | 181 | ||
182 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 182 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
183 | bool backwards ) | 183 | bool backwards ) |
184 | { | 184 | { |
185 | static bool wrap = FALSE; | 185 | static bool wrap = FALSE; |
186 | int line, col; | 186 | int line, col; |
187 | if ( wrap ) { | 187 | if ( wrap ) { |
188 | if ( !backwards ) | 188 | if ( !backwards ) |
189 | line = col = 0; | 189 | line = col = 0; |
190 | wrap = FALSE; | 190 | wrap = FALSE; |
191 | // emit searchWrapped(); | 191 | // emit searchWrapped(); |
192 | } else { | 192 | } else { |
193 | getCursorPosition( &line, &col ); | 193 | getCursorPosition( &line, &col ); |
194 | } | 194 | } |
195 | //ignore backwards for now.... | 195 | //ignore backwards for now.... |
196 | if ( !backwards ) { | 196 | if ( !backwards ) { |
197 | for ( ; ; ) { | 197 | for ( ; ; ) { |
198 | if ( line >= numLines() ) { | 198 | if ( line >= numLines() ) { |
199 | wrap = TRUE; | 199 | wrap = TRUE; |
200 | //emit notFound(); | 200 | //emit notFound(); |
201 | break; | 201 | break; |
202 | } | 202 | } |
203 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 203 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
204 | if ( findCol >= 0 ) { | 204 | if ( findCol >= 0 ) { |
205 | setCursorPosition( line, findCol, FALSE ); | 205 | setCursorPosition( line, findCol, FALSE ); |
206 | col = findCol + txt.length(); | 206 | col = findCol + txt.length(); |
207 | setCursorPosition( line, col, TRUE ); | 207 | setCursorPosition( line, col, TRUE ); |
208 | 208 | ||
209 | //found = TRUE; | 209 | //found = TRUE; |
210 | break; | 210 | break; |
211 | } | 211 | } |
212 | line++; | 212 | line++; |
213 | col = 0; | 213 | col = 0; |
214 | } | 214 | } |
215 | 215 | ||
216 | } | 216 | } |
217 | 217 | ||
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | #else | 221 | #else |
222 | 222 | ||
223 | #error "Must make a QpeEditor that inherits QTextEdit" | 223 | #error "Must make a QpeEditor that inherits QTextEdit" |
224 | 224 | ||
225 | #endif | 225 | #endif |
226 | 226 | ||
227 | 227 | ||
228 | 228 | ||
229 | 229 | ||
230 | static int u_id = 1; | 230 | static int u_id = 1; |
231 | static int get_unique_id() | 231 | static int get_unique_id() |
232 | { | 232 | { |
233 | return u_id++; | 233 | return u_id++; |
234 | } | 234 | } |
235 | 235 | ||
236 | static const int nfontsizes = 6; | 236 | static const int nfontsizes = 6; |
237 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 237 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
238 | 238 | ||
239 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 239 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
240 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 240 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) |
241 | { | 241 | { |
242 | doc = 0; | 242 | doc = 0; |
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 ); |
268 | a->addTo( file ); | 268 | a->addTo( file ); |
269 | 269 | ||
270 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 270 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
271 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); | 271 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); |
272 | a->addTo( bar ); | 272 | a->addTo( bar ); |
273 | a->addTo( file ); | 273 | a->addTo( file ); |
274 | 274 | ||
275 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 275 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
276 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 276 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
277 | // a->addTo( bar ); | 277 | // a->addTo( bar ); |
278 | file->insertSeparator(); | 278 | file->insertSeparator(); |
279 | a->addTo( file ); | 279 | a->addTo( file ); |
280 | 280 | ||
281 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 281 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
282 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 282 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
283 | a->addTo( file ); | 283 | a->addTo( file ); |
284 | 284 | ||
285 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 285 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
286 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 286 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
287 | a->addTo( editBar ); | 287 | a->addTo( editBar ); |
288 | a->addTo( edit ); | 288 | a->addTo( edit ); |
289 | 289 | ||
290 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 290 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
291 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 291 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
292 | a->addTo( editBar ); | 292 | a->addTo( editBar ); |
293 | a->addTo( edit ); | 293 | a->addTo( edit ); |
294 | 294 | ||
295 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 295 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
296 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 296 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
297 | a->addTo( editBar ); | 297 | a->addTo( editBar ); |
298 | a->addTo( edit ); | 298 | a->addTo( edit ); |
299 | 299 | ||
300 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 300 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
301 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 301 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
302 | edit->insertSeparator(); | 302 | edit->insertSeparator(); |
303 | a->addTo( bar ); | 303 | a->addTo( bar ); |
304 | a->addTo( edit ); | 304 | a->addTo( edit ); |
305 | 305 | ||
306 | 306 | ||
307 | int defsize; | 307 | int defsize; |
308 | bool defb, defi, wrap; | 308 | bool defb, defi, wrap; |
309 | 309 | ||
310 | Config cfg("TextEdit"); | 310 | Config cfg("TextEdit"); |
311 | cfg.setGroup("View"); | 311 | cfg.setGroup("View"); |
312 | defsize = cfg.readNumEntry("FontSize",10); | 312 | defsize = cfg.readNumEntry("FontSize",10); |
313 | defb = cfg.readBoolEntry("Bold",FALSE); | 313 | defb = cfg.readBoolEntry("Bold",FALSE); |
314 | defi = cfg.readBoolEntry("Italic",FALSE); | 314 | defi = cfg.readBoolEntry("Italic",FALSE); |
315 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 315 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
316 | 316 | ||
317 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 317 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
318 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 318 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
319 | zin->addTo( font ); | 319 | zin->addTo( font ); |
320 | 320 | ||
321 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 321 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
322 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 322 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
323 | zout->addTo( font ); | 323 | zout->addTo( font ); |
324 | 324 | ||
325 | font->insertSeparator(); | 325 | font->insertSeparator(); |
326 | 326 | ||
327 | #if 0 | 327 | #if 0 |
328 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 328 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
329 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 329 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
330 | ba->setToggleAction(TRUE); | 330 | ba->setToggleAction(TRUE); |
331 | ba->addTo( font ); | 331 | ba->addTo( font ); |
332 | 332 | ||
333 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 333 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
334 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | 334 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); |
335 | ia->setToggleAction(TRUE); | 335 | ia->setToggleAction(TRUE); |
336 | ia->addTo( font ); | 336 | ia->addTo( font ); |
337 | 337 | ||
338 | ba->setOn(defb); | 338 | ba->setOn(defb); |
339 | ia->setOn(defi); | 339 | ia->setOn(defi); |
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 & ) ), |
364 | this, SLOT( search() ) ); | 370 | this, SLOT( search() ) ); |
365 | 371 | ||
366 | 372 | ||
367 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 373 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
368 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 374 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
369 | a->addTo( searchBar ); | 375 | a->addTo( searchBar ); |
370 | a->addTo( edit ); | 376 | a->addTo( edit ); |
371 | 377 | ||
372 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 378 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
373 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 379 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
374 | a->addTo( searchBar ); | 380 | a->addTo( searchBar ); |
375 | 381 | ||
376 | edit->insertSeparator(); | 382 | edit->insertSeparator(); |
377 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 383 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
378 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 384 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
379 | a->addTo( edit ); | 385 | a->addTo( edit ); |
380 | 386 | ||
381 | searchBar->hide(); | 387 | searchBar->hide(); |
382 | 388 | ||
383 | editorStack = new QWidgetStack( this ); | 389 | editorStack = new QWidgetStack( this ); |
384 | setCentralWidget( editorStack ); | 390 | setCentralWidget( editorStack ); |
385 | 391 | ||
386 | searchVisible = FALSE; | 392 | searchVisible = FALSE; |
387 | 393 | ||
388 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy | 394 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy |
389 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 395 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
390 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 396 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
391 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 397 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); |
392 | // fileOpen(); | 398 | // fileOpen(); |
393 | 399 | ||
394 | editor = new QpeEditor( editorStack ); | 400 | editor = new QpeEditor( editorStack ); |
395 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 401 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
396 | editorStack->addWidget( editor, get_unique_id() ); | 402 | editorStack->addWidget( editor, get_unique_id() ); |
397 | 403 | ||
398 | resize( 200, 300 ); | 404 | resize( 200, 300 ); |
399 | 405 | ||
400 | // setFontSize(defsize,TRUE); | 406 | // setFontSize(defsize,TRUE); |
401 | FontDatabase fdb; | 407 | FontDatabase fdb; |
402 | QFont defaultFont=editor->font(); | 408 | QFont defaultFont=editor->font(); |
403 | QFontInfo fontInfo(defaultFont); | 409 | QFontInfo fontInfo(defaultFont); |
404 | 410 | ||
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 | ||
420 | TextEdit::~TextEdit() | 433 | TextEdit::~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()); |
430 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 443 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
431 | } | 444 | } |
432 | 445 | ||
433 | void TextEdit::zoomIn() | 446 | void TextEdit::zoomIn() |
434 | { | 447 | { |
435 | setFontSize(editor->font().pointSize()+1,FALSE); | 448 | setFontSize(editor->font().pointSize()+1,FALSE); |
436 | } | 449 | } |
437 | 450 | ||
438 | void TextEdit::zoomOut() | 451 | void TextEdit::zoomOut() |
439 | { | 452 | { |
440 | setFontSize(editor->font().pointSize()-1,TRUE); | 453 | setFontSize(editor->font().pointSize()-1,TRUE); |
441 | } | 454 | } |
442 | 455 | ||
443 | 456 | ||
444 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 457 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
445 | { | 458 | { |
446 | int s=10; | 459 | int s=10; |
447 | for (int i=0; i<nfontsizes; i++) { | 460 | for (int i=0; i<nfontsizes; i++) { |
448 | if ( fontsize[i] == sz ) { | 461 | if ( fontsize[i] == sz ) { |
449 | s = sz; | 462 | s = sz; |
450 | break; | 463 | break; |
451 | } else if ( round_down_not_up ) { | 464 | } else if ( round_down_not_up ) { |
452 | if ( fontsize[i] < sz ) | 465 | if ( fontsize[i] < sz ) |
453 | s = fontsize[i]; | 466 | s = fontsize[i]; |
454 | } else { | 467 | } else { |
455 | if ( fontsize[i] > sz ) { | 468 | if ( fontsize[i] > sz ) { |
456 | s = fontsize[i]; | 469 | s = fontsize[i]; |
457 | break; | 470 | break; |
458 | } | 471 | } |
459 | } | 472 | } |
460 | } | 473 | } |
461 | 474 | ||
462 | QFont f = editor->font(); | 475 | QFont f = editor->font(); |
463 | f.setPointSize(s); | 476 | f.setPointSize(s); |
464 | editor->setFont(f); | 477 | editor->setFont(f); |
465 | 478 | ||
466 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 479 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
467 | zout->setEnabled(s != fontsize[0]); | 480 | zout->setEnabled(s != fontsize[0]); |
468 | } | 481 | } |
469 | 482 | ||
470 | void TextEdit::setBold(bool y) | 483 | void TextEdit::setBold(bool y) |
471 | { | 484 | { |
472 | QFont f = editor->font(); | 485 | QFont f = editor->font(); |
473 | f.setBold(y); | 486 | f.setBold(y); |
474 | editor->setFont(f); | 487 | editor->setFont(f); |
475 | } | 488 | } |
476 | 489 | ||
477 | void TextEdit::setItalic(bool y) | 490 | void TextEdit::setItalic(bool y) |
478 | { | 491 | { |
479 | QFont f = editor->font(); | 492 | QFont f = editor->font(); |
480 | f.setItalic(y); | 493 | f.setItalic(y); |
481 | editor->setFont(f); | 494 | editor->setFont(f); |
482 | } | 495 | } |
483 | 496 | ||
484 | void TextEdit::setWordWrap(bool y) | 497 | void TextEdit::setWordWrap(bool y) |
485 | { | 498 | { |
486 | bool state = editor->edited(); | 499 | bool state = editor->edited(); |
487 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 500 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
488 | editor->setEdited( state ); | 501 | editor->setEdited( state ); |
489 | } | 502 | } |
490 | 503 | ||
491 | void TextEdit::fileNew() | 504 | void TextEdit::fileNew() |
492 | { | 505 | { |
493 | if( !bFromDocView ) { | 506 | if( !bFromDocView ) { |
494 | saveAs(); | 507 | saveAs(); |
495 | } | 508 | } |
496 | newFile(DocLnk()); | 509 | newFile(DocLnk()); |
497 | } | 510 | } |
498 | 511 | ||
499 | void TextEdit::fileOpen() | 512 | void TextEdit::fileOpen() |
500 | { | 513 | { |
501 | // if ( !save() ) { | 514 | // if ( !save() ) { |
502 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 515 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
503 | // tr( "Text Editor was unable to\n" | 516 | // tr( "Text Editor was unable to\n" |
504 | // "save your changes.\n" | 517 | // "save your changes.\n" |
505 | // "Free some space and try again.\n" | 518 | // "Free some space and try again.\n" |
506 | // "\nContinue anyway?" ), | 519 | // "\nContinue anyway?" ), |
507 | // QMessageBox::Yes|QMessageBox::Escape, | 520 | // QMessageBox::Yes|QMessageBox::Escape, |
508 | // QMessageBox::No|QMessageBox::Default ) | 521 | // QMessageBox::No|QMessageBox::Default ) |
509 | // != QMessageBox::Yes ) | 522 | // != QMessageBox::Yes ) |
510 | // return; | 523 | // return; |
511 | // else { | 524 | // else { |
512 | // delete doc; | 525 | // delete doc; |
513 | // doc = 0; | 526 | // doc = 0; |
514 | // } | 527 | // } |
515 | // } | 528 | // } |
516 | menu->hide(); | 529 | menu->hide(); |
517 | editBar->hide(); | 530 | editBar->hide(); |
518 | searchBar->hide(); | 531 | searchBar->hide(); |
519 | clearWState (WState_Reserved1 ); | 532 | clearWState (WState_Reserved1 ); |
520 | editorStack->raiseWidget( fileSelector ); | 533 | editorStack->raiseWidget( fileSelector ); |
521 | fileSelector->reread(); | 534 | fileSelector->reread(); |
522 | updateCaption(); | 535 | updateCaption(); |
523 | } | 536 | } |
524 | 537 | ||
525 | void TextEdit::newFileOpen() | 538 | void TextEdit::newFileOpen() |
526 | { | 539 | { |
527 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); | 540 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); |
528 | if( browseForFiles->exec() != -1 ) { | 541 | if( browseForFiles->exec() != -1 ) { |
529 | QString selFile= browseForFiles->selectedFileName; | 542 | QString selFile= browseForFiles->selectedFileName; |
530 | QStringList fileList=browseForFiles->fileList; | 543 | QStringList fileList=browseForFiles->fileList; |
531 | qDebug(selFile); | 544 | qDebug(selFile); |
532 | QStringList::ConstIterator f; | 545 | QStringList::ConstIterator f; |
533 | QString fileTemp; | 546 | QString fileTemp; |
534 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 547 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
535 | fileTemp = *f; | 548 | fileTemp = *f; |
536 | fileTemp.right( fileTemp.length()-5); | 549 | fileTemp.right( fileTemp.length()-5); |
537 | QString fileName = fileTemp; | 550 | QString fileName = fileTemp; |
538 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 551 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
539 | currentFileName = fileName; | 552 | currentFileName = fileName; |
540 | qDebug("please open "+currentFileName); | 553 | qDebug("please open "+currentFileName); |
541 | openFile(fileName ); | 554 | openFile(fileName ); |
542 | } | 555 | } |
543 | } | 556 | } |
544 | } | 557 | } |
545 | delete browseForFiles; | 558 | delete browseForFiles; |
546 | editor->setEdited( true ); | 559 | editor->setEdited( true ); |
547 | } | 560 | } |
548 | 561 | ||
549 | #if 0 | 562 | #if 0 |
550 | void TextEdit::slotFind() | 563 | void TextEdit::slotFind() |
551 | { | 564 | { |
552 | FindDialog frmFind( "Text Editor", this ); | 565 | FindDialog frmFind( "Text Editor", this ); |
553 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 566 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
554 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 567 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
555 | 568 | ||
556 | //case sensitive, backwards, [category] | 569 | //case sensitive, backwards, [category] |
557 | 570 | ||
558 | connect( editor, SIGNAL(notFound()), | 571 | connect( editor, SIGNAL(notFound()), |
559 | &frmFind, SLOT(slotNotFound()) ); | 572 | &frmFind, SLOT(slotNotFound()) ); |
560 | connect( editor, SIGNAL(searchWrapped()), | 573 | connect( editor, SIGNAL(searchWrapped()), |
561 | &frmFind, SLOT(slotWrapAround()) ); | 574 | &frmFind, SLOT(slotWrapAround()) ); |
562 | 575 | ||
563 | frmFind.exec(); | 576 | frmFind.exec(); |
564 | 577 | ||
565 | 578 | ||
566 | } | 579 | } |
567 | #endif | 580 | #endif |
568 | 581 | ||
569 | void TextEdit::fileRevert() | 582 | void TextEdit::fileRevert() |
570 | { | 583 | { |
571 | clear(); | 584 | clear(); |
572 | fileOpen(); | 585 | fileOpen(); |
573 | } | 586 | } |
574 | 587 | ||
575 | void TextEdit::editCut() | 588 | void TextEdit::editCut() |
576 | { | 589 | { |
577 | #ifndef QT_NO_CLIPBOARD | 590 | #ifndef QT_NO_CLIPBOARD |
578 | editor->cut(); | 591 | editor->cut(); |
579 | #endif | 592 | #endif |
580 | } | 593 | } |
581 | 594 | ||
582 | void TextEdit::editCopy() | 595 | void TextEdit::editCopy() |
583 | { | 596 | { |
584 | #ifndef QT_NO_CLIPBOARD | 597 | #ifndef QT_NO_CLIPBOARD |
585 | editor->copy(); | 598 | editor->copy(); |
586 | #endif | 599 | #endif |
587 | } | 600 | } |
588 | 601 | ||
589 | void TextEdit::editPaste() | 602 | void TextEdit::editPaste() |
590 | { | 603 | { |
591 | #ifndef QT_NO_CLIPBOARD | 604 | #ifndef QT_NO_CLIPBOARD |
592 | editor->paste(); | 605 | editor->paste(); |
593 | #endif | 606 | #endif |
594 | } | 607 | } |
595 | 608 | ||
596 | void TextEdit::editFind() | 609 | void TextEdit::editFind() |
597 | { | 610 | { |
598 | searchBar->show(); | 611 | searchBar->show(); |
599 | searchVisible = TRUE; | 612 | searchVisible = TRUE; |
600 | searchEdit->setFocus(); | 613 | searchEdit->setFocus(); |
601 | } | 614 | } |
602 | 615 | ||
603 | void TextEdit::findNext() | 616 | void TextEdit::findNext() |
604 | { | 617 | { |
605 | editor->find( searchEdit->text(), FALSE, FALSE ); | 618 | editor->find( searchEdit->text(), FALSE, FALSE ); |
606 | 619 | ||
607 | } | 620 | } |
608 | 621 | ||
609 | void TextEdit::findClose() | 622 | void TextEdit::findClose() |
610 | { | 623 | { |
611 | searchVisible = FALSE; | 624 | searchVisible = FALSE; |
612 | searchBar->hide(); | 625 | searchBar->hide(); |
613 | } | 626 | } |
614 | 627 | ||
615 | void TextEdit::search() | 628 | void TextEdit::search() |
616 | { | 629 | { |
617 | editor->find( searchEdit->text(), FALSE, FALSE ); | 630 | editor->find( searchEdit->text(), FALSE, FALSE ); |
618 | } | 631 | } |
619 | 632 | ||
620 | void TextEdit::newFile( const DocLnk &f ) | 633 | void TextEdit::newFile( const DocLnk &f ) |
621 | { | 634 | { |
622 | DocLnk nf = f; | 635 | DocLnk nf = f; |
623 | nf.setType("text/plain"); | 636 | nf.setType("text/plain"); |
624 | clear(); | 637 | clear(); |
625 | editorStack->raiseWidget( editor ); | 638 | editorStack->raiseWidget( editor ); |
626 | setWState (WState_Reserved1 ); | 639 | setWState (WState_Reserved1 ); |
627 | editor->setFocus(); | 640 | editor->setFocus(); |
628 | doc = new DocLnk(nf); | 641 | doc = new DocLnk(nf); |
629 | qDebug("newFile "+currentFileName); | 642 | qDebug("newFile "+currentFileName); |
630 | updateCaption(currentFileName); | 643 | updateCaption(currentFileName); |
631 | } | 644 | } |
632 | 645 | ||
633 | void TextEdit::openFile( const QString &f ) | 646 | void TextEdit::openFile( const QString &f ) |
634 | { | 647 | { |
635 | bFromDocView = TRUE; | 648 | bFromDocView = TRUE; |
636 | DocLnk nf; | 649 | DocLnk nf; |
637 | nf.setType("text/plain"); | 650 | nf.setType("text/plain"); |
638 | nf.setFile(f); | 651 | nf.setFile(f); |
639 | currentFileName=f; | 652 | currentFileName=f; |
640 | QFileInfo fi( currentFileName); | 653 | QFileInfo fi( currentFileName); |
641 | nf.setName(fi.baseName()); | 654 | nf.setName(fi.baseName()); |
642 | qDebug("openFile string"+currentFileName); | 655 | qDebug("openFile string"+currentFileName); |
643 | 656 | ||
644 | openFile(nf); | 657 | openFile(nf); |
645 | showEditTools(); | 658 | showEditTools(); |
646 | // Show filename in caption | 659 | // Show filename in caption |
647 | QString name = f; | 660 | QString name = f; |
648 | int sep = name.findRev( '/' ); | 661 | int sep = name.findRev( '/' ); |
649 | if ( sep > 0 ) | 662 | if ( sep > 0 ) |
650 | name = name.mid( sep+1 ); | 663 | name = name.mid( sep+1 ); |
651 | updateCaption( name ); | 664 | updateCaption( name ); |
652 | } | 665 | } |
653 | 666 | ||
654 | void TextEdit::openFile( const DocLnk &f ) | 667 | void TextEdit::openFile( const DocLnk &f ) |
655 | { | 668 | { |
656 | // clear(); | 669 | // clear(); |
657 | bFromDocView = TRUE; | 670 | bFromDocView = TRUE; |
658 | FileManager fm; | 671 | FileManager fm; |
659 | QString txt; | 672 | QString txt; |
660 | currentFileName=f.name(); | 673 | currentFileName=f.name(); |
661 | qDebug("openFile doclnk " + currentFileName); | 674 | qDebug("openFile doclnk " + currentFileName); |
662 | if ( !fm.loadFile( f, txt ) ) { | 675 | if ( !fm.loadFile( f, txt ) ) { |
663 | // ####### could be a new file | 676 | // ####### could be a new file |
664 | qDebug( "Cannot open file" ); | 677 | qDebug( "Cannot open file" ); |
665 | 678 | ||
666 | //return; | 679 | //return; |
667 | } | 680 | } |
668 | 681 | ||
669 | fileNew(); | 682 | fileNew(); |
670 | if ( doc ) | 683 | if ( doc ) |
671 | delete doc; | 684 | delete doc; |
672 | doc = new DocLnk(f); | 685 | doc = new DocLnk(f); |
673 | editor->setText(txt); | 686 | editor->setText(txt); |
674 | editor->setEdited( false); | 687 | editor->setEdited( false); |
675 | qDebug("openFile doclnk "+currentFileName); | 688 | qDebug("openFile doclnk "+currentFileName); |
676 | doc->setName(currentFileName); | 689 | doc->setName(currentFileName); |
677 | updateCaption(); | 690 | updateCaption(); |
678 | } | 691 | } |
679 | 692 | ||
680 | void TextEdit::showEditTools() | 693 | void TextEdit::showEditTools() |
681 | { | 694 | { |
682 | // if ( !doc ) | 695 | // if ( !doc ) |
683 | // close(); | 696 | // close(); |
684 | // clear(); | 697 | // clear(); |
685 | fileSelector->hide(); | 698 | fileSelector->hide(); |
686 | menu->show(); | 699 | menu->show(); |
687 | editBar->show(); | 700 | editBar->show(); |
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 */ |
697 | bool TextEdit::save() | 710 | bool 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 */ |
724 | bool TextEdit::saveAs() | 745 | bool 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"); |
732 | // return true; | 753 | // return true; |
733 | // } | 754 | // } |
734 | if ( !editor->edited() ) { | 755 | if ( !editor->edited() ) { |
735 | delete doc; | 756 | delete doc; |
736 | doc = 0; | 757 | doc = 0; |
737 | return true; | 758 | return true; |
738 | } | 759 | } |
739 | 760 | ||
740 | QString rt = editor->text(); | 761 | QString rt = editor->text(); |
741 | qDebug(currentFileName); | 762 | qDebug(currentFileName); |
742 | 763 | ||
743 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 764 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
744 | qDebug("do silly TT filename thing"); | 765 | qDebug("do silly TT filename thing"); |
745 | if ( doc->name().isEmpty() ) { | 766 | if ( doc->name().isEmpty() ) { |
746 | QString pt = rt.simplifyWhiteSpace(); | 767 | QString pt = rt.simplifyWhiteSpace(); |
747 | int i = pt.find( ' ' ); | 768 | int i = pt.find( ' ' ); |
748 | QString docname = pt; | 769 | QString docname = pt; |
749 | if ( i > 0 ) | 770 | if ( i > 0 ) |
750 | docname = pt.left( i ); | 771 | docname = pt.left( i ); |
751 | // remove "." at the beginning | 772 | // remove "." at the beginning |
752 | while( docname.startsWith( "." ) ) | 773 | while( docname.startsWith( "." ) ) |
753 | docname = docname.mid( 1 ); | 774 | docname = docname.mid( 1 ); |
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 ); |
797 | if( filePerm) | 817 | if( filePerm) |
798 | delete filePerm; | 818 | delete filePerm; |
799 | } | 819 | } |
800 | } | 820 | } |
801 | } | 821 | } |
802 | 822 | ||
803 | if(fileSaveDlg) | 823 | if(fileSaveDlg) |
804 | delete fileSaveDlg; | 824 | delete fileSaveDlg; |
805 | return true; | 825 | return true; |
806 | } | 826 | } |
807 | 827 | ||
808 | void TextEdit::clear() | 828 | void TextEdit::clear() |
809 | { | 829 | { |
810 | delete doc; | 830 | delete doc; |
811 | doc = 0; | 831 | doc = 0; |
812 | editor->clear(); | 832 | editor->clear(); |
813 | } | 833 | } |
814 | 834 | ||
815 | void TextEdit::updateCaption( const QString &name ) | 835 | void TextEdit::updateCaption( const QString &name ) |
816 | { | 836 | { |
817 | if ( !doc ) | 837 | if ( !doc ) |
818 | setCaption( tr("Text Editor") ); | 838 | setCaption( tr("Text Editor") ); |
819 | else { | 839 | else { |
820 | QString s = name; | 840 | QString s = name; |
821 | if ( s.isNull() ) | 841 | if ( s.isNull() ) |
822 | s = doc->name(); | 842 | s = doc->name(); |
823 | if ( s.isEmpty() ) { | 843 | if ( s.isEmpty() ) { |
824 | s = tr( "Unnamed" ); | 844 | s = tr( "Unnamed" ); |
825 | currentFileName=s; | 845 | currentFileName=s; |
826 | } | 846 | } |
827 | 847 | ||
828 | setCaption( s + " - " + tr("Text Editor") ); | 848 | setCaption( s + " - " + tr("Text Editor") ); |
829 | } | 849 | } |
830 | } | 850 | } |
831 | 851 | ||
832 | void TextEdit::setDocument(const QString& fileref) | 852 | void TextEdit::setDocument(const QString& fileref) |
833 | { | 853 | { |
834 | bFromDocView = TRUE; | 854 | bFromDocView = TRUE; |
835 | qDebug("setDocument "+fileref); | 855 | qDebug("setDocument "+fileref); |
836 | bFromDocView = TRUE; | 856 | bFromDocView = TRUE; |
837 | if(fileref.find(".desktop",0,TRUE) == -1) { | 857 | if(fileref.find(".desktop",0,TRUE) == -1) { |
838 | openFile(fileref); | 858 | openFile(fileref); |
839 | } else { | 859 | } else { |
840 | openFile(DocLnk(fileref)); | 860 | openFile(DocLnk(fileref)); |
841 | } | 861 | } |
842 | } | 862 | } |
843 | 863 | ||
844 | void TextEdit::closeEvent( QCloseEvent *e ) | 864 | void TextEdit::closeEvent( QCloseEvent *e ) |
845 | { | 865 | { |
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 | ||
857 | void TextEdit::accept() | 877 | void 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 | ||
864 | void TextEdit::changeFont() { | 889 | void 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()) ); |
874 | 899 | ||
875 | defaultFont = fdb.font(family,style,i_size,charSet); | 900 | defaultFont = fdb.font(family,style,i_size,charSet); |
876 | 901 | ||
877 | FontDialog *fontDlg; | 902 | FontDialog *fontDlg; |
878 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 903 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
879 | 904 | ||
880 | fontDlg->exec(); | 905 | fontDlg->exec(); |
881 | 906 | ||
882 | QFont myFont=fontDlg->selectedFont; | 907 | QFont myFont=fontDlg->selectedFont; |
883 | editor->setFont( myFont); | 908 | editor->setFont( myFont); |
884 | delete fontDlg; | 909 | delete fontDlg; |
885 | 910 | ||
886 | } | 911 | } |
887 | 912 | ||
888 | void TextEdit::editDelete() | 913 | void TextEdit::editDelete() |
889 | { | 914 | { |
890 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { | 915 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { |
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 | |||
929 | void 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 | |||
@@ -1,114 +1,118 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 | 20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 |
21 | 21 | ||
22 | #ifndef TEXTEDIT_H | 22 | #ifndef TEXTEDIT_H |
23 | #define TEXTEDIT_H | 23 | #define TEXTEDIT_H |
24 | 24 | ||
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 | ||
37 | class QAction; | ||
37 | class QWidgetStack; | 38 | class QWidgetStack; |
38 | class QToolButton; | 39 | class QToolButton; |
39 | class QPopupMenu; | 40 | class QPopupMenu; |
40 | class QToolBar; | 41 | class QToolBar; |
41 | class QLineEdit; | 42 | class QLineEdit; |
42 | class QAction; | 43 | class QAction; |
43 | class FileSelector; | 44 | class FileSelector; |
44 | class QpeEditor; | 45 | class QpeEditor; |
46 | class QPopupMenu; | ||
45 | 47 | ||
46 | class TextEdit : public QMainWindow | 48 | class TextEdit : public QMainWindow |
47 | { | 49 | { |
48 | Q_OBJECT | 50 | Q_OBJECT |
49 | 51 | ||
50 | public: | 52 | public: |
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 | ||
56 | protected: | 59 | protected: |
57 | void closeEvent( QCloseEvent *e ); | 60 | void closeEvent( QCloseEvent *e ); |
58 | 61 | ||
59 | private slots: | 62 | private 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(); |
78 | 82 | ||
79 | void search(); | 83 | void search(); |
80 | void accept(); | 84 | void accept(); |
81 | 85 | ||
82 | void newFile( const DocLnk & ); | 86 | void newFile( const DocLnk & ); |
83 | void openFile( const DocLnk & ); | 87 | void openFile( const DocLnk & ); |
84 | void showEditTools(); | 88 | void showEditTools(); |
85 | 89 | ||
86 | void zoomIn(); | 90 | void zoomIn(); |
87 | void zoomOut(); | 91 | void zoomOut(); |
88 | void setBold(bool y); | 92 | void setBold(bool y); |
89 | void setItalic(bool y); | 93 | void setItalic(bool y); |
90 | void setWordWrap(bool y); | 94 | void setWordWrap(bool y); |
91 | 95 | ||
92 | private: | 96 | private: |
93 | void colorChanged( const QColor &c ); | 97 | void colorChanged( const QColor &c ); |
94 | void clear(); | 98 | void clear(); |
95 | void updateCaption( const QString &name=QString::null ); | 99 | void updateCaption( const QString &name=QString::null ); |
96 | void setFontSize(int sz, bool round_down_not_up); | 100 | void setFontSize(int sz, bool round_down_not_up); |
97 | 101 | ||
98 | private: | 102 | private: |
99 | QWidgetStack *editorStack; | 103 | QWidgetStack *editorStack; |
100 | FileSelector *fileSelector; | 104 | FileSelector *fileSelector; |
101 | fileSaver *fileSaveDlg; | 105 | fileSaver *fileSaveDlg; |
102 | fileBrowser *browseForFiles; | 106 | fileBrowser *browseForFiles; |
103 | 107 | ||
104 | QpeEditor* editor; | 108 | QpeEditor* editor; |
105 | QToolBar *menu, *editBar, *searchBar; | 109 | QToolBar *menu, *editBar, *searchBar; |
106 | QLineEdit *searchEdit; | 110 | QLineEdit *searchEdit; |
107 | DocLnk *doc; | 111 | DocLnk *doc; |
108 | bool searchVisible; | 112 | bool searchVisible; |
109 | bool bFromDocView; | 113 | bool bFromDocView; |
110 | QAction *zin, *zout; | 114 | QAction *zin, *zout; |
111 | QString currentFileName; | 115 | QString currentFileName; |
112 | }; | 116 | }; |
113 | 117 | ||
114 | #endif | 118 | #endif |