Examples of IDoc


Examples of floobits.common.interfaces.IDoc

            return;
        }
        editor.queue(new Runnable() {
            @Override
            public void run() {
                IDoc iDoc = getDocument(iFile);
                if (iDoc == null) {
                    return;
                }
                iDoc.removeHighlight(userId, path);
            }
        });
    }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

        state.lastHighlight = obj;
        final Buf buf = this.state.bufs.get(res.id);
        editor.queue(buf, new RunLater<Buf>() {
            @Override
            public void run(Buf arg) {
                IDoc iDoc = context.iFactory.getDocument(buf.path);
                if (iDoc == null) {
                    return;
                }
                String username = state.getUsername(res.user_id);
                iDoc.applyHighlight(buf.path, res.user_id, username, state.getFollowing() && !res.following, res.summon, res.ranges);
            }
        });
    }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

    void _on_saved(JsonObject obj) {
        final Integer id = obj.get("id").getAsInt();
        final Buf buf = this.state.bufs.get(id);
        editor.queue(buf, new RunLater<Buf>() {
            public void run(Buf b) {
                IDoc document = context.iFactory.getDocument(buf.path);
                if (document == null) {
                    return;
                }
                document.save();
            }
        });
    }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

                            return;
                        }
                        synchronized (context) {
                            try {
                                context.setListener(false);
                                IDoc d = context.iFactory.getDocument(virtualFile);
                                if (d == null) {
                                    return;
                                }
                                d.setReadOnly(false);
                                d.setText(text);
                                d.setReadOnly(true);
                            } catch (Throwable e) {
                                Flog.warn(e);
                            } finally {
                                context.setListener(true);
                            }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

        this.encoding = Encoding.UTF8;
    }


    public void read () {
        IDoc d = getVirtualDoc();
        if (d == null) {
            return;
        }
        this.buf = d.getText();
        this.md5 = DigestUtils.md5Hex(this.buf);
    }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

        if (!isPopulated()) {
            Flog.warn("Unable to write %s because it's not populated yet.", path);
            return;
        }

        IDoc d = getVirtualDoc();
        if (d != null) {
            synchronized (context) {
                try {
                    context.setListener(false);
                    d.setReadOnly(false);
                    d.setText(buf);
                } finally {
                    context.setListener(true);
                }
                return;
            }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

        return buf;
    }

    @Override
    public void send_patch(IFile virtualFile) {
        IDoc d = context.iFactory.getDocument(virtualFile);
        if (d == null) {
            Flog.warn("Can't get document to read from disk for sending patch %s", path);
            return;
        }
        send_patch(d.getText());
    }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

        if (virtualFile == null) {
            Flog.warn("VirtualFile is null, no idea what do do. Aborting everything %s", this);
            getBuf();
            return;
        }
        IDoc d = context.iFactory.getDocument(virtualFile);
        if (d == null) {
            Flog.warn("Document not found for %s", virtualFile);
            getBuf();
            return;
        }
        String viewText;
        if (!virtualFile.exists()) {
            viewText = oldText;
        } else {
            viewText = d.getText();
            if (viewText.equals(oldText)) {
                b.forced_patch = false;
            } else if (!b.forced_patch) {
                b.forced_patch = true;
                oldText = viewText;
                b.send_patch(viewText);
                Flog.warn("Sending force patch for %s. this is dangerous!", b.path);
            }
        }

        b.cancelTimeout();

        String md5Before = DigestUtils.md5Hex(viewText);
        if (!md5Before.equals(res.md5_before)) {
            Flog.warn("starting md5s don't match for %s. this is dangerous!", b.path);
        }

        List<diff_match_patch.Patch> patches =  dmp.patch_fromText(res.patch);
        final Object[] results = dmp.patch_apply((LinkedList<diff_match_patch.Patch>) patches, oldText);
        final String patchedContents = (String) results[0];
        final boolean[] patchesClean = (boolean[]) results[1];
        final FlooPatchPosition[] positions = (FlooPatchPosition[]) results[2];

        for (boolean clean : patchesClean) {
            if (!clean) {
                Flog.log("Patch not clean for %s. Sending get_buf and setting readonly.", d);
                getBuf();
                return;
            }
        }
        // XXX: If patchedContents have carriage returns this will be a problem:
        String md5After = DigestUtils.md5Hex(patchedContents);
        if (!md5After.equals(res.md5_after)) {
            Flog.info("MD5 after mismatch (ours %s remote %s)", md5After, res.md5_after);
        }

        if (!d.makeWritable()) {
            Flog.info("Document: %s is not writable.", d);
            return;
        }

        String text = d.patch(positions);
        if (text == null) {
            getBuf();
            return;
        }
View Full Code Here

Examples of floobits.common.interfaces.IDoc

                Flog.warn("Got null bytes (I/O error) for %s", virtualFile);
            }
            byte[] decodedContents = encodedContents.getBytes();
            String filePath = context.toProjectRelPath(virtualFile.getPath());
            if (Arrays.equals(decodedContents, originalBytes)) {
                IDoc doc = context.iFactory.getDocument(virtualFile);
                String contents = doc == null ? encodedContents : doc.getText();
                String md5 = DigestUtils.md5Hex(contents);
                return new TextBuf(filePath, null, contents, md5, context, outbound);
            } else {
                String md5 = DigestUtils.md5Hex(originalBytes);
                return new BinaryBuf(filePath, null, originalBytes, md5, context, outbound);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.