summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-04-10 19:08:30 (UTC)
committer llornkcor <llornkcor>2002-04-10 19:08:30 (UTC)
commit11d754ffa429875b526c49f125d8a844c5cda3d8 (patch) (side-by-side diff)
tree4b2fa1f980e62dad5a0ae465c95eb627df32cdd9
parent5504a71f3e65673a3eea23051d0043f2b483276b (diff)
downloadopie-11d754ffa429875b526c49f125d8a844c5cda3d8.zip
opie-11d754ffa429875b526c49f125d8a844c5cda3d8.tar.gz
opie-11d754ffa429875b526c49f125d8a844c5cda3d8.tar.bz2
bug fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileBrowser.cpp28
-rw-r--r--core/apps/textedit/textedit.cpp99
-rw-r--r--core/apps/textedit/textedit.h7
3 files changed, 73 insertions, 61 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp
index bc99348..f322513 100644
--- a/core/apps/textedit/fileBrowser.cpp
+++ b/core/apps/textedit/fileBrowser.cpp
@@ -27,49 +27,49 @@
#include <qlistview.h>
#include <qcombo.h>
#include <qpushbutton.h>
#include <qfile.h>
#include <qmessagebox.h>
#include <qlayout.h>
#include <unistd.h>
#include <qpopupmenu.h>
#include <qlineedit.h>
#include <qstringlist.h>
#include <unistd.h>
#include <stdlib.h>
static int u_id = 1;
static int get_unique_id()
{
return u_id++;
}
fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString mimeFilter )
: QDialog( parent, name, modal, fl )
{
if ( !name )
- setName( tr("fileBrowser") );
+ setName( "fileBrowser" );
setCaption(tr( name ) );
// mimeType = mimeFilter;
// MimeType mt( mimeType);
// if( mt.extension().isEmpty())
// QStringList filterList;
// filterList=QStringList::split(";",mimeFilter,FALSE);
// for ( QStringList::Iterator it = filterList.begin(); it != filterList.end(); ++it ) {
// printf( "%s \n", (*it).latin1() );
// }
filterStr = mimeFilter.right(mimeFilter.length() - mimeFilter.find("/",0,TRUE) - 1);// "*";
qDebug(filterStr);
// else
// filterStr = "*."+ mt.extension();
// qDebug("description "+mt.description());
// qDebug( "id "+mt.id());
// qDebug("extension "+mt.extension());
// channel = new QCopChannel( "QPE/fileDialog", this );
// connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
// this, SLOT(receive(const QCString&, const QByteArray&)) );
QGridLayout *layout = new QGridLayout( this );
@@ -99,63 +99,63 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton");
docButton->setMinimumSize( QSize( 20, 20 ) );
docButton->setMaximumSize( QSize( 20, 20 ) );
connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) );
docButton->setFlat(TRUE);
layout->addMultiCellWidget( docButton, 0, 0, 6, 6 );
homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton");
homeButton->setMinimumSize( QSize( 20, 20 ) );
homeButton->setMaximumSize( QSize( 20, 20 ) );
connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) );
homeButton->setFlat(TRUE);
layout->addMultiCellWidget( homeButton, 0, 0, 7, 7 );
FileStack = new QWidgetStack( this );
ListView = new QListView( this, "ListView" );
// ListView->setMinimumSize( QSize( 100, 25 ) );
ListView->addColumn( tr( "Name" ) );
ListView->setColumnWidth(0,120);
ListView->setSorting( 2, FALSE);
ListView->addColumn( tr( "Size" ) );
ListView->setColumnWidth(1,-1);
- ListView->addColumn( tr("Date"),-1);
+ ListView->addColumn( "Date",-1);
ListView->setColumnWidthMode(0,QListView::Manual);
ListView->setColumnAlignment(1,QListView::AlignRight);
ListView->setColumnAlignment(2,QListView::AlignRight);
ListView->setAllColumnsShowFocus( TRUE );
QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold);
connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
this, SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
connect( ListView, SIGNAL( clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
FileStack->addWidget( ListView, get_unique_id() );
-
+mimeType="text/plain";
fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //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( docOpen( const DocLnk & ) ) );
layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 );
SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" );
SelectionCombo->insertItem( tr( "Documents" ) );
SelectionCombo->insertItem( tr( "All files" ) );
SelectionCombo->insertItem( tr( "Hidden files" ) );
// SelectionCombo->setMaximumWidth(120);
layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 );
connect( SelectionCombo, SIGNAL( activated( const QString & ) ),
this, SLOT( selectionChanged( const QString & ) ) );
typemb = new MenuButton(this);
typemb->setLabel(tr("Type: %1"));
typemb->setMinimumWidth(110);
typemb->setFixedHeight(22);
layout->addMultiCellWidget( typemb, 2, 2, 4, 7 );
updateMimeTypeMenu() ;
@@ -327,56 +327,56 @@ void fileBrowser::OnOK()
}
}
accept();
}
void fileBrowser::homeButtonPushed() {
QString current = QDir::homeDirPath();
chdir( current.latin1() );
currentDir.cd( current, TRUE);
populateList();
update();
}
void fileBrowser::docButtonPushed() {
QString current = QPEApplication::documentDir();
chdir( current.latin1() );
currentDir.cd( current, TRUE);
populateList();
update();
}
void fileBrowser::selectionChanged( const QString &select )
{
- if ( select == tr("Documents")) {
+ if ( select == "Documents") {
FileStack->raiseWidget( fileSelector );
dirPathCombo->hide();
cdUpButton->hide();
docButton->hide();
homeButton->hide();
} else {
- if ( select == tr("All files") )
+ if ( select == "All files" )
currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All);
else
currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
populateList();
update();
dirPathCombo->show();
cdUpButton->show();
docButton->show();
homeButton->show();
FileStack->raiseWidget( ListView );
}
}
void fileBrowser::docOpen( const DocLnk &doc )
{
fileList.append( doc.file().latin1() );
accept();
}
void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i)
{
switch (mouse) {
case 1:
@@ -391,130 +391,130 @@ void fileBrowser::showListMenu(QListViewItem *item) {
QPopupMenu m;// = new QPopupMenu( Local_View );
if(item) {
if( item->text(0).find("/",0,TRUE))
m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() ));
m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() ));
m.insertItem( tr( "Rescan" ), this, SLOT( populateList() ));
m.insertItem( tr( "Rename" ), this, SLOT( localRename() ));
m.insertSeparator();
m.insertItem( tr( "Delete" ), this, SLOT( localDelete() ));
} else {
m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() ));
m.insertItem( tr( "Rescan" ), this, SLOT( populateList() ));
}
m.exec( QCursor::pos() );
}
void fileBrowser::doCd() {
listClicked( ListView->currentItem());
}
void fileBrowser::makDir() {
InputDialog *fileDlg;
- fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
+ fileDlg = new InputDialog(this,"Make Directory",TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
QString filename = fileDlg->LineEdit1->text();
qDebug("Make dir");
currentDir.mkdir( currentDir.canonicalPath()+"/"+filename);
}
populateList();
}
void fileBrowser::localRename() {
QString curFile = ListView->currentItem()->text(0);
InputDialog *fileDlg;
- fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0);
+ fileDlg = new InputDialog(this,"Rename",TRUE, 0);
fileDlg->setTextEdit((const QString &) curFile);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
QString oldname = currentDir.canonicalPath() + "/" + curFile;
QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist";
if( rename(oldname.latin1(), newName.latin1())== -1)
- QMessageBox::message(tr("Note"),tr("Could not rename"));
+ QMessageBox::message("Note","Could not rename");
}
populateList();
}
void fileBrowser::localDelete() {
QString f = ListView->currentItem()->text(0);
if(QDir(f).exists() ) {
- switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+
- tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) {
+ switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+
+ " ?\nIt must be empty","Yes","No",0,0,1) ) {
case 0: {
f=currentDir.canonicalPath()+"/"+f;
QString cmd="rmdir "+f;
system( cmd.latin1());
populateList();
}
break;
case 1:
// exit
break;
};
} else {
- switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f
- +" ?",tr("Yes"),tr("No"),0,0,1) ) {
+ switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f
+ +" ?","Yes","No",0,0,1) ) {
case 0: {
f=currentDir.canonicalPath()+"/"+f;
QString cmd="rm "+f;
system( cmd.latin1());
populateList();
}
break;
case 1:
// exit
break;
};
}
}
void fileBrowser::updateMimeTypeMenu() {
disconnect( typemb, SIGNAL(selected(const QString&)),
this, SLOT(showType(const QString&)) );
QString prev;
// Type filter
QStringList types;
types << tr("All");
types << "--";
types += getMimeTypes();
prev = typemb->currentText();
typemb->clear();
typemb->insertItems(types);
// typemb->select(prev);
connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&)));
}
void fileBrowser::showType(const QString &t) {
qDebug(t);
- if(t.find(tr("All"),0,TRUE) != -1) {
+ if(t.find("All",0,TRUE) != -1) {
filterStr = "*";
} else {
QStringList list = mimetypes.grep( t,TRUE);
QString ext;
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
mimeType =(*it);
MimeType mt( mimeType);
// qDebug("mime "+mimeType);
// qDebug("description "+mt.description());
// qDebug( "id "+mt.id());
// qDebug("extension "+mt.extension());
// if( mt.extension().isEmpty())
filterStr = "*";
// else
// filterStr = "*."+ mt.extension()+" ";
// printf( "%s \n", (*it).latin1() );
}
}
currentDir.setNameFilter(filterStr);
populateList();
update();
// if(fileSelector) {
// disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) );
@@ -584,42 +584,42 @@ void fileBrowser::dirPathComboActivated( const QString & current) {
void fileBrowser::dirPathEditPressed() {
QString current = dirPathCombo->lineEdit()->text();
chdir( current.latin1() );
currentDir.cd( current, TRUE);
populateList();
update();
}
void fileBrowser::fillCombo(const QString &currentPath) {
dirPathCombo->lineEdit()->setText(currentPath);
if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) {
dirPathCombo->clear();
dirPathStringList.prepend(currentPath );
dirPathCombo->insertStringList( dirPathStringList,-1);
}
}
InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
if ( !name )
- setName( tr("InputDialog") );
+ setName( "InputDialog" );
resize( 234, 50 );
setMaximumSize( QSize( 240, 50 ) );
setCaption( tr(name ) );
LineEdit1 = new QLineEdit( this, "LineEdit1" );
LineEdit1->setGeometry( QRect( 10, 10, 216, 22 ) );
}
InputDialog::~InputDialog()
{
inputText= LineEdit1->text();
}
void InputDialog::setTextEdit(const QString &string) {
LineEdit1->setText(string);
}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 6804918..943fecd 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -14,48 +14,49 @@
** 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.
**
**********************************************************************/
// changes added by L. J. Potter Sun 02-17-2002 21:31:31
#include "textedit.h"
#include "fileBrowser.h"
#include "fileSaver.h"
#include "filePermissions.h"
#include "fontDialog.h"
#include <qpe/fontdatabase.h>
#include <qpe/global.h>
#include <qpe/fileselector.h>
#include <qpe/applnk.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
+#include <qpe/qcopenvelope_qws.h>
//#include <qpe/finddialog.h>
#include <qstringlist.h>
#include <qaction.h>
#include <qcolordialog.h>
#include <qfileinfo.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qobjectlist.h>
#include <qpopupmenu.h>
#include <qspinbox.h>
#include <qtoolbutton.h>
#include <qwidgetstack.h>
#include <qcheckbox.h>
#include <qcombo.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h> //getenv
/* XPM */
static char * filesave_xpm[] = {
"16 16 78 1",
" c None",
". c #343434",
@@ -217,48 +218,52 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive,
}
}
#else
#error "Must make a QpeEditor that inherits QTextEdit"
#endif
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;
edited=FALSE;
edited1=FALSE;
setToolBarsMovable( FALSE );
connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
+ channel = new QCopChannel( "QPE/Application/textedit", this );
+ connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
+ this, SLOT(receive(const QCString&, const QByteArray&)) );
+
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 );
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 );
@@ -376,55 +381,55 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
editor = new QpeEditor( this );
setCentralWidget( editor );
editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
// 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();
- cfg.setGroup("View");
- if(cfg.readEntry("startNew","TRUE") == "TRUE") {
- nStart->setOn(TRUE);
- fileNew();
- } else {
- fileOpen();
- }
+ cfg.setGroup("View");
+ if(cfg.readEntry("startNew","TRUE") == "TRUE") {
+ nStart->setOn(TRUE);
+ fileNew();
+ } else {
+ fileOpen();
+ }
viewSelection = cfg.readNumEntry( "FileView", 0 );
}
void TextEdit::cleanUp()
{
// 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);
cfg.writeEntry( "FileView", viewSelection );
}
TextEdit::~TextEdit()
{
}
void TextEdit::zoomIn()
{
setFontSize(editor->font().pointSize()+1,FALSE);
@@ -464,59 +469,61 @@ 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 ) {
- saveAs();
- }
+// if( !bFromDocView ) {
+// saveAs();
+// }
newFile(DocLnk());
}
void TextEdit::fileOpen()
{
- browseForFiles=new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); //
+ browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); //
browseForFiles->setFileView( viewSelection );
browseForFiles->showMaximized();
+// if( result != -1 )
+
if( browseForFiles->exec() != -1 ) {
QString selFile = browseForFiles->selectedFileName;
QStringList fileList = browseForFiles->fileList;
qDebug(selFile);
QStringList::ConstIterator f;
QString fileTemp;
for ( f = fileList.begin(); f != fileList.end(); f++ ) {
fileTemp = *f;
fileTemp.right( fileTemp.length()-5);
QString fileName = fileTemp;
if( fileName != "Unnamed" || fileName != "Empty Text" ) {
currentFileName = fileName;
qDebug("please open "+currentFileName);
openFile(fileName );
}
}
viewSelection = browseForFiles->SelectionCombo->currentItem();
}
delete browseForFiles;
editor->setEdited( FALSE);
edited1=FALSE;
edited=FALSE;
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
@@ -597,178 +604,175 @@ void TextEdit::findNext()
void TextEdit::findClose()
{
searchVisible = FALSE;
searchBar->hide();
Config cfg("TextEdit");
cfg.setGroup("View");
cfg.writeEntry("SearchBar","Closed");
cfg.write();
}
void TextEdit::search()
{
editor->find( searchEdit->text(), FALSE, FALSE );
}
void TextEdit::newFile( const DocLnk &f )
{
DocLnk nf = f;
nf.setType("text/plain");
clear();
setWState (WState_Reserved1 );
editor->setFocus();
doc = new DocLnk(nf);
+ currentFileName = "Unnamed";
qDebug("newFile "+currentFileName);
- updateCaption(currentFileName);
+ updateCaption( currentFileName);
+// editor->setEdited( FALSE);
}
void TextEdit::openFile( const QString &f )
{
- bFromDocView = TRUE;
+// bFromDocView = TRUE;
DocLnk nf;
nf.setType("text/plain");
nf.setFile(f);
currentFileName=f;
QFileInfo fi( currentFileName);
nf.setName(fi.baseName());
qDebug("openFile string"+currentFileName);
openFile(nf);
showEditTools();
- // Show filename in caption
+ // Show filename in caption
QString name = f;
int sep = name.findRev( '/' );
if ( sep > 0 )
- name = name.mid( sep+1 );
+ name = name.mid( sep+1 );
updateCaption( name );
}
void TextEdit::openFile( const DocLnk &f )
{
// clear();
- bFromDocView = TRUE;
+// bFromDocView = TRUE;
FileManager fm;
QString txt;
currentFileName=f.name();
qDebug("openFile doclnk " + currentFileName);
if ( !fm.loadFile( f, txt ) ) {
- // ####### could be a new file
+ // ####### could be a new file
qDebug( "Cannot open file" );
-
- //return;
}
-
- fileNew();
+// fileNew();
if ( doc )
- delete doc;
+ delete doc;
doc = new DocLnk(f);
editor->setText(txt);
editor->setEdited( FALSE);
edited1=FALSE;
edited=FALSE;
- qDebug("openFile doclnk "+currentFileName);
doc->setName(currentFileName);
updateCaption();
}
void TextEdit::showEditTools()
{
// if ( !doc )
// close();
// clear();
menu->show();
editBar->show();
if ( searchVisible )
searchBar->show();
// updateCaption();
setWState (WState_Reserved1 );
}
/*!
unprompted save */
bool TextEdit::save()
{
QString file = doc->file();
- qDebug(file);
+ qDebug("saver file "+file);
QString name= doc->name();
- qDebug(name);
+ qDebug("File named "+name);
QString rt = editor->text();
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);
edited1=FALSE;
edited=FALSE;
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
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;
-// }
+ // case of nothing 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 == tr("Unnamed")) {
+ if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) {
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 = tr("Unnamed");
doc->setName(docname);
currentFileName=docname;
}
}
fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName);
qDebug("wanna save filename "+currentFileName);
@@ -793,104 +797,101 @@ bool TextEdit::saveAs()
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
return false;
}
if( fileSaveDlg->filePermCheck->isChecked() ) {
filePermissions *filePerm;
filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm);
filePerm->exec();
if( filePerm)
delete filePerm;
}
}
}
editor->setEdited(TRUE);
edited1=FALSE;
edited=TRUE;
if(caption().left(1)=="*")
setCaption(caption().right(caption().length()-1));
if(fileSaveDlg)
delete fileSaveDlg;
return true;
-}
+} //end saveAs
void TextEdit::clear()
{
delete doc;
doc = 0;
editor->clear();
}
void TextEdit::updateCaption( const QString &name )
{
if ( !doc )
setCaption( tr("Text Editor") );
else {
QString s = name;
if ( s.isNull() )
s = doc->name();
if ( s.isEmpty() ) {
s = tr( "Unnamed" );
currentFileName=s;
}
-
+ if(s.left(1) == "/")
+ s = s.right(s.length()-1);
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);
+ openFile(fileref);
} else {
- openFile(DocLnk(fileref));
+ qDebug("is desktop file");
+ openFile(DocLnk(fileref));
}
editor->setEdited(TRUE);
edited1=FALSE;
edited=TRUE;
doSearchBar();
}
void TextEdit::closeEvent( QCloseEvent *e )
{
bFromDocView = FALSE;
e->accept();
}
void TextEdit::accept()
{
- QString file = doc->file();
- if (file.find("_.txt",0,TRUE) ==-1)
- save();
- else {
- QFile(file).remove();
- }
+ //if(caption() !="Unnamed")
+ if(edited1)
+ saveAs();
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,tr("FontDialog"),TRUE);
fontDlg->exec();
QFont myFont=fontDlg->selectedFont;
editor->setFont( myFont);
@@ -913,24 +914,32 @@ void TextEdit::editDelete()
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();
}
void TextEdit::editorChanged() {
if(editor->edited() && edited && !edited1) {
setCaption( "*"+caption());
edited1=TRUE;
}
edited=TRUE;
}
+
+void TextEdit::receive(const QCString&msg, const QByteArray&) {
+ qDebug("QCop "+msg);
+ if ( msg == "setDocument(QString)" ) {
+ qDebug("bugger all");
+ }
+
+}
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h
index af69518..61fa2a0 100644
--- a/core/apps/textedit/textedit.h
+++ b/core/apps/textedit/textedit.h
@@ -7,115 +7,118 @@
** 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 <qpe/qcopenvelope_qws.h>
+
+#include <opie/ofileselector.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;
bool edited, edited1;
void openFile( const QString & );
+ QCopChannel * channel;
public slots:
void editorChanged();
-
+void receive(const QCString&, const QByteArray&);
protected:
void closeEvent( QCloseEvent *e );
void doSearchBar();
private slots:
void setDocument(const QString&);
void changeFont();
void fileNew();
void fileRevert();
void fileOpen();
void changeStartConfig(bool);
bool save();
bool saveAs();
void cleanUp();
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);
private:
fileSaver *fileSaveDlg;
fileBrowser *browseForFiles;
-
QpeEditor* editor;
QToolBar *menu, *editBar, *searchBar;
QLineEdit *searchEdit;
DocLnk *doc;
bool searchVisible;
bool bFromDocView;
int viewSelection;
QAction *zin, *zout;
QString currentFileName;
};
#endif