comparison src/mainwindow.cpp @ 417:4593555915cf ignore

Make ignore function largely work
author Chris Cannam
date Thu, 16 Jun 2011 15:33:28 +0100
parents 8df07172d6da
children 93cb9005bb6f
comparison
equal deleted inserted replaced
416:8df07172d6da 417:4593555915cf
545 m_runner->requestAction(HgAction(ACT_TAG, m_workFolderPath, params)); 545 m_runner->requestAction(HgAction(ACT_TAG, m_workFolderPath, params));
546 } 546 }
547 } 547 }
548 } 548 }
549 549
550 void MainWindow::hgEditIgnore() 550 void MainWindow::initHgIgnore()
551 { 551 {
552 QString hgIgnorePath;
553 QStringList params;
554
555 hgIgnorePath = m_workFolderPath;
556 hgIgnorePath += "/.hgignore";
557
558 if (!QDir(m_workFolderPath).exists()) return; 552 if (!QDir(m_workFolderPath).exists()) return;
553 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
554
559 QFile f(hgIgnorePath); 555 QFile f(hgIgnorePath);
560 if (!f.exists()) { 556 if (!f.exists()) {
561 f.open(QFile::WriteOnly); 557 f.open(QFile::WriteOnly);
562 QTextStream *ts = new QTextStream(&f); 558 QTextStream *ts = new QTextStream(&f);
563 *ts << "syntax: glob\n"; 559 *ts << "syntax: glob\n";
564 delete ts; 560 delete ts;
565 f.close(); 561 f.close();
566 } 562 }
567 563 }
564
565 void MainWindow::hgEditIgnore()
566 {
567 if (!QDir(m_workFolderPath).exists()) return;
568
569 initHgIgnore();
570
571 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
572 QStringList params;
573
568 params << hgIgnorePath; 574 params << hgIgnorePath;
569 575
570 QString editor = getEditorBinaryName(); 576 QString editor = getEditorBinaryName();
571 577
572 if (editor == "") { 578 if (editor == "") {
573 DEBUG << "Failed to find a text editor" << endl; 579 QMessageBox::critical
574 //!!! visible error! 580 (this, tr("Edit .hgignore"),
581 tr("Failed to locate a system text editor program!"));
575 return; 582 return;
576 } 583 }
577 584
578 HgAction action(ACT_HG_IGNORE, m_workFolderPath, params); 585 HgAction action(ACT_HG_IGNORE, m_workFolderPath, params);
579 action.executable = editor; 586 action.executable = editor;
581 m_runner->requestAction(action); 588 m_runner->requestAction(action);
582 } 589 }
583 590
584 void MainWindow::hgIgnoreFiles(QStringList files) 591 void MainWindow::hgIgnoreFiles(QStringList files)
585 { 592 {
586 //!!! not implemented yet 593 if (!QDir(m_workFolderPath).exists() || files.empty()) return;
587 594
588 // we should: 595 // we should:
589 // 596 //
590 // * show the user the list of file names selected 597 // * show the user the list of file names selected
591 // 598 //
598 // - ignore all files with this extension (if they have a common 605 // - ignore all files with this extension (if they have a common
599 // extension)? 606 // extension)?
600 // 607 //
601 // - ignore all files with these extensions (if they have any 608 // - ignore all files with these extensions (if they have any
602 // extensions?) 609 // extensions?)
603 //
604 // Do we need different mechanisms based on whether we have glob
605 // or regex syntax?
606 610
607 DEBUG << "MainWindow::hgIgnoreFiles: File names are:" << endl; 611 DEBUG << "MainWindow::hgIgnoreFiles: File names are:" << endl;
608 foreach (QString file, files) DEBUG << file << endl; 612 foreach (QString file, files) DEBUG << file << endl;
609 613
610 QSet<QString> suffixes; 614 QSet<QString> suffixes;
616 HgIgnoreDialog::IgnoreType itype = 620 HgIgnoreDialog::IgnoreType itype =
617 HgIgnoreDialog::confirmIgnore 621 HgIgnoreDialog::confirmIgnore
618 (this, files, QStringList::fromSet(suffixes)); 622 (this, files, QStringList::fromSet(suffixes));
619 623
620 DEBUG << "hgIgnoreFiles: Ignore type is " << itype << endl; 624 DEBUG << "hgIgnoreFiles: Ignore type is " << itype << endl;
625
626 // Now, .hgignore can be switched from regex to glob syntax
627 // part-way through -- and glob is much simpler for us, so we
628 // should do that if it's in regex mode at the end of the file.
629
630 initHgIgnore();
631
632 QString hgIgnorePath = m_workFolderPath + "/.hgignore";
633
634 // hgignore file should now exist (initHgIgnore should have
635 // created it if it didn't). Check for glob status first
636
637 QFile f(hgIgnorePath);
638 if (!f.exists()) {
639 std::cerr << "MainWindow::ignoreFiles: Internal error: .hgignore file not found (even though we were supposed to have created it)" << std::endl;
640 return;
641 }
642
643 f.open(QFile::ReadOnly);
644 bool glob = false;
645 while (!f.atEnd()) {
646 QByteArray ba = f.readLine();
647 QString s = QString::fromLocal8Bit(ba).trimmed();
648 if (s.startsWith("syntax:")) {
649 if (s.endsWith("glob")) {
650 glob = true;
651 } else {
652 glob = false;
653 }
654 }
655 }
656 f.close();
657
658 f.open(QFile::Append);
659 QTextStream out(&f);
660
661 if (!glob) {
662 out << "syntax: glob" << endl;
663 }
664
665 if (itype == HgIgnoreDialog::IgnoreAllFilesOfGivenSuffixes) {
666 foreach (QString s, suffixes) {
667 out << "*." << s << endl;
668 }
669 } else if (itype == HgIgnoreDialog::IgnoreGivenFilesOnly) {
670 foreach (QString f, files) {
671 out << f << endl;
672 }
673 } else {
674
675 //!!! uh, can we do this in glob mode??
676 }
677
678 //!!! report, and offer to edit .hgignore now
621 679
680
681 hgRefresh();
622 } 682 }
623 683
624 void MainWindow::hgUnIgnoreFiles(QStringList files) 684 void MainWindow::hgUnIgnoreFiles(QStringList files)
625 { 685 {
626 //!!! not implemented yet 686 //!!! not implemented yet