From kwin Fri Aug 31 14:12:16 2012 From: =?utf-8?q?Martin_Gr=C3=A4=C3=9Flin?= Date: Fri, 31 Aug 2012 14:12:16 +0000 To: kwin Subject: Re: Review Request: Allow Scripts to add menus to the UserActionsMenu Message-Id: <20120831141216.2302.90132 () vidsolbach ! de> X-MARC-Message: https://marc.info/?l=kwin&m=134642235018326 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============2479638328814384525==" --===============2479638328814384525== Content-Type: multipart/alternative; boundary="===============3131365120729628983==" --===============3131365120729628983== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://git.reviewboard.kde.org/r/106285/ ----------------------------------------------------------- (Updated Aug. 31, 2012, 2:12 p.m.) Review request for kwin. Changes ------- * removed some no longer needed code * using references to QScriptValue in the methods * added code documentation Description ------- Allow Scripts to add menus to the UserActionsMenu A script can register a callback through registerUserActionsMenu to be informed when the UserActionsMenu is about to be shown. This menu calls the Scripting component to gather actions to add to a Scripts submenu. The Scripting component now asks all scripts for the actions, which will invoke the registered callbacks with the Client for which the menu is to be shown as argument. The callback is supposed to return a JSON structure describing how the menu should look like. The returned object can either be a menu item or a complete menu. If multiple menu items or menus are supposed to be added by the script it should just register multiple callbacks. The structure for an item looks like the following: { text: "My caption", checkable: true, checked: false, triggered: function (action) { print("The triggered action as parameter"); } } The structure for a complete menu looks quite similar: { text: "My menu caption", items: [ {...}, {...} // items as described above ] } The C++ part of the script parses the returned object and generates either QAction or QMenu from it. All objects become children of the scripts QMenu provided by the UserActionsMenu. Before the menu is shown again the existing menu is deleted to ensure that no outdated values from no longer existing scripts are around. This means the scripts are queried each time the menu is shown. FEATURE: 303756 FIXED-IN: 4.10 This addresses bug 303756. http://bugs.kde.org/show_bug.cgi?id=3D303756 Diffs (updated) ----- kwin/scripting/documentation-global.xml 0b1c05869e1279ef4a38b0a559e22f9da= 8fb933e = kwin/scripting/scripting.h d48b3699b2d847dfd51fc84287f57c3fb441982f = kwin/scripting/scripting.cpp 8786bce8dcee01e1bb12ea5d6cb198474b90e993 = kwin/scripting/scriptingutils.h ff8f99fa44ff2c101a61249b0555962b5a853f4d = kwin/useractions.h 094a614ef4c94424968cf230e376e2f1a8615245 = kwin/useractions.cpp ea0071741e5b313ed9857bbaca4da734ec1e0089 = kwin/workspace.h fdd2223e578324f1b309feec5fe796d0ec73d7d5 = Diff: http://git.reviewboard.kde.org/r/106285/diff/ Testing ------- registerUserActionsMenu(function (client) { var opacity =3D Math.round(client.opacity*100); return { text: "Window Opacity", items: [{ text: "100 %", checkable: true, checked: opacity =3D=3D 100, triggered: function () { client.opacity =3D 1.0; } }, { text: "75 %", checkable: true, checked: opacity =3D=3D 75, triggered: function () { client.opacity =3D 0.75; } }, { text: "50 %", checkable: true, checked: opacity =3D=3D 50, triggered: function () { client.opacity =3D 0.5; } }, { text: "25 %", checkable: true, checked: opacity =3D=3D 25, triggered: function () { client.opacity =3D 0.25; } }, { text: "10 %", checkable: true, checked: opacity =3D=3D 10, triggered: function () { client.opacity =3D 0.1; } } ] }; }); Thanks, Martin Gr=C3=A4=C3=9Flin --===============3131365120729628983== Content-Type: text/html; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable
This is an automatically generated e-mail. To reply, visit: http://git.revie= wboard.kde.org/r/106285/

Review request for kwin.
By Martin Gr=C3=A4=C3=9Flin.

Updated Aug. 31, 2012, 2:12 p.m.

Changes
* removed some no longer needed code
* using references to QScriptValue in the methods
* added code documentation

Descripti= on

Allow Scripts to add menus to the UserActionsMenu

A script can register a callback through registerUserActionsMenu to be
informed when the UserActionsMenu is about to be shown. This menu calls
the Scripting component to gather actions to add to a Scripts submenu.

The Scripting component now asks all scripts for the actions, which will
invoke the registered callbacks with the Client for which the menu is to
be shown as argument.

The callback is supposed to return a JSON structure describing how the
menu should look like. The returned object can either be a menu item or
a complete menu. If multiple menu items or menus are supposed to be added
by the script it should just register multiple callbacks.

The structure for an item looks like the following:
{
    text: "My caption",
    checkable: true,
    checked: false,
    triggered: function (action) {
       print("The triggered action as parameter");
    }
}

The structure for a complete menu looks quite similar:
{
    text: "My menu caption",
    items: [
         {...}, {...} // items as described above
    ]
}

The C++ part of the script parses the returned object and generates
either QAction or QMenu from it. All objects become children of the
scripts QMenu provided by the UserActionsMenu.

Before the menu is shown again the existing menu is deleted to ensure
that no outdated values from no longer existing scripts are around. This
means the scripts are queried each time the menu is shown.

FEATURE: 303756
FIXED-IN: 4.10

Testing <= /h1>
registerUserActionsMenu(function (client) {
  var opacity =3D Math.round(client.opacity*100);
  return {
    text: "Window Opacity",
    items: [{
      text: "100 %",
      checkable: true,
      checked: opacity =3D=3D 100,
      triggered: function () {
	client.opacity =3D 1.0;
      }
    }, {
      text: "75 %",
      checkable: true,
      checked: opacity =3D=3D 75,
      triggered: function () {
	client.opacity =3D 0.75;
      }
    }, {
      text: "50 %",
      checkable: true,
      checked: opacity =3D=3D 50,
      triggered: function () {
	client.opacity =3D 0.5;
      }
    }, {
      text: "25 %",
      checkable: true,
      checked: opacity =3D=3D 25,
      triggered: function () {
	client.opacity =3D 0.25;
      }
    }, {
      text: "10 %",
      checkable: true,
      checked: opacity =3D=3D 10,
      triggered: function () {
	client.opacity =3D 0.1;
      }
    }
    ]
  };
});
Bugs: 303756

Diffs= (updated)

  • kwin/scripting/documentation-global.xml (0= b1c05869e1279ef4a38b0a559e22f9da8fb933e)
  • kwin/scripting/scripting.h (d48b3699b2d847= dfd51fc84287f57c3fb441982f)
  • kwin/scripting/scripting.cpp (8786bce8dcee= 01e1bb12ea5d6cb198474b90e993)
  • kwin/scripting/scriptingutils.h (ff8f99fa4= 4ff2c101a61249b0555962b5a853f4d)
  • kwin/useractions.h (094a614ef4c94424968cf2= 30e376e2f1a8615245)
  • kwin/useractions.cpp (ea0071741e5b313ed985= 7bbaca4da734ec1e0089)
  • kwin/workspace.h (fdd2223e578324f1b309feec= 5fe796d0ec73d7d5)

View Diff

--===============3131365120729628983==-- --===============2479638328814384525== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kwin mailing list kwin@kde.org https://mail.kde.org/mailman/listinfo/kwin --===============2479638328814384525==--