• Passive Notifications in Kate Part

    by  • November 6, 2012 • Developers, Users • 14 Comments

    In KDE 4.10, Kate Part got a new MessageInterface. The idea of this interface is to have a standardized way of showing notifications in a non-intrusive way, similar to how KMessageWidget in kdelibs works. Using the MessageInterface is extremly easy, for instance to show a quick notification, you write

    KTextEditor::Message *message = new KTextEditor::Message(KTextEditor::Message::Positive,
                                                             "Code successfully reformated.");
    document->postMessage(message);

    That’s basically it! The result looks like this (with a nice fade-in and fade-out animation):

    As developer, once you called postMessage(), you can safely forget the message pointer. It’s automatically deleted either if the user closes the notification, or if the document is closed or reloaded. The API for more tricks. You can add multiple actions through KTextEditor::Message::addAction(), which then appear as buttons. For each added action, you can control whether triggering the action should close the widget or not.

    Further, you can set an auto hide timer through Message::setAutoHide(int timeInMilliSeconds).

    If you want a message to only appear in one specific KTextEditor::View of the Document, you just call Message::setView() before calling postMessage(). If several messages are in the queue, the one with the highest Message::priority() is shown first.

    This notification system is already used in Kate Part by the data recovery (swap files), or to show a notification when loading remote files, and in some other places.

    The cool thin is that this solution requires no special code in KateView or other classes, hence, it’s a perfectly clean solution with an easy-to-use API. You as KTextEditor user (developer) should definitely consider using it when it’s public.

    Note: The MessageInterface is a KTextEditor interface; however, since the 4.10 branch is frozen for BIC changes, we cannot just add this interface for KDE 4.10. Instead, for Kate Part users (Kile, KDevelop, …) this interface will only be available in KDE5.

    Finally, an example of all four message types: Positive, Information, Warning and Error:

    About

    Dominik is a PhD student at the Control Theory and Robotics Lab, TU Darmstadt, as part of the Research Training Group GKMM (GRK1362). My research focuses on state estimation in distributed systems. As hobby, I contribute to the KDE project and work on the Kate application and editor component.

    http://www.kate-editor.org

    14 Responses to Passive Notifications in Kate Part

    1. November 6, 2012 at 14:32

      So, do I understand correctly that tis does not use KMessageWidget internally? If no, what is the reason?

      Of course, this is a very welcome addition, I just want to make sure I understand the implementation details right.

      Thank you!

      • November 6, 2012 at 14:37

        It uses KMessageWidget internally, that’s also why we have the same message types (Positive, Information, Warnung, Error) :-) The MessageInterface is just an easy to use thin wrapper that completely hides the implementation. So no worries!

    2. KillerCookie
      November 6, 2012 at 14:36

      Well done – the notifications look very nice.

      Some small suggestion: The spacing between the notification and the window-border should be equal to other elements. For example: The Text-Input-Area has more space to the left window-border than the notifications. At the right side the notification should not be wider as the scrollbar.

      Another small one: The spacing between the notification and the text-input-area should match the spacing to the borders.

      I believe with those two little changes it would look even better. :) )

      • November 6, 2012 at 14:40

        Right, I’ll probably take a look into this in the evening.

    3. Pedro Alves
      November 6, 2012 at 15:05

      The “[X] Some error occurred… (X)” notification has a significant usability issue IMO. I trip on it on Dolphin all the time.

      The red square with white cross sign on the left looks too much like the red circle with white cross on the left.
      I frequently try to click the left square to dismiss the notification, thinking that’s a clickable button. But it’s not…
      Worse, the left square, being close to the text, on the left, tends to be closer to your point of eye focus, than the circle on the right, which with a wide enough window/screen, is almost on peripheral vision …

      • November 6, 2012 at 15:29

        If this is really an issue, then it’s an issue of KMessageWidget. Still, I’m not convinced that this is really a usability issue. The actions including Close are all buttons intentionally, and thus distinct from the rest of the widget :-)

      • Wolfgang Mader
        November 6, 2012 at 16:04

        I can not back up my view with a study, but I would follow Pedro Alves in this point. In KWrite, for example, the “red square with white cross”-icon is used, if “Quit” is added to the toolbar. As a suggestion, the complete notification area can be made clickable. A button would be cleaned from the interface, but perhaps discoverability of how to interact with the widget is lost.

      • November 6, 2012 at 17:22

        I don’t know if I’m just another exception or whether it is really a usability issue, but I also agree with Pedro. Although I implemented the code in Dolphin to use KMessageWidget and did quite a lot tests with it, I still regularly click on the left ‘X’-icon instead on the right close-button. But as Dominik said: This must be handled inside KMessageWidget and submitting a request at bugs.kde.org would be useful (sadly I cannot do this myself anymore as I cannot promise having enough time for being responsive for any discussions on the submitted bug).

        • November 6, 2012 at 18:48

          Hi Peter and others, thanks for your input. I wouldn’t have thought that so many of you (even developers) run into this problem. Maybe it’s really an issue. But then, I’m not an expert, so I’d like to point you all to bugs.kde.org and open a report :-)

          @Wolfgang: Making the entire area clickable is not really intuitive either imo, besides, we sometimes have more than one button, and e.g. if you make the entire area clickable, it’s not clear which action would be executed (think of the abort loading thing).

        • November 9, 2012 at 10:26

          Peter, another question: In dolphinviewcontainer.cpp, you have the code

          264 m_messageWidget->setWordWrap(false);
          265 const int unwrappedWidth = m_messageWidget->sizeHint().width();
          266 m_messageWidget->setWordWrap(unwrappedWidth > size().width());

          Does this really work? If so, I’d consider using this as well, if the widget does not fit.

          • November 25, 2012 at 15:05

            to answer my own question: no, it does not work, at least not in Kate…

    4. November 9, 2012 at 09:52

      What always bothers me is the coloring in that widget. Blue and green looks good but red and yellow are plain. I hope the widget on KDE side can be fixed for it. Meaning, red needs to be darker so it is visually stronger and white text on it. And green should be darker as well with white text.

      What comes to icons on left, I would just make them bigger so they don’t look like a buttons. And then add right a button “close” instead a X.

      Of cource none of these are possible to solve by Kate Devs in here.

      • November 9, 2012 at 09:54

        Sorry about button. Just waked and hard still to concentrate ;-)

      • kbroulik
        November 25, 2012 at 15:30

        Well, that is not an issue of the KMessageWidget but more of the oxygen color scheme / default settings.
        KMessageWidget just uses getColorsFromColorScheme(KColorScheme::NegativeBackground, &bg1, &fg); for the color (and adds a faint gradient to it), so you can change that color in System Settings → Application Appearance → Colors → Color selection → “Negative Background”