GtkShortcutsWindow how to

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

GtkShortcutsWindow how to

Ondrej Tuma-2
Hi there,

i try to create ShortcutsWindow for my application but,
in documentation is:

The recommended way to construct a GtkShortcutsWindow is with
GtkBuilder, by populating a GtkShortcutsWindow with one or more
GtkShortcutsSection objects, which contain GtkShortcutsGroups that in
turn contain objects of class GtkShortcutsShortcut.

At first, is very sad, that it not possible to create ShortcutsWindow
without user interface file. May be, it is possible, but documentation
conceals about that. The last way is study source code, which is wrong!

Why I try to create GtkShortcutsWindow without ui data file? Because my
application don't have any data files now.

Ok, let's create data file with my favorite editor (no other is not
exists what I know) glade. But, glade does not support any Shortcuts
widget.

So that is really means seriously, that application authors must create
this data files by hand in theirs text/xml editors?

--
Ondřej Tůma <[hidden email]>
www: http://ipv6.mcbig.cz   jabber: [hidden email]   twitter: mcbig_cz

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
'-'
Reply | Threaded
Open this post in threaded view
|

Re: GtkShortcutsWindow how to

'-'
Hello,

See object hierarchy on the documentation page. GtkShortcutsWindow
inherits from GtkContainer, suggesting you treat it like a regular box.
UI data files are good for examples, because you immediately see the
widget hierarchy, which can be hard to follow in flat code. Here is
how you can "translate" a part of the example shortcuts window UI:

```javascript
#!/usr/bin/gjs

const {
   Application,
   ShortcutsGroup,
   ShortcutsSection,
   ShortcutsShortcut,
   ShortcutsWindow
} = imports.gi.Gtk;

imports.gi.Gtk.init(null);

const application = new Application();

/** @type {ApplicationWindow} */
let win;

application.connect("startup", () => {
   win = new ShortcutsWindow({ application });

   const editor = new ShortcutsSection();
   editor.title = "Editor shortcuts"; // Used in header.
   editor.visible = true; // Seems required here.
   win.add(editor);

   const doc = new ShortcutsGroup();
   doc.title = "Document";
   editor.add(doc);

   const create = new ShortcutsShortcut();
   create.accelerator = "<ctrl>n";
   create.title = "Create new document";
   doc.add(create);

   const open = new ShortcutsShortcut();
   open.accelerator = "<ctrl>o";
   open.title = "Open a document";
   doc.add(open);
});

application.connect("activate", () => {
   win.show_all();
});

application.run(ARGV);
```

I don't know though, how to get search to work in this. Please share the
setup if you succesfully implement it in your window!

Cheers,
Makepost

On 2018-01-09 14:04, Ondrej Tuma wrote:

> Hi there,
>
> i try to create ShortcutsWindow for my application but,
> in documentation is:
>
> The recommended way to construct a GtkShortcutsWindow is with
> GtkBuilder, by populating a GtkShortcutsWindow with one or more
> GtkShortcutsSection objects, which contain GtkShortcutsGroups that in
> turn contain objects of class GtkShortcutsShortcut.
>
> At first, is very sad, that it not possible to create ShortcutsWindow
> without user interface file. May be, it is possible, but documentation
> conceals about that. The last way is study source code, which is wrong!
>
> Why I try to create GtkShortcutsWindow without ui data file? Because my
> application don't have any data files now.
>
> Ok, let's create data file with my favorite editor (no other is not
> exists what I know) glade. But, glade does not support any Shortcuts
> widget.
>
> So that is really means seriously, that application authors must create
> this data files by hand in theirs text/xml editors?
>
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: GtkShortcutsWindow how to

Ondrej Tuma-2
Thanks a lot! It works!

Searching is simple, it is about adding section to window. All what is
in section when you add section to window is searchable. So simple fix
is append section to window at and of your on-startup function :-)

Ondra

V Tue, 09 Jan 2018 15:43:02 +0200
'-' <[hidden email]> napsáno:

> Hello,
>
> See object hierarchy on the documentation page. GtkShortcutsWindow
> inherits from GtkContainer, suggesting you treat it like a regular
> box. UI data files are good for examples, because you immediately see
> the widget hierarchy, which can be hard to follow in flat code. Here
> is how you can "translate" a part of the example shortcuts window UI:
>
> ```javascript
> #!/usr/bin/gjs
>
> const {
>    Application,
>    ShortcutsGroup,
>    ShortcutsSection,
>    ShortcutsShortcut,
>    ShortcutsWindow
> } = imports.gi.Gtk;
>
> imports.gi.Gtk.init(null);
>
> const application = new Application();
>
> /** @type {ApplicationWindow} */
> let win;
>
> application.connect("startup", () => {
>    win = new ShortcutsWindow({ application });
>
>    const editor = new ShortcutsSection();
>    editor.title = "Editor shortcuts"; // Used in header.
>    editor.visible = true; // Seems required here.
>    win.add(editor);
>
>    const doc = new ShortcutsGroup();
>    doc.title = "Document";
>    editor.add(doc);
>
>    const create = new ShortcutsShortcut();
>    create.accelerator = "<ctrl>n";
>    create.title = "Create new document";
>    doc.add(create);
>
>    const open = new ShortcutsShortcut();
>    open.accelerator = "<ctrl>o";
>    open.title = "Open a document";
>    doc.add(open);
> });
>
> application.connect("activate", () => {
>    win.show_all();
> });
>
> application.run(ARGV);
> ```
>
> I don't know though, how to get search to work in this. Please share
> the setup if you succesfully implement it in your window!
>
> Cheers,
> Makepost
>
> On 2018-01-09 14:04, Ondrej Tuma wrote:
> > Hi there,
> >
> > i try to create ShortcutsWindow for my application but,
> > in documentation is:
> >
> > The recommended way to construct a GtkShortcutsWindow is with
> > GtkBuilder, by populating a GtkShortcutsWindow with one or more
> > GtkShortcutsSection objects, which contain GtkShortcutsGroups that
> > in turn contain objects of class GtkShortcutsShortcut.
> >
> > At first, is very sad, that it not possible to create
> > ShortcutsWindow without user interface file. May be, it is
> > possible, but documentation conceals about that. The last way is
> > study source code, which is wrong!
> >
> > Why I try to create GtkShortcutsWindow without ui data file?
> > Because my application don't have any data files now.
> >
> > Ok, let's create data file with my favorite editor (no other is not
> > exists what I know) glade. But, glade does not support any Shortcuts
> > widget.
> >
> > So that is really means seriously, that application authors must
> > create this data files by hand in theirs text/xml editors?
> >
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > [hidden email]
> > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list 


--
Ondřej Tůma <[hidden email]>
www: http://ipv6.mcbig.cz   jabber: [hidden email]   twitter: mcbig_cz

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list