summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-02-18 15:02:33 (UTC)
committer llornkcor <llornkcor>2002-02-18 15:02:33 (UTC)
commita6266fb220a61c4904e24ebf31eeefab34362e59 (patch) (side-by-side diff)
treeab1da9da25c4b5118935bc981fca62a8c72b6810
parent00f89d28e669140eb50f1f220c389f88fba1105c (diff)
downloadopie-a6266fb220a61c4904e24ebf31eeefab34362e59.zip
opie-a6266fb220a61c4904e24ebf31eeefab34362e59.tar.gz
opie-a6266fb220a61c4904e24ebf31eeefab34362e59.tar.bz2
added Save As (prompt user) and moved save (no prompt) functions there
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp23
-rw-r--r--core/apps/textedit/textedit.h2
2 files changed, 23 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 429c195..834971a 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -254,48 +254,52 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
editBar = bar;
QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
a->addTo( bar );
a->addTo( file );
a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
// a->addTo( bar );
a->addTo( file );
a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) );
a->addTo( bar );
a->addTo( file );
//
a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
// a->addTo( bar );
file->insertSeparator();
a->addTo( file );
+ a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
+ a->addTo( file );
+
a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
a->addTo( editBar );
a->addTo( edit );
a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
a->addTo( editBar );
a->addTo( edit );
a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
a->addTo( editBar );
a->addTo( edit );
a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
edit->insertSeparator();
a->addTo( bar );
a->addTo( edit );
int defsize;
bool defb, defi, wrap;
@@ -393,49 +397,49 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
QString family = cfg.readEntry("Family", fontInfo.family());
QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
defaultFont = fdb.font(family,style,i_size,charSet);
editor->setFont( defaultFont);
wa->setOn(wrap);
updateCaption();
if( qApp->argc() > 1 ) {
for (int i=1;i< qApp->argc();i++) {
QString tmp;
currentFileName = tmp.sprintf("%s",qApp->argv()[i]);
qDebug(currentFileName);
setDocument( currentFileName );
}
}
else
fileNew();
}
TextEdit::~TextEdit()
{
- save();
+ saveAs();
Config cfg("TextEdit");
cfg.setGroup("View");
QFont f = editor->font();
cfg.writeEntry("FontSize",f.pointSize());
cfg.writeEntry("Bold",f.bold());
cfg.writeEntry("Italic",f.italic());
cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
}
void TextEdit::zoomIn()
{
setFontSize(editor->font().pointSize()+1,FALSE);
}
void TextEdit::zoomOut()
{
setFontSize(editor->font().pointSize()-1,TRUE);
}
void TextEdit::setFontSize(int sz, bool round_down_not_up)
{
int s=10;
@@ -465,49 +469,49 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up)
void TextEdit::setBold(bool y)
{
QFont f = editor->font();
f.setBold(y);
editor->setFont(f);
}
void TextEdit::setItalic(bool y)
{
QFont f = editor->font();
f.setItalic(y);
editor->setFont(f);
}
void TextEdit::setWordWrap(bool y)
{
bool state = editor->edited();
editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
editor->setEdited( state );
}
void TextEdit::fileNew()
{
if( !bFromDocView ) {
- save();
+ saveAs();
}
newFile(DocLnk());
}
void TextEdit::fileOpen()
{
// if ( !save() ) {
// if ( QMessageBox::critical( this, tr( "Out of space" ),
// tr( "Text Editor was unable to\n"
// "save your changes.\n"
// "Free some space and try again.\n"
// "\nContinue anyway?" ),
// QMessageBox::Yes|QMessageBox::Escape,
// QMessageBox::No|QMessageBox::Default )
// != QMessageBox::Yes )
// return;
// else {
// delete doc;
// doc = 0;
// }
// }
menu->hide();
editBar->hide();
searchBar->hide();
@@ -659,48 +663,63 @@ void TextEdit::openFile( const DocLnk &f )
delete doc;
doc = new DocLnk(f);
editor->setText(txt);
editor->setEdited(FALSE);
updateCaption(currentFileName);
}
void TextEdit::showEditTools()
{
// if ( !doc )
// close();
// clear();
fileSelector->hide();
menu->show();
editBar->show();
if ( searchVisible )
searchBar->show();
// updateCaption();
editorStack->raiseWidget( editor );
setWState (WState_Reserved1 );
}
bool TextEdit::save()
{
+ QString rt = editor->text();
+ doc->setName( currentFileName);
+ FileManager fm;
+ if ( !fm.saveFile( *doc, rt ) ) {
+ return false;
+ }
+ delete doc;
+ doc = 0;
+ editor->setEdited( false );
+ return true;
+
+}
+
+bool TextEdit::saveAs()
+{
// case of nothing to save...
if ( !doc || !bFromDocView)
return true;
if ( !editor->edited() ) {
delete doc;
doc = 0;
return true;
}
QString rt = editor->text();
qDebug(currentFileName);
if( currentFileName.isEmpty() || currentFileName == "Unnamed") {
if ( doc->name().isEmpty() ) {
QString pt = rt.simplifyWhiteSpace();
int i = pt.find( ' ' );
QString docname = pt;
if ( i > 0 )
docname = pt.left( i );
// remove "." at the beginning
while( docname.startsWith( "." ) )
docname = docname.mid( 1 );
docname.replace( QRegExp("/"), "_" );
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h
index 4bfb260..f9eb241 100644
--- a/core/apps/textedit/textedit.h
+++ b/core/apps/textedit/textedit.h
@@ -40,48 +40,50 @@ class QAction;
class FileSelector;
class QpeEditor;
class TextEdit : public QMainWindow
{
Q_OBJECT
public:
TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
~TextEdit();
void openFile( const QString & );
protected:
void closeEvent( QCloseEvent *e );
private slots:
void setDocument(const QString&);
void changeFont();
void fileNew();
void fileRevert();
void fileOpen();
void newFileOpen();
bool save();
+ bool saveAs();
+
void editCut();
void editCopy();
void editPaste();
void editFind();
void findNext();
void findClose();
void search();
void accept();
void newFile( const DocLnk & );
void openFile( const DocLnk & );
void showEditTools();
void zoomIn();
void zoomOut();
void setBold(bool y);
void setItalic(bool y);
void setWordWrap(bool y);
private:
void colorChanged( const QColor &c );