Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 291 |
1 files changed, 250 insertions, 41 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 867625e..14bc496 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -14,47 +14,155 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | ||
20 | 21 | ||
21 | #include "textedit.h" | 22 | #include "textedit.h" |
23 | #include "fileBrowser.h" | ||
24 | #include "fileSaver.h" | ||
22 | 25 | ||
26 | #include "fontDialog.h" | ||
27 | |||
28 | #include <qpe/fontdatabase.h> | ||
23 | #include <qpe/global.h> | 29 | #include <qpe/global.h> |
24 | #include <qpe/fileselector.h> | 30 | #include <qpe/fileselector.h> |
25 | #include <qpe/applnk.h> | 31 | #include <qpe/applnk.h> |
26 | #include <qpe/resource.h> | 32 | #include <qpe/resource.h> |
27 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
28 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
29 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
30 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
31 | //#include <qpe/finddialog.h> | 37 | //#include <qpe/finddialog.h> |
32 | 38 | ||
39 | #include <qstringlist.h> | ||
33 | #include <qaction.h> | 40 | #include <qaction.h> |
34 | #include <qcolordialog.h> | 41 | #include <qcolordialog.h> |
35 | #include <qfileinfo.h> | 42 | #include <qfileinfo.h> |
36 | #include <qlineedit.h> | 43 | #include <qlineedit.h> |
37 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
38 | #include <qobjectlist.h> | 45 | #include <qobjectlist.h> |
39 | #include <qpopupmenu.h> | 46 | #include <qpopupmenu.h> |
40 | #include <qspinbox.h> | 47 | #include <qspinbox.h> |
41 | #include <qtoolbutton.h> | 48 | #include <qtoolbutton.h> |
42 | #include <qwidgetstack.h> | 49 | #include <qwidgetstack.h> |
43 | 50 | ||
44 | #include <stdlib.h> //getenv | 51 | #include <stdlib.h> //getenv |
52 | /* XPM */ | ||
53 | static char * filesave_xpm[] = { | ||
54 | "16 16 78 1", | ||
55 | " c None", | ||
56 | ". c #343434", | ||
57 | "+ c #A0A0A0", | ||
58 | "@ c #565656", | ||
59 | "# c #9E9E9E", | ||
60 | "$ c #525252", | ||
61 | "% c #929292", | ||
62 | "& c #676767", | ||
63 | "* c #848484", | ||
64 | "= c #666666", | ||
65 | "- c #D8D8D8", | ||
66 | "; c #FFFFFF", | ||
67 | "> c #DBDBDB", | ||
68 | ", c #636363", | ||
69 | "' c #989898", | ||
70 | ") c #2D2D2D", | ||
71 | "! c #909090", | ||
72 | "~ c #AEAEAE", | ||
73 | "{ c #EAEAEA", | ||
74 | "] c #575757", | ||
75 | "^ c #585858", | ||
76 | "/ c #8A8A8A", | ||
77 | "( c #828282", | ||
78 | "_ c #6F6F6F", | ||
79 | ": c #C9C9C9", | ||
80 | "< c #050505", | ||
81 | "[ c #292929", | ||
82 | "} c #777777", | ||
83 | "| c #616161", | ||
84 | "1 c #3A3A3A", | ||
85 | "2 c #BEBEBE", | ||
86 | "3 c #2C2C2C", | ||
87 | "4 c #7C7C7C", | ||
88 | "5 c #F6F6F6", | ||
89 | "6 c #FCFCFC", | ||
90 | "7 c #6B6B6B", | ||
91 | "8 c #959595", | ||
92 | "9 c #4F4F4F", | ||
93 | "0 c #808080", | ||
94 | "a c #767676", | ||
95 | "b c #818181", | ||
96 | "c c #B8B8B8", | ||
97 | "d c #FBFBFB", | ||
98 | "e c #F9F9F9", | ||
99 | "f c #CCCCCC", | ||
100 | "g c #030303", | ||
101 | "h c #737373", | ||
102 | "i c #7A7A7A", | ||
103 | "j c #7E7E7E", | ||
104 | "k c #6A6A6A", | ||
105 | "l c #FAFAFA", | ||
106 | "m c #505050", | ||
107 | "n c #9D9D9D", | ||
108 | "o c #333333", | ||
109 | "p c #7B7B7B", | ||
110 | "q c #787878", | ||
111 | "r c #696969", | ||
112 | "s c #494949", | ||
113 | "t c #555555", | ||
114 | "u c #949494", | ||
115 | "v c #E6E6E6", | ||
116 | "w c #424242", | ||
117 | "x c #515151", | ||
118 | "y c #535353", | ||
119 | "z c #3E3E3E", | ||
120 | "A c #D4D4D4", | ||
121 | "B c #0C0C0C", | ||
122 | "C c #353535", | ||
123 | "D c #474747", | ||
124 | "E c #ECECEC", | ||
125 | "F c #919191", | ||
126 | "G c #7D7D7D", | ||
127 | "H c #000000", | ||
128 | "I c #404040", | ||
129 | "J c #858585", | ||
130 | "K c #323232", | ||
131 | "L c #D0D0D0", | ||
132 | "M c #1C1C1C", | ||
133 | " ...+ ", | ||
134 | " @#$%&..+ ", | ||
135 | " .*=-;;>,..+ ", | ||
136 | " ')!~;;;;;;{]..", | ||
137 | " ^/(-;;;;;;;_:<", | ||
138 | " [}|;;;;;;;{12$", | ||
139 | " #34-55;;;;678$+", | ||
140 | " 90ab=c;dd;e1fg ", | ||
141 | " [ahij((kbl0mn$ ", | ||
142 | " op^q^^7r&]s/$+ ", | ||
143 | "@btu;vbwxy]zAB ", | ||
144 | "CzDEvEv;;DssF$ ", | ||
145 | "G.H{E{E{IxsJ$+ ", | ||
146 | " +...vEKxzLM ", | ||
147 | " +...z]n$ ", | ||
148 | " +... "}; | ||
45 | 149 | ||
46 | 150 | ||
47 | #if QT_VERSION < 300 | 151 | #if QT_VERSION < 300 |
48 | 152 | ||
49 | class QpeEditor : public QMultiLineEdit | 153 | class QpeEditor : public QMultiLineEdit |
50 | { | 154 | { |
51 | // Q_OBJECT | 155 | // Q_OBJECT |
52 | public: | 156 | public: |
53 | QpeEditor( QWidget *parent, const char * name = 0 ) | 157 | QpeEditor( QWidget *parent, const char * name = 0 ) |
54 | : QMultiLineEdit( parent, name ) {} | 158 | : QMultiLineEdit( parent, name ) |
159 | { | ||
160 | clearTableFlags(); | ||
161 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | ||
162 | } | ||
55 | 163 | ||
56 | //public slots: | 164 | //public slots: |
57 | void find( const QString &txt, bool caseSensitive, | 165 | void find( const QString &txt, bool caseSensitive, |
58 | bool backwards ); | 166 | bool backwards ); |
59 | /* | 167 | /* |
60 | signals: | 168 | signals: |
@@ -126,14 +234,12 @@ static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | |||
126 | 234 | ||
127 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 235 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
128 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 236 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) |
129 | { | 237 | { |
130 | doc = 0; | 238 | doc = 0; |
131 | 239 | ||
132 | QString lang = getenv( "LANG" ); | ||
133 | |||
134 | setToolBarsMovable( FALSE ); | 240 | setToolBarsMovable( FALSE ); |
135 | 241 | ||
136 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 242 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
137 | 243 | ||
138 | QPEToolBar *bar = new QPEToolBar( this ); | 244 | QPEToolBar *bar = new QPEToolBar( this ); |
139 | bar->setHorizontalStretchable( TRUE ); | 245 | bar->setHorizontalStretchable( TRUE ); |
@@ -151,15 +257,27 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
151 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 257 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
152 | a->addTo( bar ); | 258 | a->addTo( bar ); |
153 | a->addTo( file ); | 259 | a->addTo( file ); |
154 | 260 | ||
155 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 261 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
156 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 262 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
263 | // a->addTo( bar ); | ||
264 | a->addTo( file ); | ||
265 | |||
266 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | ||
267 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); | ||
157 | a->addTo( bar ); | 268 | a->addTo( bar ); |
158 | a->addTo( file ); | 269 | a->addTo( file ); |
159 | 270 | ||
271 | // | ||
272 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | ||
273 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | ||
274 | // a->addTo( bar ); | ||
275 | file->insertSeparator(); | ||
276 | a->addTo( file ); | ||
277 | |||
160 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 278 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
161 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 279 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
162 | a->addTo( editBar ); | 280 | a->addTo( editBar ); |
163 | a->addTo( edit ); | 281 | a->addTo( edit ); |
164 | 282 | ||
165 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 283 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
@@ -177,20 +295,19 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
177 | edit->insertSeparator(); | 295 | edit->insertSeparator(); |
178 | a->addTo( bar ); | 296 | a->addTo( bar ); |
179 | a->addTo( edit ); | 297 | a->addTo( edit ); |
180 | 298 | ||
181 | int defsize; | 299 | int defsize; |
182 | bool defb, defi, wrap; | 300 | bool defb, defi, wrap; |
183 | { | 301 | |
184 | Config cfg("TextEdit"); | 302 | Config cfg("TextEdit"); |
185 | cfg.setGroup("View"); | 303 | cfg.setGroup("View"); |
186 | defsize = cfg.readNumEntry("FontSize",10); | 304 | defsize = cfg.readNumEntry("FontSize",10); |
187 | defb = cfg.readBoolEntry("Bold",FALSE); | 305 | defb = cfg.readBoolEntry("Bold",FALSE); |
188 | defi = cfg.readBoolEntry("Italic",FALSE); | 306 | defi = cfg.readBoolEntry("Italic",FALSE); |
189 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 307 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
190 | } | ||
191 | 308 | ||
192 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 309 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
193 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 310 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
194 | zin->addTo( font ); | 311 | zin->addTo( font ); |
195 | 312 | ||
196 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 313 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
@@ -218,12 +335,15 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
218 | 335 | ||
219 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 336 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
220 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 337 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
221 | wa->setToggleAction(TRUE); | 338 | wa->setToggleAction(TRUE); |
222 | wa->addTo( font ); | 339 | wa->addTo( font ); |
223 | 340 | ||
341 | font->insertSeparator(); | ||
342 | font->insertItem("Font", this, SLOT(changeFont()) ); | ||
343 | |||
224 | mb->insertItem( tr( "File" ), file ); | 344 | mb->insertItem( tr( "File" ), file ); |
225 | mb->insertItem( tr( "Edit" ), edit ); | 345 | mb->insertItem( tr( "Edit" ), edit ); |
226 | mb->insertItem( tr( "View" ), font ); | 346 | mb->insertItem( tr( "View" ), font ); |
227 | 347 | ||
228 | searchBar = new QPEToolBar(this); | 348 | searchBar = new QPEToolBar(this); |
229 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 349 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
@@ -232,12 +352,13 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
232 | 352 | ||
233 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 353 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
234 | searchBar->setStretchableWidget( searchEdit ); | 354 | searchBar->setStretchableWidget( searchEdit ); |
235 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 355 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
236 | this, SLOT( search() ) ); | 356 | this, SLOT( search() ) ); |
237 | 357 | ||
358 | |||
238 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 359 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
239 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 360 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
240 | a->addTo( searchBar ); | 361 | a->addTo( searchBar ); |
241 | a->addTo( edit ); | 362 | a->addTo( edit ); |
242 | 363 | ||
243 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 364 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
@@ -248,27 +369,50 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
248 | 369 | ||
249 | editorStack = new QWidgetStack( this ); | 370 | editorStack = new QWidgetStack( this ); |
250 | setCentralWidget( editorStack ); | 371 | setCentralWidget( editorStack ); |
251 | 372 | ||
252 | searchVisible = FALSE; | 373 | searchVisible = FALSE; |
253 | 374 | ||
254 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , | 375 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy |
255 | TRUE, FALSE ); | ||
256 | fileSelector->setCategoriesVisible(TRUE); | ||
257 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 376 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
258 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 377 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
259 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 378 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); |
260 | fileOpen(); | 379 | // fileOpen(); |
261 | 380 | ||
262 | editor = new QpeEditor( editorStack ); | 381 | editor = new QpeEditor( editorStack ); |
382 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
263 | editorStack->addWidget( editor, get_unique_id() ); | 383 | editorStack->addWidget( editor, get_unique_id() ); |
264 | 384 | ||
265 | resize( 200, 300 ); | 385 | resize( 200, 300 ); |
266 | 386 | ||
267 | setFontSize(defsize,TRUE); | 387 | // setFontSize(defsize,TRUE); |
388 | FontDatabase fdb; | ||
389 | QFont defaultFont=editor->font(); | ||
390 | QFontInfo fontInfo(defaultFont); | ||
391 | |||
392 | cfg.setGroup("Font"); | ||
393 | QString family = cfg.readEntry("Family", fontInfo.family()); | ||
394 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | ||
395 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | ||
396 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | ||
397 | |||
398 | defaultFont = fdb.font(family,style,i_size,charSet); | ||
399 | editor->setFont( defaultFont); | ||
400 | |||
268 | wa->setOn(wrap); | 401 | wa->setOn(wrap); |
402 | updateCaption(); | ||
403 | if( qApp->argc() > 1 ) { | ||
404 | for (int i=1;i< qApp->argc();i++) { | ||
405 | QString tmp; | ||
406 | currentFileName = tmp.sprintf("%s",qApp->argv()[i]); | ||
407 | qDebug(currentFileName); | ||
408 | setDocument( currentFileName ); | ||
409 | } | ||
410 | } | ||
411 | else | ||
412 | fileNew(); | ||
269 | } | 413 | } |
270 | 414 | ||
271 | TextEdit::~TextEdit() | 415 | TextEdit::~TextEdit() |
272 | { | 416 | { |
273 | save(); | 417 | save(); |
274 | 418 | ||
@@ -331,58 +475,82 @@ void TextEdit::setItalic(bool y) | |||
331 | f.setItalic(y); | 475 | f.setItalic(y); |
332 | editor->setFont(f); | 476 | editor->setFont(f); |
333 | } | 477 | } |
334 | 478 | ||
335 | void TextEdit::setWordWrap(bool y) | 479 | void TextEdit::setWordWrap(bool y) |
336 | { | 480 | { |
481 | bool state = editor->edited(); | ||
337 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 482 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
483 | editor->setEdited( state ); | ||
338 | } | 484 | } |
339 | 485 | ||
340 | void TextEdit::fileNew() | 486 | void TextEdit::fileNew() |
341 | { | 487 | { |
342 | save(); | 488 | save(); |
343 | newFile(DocLnk()); | 489 | newFile(DocLnk()); |
344 | } | 490 | } |
345 | 491 | ||
346 | void TextEdit::fileOpen() | 492 | void TextEdit::fileOpen() |
347 | { | 493 | { |
348 | if ( !save() ) { | 494 | // if ( !save() ) { |
349 | if ( QMessageBox::critical( this, tr( "Out of space" ), | 495 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
350 | tr( "Text Editor was unable to\n" | 496 | // tr( "Text Editor was unable to\n" |
351 | "save your changes.\n" | 497 | // "save your changes.\n" |
352 | "Free some space and try again.\n" | 498 | // "Free some space and try again.\n" |
353 | "\nContinue anyway?" ), | 499 | // "\nContinue anyway?" ), |
354 | QMessageBox::Yes|QMessageBox::Escape, | 500 | // QMessageBox::Yes|QMessageBox::Escape, |
355 | QMessageBox::No|QMessageBox::Default ) | 501 | // QMessageBox::No|QMessageBox::Default ) |
356 | != QMessageBox::Yes ) | 502 | // != QMessageBox::Yes ) |
357 | return; | 503 | // return; |
358 | else { | 504 | // else { |
359 | delete doc; | 505 | // delete doc; |
360 | doc = 0; | 506 | // doc = 0; |
361 | } | 507 | // } |
362 | } | 508 | // } |
363 | menu->hide(); | 509 | menu->hide(); |
364 | editBar->hide(); | 510 | editBar->hide(); |
365 | searchBar->hide(); | 511 | searchBar->hide(); |
366 | clearWState (WState_Reserved1 ); | 512 | clearWState (WState_Reserved1 ); |
367 | editorStack->raiseWidget( fileSelector ); | 513 | editorStack->raiseWidget( fileSelector ); |
368 | fileSelector->reread(); | 514 | fileSelector->reread(); |
369 | updateCaption(); | 515 | updateCaption(); |
370 | } | 516 | } |
371 | 517 | ||
518 | void TextEdit::newFileOpen() | ||
519 | { | ||
520 | fileBrowser *browseForFiles; | ||
521 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); | ||
522 | browseForFiles->exec(); | ||
523 | QString selFile= browseForFiles->selectedFileName; | ||
524 | QStringList fileList=browseForFiles->fileList; | ||
525 | qDebug(selFile); | ||
526 | QStringList::ConstIterator f; | ||
527 | QString fileTemp; | ||
528 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | ||
529 | fileTemp = *f; | ||
530 | fileTemp.right( fileTemp.length()-5); | ||
531 | QString fileName = fileTemp; | ||
532 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | ||
533 | currentFileName = fileName; | ||
534 | qDebug("please open "+currentFileName); | ||
535 | openFile(fileName ); | ||
536 | } | ||
537 | } | ||
538 | delete browseForFiles; | ||
539 | |||
540 | } | ||
372 | 541 | ||
373 | #if 0 | 542 | #if 0 |
374 | void TextEdit::slotFind() | 543 | void TextEdit::slotFind() |
375 | { | 544 | { |
376 | FindDialog frmFind( "Text Editor", this ); | 545 | FindDialog frmFind( "Text Editor", this ); |
377 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 546 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
378 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 547 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
379 | 548 | ||
380 | //case sensitive, backwards, [category] | 549 | //case sensitive, backwards, [category] |
381 | 550 | ||
382 | |||
383 | connect( editor, SIGNAL(notFound()), | 551 | connect( editor, SIGNAL(notFound()), |
384 | &frmFind, SLOT(slotNotFound()) ); | 552 | &frmFind, SLOT(slotNotFound()) ); |
385 | connect( editor, SIGNAL(searchWrapped()), | 553 | connect( editor, SIGNAL(searchWrapped()), |
386 | &frmFind, SLOT(slotWrapAround()) ); | 554 | &frmFind, SLOT(slotWrapAround()) ); |
387 | 555 | ||
388 | frmFind.exec(); | 556 | frmFind.exec(); |
@@ -469,54 +637,61 @@ void TextEdit::openFile( const QString &f ) | |||
469 | name = name.mid( sep+1 ); | 637 | name = name.mid( sep+1 ); |
470 | updateCaption( name ); | 638 | updateCaption( name ); |
471 | } | 639 | } |
472 | 640 | ||
473 | void TextEdit::openFile( const DocLnk &f ) | 641 | void TextEdit::openFile( const DocLnk &f ) |
474 | { | 642 | { |
475 | clear(); | 643 | // clear(); |
476 | FileManager fm; | 644 | FileManager fm; |
477 | QString txt; | 645 | QString txt; |
478 | if ( !fm.loadFile( f, txt ) ) { | 646 | if ( !fm.loadFile( f, txt ) ) { |
479 | // ####### could be a new file | 647 | // ####### could be a new file |
480 | //qDebug( "Cannot open file" ); | 648 | qDebug( "Cannot open file" ); |
649 | |||
481 | //return; | 650 | //return; |
482 | } | 651 | } |
652 | |||
483 | fileNew(); | 653 | fileNew(); |
484 | if ( doc ) | 654 | if ( doc ) |
485 | delete doc; | 655 | delete doc; |
486 | doc = new DocLnk(f); | 656 | doc = new DocLnk(f); |
487 | editor->setText(txt); | 657 | editor->setText(txt); |
488 | editor->setEdited(FALSE); | 658 | editor->setEdited(FALSE); |
489 | updateCaption(); | 659 | updateCaption(); |
490 | } | 660 | } |
491 | 661 | ||
492 | void TextEdit::showEditTools() | 662 | void TextEdit::showEditTools() |
493 | { | 663 | { |
494 | if ( !doc ) | 664 | // if ( !doc ) |
495 | close(); | 665 | // close(); |
666 | // clear(); | ||
496 | fileSelector->hide(); | 667 | fileSelector->hide(); |
497 | menu->show(); | 668 | menu->show(); |
498 | editBar->show(); | 669 | editBar->show(); |
499 | if ( searchVisible ) | 670 | if ( searchVisible ) |
500 | searchBar->show(); | 671 | searchBar->show(); |
501 | updateCaption(); | 672 | updateCaption(); |
673 | editorStack->raiseWidget( editor ); | ||
674 | setWState (WState_Reserved1 ); | ||
502 | } | 675 | } |
503 | 676 | ||
504 | bool TextEdit::save() | 677 | bool TextEdit::save() |
505 | { | 678 | { |
506 | // case of nothing to save... | 679 | // case of nothing to save... |
507 | if ( !doc ) | 680 | if ( !doc || !bFromDocView) |
508 | return true; | 681 | return true; |
509 | if ( !editor->edited() ) { | 682 | if ( !editor->edited() ) { |
510 | delete doc; | 683 | delete doc; |
511 | doc = 0; | 684 | doc = 0; |
512 | return true; | 685 | return true; |
513 | } | 686 | } |
514 | 687 | ||
515 | QString rt = editor->text(); | 688 | QString rt = editor->text(); |
516 | 689 | ||
690 | if(currentFileName.isEmpty() || currentFileName == "Unnamed") { | ||
691 | |||
517 | if ( doc->name().isEmpty() ) { | 692 | if ( doc->name().isEmpty() ) { |
518 | QString pt = rt.simplifyWhiteSpace(); | 693 | QString pt = rt.simplifyWhiteSpace(); |
519 | int i = pt.find( ' ' ); | 694 | int i = pt.find( ' ' ); |
520 | QString docname = pt; | 695 | QString docname = pt; |
521 | if ( i > 0 ) | 696 | if ( i > 0 ) |
522 | docname = pt.left( i ); | 697 | docname = pt.left( i ); |
@@ -527,20 +702,24 @@ bool TextEdit::save() | |||
527 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 702 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
528 | if ( docname.length() > 40 ) | 703 | if ( docname.length() > 40 ) |
529 | docname = docname.left(40); | 704 | docname = docname.left(40); |
530 | if ( docname.isEmpty() ) | 705 | if ( docname.isEmpty() ) |
531 | docname = "Empty Text"; | 706 | docname = "Empty Text"; |
532 | doc->setName(docname); | 707 | doc->setName(docname); |
533 | 708 | currentFileName=docname; | |
534 | // append .txt to the file name | ||
535 | if ( doc->file().find(".txt") == -1 ) { | ||
536 | QString file = doc->file() + ".txt"; | ||
537 | doc->setFile( file ); | ||
538 | } | 709 | } |
539 | } | 710 | } |
540 | 711 | ||
712 | fileSaver *fileSaveDlg; | ||
713 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); | ||
714 | fileSaveDlg->exec(); | ||
715 | QString fileNm=fileSaveDlg->selectedFileName; | ||
716 | qDebug("save filename "+fileNm); | ||
717 | doc->setName(fileNm); | ||
718 | updateCaption(); | ||
719 | delete fileSaveDlg; | ||
541 | 720 | ||
542 | FileManager fm; | 721 | FileManager fm; |
543 | if ( !fm.saveFile( *doc, rt ) ) { | 722 | if ( !fm.saveFile( *doc, rt ) ) { |
544 | return false; | 723 | return false; |
545 | } | 724 | } |
546 | delete doc; | 725 | delete doc; |
@@ -561,34 +740,64 @@ void TextEdit::updateCaption( const QString &name ) | |||
561 | if ( !doc ) | 740 | if ( !doc ) |
562 | setCaption( tr("Text Editor") ); | 741 | setCaption( tr("Text Editor") ); |
563 | else { | 742 | else { |
564 | QString s = name; | 743 | QString s = name; |
565 | if ( s.isNull() ) | 744 | if ( s.isNull() ) |
566 | s = doc->name(); | 745 | s = doc->name(); |
567 | if ( s.isEmpty() ) | 746 | if ( s.isEmpty() ) { |
568 | s = tr( "Unnamed" ); | 747 | s = tr( "Unnamed" ); |
748 | currentFileName=s; | ||
749 | } | ||
569 | setCaption( s + " - " + tr("Text Editor") ); | 750 | setCaption( s + " - " + tr("Text Editor") ); |
570 | } | 751 | } |
571 | } | 752 | } |
572 | 753 | ||
573 | void TextEdit::setDocument(const QString& fileref) | 754 | void TextEdit::setDocument(const QString& fileref) |
574 | { | 755 | { |
575 | bFromDocView = TRUE; | 756 | bFromDocView = TRUE; |
576 | openFile(DocLnk(fileref)); | 757 | openFile(DocLnk(fileref)); |
577 | showEditTools(); | 758 | // showEditTools(); |
578 | } | 759 | } |
579 | 760 | ||
580 | void TextEdit::closeEvent( QCloseEvent *e ) | 761 | void TextEdit::closeEvent( QCloseEvent *e ) |
581 | { | 762 | { |
582 | if ( editorStack->visibleWidget() == editor && !bFromDocView ) { | 763 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
583 | e->ignore(); | 764 | e->ignore(); |
584 | fileRevert(); | 765 | repaint(); |
766 | // fileRevert(); | ||
767 | |||
585 | } else { | 768 | } else { |
586 | bFromDocView = FALSE; | 769 | bFromDocView = FALSE; |
587 | e->accept(); | 770 | e->accept(); |
588 | } | 771 | } |
589 | } | 772 | } |
590 | 773 | ||
591 | void TextEdit::accept() | 774 | void TextEdit::accept() |
592 | { | 775 | { |
593 | fileOpen(); | 776 | close(); |
777 | // fileOpen(); //godamn thats obnoxious! lemme out!!! | ||
778 | } | ||
779 | |||
780 | void TextEdit::changeFont() { | ||
781 | FontDatabase fdb; | ||
782 | QFont defaultFont=editor->font(); | ||
783 | QFontInfo fontInfo(defaultFont); | ||
784 | Config cfg("TextEdit"); | ||
785 | cfg.setGroup("Font"); | ||
786 | QString family = cfg.readEntry("Family", fontInfo.family()); | ||
787 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | ||
788 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | ||
789 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | ||
790 | |||
791 | defaultFont = fdb.font(family,style,i_size,charSet); | ||
792 | |||
793 | FontDialog *fontDlg; | ||
794 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | ||
795 | |||
796 | fontDlg->exec(); | ||
797 | |||
798 | QFont myFont=fontDlg->selectedFont; | ||
799 | editor->setFont( myFont); | ||
800 | delete fontDlg; | ||
801 | |||
594 | } | 802 | } |
803 | |||