OSDN Git Service

Improve performance on large notes by putting in a delay between editing the note...
authorRandy Baumgarte <randy@fbn.cx>
Sat, 27 Aug 2011 19:46:09 +0000 (15:46 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Sat, 27 Aug 2011 19:46:09 +0000 (15:46 -0400)
src/cx/fbn/nevernote/gui/BrowserWindow.java

index 5b033ae..8882212 100644 (file)
@@ -67,6 +67,7 @@ import com.trolltech.qt.core.QFileSystemWatcher;
 import com.trolltech.qt.core.QIODevice;\r
 import com.trolltech.qt.core.QMimeData;\r
 import com.trolltech.qt.core.QTextCodec;\r
+import com.trolltech.qt.core.QTimer;\r
 import com.trolltech.qt.core.QUrl;\r
 import com.trolltech.qt.core.Qt;\r
 import com.trolltech.qt.core.Qt.Key;\r
@@ -259,6 +260,7 @@ public class BrowserWindow extends QWidget {
        public Signal0 unblockApplication;\r
        public boolean awaitingHttpResponse;\r
        public long     unblockTime;\r
+       private final QTimer setSourceTimer;\r
        String latexGuid;  // This is set if we are editing an existing LaTeX formula.  Useful to track guid.\r
 \r
        \r
@@ -647,6 +649,9 @@ public class BrowserWindow extends QWidget {
                blockApplication = new Signal1<BrowserWindow>();\r
                unblockApplication = new Signal0();\r
                \r
+               setSourceTimer = new QTimer();\r
+               setSourceTimer.timeout.connect(this, "setSource()");\r
+               \r
                logger.log(logger.HIGH, "Browser setup complete");\r
        }\r
 \r
@@ -737,7 +742,7 @@ public class BrowserWindow extends QWidget {
        public void setContent(QByteArray data) {\r
                sourceEdit.blockSignals(true);\r
                browser.setContent(data);\r
-               setSource(getBrowser().page().mainFrame().toHtml());\r
+               setSource();\r
        }\r
        // get/set current note\r
        public void setNote(Note n) {\r
@@ -2054,7 +2059,19 @@ public class BrowserWindow extends QWidget {
        // The note contents have changed\r
        public void contentChanged() {\r
                String content = getContent();\r
-               setSource(content);\r
+               \r
+               // This puts in a 1/2 second delay\r
+               // before updating the source editor.\r
+               // It improves response when someone is doing\r
+               // frequent updates on a large note.\r
+               // If the source editor isn't visible, then there\r
+               // is no point to doing any of this.\r
+               if (sourceEdit.isVisible()) {\r
+                       setSourceTimer.stop();\r
+                       setSourceTimer.setInterval(500);\r
+                       setSourceTimer.setSingleShot(true);\r
+                       setSourceTimer.start();\r
+               }\r
                \r
                checkNoteTitle();\r
                noteSignal.noteChanged.emit(currentNote.getGuid(), content); \r
@@ -3398,7 +3415,8 @@ public class BrowserWindow extends QWidget {
                        noteSignal.noteChanged.emit(currentNote.getGuid(), sourceEdit.toPlainText()); \r
        }\r
        \r
-       private void setSource(String text) {\r
+       private void setSource() {\r
+               String text = getContent();\r
                sourceEdit.blockSignals(true);\r
                int body = text.indexOf("<body");\r
                if (body > 0) {\r
@@ -3411,12 +3429,14 @@ public class BrowserWindow extends QWidget {
                text = text.replace("</body></html>", "");\r
                sourceEdit.setPlainText(text);\r
                sourceEdit.setReadOnly(!getBrowser().page().isContentEditable());\r
-               syntaxHighlighter.rehighlight();\r
+               //syntaxHighlighter.rehighlight();\r
                sourceEdit.blockSignals(false);\r
        }\r
 \r
        // show/hide view source window\r
        public void showSource(boolean value) {\r
+               if (sourceEdit.isVisible()) \r
+                       setSource();\r
                sourceEdit.setVisible(value);\r
        }\r
 \r