author | llornkcor <llornkcor> | 2005-08-04 07:14:03 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-08-04 07:14:03 (UTC) |
commit | 32743ebb00d374ad18afbed69ab3e94b03699a57 (patch) (unidiff) | |
tree | ef73f41d2a76c15f0c31f0bcdec9fbf63ba5743f | |
parent | 30a5df87b42e35c48932a2041944e59021568f38 (diff) | |
download | opie-32743ebb00d374ad18afbed69ab3e94b03699a57.zip opie-32743ebb00d374ad18afbed69ab3e94b03699a57.tar.gz opie-32743ebb00d374ad18afbed69ab3e94b03699a57.tar.bz2 |
fix # 0001687: opening desktop file
-rw-r--r-- | noncore/apps/tinykate/mainwindow/tinykate.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.cpp b/noncore/apps/tinykate/mainwindow/tinykate.cpp index bbb0be7e..e808a2e 100644 --- a/noncore/apps/tinykate/mainwindow/tinykate.cpp +++ b/noncore/apps/tinykate/mainwindow/tinykate.cpp | |||
@@ -78,248 +78,249 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
78 | QString::null, 0, this, 0 ); | 78 | 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" ), Opie::Core::OResource::loadPixmap( "quit_icon", Opie::Core::OResource::SmallIcon ), | 83 | a = new QAction( tr( "Close" ), Opie::Core::OResource::loadPixmap( "quit_icon", Opie::Core::OResource::SmallIcon ), |
84 | QString::null, 0, this, 0 ); | 84 | QString::null, 0, this, 0 ); |
85 | a->addTo(popup); | 85 | a->addTo(popup); |
86 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); | 86 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); |
87 | 87 | ||
88 | 88 | ||
89 | mb->insertItem(tr("File"),popup); | 89 | mb->insertItem(tr("File"),popup); |
90 | 90 | ||
91 | //EDIT ACTIONS | 91 | //EDIT ACTIONS |
92 | bool useBigIcon = qApp->desktop()->size().width() > 330; | 92 | bool useBigIcon = qApp->desktop()->size().width() > 330; |
93 | 93 | ||
94 | // Action for cutting text | 94 | // Action for cutting text |
95 | editCut = new QToolButton( 0 ); | 95 | editCut = new QToolButton( 0 ); |
96 | editCut->setUsesBigPixmap( useBigIcon ); | 96 | editCut->setUsesBigPixmap( useBigIcon ); |
97 | editCut->setAutoRaise( true ); | 97 | editCut->setAutoRaise( true ); |
98 | editCut->setIconSet( Opie::Core::OResource::loadPixmap( "cut", Opie::Core::OResource::SmallIcon ) ); | 98 | editCut->setIconSet( Opie::Core::OResource::loadPixmap( "cut", Opie::Core::OResource::SmallIcon ) ); |
99 | 99 | ||
100 | // Action for Copying text | 100 | // Action for Copying text |
101 | editCopy = new QToolButton( 0 ); | 101 | editCopy = new QToolButton( 0 ); |
102 | editCopy->setUsesBigPixmap( useBigIcon ); | 102 | editCopy->setUsesBigPixmap( useBigIcon ); |
103 | editCopy->setAutoRaise( true ); | 103 | editCopy->setAutoRaise( true ); |
104 | editCopy->setIconSet( Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ) ); | 104 | editCopy->setIconSet( Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ) ); |
105 | 105 | ||
106 | // Action for pasting text | 106 | // Action for pasting text |
107 | editPaste = new QToolButton( 0 ); | 107 | editPaste = new QToolButton( 0 ); |
108 | editPaste->setUsesBigPixmap( useBigIcon ); | 108 | editPaste->setUsesBigPixmap( useBigIcon ); |
109 | editPaste->setAutoRaise( true ); | 109 | editPaste->setAutoRaise( true ); |
110 | editPaste->setIconSet( Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ) ); | 110 | editPaste->setIconSet( Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ) ); |
111 | 111 | ||
112 | // Action for finding / replacing text | 112 | // Action for finding / replacing text |
113 | editFindReplace = new QToolButton( 0 ); | 113 | editFindReplace = new QToolButton( 0 ); |
114 | editFindReplace->setUsesBigPixmap( useBigIcon ); | 114 | editFindReplace->setUsesBigPixmap( useBigIcon ); |
115 | editFindReplace->setAutoRaise( true ); | 115 | editFindReplace->setAutoRaise( true ); |
116 | editFindReplace->setIconSet( Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ) ); | 116 | editFindReplace->setIconSet( Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ) ); |
117 | 117 | ||
118 | // Action for undo | 118 | // Action for undo |
119 | editUndo = new QToolButton( 0 ); | 119 | editUndo = new QToolButton( 0 ); |
120 | editUndo->setUsesBigPixmap( useBigIcon ); | 120 | editUndo->setUsesBigPixmap( useBigIcon ); |
121 | editUndo->setAutoRaise( true ); | 121 | editUndo->setAutoRaise( true ); |
122 | editUndo->setIconSet( Opie::Core::OResource::loadPixmap( "undo", Opie::Core::OResource::SmallIcon ) ); | 122 | editUndo->setIconSet( Opie::Core::OResource::loadPixmap( "undo", Opie::Core::OResource::SmallIcon ) ); |
123 | 123 | ||
124 | // Action for redo | 124 | // Action for redo |
125 | editRedo = new QToolButton( 0 ); | 125 | editRedo = new QToolButton( 0 ); |
126 | editRedo->setUsesBigPixmap( useBigIcon ); | 126 | editRedo->setUsesBigPixmap( useBigIcon ); |
127 | editRedo->setAutoRaise( true ); | 127 | editRedo->setAutoRaise( true ); |
128 | editRedo->setIconSet( Opie::Core::OResource::loadPixmap( "redo", Opie::Core::OResource::SmallIcon ) ); | 128 | editRedo->setIconSet( Opie::Core::OResource::loadPixmap( "redo", Opie::Core::OResource::SmallIcon ) ); |
129 | 129 | ||
130 | //VIEW ACITONS | 130 | //VIEW ACITONS |
131 | popup = new QPopupMenu( this ); | 131 | popup = new QPopupMenu( this ); |
132 | 132 | ||
133 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); | 133 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); |
134 | viewIncFontSizes->addTo( popup ); | 134 | viewIncFontSizes->addTo( popup ); |
135 | 135 | ||
136 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); | 136 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); |
137 | viewDecFontSizes->addTo( popup ); | 137 | viewDecFontSizes->addTo( popup ); |
138 | 138 | ||
139 | mb->insertItem(tr("View"),popup); | 139 | mb->insertItem(tr("View"),popup); |
140 | 140 | ||
141 | popup = new QPopupMenu( this ); | 141 | popup = new QPopupMenu( this ); |
142 | mb->insertItem(tr("Utils"),popup); | 142 | mb->insertItem(tr("Utils"),popup); |
143 | 143 | ||
144 | 144 | ||
145 | mb->insertItem( editCut ); | 145 | mb->insertItem( editCut ); |
146 | mb->insertItem( editCopy ); | 146 | mb->insertItem( editCopy ); |
147 | mb->insertItem( editPaste ); | 147 | mb->insertItem( editPaste ); |
148 | mb->insertItem( editFindReplace ); | 148 | mb->insertItem( editFindReplace ); |
149 | mb->insertItem( editUndo ); | 149 | mb->insertItem( editUndo ); |
150 | mb->insertItem( editRedo ); | 150 | mb->insertItem( editRedo ); |
151 | 151 | ||
152 | 152 | ||
153 | //Highlight management | 153 | //Highlight management |
154 | hlmenu=new QPopupMenu(this); | 154 | hlmenu=new QPopupMenu(this); |
155 | HlManager *hlm=HlManager::self(); | 155 | HlManager *hlm=HlManager::self(); |
156 | for (int i=0;i<hlm->highlights();i++) | 156 | for (int i=0;i<hlm->highlights();i++) |
157 | { | 157 | { |
158 | hlmenu->insertItem(hlm->hlName(i),i); | 158 | hlmenu->insertItem(hlm->hlName(i),i); |
159 | } | 159 | } |
160 | popup->insertItem(tr("Highlighting"),hlmenu); | 160 | popup->insertItem(tr("Highlighting"),hlmenu); |
161 | 161 | ||
162 | 162 | ||
163 | utilSettings = new QAction( tr( "Settings" ), | 163 | utilSettings = new QAction( tr( "Settings" ), |
164 | Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), | 164 | Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), |
165 | QString::null, 0, this, 0 ); | 165 | QString::null, 0, this, 0 ); |
166 | utilSettings->addTo( popup); | 166 | utilSettings->addTo( popup); |
167 | 167 | ||
168 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 168 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
169 | else slotNew(); | 169 | else slotNew(); |
170 | 170 | ||
171 | } | 171 | } |
172 | 172 | ||
173 | TinyKate::~TinyKate( ) | 173 | TinyKate::~TinyKate( ) |
174 | { | 174 | { |
175 | owarn << "TinyKate destructor\n" << oendl; | 175 | owarn << "TinyKate destructor\n" << oendl; |
176 | 176 | ||
177 | shutDown=true; | 177 | shutDown=true; |
178 | while (currentView!=0) | 178 | while (currentView!=0) |
179 | { | 179 | { |
180 | slotClose(); | 180 | slotClose(); |
181 | } | 181 | } |
182 | 182 | ||
183 | if( KGlobal::config() != 0 ) | 183 | if( KGlobal::config() != 0 ) |
184 | { | 184 | { |
185 | owarn << "deleting KateConfig object..\n" << oendl; | 185 | owarn << "deleting KateConfig object..\n" << oendl; |
186 | delete KGlobal::config(); | 186 | delete KGlobal::config(); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | void TinyKate::slotOpen( ) | 190 | void TinyKate::slotOpen( ) |
191 | { | 191 | { |
192 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 192 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
193 | QString::null); | 193 | QString::null); |
194 | if (!filename.isEmpty()) | 194 | if (!filename.isEmpty()) |
195 | { | 195 | { |
196 | open(filename); | 196 | open(filename); |
197 | } | 197 | } |
198 | } | 198 | } |
199 | 199 | ||
200 | void TinyKate::open(const QString & filename) | 200 | void TinyKate::open(const QString & filename) |
201 | { | 201 | { |
202 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 202 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
203 | KTextEditor::View *kv; | 203 | KTextEditor::View *kv; |
204 | QString realFileName; | 204 | QString realFileName; |
205 | //check if filename is a .desktop file | 205 | //check if filename is a .desktop file |
206 | if ( filename.find( ".desktop", 0, true ) ) | 206 | if ( filename.find( ".desktop", 0, true ) != -1 ) { |
207 | { | ||
208 | switch ( QMessageBox::warning( this, tr( "TinyKATE" ), | 207 | switch ( QMessageBox::warning( this, tr( "TinyKATE" ), |
209 | tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ), | 208 | tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ), |
210 | tr(".desktop File"), | 209 | tr(".desktop File"), |
211 | tr("Linked Document"), 0, 1, 1 ) ) | 210 | tr("Linked Document"), 0, 1, 1 ) ) |
212 | { | 211 | { |
213 | case 0: //desktop | 212 | case 0: //desktop |
214 | realFileName = filename; | 213 | realFileName = filename; |
215 | break; | 214 | break; |
216 | case 1: //linked | 215 | case 1: //linked |
217 | DocLnk docLnk( filename ); | 216 | DocLnk docLnk( filename ); |
218 | realFileName = docLnk.file(); | 217 | realFileName = docLnk.file(); |
219 | break; | 218 | break; |
220 | }; | 219 | }; |
220 | } else { | ||
221 | realFileName = filename; | ||
221 | } | 222 | } |
222 | 223 | ||
223 | QFileInfo fileInfo( realFileName ); | 224 | QFileInfo fileInfo( realFileName ); |
224 | QString filenamed = fileInfo.fileName(); | 225 | QString filenamed = fileInfo.fileName(); |
225 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); | 226 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); |
226 | odebug << realFileName << oendl; | 227 | odebug << realFileName << oendl; |
227 | 228 | ||
228 | kd->setDocName( filenamed); | 229 | kd->setDocName( filenamed); |
229 | kd->open( realFileName ); | 230 | kd->open( realFileName ); |
230 | viewCount++; | 231 | viewCount++; |
231 | } | 232 | } |
232 | 233 | ||
233 | void TinyKate::setDocument(const QString& fileref) | 234 | void TinyKate::setDocument(const QString& fileref) |
234 | { | 235 | { |
235 | open( fileref ); | 236 | open( fileref ); |
236 | } | 237 | } |
237 | 238 | ||
238 | void TinyKate::slotCurrentChanged( QWidget * view) | 239 | void TinyKate::slotCurrentChanged( QWidget * view) |
239 | { | 240 | { |
240 | if (currentView) | 241 | if (currentView) |
241 | { | 242 | { |
242 | 243 | ||
243 | disconnect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); | 244 | disconnect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); |
244 | disconnect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); | 245 | disconnect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); |
245 | disconnect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); | 246 | disconnect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); |
246 | disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); | 247 | disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); |
247 | disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); | 248 | disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); |
248 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 249 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
249 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 250 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
250 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 251 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
251 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 252 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
252 | } | 253 | } |
253 | 254 | ||
254 | currentView=(KTextEditor::View*)view; | 255 | currentView=(KTextEditor::View*)view; |
255 | 256 | ||
256 | connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); | 257 | connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); |
257 | connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); | 258 | connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); |
258 | connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); | 259 | connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); |
259 | connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); | 260 | connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); |
260 | connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); | 261 | connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); |
261 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 262 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
262 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 263 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
263 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 264 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
264 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 265 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
265 | 266 | ||
266 | } | 267 | } |
267 | 268 | ||
268 | void TinyKate::slotNew( ) | 269 | void TinyKate::slotNew( ) |
269 | { | 270 | { |
270 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 271 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
271 | KTextEditor::View *kv; | 272 | KTextEditor::View *kv; |
272 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), | 273 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), |
273 | "tinykate/tinykate", | 274 | "tinykate/tinykate", |
274 | tr("Unnamed %1").arg(nextUnnamed++)); | 275 | tr("Unnamed %1").arg(nextUnnamed++)); |
275 | viewCount++; | 276 | viewCount++; |
276 | } | 277 | } |
277 | 278 | ||
278 | void TinyKate::slotClose( ) | 279 | void TinyKate::slotClose( ) |
279 | { | 280 | { |
280 | if (currentView==0) return; | 281 | if (currentView==0) return; |
281 | KTextEditor::View *dv=currentView; | 282 | KTextEditor::View *dv=currentView; |
282 | currentView=0; | 283 | currentView=0; |
283 | tabwidget->removePage(dv); | 284 | tabwidget->removePage(dv); |
284 | delete dv->document(); | 285 | delete dv->document(); |
285 | viewCount--; | 286 | viewCount--; |
286 | if ((!viewCount) && (!shutDown)) slotNew(); | 287 | if ((!viewCount) && (!shutDown)) slotNew(); |
287 | } | 288 | } |
288 | 289 | ||
289 | void TinyKate::slotSave() | 290 | void TinyKate::slotSave() |
290 | { | 291 | { |
291 | // feel free to make this how you want | 292 | // feel free to make this how you want |
292 | if (currentView==0) return; | 293 | if (currentView==0) return; |
293 | 294 | ||
294 | // KateView *kv = (KateView*) currentView; | 295 | // KateView *kv = (KateView*) currentView; |
295 | KateDocument *kd = (KateDocument*) currentView->document(); | 296 | KateDocument *kd = (KateDocument*) currentView->document(); |
296 | // odebug << "saving file "+kd->docName() << oendl; | 297 | // odebug << "saving file "+kd->docName() << oendl; |
297 | if( kd->docName().isEmpty()) | 298 | if( kd->docName().isEmpty()) |
298 | slotSaveAs(); | 299 | slotSaveAs(); |
299 | else | 300 | else |
300 | kd->saveFile(); | 301 | kd->saveFile(); |
301 | // kv->save(); | 302 | // kv->save(); |
302 | // kd->saveFile(); | 303 | // kd->saveFile(); |
303 | } | 304 | } |
304 | 305 | ||
305 | void TinyKate::slotSaveAs() | 306 | void TinyKate::slotSaveAs() |
306 | { | 307 | { |
307 | if (currentView==0) return; | 308 | if (currentView==0) return; |
308 | KateDocument *kd = (KateDocument*) currentView->document(); | 309 | KateDocument *kd = (KateDocument*) currentView->document(); |
309 | 310 | ||
310 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, | 311 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
311 | QString::null); | 312 | QString::null); |
312 | if (!filename.isEmpty()) | 313 | if (!filename.isEmpty()) |
313 | { | 314 | { |
314 | odebug << "saving file "+filename << oendl; | 315 | odebug << "saving file "+filename << oendl; |
315 | QFileInfo fi(filename); | 316 | QFileInfo fi(filename); |
316 | QString filenamed = fi.fileName(); | 317 | QString filenamed = fi.fileName(); |
317 | kd->setDocFile( filename); | 318 | kd->setDocFile( filename); |
318 | kd->setDocName( filenamed); | 319 | kd->setDocName( filenamed); |
319 | kd->saveFile(); | 320 | kd->saveFile(); |
320 | // KTextEditor::View *dv = currentView; | 321 | // KTextEditor::View *dv = currentView; |
321 | // tabwidget->changeTab( dv, filenamed); | 322 | // tabwidget->changeTab( dv, filenamed); |
322 | // need to change tab label here | 323 | // need to change tab label here |
323 | } | 324 | } |
324 | 325 | ||
325 | } | 326 | } |