Beispiel #1
0
/*
 * show all the commands supported by KTextEditor
 * It's a debug function
 */
void EditorPage::aboutCommand()
{
    KTextEditor::Editor *editor = m_pDoc->editor();
    KTextEditor::CommandInterface *iface = qobject_cast<KTextEditor::CommandInterface *>(editor);

    if (iface == NULL) {
        qDebug("CommandInterface cast failed");
        return;
    }

    QString msg;
    const QString cmd("set-tab-width");
    KTextEditor::Command *pcmd = iface->queryCommand(cmd);
    QStringList list = pcmd->cmds();

#if 0
    for (int i = 0; i < list.size(); i++)
        qDebug("cmd: %s", list[i].toAscii().data());
#endif

    if (pcmd) {
        pcmd->help(m_pView, cmd, msg);
        qDebug("%s", msg.toAscii().data());
    } else {
        qDebug("no this cmd");
    }
}
Beispiel #2
0
KateAppCommands::~KateAppCommands()
{
    KTextEditor::Editor *editor = KateDocManager::self()->editor();
    KTextEditor::CommandInterface *iface = qobject_cast<KTextEditor::CommandInterface*>(editor);

    if (iface) {
        iface->unregisterCommand(this);
    }

    m_instance = 0;
}
TextEditor::TextEditor(KTextEditor::Document *editorPart, PackageModel *model, QWidget *parent)
        : QWidget(parent)
{
    QHBoxLayout *l = new QHBoxLayout(this);

    QWidget *centralWidget = editorPart->widget();
    KTextEditor::View *view = qobject_cast<KTextEditor::View*>(centralWidget);
    if (view) {
        view->setContextMenu(view->defaultContextMenu());

        //modify the toolbar
        modifyToolBar(view);

        KTextEditor::ConfigInterface *config = qobject_cast<KTextEditor::ConfigInterface*>(view);
        if (config) {
            config->setConfigValue("line-numbers", true);
            config->setConfigValue("dynamic-word-wrap", true);
        }

        config = dynamic_cast<KTextEditor::ConfigInterface*>(editorPart);
        if (config) {
            config->setConfigValue("backup-on-save-prefix", ".");
        }

        // set nice defaults for katepart
        KTextEditor::CommandInterface *command = dynamic_cast<KTextEditor::CommandInterface *>(editorPart->editor());
        QString ret;
        if (command) { //generic
            command->queryCommand("set-indent-mode")->exec(view, "set-indent-mode normal", ret); // more friendly
            command->queryCommand("set-replace-tabs")->exec(view, "set-replace-tabs 1", ret);// replaces tabs with spaces????
            command->queryCommand("set-indent-width")->exec(view, "set-indent-width 4", ret);//4 spaces, Plasma's general coding style
        }

        //we should be setting the specific editing indentation, highlighting based on the type of document
        if (model->implementationApi() == "declarativeappletscript" || model->implementationApi() == "javascript") {
            editorPart->setHighlightingMode("JavaScript");
        } else if (model->implementationApi() == "ruby-script") {
            editorPart->setHighlightingMode("ruby");
            if (command) {
                command->queryCommand("set-indent-width")->exec(view, "set-indent-width 2", ret);// 2 spaces recommended for ruby
            }
        }
        //there is no need for one more control. But we keep the code because it is easier to understand.
        //so keep the generic format.
        /*} else if (editorPart->setHighlightingMode() == "python") {
            continue;
            // Q: why we don't change the spaces?
            // A: 4 spaces are recommended for python
        }*/

    }

    l->addWidget(centralWidget);
}
Beispiel #4
0
void EditorPage::setTabWidth(uint nTabWidth)
{
	KTextEditor::CommandInterface *pCmdIf;
	KTextEditor::Command *pKateCmd;
	QString sCmd, sResult;

	pCmdIf = qobject_cast<KTextEditor::CommandInterface *>(KTextEditor::EditorChooser::editor());
	if ( pCmdIf && (pKateCmd = pCmdIf->queryCommand("set-tab-width"))) {
		sCmd.sprintf("set-tab-width %u", nTabWidth);
		pKateCmd->exec(m_pView, sCmd, sResult);
	}
}
Beispiel #5
0
// set Tab charactor's width (4 / 8 or else)
void EditorPage::setTabWidth(uint nTabWidth)
{
    KTextEditor::Editor *editor = m_pDoc->editor();
    KTextEditor::CommandInterface *iface = 
        qobject_cast<KTextEditor::CommandInterface *>(editor);

	QString sCmd, sResult;
    const QString cmd("set-tab-width");
    KTextEditor::Command *pCmd = iface->queryCommand(cmd);

    if (pCmd) {
		sCmd.sprintf("set-tab-width %u", nTabWidth);
		if (pCmd->exec(m_pView, sCmd, sResult) == false) {
            qDebug("set tab width failed: %s", sResult.toAscii().data());
        }
    } else {
        qDebug("no this cmd");
    }
}
Beispiel #6
0
KateAppCommands::KateAppCommands()
    : KTextEditor::Command()
{
    KTextEditor::Editor *editor = KateDocManager::self()->editor();
    KTextEditor::CommandInterface *iface = qobject_cast<KTextEditor::CommandInterface*>(editor);

    if (iface) {
        iface->registerCommand(this);
    }

    re_write.setPattern("w(a)?");
    re_close.setPattern("bd(elete)?|tabc(lose)?");
    re_quit.setPattern("(w)?q?(a)?");
    re_exit.setPattern("x(a)?");
    re_edit.setPattern("e(dit)?|tabe(dit)?|tabnew");
    re_new.setPattern("(v)?new");
    re_split.setPattern("sp(lit)?");
    re_vsplit.setPattern("vs(plit)?");
    re_only.setPattern("on(ly)?");
}