-rw-r--r-- | noncore/apps/tinykate/libkate/view/kateview.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp index 423634b..c5673a5 100644 --- a/noncore/apps/tinykate/libkate/view/kateview.cpp +++ b/noncore/apps/tinykate/libkate/view/kateview.cpp | |||
@@ -1704,443 +1704,446 @@ void KateView::toggleVertical() | |||
1704 | setConfig(configFlags ^ KateView::cfVerticalSelect); | 1704 | setConfig(configFlags ^ KateView::cfVerticalSelect); |
1705 | } | 1705 | } |
1706 | 1706 | ||
1707 | 1707 | ||
1708 | int KateView::numLines() { | 1708 | int KateView::numLines() { |
1709 | return myDoc->numLines(); | 1709 | return myDoc->numLines(); |
1710 | } | 1710 | } |
1711 | 1711 | ||
1712 | QString KateView::text() { | 1712 | QString KateView::text() { |
1713 | return myDoc->text(); | 1713 | return myDoc->text(); |
1714 | } | 1714 | } |
1715 | 1715 | ||
1716 | QString KateView::currentTextLine() { | 1716 | QString KateView::currentTextLine() { |
1717 | TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y); | 1717 | TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y); |
1718 | return QString(textLine->getText(), textLine->length()); | 1718 | return QString(textLine->getText(), textLine->length()); |
1719 | } | 1719 | } |
1720 | 1720 | ||
1721 | QString KateView::textLine(int num) { | 1721 | QString KateView::textLine(int num) { |
1722 | TextLine::Ptr textLine = myDoc->getTextLine(num); | 1722 | TextLine::Ptr textLine = myDoc->getTextLine(num); |
1723 | return QString(textLine->getText(), textLine->length()); | 1723 | return QString(textLine->getText(), textLine->length()); |
1724 | } | 1724 | } |
1725 | 1725 | ||
1726 | QString KateView::currentWord() { | 1726 | QString KateView::currentWord() { |
1727 | return myDoc->getWord(myViewInternal->cursor); | 1727 | return myDoc->getWord(myViewInternal->cursor); |
1728 | } | 1728 | } |
1729 | 1729 | ||
1730 | QString KateView::word(int x, int y) { | 1730 | QString KateView::word(int x, int y) { |
1731 | PointStruc cursor; | 1731 | PointStruc cursor; |
1732 | cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight; | 1732 | cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight; |
1733 | if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString(); | 1733 | if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString(); |
1734 | cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x); | 1734 | cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x); |
1735 | return myDoc->getWord(cursor); | 1735 | return myDoc->getWord(cursor); |
1736 | } | 1736 | } |
1737 | 1737 | ||
1738 | void KateView::setText(const QString &s) { | 1738 | void KateView::setText(const QString &s) { |
1739 | myDoc->setText(s); | 1739 | myDoc->setText(s); |
1740 | myDoc->updateViews(); | 1740 | myDoc->updateViews(); |
1741 | } | 1741 | } |
1742 | 1742 | ||
1743 | void KateView::insertText(const QString &s, bool /*mark*/) { | 1743 | void KateView::insertText(const QString &s, bool /*mark*/) { |
1744 | VConfig c; | 1744 | VConfig c; |
1745 | myViewInternal->getVConfig(c); | 1745 | myViewInternal->getVConfig(c); |
1746 | myDoc->insert(c, s); | 1746 | myDoc->insert(c, s); |
1747 | myDoc->updateViews(); | 1747 | myDoc->updateViews(); |
1748 | } | 1748 | } |
1749 | 1749 | ||
1750 | bool KateView::hasMarkedText() { | 1750 | bool KateView::hasMarkedText() { |
1751 | return myDoc->hasMarkedText(); | 1751 | return myDoc->hasMarkedText(); |
1752 | } | 1752 | } |
1753 | 1753 | ||
1754 | QString KateView::markedText() { | 1754 | QString KateView::markedText() { |
1755 | return myDoc->markedText(configFlags); | 1755 | return myDoc->markedText(configFlags); |
1756 | } | 1756 | } |
1757 | 1757 | ||
1758 | bool KateView::canDiscard() { | 1758 | bool KateView::canDiscard() { |
1759 | int query; | 1759 | int query; |
1760 | 1760 | ||
1761 | if (isModified()) { | 1761 | if (isModified()) { |
1762 | query = KMessageBox::warningYesNoCancel(this, | 1762 | query = KMessageBox::warningYesNoCancel(this, |
1763 | i18n("The current Document has been modified.\nWould you like to save it?")); | 1763 | i18n("The current Document has been modified.\nWould you like to save it?")); |
1764 | switch (query) { | 1764 | switch (query) { |
1765 | case KMessageBox::Yes: //yes | 1765 | case KMessageBox::Yes: //yes |
1766 | if (save() == CANCEL) return false; | 1766 | if (save() == CANCEL) return false; |
1767 | if (isModified()) { | 1767 | if (isModified()) { |
1768 | query = KMessageBox::warningContinueCancel(this, | 1768 | query = KMessageBox::warningContinueCancel(this, |
1769 | i18n("Could not save the document.\nDiscard it and continue?"), | 1769 | i18n("Could not save the document.\nDiscard it and continue?"), |
1770 | QString::null, i18n("&Discard")); | 1770 | QString::null, i18n("&Discard")); |
1771 | if (query == KMessageBox::Cancel) return false; | 1771 | if (query == KMessageBox::Cancel) return false; |
1772 | } | 1772 | } |
1773 | break; | 1773 | break; |
1774 | case KMessageBox::Cancel: //cancel | 1774 | case KMessageBox::Cancel: //cancel |
1775 | return false; | 1775 | return false; |
1776 | } | 1776 | } |
1777 | } | 1777 | } |
1778 | return true; | 1778 | return true; |
1779 | } | 1779 | } |
1780 | 1780 | ||
1781 | void KateView::flush() | 1781 | void KateView::flush() |
1782 | { | 1782 | { |
1783 | if (canDiscard()) myDoc->flush(); | 1783 | if (canDiscard()) myDoc->flush(); |
1784 | } | 1784 | } |
1785 | 1785 | ||
1786 | KateView::fileResult KateView::save() { | 1786 | KateView::fileResult KateView::save() { |
1787 | int query = KMessageBox::Yes; | 1787 | int query = KMessageBox::Yes; |
1788 | if (isModified()) { | 1788 | if (isModified()) { |
1789 | return saveAs(); | 1789 | return saveAs(); |
1790 | } | 1790 | } |
1791 | return OK; | 1791 | return OK; |
1792 | } | 1792 | } |
1793 | 1793 | ||
1794 | KateView::fileResult KateView::saveAs() { | 1794 | KateView::fileResult KateView::saveAs() { |
1795 | return OK; | 1795 | return OK; |
1796 | } | 1796 | } |
1797 | 1797 | ||
1798 | void KateView::doCursorCommand(int cmdNum) { | 1798 | void KateView::doCursorCommand(int cmdNum) { |
1799 | VConfig c; | 1799 | VConfig c; |
1800 | myViewInternal->getVConfig(c); | 1800 | myViewInternal->getVConfig(c); |
1801 | if (cmdNum & selectFlag) c.flags |= KateView::cfMark; | 1801 | if (cmdNum & selectFlag) c.flags |= KateView::cfMark; |
1802 | if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection; | 1802 | if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection; |
1803 | cmdNum &= ~(selectFlag | multiSelectFlag); | 1803 | cmdNum &= ~(selectFlag | multiSelectFlag); |
1804 | myViewInternal->doCursorCommand(c, cmdNum); | 1804 | myViewInternal->doCursorCommand(c, cmdNum); |
1805 | myDoc->updateViews(); | 1805 | myDoc->updateViews(); |
1806 | } | 1806 | } |
1807 | 1807 | ||
1808 | void KateView::doEditCommand(int cmdNum) { | 1808 | void KateView::doEditCommand(int cmdNum) { |
1809 | VConfig c; | 1809 | VConfig c; |
1810 | myViewInternal->getVConfig(c); | 1810 | myViewInternal->getVConfig(c); |
1811 | myViewInternal->doEditCommand(c, cmdNum); | 1811 | myViewInternal->doEditCommand(c, cmdNum); |
1812 | myDoc->updateViews(); | 1812 | myDoc->updateViews(); |
1813 | } | 1813 | } |
1814 | 1814 | ||
1815 | void KateView::undoMultiple(int count) { | 1815 | void KateView::undoMultiple(int count) { |
1816 | if (isReadOnly()) | 1816 | if (isReadOnly()) |
1817 | return; | 1817 | return; |
1818 | 1818 | ||
1819 | VConfig c; | 1819 | VConfig c; |
1820 | myViewInternal->getVConfig(c); | 1820 | myViewInternal->getVConfig(c); |
1821 | myDoc->undo(c, count); | 1821 | myDoc->undo(c, count); |
1822 | myDoc->updateViews(); | 1822 | myDoc->updateViews(); |
1823 | } | 1823 | } |
1824 | 1824 | ||
1825 | void KateView::redoMultiple(int count) { | 1825 | void KateView::redoMultiple(int count) { |
1826 | if (isReadOnly()) | 1826 | if (isReadOnly()) |
1827 | return; | 1827 | return; |
1828 | 1828 | ||
1829 | VConfig c; | 1829 | VConfig c; |
1830 | myViewInternal->getVConfig(c); | 1830 | myViewInternal->getVConfig(c); |
1831 | myDoc->redo(c, count); | 1831 | myDoc->redo(c, count); |
1832 | myDoc->updateViews(); | 1832 | myDoc->updateViews(); |
1833 | } | 1833 | } |
1834 | 1834 | ||
1835 | void KateView::undoHistory() | 1835 | void KateView::undoHistory() |
1836 | { | 1836 | { |
1837 | UndoHistory *undoH; | 1837 | UndoHistory *undoH; |
1838 | 1838 | ||
1839 | undoH = new UndoHistory(this, this, "UndoHistory", true); | 1839 | undoH = new UndoHistory(this, this, "UndoHistory", true); |
1840 | 1840 | ||
1841 | undoH->setCaption(i18n("Undo/Redo History")); | 1841 | undoH->setCaption(i18n("Undo/Redo History")); |
1842 | 1842 | ||
1843 | connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo())); | 1843 | connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo())); |
1844 | connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int))); | 1844 | connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int))); |
1845 | connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int))); | 1845 | connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int))); |
1846 | 1846 | ||
1847 | undoH->exec(); | 1847 | undoH->exec(); |
1848 | 1848 | ||
1849 | delete undoH; | 1849 | delete undoH; |
1850 | } | 1850 | } |
1851 | 1851 | ||
1852 | static void kwview_addToStrList(QStringList &list, const QString &str) { | 1852 | static void kwview_addToStrList(QStringList &list, const QString &str) { |
1853 | if (list.count() > 0) { | 1853 | if (list.count() > 0) { |
1854 | if (list.first() == str) return; | 1854 | if (list.first() == str) return; |
1855 | QStringList::Iterator it; | 1855 | QStringList::Iterator it; |
1856 | it = list.find(str); | 1856 | it = list.find(str); |
1857 | if (*it != 0L) list.remove(it); | 1857 | if (*it != 0L) list.remove(it); |
1858 | if (list.count() >= 16) list.remove(list.fromLast()); | 1858 | if (list.count() >= 16) list.remove(list.fromLast()); |
1859 | } | 1859 | } |
1860 | list.prepend(str); | 1860 | list.prepend(str); |
1861 | } | 1861 | } |
1862 | 1862 | ||
1863 | void KateView::find() { | 1863 | void KateView::find() { |
1864 | SearchDialog *searchDialog; | 1864 | SearchDialog *searchDialog; |
1865 | 1865 | ||
1866 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; | 1866 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; |
1867 | 1867 | ||
1868 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, | 1868 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, |
1869 | searchFlags & ~KateView::sfReplace); | 1869 | searchFlags & ~KateView::sfReplace); |
1870 | 1870 | ||
1871 | // If the user has marked some text we use that otherwise | 1871 | // If the user has marked some text we use that otherwise |
1872 | // use the word under the cursor. | 1872 | // use the word under the cursor. |
1873 | QString str; | 1873 | QString str; |
1874 | if (myDoc->hasMarkedText()) | 1874 | if (myDoc->hasMarkedText()) |
1875 | str = markedText(); | 1875 | str = markedText(); |
1876 | 1876 | ||
1877 | if (str.isEmpty()) | 1877 | if (str.isEmpty()) |
1878 | str = currentWord(); | 1878 | str = currentWord(); |
1879 | 1879 | ||
1880 | if (!str.isEmpty()) | 1880 | if (!str.isEmpty()) |
1881 | { | 1881 | { |
1882 | str.replace(QRegExp("^\n"), ""); | 1882 | str.replace(QRegExp("^\n"), ""); |
1883 | int pos=str.find("\n"); | 1883 | int pos=str.find("\n"); |
1884 | if (pos>-1) | 1884 | if (pos>-1) |
1885 | str=str.left(pos); | 1885 | str=str.left(pos); |
1886 | searchDialog->setSearchText( str ); | 1886 | searchDialog->setSearchText( str ); |
1887 | } | 1887 | } |
1888 | 1888 | ||
1889 | myViewInternal->focusOutEvent(0L);// QT bug ? | 1889 | myViewInternal->focusOutEvent(0L);// QT bug ? |
1890 | if (searchDialog->exec() == QDialog::Accepted) { | 1890 | if (searchDialog->exec() == QDialog::Accepted) { |
1891 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); | 1891 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); |
1892 | searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt); | 1892 | searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt); |
1893 | initSearch(s, searchFlags); | 1893 | initSearch(s, searchFlags); |
1894 | findAgain(s); | 1894 | findAgain(s); |
1895 | } | 1895 | } |
1896 | qApp->processEvents(); | ||
1896 | delete searchDialog; | 1897 | delete searchDialog; |
1897 | } | 1898 | } |
1898 | 1899 | ||
1899 | void KateView::replace() { | 1900 | void KateView::replace() { |
1900 | SearchDialog *searchDialog; | 1901 | SearchDialog *searchDialog; |
1901 | 1902 | ||
1902 | if (isReadOnly()) return; | 1903 | if (isReadOnly()) return; |
1903 | 1904 | ||
1904 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; | 1905 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; |
1905 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, | 1906 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, |
1906 | searchFlags | KateView::sfReplace); | 1907 | searchFlags | KateView::sfReplace); |
1907 | 1908 | ||
1908 | // If the user has marked some text we use that otherwise | 1909 | // If the user has marked some text we use that otherwise |
1909 | // use the word under the cursor. | 1910 | // use the word under the cursor. |
1910 | QString str; | 1911 | QString str; |
1911 | if (myDoc->hasMarkedText()) | 1912 | if (myDoc->hasMarkedText()) |
1912 | str = markedText(); | 1913 | str = markedText(); |
1913 | 1914 | ||
1914 | if (str.isEmpty()) | 1915 | if (str.isEmpty()) |
1915 | str = currentWord(); | 1916 | str = currentWord(); |
1916 | 1917 | ||
1917 | if (!str.isEmpty()) | 1918 | if (!str.isEmpty()) |
1918 | { | 1919 | { |
1919 | str.replace(QRegExp("^\n"), ""); | 1920 | str.replace(QRegExp("^\n"), ""); |
1920 | int pos=str.find("\n"); | 1921 | int pos=str.find("\n"); |
1921 | if (pos>-1) | 1922 | if (pos>-1) |
1922 | str=str.left(pos); | 1923 | str=str.left(pos); |
1923 | searchDialog->setSearchText( str ); | 1924 | searchDialog->setSearchText( str ); |
1924 | } | 1925 | } |
1925 | 1926 | ||
1926 | myViewInternal->focusOutEvent(0L);// QT bug ? | 1927 | myViewInternal->focusOutEvent(0L);// QT bug ? |
1927 | if (searchDialog->exec() == QDialog::Accepted) { | 1928 | if (searchDialog->exec() == QDialog::Accepted) { |
1928 | // myDoc->recordReset(); | 1929 | // myDoc->recordReset(); |
1929 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); | 1930 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); |
1930 | kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith()); | 1931 | kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith()); |
1931 | searchFlags = searchDialog->getFlags(); | 1932 | searchFlags = searchDialog->getFlags(); |
1932 | initSearch(s, searchFlags); | 1933 | initSearch(s, searchFlags); |
1933 | replaceAgain(); | 1934 | replaceAgain(); |
1934 | } | 1935 | } |
1936 | qApp->processEvents(); | ||
1935 | delete searchDialog; | 1937 | delete searchDialog; |
1936 | } | 1938 | } |
1937 | 1939 | ||
1938 | void KateView::gotoLine() { | 1940 | void KateView::gotoLine() { |
1939 | GotoLineDialog *dlg; | 1941 | GotoLineDialog *dlg; |
1940 | PointStruc cursor; | 1942 | PointStruc cursor; |
1941 | 1943 | ||
1942 | dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines()); | 1944 | dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines()); |
1943 | // dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this); | 1945 | // dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this); |
1944 | 1946 | ||
1945 | if (dlg->exec() == QDialog::Accepted) { | 1947 | if (dlg->exec() == QDialog::Accepted) { |
1946 | // myDoc->recordReset(); | 1948 | // myDoc->recordReset(); |
1947 | cursor.x = 0; | 1949 | cursor.x = 0; |
1948 | cursor.y = dlg->getLine() - 1; | 1950 | cursor.y = dlg->getLine() - 1; |
1949 | myDoc->needPreHighlight(cursor.y); | 1951 | myDoc->needPreHighlight(cursor.y); |
1950 | myViewInternal->updateCursor(cursor); | 1952 | myViewInternal->updateCursor(cursor); |
1951 | myViewInternal->center(); | 1953 | myViewInternal->center(); |
1952 | myViewInternal->updateView(KateView::ufUpdateOnScroll); | 1954 | myViewInternal->updateView(KateView::ufUpdateOnScroll); |
1953 | myDoc->updateViews(this); //uptade all other views except this one | 1955 | myDoc->updateViews(this); //uptade all other views except this one |
1954 | } | 1956 | } |
1957 | qApp->processEvents(); | ||
1955 | delete dlg; | 1958 | delete dlg; |
1956 | } | 1959 | } |
1957 | 1960 | ||
1958 | 1961 | ||
1959 | void KateView::initSearch(SConfig &s, int flags) { | 1962 | void KateView::initSearch(SConfig &s, int flags) { |
1960 | 1963 | ||
1961 | s.flags = flags; | 1964 | s.flags = flags; |
1962 | s.setPattern(myDoc->searchForList.first()); | 1965 | s.setPattern(myDoc->searchForList.first()); |
1963 | 1966 | ||
1964 | if (!(s.flags & KateView::sfFromBeginning)) { | 1967 | if (!(s.flags & KateView::sfFromBeginning)) { |
1965 | // If we are continuing a backward search, make sure we do not get stuck | 1968 | // If we are continuing a backward search, make sure we do not get stuck |
1966 | // at an existing match. | 1969 | // at an existing match. |
1967 | s.cursor = myViewInternal->cursor; | 1970 | s.cursor = myViewInternal->cursor; |
1968 | TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y); | 1971 | TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y); |
1969 | QString const txt(textLine->getText(),textLine->length()); | 1972 | QString const txt(textLine->getText(),textLine->length()); |
1970 | const QString searchFor= myDoc->searchForList.first(); | 1973 | const QString searchFor= myDoc->searchForList.first(); |
1971 | int pos = s.cursor.x-searchFor.length()-1; | 1974 | int pos = s.cursor.x-searchFor.length()-1; |
1972 | if ( pos < 0 ) pos = 0; | 1975 | if ( pos < 0 ) pos = 0; |
1973 | pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive); | 1976 | pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive); |
1974 | if ( s.flags & KateView::sfBackward ) | 1977 | if ( s.flags & KateView::sfBackward ) |
1975 | { | 1978 | { |
1976 | if ( pos <= s.cursor.x ) s.cursor.x= pos-1; | 1979 | if ( pos <= s.cursor.x ) s.cursor.x= pos-1; |
1977 | } | 1980 | } |
1978 | else | 1981 | else |
1979 | if ( pos == s.cursor.x ) s.cursor.x++; | 1982 | if ( pos == s.cursor.x ) s.cursor.x++; |
1980 | } else { | 1983 | } else { |
1981 | if (!(s.flags & KateView::sfBackward)) { | 1984 | if (!(s.flags & KateView::sfBackward)) { |
1982 | s.cursor.x = 0; | 1985 | s.cursor.x = 0; |
1983 | s.cursor.y = 0; | 1986 | s.cursor.y = 0; |
1984 | } else { | 1987 | } else { |
1985 | s.cursor.x = -1; | 1988 | s.cursor.x = -1; |
1986 | s.cursor.y = myDoc->lastLine(); | 1989 | s.cursor.y = myDoc->lastLine(); |
1987 | } | 1990 | } |
1988 | s.flags |= KateView::sfFinished; | 1991 | s.flags |= KateView::sfFinished; |
1989 | } | 1992 | } |
1990 | if (!(s.flags & KateView::sfBackward)) { | 1993 | if (!(s.flags & KateView::sfBackward)) { |
1991 | if (!(s.cursor.x || s.cursor.y)) | 1994 | if (!(s.cursor.x || s.cursor.y)) |
1992 | s.flags |= KateView::sfFinished; | 1995 | s.flags |= KateView::sfFinished; |
1993 | } | 1996 | } |
1994 | s.startCursor = s.cursor; | 1997 | s.startCursor = s.cursor; |
1995 | } | 1998 | } |
1996 | 1999 | ||
1997 | void KateView::continueSearch(SConfig &s) { | 2000 | void KateView::continueSearch(SConfig &s) { |
1998 | 2001 | ||
1999 | if (!(s.flags & KateView::sfBackward)) { | 2002 | if (!(s.flags & KateView::sfBackward)) { |
2000 | s.cursor.x = 0; | 2003 | s.cursor.x = 0; |
2001 | s.cursor.y = 0; | 2004 | s.cursor.y = 0; |
2002 | } else { | 2005 | } else { |
2003 | s.cursor.x = -1; | 2006 | s.cursor.x = -1; |
2004 | s.cursor.y = myDoc->lastLine(); | 2007 | s.cursor.y = myDoc->lastLine(); |
2005 | } | 2008 | } |
2006 | s.flags |= KateView::sfFinished; | 2009 | s.flags |= KateView::sfFinished; |
2007 | s.flags &= ~KateView::sfAgain; | 2010 | s.flags &= ~KateView::sfAgain; |
2008 | } | 2011 | } |
2009 | 2012 | ||
2010 | void KateView::findAgain(SConfig &s) { | 2013 | void KateView::findAgain(SConfig &s) { |
2011 | int query; | 2014 | int query; |
2012 | PointStruc cursor; | 2015 | PointStruc cursor; |
2013 | QString str; | 2016 | QString str; |
2014 | 2017 | ||
2015 | QString searchFor = myDoc->searchForList.first(); | 2018 | QString searchFor = myDoc->searchForList.first(); |
2016 | 2019 | ||
2017 | if( searchFor.isEmpty() ) { | 2020 | if( searchFor.isEmpty() ) { |
2018 | find(); | 2021 | find(); |
2019 | return; | 2022 | return; |
2020 | } | 2023 | } |
2021 | 2024 | ||
2022 | do { | 2025 | do { |
2023 | query = KMessageBox::Cancel; | 2026 | query = KMessageBox::Cancel; |
2024 | if (myDoc->doSearch(s,searchFor)) { | 2027 | if (myDoc->doSearch(s,searchFor)) { |
2025 | cursor = s.cursor; | 2028 | cursor = s.cursor; |
2026 | if (!(s.flags & KateView::sfBackward)) | 2029 | if (!(s.flags & KateView::sfBackward)) |
2027 | s.cursor.x += s.matchedLength; | 2030 | s.cursor.x += s.matchedLength; |
2028 | myViewInternal->updateCursor(s.cursor); //does deselectAll() | 2031 | myViewInternal->updateCursor(s.cursor); //does deselectAll() |
2029 | exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false); | 2032 | exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false); |
2030 | } else { | 2033 | } else { |
2031 | if (!(s.flags & KateView::sfFinished)) { | 2034 | if (!(s.flags & KateView::sfFinished)) { |
2032 | // ask for continue | 2035 | // ask for continue |
2033 | if (!(s.flags & KateView::sfBackward)) { | 2036 | if (!(s.flags & KateView::sfBackward)) { |
2034 | // forward search | 2037 | // forward search |
2035 | str = i18n("End of document reached.\n" | 2038 | str = i18n("End of document reached.\n" |
2036 | "Continue from the beginning?"); | 2039 | "Continue from the beginning?"); |
2037 | query = KMessageBox::warningContinueCancel(this, | 2040 | query = KMessageBox::warningContinueCancel(this, |
2038 | str, i18n("Find"), i18n("Continue")); | 2041 | str, i18n("Find"), i18n("Continue")); |
2039 | } else { | 2042 | } else { |
2040 | // backward search | 2043 | // backward search |
2041 | str = i18n("Beginning of document reached.\n" | 2044 | str = i18n("Beginning of document reached.\n" |
2042 | "Continue from the end?"); | 2045 | "Continue from the end?"); |
2043 | query = KMessageBox::warningContinueCancel(this, | 2046 | query = KMessageBox::warningContinueCancel(this, |
2044 | str, i18n("Find"), i18n("Continue")); | 2047 | str, i18n("Find"), i18n("Continue")); |
2045 | } | 2048 | } |
2046 | continueSearch(s); | 2049 | continueSearch(s); |
2047 | } else { | 2050 | } else { |
2048 | // wrapped | 2051 | // wrapped |
2049 | KMessageBox::sorry(this, | 2052 | KMessageBox::sorry(this, |
2050 | i18n("Search string '%1' not found!").arg(searchFor), | 2053 | i18n("Search string '%1' not found!").arg(searchFor), |
2051 | i18n("Find")); | 2054 | i18n("Find")); |
2052 | } | 2055 | } |
2053 | } | 2056 | } |
2054 | } while (query == KMessageBox::Continue); | 2057 | } while (query == KMessageBox::Continue); |
2055 | } | 2058 | } |
2056 | 2059 | ||
2057 | void KateView::replaceAgain() { | 2060 | void KateView::replaceAgain() { |
2058 | if (isReadOnly()) | 2061 | if (isReadOnly()) |
2059 | return; | 2062 | return; |
2060 | 2063 | ||
2061 | replaces = 0; | 2064 | replaces = 0; |
2062 | if (s.flags & KateView::sfPrompt) { | 2065 | if (s.flags & KateView::sfPrompt) { |
2063 | doReplaceAction(-1); | 2066 | doReplaceAction(-1); |
2064 | } else { | 2067 | } else { |
2065 | doReplaceAction(KateView::srAll); | 2068 | doReplaceAction(KateView::srAll); |
2066 | } | 2069 | } |
2067 | } | 2070 | } |
2068 | 2071 | ||
2069 | void KateView::doReplaceAction(int result, bool found) { | 2072 | void KateView::doReplaceAction(int result, bool found) { |
2070 | int rlen; | 2073 | int rlen; |
2071 | PointStruc cursor; | 2074 | PointStruc cursor; |
2072 | bool started; | 2075 | bool started; |
2073 | 2076 | ||
2074 | QString searchFor = myDoc->searchForList.first(); | 2077 | QString searchFor = myDoc->searchForList.first(); |
2075 | QString replaceWith = myDoc->replaceWithList.first(); | 2078 | QString replaceWith = myDoc->replaceWithList.first(); |
2076 | rlen = replaceWith.length(); | 2079 | rlen = replaceWith.length(); |
2077 | 2080 | ||
2078 | switch (result) { | 2081 | switch (result) { |
2079 | case KateView::srYes: //yes | 2082 | case KateView::srYes: //yes |
2080 | myDoc->recordStart(this, s.cursor, configFlags, | 2083 | myDoc->recordStart(this, s.cursor, configFlags, |
2081 | KateActionGroup::ugReplace, true); | 2084 | KateActionGroup::ugReplace, true); |
2082 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); | 2085 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); |
2083 | replaces++; | 2086 | replaces++; |
2084 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) | 2087 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) |
2085 | s.startCursor.x += rlen - s.matchedLength; | 2088 | s.startCursor.x += rlen - s.matchedLength; |
2086 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; | 2089 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; |
2087 | myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent); | 2090 | myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent); |
2088 | break; | 2091 | break; |
2089 | case KateView::srNo: //no | 2092 | case KateView::srNo: //no |
2090 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength; | 2093 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength; |
2091 | break; | 2094 | break; |
2092 | case KateView::srAll: //replace all | 2095 | case KateView::srAll: //replace all |
2093 | deleteReplacePrompt(); | 2096 | deleteReplacePrompt(); |
2094 | do { | 2097 | do { |
2095 | started = false; | 2098 | started = false; |
2096 | while (found || myDoc->doSearch(s,searchFor)) { | 2099 | while (found || myDoc->doSearch(s,searchFor)) { |
2097 | if (!started) { | 2100 | if (!started) { |
2098 | found = false; | 2101 | found = false; |
2099 | myDoc->recordStart(this, s.cursor, configFlags, | 2102 | myDoc->recordStart(this, s.cursor, configFlags, |
2100 | KateActionGroup::ugReplace); | 2103 | KateActionGroup::ugReplace); |
2101 | started = true; | 2104 | started = true; |
2102 | } | 2105 | } |
2103 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); | 2106 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); |
2104 | replaces++; | 2107 | replaces++; |
2105 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) | 2108 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) |
2106 | s.startCursor.x += rlen - s.matchedLength; | 2109 | s.startCursor.x += rlen - s.matchedLength; |
2107 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; | 2110 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; |
2108 | } | 2111 | } |
2109 | if (started) myDoc->recordEnd(this, s.cursor, | 2112 | if (started) myDoc->recordEnd(this, s.cursor, |
2110 | configFlags | KateView::cfPersistent); | 2113 | configFlags | KateView::cfPersistent); |
2111 | } while (!askReplaceEnd()); | 2114 | } while (!askReplaceEnd()); |
2112 | return; | 2115 | return; |
2113 | case KateView::srCancel: //cancel | 2116 | case KateView::srCancel: //cancel |
2114 | deleteReplacePrompt(); | 2117 | deleteReplacePrompt(); |
2115 | return; | 2118 | return; |
2116 | default: | 2119 | default: |
2117 | replacePrompt = 0L; | 2120 | replacePrompt = 0L; |
2118 | } | 2121 | } |
2119 | 2122 | ||
2120 | do { | 2123 | do { |
2121 | if (myDoc->doSearch(s,searchFor)) { | 2124 | if (myDoc->doSearch(s,searchFor)) { |
2122 | //text found: highlight it, show replace prompt if needed and exit | 2125 | //text found: highlight it, show replace prompt if needed and exit |
2123 | cursor = s.cursor; | 2126 | cursor = s.cursor; |
2124 | if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength; | 2127 | if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength; |
2125 | myViewInternal->updateCursor(cursor); //does deselectAll() | 2128 | myViewInternal->updateCursor(cursor); //does deselectAll() |
2126 | exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true); | 2129 | exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true); |
2127 | if (replacePrompt == 0L) { | 2130 | if (replacePrompt == 0L) { |
2128 | replacePrompt = new ReplacePrompt(this); | 2131 | replacePrompt = new ReplacePrompt(this); |
2129 | myDoc->setPseudoModal(replacePrompt);//disable(); | 2132 | myDoc->setPseudoModal(replacePrompt);//disable(); |
2130 | connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot())); | 2133 | connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot())); |
2131 | replacePrompt->show(); //this is not modal | 2134 | replacePrompt->show(); //this is not modal |
2132 | } | 2135 | } |
2133 | return; //exit if text found | 2136 | return; //exit if text found |
2134 | } | 2137 | } |
2135 | //nothing found: repeat until user cancels "repeat from beginning" dialog | 2138 | //nothing found: repeat until user cancels "repeat from beginning" dialog |
2136 | } while (!askReplaceEnd()); | 2139 | } while (!askReplaceEnd()); |
2137 | deleteReplacePrompt(); | 2140 | deleteReplacePrompt(); |
2138 | } | 2141 | } |
2139 | 2142 | ||
2140 | void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) { | 2143 | void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) { |
2141 | int x1, x2, y1, y2, xPos, yPos; | 2144 | int x1, x2, y1, y2, xPos, yPos; |
2142 | 2145 | ||
2143 | VConfig c; | 2146 | VConfig c; |
2144 | myViewInternal->getVConfig(c); | 2147 | myViewInternal->getVConfig(c); |
2145 | myDoc->selectLength(cursor,slen,c.flags); | 2148 | myDoc->selectLength(cursor,slen,c.flags); |
2146 | 2149 | ||