4545from gradia .ui .dialog .confirm_close_dialog import ConfirmCloseDialog
4646from gradia .backend .tool_config import ToolOption
4747from gradia .ui .dialog .ocr_dialog import OCRDialog
48+ from gradia .ui .preferences .provider_selection_window import ProviderListPage
4849
4950@Gtk .Template (resource_path = f"{ rootdir } /ui/main_window.ui" )
5051class GradiaMainWindow (Adw .ApplicationWindow ):
@@ -138,7 +139,7 @@ def _setup_actions(self) -> None:
138139 self .create_action ("open-folder" , lambda * _ : self .open_loaded_image_folder (), enabled = False )
139140 self .create_action ("save" , lambda * _ : self .export_manager .save_to_file (), ["<Primary>s" ], enabled = False )
140141 self .create_action ("copy" , lambda * _ : self .export_manager .copy_to_clipboard (), ["<Primary>c" ], enabled = False )
141- self .create_action ("command" , lambda * _ : self ._run_custom_command (), ["<Primary>m" ], enabled = False )
142+ self .create_action ("command" , lambda * _ : self ._run_custom_command (), ["<Primary>m" ])
142143
143144 self .create_action ("aspect-ratio-crop" , lambda _ , variant : self .image_bin .set_aspect_ratio (variant .get_double ()), vt = "d" )
144145 self .create_action ("crop" , lambda * _ : self .image_bin .on_toggle_crop (), ["<Primary>r" ])
@@ -441,7 +442,6 @@ def _set_export_ready(self, enabled: bool) -> None:
441442 action = self .lookup_action (action_name )
442443 if action :
443444 action .set_enabled (enabled )
444- self .update_command_ready ()
445445
446446 def open_loaded_image_folder (self ):
447447 folder_uri = GLib .filename_to_uri (self .image .get_folder_path ())
@@ -450,12 +450,6 @@ def open_loaded_image_folder(self):
450450 except Exception as e :
451451 print ("Failed to open folder:" , e )
452452
453- def update_command_ready (self ) -> None :
454- action = self .lookup_action ('command' )
455- if action :
456- action .set_enabled (self .image_ready )
457- self .share_button .set_visible (bool (self .settings .custom_export_command .strip ()))
458-
459453 def _create_delete_screenshots_dialog (self ) -> None :
460454 dialog = DeleteScreenshotsDialog (self )
461455 dialog .show (
@@ -472,6 +466,21 @@ def set_screenshot_folder(self, subfolder) -> None:
472466 self .welcome_content .refresh_recent_picker ()
473467
474468 def _run_custom_command (self ) -> None :
469+ if not self .settings .custom_export_command :
470+ dialog = Adw .PreferencesDialog (content_width = 600 , content_height = 500 )
471+ dialog .set_title (_ ("Select Provider" ))
472+
473+ def handle_selection (name : str , command : str ):
474+ self .settings .provider_name = name
475+ self .settings .custom_export_command = command
476+ dialog .close ()
477+ self ._run_custom_command ()
478+
479+ provider_page = ProviderListPage (preferences_dialog = dialog , on_provider_selected = handle_selection , can_pop = False )
480+ dialog .push_subpage (provider_page )
481+ dialog .present (self )
482+ return
483+
475484 if self .settings .show_export_confirm_dialog :
476485 provider_name = self .settings .provider_name
477486
0 commit comments