Ejemplo n.º 1
0
void KatePluginHelloWorld::slotInsertHello()
{
  if (!application()->activeMainWindow())
    return;

  Kate::View *kv = application()->activeMainWindow()->viewManager()->activeView();

  if (kv)
    kv->insertText ("Hello World");
}
Ejemplo n.º 2
0
void KateFileList::slotViewChanged()
{
    if(!viewManager->activeView())
        return;

    Kate::View *view = viewManager->activeView();
    uint dn = view->getDoc()->documentNumber();

    QListViewItem *i = firstChild();
    while(i)
    {
        if(((KateFileListItem *)i)->documentNumber() == dn)
        {
            break;
        }
        i = i->nextSibling();
    }

    if(!i)
        return;

    KateFileListItem *item = (KateFileListItem *)i;
    setCurrentItem(item);

    // ### During load of file lists, all the loaded views gets active.
    // Do something to avoid shading them -- maybe not creating views, just
    // open the documents???


    //   int p = 0;
    //   if (  m_viewHistory.count() )
    //   {
    //     int p =  m_viewHistory.findRef( item ); // only repaint items that needs it
    //   }

    m_viewHistory.removeRef(item);
    m_viewHistory.prepend(item);

    for(uint i = 0; i < m_viewHistory.count(); i++)
    {
        m_viewHistory.at(i)->setViewHistPos(i + 1);
        repaintItem(m_viewHistory.at(i));
    }
}
Ejemplo n.º 3
0
void PluginKateHtmlTools::slipInHTMLtag (Kate::View & view, QString text)  //  PCP
{

  //  We must add a heavy elaborate HTML markup system. Not!

  QStringList list = QStringList::split (' ', text);
  QString marked = view.getDoc()->selection ();
  uint preDeleteLine = 0, preDeleteCol = 0;
  view.cursorPosition (&preDeleteLine, &preDeleteCol);

  if (marked.length() > 0)
    view.keyDelete ();
  uint line = 0, col = 0;
  view.cursorPosition (&line, &col);
  QString pre ("<" + text + ">");
  QString post;
  if (list.count () > 0)  post = "</" + list[0] + ">";
  view.insertText (pre + marked + post);

  //  all this muck to leave the cursor exactly where the user
  //  put it...

  //  Someday we will can all this (unless if it already
  //  is canned and I didn't find it...)

  //  The second part of the if disrespects the display bugs
  //  when we try to reselect. TODO: fix those bugs, and we can
  //  un-break this if...

  if (preDeleteLine == line && -1 == marked.find ('\n'))
    if (preDeleteLine == line && preDeleteCol == col)
        {
        view.setCursorPosition (line, col + pre.length () + marked.length () - 1);

        for (int x (marked.length());  x--;)
                view.shiftCursorLeft ();
        }
    else
        {
        view.setCursorPosition (line, col += pre.length ());

        for (int x (marked.length());  x--;)
                view.shiftCursorRight ();
        }

}
Ejemplo n.º 4
0
/**
 * Moves the cursor to a given position.
 * @param	nLine	The cursor's new line number
 * @param	nCol	The cursor's new column number
 * @return	true if successful, false otherwise (cursor interface was not
 *			obtained)
 */
bool EditorPage::setCursorPos(uint nLine, uint nCol)
{
	Kate::View* pKateView;
	KTextEditor::ViewCursorInterface* pCursorIf;
	
	// Cannot accept line 0
	if (nLine == 0)
		return false;
	
	// Adjust to 0-based counting
	nLine--;
	nCol--;
		
	// Acquire the view cursor
	pCursorIf = dynamic_cast<KTextEditor::ViewCursorInterface*>(m_pView);
	if (pCursorIf == NULL)
		return false;
	
	// NOTE: The following code is a fix to a bug in Kate, which wrongly
	// calculates the column number in setCursorPosition.
	pKateView = dynamic_cast<Kate::View*>(m_pView);
	if (pKateView != NULL) {
		KTextEditor::EditInterface* pEditIf;
		const char* szLine;
		uint nRealCol;
		uint nTabAdjust;
		
		// Get a pointer to the edit interface
		pEditIf = dynamic_cast<KTextEditor::EditInterface*>(m_pDoc);
		if (!pEditIf)
			return false;
		
		nRealCol = 0;
		
		// Check for out of bound line numbers
		if (nLine < pEditIf->numLines()) {
			// Get the contents of the requested line
			szLine = pEditIf->textLine(nLine).latin1();
			
			// Check for empty line
			if (szLine != NULL) {
				// The number of columns which a tab character adds
				nTabAdjust = pKateView->tabWidth() - 1;
				
				// Calculate the real column, based on the tab width
				for (; nRealCol < nCol && szLine[nRealCol] != 0; nRealCol++) {
					if (szLine[nRealCol] == '\t')
						nCol -= nTabAdjust;
				}
			}
		}
		else {
			// Marker set beyond end of file, move to the last line
			nLine = pEditIf->numLines() - 1;
		}
		// Set the cursor position
		pCursorIf->setCursorPositionReal(nLine, nRealCol);
	}
	else {
		// Non-Kate editors: set the cursor position normally
		pCursorIf->setCursorPosition(nLine, nCol);
	}
	
	return true;
}