forked from rafaelmardojai/blanket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds feature requested in rafaelmardojai#337.
- Loading branch information
1 parent
d95a837
commit 838e2a9
Showing
11 changed files
with
220 additions
and
31 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
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,75 @@ | ||
# Copyright 2025 Rafael Mardojai CM | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from gettext import gettext as _ | ||
from gi.repository import Gio, Gtk, Adw | ||
|
||
from blanket.define import RES_PATH | ||
from blanket.sound import Sound | ||
from blanket.settings import Settings | ||
|
||
@Gtk.Template(resource_path=f'{RES_PATH}/sound-rename-dialog.ui') | ||
class SoundRenameDialog(Adw.Dialog): | ||
__gtype_name__ = 'SoundRenameDialog' | ||
|
||
headerbar: Adw.HeaderBar = Gtk.Template.Child() # type: ignore | ||
title_widget: Adw.WindowTitle = Gtk.Template.Child() # type: ignore | ||
accept_btn: Gtk.Button = Gtk.Template.Child() # type: ignore | ||
name_entry: Adw.EntryRow = Gtk.Template.Child() # type: ignore | ||
|
||
def __init__(self, sound: Sound, index: int, **kwargs): | ||
super().__init__() | ||
|
||
self.sound = sound | ||
self.index = index | ||
app = Gio.Application.get_default() | ||
self.window = app.get_active_window() # type: ignore | ||
|
||
self.set_title(_('Rename Sound')) | ||
self.title_widget.set_subtitle(self.sound.name) | ||
self.name_entry.set_text(self.sound.name) | ||
# Wire buttons | ||
self.accept_btn.connect('clicked', self._on_rename_sound) | ||
|
||
@Gtk.Template.Callback() | ||
def _on_cancel_clicked(self, _button): | ||
self.close() | ||
|
||
@Gtk.Template.Callback() | ||
def _on_entry_changed(self, _entry): | ||
name = self.__get_name() | ||
|
||
if self.sound is not None and self.sound.name == name: | ||
self.accept_btn.set_sensitive(False) | ||
return | ||
|
||
if name: | ||
self.accept_btn.set_sensitive(True) | ||
else: | ||
self.accept_btn.set_sensitive(False) | ||
|
||
def _on_rename_sound(self, _button): | ||
new_name = self.__get_name() | ||
|
||
if new_name == self.sound.name: | ||
self.close() | ||
return | ||
|
||
if not new_name or new_name in Settings.get().custom_audios: | ||
self.__invalid_name() | ||
return | ||
|
||
Settings.get().rename_custom_audio(self.sound.name, new_name) | ||
self.sound.name = new_name | ||
self.sound.title = new_name | ||
|
||
self.close() | ||
|
||
def __get_name(self): | ||
name = self.name_entry.get_text() | ||
name = name.strip() # Strip name | ||
|
||
return name | ||
|
||
def __invalid_name(self): | ||
pass |
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,48 @@ | ||
using Gtk 4.0; | ||
using Adw 1; | ||
|
||
template $SoundRenameDialog : Adw.Dialog { | ||
width-request: 360; | ||
height-request: 148; | ||
focus-widget: name_entry; | ||
|
||
Adw.ToolbarView { | ||
|
||
[top] | ||
Adw.HeaderBar headerbar { | ||
show-end-title-buttons: false; | ||
show-start-title-buttons: false; | ||
|
||
title-widget: Adw.WindowTitle title_widget { | ||
title: bind template.title; | ||
}; | ||
|
||
Button { | ||
label: _("Cancel"); | ||
|
||
clicked => $_on_cancel_clicked(); | ||
} | ||
|
||
[end] | ||
Button accept_btn { | ||
sensitive: false; | ||
label: _("Save"); | ||
|
||
styles [ | ||
"suggested-action" | ||
] | ||
} | ||
} | ||
|
||
Adw.PreferencesPage { | ||
Adw.PreferencesGroup { | ||
Adw.EntryRow name_entry { | ||
title: _("Sound Name"); | ||
selectable: false; | ||
|
||
changed => $_on_entry_changed(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.