summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-12-26 03:49:11 (UTC)
committer llornkcor <llornkcor>2002-12-26 03:49:11 (UTC)
commite4e891190200cf26ba4bafcadca17f2473493276 (patch) (unidiff)
tree16d36e9a6253758c7da926e457cfb613775dae28
parentf736bf0ae774159a80a97b9492d7624e7caf07a3 (diff)
downloadopie-e4e891190200cf26ba4bafcadca17f2473493276.zip
opie-e4e891190200cf26ba4bafcadca17f2473493276.tar.gz
opie-e4e891190200cf26ba4bafcadca17f2473493276.tar.bz2
hook up save and saveAs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/tinykate.cpp41
-rw-r--r--noncore/apps/tinykate/tinykate.h6
2 files changed, 44 insertions, 3 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp
index a823530..c8c3b31 100644
--- a/noncore/apps/tinykate/tinykate.cpp
+++ b/noncore/apps/tinykate/tinykate.cpp
@@ -1,214 +1,253 @@
1/*************************************************************************** 1/***************************************************************************
2 tinykate.cpp 2 tinykate.cpp
3 Tiny KATE mainwindow 3 Tiny KATE mainwindow
4 ------------------- 4 -------------------
5 begin : November 2002 5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> 6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. * 13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * 14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17#include <qwidget.h> 17#include <qwidget.h>
18#include <qaction.h> 18#include <qaction.h>
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qpe/qpetoolbar.h> 20#include <qpe/qpetoolbar.h>
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25 25
26#include <opie/ofiledialog.h> 26#include <opie/ofiledialog.h>
27 27
28#include "tinykate.h" 28#include "tinykate.h"
29#include "pics/file-new.xpm" 29#include "pics/file-new.xpm"
30#include "pics/file-open.xpm" 30#include "pics/file-open.xpm"
31#include "pics/file-save.xpm" 31#include "pics/file-save.xpm"
32#include "pics/edit-undo.xpm" 32#include "pics/edit-undo.xpm"
33#include "pics/edit-redo.xpm" 33#include "pics/edit-redo.xpm"
34 34
35#include <katedocument.h> 35#include <katedocument.h>
36#include <katehighlight.h> 36#include <katehighlight.h>
37#include <kateview.h>
37 38
38TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : 39TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
39 QMainWindow( parent, name, f ) 40 QMainWindow( parent, name, f )
40{ 41{
41 nextUnnamed=0; 42 nextUnnamed=0;
42 currentView=0; 43 currentView=0;
43 viewCount=0; 44 viewCount=0;
44 setCaption(tr("TinyKATE")); 45 setCaption(tr("TinyKATE"));
45 46
46 setToolBarsMovable(FALSE); 47 setToolBarsMovable(FALSE);
47 48
48 QPEToolBar *bar = new QPEToolBar( this ); 49 QPEToolBar *bar = new QPEToolBar( this );
49 bar->setHorizontalStretchable( TRUE ); 50 bar->setHorizontalStretchable( TRUE );
50 QPEMenuBar *mb = new QPEMenuBar( bar ); 51 QPEMenuBar *mb = new QPEMenuBar( bar );
51 mb->setMargin( 0 ); 52 mb->setMargin( 0 );
52 53
53 tabwidget=new OTabWidget(this); 54 tabwidget=new OTabWidget(this);
54 setCentralWidget(tabwidget); 55 setCentralWidget(tabwidget);
55 connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); 56 connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *)));
56 57
57//FILE ACTIONS 58//FILE ACTIONS
58 QPopupMenu *popup = new QPopupMenu( this ); 59 QPopupMenu *popup = new QPopupMenu( this );
59 60
60 // Action for creating a new document 61 // Action for creating a new document
61 QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 ); 62 QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 );
62 a->addTo( popup ); 63 a->addTo( popup );
63 connect(a, SIGNAL(activated()), this, SLOT(slotNew())); 64 connect(a, SIGNAL(activated()), this, SLOT(slotNew()));
64 65
65 // Action for opening an exisiting document 66 // Action for opening an exisiting document
66 a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 ); 67 a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 );
67 a->addTo(popup); 68 a->addTo(popup);
68 connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); 69 connect(a, SIGNAL(activated()), this, SLOT(slotOpen()));
69 70
70 71
71 // Action for saving document 72 // Action for saving document
72 a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); 73 a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 );
73 a->addTo(popup); 74 a->addTo(popup);
75 connect(a, SIGNAL(activated()), this, SLOT(slotSave()));
74 76
75 // Action for saving document to a new name 77 // Action for saving document to a new name
76 a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); 78 a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 );
77 a->addTo(popup); 79 a->addTo(popup);
80 connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs()));
78 81
79 // Action for closing the currently active document 82 // Action for closing the currently active document
80 a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 ); 83 a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 );
81 a->addTo(popup); 84 a->addTo(popup);
82 connect(a, SIGNAL(activated()), this, SLOT(slotClose())); 85 connect(a, SIGNAL(activated()), this, SLOT(slotClose()));
83 86
84 87
85 mb->insertItem(tr("File"),popup); 88 mb->insertItem(tr("File"),popup);
86 89
87//EDIT ACTIONS 90//EDIT ACTIONS
88 91
89 // Action for cutting text 92 // Action for cutting text
90 editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 93 editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
91 editCut->addTo( bar ); 94 editCut->addTo( bar );
92 95
93 // Action for Copying text 96 // Action for Copying text
94 editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); 97 editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
95 editCopy->addTo( bar ); 98 editCopy->addTo( bar );
96 99
97 // Action for pasting text 100 // Action for pasting text
98 editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 101 editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
99 editPaste->addTo( bar ); 102 editPaste->addTo( bar );
100 103
101 104
102 // Action for finding / replacing text 105 // Action for finding / replacing text
103 editFindReplace = new QAction( tr( "Find/Replace" ), Resource::loadPixmap("find"), QString::null, 0, this, 0 ); 106 editFindReplace = new QAction( tr( "Find/Replace" ), Resource::loadPixmap("find"), QString::null, 0, this, 0 );
104 editFindReplace->addTo( bar ); 107 editFindReplace->addTo( bar );
105 108
106 // Action for undo 109 // Action for undo
107 editUndo = new QAction( tr( "Undo" ), QPixmap((const char**)edit_undo_xpm), QString::null, 0, this, 0 ); 110 editUndo = new QAction( tr( "Undo" ), QPixmap((const char**)edit_undo_xpm), QString::null, 0, this, 0 );
108 editUndo->addTo( bar ); 111 editUndo->addTo( bar );
109 112
110 // Action for redo 113 // Action for redo
111 editRedo = new QAction( tr( "Redo" ), QPixmap((const char**)edit_redo_xpm), QString::null, 0, this, 0 ); 114 editRedo = new QAction( tr( "Redo" ), QPixmap((const char**)edit_redo_xpm), QString::null, 0, this, 0 );
112 editRedo->addTo( bar ); 115 editRedo->addTo( bar );
113 116
114//VIEW ACITONS 117//VIEW ACITONS
115 popup = new QPopupMenu( this ); 118 popup = new QPopupMenu( this );
116 119
117 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); 120 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 );
118 viewIncFontSizes->addTo( popup ); 121 viewIncFontSizes->addTo( popup );
119 122
120 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); 123 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 );
121 viewDecFontSizes->addTo( popup ); 124 viewDecFontSizes->addTo( popup );
122 125
123 mb->insertItem(tr("View"),popup); 126 mb->insertItem(tr("View"),popup);
124 127
125 128
126 129
127 popup = new QPopupMenu( this ); 130 popup = new QPopupMenu( this );
128 mb->insertItem(tr("Utils"),popup); 131 mb->insertItem(tr("Utils"),popup);
129 132
130//Highlight management 133//Highlight management
131 hlmenu=new QPopupMenu(this); 134 hlmenu=new QPopupMenu(this);
132 HlManager *hlm=HlManager::self(); 135 HlManager *hlm=HlManager::self();
133 for (int i=0;i<hlm->highlights();i++) 136 for (int i=0;i<hlm->highlights();i++)
134 { 137 {
135 hlmenu->insertItem(hlm->hlName(i),i); 138 hlmenu->insertItem(hlm->hlName(i),i);
136 } 139 }
137 popup->insertItem(tr("Highlighting"),hlmenu); 140 popup->insertItem(tr("Highlighting"),hlmenu);
138 141
139 142
140 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); 143 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 );
141 utilSettings->addTo( popup); 144 utilSettings->addTo( popup);
142 145
143 if( qApp->argc() > 1) open(qApp->argv()[1]); 146 if( qApp->argc() > 1) open(qApp->argv()[1]);
144 else slotNew(); 147 else slotNew();
145 148
146} 149}
147 150
148 151
149void TinyKate::slotOpen( ) 152void TinyKate::slotOpen( )
150{ 153{
151 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL); 154 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL);
152 if (!filename.isEmpty()) { 155 if (!filename.isEmpty()) {
153 open(filename); 156 open(filename);
154 } 157 }
155} 158}
156 159
157void TinyKate::open(const QString & filename) 160void TinyKate::open(const QString & filename)
158{ 161{
159 KateDocument *kd= new KateDocument(false, false, this,0,this); 162 KateDocument *kd= new KateDocument(false, false, this,0,this);
160 KTextEditor::View *kv; 163 KTextEditor::View *kv;
161 QFileInfo fi(filename); 164 QFileInfo fi(filename);
162 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate",fi.fileName()); 165 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate",fi.fileName());
163 qDebug(filename); 166 qDebug(filename);
164 kd->open(filename); 167 kd->open(filename);
165 viewCount++; 168 viewCount++;
166} 169}
167 170
168void TinyKate::slotCurrentChanged( QWidget * view) 171void TinyKate::slotCurrentChanged( QWidget * view)
169{ 172{
170 if (currentView) { 173 if (currentView) {
174
171 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); 175 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
172 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); 176 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
173 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); 177 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
174 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); 178 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
175 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); 179 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
176 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 180 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
177 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 181 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
178 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 182 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
179 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 183 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
180 } 184 }
181 185
182 currentView=(KTextEditor::View*)view; 186 currentView=(KTextEditor::View*)view;
183 187
184 connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); 188 connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
185 connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); 189 connect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
186 connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); 190 connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
187 connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); 191 connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
188 connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); 192 connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
189 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 193 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
190 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 194 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
191 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 195 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
192 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 196 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
193 197
194} 198}
195 199
196void TinyKate::slotNew( ) 200void TinyKate::slotNew( )
197{ 201{
198 KateDocument *kd= new KateDocument(false, false, this,0,this); 202 KateDocument *kd= new KateDocument(false, false, this,0,this);
199 KTextEditor::View *kv; 203 KTextEditor::View *kv;
200 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),"tinykate/tinykate",tr("Unnamed %1").arg(nextUnnamed++)); 204 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),
205 "tinykate/tinykate",
206 tr("Unnamed %1").arg(nextUnnamed++));
201 viewCount++; 207 viewCount++;
202} 208}
203 209
204void TinyKate::slotClose( ) 210void TinyKate::slotClose( )
205{ 211{
206 if (currentView==0) return; 212 if (currentView==0) return;
207 KTextEditor::View *dv=currentView; 213 KTextEditor::View *dv=currentView;
208 currentView=0; 214 currentView=0;
209 tabwidget->removePage(dv); 215 tabwidget->removePage(dv);
210 delete dv->document(); 216 delete dv->document();
211 viewCount--; 217 viewCount--;
212 if (!viewCount) slotNew(); 218 if (!viewCount) slotNew();
213} 219}
214 220
221void TinyKate::slotSave() {
222 // feel free to make this how you want
223 if (currentView==0) return;
224
225 // KateView *kv = (KateView*) currentView;
226 KateDocument *kd = (KateDocument*) currentView->document();
227 // qDebug("saving file "+kd->docName());
228 if( kd->docName().isEmpty())
229 slotSaveAs();
230 else
231 kd->saveFile();
232 // kv->save();
233 // kd->saveFile();
234}
235
236void TinyKate::slotSaveAs() {
237 if (currentView==0) return;
238 KateDocument *kd = (KateDocument*) currentView->document();
239
240 QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL);
241 if (!filename.isEmpty()) {
242 qDebug("saving file "+filename);
243 QFileInfo fi(filename);
244 QString filenamed = fi.fileName();
245 kd->setDocFile( filename);
246 kd->setDocName( filenamed);
247 kd->saveFile();
248// KTextEditor::View *dv = currentView;
249// tabwidget->changeTab( dv, filenamed);
250 // need to change tab label here
251 }
252
253}
diff --git a/noncore/apps/tinykate/tinykate.h b/noncore/apps/tinykate/tinykate.h
index ef0dcba..7b61bae 100644
--- a/noncore/apps/tinykate/tinykate.h
+++ b/noncore/apps/tinykate/tinykate.h
@@ -1,65 +1,67 @@
1/*************************************************************************** 1/***************************************************************************
2 tinykate.h 2 tinykate.h
3 Tiny KATE mainwindow 3 Tiny KATE mainwindow
4 ------------------- 4 -------------------
5 begin : November 2002 5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> 6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. * 13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * 14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#ifndef __TINYKATE_H__ 18#ifndef __TINYKATE_H__
19#define __TINYKATE_H__ 19#define __TINYKATE_H__
20 20
21 21
22#include <qmainwindow.h> 22#include <qmainwindow.h>
23#include <opie/otabwidget.h> 23#include <opie/otabwidget.h>
24#include <ktexteditor.h> 24#include <ktexteditor.h>
25 25
26class QAction; 26class QAction;
27class QPopupMenu; 27class QPopupMenu;
28 28
29class TinyKate : public QMainWindow 29class TinyKate : public QMainWindow
30{ 30{
31Q_OBJECT 31Q_OBJECT
32public: 32public:
33 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); 33 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0);
34 34
35public slots: 35public slots:
36 QString currentFileName;
36 void slotNew(); 37 void slotNew();
37 38
38protected slots: 39protected slots:
39 void slotOpen(); 40 void slotOpen();
40 void slotClose(); 41 void slotClose();
41 void slotCurrentChanged(QWidget *); 42 void slotCurrentChanged(QWidget *);
42 43 void slotSave();
44 void slotSaveAs();
43protected: 45protected:
44 void open(const QString&); 46 void open(const QString&);
45private: 47private:
46 OTabWidget *tabwidget; 48 OTabWidget *tabwidget;
47 KTextEditor::View *currentView; 49 KTextEditor::View *currentView;
48 50
49 QAction *editCopy; 51 QAction *editCopy;
50 QAction *editCut; 52 QAction *editCut;
51 QAction *editPaste; 53 QAction *editPaste;
52 QAction *editUndo; 54 QAction *editUndo;
53 QAction *editRedo; 55 QAction *editRedo;
54 QAction *editFindReplace; 56 QAction *editFindReplace;
55 QAction *viewIncFontSizes; 57 QAction *viewIncFontSizes;
56 QAction *viewDecFontSizes; 58 QAction *viewDecFontSizes;
57 QAction *utilSettings; 59 QAction *utilSettings;
58 60
59 QPopupMenu *hlmenu; 61 QPopupMenu *hlmenu;
60 uint nextUnnamed; 62 uint nextUnnamed;
61 uint viewCount; 63 uint viewCount;
62}; 64};
63 65
64 66
65#endif // __TINYKATE_H__ 67#endif // __TINYKATE_H__