-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 | |||
@@ -1848,155 +1848,158 @@ void KateView::undoHistory() | |||
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 { |