KTextEditor::View* EditorTabWidget::openKDocument(KURL url)
{
  QWidget* tab = new QWidget(this);
  QVBoxLayout *lay = new QVBoxLayout(tab, 1, 1);

  KTextEditor::Document *doc =
    KTextEditor::EditorChooser::createDocument(
      0L, "KTextEditor::Document");

  if(!doc->openURL(url)) {
    delete tab;
    delete doc;
    return NULL;
  }

  KTextEditor::View * view = doc->createView(tab);

  lay->addWidget(view);
  insertTab(tab, url.fileName());
  setCurrentPage(count()-1);
  return view;
}
Example #2
0
void
FileManager::showInEditor(const KURL& url)
{
    for (std::list<ManagedFileInfo*>::iterator mfi = files.begin();
         mfi != files.end(); ++mfi)
        if ((*mfi)->getFileURL() == url)
        {
            if (!(*mfi)->getEditor())
            {
                // The file has not yet been loaded, so we create an editor for
                // it.
                KTextEditor::Document* document;
                if (!(document = KTextEditor::EditorChooser::createDocument
                      (viewStack, "KTextEditor::Document", "Editor")))
                {
                    KMessageBox::error
                        (viewStack,
                         i18n("A KDE text-editor component could not "
                              "be found; please check your KDE "
                              "installation."));
                    return;
                }
                if (!editorConfigured)
                {
                    if (!KTextEditor::configInterface(document))
                    {
                        KMessageBox::error
                            (viewStack,
                             i18n("You have selected a KDE Editor component "
                                  "that is not powerful enough for "
                                  "TaskJuggler. "
                                  "Please select the 'Embedded Advanced Text "
                                  "Editor' component in the KDE Control "
                                  "Panel."));
                        return;
                    }
                    KTextEditor::configInterface(document)->readConfig(config);
                    editorConfigured = true;
                }

                KTextEditor::View* editor =
                    document->createView(viewStack);
                viewStack->addWidget(editor);
                (*mfi)->setEditor(editor);
                editor->setMinimumSize(400, 200);
                editor->setSizePolicy(QSizePolicy(QSizePolicy::Maximum,
                                                  QSizePolicy::Maximum, 0, 85,
                                                  editor->sizePolicy()
                                                  .hasHeightForWidth()));
                document->openURL(url);
                document->setReadWrite(true);
                document->setModified(false);

                // Signal to update the file-modified status
                connect(document, SIGNAL(textChanged()),
                        *mfi, SLOT(setModified()));

                connect(document,
                        SIGNAL(modifiedOnDisc(Kate::Document*, bool,
                                              unsigned char)),
                        *mfi,
                        SLOT(setModifiedOnDisc(Kate::Document*, bool,
                                               unsigned char)));

                /* Remove some actions of the editor that we don't want to
                 * show in the menu/toolbars */
                KActionCollection* ac = editor->actionCollection();
                if (ac->action("file_print"))
                    ac->remove(ac->action("file_print"));
                if (ac->action("view_folding_markers"))
                    ac->action("view_folding_markers")->
                        setShortcut(KShortcut());
                if (ac->action("view_border"))
                    ac->action("view_border")->setShortcut(KShortcut());
                if (ac->action("view_line_numbers"))
                    ac->action("view_line_numbers")->setShortcut(KShortcut());
                if (ac->action("view_dynamic_word_wrap"))
                    ac->action("view_dynamic_word_wrap")->
                        setShortcut(KShortcut());

/*                KActionPtrList actionList =
                    editor->actionCollection()->actions();
                for (KActionPtrList::iterator it = actionList.begin();
                     it != actionList.end(); ++it)
                {
                    printf("** Action found: %s\n", (*it)->name());
                }*/
            }
            viewStack->raiseWidget((*mfi)->getEditor());

            browser->clearSelection();
            QListViewItem* lvi = (*mfi)->getBrowserEntry();
            if (lvi)
            {
                browser->setCurrentItem(lvi);
                lvi->setSelected(true);
            }

            break;
        }