-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index 51afd31..6164fa5 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp | |||
@@ -1,256 +1,258 @@ | |||
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 | #include <kateview.h> |
38 | 38 | ||
39 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 39 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
40 | QMainWindow( parent, name, f ) | 40 | QMainWindow( parent, name, f ) |
41 | { | 41 | { |
42 | nextUnnamed=0; | 42 | nextUnnamed=0; |
43 | currentView=0; | 43 | currentView=0; |
44 | viewCount=0; | 44 | viewCount=0; |
45 | setCaption(tr("TinyKATE")); | 45 | setCaption(tr("TinyKATE")); |
46 | 46 | ||
47 | setToolBarsMovable(FALSE); | 47 | setToolBarsMovable(FALSE); |
48 | 48 | ||
49 | QPEToolBar *bar = new QPEToolBar( this ); | 49 | QPEToolBar *bar = new QPEToolBar( this ); |
50 | bar->setHorizontalStretchable( TRUE ); | 50 | bar->setHorizontalStretchable( TRUE ); |
51 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 51 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
52 | mb->setMargin( 0 ); | 52 | mb->setMargin( 0 ); |
53 | 53 | ||
54 | tabwidget=new OTabWidget(this); | 54 | tabwidget=new OTabWidget(this); |
55 | setCentralWidget(tabwidget); | 55 | setCentralWidget(tabwidget); |
56 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); | 56 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); |
57 | 57 | ||
58 | //FILE ACTIONS | 58 | //FILE ACTIONS |
59 | QPopupMenu *popup = new QPopupMenu( this ); | 59 | QPopupMenu *popup = new QPopupMenu( this ); |
60 | 60 | ||
61 | // Action for creating a new document | 61 | // Action for creating a new document |
62 | 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 ); |
63 | a->addTo( popup ); | 63 | a->addTo( popup ); |
64 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); | 64 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); |
65 | 65 | ||
66 | // Action for opening an exisiting document | 66 | // Action for opening an exisiting document |
67 | 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 ); |
68 | a->addTo(popup); | 68 | a->addTo(popup); |
69 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); | 69 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); |
70 | 70 | ||
71 | 71 | ||
72 | // Action for saving document | 72 | // Action for saving document |
73 | 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 ); |
74 | a->addTo(popup); | 74 | a->addTo(popup); |
75 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); | 75 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); |
76 | 76 | ||
77 | // Action for saving document to a new name | 77 | // Action for saving document to a new name |
78 | 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 ); |
79 | a->addTo(popup); | 79 | a->addTo(popup); |
80 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); | 80 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); |
81 | 81 | ||
82 | // Action for closing the currently active document | 82 | // Action for closing the currently active document |
83 | a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 ); | 83 | a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 ); |
84 | a->addTo(popup); | 84 | a->addTo(popup); |
85 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); | 85 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); |
86 | 86 | ||
87 | 87 | ||
88 | mb->insertItem(tr("File"),popup); | 88 | mb->insertItem(tr("File"),popup); |
89 | 89 | ||
90 | //EDIT ACTIONS | 90 | //EDIT ACTIONS |
91 | 91 | ||
92 | // Action for cutting text | 92 | // Action for cutting text |
93 | 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 ); |
94 | editCut->addTo( bar ); | 94 | editCut->addTo( bar ); |
95 | 95 | ||
96 | // Action for Copying text | 96 | // Action for Copying text |
97 | 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 ); |
98 | editCopy->addTo( bar ); | 98 | editCopy->addTo( bar ); |
99 | 99 | ||
100 | // Action for pasting text | 100 | // Action for pasting text |
101 | 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 ); |
102 | editPaste->addTo( bar ); | 102 | editPaste->addTo( bar ); |
103 | 103 | ||
104 | 104 | ||
105 | // Action for finding / replacing text | 105 | // Action for finding / replacing text |
106 | 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 ); |
107 | editFindReplace->addTo( bar ); | 107 | editFindReplace->addTo( bar ); |
108 | 108 | ||
109 | // Action for undo | 109 | // Action for undo |
110 | 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 ); |
111 | editUndo->addTo( bar ); | 111 | editUndo->addTo( bar ); |
112 | 112 | ||
113 | // Action for redo | 113 | // Action for redo |
114 | 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 ); |
115 | editRedo->addTo( bar ); | 115 | editRedo->addTo( bar ); |
116 | 116 | ||
117 | //VIEW ACITONS | 117 | //VIEW ACITONS |
118 | popup = new QPopupMenu( this ); | 118 | popup = new QPopupMenu( this ); |
119 | 119 | ||
120 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); | 120 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); |
121 | viewIncFontSizes->addTo( popup ); | 121 | viewIncFontSizes->addTo( popup ); |
122 | 122 | ||
123 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); | 123 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); |
124 | viewDecFontSizes->addTo( popup ); | 124 | viewDecFontSizes->addTo( popup ); |
125 | 125 | ||
126 | mb->insertItem(tr("View"),popup); | 126 | mb->insertItem(tr("View"),popup); |
127 | 127 | ||
128 | 128 | ||
129 | 129 | ||
130 | popup = new QPopupMenu( this ); | 130 | popup = new QPopupMenu( this ); |
131 | mb->insertItem(tr("Utils"),popup); | 131 | mb->insertItem(tr("Utils"),popup); |
132 | 132 | ||
133 | //Highlight management | 133 | //Highlight management |
134 | hlmenu=new QPopupMenu(this); | 134 | hlmenu=new QPopupMenu(this); |
135 | HlManager *hlm=HlManager::self(); | 135 | HlManager *hlm=HlManager::self(); |
136 | for (int i=0;i<hlm->highlights();i++) | 136 | for (int i=0;i<hlm->highlights();i++) |
137 | { | 137 | { |
138 | hlmenu->insertItem(hlm->hlName(i),i); | 138 | hlmenu->insertItem(hlm->hlName(i),i); |
139 | } | 139 | } |
140 | popup->insertItem(tr("Highlighting"),hlmenu); | 140 | popup->insertItem(tr("Highlighting"),hlmenu); |
141 | 141 | ||
142 | 142 | ||
143 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); | 143 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); |
144 | utilSettings->addTo( popup); | 144 | utilSettings->addTo( popup); |
145 | 145 | ||
146 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 146 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
147 | else slotNew(); | 147 | else slotNew(); |
148 | 148 | ||
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | void TinyKate::slotOpen( ) | 152 | void TinyKate::slotOpen( ) |
153 | { | 153 | { |
154 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL); | 154 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
155 | if (!filename.isEmpty()) { | 155 | QPEApplication::documentDir()); |
156 | if (!filename.isEmpty()) { | ||
156 | open(filename); | 157 | open(filename); |
157 | } | 158 | } |
158 | } | 159 | } |
159 | 160 | ||
160 | void TinyKate::open(const QString & filename) | 161 | void TinyKate::open(const QString & filename) |
161 | { | 162 | { |
162 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 163 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
163 | KTextEditor::View *kv; | 164 | KTextEditor::View *kv; |
164 | QFileInfo fi(filename); | 165 | QFileInfo fi(filename); |
165 | QString filenamed = fi.fileName(); | 166 | QString filenamed = fi.fileName(); |
166 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); | 167 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); |
167 | qDebug(filename); | 168 | qDebug(filename); |
168 | 169 | ||
169 | kd->setDocName( filenamed); | 170 | kd->setDocName( filenamed); |
170 | kd->open(filename); | 171 | kd->open( filename ); |
171 | viewCount++; | 172 | viewCount++; |
172 | } | 173 | } |
173 | 174 | ||
174 | void TinyKate::slotCurrentChanged( QWidget * view) | 175 | void TinyKate::slotCurrentChanged( QWidget * view) |
175 | { | 176 | { |
176 | if (currentView) { | 177 | if (currentView) { |
177 | 178 | ||
178 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 179 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
179 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 180 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
180 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 181 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
181 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 182 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
182 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 183 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
183 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 184 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
184 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 185 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
185 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 186 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
186 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 187 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
187 | } | 188 | } |
188 | 189 | ||
189 | currentView=(KTextEditor::View*)view; | 190 | currentView=(KTextEditor::View*)view; |
190 | 191 | ||
191 | connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 192 | connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
192 | connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 193 | connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
193 | connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 194 | connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
194 | connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 195 | connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
195 | connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 196 | connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
196 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 197 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
197 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 198 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
198 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 199 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
199 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 200 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
200 | 201 | ||
201 | } | 202 | } |
202 | 203 | ||
203 | void TinyKate::slotNew( ) | 204 | void TinyKate::slotNew( ) |
204 | { | 205 | { |
205 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 206 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
206 | KTextEditor::View *kv; | 207 | KTextEditor::View *kv; |
207 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), | 208 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), |
208 | "tinykate/tinykate", | 209 | "tinykate/tinykate", |
209 | tr("Unnamed %1").arg(nextUnnamed++)); | 210 | tr("Unnamed %1").arg(nextUnnamed++)); |
210 | viewCount++; | 211 | viewCount++; |
211 | } | 212 | } |
212 | 213 | ||
213 | void TinyKate::slotClose( ) | 214 | void TinyKate::slotClose( ) |
214 | { | 215 | { |
215 | if (currentView==0) return; | 216 | if (currentView==0) return; |
216 | KTextEditor::View *dv=currentView; | 217 | KTextEditor::View *dv=currentView; |
217 | currentView=0; | 218 | currentView=0; |
218 | tabwidget->removePage(dv); | 219 | tabwidget->removePage(dv); |
219 | delete dv->document(); | 220 | delete dv->document(); |
220 | viewCount--; | 221 | viewCount--; |
221 | if (!viewCount) slotNew(); | 222 | if (!viewCount) slotNew(); |
222 | } | 223 | } |
223 | 224 | ||
224 | void TinyKate::slotSave() { | 225 | void TinyKate::slotSave() { |
225 | // feel free to make this how you want | 226 | // feel free to make this how you want |
226 | if (currentView==0) return; | 227 | if (currentView==0) return; |
227 | 228 | ||
228 | // KateView *kv = (KateView*) currentView; | 229 | // KateView *kv = (KateView*) currentView; |
229 | KateDocument *kd = (KateDocument*) currentView->document(); | 230 | KateDocument *kd = (KateDocument*) currentView->document(); |
230 | // qDebug("saving file "+kd->docName()); | 231 | // qDebug("saving file "+kd->docName()); |
231 | if( kd->docName().isEmpty()) | 232 | if( kd->docName().isEmpty()) |
232 | slotSaveAs(); | 233 | slotSaveAs(); |
233 | else | 234 | else |
234 | kd->saveFile(); | 235 | kd->saveFile(); |
235 | // kv->save(); | 236 | // kv->save(); |
236 | // kd->saveFile(); | 237 | // kd->saveFile(); |
237 | } | 238 | } |
238 | 239 | ||
239 | void TinyKate::slotSaveAs() { | 240 | void TinyKate::slotSaveAs() { |
240 | if (currentView==0) return; | 241 | if (currentView==0) return; |
241 | KateDocument *kd = (KateDocument*) currentView->document(); | 242 | KateDocument *kd = (KateDocument*) currentView->document(); |
242 | 243 | ||
243 | QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL); | 244 | QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
245 | QPEApplication::documentDir()); | ||
244 | if (!filename.isEmpty()) { | 246 | if (!filename.isEmpty()) { |
245 | qDebug("saving file "+filename); | 247 | qDebug("saving file "+filename); |
246 | QFileInfo fi(filename); | 248 | QFileInfo fi(filename); |
247 | QString filenamed = fi.fileName(); | 249 | QString filenamed = fi.fileName(); |
248 | kd->setDocFile( filename); | 250 | kd->setDocFile( filename); |
249 | kd->setDocName( filenamed); | 251 | kd->setDocName( filenamed); |
250 | kd->saveFile(); | 252 | kd->saveFile(); |
251 | // KTextEditor::View *dv = currentView; | 253 | // KTextEditor::View *dv = currentView; |
252 | // tabwidget->changeTab( dv, filenamed); | 254 | // tabwidget->changeTab( dv, filenamed); |
253 | // need to change tab label here | 255 | // need to change tab label here |
254 | } | 256 | } |
255 | 257 | ||
256 | } | 258 | } |