src/gui_actions.cpp

changeset 522
afa691788bdb
parent 504
6a1fa662bfc1
child 530
f9476dbd87ec
equal deleted inserted replaced
521:b85554206155 522:afa691788bdb
229 } 229 }
230 230
231 // ============================================================================= 231 // =============================================================================
232 // ----------------------------------------------------------------------------- 232 // -----------------------------------------------------------------------------
233 DEFINE_ACTION (Edit, 0) 233 DEFINE_ACTION (Edit, 0)
234 { if (g_win->sel().size() != 1) 234 { if (selection().size() != 1)
235 return; 235 return;
236 236
237 LDObject* obj = g_win->sel() [0]; 237 LDObject* obj = selection() [0];
238 AddObjectDialog::staticDialog (obj->getType(), obj); 238 AddObjectDialog::staticDialog (obj->getType(), obj);
239 } 239 }
240 240
241 // ============================================================================= 241 // =============================================================================
242 // ----------------------------------------------------------------------------- 242 // -----------------------------------------------------------------------------
257 } 257 }
258 258
259 // ============================================================================= 259 // =============================================================================
260 // ----------------------------------------------------------------------------- 260 // -----------------------------------------------------------------------------
261 DEFINE_ACTION (SelectAll, CTRL (A)) 261 DEFINE_ACTION (SelectAll, CTRL (A))
262 { g_win->sel().clear(); 262 { for (LDObject* obj : LDFile::current()->objects())
263 263 obj->select();
264 for (LDObject* obj : LDFile::current()->objects())
265 g_win->sel() << obj;
266 264
267 g_win->updateSelection(); 265 g_win->updateSelection();
268 } 266 }
269 267
270 // ============================================================================= 268 // =============================================================================
273 { short colnum = g_win->getSelectedColor(); 271 { short colnum = g_win->getSelectedColor();
274 272
275 if (colnum == -1) 273 if (colnum == -1)
276 return; // no consensus on color 274 return; // no consensus on color
277 275
278 g_win->sel().clear(); 276 LDFile::current()->clearSelection();
279 277
280 for (LDObject* obj : LDFile::current()->objects()) 278 for (LDObject* obj : LDFile::current()->objects())
281 if (obj->color() == colnum) 279 if (obj->color() == colnum)
282 g_win->sel() << obj; 280 obj->select();
283 281
284 g_win->updateSelection(); 282 g_win->updateSelection();
285 } 283 }
286 284
287 // ============================================================================= 285 // =============================================================================
288 // ----------------------------------------------------------------------------- 286 // -----------------------------------------------------------------------------
289 DEFINE_ACTION (SelectByType, 0) 287 DEFINE_ACTION (SelectByType, 0)
290 { if (g_win->sel().size() == 0) 288 { if (selection().isEmpty())
291 return; 289 return;
292 290
293 LDObject::Type type = g_win->uniformSelectedType(); 291 LDObject::Type type = g_win->uniformSelectedType();
294 292
295 if (type == LDObject::Unidentified) 293 if (type == LDObject::Unidentified)
298 // If we're selecting subfile references, the reference filename must also 296 // If we're selecting subfile references, the reference filename must also
299 // be uniform. 297 // be uniform.
300 str refName; 298 str refName;
301 299
302 if (type == LDObject::Subfile) 300 if (type == LDObject::Subfile)
303 { refName = static_cast<LDSubfile*> (g_win->sel() [0])->fileInfo()->name(); 301 { refName = static_cast<LDSubfile*> (selection()[0])->fileInfo()->name();
304 302
305 for (LDObject* obj : g_win->sel()) 303 for (LDObject* obj : selection())
306 if (static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName) 304 if (static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName)
307 return; 305 return;
308 } 306 }
309 307
310 g_win->sel().clear(); 308 LDFile::current()->clearSelection();
311 309
312 for (LDObject* obj : LDFile::current()->objects()) 310 for (LDObject* obj : LDFile::current()->objects())
313 { if (obj->getType() != type) 311 { if (obj->getType() != type)
314 continue; 312 continue;
315 313
316 if (type == LDObject::Subfile && static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName) 314 if (type == LDObject::Subfile && static_cast<LDSubfile*> (obj)->fileInfo()->name() != refName)
317 continue; 315 continue;
318 316
319 g_win->sel() << obj; 317 obj->select();
320 } 318 }
321 319
322 g_win->updateSelection(); 320 g_win->updateSelection();
323 } 321 }
324 322
362 return; 360 return;
363 } 361 }
364 362
365 QList<LDObject*> objs = loadFileContents (&f, null); 363 QList<LDObject*> objs = loadFileContents (&f, null);
366 364
367 g_win->sel().clear(); 365 LDFile::current()->clearSelection();
368 366
369 for (LDObject* obj : objs) 367 for (LDObject* obj : objs)
370 { LDFile::current()->insertObj (idx, obj); 368 { LDFile::current()->insertObj (idx, obj);
371 g_win->sel() << obj; 369 obj->select();
372 g_win->R()->compileObject (obj); 370 g_win->R()->compileObject (obj);
373 371
374 idx++; 372 idx++;
375 } 373 }
376 374
379 } 377 }
380 378
381 // ============================================================================= 379 // =============================================================================
382 // ----------------------------------------------------------------------------- 380 // -----------------------------------------------------------------------------
383 DEFINE_ACTION (ExportTo, 0) 381 DEFINE_ACTION (ExportTo, 0)
384 { if (g_win->sel().size() == 0) 382 { if (selection().isEmpty())
385 return; 383 return;
386 384
387 str fname = QFileDialog::getSaveFileName(); 385 str fname = QFileDialog::getSaveFileName();
388 386
389 if (fname.length() == 0) 387 if (fname.length() == 0)
394 if (!file.open (QIODevice::WriteOnly | QIODevice::Text)) 392 if (!file.open (QIODevice::WriteOnly | QIODevice::Text))
395 { critical (fmt ("Unable to open %1 for writing (%2)", fname, strerror (errno))); 393 { critical (fmt ("Unable to open %1 for writing (%2)", fname, strerror (errno)));
396 return; 394 return;
397 } 395 }
398 396
399 for (LDObject* obj : g_win->sel()) 397 for (LDObject* obj : selection())
400 { str contents = obj->raw(); 398 { str contents = obj->raw();
401 QByteArray data = contents.toUtf8(); 399 QByteArray data = contents.toUtf8();
402 file.write (data, data.size()); 400 file.write (data, data.size());
403 file.write ("\r\n", 2); 401 file.write ("\r\n", 2);
404 } 402 }
422 dlg->connect (bbx_buttons, SIGNAL (rejected()), dlg, SLOT (reject())); 420 dlg->connect (bbx_buttons, SIGNAL (rejected()), dlg, SLOT (reject()));
423 421
424 if (dlg->exec() == false) 422 if (dlg->exec() == false)
425 return; 423 return;
426 424
427 g_win->sel().clear(); 425 LDFile::current()->clearSelection();
428 426
429 for (str line : str (te_edit->toPlainText()).split ("\n")) 427 for (str line : str (te_edit->toPlainText()).split ("\n"))
430 { LDObject* obj = parseLine (line); 428 { LDObject* obj = parseLine (line);
431 429
432 LDFile::current()->insertObj (idx, obj); 430 LDFile::current()->insertObj (idx, obj);
433 g_win->sel() << obj; 431 obj->select();
434 g_win->R()->compileObject (obj); 432 g_win->R()->compileObject (obj);
435 idx++; 433 idx++;
436 } 434 }
437 435
438 g_win->refresh(); 436 g_win->refresh();
473 } 471 }
474 472
475 // ============================================================================= 473 // =============================================================================
476 // ----------------------------------------------------------------------------- 474 // -----------------------------------------------------------------------------
477 DEFINE_ACTION (Visibility, 0) 475 DEFINE_ACTION (Visibility, 0)
478 { for (LDObject* obj : g_win->sel()) 476 { for (LDObject* obj : selection())
479 obj->setHidden (!obj->hidden()); 477 obj->setHidden (!obj->hidden());
480 478
481 g_win->refresh(); 479 g_win->refresh();
482 } 480 }
483 481
603 DEFINE_ACTION (JumpTo, CTRL (G)) 601 DEFINE_ACTION (JumpTo, CTRL (G))
604 { bool ok; 602 { bool ok;
605 int defval = 0; 603 int defval = 0;
606 LDObject* obj; 604 LDObject* obj;
607 605
608 if (g_win->sel().size() == 1) 606 if (selection().size() == 1)
609 defval = g_win->sel() [0]->getIndex(); 607 defval = selection()[0]->getIndex();
610 608
611 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval, 609 int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval,
612 1, LDFile::current()->numObjs(), 1, &ok); 610 1, LDFile::current()->numObjs(), 1, &ok);
613 611
614 if (!ok || (obj = LDFile::current()->object (idx - 1)) == null) 612 if (!ok || (obj = LDFile::current()->object (idx - 1)) == null)
615 return; 613 return;
616 614
617 g_win->clearSelection(); 615 LDFile::current()->clearSelection();
618 g_win->sel() << obj; 616 obj->select();
619 g_win->updateSelection(); 617 g_win->updateSelection();
620 } 618 }

mercurial