Skip to content

Commit 1f69d2e

Browse files
committed
feat: FileChooserNative => FileDialog
1 parent 4e674c2 commit 1f69d2e

File tree

3 files changed

+29
-46
lines changed

3 files changed

+29
-46
lines changed

data/ui/application.ui

-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
<attribute name="action">app.about</attribute>
2020
</item>
2121
</menu>
22-
<object class="GtkFileChooserNative" id="mainFileChooserNative">
23-
<property name="title" translatable="yes">Choose a File</property>
24-
<property name="modal">1</property>
25-
<property name="select-multiple">1</property>
26-
</object>
27-
<object class="GtkFileChooserNative" id="compareBtnFileChooserNative">
28-
<property name="title" translatable="yes">Choose a File</property>
29-
<property name="modal">1</property>
30-
</object>
3122
<template class="Collision-Window" parent="AdwApplicationWindow">
3223
<property name="width-request">360</property>
3324
<property name="height-request">360</property>

shard.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ shards:
1010

1111
gi-crystal:
1212
git: https://github.com/hugopl/gi-crystal.git
13-
version: 0.22.3
13+
version: 0.24.0
1414

1515
gtk4:
1616
git: https://github.com/hugopl/gtk4.cr.git
17-
version: 0.16.1
17+
version: 0.17.0
1818

1919
harfbuzz:
2020
git: https://github.com/hugopl/harfbuzz.cr.git

src/collision/window.cr

+27-35
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ module Collision
66
resource: "/dev/geopjr/Collision/ui/application.ui",
77
children: {
88
"welcomeBtn",
9-
"mainFileChooserNative",
10-
"compareBtnFileChooserNative",
119
"mainStack",
1210
"fileInfo",
1311
"headerbarStack",
@@ -35,8 +33,6 @@ module Collision
3533
@compareBtnLabel : Gtk::Label
3634
@compareBtnStack : Gtk::Stack
3735
@openFileBtn : Gtk::Button
38-
@mainFileChooserNative : Gtk::FileChooserNative
39-
@compareBtnFileChooserNative : Gtk::FileChooserNative
4036
@mainStack : Gtk::Stack
4137
@fileInfo : Adw::StatusPage
4238
@switcher_bar : Adw::ViewSwitcherBar
@@ -82,7 +78,23 @@ module Collision
8278
end
8379

8480
def on_open_btn_clicked
85-
@mainFileChooserNative.show
81+
Gtk::FileDialog.new(
82+
title: Gettext.gettext("Choose a File"),
83+
modal: true
84+
).open_multiple(self, nil) do |obj, result|
85+
next if (files = obj.as(Gtk::FileDialog).open_multiple_finish(result)).nil?
86+
87+
gio_files = [] of Gio::File
88+
files.n_items.times do |i|
89+
gio_files << Gio::File.cast(files.item(i).not_nil!)
90+
end
91+
92+
loading
93+
self.file = gio_files.shift
94+
open_files(Adw::Application.cast(self.application.not_nil!), gio_files) unless gio_files.empty? || self.application.nil?
95+
rescue ex
96+
Collision::LOGGER.debug { ex }
97+
end
8698
end
8799

88100
def on_drop(file : Gio::File)
@@ -227,49 +239,29 @@ module Collision
227239
@compareBtnStack = Gtk::Stack.cast(template_child("compareBtnStack"))
228240
@progressbar = Gtk::ProgressBar.cast(template_child("progressbar"))
229241

230-
@mainFileChooserNative = Gtk::FileChooserNative.cast(template_child("mainFileChooserNative"))
231-
@compareBtnFileChooserNative = Gtk::FileChooserNative.cast(template_child("compareBtnFileChooserNative"))
232-
@mainFileChooserNative.transient_for = self
233-
@compareBtnFileChooserNative.transient_for = self
234-
235242
@verifyTextView.buffer.notify_signal["text"].connect do
236243
Collision::LOGGER.debug { "Verify tool notify event" }
237244

238245
handle_input_change(@verifyTextView.buffer.text)
239246
end
240247

241-
@mainFileChooserNative.response_signal.connect do |response|
242-
next unless response == -3
243-
244-
gio_files = [] of Gio::File
245-
files = @mainFileChooserNative.files
246-
files.n_items.times do |i|
247-
gio_files << Gio::File.cast(files.item(i).not_nil!)
248-
end
249-
250-
loading
251-
self.file = gio_files.shift
252-
open_files(Adw::Application.cast(self.application.not_nil!), gio_files) unless gio_files.empty? || self.application.nil?
253-
rescue ex
254-
Collision::LOGGER.debug { ex }
255-
end
256-
257-
@compareBtnFileChooserNative.response_signal.connect do |response|
258-
next unless response == -3
259-
260-
self.comparefile = @compareBtnFileChooserNative.file.not_nil!
261-
rescue ex
262-
Collision::LOGGER.debug { ex }
263-
end
264-
265248
@welcomeBtn.clicked_signal.connect(->on_open_btn_clicked)
266249
@openFileBtn.clicked_signal.connect(->on_open_btn_clicked)
267250

268251
@mainStack.add_controller(Collision::DragNDrop.new(->on_drop(Gio::File)).controller)
269252
@compareBtn.add_controller(Collision::DragNDrop.new(->comparefile=(Gio::File)).controller)
270253

271254
@compareBtn.clicked_signal.connect do
272-
@compareBtnFileChooserNative.show
255+
Gtk::FileDialog.new(
256+
title: Gettext.gettext("Choose a File"),
257+
modal: true
258+
).open(self, nil) do |obj, result|
259+
next if (file = obj.as(Gtk::FileDialog).open_finish(result)).nil?
260+
261+
self.comparefile = file
262+
rescue ex
263+
Collision::LOGGER.debug { ex }
264+
end
273265
end
274266
end
275267
end

0 commit comments

Comments
 (0)