summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/mainwindow/tinykate.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.cpp b/noncore/apps/tinykate/mainwindow/tinykate.cpp
index 30c07fc..8d19c71 100644
--- a/noncore/apps/tinykate/mainwindow/tinykate.cpp
+++ b/noncore/apps/tinykate/mainwindow/tinykate.cpp
@@ -1,311 +1,311 @@
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 softwaSre; you can redistribute it and/or modify * 11 * This program is free softwaSre; 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#include "tinykate.h" 18#include "tinykate.h"
19 19
20#include "katedocument.h" 20#include "katedocument.h"
21#include "kglobal.h" 21#include "kglobal.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25#include <opie2/ofiledialog.h> 25#include <opie2/ofiledialog.h>
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28 28
29/* QT */ 29/* QT */
30#include <qaction.h> 30#include <qaction.h>
31#include <qtoolbutton.h> 31#include <qtoolbutton.h>
32#include <qmenubar.h> 32#include <qmenubar.h>
33#include <qmessagebox.h> 33#include <qmessagebox.h>
34 34
35 35
36using namespace Opie::Ui; 36using namespace Opie::Ui;
37TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : 37TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
38 QMainWindow( parent, name, f ) 38 QMainWindow( parent, name, f )
39{ 39{
40 shutDown=false; 40 shutDown=false;
41 nextUnnamed=0; 41 nextUnnamed=0;
42 currentView=0; 42 currentView=0;
43 viewCount=0; 43 viewCount=0;
44 setCaption(tr("TinyKATE")); 44 setCaption(tr("TinyKATE"));
45 KGlobal::setAppName("TinyKATE"); 45 KGlobal::setAppName("TinyKATE");
46 46
47 QMenuBar *mb = new QMenuBar( this ); 47 QMenuBar *mb = new QMenuBar( this );
48 mb->setMargin( 0 ); 48 mb->setMargin( 0 );
49 49
50 tabwidget=new OTabWidget(this); 50 tabwidget=new OTabWidget(this);
51 setCentralWidget(tabwidget); 51 setCentralWidget(tabwidget);
52 connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*))); 52 connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*)));
53 53
54 //FILE ACTIONS 54 //FILE ACTIONS
55 QPopupMenu *popup = new QPopupMenu( this ); 55 QPopupMenu *popup = new QPopupMenu( this );
56 56
57 // Action for creating a new document 57 // Action for creating a new document
58 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 58 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
59 a->addTo( popup ); 59 a->addTo( popup );
60 connect(a, SIGNAL(activated()), this, SLOT(slotNew())); 60 connect(a, SIGNAL(activated()), this, SLOT(slotNew()));
61 61
62 // Action for opening an exisiting document 62 // Action for opening an exisiting document
63 a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 ); 63 a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 );
64 a->addTo(popup); 64 a->addTo(popup);
65 connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); 65 connect(a, SIGNAL(activated()), this, SLOT(slotOpen()));
66 66
67 67
68 // Action for saving document 68 // Action for saving document
69 a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); 69 a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 );
70 a->addTo(popup); 70 a->addTo(popup);
71 connect(a, SIGNAL(activated()), this, SLOT(slotSave())); 71 connect(a, SIGNAL(activated()), this, SLOT(slotSave()));
72 72
73 // Action for saving document to a new name 73 // Action for saving document to a new name
74 a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); 74 a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 );
75 a->addTo(popup); 75 a->addTo(popup);
76 connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); 76 connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs()));
77 77
78 // Action for closing the currently active document 78 // Action for closing the currently active document
79 a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 ); 79 a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 );
80 a->addTo(popup); 80 a->addTo(popup);
81 connect(a, SIGNAL(activated()), this, SLOT(slotClose())); 81 connect(a, SIGNAL(activated()), this, SLOT(slotClose()));
82 82
83 83
84 mb->insertItem(tr("File"),popup); 84 mb->insertItem(tr("File"),popup);
85 85
86 //EDIT ACTIONS 86 //EDIT ACTIONS
87 87
88 // Action for cutting text 88 // Action for cutting text
89 editCut = new QToolButton( 0 ); 89 editCut = new QToolButton( 0 );
90 editCut->setAutoRaise( true ); 90 editCut->setAutoRaise( true );
91 editCut->setIconSet( Resource::loadPixmap( "cut" ) ); 91 editCut->setIconSet( Resource::loadPixmap( "cut" ) );
92 92
93 // Action for Copying text 93 // Action for Copying text
94 editCopy = new QToolButton( 0 ); 94 editCopy = new QToolButton( 0 );
95 editCopy->setAutoRaise( true ); 95 editCopy->setAutoRaise( true );
96 editCopy->setIconSet( Resource::loadPixmap( "copy" ) ); 96 editCopy->setIconSet( Resource::loadPixmap( "copy" ) );
97 97
98 // Action for pasting text 98 // Action for pasting text
99 editPaste = new QToolButton( 0 ); 99 editPaste = new QToolButton( 0 );
100 editPaste->setAutoRaise( true ); 100 editPaste->setAutoRaise( true );
101 editPaste->setIconSet( Resource::loadPixmap( "paste" ) ); 101 editPaste->setIconSet( Resource::loadPixmap( "paste" ) );
102 102
103 // Action for finding / replacing text 103 // Action for finding / replacing text
104 editFindReplace = new QToolButton( 0 ); 104 editFindReplace = new QToolButton( 0 );
105 editFindReplace->setAutoRaise( true ); 105 editFindReplace->setAutoRaise( true );
106 editFindReplace->setIconSet( Resource::loadPixmap("find") ); 106 editFindReplace->setIconSet( Resource::loadPixmap("find") );
107 107
108 // Action for undo 108 // Action for undo
109 editUndo = new QToolButton( 0 ); 109 editUndo = new QToolButton( 0 );
110 editUndo->setAutoRaise( true ); 110 editUndo->setAutoRaise( true );
111 editUndo->setIconSet( Resource::loadPixmap( "undo" ) ); 111 editUndo->setIconSet( Resource::loadPixmap( "undo" ) );
112 112
113 // Action for redo 113 // Action for redo
114 editRedo = new QToolButton( 0 ); 114 editRedo = new QToolButton( 0 );
115 editRedo->setAutoRaise( true ); 115 editRedo->setAutoRaise( true );
116 editRedo->setIconSet( Resource::loadPixmap( "redo" ) ); 116 editRedo->setIconSet( Resource::loadPixmap( "redo" ) );
117 117
118 //VIEW ACITONS 118 //VIEW ACITONS
119 popup = new QPopupMenu( this ); 119 popup = new QPopupMenu( this );
120 120
121 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); 121 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 );
122 viewIncFontSizes->addTo( popup ); 122 viewIncFontSizes->addTo( popup );
123 123
124 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); 124 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 );
125 viewDecFontSizes->addTo( popup ); 125 viewDecFontSizes->addTo( popup );
126 126
127 mb->insertItem(tr("View"),popup); 127 mb->insertItem(tr("View"),popup);
128 128
129 popup = new QPopupMenu( this ); 129 popup = new QPopupMenu( this );
130 mb->insertItem(tr("Utils"),popup); 130 mb->insertItem(tr("Utils"),popup);
131 131
132 132
133 mb->insertItem( editCut ); 133 mb->insertItem( editCut );
134 mb->insertItem( editCopy ); 134 mb->insertItem( editCopy );
135 mb->insertItem( editPaste ); 135 mb->insertItem( editPaste );
136 mb->insertItem( editFindReplace ); 136 mb->insertItem( editFindReplace );
137 mb->insertItem( editUndo ); 137 mb->insertItem( editUndo );
138 mb->insertItem( editRedo ); 138 mb->insertItem( editRedo );
139 139
140 140
141 //Highlight management 141 //Highlight management
142 hlmenu=new QPopupMenu(this); 142 hlmenu=new QPopupMenu(this);
143 HlManager *hlm=HlManager::self(); 143 HlManager *hlm=HlManager::self();
144 for (int i=0;i<hlm->highlights();i++) 144 for (int i=0;i<hlm->highlights();i++)
145 { 145 {
146 hlmenu->insertItem(hlm->hlName(i),i); 146 hlmenu->insertItem(hlm->hlName(i),i);
147 } 147 }
148 popup->insertItem(tr("Highlighting"),hlmenu); 148 popup->insertItem(tr("Highlighting"),hlmenu);
149 149
150 150
151 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); 151 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 );
152 utilSettings->addTo( popup); 152 utilSettings->addTo( popup);
153 153
154 if( qApp->argc() > 1) open(qApp->argv()[1]); 154 if( qApp->argc() > 1) open(qApp->argv()[1]);
155 else slotNew(); 155 else slotNew();
156 156
157} 157}
158 158
159TinyKate::~TinyKate( ) 159TinyKate::~TinyKate( )
160{ 160{
161 owarn << "TinyKate destructor\n" << oendl; 161 owarn << "TinyKate destructor\n" << oendl;
162 162
163 shutDown=true; 163 shutDown=true;
164 while (currentView!=0) 164 while (currentView!=0)
165 { 165 {
166 slotClose(); 166 slotClose();
167 } 167 }
168 168
169 if( KGlobal::config() != 0 ) 169 if( KGlobal::config() != 0 )
170 { 170 {
171 owarn << "deleting KateConfig object..\n" << oendl; 171 owarn << "deleting KateConfig object..\n" << oendl;
172 delete KGlobal::config(); 172 delete KGlobal::config();
173 } 173 }
174} 174}
175 175
176void TinyKate::slotOpen( ) 176void TinyKate::slotOpen( )
177{ 177{
178 QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 178 QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
179 QString::null); 179 QString::null);
180 if (!filename.isEmpty()) 180 if (!filename.isEmpty())
181 { 181 {
182 open(filename); 182 open(filename);
183 } 183 }
184} 184}
185 185
186void TinyKate::open(const QString & filename) 186void TinyKate::open(const QString & filename)
187{ 187{
188 KateDocument *kd= new KateDocument(false, false, this,0,this); 188 KateDocument *kd= new KateDocument(false, false, this,0,this);
189 KTextEditor::View *kv; 189 KTextEditor::View *kv;
190 QString realFileName; 190 QString realFileName;
191 //check if filename is a .desktop file 191 //check if filename is a .desktop file
192 if ( filename.find( ".desktop", 0, true ) ) 192 if ( filename.find( ".desktop", 0, true ) )
193 { 193 {
194 switch ( QMessageBox::warning( this, tr( "TinyKATE" ), 194 switch ( QMessageBox::warning( this, tr( "TinyKATE" ),
195 tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ), 195 tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ),
196 tr(".desktop File"), 196 tr(".desktop File"),
197 tr("Linked Document"), 0, 1, 1 ) ) 197 tr("Linked Document"), 0, 1, 1 ) )
198 { 198 {
199 case 0: //desktop 199 case 0: //desktop
200 realFileName = filename; 200 realFileName = filename;
201 break; 201 break;
202 case 1: //linked 202 case 1: //linked
203 DocLnk docLnk( filename ); 203 DocLnk docLnk( filename );
204 realFileName = docLnk.file(); 204 realFileName = docLnk.file();
205 break; 205 break;
206 }; 206 };
207 } 207 }
208 208
209 QFileInfo fileInfo( realFileName ); 209 QFileInfo fileInfo( realFileName );
210 QString filenamed = fileInfo.fileName(); 210 QString filenamed = fileInfo.fileName();
211 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); 211 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed );
212 odebug << realFileName << oendl; 212 odebug << realFileName << oendl;
213 213
214 kd->setDocName( filenamed); 214 kd->setDocName( filenamed);
215 kd->open( realFileName ); 215 kd->open( realFileName );
216 viewCount++; 216 viewCount++;
217} 217}
218 218
219void TinyKate::setDocument(const QString& fileref) 219void TinyKate::setDocument(const QString& fileref)
220{ 220{
221 open( fileref ); 221 open( fileref );
222} 222}
223 223
224void TinyKate::slotCurrentChanged( QWidget * view) 224void TinyKate::slotCurrentChanged( QWidget * view)
225{ 225{
226 if (currentView) 226 if (currentView)
227 { 227 {
228 228
229 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); 229 disconnect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy()));
230 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); 230 disconnect(editCut,SIGNAL(clicked()),currentView,SLOT(cut()));
231 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); 231 disconnect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste()));
232 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); 232 disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo()));
233 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); 233 disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo()));
234 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 234 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
235 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 235 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
236 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 236 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
237 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 237 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
238 } 238 }
239 239
240 currentView=(KTextEditor::View*)view; 240 currentView=(KTextEditor::View*)view;
241 241
242 connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); 242 connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy()));
243 connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); 243 connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut()));
244 connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); 244 connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste()));
245 connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); 245 connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo()));
246 connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); 246 connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo()));
247 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 247 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
248 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 248 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
249 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 249 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
250 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 250 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
251 251
252} 252}
253 253
254void TinyKate::slotNew( ) 254void TinyKate::slotNew( )
255{ 255{
256 KateDocument *kd= new KateDocument(false, false, this,0,this); 256 KateDocument *kd= new KateDocument(false, false, this,0,this);
257 KTextEditor::View *kv; 257 KTextEditor::View *kv;
258 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), 258 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),
259 "tinykate/tinykate", 259 "tinykate/tinykate",
260 tr("Unnamed %1").arg(nextUnnamed++)); 260 tr("Unnamed %1").arg(nextUnnamed++));
261 viewCount++; 261 viewCount++;
262} 262}
263 263
264void TinyKate::slotClose( ) 264void TinyKate::slotClose( )
265{ 265{
266 if (currentView==0) return; 266 if (currentView==0) return;
267 KTextEditor::View *dv=currentView; 267 KTextEditor::View *dv=currentView;
268 currentView=0; 268 currentView=0;
269 tabwidget->removePage(dv); 269 tabwidget->removePage(dv);
270 delete dv->document(); 270 delete dv->document();
271 viewCount--; 271 viewCount--;
272 if ((!viewCount) && (!shutDown)) slotNew(); 272 if ((!viewCount) && (!shutDown)) slotNew();
273} 273}
274 274
275void TinyKate::slotSave() 275void TinyKate::slotSave()
276{ 276{
277 // feel free to make this how you want 277 // feel free to make this how you want
278 if (currentView==0) return; 278 if (currentView==0) return;
279 279
280 // KateView *kv = (KateView*) currentView; 280 // KateView *kv = (KateView*) currentView;
281 KateDocument *kd = (KateDocument*) currentView->document(); 281 KateDocument *kd = (KateDocument*) currentView->document();
282 // odebug << "saving file "+kd->docName() << oendl; 282 // odebug << "saving file "+kd->docName() << oendl;
283 if( kd->docName().isEmpty()) 283 if( kd->docName().isEmpty())
284 slotSaveAs(); 284 slotSaveAs();
285 else 285 else
286 kd->saveFile(); 286 kd->saveFile();
287 // kv->save(); 287 // kv->save();
288 // kd->saveFile(); 288 // kd->saveFile();
289} 289}
290 290
291void TinyKate::slotSaveAs() 291void TinyKate::slotSaveAs()
292{ 292{
293 if (currentView==0) return; 293 if (currentView==0) return;
294 KateDocument *kd = (KateDocument*) currentView->document(); 294 KateDocument *kd = (KateDocument*) currentView->document();
295 295
296 QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, 296 QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL,
297 QString::null); 297 QString::null);
298 if (!filename.isEmpty()) 298 if (!filename.isEmpty())
299 { 299 {
300 odebug << "saving file "+filename << oendl; 300 odebug << "saving file "+filename << oendl;
301 QFileInfo fi(filename); 301 QFileInfo fi(filename);
302 QString filenamed = fi.fileName(); 302 QString filenamed = fi.fileName();
303 kd->setDocFile( filename); 303 kd->setDocFile( filename);
304 kd->setDocName( filenamed); 304 kd->setDocName( filenamed);
305 kd->saveFile(); 305 kd->saveFile();
306 // KTextEditor::View *dv = currentView; 306 // KTextEditor::View *dv = currentView;
307 // tabwidget->changeTab( dv, filenamed); 307 // tabwidget->changeTab( dv, filenamed);
308 // need to change tab label here 308 // need to change tab label here
309 } 309 }
310 310
311} 311}