summaryrefslogtreecommitdiff
authorbipolar <bipolar>2002-03-08 00:12:12 (UTC)
committer bipolar <bipolar>2002-03-08 00:12:12 (UTC)
commit11b56113b6641e0b85c6015eafab802dd7663198 (patch) (side-by-side diff)
tree1899707c9144a342519acf9693ec69d2d4edffc7
parent50f8f55346f369787063f42c571d2dc832eb58aa (diff)
downloadopie-11b56113b6641e0b85c6015eafab802dd7663198.zip
opie-11b56113b6641e0b85c6015eafab802dd7663198.tar.gz
opie-11b56113b6641e0b85c6015eafab802dd7663198.tar.bz2
ljp: added startup option,a dn fixed save when closing with no file edited
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileSaver.cpp2
-rw-r--r--core/apps/textedit/textedit.cpp88
-rw-r--r--core/apps/textedit/textedit.h6
3 files changed, 69 insertions, 27 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp
index d78f2e8..4e80735 100644
--- a/core/apps/textedit/fileSaver.cpp
+++ b/core/apps/textedit/fileSaver.cpp
@@ -46,65 +46,65 @@ fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl
ListView = new QListView( this, "ListView" );
ListView->addColumn( tr( "Name" ) );
ListView->setColumnWidth(0,140);
ListView->setSorting( 2, FALSE);
ListView->addColumn( tr( "Size" ) );
ListView->setColumnWidth(1,59);
ListView->setColumnWidthMode(0,QListView::Manual);
ListView->setColumnAlignment(1,QListView::AlignRight);
// ListView->setMultiSelection(true);
// ListView->setSelectionMode(QListView::Extended);
ListView->setAllColumnsShowFocus( TRUE );
ListView->setGeometry( QRect( 10,35,220,125));
fileEdit= new QLineEdit(this);
fileEdit->setGeometry( QRect( 10, 162, 205, 17));
fileEdit->setText( tmpFileName);
filePermCheck = new QCheckBox( this, "SetFilePerms" );
filePermCheck->setText("set file permissions");
filePermCheck->setGeometry(10, 178, 150,17);
// signals and slots connections
connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
// tmpFileName=fi.FilePath();
// qDebug( tmpFileName);
currentDir.setPath( QDir::currentDirPath() );
populateList();
move(0,15);
-
+ fileEdit->setFocus();
}
fileSaver::~fileSaver()
{
}
void fileSaver::populateList()
{
ListView->clear();
currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden );
currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
currentDir.setMatchAllDirs(TRUE);
currentDir.setNameFilter("*");
QString fileL, fileS;
const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
QFileInfoListIterator it(*list);
QFileInfo *fi;
while ( (fi=it.current()) ) {
if (fi->isSymLink() ){
QString symLink=fi->readLink();
// qDebug("Symlink detected "+symLink);
QFileInfo sym( symLink);
fileS.sprintf( "%10li", sym.size() );
fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
} else {
// // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
fileS.sprintf( "%10li", fi->size() );
fileL.sprintf( "%s",fi->fileName().data() );
if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 0f19da9..03f3a1e 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -223,65 +223,65 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive,
#error "Must make a QpeEditor that inherits QTextEdit"
#endif
static int u_id = 1;
static int get_unique_id()
{
return u_id++;
}
static const int nfontsizes = 6;
static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
: QMainWindow( parent, name, f ), bFromDocView( FALSE )
{
doc = 0;
setToolBarsMovable( FALSE );
setIcon( Resource::loadPixmap( "TextEditor" ) );
QPEToolBar *bar = new QPEToolBar( this );
bar->setHorizontalStretchable( TRUE );
menu = bar;
QPEMenuBar *mb = new QPEMenuBar( bar );
QPopupMenu *file = new QPopupMenu( this );
QPopupMenu *edit = new QPopupMenu( this );
- QPopupMenu *font = new QPopupMenu( this );
+ font = new QPopupMenu( this );
bar = new QPEToolBar( this );
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 );
@@ -320,64 +320,70 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
zout->addTo( font );
font->insertSeparator();
#if 0
QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
ba->setToggleAction(TRUE);
ba->addTo( font );
QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
ia->setToggleAction(TRUE);
ia->addTo( font );
ba->setOn(defb);
ia->setOn(defi);
font->insertSeparator();
#endif
QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
wa->setToggleAction(TRUE);
wa->addTo( font );
font->insertSeparator();
font->insertItem("Font", this, SLOT(changeFont()) );
+ font->insertSeparator();
+ nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
+ connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
+ nStart->setToggleAction(TRUE);
+ nStart->addTo( font );
+
mb->insertItem( tr( "File" ), file );
mb->insertItem( tr( "Edit" ), edit );
mb->insertItem( tr( "View" ), font );
searchBar = new QPEToolBar(this);
addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
searchBar->setHorizontalStretchable( TRUE );
searchEdit = new QLineEdit( searchBar, "searchEdit" );
searchBar->setStretchableWidget( searchEdit );
connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
this, SLOT( search() ) );
a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
a->addTo( searchBar );
a->addTo( edit );
a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
a->addTo( searchBar );
edit->insertSeparator();
a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
a->addTo( edit );
searchBar->hide();
editorStack = new QWidgetStack( this );
@@ -385,65 +391,72 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
searchVisible = FALSE;
fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy
connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
// fileOpen();
editor = new QpeEditor( editorStack );
editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
editorStack->addWidget( editor, get_unique_id() );
resize( 200, 300 );
// setFontSize(defsize,TRUE);
FontDatabase fdb;
QFont defaultFont=editor->font();
QFontInfo fontInfo(defaultFont);
cfg.setGroup("Font");
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();
- fileNew();
+ cfg.setGroup("View");
+ if(cfg.readEntry("startNew","TRUE") == "TRUE") {
+ nStart->setOn(TRUE);
+ fileNew();
+ } else {
+ fileOpen();
+ }
+
}
TextEdit::~TextEdit()
{
// save();
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;
for (int i=0; i<nfontsizes; i++) {
if ( fontsize[i] == sz ) {
s = sz;
@@ -668,149 +681,156 @@ void TextEdit::openFile( const DocLnk &f )
fileNew();
if ( doc )
delete doc;
doc = new DocLnk(f);
editor->setText(txt);
editor->setEdited( false);
qDebug("openFile doclnk "+currentFileName);
doc->setName(currentFileName);
updateCaption();
}
void TextEdit::showEditTools()
{
// if ( !doc )
// close();
// clear();
fileSelector->hide();
menu->show();
editBar->show();
if ( searchVisible )
searchBar->show();
// updateCaption();
editorStack->raiseWidget( editor );
setWState (WState_Reserved1 );
}
/*!
unprompted save */
bool TextEdit::save()
{
QString file = doc->file();
+ qDebug(file);
QString name= doc->name();
-
+ qDebug(name);
QString rt = editor->text();
- currentFileName= name ;
- qDebug("saveFile "+currentFileName);
-
- struct stat buf;
- mode_t mode;
- stat(file.latin1(), &buf);
- mode = buf.st_mode;
+ if( !rt.isEmpty() ) {
+ if(name.isEmpty()) {
+ saveAs();
+ } else {
+ currentFileName= name ;
+ qDebug("saveFile "+currentFileName);
+
+ struct stat buf;
+ mode_t mode;
+ stat(file.latin1(), &buf);
+ mode = buf.st_mode;
+
+ doc->setName( name);
+ FileManager fm;
+ if ( !fm.saveFile( *doc, rt ) ) {
+ return false;
+ }
+ editor->setEdited( false );
- doc->setName( name);
- FileManager fm;
- if ( !fm.saveFile( *doc, rt ) ) {
- return false;
+ chmod( file.latin1(), mode);
+ }
+ return true;
}
- editor->setEdited( false );
-
- chmod( file.latin1(), mode);
- return true;
+ return false;
}
/*!
prompted save */
bool TextEdit::saveAs()
{
// qDebug("saveAsFile "+currentFileName);
// case of nothing to save... /// there's always something to save
// if ( !doc )//|| !bFromDocView)
// {
// qDebug("no doc");
// return true;
// }
if ( !editor->edited() ) {
delete doc;
doc = 0;
return true;
}
QString rt = editor->text();
qDebug(currentFileName);
if( currentFileName.isEmpty() || currentFileName == "Unnamed") {
qDebug("do silly TT filename thing");
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("/"), "_" );
// cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
if ( docname.length() > 40 )
docname = docname.left(40);
if ( docname.isEmpty() )
docname = "Unnamed";
doc->setName(docname);
currentFileName=docname;
}
}
- fileSaveDlg=new fileSaver(this,"Save File",TRUE, 0, currentFileName);
+ fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName);
qDebug("wanna save filename "+currentFileName);
fileSaveDlg->exec();
if( fileSaveDlg->result() == 1 ) {
QString fileNm=fileSaveDlg->selectedFileName;
qDebug("saving filename "+fileNm);
QFileInfo fi(fileNm);
currentFileName=fi.fileName();
if(doc) {
- qDebug("doclnk exists");
// QString file = doc->file();
// doc->removeFiles();
delete doc;
DocLnk nf;
nf.setType("text/plain");
nf.setFile( fileNm);
doc = new DocLnk(nf);
// editor->setText(rt);
- qDebug("openFile doclnk "+currentFileName);
+// qDebug("openFile doclnk "+currentFileName);
doc->setName( currentFileName);
updateCaption( currentFileName);
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
return false;
}
if( fileSaveDlg->filePermCheck->isChecked() ) {
filePermissions *filePerm;
filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm);
filePerm->exec();
editor->setEdited( false );
if( filePerm)
delete filePerm;
}
}
}
if(fileSaveDlg)
delete fileSaveDlg;
return true;
}
void TextEdit::clear()
{
delete doc;
doc = 0;
editor->clear();
}
void TextEdit::updateCaption( const QString &name )
{
@@ -826,77 +846,95 @@ void TextEdit::updateCaption( const QString &name )
}
setCaption( s + " - " + tr("Text Editor") );
}
}
void TextEdit::setDocument(const QString& fileref)
{
bFromDocView = TRUE;
qDebug("setDocument "+fileref);
bFromDocView = TRUE;
if(fileref.find(".desktop",0,TRUE) == -1) {
openFile(fileref);
} else {
openFile(DocLnk(fileref));
}
}
void TextEdit::closeEvent( QCloseEvent *e )
{
if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
e->ignore();
repaint();
// fileRevert();
} else {
bFromDocView = FALSE;
e->accept();
}
}
void TextEdit::accept()
-{
- save();
- close();
-// fileOpen(); //godamn thats obnoxious! lemme out!!!
+ {
+ QString file = doc->file();
+ if (file.find("_.txt",0,TRUE) ==-1)
+ save();
+ else {
+ QFile(file).remove();
+ }
+ exit(0);
+
}
void TextEdit::changeFont() {
FontDatabase fdb;
QFont defaultFont=editor->font();
QFontInfo fontInfo(defaultFont);
Config cfg("TextEdit");
cfg.setGroup("Font");
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);
FontDialog *fontDlg;
fontDlg=new FontDialog(this,"FontDialog",TRUE);
fontDlg->exec();
QFont myFont=fontDlg->selectedFont;
editor->setFont( myFont);
delete fontDlg;
}
void TextEdit::editDelete()
{
switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) {
case 0:
if(doc) {
doc->removeFiles();
clear();
setCaption( tr("Text Editor") );
}
break;
case 1:
// exit
break;
};
}
+
+void TextEdit::changeStartConfig( bool b ) {
+
+ Config cfg("TextEdit");
+ cfg.setGroup("View");
+ if(b) {
+ qDebug("bool");
+ cfg.writeEntry("startNew","TRUE");
+ } else {
+ cfg.writeEntry("startNew","FALSE");
+ }
+ update();
+}
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h
index 781061a..fb58738 100644
--- a/core/apps/textedit/textedit.h
+++ b/core/apps/textedit/textedit.h
@@ -5,93 +5,97 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
// additions made by L.J. Potter Sun 02-17-2002 22:27:46
#ifndef TEXTEDIT_H
#define TEXTEDIT_H
#define QTEXTEDIT_OPEN_API
#include "fileBrowser.h"
#include "fileSaver.h"
#include <qpe/filemanager.h>
#include <qmainwindow.h>
#include <qmultilineedit.h>
#include <qlist.h>
#include <qmap.h>
+class QAction;
class QWidgetStack;
class QToolButton;
class QPopupMenu;
class QToolBar;
class QLineEdit;
class QAction;
class FileSelector;
class QpeEditor;
+class QPopupMenu;
class TextEdit : public QMainWindow
{
Q_OBJECT
public:
TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
~TextEdit();
-
+ QPopupMenu *font;
+ QAction *nStart;
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();
+ void changeStartConfig(bool);
bool save();
bool saveAs();
void editCut();
void editCopy();
void editPaste();
void editFind();
void editDelete();
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 );
void clear();
void updateCaption( const QString &name=QString::null );
void setFontSize(int sz, bool round_down_not_up);