Category Archives: Developers

GSoC – Swap Files for Kate

Hello,

As mid-term evaluations have started, I would like to show my current state of GSoC project, because I’ve never found the time to do it.

The swap file feature is implemented, except for the view differences feature and few TODOs. Some more testing need to be done, though. Below are some screenshots of how it works.

When you start editing in a document, a swap file for the document is created (“.swp.originalFileName”). If Kate crashes and the user didn’t save the changes, the swap file remains on the disk.

On the load of the original file, Kate checks if there is a swap file on the disk, and if it is, a warning bar pops from the top, asking if you either want to recover the data loss, discard it or view differences. If the recover button is pressed, the lost data is replayed. Otherwise, if the discard button is pressed, the swap file is removed from the disk. This also happens on normal close and on save of the original file.

Many thanks to Christoph and Dominik who helped me get it through.

Kate: Scripted Actions

Finally, I came around to implement scripted actions for Kate in KDE SC 4.6. Let’s take a look at how this works. When Kate starts, it searches for $KDEDIRS/share/apps/katepart/script/ for *.js files. As example, let’s take a look at utils.js there:

/* kate-script
 * author: Dominik Haumann
 * license: LGPL
 * revision: 3
 * kate-version: 3.4
 * type: commands
 * functions: moveLinesDown
 */

function moveLinesDown()
{
  var fromLine = -1;
  var toLine = -1;

  var selectionRange = view.selection();
  if (selectionRange.isValid() &&
      selectionRange.end.line < document.lines() - 1)
  {
    toLine = selectionRange.start.line;
    fromLine = selectionRange.end.line + 1;
  } else if (view.cursorPosition().line < document.lines() - 1) {
    toLine = view.cursorPosition().line;
    fromLine = toLine + 1;
  }

  if (fromLine != -1 && toLine != -1) {
    var text = document.line(fromLine);

    document.editBegin();
    document.removeLine(fromLine);
    document.insertLine(toLine, text);
    document.editEnd();
  }
}

function action(cmd)
{
  var a = new Object();
  if (cmd == "moveLinesDown") {
    a.text = i18n("Move Lines Down");
    a.icon = "";
    a.category = "";
    a.interactive = false;
    a.shortcut = "";
  }

  return a;
}

function help(cmd)
{
  if (cmd == "moveLinesDown") {
    return i18n("Move selected lines down.");
  }
}

What happens is the following:

  1. the header tells kate that there is an exported function “moveLinesDown”
  2. so when Kate Part is loaded, it calls “action(moveLinesDown)” to check whether this function should be exposed in the GUI. Here, we return the action info that includes the displayed text, an icon, a category, whether the script needs user input (interactive) and a default shortcut. Of course, you can change the shortcuts, and also configure the toolbars to show the actions.

With this, every user is able to script arbitrary editing functions for Kate Part. We don’t have to implement all those helpers in C++ anymore. The result looks like this:
You can have this already now, you just have to use the development version of Kate :)

A Flashback of Kate in Gitorious

Back in February, I blogged about Kate’s move to gitorious. The main reason for this move was to make building Kate as easy as possible. If you want to build Kate as part of KDE, (as of now) you have to compile kdesupport, phonon, dbusmenu-qt, kdelibs, kdepimlibs, kdebase for kwrite and kdesdk for the kate application. Getting all this done is a huge effort, especially if you are new to KDE development (I very well remember my own times spending weeks to get everything going. Be aware of new contributors might now close to nothing about KDE and all the dependencies!).
As getting new contributors is essential for keeping a project alive, the barrier to get involved should be as low as possible. And exactly this was achieved by moving all pieces to one place (this was gitorious for us). Building Kate is so simple right now that we can even make bug reporters build Kate out of the box. This helps a lot, and even results in patches from time to time. We also got quite some merge requests.
There were several voices at that time that considered moving “away from KDE” was very bad. However, this is not the case, as Christoph is synchronizing all the changes in KDE’s subversion and gitorious almost every day. This is certainly not optimal, but looking back at the last months, we can say it was worth it.
KDE is moving to git.kde.org in the near future. This also raises the discussion about how KDE’s source code will be organized. Speaking for Kate, we certainly want to have all of Kate’s code in one place, just as it is now with gitorious, no matter what :) I hope we can find a solution the KDE community can live with. To be discussed, maybe in Tampere in two weeks? :)

Debugging Kate with Qt Creator

Let’s have a quick look at how to debug Kate and KWrite with Qt Creator. First, make sure you meet the requirements:

  1. build Kate according to this tutorial
  2. install Qt-Creator (in my case this is version 2.0.0)

Setup the Kate project Qt-Creator once like this

  1. start Qt-Creator like this (important to get all environment variables right):
    ~/kde/run.sh /path/to/qtcreator/bin/qtcreator
  2. invoke File > Open File or Project and choose ~/kde/kate/CMakeLists.txt
  3. Build Location: choose ~/kde/build
  4. Run CMake arguments: type
    ../kate -DCMAKE_BUILD_TYPE=debugfull -DCMAKE_INSTALL_PREFIX=~/kde/usr
  5. click the button “Run CMake” and then “Finish”

Start debugging like this

  1. click the (C) “hammer” icon button on the very bottom left to compile Kate
  2. click the (B) “computer” icon button and choose “kate” (or “kwrite”) in the Run combo box
  3. choose the (A) “Debug” icon in the left pane
  4. invoke “Debug > Start Debugging (F5)”, now Kate starts
  5. open part/document/katedocument.cpp in the file tree view on the left
  6. go to the line “KateDocument::insertText” and click “Debug > Toggle Breakpoint (F9)”
  7. now if you type a character in Kate, Qt-Crator will halt in KateDocument::insertText
  8. chose “Debug > Step Opver (F10)” (and “Debug > Stip Into (F11)”) to step through the code
  9. click on “Locals and Watchers” in the debugging pane on the bottom and you see the values of local variables

Happy debugging! :)