author | llornkcor <llornkcor> | 2003-06-14 17:39:26 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-06-14 17:39:26 (UTC) |
commit | e2a1c237211e4009ce2b76d3adc3860fbb255732 (patch) (unidiff) | |
tree | 6d76151c961368c111f478fe58cb367424c6e2c6 /noncore/apps/tinykate/tinykate.cpp | |
parent | 437e389cc5cca518c5f26677f98c464f9255ec04 (diff) | |
download | opie-e2a1c237211e4009ce2b76d3adc3860fbb255732.zip opie-e2a1c237211e4009ce2b76d3adc3860fbb255732.tar.gz opie-e2a1c237211e4009ce2b76d3adc3860fbb255732.tar.bz2 |
changes by craig graham. please test to make sure nothing important was taken out.
Diffstat (limited to 'noncore/apps/tinykate/tinykate.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 157 |
1 files changed, 101 insertions, 56 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index ea7ea45..dda8405 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp | |||
@@ -8,7 +8,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 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 * |
@@ -17,14 +17,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 <qtoolbutton.h> | 20 | #include <qpe/qpetoolbar.h> |
21 | #include <qmenubar.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 "cgotoline.h" | ||
29 | |||
28 | #include "tinykate.h" | 30 | #include "tinykate.h" |
29 | 31 | ||
30 | #include <katedocument.h> | 32 | #include <katedocument.h> |
@@ -34,15 +36,21 @@ | |||
34 | 36 | ||
35 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 37 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
36 | QMainWindow( parent, name, f ) | 38 | QMainWindow( parent, name, f ) |
37 | { | 39 | { |
38 | nextUnnamed=0; | 40 | nextUnnamed=0; |
39 | currentView=0; | 41 | currentView=0; |
40 | viewCount=0; | 42 | viewCount=0; |
41 | setCaption(tr("TinyKATE")); | 43 | setCaption("TinyKATE : line 1 col 1"); |
42 | KGlobal::setAppName("TinyKATE"); | 44 | KGlobal::setAppName("TinyKATE"); |
43 | 45 | ||
44 | QMenuBar *mb = new QMenuBar( this ); | 46 | curLine=curCol=1; |
45 | mb->setMargin( 0 ); | 47 | |
48 | setToolBarsMovable(FALSE); | ||
49 | |||
50 | QPEToolBar *bar = new QPEToolBar( this ); | ||
51 | bar->setHorizontalStretchable( TRUE ); | ||
52 | QPEMenuBar *mb = new QPEMenuBar( bar ); | ||
53 | mb->setMargin( 0 ); | ||
46 | 54 | ||
47 | tabwidget=new OTabWidget(this); | 55 | tabwidget=new OTabWidget(this); |
48 | setCentralWidget(tabwidget); | 56 | setCentralWidget(tabwidget); |
@@ -52,88 +60,82 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
52 | QPopupMenu *popup = new QPopupMenu( this ); | 60 | QPopupMenu *popup = new QPopupMenu( this ); |
53 | 61 | ||
54 | // Action for creating a new document | 62 | // Action for creating a new document |
55 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 63 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, CTRL+Key_N, this, 0 ); |
56 | a->addTo( popup ); | 64 | a->addTo( popup ); |
57 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); | 65 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); |
58 | 66 | ||
59 | // Action for opening an exisiting document | 67 | // Action for opening an exisiting document |
60 | a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 ); | 68 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, CTRL+Key_O, this, 0 ); |
61 | a->addTo(popup); | 69 | a->addTo(popup); |
62 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); | 70 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); |
63 | 71 | ||
64 | 72 | ||
65 | // Action for saving document | 73 | // Action for saving document |
66 | a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); | 74 | a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ), QString::null, CTRL+Key_S, this, 0 ); |
67 | a->addTo(popup); | 75 | a->addTo(popup); |
68 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); | 76 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); |
69 | 77 | ||
70 | // Action for saving document to a new name | 78 | // Action for saving document to a new name |
71 | a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); | 79 | a = new QAction( tr( "Save As" ), Resource::loadPixmap( "save" ), QString::null, 0, this, 0 ); |
72 | a->addTo(popup); | 80 | a->addTo(popup); |
73 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); | 81 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); |
74 | 82 | ||
75 | // Action for closing the currently active document | 83 | // Action for closing the currently active document |
76 | a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 ); | 84 | a = new QAction( tr( "Close" ), Resource::loadPixmap( "close" ), QString::null, CTRL+Key_W, this, 0 ); |
77 | a->addTo(popup); | 85 | a->addTo(popup); |
78 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); | 86 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); |
79 | 87 | ||
80 | 88 | ||
81 | mb->insertItem(tr("File"),popup); | 89 | mb->insertItem(tr("File"),popup); |
82 | 90 | ||
83 | //EDIT ACTIONS | 91 | //EDIT ACTIONS |
84 | 92 | ||
85 | // Action for cutting text | 93 | // Action for cutting text |
86 | editCut = new QToolButton( 0 ); | 94 | editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, CTRL+Key_X, this, 0 ); |
87 | editCut->setAutoRaise( true ); | 95 | editCut->addTo( bar ); |
88 | editCut->setIconSet( Resource::loadPixmap( "cut" ) ); | ||
89 | 96 | ||
90 | // Action for Copying text | 97 | // Action for Copying text |
91 | editCopy = new QToolButton( 0 ); | 98 | editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, CTRL+Key_C, this, 0 ); |
92 | editCopy->setAutoRaise( true ); | 99 | editCopy->addTo( bar ); |
93 | editCopy->setIconSet( Resource::loadPixmap( "copy" ) ); | ||
94 | 100 | ||
95 | // Action for pasting text | 101 | // Action for pasting text |
96 | editPaste = new QToolButton( 0 ); | 102 | editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, CTRL+Key_V, this, 0 ); |
97 | editPaste->setAutoRaise( true ); | 103 | editPaste->addTo( bar ); |
98 | editPaste->setIconSet( Resource::loadPixmap( "paste" ) ); | 104 | |
99 | 105 | ||
100 | // Action for finding / replacing text | 106 | // Action for finding / replacing text |
101 | editFindReplace = new QToolButton( 0 ); | 107 | editFindReplace = new QAction( tr( "Replace" ), Resource::loadPixmap("find"), QString::null, CTRL+Key_R, this, 0 ); |
102 | editFindReplace->setAutoRaise( true ); | 108 | editFind = new QAction( tr( "Find" ), Resource::loadPixmap("find"), QString::null, CTRL+Key_F, this, 0 ); |
103 | editFindReplace->setIconSet( Resource::loadPixmap("find") ); | 109 | editFind->addTo( bar ); |
104 | 110 | ||
105 | // Action for undo | 111 | // Action for undo |
106 | editUndo = new QToolButton( 0 ); | 112 | editUndo = new QAction( tr( "Undo" ), Resource::loadPixmap( "undo" ), QString::null, CTRL+Key_Z, this, 0 ); |
107 | editUndo->setAutoRaise( true ); | 113 | editUndo->addTo( bar ); |
108 | editUndo->setIconSet( Resource::loadPixmap( "undo" ) ); | ||
109 | 114 | ||
110 | // Action for redo | 115 | // Action for redo |
111 | editRedo = new QToolButton( 0 ); | 116 | editRedo = new QAction( tr( "Redo" ), Resource::loadPixmap( "redo" ), QString::null, CTRL+SHIFT+Key_Z, this, 0 ); |
112 | editRedo->setAutoRaise( true ); | 117 | editRedo->addTo( bar ); |
113 | editRedo->setIconSet( Resource::loadPixmap( "redo" ) ); | 118 | |
114 | 119 | ||
115 | //VIEW ACITONS | 120 | //VIEW ACITONS |
116 | popup = new QPopupMenu( this ); | 121 | popup = new QPopupMenu( this ); |
117 | 122 | ||
123 | a = new QAction( tr( "Goto" ), QString::null, CTRL+Key_G, this, 0 ); | ||
124 | a->addTo( popup ); | ||
125 | connect(a, SIGNAL(activated()), this, SLOT(slotGoTo())); | ||
126 | |||
118 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); | 127 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); |
119 | viewIncFontSizes->addTo( popup ); | 128 | viewIncFontSizes->addTo( popup ); |
120 | 129 | ||
121 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); | 130 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); |
122 | viewDecFontSizes->addTo( popup ); | 131 | viewDecFontSizes->addTo( popup ); |
123 | 132 | ||
124 | mb->insertItem(tr("View"),popup); | 133 | mb->insertItem(tr("View"),popup); |
125 | |||
126 | popup = new QPopupMenu( this ); | ||
127 | mb->insertItem(tr("Utils"),popup); | ||
128 | 134 | ||
129 | 135 | ||
130 | mb->insertItem( editCut ); | ||
131 | mb->insertItem( editCopy ); | ||
132 | mb->insertItem( editPaste ); | ||
133 | mb->insertItem( editFindReplace ); | ||
134 | mb->insertItem( editUndo ); | ||
135 | mb->insertItem( editRedo ); | ||
136 | 136 | ||
137 | popup = new QPopupMenu( this ); | ||
138 | mb->insertItem(tr("Utils"),popup); | ||
137 | 139 | ||
138 | //Highlight management | 140 | //Highlight management |
139 | hlmenu=new QPopupMenu(this); | 141 | hlmenu=new QPopupMenu(this); |
@@ -148,6 +150,10 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
148 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); | 150 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); |
149 | utilSettings->addTo( popup); | 151 | utilSettings->addTo( popup); |
150 | 152 | ||
153 | popup->insertSeparator(); | ||
154 | editFind->addTo(popup); | ||
155 | editFindReplace->addTo(popup); | ||
156 | |||
151 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 157 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
152 | else slotNew(); | 158 | else slotNew(); |
153 | 159 | ||
@@ -156,7 +162,9 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
156 | TinyKate::~TinyKate( ) | 162 | TinyKate::~TinyKate( ) |
157 | { | 163 | { |
158 | qWarning("TinyKate destructor\n"); | 164 | qWarning("TinyKate destructor\n"); |
165 | printf("~TinyKate()\n"); | ||
159 | if( KGlobal::config() != 0 ) { | 166 | if( KGlobal::config() != 0 ) { |
167 | printf("~TinyKate(): delete configs...\n"); | ||
160 | qWarning("deleting KateConfig object..\n"); | 168 | qWarning("deleting KateConfig object..\n"); |
161 | delete KGlobal::config(); | 169 | delete KGlobal::config(); |
162 | } | 170 | } |
@@ -165,7 +173,7 @@ TinyKate::~TinyKate( ) | |||
165 | void TinyKate::slotOpen( ) | 173 | void TinyKate::slotOpen( ) |
166 | { | 174 | { |
167 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 175 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
168 | QPEApplication::documentDir()); | 176 | QString::null); |
169 | if (!filename.isEmpty()) { | 177 | if (!filename.isEmpty()) { |
170 | open(filename); | 178 | open(filename); |
171 | } | 179 | } |
@@ -185,9 +193,10 @@ void TinyKate::open(const QString & filename) | |||
185 | viewCount++; | 193 | viewCount++; |
186 | } | 194 | } |
187 | 195 | ||
188 | void TinyKate::setDocument(const QString& fileref) | 196 | void TinyKate::setDocument(const QString &doc) |
189 | { | 197 | { |
190 | open( fileref ); | 198 | printf("tinykate: setDocument(\"%s\")\n",(const char*)doc); |
199 | open(doc); | ||
191 | } | 200 | } |
192 | 201 | ||
193 | void TinyKate::slotCurrentChanged( QWidget * view) | 202 | void TinyKate::slotCurrentChanged( QWidget * view) |
@@ -199,24 +208,29 @@ void TinyKate::slotCurrentChanged( QWidget * view) | |||
199 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 208 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
200 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 209 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
201 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 210 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
202 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 211 | disconnect(editFindReplace,SIGNAL(activated()),currentView,SLOT(replace())); |
203 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 212 | disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find())); |
213 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | ||
214 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | ||
204 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 215 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
205 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 216 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
217 | disconnect(currentView,SIGNAL(newCurPos()),this,SLOT(slotCursorMoved())); | ||
206 | } | 218 | } |
207 | 219 | ||
208 | currentView=(KTextEditor::View*)view; | 220 | currentView=(KTextEditor::View*)view; |
209 | 221 | ||
210 | connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); | 222 | connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
211 | connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); | 223 | connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
212 | connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); | 224 | connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
213 | connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); | 225 | connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
214 | connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); | 226 | connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
227 | connect(editFindReplace,SIGNAL(activated()),currentView,SLOT(replace())); | ||
228 | connect(editFind,SIGNAL(activated()),currentView,SLOT(find())); | ||
215 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 229 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
216 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 230 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
217 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 231 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
218 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 232 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
219 | 233 | connect(currentView,SIGNAL(newCurPos()),this,SLOT(slotCursorMoved())); | |
220 | } | 234 | } |
221 | 235 | ||
222 | void TinyKate::slotNew( ) | 236 | void TinyKate::slotNew( ) |
@@ -260,7 +274,7 @@ void TinyKate::slotSaveAs() { | |||
260 | KateDocument *kd = (KateDocument*) currentView->document(); | 274 | KateDocument *kd = (KateDocument*) currentView->document(); |
261 | 275 | ||
262 | QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, | 276 | QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
263 | QPEApplication::documentDir()); | 277 | QString::null); |
264 | if (!filename.isEmpty()) { | 278 | if (!filename.isEmpty()) { |
265 | qDebug("saving file "+filename); | 279 | qDebug("saving file "+filename); |
266 | QFileInfo fi(filename); | 280 | QFileInfo fi(filename); |
@@ -274,3 +288,34 @@ void TinyKate::slotSaveAs() { | |||
274 | } | 288 | } |
275 | 289 | ||
276 | } | 290 | } |
291 | |||
292 | void TinyKate::slotGoTo() | ||
293 | { | ||
294 | int l,c; | ||
295 | if (currentView==0) return; | ||
296 | |||
297 | currentView->getCursorPosition(&l,&c); | ||
298 | |||
299 | CGotoLine g(l); | ||
300 | |||
301 | if(g.exec()==QDialog::Accepted) | ||
302 | { | ||
303 | currentView->setCursorPosition( g.line(), c ); | ||
304 | } | ||
305 | } | ||
306 | |||
307 | void TinyKate::slotCursorMoved() | ||
308 | { | ||
309 | char buf[100]; | ||
310 | int newLine,newCol; | ||
311 | currentView->getCursorPosition(&newLine,&newCol); | ||
312 | newLine++; | ||
313 | newCol++; | ||
314 | if((newLine!=curLine)||(newCol!=curCol)) | ||
315 | { | ||
316 | sprintf(buf,"TinyKATE : line %-6d col %d",newLine,newCol); | ||
317 | setCaption(buf); | ||
318 | curLine=newLine; | ||
319 | curCol=newCol; | ||
320 | } | ||
321 | } | ||