author | llornkcor <llornkcor> | 2002-12-16 04:34:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-12-16 04:34:10 (UTC) |
commit | d1d849bab2d54b1e9144bca1f30786882be9a464 (patch) (unidiff) | |
tree | 4a17e9dba5e5ec84cd2344f55640b262d57f0d96 | |
parent | 71f0618e5fdfe7c7f5c251fef3885ee3833d1046 (diff) | |
download | opie-d1d849bab2d54b1e9144bca1f30786882be9a464.zip opie-d1d849bab2d54b1e9144bca1f30786882be9a464.tar.gz opie-d1d849bab2d54b1e9144bca1f30786882be9a464.tar.bz2 |
work around for changing wrap changing edited state. also fixed opening dotFiles line endings
-rw-r--r-- | core/apps/textedit/textedit.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index af427ac..bd7cfb6 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -172,900 +172,907 @@ class QpeEditor : public QMultiLineEdit | |||
172 | // Q_OBJECT | 172 | // Q_OBJECT |
173 | public: | 173 | public: |
174 | QpeEditor( QWidget *parent, const char * name = 0 ) | 174 | QpeEditor( QWidget *parent, const char * name = 0 ) |
175 | : QMultiLineEdit( parent, name ) { | 175 | : QMultiLineEdit( parent, name ) { |
176 | clearTableFlags(); | 176 | clearTableFlags(); |
177 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 177 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
178 | } | 178 | } |
179 | 179 | ||
180 | void find( const QString &txt, bool caseSensitive, | 180 | void find( const QString &txt, bool caseSensitive, |
181 | bool backwards ); | 181 | bool backwards ); |
182 | //public slots: | 182 | //public slots: |
183 | /* | 183 | /* |
184 | signals: | 184 | signals: |
185 | void notFound(); | 185 | void notFound(); |
186 | void searchWrapped(); | 186 | void searchWrapped(); |
187 | */ | 187 | */ |
188 | 188 | ||
189 | private: | 189 | private: |
190 | 190 | ||
191 | }; | 191 | }; |
192 | 192 | ||
193 | 193 | ||
194 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 194 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
195 | bool backwards ) | 195 | bool backwards ) |
196 | { | 196 | { |
197 | static bool wrap = false; | 197 | static bool wrap = false; |
198 | int line, col; | 198 | int line, col; |
199 | if ( wrap ) { | 199 | if ( wrap ) { |
200 | if ( !backwards ) | 200 | if ( !backwards ) |
201 | line = col = 0; | 201 | line = col = 0; |
202 | wrap = false; | 202 | wrap = false; |
203 | // emit searchWrapped(); | 203 | // emit searchWrapped(); |
204 | } else { | 204 | } else { |
205 | getCursorPosition( &line, &col ); | 205 | getCursorPosition( &line, &col ); |
206 | } | 206 | } |
207 | //ignore backwards for now.... | 207 | //ignore backwards for now.... |
208 | if ( !backwards ) { | 208 | if ( !backwards ) { |
209 | for ( ; ; ) { | 209 | for ( ; ; ) { |
210 | if ( line >= numLines() ) { | 210 | if ( line >= numLines() ) { |
211 | wrap = true; | 211 | wrap = true; |
212 | //emit notFound(); | 212 | //emit notFound(); |
213 | break; | 213 | break; |
214 | } | 214 | } |
215 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 215 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
216 | if ( findCol >= 0 ) { | 216 | if ( findCol >= 0 ) { |
217 | setCursorPosition( line, findCol, false ); | 217 | setCursorPosition( line, findCol, false ); |
218 | col = findCol + txt.length(); | 218 | col = findCol + txt.length(); |
219 | setCursorPosition( line, col, true ); | 219 | setCursorPosition( line, col, true ); |
220 | 220 | ||
221 | //found = true; | 221 | //found = true; |
222 | break; | 222 | break; |
223 | } | 223 | } |
224 | line++; | 224 | line++; |
225 | col = 0; | 225 | col = 0; |
226 | } | 226 | } |
227 | } | 227 | } |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
231 | #else | 231 | #else |
232 | 232 | ||
233 | #error "Must make a QpeEditor that inherits QTextEdit" | 233 | #error "Must make a QpeEditor that inherits QTextEdit" |
234 | 234 | ||
235 | #endif | 235 | #endif |
236 | 236 | ||
237 | 237 | ||
238 | static const int nfontsizes = 6; | 238 | static const int nfontsizes = 6; |
239 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 239 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
240 | 240 | ||
241 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 241 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
242 | : QMainWindow( parent, name, f ), bFromDocView( false ) | 242 | : QMainWindow( parent, name, f ), bFromDocView( false ) |
243 | { | 243 | { |
244 | doc = 0; | 244 | doc = 0; |
245 | edited=false; | 245 | edited=false; |
246 | fromSetDocument=false; | 246 | fromSetDocument=false; |
247 | 247 | ||
248 | setToolBarsMovable( false ); | 248 | setToolBarsMovable( false ); |
249 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 249 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
250 | 250 | ||
251 | channel = new QCopChannel( "QPE/Application/textedit", this ); | 251 | channel = new QCopChannel( "QPE/Application/textedit", this ); |
252 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 252 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
253 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 253 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
254 | 254 | ||
255 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 255 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
256 | 256 | ||
257 | QPEToolBar *bar = new QPEToolBar( this ); | 257 | QPEToolBar *bar = new QPEToolBar( this ); |
258 | bar->setHorizontalStretchable( true ); | 258 | bar->setHorizontalStretchable( true ); |
259 | menu = bar; | 259 | menu = bar; |
260 | 260 | ||
261 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 261 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
262 | QPopupMenu *file = new QPopupMenu( this ); | 262 | QPopupMenu *file = new QPopupMenu( this ); |
263 | QPopupMenu *edit = new QPopupMenu( this ); | 263 | QPopupMenu *edit = new QPopupMenu( this ); |
264 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 264 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
265 | 265 | ||
266 | font = new QPopupMenu( this ); | 266 | font = new QPopupMenu( this ); |
267 | 267 | ||
268 | bar = new QPEToolBar( this ); | 268 | bar = new QPEToolBar( this ); |
269 | editBar = bar; | 269 | editBar = bar; |
270 | 270 | ||
271 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 271 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
272 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 272 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
273 | // a->addTo( bar ); | 273 | // a->addTo( bar ); |
274 | a->addTo( file ); | 274 | a->addTo( file ); |
275 | 275 | ||
276 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 276 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
277 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 277 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
278 | a->addTo( bar ); | 278 | a->addTo( bar ); |
279 | a->addTo( file ); | 279 | a->addTo( file ); |
280 | 280 | ||
281 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 281 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
282 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 282 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
283 | file->insertSeparator(); | 283 | file->insertSeparator(); |
284 | a->addTo( bar ); | 284 | a->addTo( bar ); |
285 | a->addTo( file ); | 285 | a->addTo( file ); |
286 | 286 | ||
287 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 287 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
288 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 288 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
289 | a->addTo( file ); | 289 | a->addTo( file ); |
290 | 290 | ||
291 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 291 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
292 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 292 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
293 | a->addTo( editBar ); | 293 | a->addTo( editBar ); |
294 | a->addTo( edit ); | 294 | a->addTo( edit ); |
295 | 295 | ||
296 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 296 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
297 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 297 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
298 | a->addTo( editBar ); | 298 | a->addTo( editBar ); |
299 | a->addTo( edit ); | 299 | a->addTo( edit ); |
300 | 300 | ||
301 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 301 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
302 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 302 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
303 | a->addTo( editBar ); | 303 | a->addTo( editBar ); |
304 | a->addTo( edit ); | 304 | a->addTo( edit ); |
305 | 305 | ||
306 | 306 | ||
307 | #ifndef QT_NO_CLIPBOARD | 307 | #ifndef QT_NO_CLIPBOARD |
308 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 308 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
309 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 309 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
310 | a->addTo( edit ); | 310 | a->addTo( edit ); |
311 | #endif | 311 | #endif |
312 | 312 | ||
313 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 313 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
314 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 314 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
315 | edit->insertSeparator(); | 315 | edit->insertSeparator(); |
316 | a->addTo( bar ); | 316 | a->addTo( bar ); |
317 | a->addTo( edit ); | 317 | a->addTo( edit ); |
318 | 318 | ||
319 | 319 | ||
320 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 320 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
321 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 321 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
322 | zin->addTo( font ); | 322 | zin->addTo( font ); |
323 | 323 | ||
324 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 324 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
325 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 325 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
326 | zout->addTo( font ); | 326 | zout->addTo( font ); |
327 | 327 | ||
328 | font->insertSeparator(); | 328 | font->insertSeparator(); |
329 | // font->insertSeparator(); | 329 | // font->insertSeparator(); |
330 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 330 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
331 | 331 | ||
332 | font->insertSeparator(); | 332 | font->insertSeparator(); |
333 | font->insertItem(tr("Advanced Features"), advancedMenu); | 333 | font->insertItem(tr("Advanced Features"), advancedMenu); |
334 | 334 | ||
335 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 335 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
336 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 336 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
337 | wa->setToggleAction(true); | 337 | wa->setToggleAction(true); |
338 | wa->addTo( advancedMenu); | 338 | wa->addTo( advancedMenu); |
339 | 339 | ||
340 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 340 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); |
341 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 341 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); |
342 | nStart->setToggleAction(true); | 342 | nStart->setToggleAction(true); |
343 | nStart->addTo( advancedMenu ); | 343 | nStart->addTo( advancedMenu ); |
344 | nStart->setEnabled(false); | 344 | nStart->setEnabled(false); |
345 | 345 | ||
346 | nAdvanced = new QAction( tr("Prompt on Exit"), QString::null, 0, this, 0 ); | 346 | nAdvanced = new QAction( tr("Prompt on Exit"), QString::null, 0, this, 0 ); |
347 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) ); | 347 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) ); |
348 | nAdvanced->setToggleAction(true); | 348 | nAdvanced->setToggleAction(true); |
349 | nAdvanced->addTo( advancedMenu ); | 349 | nAdvanced->addTo( advancedMenu ); |
350 | 350 | ||
351 | desktopAction = new QAction( tr("Always open linked file"), QString::null, 0, this, 0 ); | 351 | desktopAction = new QAction( tr("Always open linked file"), QString::null, 0, this, 0 ); |
352 | connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) ); | 352 | connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) ); |
353 | desktopAction->setToggleAction(true); | 353 | desktopAction->setToggleAction(true); |
354 | desktopAction->addTo( advancedMenu); | 354 | desktopAction->addTo( advancedMenu); |
355 | 355 | ||
356 | filePermAction = new QAction( tr("File Permissions"), QString::null, 0, this, 0 ); | 356 | filePermAction = new QAction( tr("File Permissions"), QString::null, 0, this, 0 ); |
357 | connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) ); | 357 | connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) ); |
358 | filePermAction->setToggleAction(true); | 358 | filePermAction->setToggleAction(true); |
359 | filePermAction->addTo( advancedMenu); | 359 | filePermAction->addTo( advancedMenu); |
360 | 360 | ||
361 | searchBarAction = new QAction( tr("Search Bar Open"), QString::null, 0, this, 0 ); | 361 | searchBarAction = new QAction( tr("Search Bar Open"), QString::null, 0, this, 0 ); |
362 | connect( searchBarAction, SIGNAL( toggled(bool) ), this, SLOT( setSearchBar(bool) ) ); | 362 | connect( searchBarAction, SIGNAL( toggled(bool) ), this, SLOT( setSearchBar(bool) ) ); |
363 | searchBarAction->setToggleAction(true); | 363 | searchBarAction->setToggleAction(true); |
364 | searchBarAction->addTo( advancedMenu); | 364 | searchBarAction->addTo( advancedMenu); |
365 | 365 | ||
366 | 366 | ||
367 | font->insertSeparator(); | 367 | font->insertSeparator(); |
368 | 368 | ||
369 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 369 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
370 | 370 | ||
371 | mb->insertItem( tr( "File" ), file ); | 371 | mb->insertItem( tr( "File" ), file ); |
372 | mb->insertItem( tr( "Edit" ), edit ); | 372 | mb->insertItem( tr( "Edit" ), edit ); |
373 | mb->insertItem( tr( "View" ), font ); | 373 | mb->insertItem( tr( "View" ), font ); |
374 | 374 | ||
375 | searchBar = new QPEToolBar(this); | 375 | searchBar = new QPEToolBar(this); |
376 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 376 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
377 | 377 | ||
378 | searchBar->setHorizontalStretchable( true ); | 378 | searchBar->setHorizontalStretchable( true ); |
379 | 379 | ||
380 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 380 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
381 | searchBar->setStretchableWidget( searchEdit ); | 381 | searchBar->setStretchableWidget( searchEdit ); |
382 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 382 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
383 | this, SLOT( search() ) ); | 383 | this, SLOT( search() ) ); |
384 | 384 | ||
385 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 385 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
386 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 386 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
387 | a->addTo( searchBar ); | 387 | a->addTo( searchBar ); |
388 | a->addTo( edit ); | 388 | a->addTo( edit ); |
389 | 389 | ||
390 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 390 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
391 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 391 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
392 | a->addTo( searchBar ); | 392 | a->addTo( searchBar ); |
393 | 393 | ||
394 | edit->insertSeparator(); | 394 | edit->insertSeparator(); |
395 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 395 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
396 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 396 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
397 | a->addTo( edit ); | 397 | a->addTo( edit ); |
398 | 398 | ||
399 | searchBar->hide(); | 399 | searchBar->hide(); |
400 | 400 | ||
401 | editor = new QpeEditor( this ); | 401 | editor = new QpeEditor( this ); |
402 | setCentralWidget( editor ); | 402 | setCentralWidget( editor ); |
403 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 403 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
404 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); | 404 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); |
405 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 405 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
406 | 406 | ||
407 | Config cfg("TextEdit"); | 407 | Config cfg("TextEdit"); |
408 | cfg. setGroup ( "Font" ); | 408 | cfg. setGroup ( "Font" ); |
409 | 409 | ||
410 | QFont defaultFont = editor-> font ( ); | 410 | QFont defaultFont = editor-> font ( ); |
411 | 411 | ||
412 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 412 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
413 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 413 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
414 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 414 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
415 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 415 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
416 | 416 | ||
417 | defaultFont = QFont ( family, size, weight, italic ); | 417 | defaultFont = QFont ( family, size, weight, italic ); |
418 | editor-> setFont ( defaultFont ); | 418 | editor-> setFont ( defaultFont ); |
419 | 419 | ||
420 | // updateCaption(); | 420 | // updateCaption(); |
421 | 421 | ||
422 | cfg.setGroup ( "View" ); | 422 | cfg.setGroup ( "View" ); |
423 | 423 | ||
424 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 424 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
425 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 425 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
426 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 426 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
427 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 427 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
428 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 428 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
429 | 429 | ||
430 | if(useSearchBar) searchBarAction->setOn(true); | 430 | if(useSearchBar) searchBarAction->setOn(true); |
431 | if(promptExit ) nAdvanced->setOn( true ); | 431 | if(promptExit ) nAdvanced->setOn( true ); |
432 | if(openDesktop) desktopAction->setOn( true ); | 432 | if(openDesktop) desktopAction->setOn( true ); |
433 | if(filePerms) filePermAction->setOn( true ); | 433 | if(filePerms) filePermAction->setOn( true ); |
434 | if(startWithNew) nStart->setOn( true ); | 434 | if(startWithNew) nStart->setOn( true ); |
435 | 435 | ||
436 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 436 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
437 | wa-> setOn ( wrap ); | 437 | wa-> setOn ( wrap ); |
438 | setWordWrap ( wrap ); | 438 | setWordWrap ( wrap ); |
439 | 439 | ||
440 | if( qApp->argc() > 1) { | 440 | if( qApp->argc() > 1) { |
441 | currentFileName=qApp->argv()[1]; | 441 | currentFileName=qApp->argv()[1]; |
442 | 442 | ||
443 | QFileInfo fi(currentFileName); | 443 | QFileInfo fi(currentFileName); |
444 | 444 | ||
445 | if(fi.baseName().left(1) == "") { | 445 | if(fi.baseName().left(1) == "") { |
446 | openDotFile(currentFileName); | 446 | openDotFile(currentFileName); |
447 | } else { | 447 | } else { |
448 | openFile(currentFileName); | 448 | openFile(currentFileName); |
449 | } | 449 | } |
450 | } else { | 450 | } else { |
451 | edited1=false; | 451 | edited1=false; |
452 | 452 | ||
453 | // if(startWithNew ) { | 453 | // if(startWithNew ) { |
454 | openDotFile(""); | 454 | openDotFile(""); |
455 | // fileNew(); | 455 | // fileNew(); |
456 | // } | 456 | // } |
457 | // else { | 457 | // else { |
458 | // fileOpen(); | 458 | // fileOpen(); |
459 | // } | 459 | // } |
460 | } | 460 | } |
461 | 461 | ||
462 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 462 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
463 | // setCaption(tr("Text Editor")); | 463 | // setCaption(tr("Text Editor")); |
464 | } | 464 | } |
465 | 465 | ||
466 | TextEdit::~TextEdit() { | 466 | TextEdit::~TextEdit() { |
467 | // qDebug("destr"); | 467 | // qDebug("destr"); |
468 | } | 468 | } |
469 | 469 | ||
470 | void TextEdit::closeEvent(QCloseEvent *) { | 470 | void TextEdit::closeEvent(QCloseEvent *) { |
471 | // qDebug("closing here"); | 471 | // qDebug("closing here"); |
472 | if( edited1 && promptExit) | 472 | if( edited1 && promptExit) |
473 | saveAs(); | 473 | saveAs(); |
474 | qApp->quit(); | 474 | qApp->quit(); |
475 | } | 475 | } |
476 | 476 | ||
477 | void TextEdit::cleanUp() { | 477 | void TextEdit::cleanUp() { |
478 | // qDebug("cleanUp");// save(); | 478 | // qDebug("cleanUp");// save(); |
479 | 479 | ||
480 | Config cfg ( "TextEdit" ); | 480 | Config cfg ( "TextEdit" ); |
481 | cfg. setGroup ( "Font" ); | 481 | cfg. setGroup ( "Font" ); |
482 | QFont f = editor->font(); | 482 | QFont f = editor->font(); |
483 | cfg.writeEntry ( "Family", f. family ( )); | 483 | cfg.writeEntry ( "Family", f. family ( )); |
484 | cfg.writeEntry ( "Size", f. pointSize ( )); | 484 | cfg.writeEntry ( "Size", f. pointSize ( )); |
485 | cfg.writeEntry ( "Weight", f. weight ( )); | 485 | cfg.writeEntry ( "Weight", f. weight ( )); |
486 | cfg.writeEntry ( "Italic", f. italic ( )); | 486 | cfg.writeEntry ( "Italic", f. italic ( )); |
487 | 487 | ||
488 | cfg.setGroup ( "View" ); | 488 | cfg.setGroup ( "View" ); |
489 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 489 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
490 | cfg.writeEntry ( "FileView", viewSelection ); | 490 | cfg.writeEntry ( "FileView", viewSelection ); |
491 | 491 | ||
492 | cfg.writeEntry ( "PromptExit", promptExit ); | 492 | cfg.writeEntry ( "PromptExit", promptExit ); |
493 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 493 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
494 | cfg.writeEntry ( "FilePermissions", filePerms ); | 494 | cfg.writeEntry ( "FilePermissions", filePerms ); |
495 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 495 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
496 | cfg.writeEntry ( "startNew", startWithNew ); | 496 | cfg.writeEntry ( "startNew", startWithNew ); |
497 | 497 | ||
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
501 | void TextEdit::accept() { | 501 | void TextEdit::accept() { |
502 | // qDebug("accept"); | 502 | // qDebug("accept"); |
503 | if( edited1) | 503 | if( edited1) |
504 | saveAs(); | 504 | saveAs(); |
505 | qApp->quit(); | 505 | qApp->quit(); |
506 | } | 506 | } |
507 | 507 | ||
508 | void TextEdit::zoomIn() { | 508 | void TextEdit::zoomIn() { |
509 | setFontSize(editor->font().pointSize()+1,false); | 509 | setFontSize(editor->font().pointSize()+1,false); |
510 | } | 510 | } |
511 | 511 | ||
512 | void TextEdit::zoomOut() { | 512 | void TextEdit::zoomOut() { |
513 | setFontSize(editor->font().pointSize()-1,true); | 513 | setFontSize(editor->font().pointSize()-1,true); |
514 | } | 514 | } |
515 | 515 | ||
516 | 516 | ||
517 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 517 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
518 | int s=10; | 518 | int s=10; |
519 | for (int i=0; i<nfontsizes; i++) { | 519 | for (int i=0; i<nfontsizes; i++) { |
520 | if ( fontsize[i] == sz ) { | 520 | if ( fontsize[i] == sz ) { |
521 | s = sz; | 521 | s = sz; |
522 | break; | 522 | break; |
523 | } else if ( round_down_not_up ) { | 523 | } else if ( round_down_not_up ) { |
524 | if ( fontsize[i] < sz ) | 524 | if ( fontsize[i] < sz ) |
525 | s = fontsize[i]; | 525 | s = fontsize[i]; |
526 | } else { | 526 | } else { |
527 | if ( fontsize[i] > sz ) { | 527 | if ( fontsize[i] > sz ) { |
528 | s = fontsize[i]; | 528 | s = fontsize[i]; |
529 | break; | 529 | break; |
530 | } | 530 | } |
531 | } | 531 | } |
532 | } | 532 | } |
533 | 533 | ||
534 | QFont f = editor->font(); | 534 | QFont f = editor->font(); |
535 | f.setPointSize(s); | 535 | f.setPointSize(s); |
536 | editor->setFont(f); | 536 | editor->setFont(f); |
537 | 537 | ||
538 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 538 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
539 | zout->setEnabled(s != fontsize[0]); | 539 | zout->setEnabled(s != fontsize[0]); |
540 | } | 540 | } |
541 | 541 | ||
542 | void TextEdit::setBold(bool y) { | 542 | void TextEdit::setBold(bool y) { |
543 | QFont f = editor->font(); | 543 | QFont f = editor->font(); |
544 | f.setBold(y); | 544 | f.setBold(y); |
545 | editor->setFont(f); | 545 | editor->setFont(f); |
546 | } | 546 | } |
547 | 547 | ||
548 | void TextEdit::setItalic(bool y) { | 548 | void TextEdit::setItalic(bool y) { |
549 | QFont f = editor->font(); | 549 | QFont f = editor->font(); |
550 | f.setItalic(y); | 550 | f.setItalic(y); |
551 | editor->setFont(f); | 551 | editor->setFont(f); |
552 | } | 552 | } |
553 | 553 | ||
554 | void TextEdit::setWordWrap(bool y) { | 554 | void TextEdit::setWordWrap(bool y) { |
555 | bool state = editor->edited(); | 555 | bool state = editor->edited(); |
556 | QString captionStr = caption(); | ||
557 | bool b1 = edited1; | ||
558 | bool b2 = edited; | ||
559 | |||
556 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 560 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
557 | editor->setEdited( state ); | 561 | editor->setEdited( state ); |
562 | edited1=b1; | ||
563 | edited=b2; | ||
564 | setCaption(captionStr); | ||
558 | } | 565 | } |
559 | 566 | ||
560 | void TextEdit::setSearchBar(bool b) { | 567 | void TextEdit::setSearchBar(bool b) { |
561 | useSearchBar=b; | 568 | useSearchBar=b; |
562 | Config cfg("TextEdit"); | 569 | Config cfg("TextEdit"); |
563 | cfg.setGroup("View"); | 570 | cfg.setGroup("View"); |
564 | cfg.writeEntry ( "SearchBar", b ); | 571 | cfg.writeEntry ( "SearchBar", b ); |
565 | searchBarAction->setOn(b); | 572 | searchBarAction->setOn(b); |
566 | if(b) | 573 | if(b) |
567 | searchBar->show(); | 574 | searchBar->show(); |
568 | else | 575 | else |
569 | searchBar->hide(); | 576 | searchBar->hide(); |
570 | editor->setFocus(); | 577 | editor->setFocus(); |
571 | } | 578 | } |
572 | 579 | ||
573 | void TextEdit::fileNew() { | 580 | void TextEdit::fileNew() { |
574 | // if( !bFromDocView ) { | 581 | // if( !bFromDocView ) { |
575 | // saveAs(); | 582 | // saveAs(); |
576 | // } | 583 | // } |
577 | newFile(DocLnk()); | 584 | newFile(DocLnk()); |
578 | } | 585 | } |
579 | 586 | ||
580 | void TextEdit::fileOpen() { | 587 | void TextEdit::fileOpen() { |
581 | QMap<QString, QStringList> map; | 588 | QMap<QString, QStringList> map; |
582 | map.insert(tr("All"), QStringList() ); | 589 | map.insert(tr("All"), QStringList() ); |
583 | QStringList text; | 590 | QStringList text; |
584 | text << "text/*"; | 591 | text << "text/*"; |
585 | map.insert(tr("Text"), text ); | 592 | map.insert(tr("Text"), text ); |
586 | text << "*"; | 593 | text << "*"; |
587 | map.insert(tr("All"), text ); | 594 | map.insert(tr("All"), text ); |
588 | QString str = OFileDialog::getOpenFileName( 2, | 595 | QString str = OFileDialog::getOpenFileName( 2, |
589 | QPEApplication::documentDir(), | 596 | QPEApplication::documentDir(), |
590 | QString::null, map); | 597 | QString::null, map); |
591 | if( QFile(str).exists()) | 598 | if( QFile(str).exists()) |
592 | openFile( str ); | 599 | openFile( str ); |
593 | else | 600 | else |
594 | updateCaption(); | 601 | updateCaption(); |
595 | } | 602 | } |
596 | 603 | ||
597 | void TextEdit::doSearchBar() { | 604 | void TextEdit::doSearchBar() { |
598 | if(!useSearchBar) | 605 | if(!useSearchBar) |
599 | searchBar->hide(); | 606 | searchBar->hide(); |
600 | else | 607 | else |
601 | searchBar->show(); | 608 | searchBar->show(); |
602 | } | 609 | } |
603 | 610 | ||
604 | #if 0 | 611 | #if 0 |
605 | void TextEdit::slotFind() { | 612 | void TextEdit::slotFind() { |
606 | FindDialog frmFind( tr("Text Editor"), this ); | 613 | FindDialog frmFind( tr("Text Editor"), this ); |
607 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 614 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
608 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 615 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
609 | 616 | ||
610 | //case sensitive, backwards, [category] | 617 | //case sensitive, backwards, [category] |
611 | 618 | ||
612 | connect( editor, SIGNAL(notFound()), | 619 | connect( editor, SIGNAL(notFound()), |
613 | &frmFind, SLOT(slotNotFound()) ); | 620 | &frmFind, SLOT(slotNotFound()) ); |
614 | connect( editor, SIGNAL(searchWrapped()), | 621 | connect( editor, SIGNAL(searchWrapped()), |
615 | &frmFind, SLOT(slotWrapAround()) ); | 622 | &frmFind, SLOT(slotWrapAround()) ); |
616 | 623 | ||
617 | frmFind.exec(); | 624 | frmFind.exec(); |
618 | 625 | ||
619 | 626 | ||
620 | } | 627 | } |
621 | #endif | 628 | #endif |
622 | 629 | ||
623 | void TextEdit::fileRevert() { | 630 | void TextEdit::fileRevert() { |
624 | clear(); | 631 | clear(); |
625 | fileOpen(); | 632 | fileOpen(); |
626 | } | 633 | } |
627 | 634 | ||
628 | void TextEdit::editCut() { | 635 | void TextEdit::editCut() { |
629 | #ifndef QT_NO_CLIPBOARD | 636 | #ifndef QT_NO_CLIPBOARD |
630 | editor->cut(); | 637 | editor->cut(); |
631 | #endif | 638 | #endif |
632 | } | 639 | } |
633 | 640 | ||
634 | void TextEdit::editCopy() { | 641 | void TextEdit::editCopy() { |
635 | #ifndef QT_NO_CLIPBOARD | 642 | #ifndef QT_NO_CLIPBOARD |
636 | editor->copy(); | 643 | editor->copy(); |
637 | #endif | 644 | #endif |
638 | } | 645 | } |
639 | 646 | ||
640 | void TextEdit::editPaste() { | 647 | void TextEdit::editPaste() { |
641 | #ifndef QT_NO_CLIPBOARD | 648 | #ifndef QT_NO_CLIPBOARD |
642 | editor->paste(); | 649 | editor->paste(); |
643 | #endif | 650 | #endif |
644 | } | 651 | } |
645 | 652 | ||
646 | void TextEdit::editFind() { | 653 | void TextEdit::editFind() { |
647 | searchBar->show(); | 654 | searchBar->show(); |
648 | searchEdit->setFocus(); | 655 | searchEdit->setFocus(); |
649 | } | 656 | } |
650 | 657 | ||
651 | void TextEdit::findNext() { | 658 | void TextEdit::findNext() { |
652 | editor->find( searchEdit->text(), false, false ); | 659 | editor->find( searchEdit->text(), false, false ); |
653 | 660 | ||
654 | } | 661 | } |
655 | 662 | ||
656 | void TextEdit::findClose() { | 663 | void TextEdit::findClose() { |
657 | searchBar->hide(); | 664 | searchBar->hide(); |
658 | } | 665 | } |
659 | 666 | ||
660 | void TextEdit::search() { | 667 | void TextEdit::search() { |
661 | editor->find( searchEdit->text(), false, false ); | 668 | editor->find( searchEdit->text(), false, false ); |
662 | } | 669 | } |
663 | 670 | ||
664 | void TextEdit::newFile( const DocLnk &f ) { | 671 | void TextEdit::newFile( const DocLnk &f ) { |
665 | DocLnk nf = f; | 672 | DocLnk nf = f; |
666 | nf.setType("text/plain"); | 673 | nf.setType("text/plain"); |
667 | clear(); | 674 | clear(); |
668 | setWState (WState_Reserved1 ); | 675 | setWState (WState_Reserved1 ); |
669 | editor->setFocus(); | 676 | editor->setFocus(); |
670 | doc = new DocLnk(nf); | 677 | doc = new DocLnk(nf); |
671 | currentFileName = "Unnamed"; | 678 | currentFileName = "Unnamed"; |
672 | qDebug("newFile "+currentFileName); | 679 | qDebug("newFile "+currentFileName); |
673 | updateCaption( currentFileName); | 680 | updateCaption( currentFileName); |
674 | // editor->setEdited( false); | 681 | // editor->setEdited( false); |
675 | } | 682 | } |
676 | 683 | ||
677 | void TextEdit::openDotFile( const QString &f ) { | 684 | void TextEdit::openDotFile( const QString &f ) { |
678 | if(!currentFileName.isEmpty()) { | 685 | if(!currentFileName.isEmpty()) { |
679 | currentFileName=f; | 686 | currentFileName=f; |
680 | 687 | ||
681 | qDebug("openFile dotfile " + currentFileName); | 688 | qDebug("openFile dotfile " + currentFileName); |
682 | QString txt; | 689 | QString txt; |
683 | QFile file(f); | 690 | QFile file(f); |
684 | file.open(IO_ReadWrite); | 691 | file.open(IO_ReadWrite); |
685 | QTextStream t(&file); | 692 | QTextStream t(&file); |
686 | while ( !t.atEnd()) { | 693 | while ( !t.atEnd()) { |
687 | txt+=t.readLine(); | 694 | txt+=t.readLine()+"\n"; |
688 | } | 695 | } |
689 | editor->setText(txt); | 696 | editor->setText(txt); |
690 | editor->setEdited( false); | 697 | editor->setEdited( false); |
691 | edited1=false; | 698 | edited1=false; |
692 | edited=false; | 699 | edited=false; |
693 | 700 | ||
694 | 701 | ||
695 | } | 702 | } |
696 | updateCaption( currentFileName); | 703 | updateCaption( currentFileName); |
697 | } | 704 | } |
698 | 705 | ||
699 | void TextEdit::openFile( const QString &f ) { | 706 | void TextEdit::openFile( const QString &f ) { |
700 | qDebug("filename is "+ f); | 707 | qDebug("filename is "+ f); |
701 | QString filer; | 708 | QString filer; |
702 | QFileInfo fi( f); | 709 | QFileInfo fi( f); |
703 | // bFromDocView = true; | 710 | // bFromDocView = true; |
704 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { | 711 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { |
705 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 712 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
706 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> | 713 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> |
707 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | 714 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), |
708 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 715 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
709 | case 0: | 716 | case 0: |
710 | filer = f; | 717 | filer = f; |
711 | break; | 718 | break; |
712 | case 1: | 719 | case 1: |
713 | DocLnk sf(f); | 720 | DocLnk sf(f); |
714 | filer = sf.file(); | 721 | filer = sf.file(); |
715 | break; | 722 | break; |
716 | } | 723 | } |
717 | } else if(fi.baseName().left(1) == "") { | 724 | } else if(fi.baseName().left(1) == "") { |
718 | currentFileName=f; | 725 | currentFileName=f; |
719 | openDotFile(currentFileName); | 726 | openDotFile(currentFileName); |
720 | } else { | 727 | } else { |
721 | DocLnk sf(f); | 728 | DocLnk sf(f); |
722 | filer = sf.file(); | 729 | filer = sf.file(); |
723 | if(filer.right(1) == "/") | 730 | if(filer.right(1) == "/") |
724 | filer = f; | 731 | filer = f; |
725 | } | 732 | } |
726 | 733 | ||
727 | DocLnk nf; | 734 | DocLnk nf; |
728 | nf.setType("text/plain"); | 735 | nf.setType("text/plain"); |
729 | nf.setFile(filer); | 736 | nf.setFile(filer); |
730 | currentFileName=filer; | 737 | currentFileName=filer; |
731 | 738 | ||
732 | nf.setName(fi.baseName()); | 739 | nf.setName(fi.baseName()); |
733 | openFile(nf); | 740 | openFile(nf); |
734 | 741 | ||
735 | qDebug("openFile string "+currentFileName); | 742 | qDebug("openFile string "+currentFileName); |
736 | 743 | ||
737 | showEditTools(); | 744 | showEditTools(); |
738 | // Show filename in caption | 745 | // Show filename in caption |
739 | QString name = filer; | 746 | QString name = filer; |
740 | int sep = name.findRev( '/' ); | 747 | int sep = name.findRev( '/' ); |
741 | if ( sep > 0 ) | 748 | if ( sep > 0 ) |
742 | name = name.mid( sep+1 ); | 749 | name = name.mid( sep+1 ); |
743 | updateCaption( name ); | 750 | updateCaption( name ); |
744 | } | 751 | } |
745 | 752 | ||
746 | void TextEdit::openFile( const DocLnk &f ) { | 753 | void TextEdit::openFile( const DocLnk &f ) { |
747 | // clear(); | 754 | // clear(); |
748 | // bFromDocView = true; | 755 | // bFromDocView = true; |
749 | FileManager fm; | 756 | FileManager fm; |
750 | QString txt; | 757 | QString txt; |
751 | currentFileName=f.file(); | 758 | currentFileName=f.file(); |
752 | qDebug("openFile doclnk " + currentFileName); | 759 | qDebug("openFile doclnk " + currentFileName); |
753 | if ( !fm.loadFile( f, txt ) ) { | 760 | if ( !fm.loadFile( f, txt ) ) { |
754 | // ####### could be a new file | 761 | // ####### could be a new file |
755 | qDebug( "Cannot open file" ); | 762 | qDebug( "Cannot open file" ); |
756 | } | 763 | } |
757 | // fileNew(); | 764 | // fileNew(); |
758 | if ( doc ) | 765 | if ( doc ) |
759 | delete doc; | 766 | delete doc; |
760 | doc = new DocLnk(f); | 767 | doc = new DocLnk(f); |
761 | editor->setText(txt); | 768 | editor->setText(txt); |
762 | editor->setEdited( false); | 769 | editor->setEdited( false); |
763 | edited1=false; | 770 | edited1=false; |
764 | edited=false; | 771 | edited=false; |
765 | 772 | ||
766 | doc->setName(currentFileName); | 773 | doc->setName(currentFileName); |
767 | updateCaption(); | 774 | updateCaption(); |
768 | } | 775 | } |
769 | 776 | ||
770 | void TextEdit::showEditTools() { | 777 | void TextEdit::showEditTools() { |
771 | menu->show(); | 778 | menu->show(); |
772 | editBar->show(); | 779 | editBar->show(); |
773 | if(!useSearchBar) | 780 | if(!useSearchBar) |
774 | searchBar->hide(); | 781 | searchBar->hide(); |
775 | else | 782 | else |
776 | searchBar->show(); | 783 | searchBar->show(); |
777 | setWState (WState_Reserved1 ); | 784 | setWState (WState_Reserved1 ); |
778 | } | 785 | } |
779 | 786 | ||
780 | /*! | 787 | /*! |
781 | unprompted save */ | 788 | unprompted save */ |
782 | bool TextEdit::save() { | 789 | bool TextEdit::save() { |
783 | QString file = doc->file(); | 790 | QString file = doc->file(); |
784 | qDebug("saver file "+file); | 791 | qDebug("saver file "+file); |
785 | QString name= doc->name(); | 792 | QString name= doc->name(); |
786 | qDebug("File named "+name); | 793 | qDebug("File named "+name); |
787 | QString rt = editor->text(); | 794 | QString rt = editor->text(); |
788 | if( !rt.isEmpty() ) { | 795 | if( !rt.isEmpty() ) { |
789 | if(name.isEmpty()) { | 796 | if(name.isEmpty()) { |
790 | saveAs(); | 797 | saveAs(); |
791 | } else { | 798 | } else { |
792 | currentFileName= name ; | 799 | currentFileName= name ; |
793 | qDebug("saveFile "+currentFileName); | 800 | qDebug("saveFile "+currentFileName); |
794 | 801 | ||
795 | struct stat buf; | 802 | struct stat buf; |
796 | mode_t mode; | 803 | mode_t mode; |
797 | stat(file.latin1(), &buf); | 804 | stat(file.latin1(), &buf); |
798 | mode = buf.st_mode; | 805 | mode = buf.st_mode; |
799 | 806 | ||
800 | if(!fileIs) { | 807 | if(!fileIs) { |
801 | doc->setName( name); | 808 | doc->setName( name); |
802 | FileManager fm; | 809 | FileManager fm; |
803 | if ( !fm.saveFile( *doc, rt ) ) { | 810 | if ( !fm.saveFile( *doc, rt ) ) { |
804 | return false; | 811 | return false; |
805 | } | 812 | } |
806 | } else { | 813 | } else { |
807 | qDebug("regular save file"); | 814 | qDebug("regular save file"); |
808 | QFile f(file); | 815 | QFile f(file); |
809 | if( f.open(IO_WriteOnly)) { | 816 | if( f.open(IO_WriteOnly)) { |
810 | QCString crt = rt.utf8(); | 817 | QCString crt = rt.utf8(); |
811 | f.writeBlock(crt,crt.length()); | 818 | f.writeBlock(crt,crt.length()); |
812 | } else { | 819 | } else { |
813 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 820 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
814 | return false; | 821 | return false; |
815 | } | 822 | } |
816 | 823 | ||
817 | } | 824 | } |
818 | editor->setEdited( false); | 825 | editor->setEdited( false); |
819 | edited1=false; | 826 | edited1=false; |
820 | edited=false; | 827 | edited=false; |
821 | if(caption().left(1)=="*") | 828 | if(caption().left(1)=="*") |
822 | setCaption(caption().right(caption().length()-1)); | 829 | setCaption(caption().right(caption().length()-1)); |
823 | 830 | ||
824 | 831 | ||
825 | chmod( file.latin1(), mode); | 832 | chmod( file.latin1(), mode); |
826 | } | 833 | } |
827 | return true; | 834 | return true; |
828 | } | 835 | } |
829 | return false; | 836 | return false; |
830 | } | 837 | } |
831 | 838 | ||
832 | /*! | 839 | /*! |
833 | prompted save */ | 840 | prompted save */ |
834 | bool TextEdit::saveAs() { | 841 | bool TextEdit::saveAs() { |
835 | if(caption() == tr("Text Editor")) | 842 | if(caption() == tr("Text Editor")) |
836 | return false; | 843 | return false; |
837 | qDebug("saveAsFile " + currentFileName); | 844 | qDebug("saveAsFile " + currentFileName); |
838 | // case of nothing to save... | 845 | // case of nothing to save... |
839 | // if ( !doc && !currentFileName.isEmpty()) { | 846 | // if ( !doc && !currentFileName.isEmpty()) { |
840 | // //|| !bFromDocView) | 847 | // //|| !bFromDocView) |
841 | // qDebug("no doc"); | 848 | // qDebug("no doc"); |
842 | // return true; | 849 | // return true; |
843 | // } | 850 | // } |
844 | // if ( !editor->edited() ) { | 851 | // if ( !editor->edited() ) { |
845 | // delete doc; | 852 | // delete doc; |
846 | // doc = 0; | 853 | // doc = 0; |
847 | // return true; | 854 | // return true; |
848 | // } | 855 | // } |
849 | 856 | ||
850 | QString rt = editor->text(); | 857 | QString rt = editor->text(); |
851 | qDebug(currentFileName); | 858 | qDebug(currentFileName); |
852 | 859 | ||
853 | if( currentFileName.isEmpty() | 860 | if( currentFileName.isEmpty() |
854 | || currentFileName == tr("Unnamed") | 861 | || currentFileName == tr("Unnamed") |
855 | || currentFileName == tr("Text Editor")) { | 862 | || currentFileName == tr("Text Editor")) { |
856 | qDebug("do silly TT filename thing"); | 863 | qDebug("do silly TT filename thing"); |
857 | // if ( doc && doc->name().isEmpty() ) { | 864 | // if ( doc && doc->name().isEmpty() ) { |
858 | QString pt = rt.simplifyWhiteSpace(); | 865 | QString pt = rt.simplifyWhiteSpace(); |
859 | int i = pt.find( ' ' ); | 866 | int i = pt.find( ' ' ); |
860 | QString docname = pt; | 867 | QString docname = pt; |
861 | if ( i > 0 ) | 868 | if ( i > 0 ) |
862 | docname = pt.left( i ); | 869 | docname = pt.left( i ); |
863 | // remove "." at the beginning | 870 | // remove "." at the beginning |
864 | while( docname.startsWith( "." ) ) | 871 | while( docname.startsWith( "." ) ) |
865 | docname = docname.mid( 1 ); | 872 | docname = docname.mid( 1 ); |
866 | docname.replace( QRegExp("/"), "_" ); | 873 | docname.replace( QRegExp("/"), "_" ); |
867 | // cut the length. filenames longer than that | 874 | // cut the length. filenames longer than that |
868 | //don't make sense and something goes wrong when they get too long. | 875 | //don't make sense and something goes wrong when they get too long. |
869 | if ( docname.length() > 40 ) | 876 | if ( docname.length() > 40 ) |
870 | docname = docname.left(40); | 877 | docname = docname.left(40); |
871 | if ( docname.isEmpty() ) | 878 | if ( docname.isEmpty() ) |
872 | docname = tr("Unnamed"); | 879 | docname = tr("Unnamed"); |
873 | if(doc) doc->setName(docname); | 880 | if(doc) doc->setName(docname); |
874 | currentFileName=docname; | 881 | currentFileName=docname; |
875 | // } | 882 | // } |
876 | // else | 883 | // else |
877 | // qDebug("hmmmmmm"); | 884 | // qDebug("hmmmmmm"); |
878 | } | 885 | } |
879 | 886 | ||
880 | 887 | ||
881 | QMap<QString, QStringList> map; | 888 | QMap<QString, QStringList> map; |
882 | map.insert(tr("All"), QStringList() ); | 889 | map.insert(tr("All"), QStringList() ); |
883 | QStringList text; | 890 | QStringList text; |
884 | text << "text/*"; | 891 | text << "text/*"; |
885 | map.insert(tr("Text"), text ); | 892 | map.insert(tr("Text"), text ); |
886 | text << "*"; | 893 | text << "*"; |
887 | map.insert(tr("All"), text ); | 894 | map.insert(tr("All"), text ); |
888 | 895 | ||
889 | QFileInfo cuFi( currentFileName); | 896 | QFileInfo cuFi( currentFileName); |
890 | QString filee = cuFi.fileName(); | 897 | QString filee = cuFi.fileName(); |
891 | QString dire = cuFi.dirPath(); | 898 | QString dire = cuFi.dirPath(); |
892 | if(dire==".") | 899 | if(dire==".") |
893 | dire = QPEApplication::documentDir(); | 900 | dire = QPEApplication::documentDir(); |
894 | QString str = OFileDialog::getSaveFileName( 2, | 901 | QString str = OFileDialog::getSaveFileName( 2, |
895 | dire, | 902 | dire, |
896 | filee, map); | 903 | filee, map); |
897 | 904 | ||
898 | if(!str.isEmpty()) { | 905 | if(!str.isEmpty()) { |
899 | QString fileNm=str; | 906 | QString fileNm=str; |
900 | 907 | ||
901 | qDebug("saving filename "+fileNm); | 908 | qDebug("saving filename "+fileNm); |
902 | QFileInfo fi(fileNm); | 909 | QFileInfo fi(fileNm); |
903 | currentFileName=fi.fileName(); | 910 | currentFileName=fi.fileName(); |
904 | if(doc) | 911 | if(doc) |
905 | // QString file = doc->file(); | 912 | // QString file = doc->file(); |
906 | // doc->removeFiles(); | 913 | // doc->removeFiles(); |
907 | delete doc; | 914 | delete doc; |
908 | DocLnk nf; | 915 | DocLnk nf; |
909 | nf.setType("text/plain"); | 916 | nf.setType("text/plain"); |
910 | nf.setFile( fileNm); | 917 | nf.setFile( fileNm); |
911 | doc = new DocLnk(nf); | 918 | doc = new DocLnk(nf); |
912 | // editor->setText(rt); | 919 | // editor->setText(rt); |
913 | qDebug("Saving file as "+currentFileName); | 920 | qDebug("Saving file as "+currentFileName); |
914 | doc->setName( currentFileName); | 921 | doc->setName( currentFileName); |
915 | updateCaption( currentFileName); | 922 | updateCaption( currentFileName); |
916 | 923 | ||
917 | FileManager fm; | 924 | FileManager fm; |
918 | if ( !fm.saveFile( *doc, rt ) ) { | 925 | if ( !fm.saveFile( *doc, rt ) ) { |
919 | return false; | 926 | return false; |
920 | } | 927 | } |
921 | 928 | ||
922 | if( filePerms ) { | 929 | if( filePerms ) { |
923 | filePermissions *filePerm; | 930 | filePermissions *filePerm; |
924 | filePerm = new filePermissions(this, | 931 | filePerm = new filePermissions(this, |
925 | tr("Permissions"),true, | 932 | tr("Permissions"),true, |
926 | 0,(const QString &)fileNm); | 933 | 0,(const QString &)fileNm); |
927 | filePerm->showMaximized(); | 934 | filePerm->showMaximized(); |
928 | filePerm->exec(); | 935 | filePerm->exec(); |
929 | 936 | ||
930 | if( filePerm) | 937 | if( filePerm) |
931 | delete filePerm; | 938 | delete filePerm; |
932 | } | 939 | } |
933 | // } | 940 | // } |
934 | editor->setEdited( false); | 941 | editor->setEdited( false); |
935 | edited1 = false; | 942 | edited1 = false; |
936 | edited = false; | 943 | edited = false; |
937 | if(caption().left(1)=="*") | 944 | if(caption().left(1)=="*") |
938 | setCaption(caption().right(caption().length()-1)); | 945 | setCaption(caption().right(caption().length()-1)); |
939 | 946 | ||
940 | return true; | 947 | return true; |
941 | } | 948 | } |
942 | qDebug("returning false"); | 949 | qDebug("returning false"); |
943 | return false; | 950 | return false; |
944 | } //end saveAs | 951 | } //end saveAs |
945 | 952 | ||
946 | void TextEdit::clear() { | 953 | void TextEdit::clear() { |
947 | delete doc; | 954 | delete doc; |
948 | doc = 0; | 955 | doc = 0; |
949 | editor->clear(); | 956 | editor->clear(); |
950 | } | 957 | } |
951 | 958 | ||
952 | void TextEdit::updateCaption( const QString &name ) { | 959 | void TextEdit::updateCaption( const QString &name ) { |
953 | 960 | ||
954 | if ( name.isEmpty() ) | 961 | if ( name.isEmpty() ) |
955 | setCaption( tr("Text Editor") ); | 962 | setCaption( tr("Text Editor") ); |
956 | else { | 963 | else { |
957 | QString s = name; | 964 | QString s = name; |
958 | if ( s.isNull() ) | 965 | if ( s.isNull() ) |
959 | s = doc->name(); | 966 | s = doc->name(); |
960 | if ( s.isEmpty() ) { | 967 | if ( s.isEmpty() ) { |
961 | s = tr( "Unnamed" ); | 968 | s = tr( "Unnamed" ); |
962 | currentFileName=s; | 969 | currentFileName=s; |
963 | } | 970 | } |
964 | // if(s.left(1) == "/") | 971 | // if(s.left(1) == "/") |
965 | // s = s.right(s.length()-1); | 972 | // s = s.right(s.length()-1); |
966 | setCaption( s + " - " + tr("Text Editor") ); | 973 | setCaption( s + " - " + tr("Text Editor") ); |
967 | } | 974 | } |
968 | } | 975 | } |
969 | 976 | ||
970 | void TextEdit::setDocument(const QString& fileref) { | 977 | void TextEdit::setDocument(const QString& fileref) { |
971 | if(fileref != "Unnamed") { | 978 | if(fileref != "Unnamed") { |
972 | currentFileName=fileref; | 979 | currentFileName=fileref; |
973 | qDebug("setDocument"); | 980 | qDebug("setDocument"); |
974 | QFileInfo fi(currentFileName); | 981 | QFileInfo fi(currentFileName); |
975 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 982 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
976 | if( (fi.baseName().left(1)).isEmpty() ) { | 983 | if( (fi.baseName().left(1)).isEmpty() ) { |
977 | openDotFile(currentFileName); | 984 | openDotFile(currentFileName); |
978 | 985 | ||
979 | } else { | 986 | } else { |
980 | qDebug("setDoc open"); | 987 | qDebug("setDoc open"); |
981 | bFromDocView = true; | 988 | bFromDocView = true; |
982 | openFile(fileref); | 989 | openFile(fileref); |
983 | editor->setEdited(true); | 990 | editor->setEdited(true); |
984 | edited1=false; | 991 | edited1=false; |
985 | edited=true; | 992 | edited=true; |
986 | // fromSetDocument=false; | 993 | // fromSetDocument=false; |
987 | // doSearchBar(); | 994 | // doSearchBar(); |
988 | } | 995 | } |
989 | } | 996 | } |
990 | updateCaption( currentFileName); | 997 | updateCaption( currentFileName); |
991 | } | 998 | } |
992 | 999 | ||
993 | void TextEdit::changeFont() { | 1000 | void TextEdit::changeFont() { |
994 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1001 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
995 | d-> setCaption ( tr( "Choose font" )); | 1002 | d-> setCaption ( tr( "Choose font" )); |
996 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1003 | QBoxLayout *lay = new QVBoxLayout ( d ); |
997 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1004 | OFontSelector *ofs = new OFontSelector ( true, d ); |
998 | lay-> addWidget ( ofs ); | 1005 | lay-> addWidget ( ofs ); |
999 | ofs-> setSelectedFont ( editor-> font ( )); | 1006 | ofs-> setSelectedFont ( editor-> font ( )); |
1000 | 1007 | ||
1001 | d-> showMaximized ( ); | 1008 | d-> showMaximized ( ); |
1002 | if ( d-> exec ( ) == QDialog::Accepted ) | 1009 | if ( d-> exec ( ) == QDialog::Accepted ) |
1003 | editor-> setFont ( ofs-> selectedFont ( )); | 1010 | editor-> setFont ( ofs-> selectedFont ( )); |
1004 | delete d; | 1011 | delete d; |
1005 | 1012 | ||
1006 | } | 1013 | } |
1007 | 1014 | ||
1008 | void TextEdit::editDelete() { | 1015 | void TextEdit::editDelete() { |
1009 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1016 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1010 | tr("Do you really want<BR>to <B>delete</B> " | 1017 | tr("Do you really want<BR>to <B>delete</B> " |
1011 | "the current file\nfrom the disk?<BR>This is " | 1018 | "the current file\nfrom the disk?<BR>This is " |
1012 | "<B>irreversable!!</B>"), | 1019 | "<B>irreversable!!</B>"), |
1013 | tr("Yes"),tr("No"),0,0,1) ) { | 1020 | tr("Yes"),tr("No"),0,0,1) ) { |
1014 | case 0: | 1021 | case 0: |
1015 | if(doc) { | 1022 | if(doc) { |
1016 | doc->removeFiles(); | 1023 | doc->removeFiles(); |
1017 | clear(); | 1024 | clear(); |
1018 | setCaption( tr("Text Editor") ); | 1025 | setCaption( tr("Text Editor") ); |
1019 | } | 1026 | } |
1020 | break; | 1027 | break; |
1021 | case 1: | 1028 | case 1: |
1022 | // exit | 1029 | // exit |
1023 | break; | 1030 | break; |
1024 | }; | 1031 | }; |
1025 | } | 1032 | } |
1026 | 1033 | ||
1027 | void TextEdit::changeStartConfig( bool b ) { | 1034 | void TextEdit::changeStartConfig( bool b ) { |
1028 | startWithNew=b; | 1035 | startWithNew=b; |
1029 | Config cfg("TextEdit"); | 1036 | Config cfg("TextEdit"); |
1030 | cfg.setGroup("View"); | 1037 | cfg.setGroup("View"); |
1031 | cfg.writeEntry("startNew",b); | 1038 | cfg.writeEntry("startNew",b); |
1032 | update(); | 1039 | update(); |
1033 | } | 1040 | } |
1034 | 1041 | ||
1035 | void TextEdit::editorChanged() { | 1042 | void TextEdit::editorChanged() { |
1036 | // qDebug("editor changed"); | 1043 | // qDebug("editor changed"); |
1037 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1044 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1038 | setCaption( "*"+caption()); | 1045 | setCaption( "*"+caption()); |
1039 | edited1=true; | 1046 | edited1=true; |
1040 | } | 1047 | } |
1041 | edited=true; | 1048 | edited=true; |
1042 | } | 1049 | } |
1043 | 1050 | ||
1044 | void TextEdit::receive(const QCString&msg, const QByteArray &data) { | 1051 | void TextEdit::receive(const QCString&msg, const QByteArray &data) { |
1045 | qDebug("QCop "+msg); | 1052 | qDebug("QCop "+msg); |
1046 | if ( msg == "setDocument(QString)" ) { | 1053 | if ( msg == "setDocument(QString)" ) { |
1047 | qDebug("bugger all"); | 1054 | qDebug("bugger all"); |
1048 | 1055 | ||
1049 | } | 1056 | } |
1050 | 1057 | ||
1051 | } | 1058 | } |
1052 | 1059 | ||
1053 | void TextEdit::doAbout() { | 1060 | void TextEdit::doAbout() { |
1054 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1061 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1055 | "2000 Trolltech AS, and<BR>" | 1062 | "2000 Trolltech AS, and<BR>" |
1056 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1063 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1057 | "and is licensed under the GPL")); | 1064 | "and is licensed under the GPL")); |
1058 | } | 1065 | } |
1059 | 1066 | ||
1060 | void TextEdit::doPrompt(bool b) { | 1067 | void TextEdit::doPrompt(bool b) { |
1061 | promptExit=b; | 1068 | promptExit=b; |
1062 | Config cfg("TextEdit"); | 1069 | Config cfg("TextEdit"); |
1063 | cfg.setGroup ( "View" ); | 1070 | cfg.setGroup ( "View" ); |
1064 | cfg.writeEntry ( "PromptExit", b); | 1071 | cfg.writeEntry ( "PromptExit", b); |
1065 | } | 1072 | } |
1066 | 1073 | ||
1067 | void TextEdit::doDesktop(bool b) { | 1074 | void TextEdit::doDesktop(bool b) { |
1068 | openDesktop=b; | 1075 | openDesktop=b; |
1069 | Config cfg("TextEdit"); | 1076 | Config cfg("TextEdit"); |
1070 | cfg.setGroup ( "View" ); | 1077 | cfg.setGroup ( "View" ); |
1071 | cfg.writeEntry ( "OpenDesktop", b); | 1078 | cfg.writeEntry ( "OpenDesktop", b); |