Skip to content

Commit

Permalink
Add "New Window" and "Open in New Window"
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfactotum committed Jul 6, 2023
1 parent 727aedc commit 9587e5b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
12 changes: 9 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ApplicationWindow = GObject.registerClass({
})
this.content.child = this.#leaflet
utils.addMethods(this, {
actions: ['open', 'close', 'show-library', 'show-menu', 'open-copy'],
actions: ['open', 'close', 'show-library', 'show-menu', 'new-window', 'open-copy'],
props: ['fullscreened'],
})

Expand Down Expand Up @@ -137,12 +137,18 @@ const ApplicationWindow = GObject.registerClass({
showMenu() {
if (this.#bookViewer) this.#bookViewer.showPrimaryMenu()
}
openCopy() {
const { application, file } = this
addWindow(file) {
const { application } = this
const win = new ApplicationWindow({ application, file })
new Gtk.WindowGroup().add_window(win)
win.present()
}
newWindow() {
this.addWindow(null)
}
openCopy() {
this.addWindow(this.file)
}
})

export const Application = GObject.registerClass({
Expand Down
20 changes: 13 additions & 7 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ const BookList = GObject.registerClass({
else if (value) this.append(value)
}
}
getURI(identifier) {
getBook(file) {
const { identifier } = this.readFile(file)?.metadata ?? {}
return this.getBookFromIdentifier(identifier)
}
getBookFromIdentifier(identifier) {
// TODO: use tracker
return this.#uriStore.get(identifier)
const uri = this.#uriStore.get(identifier)
return uri ? Gio.File.new_for_uri(uri) : null
}
delete(file) {
const name = file.get_basename()
Expand Down Expand Up @@ -134,6 +139,7 @@ const BookItem = GObject.registerClass({
Template: pkg.moduleuri('ui/book-item.ui'),
InternalChildren: ['image', 'progress', 'title'],
Signals: {
'open-new-window': { param_types: [Gio.File.$gtype] },
'remove-book': { param_types: [Gio.File.$gtype] },
'export-book': { param_types: [Gio.File.$gtype] },
'book-info': { param_types: [Gio.File.$gtype] },
Expand All @@ -143,6 +149,7 @@ const BookItem = GObject.registerClass({
constructor(params) {
super(params)
this.insert_action_group('book-item', utils.addSimpleActions({
'open-new-window': () => this.emit('open-new-window', this.#item),
'remove': () => this.emit('remove-book', this.#item),
'export': () => this.emit('export-book', this.#item),
'info': () => this.emit('book-info', this.#item),
Expand All @@ -162,6 +169,7 @@ const BookRow = GObject.registerClass({
Template: pkg.moduleuri('ui/book-row.ui'),
InternalChildren: ['title', 'author', 'progress-grid', 'progress-bar', 'progress-label'],
Signals: {
'open-new-window': { param_types: [Gio.File.$gtype] },
'remove-book': { param_types: [Gio.File.$gtype] },
'export-book': { param_types: [Gio.File.$gtype] },
'book-info': { param_types: [Gio.File.$gtype] },
Expand All @@ -171,6 +179,7 @@ const BookRow = GObject.registerClass({
constructor(params) {
super(params)
this.insert_action_group('book-item', utils.addSimpleActions({
'open-new-window': () => this.emit('open-new-window', this.#item),
'remove': () => this.emit('remove-book', this.#item),
'export': () => this.emit('export-book', this.#item),
'info': () => this.emit('book-info', this.#item),
Expand Down Expand Up @@ -226,6 +235,7 @@ GObject.registerClass({
#filterModel = utils.connect(new Gtk.FilterListModel({ filter: this.#filter }),
{ 'items-changed': () => this.#update() })
#itemConnections = {
'open-new-window': (_, file) => this.root.addWindow(getBooks().getBook(file)),
'remove-book': (_, file) => this.removeBook(file),
'export-book': (_, file) => {
const data = getBooks().readFile(file)
Expand Down Expand Up @@ -357,11 +367,7 @@ export const Library = GObject.registerClass({
const books = getBooks()

utils.connect(this._books_view, {
'activate': (_, item) => {
const { identifier } = books.readFile(item)?.metadata ?? {}
const uri = books.getURI(identifier)
this.root.openFile(Gio.File.new_for_uri(uri))
},
'activate': (_, item) => this.root.openFile(books.getBook(item)),
'load-more': () => books.loadMore(1),
'load-all': () => books.loadMore(Infinity),
})
Expand Down
6 changes: 6 additions & 0 deletions src/ui/book-item.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><interface>
<menu id="menu">
<section>
<item>
<attribute name="label" translatable="yes">Open in New Window</attribute>
<attribute name="action">book-item.open-new-window</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">About This Book</attribute>
Expand Down
6 changes: 6 additions & 0 deletions src/ui/book-row.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><interface>
<menu id="menu">
<section>
<item>
<attribute name="label" translatable="yes">Open in New Window</attribute>
<attribute name="action">book-item.open-new-window</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">About This Book</attribute>
Expand Down
10 changes: 8 additions & 2 deletions src/ui/book-viewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
<menu id="book-menu">
<section>
<item>
<attribute name="label" translatable="yes">Reload</attribute>
<attribute name="action">view.reload</attribute>
<attribute name="label" translatable="yes">New Window</attribute>
<attribute name="action">win.new-window</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Open a Copy</attribute>
<attribute name="action">win.open-copy</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Reload</attribute>
<attribute name="action">view.reload</attribute>
</item>
</section>
<section>
<item>
Expand Down

0 comments on commit 9587e5b

Please sign in to comment.