-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 24 | ||||
-rw-r--r-- | noncore/apps/tinykate/tinykate.h | 9 |
2 files changed, 25 insertions, 8 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index 03c6e50..f177e47 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp | |||
@@ -1,64 +1,67 @@ | |||
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 | 25 | ||
25 | #include <opie/ofiledialog.h> | 26 | #include <opie/ofiledialog.h> |
26 | 27 | ||
27 | #include "tinykate.h" | 28 | #include "tinykate.h" |
28 | #include "pics/file-new.xpm" | 29 | #include "pics/file-new.xpm" |
29 | #include "pics/file-open.xpm" | 30 | #include "pics/file-open.xpm" |
30 | #include "pics/file-save.xpm" | 31 | #include "pics/file-save.xpm" |
31 | #include "pics/edit-undo.xpm" | 32 | #include "pics/edit-undo.xpm" |
32 | #include "pics/edit-redo.xpm" | 33 | #include "pics/edit-redo.xpm" |
33 | 34 | ||
34 | #include <katedocument.h> | 35 | #include <katedocument.h> |
35 | #include <katehighlight.h> | 36 | #include <katehighlight.h> |
36 | 37 | ||
37 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 38 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
38 | QMainWindow( parent, name, f ) | 39 | QMainWindow( parent, name, f ) |
39 | { | 40 | { |
41 | nextUnnamed=0; | ||
40 | currentView=0; | 42 | currentView=0; |
43 | viewCount=0; | ||
41 | setCaption(tr("TinyKATE")); | 44 | setCaption(tr("TinyKATE")); |
42 | 45 | ||
43 | setToolBarsMovable(FALSE); | 46 | setToolBarsMovable(FALSE); |
44 | 47 | ||
45 | QPEToolBar *bar = new QPEToolBar( this ); | 48 | QPEToolBar *bar = new QPEToolBar( this ); |
46 | bar->setHorizontalStretchable( TRUE ); | 49 | bar->setHorizontalStretchable( TRUE ); |
47 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 50 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
48 | mb->setMargin( 0 ); | 51 | mb->setMargin( 0 ); |
49 | 52 | ||
50 | tabwidget=new OTabWidget(this); | 53 | tabwidget=new OTabWidget(this); |
51 | setCentralWidget(tabwidget); | 54 | setCentralWidget(tabwidget); |
52 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); | 55 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); |
53 | 56 | ||
54 | //FILE ACTIONS | 57 | //FILE ACTIONS |
55 | QPopupMenu *popup = new QPopupMenu( this ); | 58 | QPopupMenu *popup = new QPopupMenu( this ); |
56 | 59 | ||
57 | // Action for creating a new document | 60 | // Action for creating a new document |
58 | QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 ); | 61 | QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 ); |
59 | a->addTo( popup ); | 62 | a->addTo( popup ); |
60 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); | 63 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); |
61 | 64 | ||
62 | // Action for opening an exisiting document | 65 | // Action for opening an exisiting document |
63 | a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 ); | 66 | a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 ); |
64 | a->addTo(popup); | 67 | a->addTo(popup); |
@@ -116,84 +119,95 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
116 | 119 | ||
117 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); | 120 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); |
118 | viewDecFontSizes->addTo( popup ); | 121 | viewDecFontSizes->addTo( popup ); |
119 | 122 | ||
120 | mb->insertItem(tr("View"),popup); | 123 | mb->insertItem(tr("View"),popup); |
121 | 124 | ||
122 | 125 | ||
123 | 126 | ||
124 | popup = new QPopupMenu( this ); | 127 | popup = new QPopupMenu( this ); |
125 | mb->insertItem(tr("Utils"),popup); | 128 | mb->insertItem(tr("Utils"),popup); |
126 | 129 | ||
127 | //Highlight management | 130 | //Highlight management |
128 | hlmenu=new QPopupMenu(this); | 131 | hlmenu=new QPopupMenu(this); |
129 | HlManager *hlm=HlManager::self(); | 132 | HlManager *hlm=HlManager::self(); |
130 | for (int i=0;i<hlm->highlights();i++) | 133 | for (int i=0;i<hlm->highlights();i++) |
131 | { | 134 | { |
132 | hlmenu->insertItem(hlm->hlName(i),i); | 135 | hlmenu->insertItem(hlm->hlName(i),i); |
133 | } | 136 | } |
134 | popup->insertItem(tr("Highlighting"),hlmenu); | 137 | popup->insertItem(tr("Highlighting"),hlmenu); |
135 | 138 | ||
136 | 139 | ||
137 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); | 140 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); |
138 | utilSettings->addTo( popup); | 141 | utilSettings->addTo( popup); |
139 | 142 | ||
143 | if( qApp->argc() > 1) open(qApp->argv()[1]); | ||
144 | else slotNew(); | ||
145 | |||
140 | } | 146 | } |
141 | 147 | ||
142 | 148 | ||
143 | void TinyKate::slotOpen( ) | 149 | void TinyKate::slotOpen( ) |
144 | { | 150 | { |
145 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL); | 151 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL); |
146 | if (!filename.isEmpty()) { | 152 | if (!filename.isEmpty()) { |
153 | open(filename); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | void TinyKate::open(const QString & filename) | ||
158 | { | ||
147 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 159 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
148 | KTextEditor::View *kv; | 160 | KTextEditor::View *kv; |
149 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"BLAH","BLAH"); | 161 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate","BLAH"); |
150 | qDebug(filename); | 162 | qDebug(filename); |
151 | kd->open(filename); | 163 | kd->open(filename); |
152 | } | 164 | viewCount++; |
153 | } | 165 | } |
154 | 166 | ||
155 | void TinyKate::slotCurrentChanged( QWidget * view) | 167 | void TinyKate::slotCurrentChanged( QWidget * view) |
156 | { | 168 | { |
157 | if (currentView) { | 169 | if (currentView) { |
158 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 170 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
159 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 171 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
160 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 172 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
161 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 173 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
162 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 174 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
163 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 175 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
164 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 176 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
165 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 177 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
166 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 178 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
167 | } | 179 | } |
168 | 180 | ||
169 | currentView=(KTextEditor::View*)view; | 181 | currentView=(KTextEditor::View*)view; |
170 | 182 | ||
171 | connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 183 | connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
172 | connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 184 | connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
173 | connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 185 | connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
174 | connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 186 | connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
175 | connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 187 | connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
176 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 188 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
177 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 189 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
178 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 190 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
179 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 191 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
180 | 192 | ||
181 | } | 193 | } |
182 | 194 | ||
183 | void TinyKate::slotNew( ) | 195 | void TinyKate::slotNew( ) |
184 | { | 196 | { |
185 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 197 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
186 | KTextEditor::View *kv; | 198 | KTextEditor::View *kv; |
187 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),"BLAH",tr("Unnamed %1").arg(0)); | 199 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),"tinykate/tinykate",tr("Unnamed %1").arg(nextUnnamed++)); |
188 | 200 | viewCount++; | |
189 | } | 201 | } |
190 | 202 | ||
191 | void TinyKate::slotClose( ) | 203 | void TinyKate::slotClose( ) |
192 | { | 204 | { |
193 | if (currentView==0) return; | 205 | if (currentView==0) return; |
194 | KTextEditor::View *dv=currentView; | 206 | KTextEditor::View *dv=currentView; |
195 | currentView=0; | 207 | currentView=0; |
196 | tabwidget->removePage(dv); | 208 | tabwidget->removePage(dv); |
197 | delete dv->document(); | 209 | delete dv->document(); |
210 | viewCount--; | ||
211 | if (!viewCount) slotNew(); | ||
198 | } | 212 | } |
199 | 213 | ||
diff --git a/noncore/apps/tinykate/tinykate.h b/noncore/apps/tinykate/tinykate.h index 6dda05d..ef0dcba 100644 --- a/noncore/apps/tinykate/tinykate.h +++ b/noncore/apps/tinykate/tinykate.h | |||
@@ -12,51 +12,54 @@ | |||
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 | ||
26 | class QAction; | 26 | class QAction; |
27 | class QPopupMenu; | 27 | class QPopupMenu; |
28 | 28 | ||
29 | class TinyKate : public QMainWindow | 29 | class TinyKate : public QMainWindow |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | public: | 32 | public: |
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 | ||
35 | public slots: | 35 | public slots: |
36 | void slotOpen(); | 36 | void slotNew(); |
37 | 37 | ||
38 | protected slots: | 38 | protected slots: |
39 | void slotNew(); | 39 | void slotOpen(); |
40 | void slotClose(); | 40 | void slotClose(); |
41 | void slotCurrentChanged(QWidget *); | 41 | void slotCurrentChanged(QWidget *); |
42 | 42 | ||
43 | protected: | ||
44 | void open(const QString&); | ||
43 | private: | 45 | private: |
44 | OTabWidget *tabwidget; | 46 | OTabWidget *tabwidget; |
45 | KTextEditor::View *currentView; | 47 | KTextEditor::View *currentView; |
46 | 48 | ||
47 | QAction *editCopy; | 49 | QAction *editCopy; |
48 | QAction *editCut; | 50 | QAction *editCut; |
49 | QAction *editPaste; | 51 | QAction *editPaste; |
50 | QAction *editUndo; | 52 | QAction *editUndo; |
51 | QAction *editRedo; | 53 | QAction *editRedo; |
52 | QAction *editFindReplace; | 54 | QAction *editFindReplace; |
53 | QAction *viewIncFontSizes; | 55 | QAction *viewIncFontSizes; |
54 | QAction *viewDecFontSizes; | 56 | QAction *viewDecFontSizes; |
55 | QAction *utilSettings; | 57 | QAction *utilSettings; |
56 | 58 | ||
57 | QPopupMenu *hlmenu; | 59 | QPopupMenu *hlmenu; |
58 | 60 | uint nextUnnamed; | |
61 | uint viewCount; | ||
59 | }; | 62 | }; |
60 | 63 | ||
61 | 64 | ||
62 | #endif // __TINYKATE_H__ | 65 | #endif // __TINYKATE_H__ |