Skip to content

Commit

Permalink
feat: connect open signal
Browse files Browse the repository at this point in the history
you can now open files using

$ collision ./my/file.txt

or your file manager's 'Open With...' context menu entry
  • Loading branch information
GeopJr committed Nov 1, 2022
1 parent 810d050 commit 21a7e95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/collision.cr
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ module Collision
FILE_INFO = Adw::StatusPage.cast(B_FI["fileInfo"])
HASH_LIST = Gtk::ListBox.cast(B_HS["hashList"])

APP = Adw::Application.new("dev.geopjr.Collision", Gio::ApplicationFlags::None)
APP = Adw::Application.new("dev.geopjr.Collision", Gio::ApplicationFlags::HandlesOpen)
end
15 changes: 14 additions & 1 deletion src/collision/views/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,21 @@ module Collision
TOOL_VERIFY_OVERLAY.child = scrolled_window
end

def open_with(app : Adw::Application, files : Enumerable(Gio::File), hint : String)
activate(app)

if files.size >= 0 && Collision.file?(files[0].path.not_nil!, false)
Collision::Welcomer.file = files[0]
end

nil
end

APP.startup_signal.connect(->startup(Adw::Application))
APP.activate_signal.connect(->activate(Adw::Application))
APP.open_signal.connect(->open_with(Adw::Application, Enumerable(Gio::File), String))

exit(APP.run(nil))
# ARGV but without flags, passed to Application.
clean_argv = [PROGRAM_NAME].concat(ARGV.reject { |x| x.starts_with?('-') })
exit(APP.run(clean_argv))
end

0 comments on commit 21a7e95

Please sign in to comment.