-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add refill item to treatment menu
- Loading branch information
Showing
8 changed files
with
249 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using Gtk 4.0; | ||
using Adw 1; | ||
|
||
Adw.Dialog refillDialog { | ||
name: 'refill-dialog'; | ||
content-width: 424; | ||
title: _("Refill"); | ||
|
||
Adw.ToolbarView { | ||
[top] | ||
Adw.HeaderBar headerBar { | ||
show-start-title-buttons: false; | ||
show-end-title-buttons: false; | ||
decoration-layout: ''; | ||
|
||
[start] | ||
Button cancelButton { | ||
label: _("Cancel"); | ||
name: 'cancel'; | ||
} | ||
|
||
[end] | ||
Button saveButton { | ||
styles [ | ||
'suggested-action' | ||
] | ||
|
||
label: _("Save"); | ||
name: 'save'; | ||
} | ||
} | ||
|
||
content: ScrolledWindow { | ||
Adw.Clamp refillDialogClamp { | ||
maximum-size: 400; | ||
|
||
Box { | ||
orientation: vertical; | ||
margin-start: 10; | ||
margin-end: 10; | ||
margin-top: 15; | ||
margin-bottom: 20; | ||
|
||
ListBox { | ||
styles [ | ||
"boxed-list-separate" | ||
] | ||
|
||
selection-mode: none; | ||
|
||
Adw.SpinRow refillRow { | ||
styles [ | ||
"property" | ||
] | ||
|
||
title: _("Inventory"); | ||
climb-rate: 0.2; | ||
digits: 2; | ||
|
||
adjustment: Adjustment refillInventory { | ||
lower: 0; | ||
upper: 99999; | ||
step-increment: 1; | ||
}; | ||
} | ||
} | ||
|
||
Box { | ||
margin-top: 18; | ||
margin-start: 2; | ||
margin-end: 2; | ||
spacing: 8; | ||
halign: fill; | ||
orientation: horizontal; | ||
homogeneous: true; | ||
|
||
Button refill5Button { | ||
styles [ | ||
"refill-amount-btn", | ||
"pill" | ||
] | ||
|
||
label: "+5"; | ||
valign: center; | ||
} | ||
|
||
Button refill10Button { | ||
styles [ | ||
"refill-amount-btn", | ||
"pill" | ||
] | ||
|
||
label: "+10"; | ||
valign: center; | ||
} | ||
|
||
Button refill30Button { | ||
styles [ | ||
"refill-amount-btn", | ||
"pill" | ||
] | ||
|
||
label: "+30"; | ||
valign: center; | ||
} | ||
|
||
Button refill60Button { | ||
styles [ | ||
"refill-amount-btn", | ||
"pill" | ||
] | ||
|
||
label: "+60"; | ||
valign: center; | ||
} | ||
|
||
Button refill100Button { | ||
styles [ | ||
"refill-amount-btn", | ||
"pill" | ||
] | ||
|
||
label: "+100"; | ||
valign: center; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2023 Diego Povliuk | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
*/ | ||
'use strict'; | ||
|
||
import Gdk from 'gi://Gdk'; | ||
import Gtk from 'gi://Gtk'; | ||
|
||
import { DosageApplication } from './main.js'; | ||
|
||
export function openRefillDialog(listItem, position) { | ||
const item = listItem.get_item().obj; | ||
const DosageWindow = DosageApplication.get_default().activeWindow; | ||
const builder = Gtk.Builder.new_from_resource('/io/github/diegopvlk/Dosage/ui/refill-dialog.ui'); | ||
|
||
const refillDialog = builder.get_object('refillDialog'); | ||
const refillRow = builder.get_object('refillRow'); | ||
const refillInv = builder.get_object('refillInventory'); | ||
const refill5Btn = builder.get_object('refill5Button'); | ||
const refill10Btn = builder.get_object('refill10Button'); | ||
const refill30Btn = builder.get_object('refill30Button'); | ||
const refill60Btn = builder.get_object('refill60Button'); | ||
const refill100Btn = builder.get_object('refill100Button'); | ||
const cancelButton = builder.get_object('cancelButton'); | ||
const saveButton = builder.get_object('saveButton'); | ||
|
||
const keyController = new Gtk.EventControllerKey(); | ||
keyController.connect('key-pressed', (_, keyval, keycode, state) => { | ||
const shiftPressed = (state & Gdk.ModifierType.SHIFT_MASK) !== 0; | ||
const controlPressed = (state & Gdk.ModifierType.CONTROL_MASK) !== 0; | ||
const enterPressed = keyval === Gdk.KEY_Return; | ||
|
||
if ((controlPressed || shiftPressed) && enterPressed) { | ||
saveButton.activate(); | ||
} | ||
}); | ||
refillDialog.add_controller(keyController); | ||
|
||
refillRow.subtitle = item.name; | ||
|
||
refillInv.value = item.inventory.current; | ||
|
||
refill5Btn.connect('clicked', () => (refillInv.value += 5)); | ||
refill10Btn.connect('clicked', () => (refillInv.value += 10)); | ||
refill30Btn.connect('clicked', () => (refillInv.value += 30)); | ||
refill60Btn.connect('clicked', () => (refillInv.value += 60)); | ||
refill100Btn.connect('clicked', () => (refillInv.value += 100)); | ||
|
||
cancelButton.connect('clicked', () => refillDialog.force_close()); | ||
|
||
saveButton.connect('clicked', () => { | ||
item.inventory.current = refillInv.value; | ||
|
||
DosageWindow._updateEverything(['skipHistUp', position]); | ||
DosageWindow._scheduleNotifications('saving'); | ||
|
||
refillDialog.force_close(); | ||
}); | ||
|
||
const refillDialogClamp = builder.get_object('refillDialogClamp'); | ||
const [refillDialogClampHeight] = refillDialogClamp.measure(Gtk.Orientation.VERTICAL, -1); | ||
refillDialog.content_height = refillDialogClampHeight + 48; | ||
|
||
refillDialog.present(DosageWindow); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters