author | llornkcor <llornkcor> | 2003-02-28 18:13:41 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-28 18:13:41 (UTC) |
commit | 64423f1852a13178f23365f2bba995ef2c355b3b (patch) (unidiff) | |
tree | 074d12cbd3b762fbcd0eac686c5b7fab3617453d | |
parent | d4db61dbd748040bed740e08a839e01b86af2c87 (diff) | |
download | opie-64423f1852a13178f23365f2bba995ef2c355b3b.zip opie-64423f1852a13178f23365f2bba995ef2c355b3b.tar.gz opie-64423f1852a13178f23365f2bba995ef2c355b3b.tar.bz2 |
no goto for 0 length texts
-rw-r--r-- | core/apps/textedit/textedit.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 797c61b..5edf102 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -985,219 +985,221 @@ void TextEdit::setDocument(const QString& fileref) { | |||
985 | QFileInfo fi(currentFileName); | 985 | QFileInfo fi(currentFileName); |
986 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 986 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
987 | if( (fi.baseName().left(1)).isEmpty() ) { | 987 | if( (fi.baseName().left(1)).isEmpty() ) { |
988 | openDotFile(currentFileName); | 988 | openDotFile(currentFileName); |
989 | 989 | ||
990 | } else { | 990 | } else { |
991 | qDebug("setDoc open"); | 991 | qDebug("setDoc open"); |
992 | bFromDocView = true; | 992 | bFromDocView = true; |
993 | openFile(fileref); | 993 | openFile(fileref); |
994 | editor->setEdited(true); | 994 | editor->setEdited(true); |
995 | edited1=false; | 995 | edited1=false; |
996 | edited=true; | 996 | edited=true; |
997 | // fromSetDocument=false; | 997 | // fromSetDocument=false; |
998 | // doSearchBar(); | 998 | // doSearchBar(); |
999 | } | 999 | } |
1000 | } | 1000 | } |
1001 | updateCaption( currentFileName); | 1001 | updateCaption( currentFileName); |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | void TextEdit::changeFont() { | 1004 | void TextEdit::changeFont() { |
1005 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1005 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1006 | d-> setCaption ( tr( "Choose font" )); | 1006 | d-> setCaption ( tr( "Choose font" )); |
1007 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1007 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1008 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1008 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1009 | lay-> addWidget ( ofs ); | 1009 | lay-> addWidget ( ofs ); |
1010 | ofs-> setSelectedFont ( editor-> font ( )); | 1010 | ofs-> setSelectedFont ( editor-> font ( )); |
1011 | 1011 | ||
1012 | d-> showMaximized ( ); | 1012 | d-> showMaximized ( ); |
1013 | if ( d-> exec ( ) == QDialog::Accepted ) | 1013 | if ( d-> exec ( ) == QDialog::Accepted ) |
1014 | editor-> setFont ( ofs-> selectedFont ( )); | 1014 | editor-> setFont ( ofs-> selectedFont ( )); |
1015 | delete d; | 1015 | delete d; |
1016 | 1016 | ||
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | void TextEdit::editDelete() { | 1019 | void TextEdit::editDelete() { |
1020 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1020 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1021 | tr("Do you really want<BR>to <B>delete</B> " | 1021 | tr("Do you really want<BR>to <B>delete</B> " |
1022 | "the current file\nfrom the disk?<BR>This is " | 1022 | "the current file\nfrom the disk?<BR>This is " |
1023 | "<B>irreversable!!</B>"), | 1023 | "<B>irreversable!!</B>"), |
1024 | tr("Yes"),tr("No"),0,0,1) ) { | 1024 | tr("Yes"),tr("No"),0,0,1) ) { |
1025 | case 0: | 1025 | case 0: |
1026 | if(doc) { | 1026 | if(doc) { |
1027 | doc->removeFiles(); | 1027 | doc->removeFiles(); |
1028 | clear(); | 1028 | clear(); |
1029 | setCaption( tr("Text Editor") ); | 1029 | setCaption( tr("Text Editor") ); |
1030 | } | 1030 | } |
1031 | break; | 1031 | break; |
1032 | case 1: | 1032 | case 1: |
1033 | // exit | 1033 | // exit |
1034 | break; | 1034 | break; |
1035 | }; | 1035 | }; |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | void TextEdit::changeStartConfig( bool b ) { | 1038 | void TextEdit::changeStartConfig( bool b ) { |
1039 | startWithNew=b; | 1039 | startWithNew=b; |
1040 | Config cfg("TextEdit"); | 1040 | Config cfg("TextEdit"); |
1041 | cfg.setGroup("View"); | 1041 | cfg.setGroup("View"); |
1042 | cfg.writeEntry("startNew",b); | 1042 | cfg.writeEntry("startNew",b); |
1043 | update(); | 1043 | update(); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | void TextEdit::editorChanged() { | 1046 | void TextEdit::editorChanged() { |
1047 | // qDebug("editor changed"); | 1047 | // qDebug("editor changed"); |
1048 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1048 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1049 | setCaption( "*"+caption()); | 1049 | setCaption( "*"+caption()); |
1050 | edited1=true; | 1050 | edited1=true; |
1051 | } | 1051 | } |
1052 | edited=true; | 1052 | edited=true; |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1055 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1056 | qDebug("QCop "+msg); | 1056 | qDebug("QCop "+msg); |
1057 | if ( msg == "setDocument(QString)" ) { | 1057 | if ( msg == "setDocument(QString)" ) { |
1058 | qDebug("bugger all"); | 1058 | qDebug("bugger all"); |
1059 | 1059 | ||
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | void TextEdit::doAbout() { | 1064 | void TextEdit::doAbout() { |
1065 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1065 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1066 | "2000 Trolltech AS, and<BR>" | 1066 | "2000 Trolltech AS, and<BR>" |
1067 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1067 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1068 | "and is licensed under the GPL")); | 1068 | "and is licensed under the GPL")); |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | void TextEdit::doPrompt(bool b) { | 1071 | void TextEdit::doPrompt(bool b) { |
1072 | promptExit=b; | 1072 | promptExit=b; |
1073 | Config cfg("TextEdit"); | 1073 | Config cfg("TextEdit"); |
1074 | cfg.setGroup ( "View" ); | 1074 | cfg.setGroup ( "View" ); |
1075 | cfg.writeEntry ( "PromptExit", b); | 1075 | cfg.writeEntry ( "PromptExit", b); |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void TextEdit::doDesktop(bool b) { | 1078 | void TextEdit::doDesktop(bool b) { |
1079 | openDesktop=b; | 1079 | openDesktop=b; |
1080 | Config cfg("TextEdit"); | 1080 | Config cfg("TextEdit"); |
1081 | cfg.setGroup ( "View" ); | 1081 | cfg.setGroup ( "View" ); |
1082 | cfg.writeEntry ( "OpenDesktop", b); | 1082 | cfg.writeEntry ( "OpenDesktop", b); |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | void TextEdit::doFilePerms(bool b) { | 1085 | void TextEdit::doFilePerms(bool b) { |
1086 | filePerms=b; | 1086 | filePerms=b; |
1087 | Config cfg("TextEdit"); | 1087 | Config cfg("TextEdit"); |
1088 | cfg.setGroup ( "View" ); | 1088 | cfg.setGroup ( "View" ); |
1089 | cfg.writeEntry ( "FilePermissions", b); | 1089 | cfg.writeEntry ( "FilePermissions", b); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | void TextEdit::editPasteTimeDate() { | 1092 | void TextEdit::editPasteTimeDate() { |
1093 | #ifndef QT_NO_CLIPBOARD | 1093 | #ifndef QT_NO_CLIPBOARD |
1094 | QClipboard *cb = QApplication::clipboard(); | 1094 | QClipboard *cb = QApplication::clipboard(); |
1095 | QDateTime dt = QDateTime::currentDateTime(); | 1095 | QDateTime dt = QDateTime::currentDateTime(); |
1096 | cb->setText( dt.toString()); | 1096 | cb->setText( dt.toString()); |
1097 | editor->paste(); | 1097 | editor->paste(); |
1098 | #endif | 1098 | #endif |
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | int TextEdit::savePrompt() | 1101 | int TextEdit::savePrompt() |
1102 | { | 1102 | { |
1103 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1103 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1104 | (tr("Textedit detected\n" | 1104 | (tr("Textedit detected\n" |
1105 | "you have unsaved changes\n" | 1105 | "you have unsaved changes\n" |
1106 | "Go ahead and save?\n")), | 1106 | "Go ahead and save?\n")), |
1107 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1107 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1108 | { | 1108 | { |
1109 | case 0: | 1109 | case 0: |
1110 | { | 1110 | { |
1111 | return 1; | 1111 | return 1; |
1112 | } | 1112 | } |
1113 | break; | 1113 | break; |
1114 | 1114 | ||
1115 | case 1: | 1115 | case 1: |
1116 | { | 1116 | { |
1117 | return 2; | 1117 | return 2; |
1118 | } | 1118 | } |
1119 | break; | 1119 | break; |
1120 | 1120 | ||
1121 | case 2: | 1121 | case 2: |
1122 | { | 1122 | { |
1123 | return -1; | 1123 | return -1; |
1124 | } | 1124 | } |
1125 | break; | 1125 | break; |
1126 | }; | 1126 | }; |
1127 | 1127 | ||
1128 | return 0; | 1128 | return 0; |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | void TextEdit::timerCrank() | 1131 | void TextEdit::timerCrank() |
1132 | { | 1132 | { |
1133 | if(featureAutoSave && edited1) | 1133 | if(featureAutoSave && edited1) |
1134 | { | 1134 | { |
1135 | if(currentFileName.isEmpty()) | 1135 | if(currentFileName.isEmpty()) |
1136 | { | 1136 | { |
1137 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | 1137 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; |
1138 | saveAs(); | 1138 | saveAs(); |
1139 | } | 1139 | } |
1140 | else | 1140 | else |
1141 | { | 1141 | { |
1142 | // qDebug("autosave"); | 1142 | // qDebug("autosave"); |
1143 | save(); | 1143 | save(); |
1144 | } | 1144 | } |
1145 | setTimer(); | 1145 | setTimer(); |
1146 | } | 1146 | } |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | void TextEdit::doTimer(bool b) | 1149 | void TextEdit::doTimer(bool b) |
1150 | { | 1150 | { |
1151 | Config cfg("TextEdit"); | 1151 | Config cfg("TextEdit"); |
1152 | cfg.setGroup ( "View" ); | 1152 | cfg.setGroup ( "View" ); |
1153 | cfg.writeEntry ( "autosave", b); | 1153 | cfg.writeEntry ( "autosave", b); |
1154 | featureAutoSave = b; | 1154 | featureAutoSave = b; |
1155 | nAutoSave->setOn(b); | 1155 | nAutoSave->setOn(b); |
1156 | if(b) | 1156 | if(b) |
1157 | { | 1157 | { |
1158 | // qDebug("doTimer true"); | 1158 | // qDebug("doTimer true"); |
1159 | setTimer(); | 1159 | setTimer(); |
1160 | } | 1160 | } |
1161 | // else | 1161 | // else |
1162 | // qDebug("doTimer false"); | 1162 | // qDebug("doTimer false"); |
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | void TextEdit::setTimer() | 1165 | void TextEdit::setTimer() |
1166 | { | 1166 | { |
1167 | if(featureAutoSave) | 1167 | if(featureAutoSave) |
1168 | { | 1168 | { |
1169 | // qDebug("setting autosave"); | 1169 | // qDebug("setting autosave"); |
1170 | QTimer *timer = new QTimer(this ); | 1170 | QTimer *timer = new QTimer(this ); |
1171 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | 1171 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); |
1172 | timer->start( 300000, true); //5 minutes | 1172 | timer->start( 300000, true); //5 minutes |
1173 | } | 1173 | } |
1174 | } | 1174 | } |
1175 | 1175 | ||
1176 | void TextEdit::gotoLine() { | 1176 | void TextEdit::gotoLine() { |
1177 | 1177 | if( editor->length() < 1) | |
1178 | return; | ||
1178 | QWidget *d = QApplication::desktop(); | 1179 | QWidget *d = QApplication::desktop(); |
1179 | gotoEdit = new QLineEdit( 0, "Goto line"); | 1180 | gotoEdit = new QLineEdit( 0, "Goto line"); |
1180 | 1181 | ||
1181 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); | 1182 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); |
1182 | gotoEdit->setFrame(true); | 1183 | gotoEdit->setFrame(true); |
1183 | gotoEdit->show(); | 1184 | gotoEdit->show(); |
1184 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); | 1185 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); |
1185 | } | 1186 | } |
1186 | 1187 | ||
1187 | void TextEdit::doGoto() { | 1188 | void TextEdit::doGoto() { |
1188 | QString number = gotoEdit->text(); | 1189 | QString number = gotoEdit->text(); |
1189 | gotoEdit->hide(); | 1190 | gotoEdit->hide(); |
1191 | |||
1190 | if(gotoEdit) { | 1192 | if(gotoEdit) { |
1191 | delete gotoEdit; | 1193 | delete gotoEdit; |
1192 | gotoEdit = 0; | 1194 | gotoEdit = 0; |
1193 | } | 1195 | } |
1194 | 1196 | ||
1195 | bool ok; | 1197 | bool ok; |
1196 | int lineNumber = number.toInt(&ok, 10); | 1198 | int lineNumber = number.toInt(&ok, 10); |
1197 | if(editor->numLines() < lineNumber) | 1199 | if( editor->numLines() < lineNumber) |
1198 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); | 1200 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); |
1199 | else | 1201 | else |
1200 | { | 1202 | { |
1201 | editor->setCursorPosition(lineNumber, 0, false); | 1203 | editor->setCursorPosition(lineNumber, 0, false); |
1202 | } | 1204 | } |
1203 | } | 1205 | } |