-rw-r--r-- | core/apps/textedit/textedit.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 2a4d391..8e106bf 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -52,1163 +52,1164 @@ | |||
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qdir.h> | 53 | #include <qdir.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> |
56 | #include <stdlib.h> //getenv | 56 | #include <stdlib.h> //getenv |
57 | 57 | ||
58 | using Opie::OFileDialog; | 58 | using Opie::OFileDialog; |
59 | using Opie::OFileSelector; | 59 | using Opie::OFileSelector; |
60 | using Opie::OFontSelector; | 60 | using Opie::OFontSelector; |
61 | 61 | ||
62 | #if QT_VERSION < 300 | 62 | #if QT_VERSION < 300 |
63 | 63 | ||
64 | class QpeEditor : public QMultiLineEdit | 64 | class QpeEditor : public QMultiLineEdit |
65 | { | 65 | { |
66 | 66 | ||
67 | public: | 67 | public: |
68 | QpeEditor( QWidget *parent, const char * name = 0 ) | 68 | QpeEditor( QWidget *parent, const char * name = 0 ) |
69 | : QMultiLineEdit( parent, name ) { | 69 | : QMultiLineEdit( parent, name ) { |
70 | clearTableFlags(); | 70 | clearTableFlags(); |
71 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 71 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
72 | } | 72 | } |
73 | 73 | ||
74 | void find( const QString &txt, bool caseSensitive, | 74 | void find( const QString &txt, bool caseSensitive, |
75 | bool backwards ); | 75 | bool backwards ); |
76 | protected: | 76 | protected: |
77 | bool markIt; | 77 | bool markIt; |
78 | int line1, line2, col1, col2; | 78 | int line1, line2, col1, col2; |
79 | void mousePressEvent( QMouseEvent * ); | 79 | void mousePressEvent( QMouseEvent * ); |
80 | void mouseReleaseEvent( QMouseEvent * ); | 80 | void mouseReleaseEvent( QMouseEvent * ); |
81 | 81 | ||
82 | //public slots: | 82 | //public slots: |
83 | /* | 83 | /* |
84 | signals: | 84 | signals: |
85 | void notFound(); | 85 | void notFound(); |
86 | void searchWrapped(); | 86 | void searchWrapped(); |
87 | */ | 87 | */ |
88 | 88 | ||
89 | private: | 89 | private: |
90 | 90 | ||
91 | }; | 91 | }; |
92 | 92 | ||
93 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { | 93 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { |
94 | switch(e->button()) { | 94 | switch(e->button()) { |
95 | case RightButton: | 95 | case RightButton: |
96 | { //rediculous workaround for qt popup menu | 96 | { //rediculous workaround for qt popup menu |
97 | //and the hold right click mechanism | 97 | //and the hold right click mechanism |
98 | this->setSelection( line1, col1, line2, col2); | 98 | this->setSelection( line1, col1, line2, col2); |
99 | QMultiLineEdit::mousePressEvent( e ); | 99 | QMultiLineEdit::mousePressEvent( e ); |
100 | markIt = false; | 100 | markIt = false; |
101 | } | 101 | } |
102 | break; | 102 | break; |
103 | default: | 103 | default: |
104 | { | 104 | { |
105 | if(!markIt) { | 105 | if(!markIt) { |
106 | int line, col; | 106 | int line, col; |
107 | this->getCursorPosition(&line, &col); | 107 | this->getCursorPosition(&line, &col); |
108 | line1=line2=line; | 108 | line1=line2=line; |
109 | col1=col2=col; | 109 | col1=col2=col; |
110 | } | 110 | } |
111 | QMultiLineEdit::mousePressEvent( e ); | 111 | QMultiLineEdit::mousePressEvent( e ); |
112 | } | 112 | } |
113 | break; | 113 | break; |
114 | }; | 114 | }; |
115 | } | 115 | } |
116 | 116 | ||
117 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { | 117 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { |
118 | if(this->hasMarkedText()) { | 118 | if(this->hasMarkedText()) { |
119 | markIt = true; | 119 | markIt = true; |
120 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); | 120 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); |
121 | } else { | 121 | } else { |
122 | markIt = false; | 122 | markIt = false; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 126 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
127 | bool backwards ) | 127 | bool backwards ) |
128 | { | 128 | { |
129 | static bool wrap = false; | 129 | static bool wrap = false; |
130 | int line, col; | 130 | int line, col; |
131 | if ( wrap ) { | 131 | if ( wrap ) { |
132 | if ( !backwards ) | 132 | if ( !backwards ) |
133 | line = col = 0; | 133 | line = col = 0; |
134 | wrap = false; | 134 | wrap = false; |
135 | // emit searchWrapped(); | 135 | // emit searchWrapped(); |
136 | } else { | 136 | } else { |
137 | getCursorPosition( &line, &col ); | 137 | getCursorPosition( &line, &col ); |
138 | } | 138 | } |
139 | //ignore backwards for now.... | 139 | //ignore backwards for now.... |
140 | if ( !backwards ) { | 140 | if ( !backwards ) { |
141 | for ( ; ; ) { | 141 | for ( ; ; ) { |
142 | if ( line >= numLines() ) { | 142 | if ( line >= numLines() ) { |
143 | wrap = true; | 143 | wrap = true; |
144 | //emit notFound(); | 144 | //emit notFound(); |
145 | break; | 145 | break; |
146 | } | 146 | } |
147 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 147 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
148 | if ( findCol >= 0 ) { | 148 | if ( findCol >= 0 ) { |
149 | setCursorPosition( line, findCol, false ); | 149 | setCursorPosition( line, findCol, false ); |
150 | col = findCol + txt.length(); | 150 | col = findCol + txt.length(); |
151 | setCursorPosition( line, col, true ); | 151 | setCursorPosition( line, col, true ); |
152 | 152 | ||
153 | //found = true; | 153 | //found = true; |
154 | break; | 154 | break; |
155 | } | 155 | } |
156 | line++; | 156 | line++; |
157 | col = 0; | 157 | col = 0; |
158 | } | 158 | } |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | #else | 163 | #else |
164 | 164 | ||
165 | #error "Must make a QpeEditor that inherits QTextEdit" | 165 | #error "Must make a QpeEditor that inherits QTextEdit" |
166 | 166 | ||
167 | #endif | 167 | #endif |
168 | 168 | ||
169 | 169 | ||
170 | static const int nfontsizes = 6; | 170 | static const int nfontsizes = 6; |
171 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 171 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
172 | 172 | ||
173 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 173 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
174 | : QMainWindow( parent, name, f ), bFromDocView( false ) | 174 | : QMainWindow( parent, name, f ), bFromDocView( false ) |
175 | { | 175 | { |
176 | doc = 0; | 176 | doc = 0; |
177 | edited=false; | 177 | edited=false; |
178 | fromSetDocument=false; | 178 | fromSetDocument=false; |
179 | 179 | ||
180 | setToolBarsMovable( false ); | 180 | setToolBarsMovable( false ); |
181 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 181 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
182 | 182 | ||
183 | channel = new QCopChannel( "QPE/Application/textedit", this ); | 183 | channel = new QCopChannel( "QPE/Application/textedit", this ); |
184 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 184 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
185 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 185 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
186 | 186 | ||
187 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 187 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
188 | 188 | ||
189 | QToolBar *bar = new QToolBar( this ); | 189 | QToolBar *bar = new QToolBar( this ); |
190 | bar->setHorizontalStretchable( true ); | 190 | bar->setHorizontalStretchable( true ); |
191 | menu = bar; | 191 | menu = bar; |
192 | 192 | ||
193 | QMenuBar *mb = new QMenuBar( bar ); | 193 | QMenuBar *mb = new QMenuBar( bar ); |
194 | QPopupMenu *file = new QPopupMenu( this ); | 194 | QPopupMenu *file = new QPopupMenu( this ); |
195 | QPopupMenu *edit = new QPopupMenu( this ); | 195 | QPopupMenu *edit = new QPopupMenu( this ); |
196 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 196 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
197 | 197 | ||
198 | font = new QPopupMenu( this ); | 198 | font = new QPopupMenu( this ); |
199 | 199 | ||
200 | bar = new QToolBar( this ); | 200 | bar = new QToolBar( this ); |
201 | editBar = bar; | 201 | editBar = bar; |
202 | 202 | ||
203 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 203 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
204 | QString::null, 0, this, 0 ); | 204 | QString::null, 0, this, 0 ); |
205 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 205 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
206 | // a->addTo( bar ); | 206 | // a->addTo( bar ); |
207 | a->addTo( file ); | 207 | a->addTo( file ); |
208 | 208 | ||
209 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), | 209 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), |
210 | QString::null, 0, this, 0 ); | 210 | QString::null, 0, this, 0 ); |
211 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 211 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
212 | a->addTo( bar ); | 212 | a->addTo( bar ); |
213 | a->addTo( file ); | 213 | a->addTo( file ); |
214 | 214 | ||
215 | a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , | 215 | a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , |
216 | QString::null, 0, this, 0 ); | 216 | QString::null, 0, this, 0 ); |
217 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 217 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
218 | file->insertSeparator(); | 218 | file->insertSeparator(); |
219 | a->addTo( bar ); | 219 | a->addTo( bar ); |
220 | a->addTo( file ); | 220 | a->addTo( file ); |
221 | 221 | ||
222 | a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , | 222 | a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , |
223 | QString::null, 0, this, 0 ); | 223 | QString::null, 0, this, 0 ); |
224 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 224 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
225 | a->addTo( file ); | 225 | a->addTo( file ); |
226 | 226 | ||
227 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), | 227 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), |
228 | QString::null, 0, this, 0 ); | 228 | QString::null, 0, this, 0 ); |
229 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 229 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
230 | a->addTo( editBar ); | 230 | a->addTo( editBar ); |
231 | a->addTo( edit ); | 231 | a->addTo( edit ); |
232 | 232 | ||
233 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), | 233 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), |
234 | QString::null, 0, this, 0 ); | 234 | QString::null, 0, this, 0 ); |
235 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 235 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
236 | a->addTo( editBar ); | 236 | a->addTo( editBar ); |
237 | a->addTo( edit ); | 237 | a->addTo( edit ); |
238 | 238 | ||
239 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), | 239 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), |
240 | QString::null, 0, this, 0 ); | 240 | QString::null, 0, this, 0 ); |
241 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 241 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
242 | a->addTo( editBar ); | 242 | a->addTo( editBar ); |
243 | a->addTo( edit ); | 243 | a->addTo( edit ); |
244 | 244 | ||
245 | 245 | ||
246 | #ifndef QT_NO_CLIPBOARD | 246 | #ifndef QT_NO_CLIPBOARD |
247 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), | 247 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), |
248 | QString::null, 0, this, 0 ); | 248 | QString::null, 0, this, 0 ); |
249 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 249 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
250 | a->addTo( edit ); | 250 | a->addTo( edit ); |
251 | #endif | 251 | #endif |
252 | 252 | ||
253 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), | 253 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), |
254 | QString::null, 0, this, 0 ); | 254 | QString::null, 0, this, 0 ); |
255 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); | 255 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); |
256 | edit->insertSeparator(); | 256 | edit->insertSeparator(); |
257 | a->addTo( edit ); | 257 | a->addTo( edit ); |
258 | 258 | ||
259 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), | 259 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), |
260 | QString::null, 0, this, 0 ); | 260 | QString::null, 0, this, 0 ); |
261 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 261 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
262 | a->addTo( bar ); | 262 | a->addTo( bar ); |
263 | a->addTo( edit ); | 263 | a->addTo( edit ); |
264 | 264 | ||
265 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 265 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
266 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 266 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
267 | zin->addTo( font ); | 267 | zin->addTo( font ); |
268 | 268 | ||
269 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 269 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
270 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 270 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
271 | zout->addTo( font ); | 271 | zout->addTo( font ); |
272 | 272 | ||
273 | font->insertSeparator(); | 273 | font->insertSeparator(); |
274 | 274 | ||
275 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 275 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
276 | 276 | ||
277 | font->insertSeparator(); | 277 | font->insertSeparator(); |
278 | font->insertItem(tr("Advanced Features"), advancedMenu); | 278 | font->insertItem(tr("Advanced Features"), advancedMenu); |
279 | 279 | ||
280 | QAction *wa = new QAction( tr("Wrap lines"), | 280 | QAction *wa = new QAction( tr("Wrap lines"), |
281 | QString::null, 0, this, 0 ); | 281 | QString::null, 0, this, 0 ); |
282 | connect( wa, SIGNAL( toggled(bool) ), | 282 | connect( wa, SIGNAL( toggled(bool) ), |
283 | this, SLOT( setWordWrap(bool) ) ); | 283 | this, SLOT( setWordWrap(bool) ) ); |
284 | wa->setToggleAction(true); | 284 | wa->setToggleAction(true); |
285 | wa->addTo( advancedMenu); | 285 | wa->addTo( advancedMenu); |
286 | 286 | ||
287 | nStart = new QAction( tr("Start with new file"), | 287 | nStart = new QAction( tr("Start with new file"), |
288 | QString::null, 0, this, 0 ); | 288 | QString::null, 0, this, 0 ); |
289 | connect( nStart, SIGNAL( toggled(bool) ), | 289 | connect( nStart, SIGNAL( toggled(bool) ), |
290 | this, SLOT( changeStartConfig(bool) ) ); | 290 | this, SLOT( changeStartConfig(bool) ) ); |
291 | nStart->setToggleAction(true); | 291 | nStart->setToggleAction(true); |
292 | nStart->addTo( advancedMenu ); | 292 | nStart->addTo( advancedMenu ); |
293 | nStart->setEnabled(false); | 293 | nStart->setEnabled(false); |
294 | 294 | ||
295 | nAdvanced = new QAction( tr("Prompt on Exit"), | 295 | nAdvanced = new QAction( tr("Prompt on Exit"), |
296 | QString::null, 0, this, 0 ); | 296 | QString::null, 0, this, 0 ); |
297 | connect( nAdvanced, SIGNAL( toggled(bool) ), | 297 | connect( nAdvanced, SIGNAL( toggled(bool) ), |
298 | this, SLOT( doPrompt(bool) ) ); | 298 | this, SLOT( doPrompt(bool) ) ); |
299 | nAdvanced->setToggleAction(true); | 299 | nAdvanced->setToggleAction(true); |
300 | nAdvanced->addTo( advancedMenu ); | 300 | nAdvanced->addTo( advancedMenu ); |
301 | 301 | ||
302 | desktopAction = new QAction( tr("Always open linked file"), | 302 | desktopAction = new QAction( tr("Always open linked file"), |
303 | QString::null, 0, this, 0 ); | 303 | QString::null, 0, this, 0 ); |
304 | connect( desktopAction, SIGNAL( toggled(bool) ), | 304 | connect( desktopAction, SIGNAL( toggled(bool) ), |
305 | this, SLOT( doDesktop(bool) ) ); | 305 | this, SLOT( doDesktop(bool) ) ); |
306 | desktopAction->setToggleAction(true); | 306 | desktopAction->setToggleAction(true); |
307 | desktopAction->addTo( advancedMenu); | 307 | desktopAction->addTo( advancedMenu); |
308 | 308 | ||
309 | filePermAction = new QAction( tr("File Permissions"), | 309 | filePermAction = new QAction( tr("File Permissions"), |
310 | QString::null, 0, this, 0 ); | 310 | QString::null, 0, this, 0 ); |
311 | connect( filePermAction, SIGNAL( toggled(bool) ), | 311 | connect( filePermAction, SIGNAL( toggled(bool) ), |
312 | this, SLOT( doFilePerms(bool) ) ); | 312 | this, SLOT( doFilePerms(bool) ) ); |
313 | filePermAction->setToggleAction(true); | 313 | filePermAction->setToggleAction(true); |
314 | filePermAction->addTo( advancedMenu); | 314 | filePermAction->addTo( advancedMenu); |
315 | 315 | ||
316 | searchBarAction = new QAction( tr("Search Bar Open"), | 316 | searchBarAction = new QAction( tr("Search Bar Open"), |
317 | QString::null, 0, this, 0 ); | 317 | QString::null, 0, this, 0 ); |
318 | connect( searchBarAction, SIGNAL( toggled(bool) ), | 318 | connect( searchBarAction, SIGNAL( toggled(bool) ), |
319 | this, SLOT( setSearchBar(bool) ) ); | 319 | this, SLOT( setSearchBar(bool) ) ); |
320 | searchBarAction->setToggleAction(true); | 320 | searchBarAction->setToggleAction(true); |
321 | searchBarAction->addTo( advancedMenu); | 321 | searchBarAction->addTo( advancedMenu); |
322 | 322 | ||
323 | nAutoSave = new QAction( tr("Auto Save 5 min."), | 323 | nAutoSave = new QAction( tr("Auto Save 5 min."), |
324 | QString::null, 0, this, 0 ); | 324 | QString::null, 0, this, 0 ); |
325 | connect( nAutoSave, SIGNAL( toggled(bool) ), | 325 | connect( nAutoSave, SIGNAL( toggled(bool) ), |
326 | this, SLOT( doTimer(bool) ) ); | 326 | this, SLOT( doTimer(bool) ) ); |
327 | nAutoSave->setToggleAction(true); | 327 | nAutoSave->setToggleAction(true); |
328 | nAutoSave->addTo( advancedMenu); | 328 | nAutoSave->addTo( advancedMenu); |
329 | 329 | ||
330 | 330 | ||
331 | //font->insertSeparator(); | 331 | //font->insertSeparator(); |
332 | 332 | ||
333 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 333 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
334 | 334 | ||
335 | mb->insertItem( tr( "File" ), file ); | 335 | mb->insertItem( tr( "File" ), file ); |
336 | mb->insertItem( tr( "Edit" ), edit ); | 336 | mb->insertItem( tr( "Edit" ), edit ); |
337 | mb->insertItem( tr( "View" ), font ); | 337 | mb->insertItem( tr( "View" ), font ); |
338 | 338 | ||
339 | searchBar = new QToolBar(this); | 339 | searchBar = new QToolBar(this); |
340 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 340 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
341 | 341 | ||
342 | searchBar->setHorizontalStretchable( true ); | 342 | searchBar->setHorizontalStretchable( true ); |
343 | 343 | ||
344 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 344 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
345 | searchBar->setStretchableWidget( searchEdit ); | 345 | searchBar->setStretchableWidget( searchEdit ); |
346 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 346 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
347 | this, SLOT( search() ) ); | 347 | this, SLOT( search() ) ); |
348 | 348 | ||
349 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), | 349 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), |
350 | QString::null, 0, this, 0 ); | 350 | QString::null, 0, this, 0 ); |
351 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 351 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
352 | a->addTo( searchBar ); | 352 | a->addTo( searchBar ); |
353 | a->addTo( edit ); | 353 | a->addTo( edit ); |
354 | 354 | ||
355 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), | 355 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), |
356 | QString::null, 0, this, 0 ); | 356 | QString::null, 0, this, 0 ); |
357 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 357 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
358 | a->addTo( searchBar ); | 358 | a->addTo( searchBar ); |
359 | 359 | ||
360 | edit->insertSeparator(); | 360 | edit->insertSeparator(); |
361 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), | 361 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), |
362 | QString::null, 0, this, 0 ); | 362 | QString::null, 0, this, 0 ); |
363 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 363 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
364 | a->addTo( edit ); | 364 | a->addTo( edit ); |
365 | 365 | ||
366 | searchBar->hide(); | 366 | searchBar->hide(); |
367 | 367 | ||
368 | editor = new QpeEditor( this ); | 368 | editor = new QpeEditor( this ); |
369 | setCentralWidget( editor ); | 369 | setCentralWidget( editor ); |
370 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 370 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
371 | connect( editor, SIGNAL( textChanged() ), | 371 | connect( editor, SIGNAL( textChanged() ), |
372 | this, SLOT( editorChanged() ) ); | 372 | this, SLOT( editorChanged() ) ); |
373 | 373 | ||
374 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 374 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
375 | 375 | ||
376 | Config cfg("TextEdit"); | 376 | Config cfg("TextEdit"); |
377 | cfg. setGroup ( "Font" ); | 377 | cfg. setGroup ( "Font" ); |
378 | 378 | ||
379 | QFont defaultFont = editor-> font ( ); | 379 | QFont defaultFont = editor-> font ( ); |
380 | 380 | ||
381 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 381 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
382 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 382 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
383 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 383 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
384 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 384 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
385 | 385 | ||
386 | defaultFont = QFont ( family, size, weight, italic ); | 386 | defaultFont = QFont ( family, size, weight, italic ); |
387 | editor-> setFont ( defaultFont ); | 387 | editor-> setFont ( defaultFont ); |
388 | // updateCaption(); | 388 | // updateCaption(); |
389 | 389 | ||
390 | cfg.setGroup ( "View" ); | 390 | cfg.setGroup ( "View" ); |
391 | 391 | ||
392 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 392 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
393 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 393 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
394 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 394 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
395 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 395 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
396 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 396 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
397 | featureAutoSave = cfg.readBoolEntry( "autosave", false); | 397 | featureAutoSave = cfg.readBoolEntry( "autosave", false); |
398 | 398 | ||
399 | if(useSearchBar) searchBarAction->setOn(true); | 399 | if(useSearchBar) searchBarAction->setOn(true); |
400 | if(promptExit) nAdvanced->setOn( true ); | 400 | if(promptExit) nAdvanced->setOn( true ); |
401 | if(openDesktop) desktopAction->setOn( true ); | 401 | if(openDesktop) desktopAction->setOn( true ); |
402 | if(filePerms) filePermAction->setOn( true ); | 402 | if(filePerms) filePermAction->setOn( true ); |
403 | if(startWithNew) nStart->setOn( true ); | 403 | if(startWithNew) nStart->setOn( true ); |
404 | if(featureAutoSave) nAutoSave->setOn(true); | 404 | if(featureAutoSave) nAutoSave->setOn(true); |
405 | 405 | ||
406 | // { | 406 | // { |
407 | // doTimer(true); | 407 | // doTimer(true); |
408 | // } | 408 | // } |
409 | 409 | ||
410 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 410 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
411 | wa-> setOn ( wrap ); | 411 | wa-> setOn ( wrap ); |
412 | setWordWrap ( wrap ); | 412 | setWordWrap ( wrap ); |
413 | 413 | ||
414 | ///////////////// | 414 | ///////////////// |
415 | if( qApp->argc() > 1) { | 415 | if( qApp->argc() > 1) { |
416 | currentFileName=qApp->argv()[1]; | 416 | currentFileName=qApp->argv()[1]; |
417 | 417 | ||
418 | QFileInfo fi(currentFileName); | 418 | QFileInfo fi(currentFileName); |
419 | 419 | ||
420 | if(fi.baseName().left(1) == "") { | 420 | if(fi.baseName().left(1) == "") { |
421 | openDotFile(currentFileName); | 421 | openDotFile(currentFileName); |
422 | } else { | 422 | } else { |
423 | openFile(currentFileName); | 423 | openFile(currentFileName); |
424 | } | 424 | } |
425 | } else { | 425 | } else { |
426 | edited1=false; | 426 | edited1=false; |
427 | openDotFile(""); | 427 | openDotFile(""); |
428 | } | 428 | } |
429 | 429 | ||
430 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 430 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
431 | } | 431 | } |
432 | 432 | ||
433 | TextEdit::~TextEdit() { | 433 | TextEdit::~TextEdit() { |
434 | qWarning("textedit d'tor"); | 434 | qWarning("textedit d'tor"); |
435 | delete editor; | 435 | delete editor; |
436 | } | 436 | } |
437 | 437 | ||
438 | void TextEdit::closeEvent(QCloseEvent *) { | 438 | void TextEdit::closeEvent(QCloseEvent *) { |
439 | if( edited1 && promptExit) | 439 | if( edited1 && promptExit) |
440 | { | 440 | { |
441 | switch( savePrompt() ) | 441 | switch( savePrompt() ) |
442 | { | 442 | { |
443 | case 1: | 443 | case 1: |
444 | { | 444 | { |
445 | saveAs(); | 445 | saveAs(); |
446 | qApp->quit(); | 446 | qApp->quit(); |
447 | } | 447 | } |
448 | break; | 448 | break; |
449 | 449 | ||
450 | case 2: | 450 | case 2: |
451 | { | 451 | { |
452 | qApp->quit(); | 452 | qApp->quit(); |
453 | } | 453 | } |
454 | break; | 454 | break; |
455 | 455 | ||
456 | case -1: | 456 | case -1: |
457 | break; | 457 | break; |
458 | }; | 458 | }; |
459 | } | 459 | } |
460 | else | 460 | else |
461 | qApp->quit(); | 461 | qApp->quit(); |
462 | 462 | ||
463 | } | 463 | } |
464 | 464 | ||
465 | void TextEdit::cleanUp() { | 465 | void TextEdit::cleanUp() { |
466 | 466 | ||
467 | Config cfg ( "TextEdit" ); | 467 | Config cfg ( "TextEdit" ); |
468 | cfg. setGroup ( "Font" ); | 468 | cfg. setGroup ( "Font" ); |
469 | QFont f = editor->font(); | 469 | QFont f = editor->font(); |
470 | cfg.writeEntry ( "Family", f. family ( )); | 470 | cfg.writeEntry ( "Family", f. family ( )); |
471 | cfg.writeEntry ( "Size", f. pointSize ( )); | 471 | cfg.writeEntry ( "Size", f. pointSize ( )); |
472 | cfg.writeEntry ( "Weight", f. weight ( )); | 472 | cfg.writeEntry ( "Weight", f. weight ( )); |
473 | cfg.writeEntry ( "Italic", f. italic ( )); | 473 | cfg.writeEntry ( "Italic", f. italic ( )); |
474 | 474 | ||
475 | cfg.setGroup ( "View" ); | 475 | cfg.setGroup ( "View" ); |
476 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 476 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
477 | cfg.writeEntry ( "FileView", viewSelection ); | 477 | cfg.writeEntry ( "FileView", viewSelection ); |
478 | 478 | ||
479 | cfg.writeEntry ( "PromptExit", promptExit ); | 479 | cfg.writeEntry ( "PromptExit", promptExit ); |
480 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 480 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
481 | cfg.writeEntry ( "FilePermissions", filePerms ); | 481 | cfg.writeEntry ( "FilePermissions", filePerms ); |
482 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 482 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
483 | cfg.writeEntry ( "startNew", startWithNew ); | 483 | cfg.writeEntry ( "startNew", startWithNew ); |
484 | 484 | ||
485 | } | 485 | } |
486 | 486 | ||
487 | 487 | ||
488 | void TextEdit::accept() { | 488 | void TextEdit::accept() { |
489 | if( edited1) | 489 | if( edited1) |
490 | saveAs(); | 490 | saveAs(); |
491 | qApp->quit(); | 491 | qApp->quit(); |
492 | } | 492 | } |
493 | 493 | ||
494 | void TextEdit::zoomIn() { | 494 | void TextEdit::zoomIn() { |
495 | setFontSize(editor->font().pointSize()+1,false); | 495 | setFontSize(editor->font().pointSize()+1,false); |
496 | } | 496 | } |
497 | 497 | ||
498 | void TextEdit::zoomOut() { | 498 | void TextEdit::zoomOut() { |
499 | setFontSize(editor->font().pointSize()-1,true); | 499 | setFontSize(editor->font().pointSize()-1,true); |
500 | } | 500 | } |
501 | 501 | ||
502 | 502 | ||
503 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 503 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
504 | int s=10; | 504 | int s=10; |
505 | for (int i=0; i<nfontsizes; i++) { | 505 | for (int i=0; i<nfontsizes; i++) { |
506 | if ( fontsize[i] == sz ) { | 506 | if ( fontsize[i] == sz ) { |
507 | s = sz; | 507 | s = sz; |
508 | break; | 508 | break; |
509 | } else if ( round_down_not_up ) { | 509 | } else if ( round_down_not_up ) { |
510 | if ( fontsize[i] < sz ) | 510 | if ( fontsize[i] < sz ) |
511 | s = fontsize[i]; | 511 | s = fontsize[i]; |
512 | } else { | 512 | } else { |
513 | if ( fontsize[i] > sz ) { | 513 | if ( fontsize[i] > sz ) { |
514 | s = fontsize[i]; | 514 | s = fontsize[i]; |
515 | break; | 515 | break; |
516 | } | 516 | } |
517 | } | 517 | } |
518 | } | 518 | } |
519 | 519 | ||
520 | QFont f = editor->font(); | 520 | QFont f = editor->font(); |
521 | f.setPointSize(s); | 521 | f.setPointSize(s); |
522 | editor->setFont(f); | 522 | editor->setFont(f); |
523 | 523 | ||
524 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 524 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
525 | zout->setEnabled(s != fontsize[0]); | 525 | zout->setEnabled(s != fontsize[0]); |
526 | } | 526 | } |
527 | 527 | ||
528 | void TextEdit::setBold(bool y) { | 528 | void TextEdit::setBold(bool y) { |
529 | QFont f = editor->font(); | 529 | QFont f = editor->font(); |
530 | f.setBold(y); | 530 | f.setBold(y); |
531 | editor->setFont(f); | 531 | editor->setFont(f); |
532 | } | 532 | } |
533 | 533 | ||
534 | void TextEdit::setItalic(bool y) { | 534 | void TextEdit::setItalic(bool y) { |
535 | QFont f = editor->font(); | 535 | QFont f = editor->font(); |
536 | f.setItalic(y); | 536 | f.setItalic(y); |
537 | editor->setFont(f); | 537 | editor->setFont(f); |
538 | } | 538 | } |
539 | 539 | ||
540 | void TextEdit::setWordWrap(bool y) { | 540 | void TextEdit::setWordWrap(bool y) { |
541 | bool state = editor->edited(); | 541 | bool state = editor->edited(); |
542 | QString captionStr = caption(); | 542 | QString captionStr = caption(); |
543 | bool b1 = edited1; | 543 | bool b1 = edited1; |
544 | bool b2 = edited; | 544 | bool b2 = edited; |
545 | 545 | ||
546 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 546 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
547 | editor->setEdited( state ); | 547 | editor->setEdited( state ); |
548 | edited1=b1; | 548 | edited1=b1; |
549 | edited=b2; | 549 | edited=b2; |
550 | setCaption(captionStr); | 550 | setCaption(captionStr); |
551 | } | 551 | } |
552 | 552 | ||
553 | void TextEdit::setSearchBar(bool b) { | 553 | void TextEdit::setSearchBar(bool b) { |
554 | useSearchBar=b; | 554 | useSearchBar=b; |
555 | Config cfg("TextEdit"); | 555 | Config cfg("TextEdit"); |
556 | cfg.setGroup("View"); | 556 | cfg.setGroup("View"); |
557 | cfg.writeEntry ( "SearchBar", b ); | 557 | cfg.writeEntry ( "SearchBar", b ); |
558 | searchBarAction->setOn(b); | 558 | searchBarAction->setOn(b); |
559 | if(b) | 559 | if(b) |
560 | searchBar->show(); | 560 | searchBar->show(); |
561 | else | 561 | else |
562 | searchBar->hide(); | 562 | searchBar->hide(); |
563 | editor->setFocus(); | 563 | editor->setFocus(); |
564 | } | 564 | } |
565 | 565 | ||
566 | void TextEdit::fileNew() { | 566 | void TextEdit::fileNew() { |
567 | // if( !bFromDocView ) { | 567 | // if( !bFromDocView ) { |
568 | // saveAs(); | 568 | // saveAs(); |
569 | // } | 569 | // } |
570 | newFile(DocLnk()); | 570 | newFile(DocLnk()); |
571 | } | 571 | } |
572 | 572 | ||
573 | void TextEdit::fileOpen() { | 573 | void TextEdit::fileOpen() { |
574 | Config cfg("TextEdit"); | 574 | Config cfg("TextEdit"); |
575 | cfg. setGroup ( "View" ); | 575 | cfg. setGroup ( "View" ); |
576 | QMap<QString, QStringList> map; | 576 | QMap<QString, QStringList> map; |
577 | map.insert(tr("All"), QStringList() ); | 577 | map.insert(tr("All"), QStringList() ); |
578 | QStringList text; | 578 | QStringList text; |
579 | text << "text/*"; | 579 | text << "text/*"; |
580 | map.insert(tr("Text"), text ); | 580 | map.insert(tr("Text"), text ); |
581 | text << "*"; | 581 | text << "*"; |
582 | map.insert(tr("All"), text ); | 582 | map.insert(tr("All"), text ); |
583 | QString str = OFileDialog::getOpenFileName( 2, | 583 | QString str = OFileDialog::getOpenFileName( 2, |
584 | QString::null , | 584 | QString::null , |
585 | QString::null, map); | 585 | QString::null, map); |
586 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) | 586 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) |
587 | { | 587 | { |
588 | openFile( str ); | 588 | openFile( str ); |
589 | } | 589 | } |
590 | else | 590 | else |
591 | updateCaption(); | 591 | updateCaption(); |
592 | } | 592 | } |
593 | 593 | ||
594 | void TextEdit::doSearchBar() { | 594 | void TextEdit::doSearchBar() { |
595 | if(!useSearchBar) | 595 | if(!useSearchBar) |
596 | searchBar->hide(); | 596 | searchBar->hide(); |
597 | else | 597 | else |
598 | searchBar->show(); | 598 | searchBar->show(); |
599 | } | 599 | } |
600 | 600 | ||
601 | #if 0 | 601 | #if 0 |
602 | void TextEdit::slotFind() { | 602 | void TextEdit::slotFind() { |
603 | FindDialog frmFind( tr("Text Editor"), this ); | 603 | FindDialog frmFind( tr("Text Editor"), this ); |
604 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 604 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
605 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 605 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
606 | 606 | ||
607 | //case sensitive, backwards, [category] | 607 | //case sensitive, backwards, [category] |
608 | 608 | ||
609 | connect( editor, SIGNAL(notFound()), | 609 | connect( editor, SIGNAL(notFound()), |
610 | &frmFind, SLOT(slotNotFound()) ); | 610 | &frmFind, SLOT(slotNotFound()) ); |
611 | connect( editor, SIGNAL(searchWrapped()), | 611 | connect( editor, SIGNAL(searchWrapped()), |
612 | &frmFind, SLOT(slotWrapAround()) ); | 612 | &frmFind, SLOT(slotWrapAround()) ); |
613 | 613 | ||
614 | frmFind.exec(); | 614 | frmFind.exec(); |
615 | 615 | ||
616 | 616 | ||
617 | } | 617 | } |
618 | #endif | 618 | #endif |
619 | 619 | ||
620 | void TextEdit::fileRevert() { | 620 | void TextEdit::fileRevert() { |
621 | clear(); | 621 | clear(); |
622 | fileOpen(); | 622 | fileOpen(); |
623 | } | 623 | } |
624 | 624 | ||
625 | void TextEdit::editCut() { | 625 | void TextEdit::editCut() { |
626 | #ifndef QT_NO_CLIPBOARD | 626 | #ifndef QT_NO_CLIPBOARD |
627 | editor->cut(); | 627 | editor->cut(); |
628 | #endif | 628 | #endif |
629 | } | 629 | } |
630 | 630 | ||
631 | void TextEdit::editCopy() { | 631 | void TextEdit::editCopy() { |
632 | #ifndef QT_NO_CLIPBOARD | 632 | #ifndef QT_NO_CLIPBOARD |
633 | editor->copy(); | 633 | editor->copy(); |
634 | #endif | 634 | #endif |
635 | } | 635 | } |
636 | 636 | ||
637 | void TextEdit::editPaste() { | 637 | void TextEdit::editPaste() { |
638 | #ifndef QT_NO_CLIPBOARD | 638 | #ifndef QT_NO_CLIPBOARD |
639 | editor->paste(); | 639 | editor->paste(); |
640 | #endif | 640 | #endif |
641 | } | 641 | } |
642 | 642 | ||
643 | void TextEdit::editFind() { | 643 | void TextEdit::editFind() { |
644 | searchBar->show(); | 644 | searchBar->show(); |
645 | searchEdit->setFocus(); | 645 | searchEdit->setFocus(); |
646 | } | 646 | } |
647 | 647 | ||
648 | void TextEdit::findNext() { | 648 | void TextEdit::findNext() { |
649 | editor->find( searchEdit->text(), false, false ); | 649 | editor->find( searchEdit->text(), false, false ); |
650 | 650 | ||
651 | } | 651 | } |
652 | 652 | ||
653 | void TextEdit::findClose() { | 653 | void TextEdit::findClose() { |
654 | searchBar->hide(); | 654 | searchBar->hide(); |
655 | } | 655 | } |
656 | 656 | ||
657 | void TextEdit::search() { | 657 | void TextEdit::search() { |
658 | editor->find( searchEdit->text(), false, false ); | 658 | editor->find( searchEdit->text(), false, false ); |
659 | } | 659 | } |
660 | 660 | ||
661 | void TextEdit::newFile( const DocLnk &f ) { | 661 | void TextEdit::newFile( const DocLnk &f ) { |
662 | DocLnk nf = f; | 662 | DocLnk nf = f; |
663 | nf.setType("text/plain"); | 663 | nf.setType("text/plain"); |
664 | clear(); | 664 | clear(); |
665 | setWState (WState_Reserved1 ); | 665 | setWState (WState_Reserved1 ); |
666 | editor->setFocus(); | 666 | editor->setFocus(); |
667 | doc = new DocLnk(nf); | 667 | doc = new DocLnk(nf); |
668 | currentFileName = "Unnamed"; | 668 | currentFileName = "Unnamed"; |
669 | qDebug("newFile "+currentFileName); | 669 | qDebug("newFile "+currentFileName); |
670 | updateCaption( currentFileName); | 670 | updateCaption( currentFileName); |
671 | // editor->setEdited( false); | 671 | // editor->setEdited( false); |
672 | } | 672 | } |
673 | 673 | ||
674 | void TextEdit::openDotFile( const QString &f ) { | 674 | void TextEdit::openDotFile( const QString &f ) { |
675 | if(!currentFileName.isEmpty()) { | 675 | if(!currentFileName.isEmpty()) { |
676 | currentFileName=f; | 676 | currentFileName=f; |
677 | 677 | ||
678 | qDebug("openFile dotfile " + currentFileName); | 678 | qDebug("openFile dotfile " + currentFileName); |
679 | QString txt; | 679 | QString txt; |
680 | QFile file(f); | 680 | QFile file(f); |
681 | file.open(IO_ReadWrite); | 681 | file.open(IO_ReadWrite); |
682 | QTextStream t(&file); | 682 | QTextStream t(&file); |
683 | while ( !t.atEnd()) { | 683 | while ( !t.atEnd()) { |
684 | txt+=t.readLine()+"\n"; | 684 | txt+=t.readLine()+"\n"; |
685 | } | 685 | } |
686 | editor->setText(txt); | 686 | editor->setText(txt); |
687 | editor->setEdited( false); | 687 | editor->setEdited( false); |
688 | edited1=false; | 688 | edited1=false; |
689 | edited=false; | 689 | edited=false; |
690 | 690 | ||
691 | 691 | ||
692 | } | 692 | } |
693 | updateCaption( currentFileName); | 693 | updateCaption( currentFileName); |
694 | } | 694 | } |
695 | 695 | ||
696 | void TextEdit::openFile( const QString &f ) { | 696 | void TextEdit::openFile( const QString &f ) { |
697 | qDebug("filename is "+ f); | 697 | qDebug("filename is "+ f); |
698 | QString filer; | 698 | QString filer; |
699 | QFileInfo fi( f); | 699 | QFileInfo fi( f); |
700 | // bFromDocView = true; | 700 | // bFromDocView = true; |
701 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) | 701 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) |
702 | { | 702 | { |
703 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) | 703 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) |
704 | { | 704 | { |
705 | case 0: //desktop | 705 | case 0: //desktop |
706 | filer = f; | 706 | filer = f; |
707 | break; | 707 | break; |
708 | case 1: //linked | 708 | case 1: //linked |
709 | DocLnk sf(f); | 709 | DocLnk sf(f); |
710 | filer = sf.file(); | 710 | filer = sf.file(); |
711 | break; | 711 | break; |
712 | }; | 712 | }; |
713 | } | 713 | } |
714 | else if(fi.baseName().left(1) == "") | 714 | else if(fi.baseName().left(1) == "") |
715 | { | 715 | { |
716 | qDebug("opening dotfile"); | 716 | qDebug("opening dotfile"); |
717 | currentFileName=f; | 717 | currentFileName=f; |
718 | openDotFile(currentFileName); | 718 | openDotFile(currentFileName); |
719 | return; | 719 | return; |
720 | } | 720 | } |
721 | /* | 721 | /* |
722 | * The problem is a file where Config(f).isValid() and it does not | 722 | * The problem is a file where Config(f).isValid() and it does not |
723 | * end with .desktop will be treated as desktop file | 723 | * end with .desktop will be treated as desktop file |
724 | */ | 724 | */ |
725 | else if (f.find(".desktop",0,true) != -1 ) | 725 | else if (f.find(".desktop",0,true) != -1 ) |
726 | { | 726 | { |
727 | DocLnk sf(f); | 727 | DocLnk sf(f); |
728 | filer = sf.file(); | 728 | filer = sf.file(); |
729 | if(filer.right(1) == "/") | 729 | if(filer.right(1) == "/") |
730 | filer = f; | 730 | filer = f; |
731 | 731 | ||
732 | } | 732 | } |
733 | else | 733 | else |
734 | filer = f; | 734 | filer = f; |
735 | 735 | ||
736 | DocLnk nf; | 736 | DocLnk nf; |
737 | nf.setType("text/plain"); | 737 | nf.setType("text/plain"); |
738 | nf.setFile(filer); | 738 | nf.setFile(filer); |
739 | currentFileName=filer; | 739 | currentFileName=filer; |
740 | 740 | ||
741 | nf.setName(fi.baseName()); | 741 | nf.setName(fi.baseName()); |
742 | openFile(nf); | 742 | openFile(nf); |
743 | 743 | ||
744 | qDebug("openFile string "+currentFileName); | 744 | qDebug("openFile string "+currentFileName); |
745 | 745 | ||
746 | showEditTools(); | 746 | showEditTools(); |
747 | // Show filename in caption | 747 | // Show filename in caption |
748 | QString name = filer; | 748 | QString name = filer; |
749 | int sep = name.findRev( '/' ); | 749 | int sep = name.findRev( '/' ); |
750 | if ( sep > 0 ) | 750 | if ( sep > 0 ) |
751 | name = name.mid( sep+1 ); | 751 | name = name.mid( sep+1 ); |
752 | updateCaption( name ); | 752 | updateCaption( name ); |
753 | } | 753 | } |
754 | 754 | ||
755 | void TextEdit::openFile( const DocLnk &f ) { | 755 | void TextEdit::openFile( const DocLnk &f ) { |
756 | // clear(); | 756 | // clear(); |
757 | // bFromDocView = true; | 757 | // bFromDocView = true; |
758 | FileManager fm; | 758 | FileManager fm; |
759 | QString txt; | 759 | QString txt; |
760 | currentFileName=f.file(); | 760 | currentFileName=f.file(); |
761 | qDebug("openFile doclnk " + currentFileName); | 761 | qDebug("openFile doclnk " + currentFileName); |
762 | if ( !fm.loadFile( f, txt ) ) { | 762 | if ( !fm.loadFile( f, txt ) ) { |
763 | // ####### could be a new file | 763 | // ####### could be a new file |
764 | qDebug( "Cannot open file" ); | 764 | qDebug( "Cannot open file" ); |
765 | } | 765 | } |
766 | // fileNew(); | 766 | // fileNew(); |
767 | if ( doc ) | 767 | if ( doc ) |
768 | delete doc; | 768 | delete doc; |
769 | doc = new DocLnk(f); | 769 | doc = new DocLnk(f); |
770 | editor->setText(txt); | 770 | editor->setText(txt); |
771 | editor->setEdited( false); | 771 | editor->setEdited( false); |
772 | edited1=false; | 772 | edited1=false; |
773 | edited=false; | 773 | edited=false; |
774 | 774 | ||
775 | doc->setName(currentFileName); | 775 | doc->setName(currentFileName); |
776 | updateCaption(); | 776 | updateCaption(); |
777 | setTimer(); | 777 | setTimer(); |
778 | } | 778 | } |
779 | 779 | ||
780 | void TextEdit::showEditTools() { | 780 | void TextEdit::showEditTools() { |
781 | menu->show(); | 781 | menu->show(); |
782 | editBar->show(); | 782 | editBar->show(); |
783 | if(!useSearchBar) | 783 | if(!useSearchBar) |
784 | searchBar->hide(); | 784 | searchBar->hide(); |
785 | else | 785 | else |
786 | searchBar->show(); | 786 | searchBar->show(); |
787 | setWState (WState_Reserved1 ); | 787 | setWState (WState_Reserved1 ); |
788 | } | 788 | } |
789 | 789 | ||
790 | /*! | 790 | /*! |
791 | unprompted save */ | 791 | unprompted save */ |
792 | bool TextEdit::save() { | 792 | bool TextEdit::save() { |
793 | qDebug("saveAsFile " + currentFileName); | 793 | qDebug("saveAsFile " + currentFileName); |
794 | if(currentFileName.isEmpty()) { | 794 | if(currentFileName.isEmpty()) { |
795 | saveAs(); | 795 | saveAs(); |
796 | return false; | 796 | return false; |
797 | } | 797 | } |
798 | 798 | ||
799 | QString file = doc->file(); | 799 | QString file = doc->file(); |
800 | qDebug("saver file "+file); | 800 | qDebug("saver file "+file); |
801 | QString name= doc->name(); | 801 | QString name= doc->name(); |
802 | qDebug("File named "+name); | 802 | qDebug("File named "+name); |
803 | QString rt = editor->text(); | 803 | QString rt = editor->text(); |
804 | if( !rt.isEmpty() ) { | 804 | if( !rt.isEmpty() ) { |
805 | if(name.isEmpty()) { | 805 | if(name.isEmpty()) { |
806 | saveAs(); | 806 | saveAs(); |
807 | } else { | 807 | } else { |
808 | currentFileName= name ; | 808 | currentFileName= name ; |
809 | qDebug("saveFile "+currentFileName); | 809 | qDebug("saveFile "+currentFileName); |
810 | 810 | ||
811 | struct stat buf; | 811 | struct stat buf; |
812 | mode_t mode; | 812 | mode_t mode; |
813 | stat(file.latin1(), &buf); | 813 | stat(file.latin1(), &buf); |
814 | mode = buf.st_mode; | 814 | mode = buf.st_mode; |
815 | 815 | ||
816 | if(!fileIs) { | 816 | if(!fileIs) { |
817 | doc->setName( name); | 817 | doc->setName( name); |
818 | FileManager fm; | 818 | FileManager fm; |
819 | if ( !fm.saveFile( *doc, rt ) ) { | 819 | if ( !fm.saveFile( *doc, rt ) ) { |
820 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | ||
820 | return false; | 821 | return false; |
821 | } | 822 | } |
822 | } else { | 823 | } else { |
823 | qDebug("regular save file"); | 824 | qDebug("regular save file"); |
824 | QFile f(file); | 825 | QFile f(file); |
825 | if( f.open(IO_WriteOnly)) { | 826 | if( f.open(IO_WriteOnly)) { |
826 | QCString crt = rt.utf8(); | 827 | QCString crt = rt.utf8(); |
827 | f.writeBlock(crt,crt.length()); | 828 | f.writeBlock(crt,crt.length()); |
828 | } else { | 829 | } else { |
829 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 830 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
830 | return false; | 831 | return false; |
831 | } | 832 | } |
832 | 833 | ||
833 | } | 834 | } |
834 | editor->setEdited( false); | 835 | editor->setEdited( false); |
835 | edited1=false; | 836 | edited1=false; |
836 | edited=false; | 837 | edited=false; |
837 | if(caption().left(1)=="*") | 838 | if(caption().left(1)=="*") |
838 | setCaption(caption().right(caption().length()-1)); | 839 | setCaption(caption().right(caption().length()-1)); |
839 | 840 | ||
840 | 841 | ||
841 | chmod( file.latin1(), mode); | 842 | chmod( file.latin1(), mode); |
842 | } | 843 | } |
843 | return true; | 844 | return true; |
844 | } | 845 | } |
845 | return false; | 846 | return false; |
846 | } | 847 | } |
847 | 848 | ||
848 | /*! | 849 | /*! |
849 | prompted save */ | 850 | prompted save */ |
850 | bool TextEdit::saveAs() { | 851 | bool TextEdit::saveAs() { |
851 | 852 | ||
852 | if(caption() == tr("Text Editor")) | 853 | if(caption() == tr("Text Editor")) |
853 | return false; | 854 | return false; |
854 | qDebug("saveAsFile " + currentFileName); | 855 | qDebug("saveAsFile " + currentFileName); |
855 | // case of nothing to save... | 856 | // case of nothing to save... |
856 | // if ( !doc && !currentFileName.isEmpty()) { | 857 | // if ( !doc && !currentFileName.isEmpty()) { |
857 | // //|| !bFromDocView) | 858 | // //|| !bFromDocView) |
858 | // qDebug("no doc"); | 859 | // qDebug("no doc"); |
859 | // return true; | 860 | // return true; |
860 | // } | 861 | // } |
861 | // if ( !editor->edited() ) { | 862 | // if ( !editor->edited() ) { |
862 | // delete doc; | 863 | // delete doc; |
863 | // doc = 0; | 864 | // doc = 0; |
864 | // return true; | 865 | // return true; |
865 | // } | 866 | // } |
866 | 867 | ||
867 | QString rt = editor->text(); | 868 | QString rt = editor->text(); |
868 | qDebug(currentFileName); | 869 | qDebug(currentFileName); |
869 | 870 | ||
870 | if( currentFileName.isEmpty() | 871 | if( currentFileName.isEmpty() |
871 | || currentFileName == tr("Unnamed") | 872 | || currentFileName == tr("Unnamed") |
872 | || currentFileName == tr("Text Editor")) { | 873 | || currentFileName == tr("Text Editor")) { |
873 | qDebug("do silly TT filename thing"); | 874 | qDebug("do silly TT filename thing"); |
874 | // if ( doc && doc->name().isEmpty() ) { | 875 | // if ( doc && doc->name().isEmpty() ) { |
875 | QString pt = rt.simplifyWhiteSpace(); | 876 | QString pt = rt.simplifyWhiteSpace(); |
876 | int i = pt.find( ' ' ); | 877 | int i = pt.find( ' ' ); |
877 | QString docname = pt; | 878 | QString docname = pt; |
878 | if ( i > 0 ) | 879 | if ( i > 0 ) |
879 | docname = pt.left( i ); | 880 | docname = pt.left( i ); |
880 | // remove "." at the beginning | 881 | // remove "." at the beginning |
881 | while( docname.startsWith( "." ) ) | 882 | while( docname.startsWith( "." ) ) |
882 | docname = docname.mid( 1 ); | 883 | docname = docname.mid( 1 ); |
883 | docname.replace( QRegExp("/"), "_" ); | 884 | docname.replace( QRegExp("/"), "_" ); |
884 | // cut the length. filenames longer than that | 885 | // cut the length. filenames longer than that |
885 | //don't make sense and something goes wrong when they get too long. | 886 | //don't make sense and something goes wrong when they get too long. |
886 | if ( docname.length() > 40 ) | 887 | if ( docname.length() > 40 ) |
887 | docname = docname.left(40); | 888 | docname = docname.left(40); |
888 | if ( docname.isEmpty() ) | 889 | if ( docname.isEmpty() ) |
889 | docname = tr("Unnamed"); | 890 | docname = tr("Unnamed"); |
890 | if(doc) doc->setName(docname); | 891 | if(doc) doc->setName(docname); |
891 | currentFileName=docname; | 892 | currentFileName=docname; |
892 | // } | 893 | // } |
893 | // else | 894 | // else |
894 | // qDebug("hmmmmmm"); | 895 | // qDebug("hmmmmmm"); |
895 | } | 896 | } |
896 | 897 | ||
897 | 898 | ||
898 | QMap<QString, QStringList> map; | 899 | QMap<QString, QStringList> map; |
899 | map.insert(tr("All"), QStringList() ); | 900 | map.insert(tr("All"), QStringList() ); |
900 | QStringList text; | 901 | QStringList text; |
901 | text << "text/*"; | 902 | text << "text/*"; |
902 | map.insert(tr("Text"), text ); | 903 | map.insert(tr("Text"), text ); |
903 | text << "*"; | 904 | text << "*"; |
904 | map.insert(tr("All"), text ); | 905 | map.insert(tr("All"), text ); |
905 | 906 | ||
906 | QFileInfo cuFi( currentFileName); | 907 | QFileInfo cuFi( currentFileName); |
907 | QString filee = cuFi.fileName(); | 908 | QString filee = cuFi.fileName(); |
908 | QString dire = cuFi.dirPath(); | 909 | QString dire = cuFi.dirPath(); |
909 | if(dire==".") | 910 | if(dire==".") |
910 | dire = QPEApplication::documentDir(); | 911 | dire = QPEApplication::documentDir(); |
911 | QString str; | 912 | QString str; |
912 | if( !featureAutoSave) | 913 | if( !featureAutoSave) { |
913 | { | ||
914 | str = OFileDialog::getSaveFileName( 2, | 914 | str = OFileDialog::getSaveFileName( 2, |
915 | dire, | 915 | dire, |
916 | filee, map); | 916 | filee, map); |
917 | } | 917 | } else |
918 | else | ||
919 | str=currentFileName; | 918 | str=currentFileName; |
919 | |||
920 | if(!str.isEmpty()) { | 920 | if(!str.isEmpty()) { |
921 | QString fileNm=str; | 921 | QString fileNm=str; |
922 | 922 | ||
923 | qDebug("saving filename "+fileNm); | 923 | qDebug("saving filename "+fileNm); |
924 | QFileInfo fi(fileNm); | 924 | QFileInfo fi(fileNm); |
925 | currentFileName=fi.fileName(); | 925 | currentFileName=fi.fileName(); |
926 | if(doc) | 926 | if(doc) |
927 | // QString file = doc->file(); | 927 | // QString file = doc->file(); |
928 | // doc->removeFiles(); | 928 | // doc->removeFiles(); |
929 | delete doc; | 929 | delete doc; |
930 | DocLnk nf; | 930 | DocLnk nf; |
931 | nf.setType("text/plain"); | 931 | nf.setType("text/plain"); |
932 | nf.setFile( fileNm); | 932 | nf.setFile( fileNm); |
933 | doc = new DocLnk(nf); | 933 | doc = new DocLnk(nf); |
934 | // editor->setText(rt); | 934 | // editor->setText(rt); |
935 | qDebug("Saving file as "+currentFileName); | 935 | qDebug("Saving file as "+currentFileName); |
936 | doc->setName( currentFileName); | 936 | doc->setName( currentFileName); |
937 | updateCaption( currentFileName); | 937 | updateCaption( currentFileName); |
938 | 938 | ||
939 | FileManager fm; | 939 | FileManager fm; |
940 | if ( !fm.saveFile( *doc, rt ) ) { | 940 | if ( !fm.saveFile( *doc, rt ) ) { |
941 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | ||
941 | return false; | 942 | return false; |
942 | } | 943 | } |
943 | 944 | ||
944 | if( filePerms ) { | 945 | if( filePerms ) { |
945 | filePermissions *filePerm; | 946 | filePermissions *filePerm; |
946 | filePerm = new filePermissions(this, | 947 | filePerm = new filePermissions(this, |
947 | tr("Permissions"),true, | 948 | tr("Permissions"),true, |
948 | 0,(const QString &)fileNm); | 949 | 0,(const QString &)fileNm); |
949 | QPEApplication::execDialog( filePerm ); | 950 | QPEApplication::execDialog( filePerm ); |
950 | 951 | ||
951 | if( filePerm) | 952 | if( filePerm) |
952 | delete filePerm; | 953 | delete filePerm; |
953 | } | 954 | } |
954 | // } | 955 | // } |
955 | editor->setEdited( false); | 956 | editor->setEdited( false); |
956 | edited1 = false; | 957 | edited1 = false; |
957 | edited = false; | 958 | edited = false; |
958 | if(caption().left(1)=="*") | 959 | if(caption().left(1)=="*") |
959 | setCaption(caption().right(caption().length()-1)); | 960 | setCaption(caption().right(caption().length()-1)); |
960 | 961 | ||
961 | return true; | 962 | return true; |
962 | } | 963 | } |
963 | qDebug("returning false"); | 964 | qDebug("returning false"); |
964 | return false; | 965 | return false; |
965 | } //end saveAs | 966 | } //end saveAs |
966 | 967 | ||
967 | void TextEdit::clear() { | 968 | void TextEdit::clear() { |
968 | delete doc; | 969 | delete doc; |
969 | doc = 0; | 970 | doc = 0; |
970 | editor->clear(); | 971 | editor->clear(); |
971 | } | 972 | } |
972 | 973 | ||
973 | void TextEdit::updateCaption( const QString &name ) { | 974 | void TextEdit::updateCaption( const QString &name ) { |
974 | 975 | ||
975 | if ( name.isEmpty() ) | 976 | if ( name.isEmpty() ) |
976 | setCaption( tr("Text Editor") ); | 977 | setCaption( tr("Text Editor") ); |
977 | else { | 978 | else { |
978 | QString s = name; | 979 | QString s = name; |
979 | if ( s.isNull() ) | 980 | if ( s.isNull() ) |
980 | s = doc->name(); | 981 | s = doc->name(); |
981 | if ( s.isEmpty() ) { | 982 | if ( s.isEmpty() ) { |
982 | s = tr( "Unnamed" ); | 983 | s = tr( "Unnamed" ); |
983 | currentFileName=s; | 984 | currentFileName=s; |
984 | } | 985 | } |
985 | // if(s.left(1) == "/") | 986 | // if(s.left(1) == "/") |
986 | // s = s.right(s.length()-1); | 987 | // s = s.right(s.length()-1); |
987 | setCaption( tr("%1 - Text Editor").arg( s ) ); | 988 | setCaption( tr("%1 - Text Editor").arg( s ) ); |
988 | } | 989 | } |
989 | } | 990 | } |
990 | 991 | ||
991 | void TextEdit::setDocument(const QString& fileref) { | 992 | void TextEdit::setDocument(const QString& fileref) { |
992 | if(fileref != "Unnamed") { | 993 | if(fileref != "Unnamed") { |
993 | currentFileName=fileref; | 994 | currentFileName=fileref; |
994 | qDebug("setDocument"); | 995 | qDebug("setDocument"); |
995 | QFileInfo fi(currentFileName); | 996 | QFileInfo fi(currentFileName); |
996 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 997 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
997 | if( (fi.baseName().left(1)).isEmpty() ) { | 998 | if( (fi.baseName().left(1)).isEmpty() ) { |
998 | openDotFile(currentFileName); | 999 | openDotFile(currentFileName); |
999 | 1000 | ||
1000 | } else { | 1001 | } else { |
1001 | qDebug("setDoc open"); | 1002 | qDebug("setDoc open"); |
1002 | bFromDocView = true; | 1003 | bFromDocView = true; |
1003 | openFile(fileref); | 1004 | openFile(fileref); |
1004 | editor->setEdited(true); | 1005 | editor->setEdited(true); |
1005 | edited1=false; | 1006 | edited1=false; |
1006 | edited=true; | 1007 | edited=true; |
1007 | // fromSetDocument=false; | 1008 | // fromSetDocument=false; |
1008 | // doSearchBar(); | 1009 | // doSearchBar(); |
1009 | } | 1010 | } |
1010 | } | 1011 | } |
1011 | updateCaption( currentFileName); | 1012 | updateCaption( currentFileName); |
1012 | } | 1013 | } |
1013 | 1014 | ||
1014 | void TextEdit::changeFont() { | 1015 | void TextEdit::changeFont() { |
1015 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1016 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1016 | d-> setCaption ( tr( "Choose font" )); | 1017 | d-> setCaption ( tr( "Choose font" )); |
1017 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1018 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1018 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1019 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1019 | lay-> addWidget ( ofs ); | 1020 | lay-> addWidget ( ofs ); |
1020 | ofs-> setSelectedFont ( editor-> font ( )); | 1021 | ofs-> setSelectedFont ( editor-> font ( )); |
1021 | 1022 | ||
1022 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) | 1023 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) |
1023 | editor-> setFont ( ofs-> selectedFont ( )); | 1024 | editor-> setFont ( ofs-> selectedFont ( )); |
1024 | delete d; | 1025 | delete d; |
1025 | 1026 | ||
1026 | } | 1027 | } |
1027 | 1028 | ||
1028 | void TextEdit::editDelete() { | 1029 | void TextEdit::editDelete() { |
1029 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1030 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1030 | tr("Do you really want<BR>to <B>delete</B> " | 1031 | tr("Do you really want<BR>to <B>delete</B> " |
1031 | "the current file\nfrom the disk?<BR>This is " | 1032 | "the current file\nfrom the disk?<BR>This is " |
1032 | "<B>irreversable!</B>"), | 1033 | "<B>irreversable!</B>"), |
1033 | tr("Yes"),tr("No"),0,0,1) ) { | 1034 | tr("Yes"),tr("No"),0,0,1) ) { |
1034 | case 0: | 1035 | case 0: |
1035 | if(doc) { | 1036 | if(doc) { |
1036 | doc->removeFiles(); | 1037 | doc->removeFiles(); |
1037 | clear(); | 1038 | clear(); |
1038 | setCaption( tr("Text Editor") ); | 1039 | setCaption( tr("Text Editor") ); |
1039 | } | 1040 | } |
1040 | break; | 1041 | break; |
1041 | case 1: | 1042 | case 1: |
1042 | // exit | 1043 | // exit |
1043 | break; | 1044 | break; |
1044 | }; | 1045 | }; |
1045 | } | 1046 | } |
1046 | 1047 | ||
1047 | void TextEdit::changeStartConfig( bool b ) { | 1048 | void TextEdit::changeStartConfig( bool b ) { |
1048 | startWithNew=b; | 1049 | startWithNew=b; |
1049 | Config cfg("TextEdit"); | 1050 | Config cfg("TextEdit"); |
1050 | cfg.setGroup("View"); | 1051 | cfg.setGroup("View"); |
1051 | cfg.writeEntry("startNew",b); | 1052 | cfg.writeEntry("startNew",b); |
1052 | update(); | 1053 | update(); |
1053 | } | 1054 | } |
1054 | 1055 | ||
1055 | void TextEdit::editorChanged() { | 1056 | void TextEdit::editorChanged() { |
1056 | // qDebug("editor changed"); | 1057 | // qDebug("editor changed"); |
1057 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1058 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1058 | setCaption( "*"+caption()); | 1059 | setCaption( "*"+caption()); |
1059 | edited1=true; | 1060 | edited1=true; |
1060 | } | 1061 | } |
1061 | edited=true; | 1062 | edited=true; |
1062 | } | 1063 | } |
1063 | 1064 | ||
1064 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1065 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1065 | qDebug("QCop "+msg); | 1066 | qDebug("QCop "+msg); |
1066 | if ( msg == "setDocument(QString)" ) { | 1067 | if ( msg == "setDocument(QString)" ) { |
1067 | qDebug("bugger all"); | 1068 | qDebug("bugger all"); |
1068 | 1069 | ||
1069 | } | 1070 | } |
1070 | 1071 | ||
1071 | } | 1072 | } |
1072 | 1073 | ||
1073 | void TextEdit::doAbout() { | 1074 | void TextEdit::doAbout() { |
1074 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1075 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1075 | "2000 Trolltech AS, and<BR>" | 1076 | "2000 Trolltech AS, and<BR>" |
1076 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1077 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1077 | "and is licensed under the GPL")); | 1078 | "and is licensed under the GPL")); |
1078 | } | 1079 | } |
1079 | 1080 | ||
1080 | void TextEdit::doPrompt(bool b) { | 1081 | void TextEdit::doPrompt(bool b) { |
1081 | promptExit=b; | 1082 | promptExit=b; |
1082 | Config cfg("TextEdit"); | 1083 | Config cfg("TextEdit"); |
1083 | cfg.setGroup ( "View" ); | 1084 | cfg.setGroup ( "View" ); |
1084 | cfg.writeEntry ( "PromptExit", b); | 1085 | cfg.writeEntry ( "PromptExit", b); |
1085 | } | 1086 | } |
1086 | 1087 | ||
1087 | void TextEdit::doDesktop(bool b) { | 1088 | void TextEdit::doDesktop(bool b) { |
1088 | openDesktop=b; | 1089 | openDesktop=b; |
1089 | Config cfg("TextEdit"); | 1090 | Config cfg("TextEdit"); |
1090 | cfg.setGroup ( "View" ); | 1091 | cfg.setGroup ( "View" ); |
1091 | cfg.writeEntry ( "OpenDesktop", b); | 1092 | cfg.writeEntry ( "OpenDesktop", b); |
1092 | } | 1093 | } |
1093 | 1094 | ||
1094 | void TextEdit::doFilePerms(bool b) { | 1095 | void TextEdit::doFilePerms(bool b) { |
1095 | filePerms=b; | 1096 | filePerms=b; |
1096 | Config cfg("TextEdit"); | 1097 | Config cfg("TextEdit"); |
1097 | cfg.setGroup ( "View" ); | 1098 | cfg.setGroup ( "View" ); |
1098 | cfg.writeEntry ( "FilePermissions", b); | 1099 | cfg.writeEntry ( "FilePermissions", b); |
1099 | } | 1100 | } |
1100 | 1101 | ||
1101 | void TextEdit::editPasteTimeDate() { | 1102 | void TextEdit::editPasteTimeDate() { |
1102 | #ifndef QT_NO_CLIPBOARD | 1103 | #ifndef QT_NO_CLIPBOARD |
1103 | QClipboard *cb = QApplication::clipboard(); | 1104 | QClipboard *cb = QApplication::clipboard(); |
1104 | QDateTime dt = QDateTime::currentDateTime(); | 1105 | QDateTime dt = QDateTime::currentDateTime(); |
1105 | cb->setText( dt.toString()); | 1106 | cb->setText( dt.toString()); |
1106 | editor->paste(); | 1107 | editor->paste(); |
1107 | #endif | 1108 | #endif |
1108 | } | 1109 | } |
1109 | 1110 | ||
1110 | int TextEdit::savePrompt() | 1111 | int TextEdit::savePrompt() |
1111 | { | 1112 | { |
1112 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1113 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1113 | (tr("Textedit detected\n" | 1114 | (tr("Textedit detected\n" |
1114 | "you have unsaved changes\n" | 1115 | "you have unsaved changes\n" |
1115 | "Go ahead and save?\n")), | 1116 | "Go ahead and save?\n")), |
1116 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1117 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1117 | { | 1118 | { |
1118 | case 0: | 1119 | case 0: |
1119 | { | 1120 | { |
1120 | return 1; | 1121 | return 1; |
1121 | } | 1122 | } |
1122 | break; | 1123 | break; |
1123 | 1124 | ||
1124 | case 1: | 1125 | case 1: |
1125 | { | 1126 | { |
1126 | return 2; | 1127 | return 2; |
1127 | } | 1128 | } |
1128 | break; | 1129 | break; |
1129 | 1130 | ||
1130 | case 2: | 1131 | case 2: |
1131 | { | 1132 | { |
1132 | return -1; | 1133 | return -1; |
1133 | } | 1134 | } |
1134 | break; | 1135 | break; |
1135 | }; | 1136 | }; |
1136 | 1137 | ||
1137 | return 0; | 1138 | return 0; |
1138 | } | 1139 | } |
1139 | 1140 | ||
1140 | void TextEdit::timerCrank() | 1141 | void TextEdit::timerCrank() |
1141 | { | 1142 | { |
1142 | if(featureAutoSave && edited1) | 1143 | if(featureAutoSave && edited1) |
1143 | { | 1144 | { |
1144 | if(currentFileName.isEmpty()) | 1145 | if(currentFileName.isEmpty()) |
1145 | { | 1146 | { |
1146 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | 1147 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; |
1147 | saveAs(); | 1148 | saveAs(); |
1148 | } | 1149 | } |
1149 | else | 1150 | else |
1150 | { | 1151 | { |
1151 | // qDebug("autosave"); | 1152 | // qDebug("autosave"); |
1152 | save(); | 1153 | save(); |
1153 | } | 1154 | } |
1154 | setTimer(); | 1155 | setTimer(); |
1155 | } | 1156 | } |
1156 | } | 1157 | } |
1157 | 1158 | ||
1158 | void TextEdit::doTimer(bool b) | 1159 | void TextEdit::doTimer(bool b) |
1159 | { | 1160 | { |
1160 | Config cfg("TextEdit"); | 1161 | Config cfg("TextEdit"); |
1161 | cfg.setGroup ( "View" ); | 1162 | cfg.setGroup ( "View" ); |
1162 | cfg.writeEntry ( "autosave", b); | 1163 | cfg.writeEntry ( "autosave", b); |
1163 | featureAutoSave = b; | 1164 | featureAutoSave = b; |
1164 | nAutoSave->setOn(b); | 1165 | nAutoSave->setOn(b); |
1165 | if(b) | 1166 | if(b) |
1166 | { | 1167 | { |
1167 | // qDebug("doTimer true"); | 1168 | // qDebug("doTimer true"); |
1168 | setTimer(); | 1169 | setTimer(); |
1169 | } | 1170 | } |
1170 | // else | 1171 | // else |
1171 | // qDebug("doTimer false"); | 1172 | // qDebug("doTimer false"); |
1172 | } | 1173 | } |
1173 | 1174 | ||
1174 | void TextEdit::setTimer() | 1175 | void TextEdit::setTimer() |
1175 | { | 1176 | { |
1176 | if(featureAutoSave) | 1177 | if(featureAutoSave) |
1177 | { | 1178 | { |
1178 | // qDebug("setting autosave"); | 1179 | // qDebug("setting autosave"); |
1179 | QTimer *timer = new QTimer(this ); | 1180 | QTimer *timer = new QTimer(this ); |
1180 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | 1181 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); |
1181 | timer->start( 300000, true); //5 minutes | 1182 | timer->start( 300000, true); //5 minutes |
1182 | } | 1183 | } |
1183 | } | 1184 | } |
1184 | 1185 | ||
1185 | void TextEdit::gotoLine() { | 1186 | void TextEdit::gotoLine() { |
1186 | if( editor->length() < 1) | 1187 | if( editor->length() < 1) |
1187 | return; | 1188 | return; |
1188 | QWidget *d = QApplication::desktop(); | 1189 | QWidget *d = QApplication::desktop(); |
1189 | gotoEdit = new QLineEdit( 0, "Goto line"); | 1190 | gotoEdit = new QLineEdit( 0, "Goto line"); |
1190 | 1191 | ||
1191 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); | 1192 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); |
1192 | gotoEdit->setFrame(true); | 1193 | gotoEdit->setFrame(true); |
1193 | gotoEdit->show(); | 1194 | gotoEdit->show(); |
1194 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); | 1195 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); |
1195 | } | 1196 | } |
1196 | 1197 | ||
1197 | void TextEdit::doGoto() { | 1198 | void TextEdit::doGoto() { |
1198 | QString number = gotoEdit->text(); | 1199 | QString number = gotoEdit->text(); |
1199 | gotoEdit->hide(); | 1200 | gotoEdit->hide(); |
1200 | 1201 | ||
1201 | if(gotoEdit) { | 1202 | if(gotoEdit) { |
1202 | delete gotoEdit; | 1203 | delete gotoEdit; |
1203 | gotoEdit = 0; | 1204 | gotoEdit = 0; |
1204 | } | 1205 | } |
1205 | 1206 | ||
1206 | bool ok; | 1207 | bool ok; |
1207 | int lineNumber = number.toInt(&ok, 10); | 1208 | int lineNumber = number.toInt(&ok, 10); |
1208 | if( editor->numLines() < lineNumber) | 1209 | if( editor->numLines() < lineNumber) |
1209 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); | 1210 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); |
1210 | else | 1211 | else |
1211 | { | 1212 | { |
1212 | editor->setCursorPosition(lineNumber, 0, false); | 1213 | editor->setCursorPosition(lineNumber, 0, false); |
1213 | } | 1214 | } |
1214 | } | 1215 | } |