Ejemplo n.º 1
0
    //restore session
    public static void Restore()
    {
        KConfig config = KApplication.kApplication().SessionConfig();

        if (config == null) {
            return;
        }

        KTextEditor.Editor editor = KTextEditor.EditorChooser.Editor();

        if (editor == null) {
            KMessageBox.Error(null, KDE.I18n("A KDE text-editor component could not be found;\n" +
                                  "please check your KDE installation."));
            QCoreApplication.Exit(1);
        }

        // simple mode
        editor.SetSimpleMode(true);

        int docs, windows;
        string buf;
        KTextEditor.Document doc;
        KWrite t;

        KConfigGroup numberConfig = new KConfigGroup(config, "Number");
        docs = numberConfig.ReadEntry("NumberOfDocuments", 0);
        windows = numberConfig.ReadEntry("NumberOfWindows", 0);

        for (int z = 1; z <= docs; z++) {
            buf = "Document " + z.ToString();
            KConfigGroup cg = new KConfigGroup(config, buf);
            doc = editor.CreateDocument(null);

            KTextEditor.SessionConfigInterface iface = qobject_cast<KTextEditor.SessionConfigInterface>(doc);
            if (iface != null)
                iface.ReadSessionConfig(cg);
            docList.Add(doc);
        }

        for (int z = 1; z <= windows; z++) {
            buf = "Window " + z;
            KConfigGroup cg = new KConfigGroup(config, buf);
            t = new KWrite(docList[cg.ReadEntry("DocumentNumber", 0) - 1]);
            t.Restore(config, z);
        }
    }