@@ -56,6 +56,9 @@ def __init__(self):
5656 self .add_main_option (
5757 "dest" , ord ("d" ), GLib .OptionFlags .NONE , GLib .OptionArg .STRING , "Destination lang code" , None
5858 )
59+ self .add_main_option (
60+ "copy" , ord ("c" ), GLib .OptionFlags .NONE , GLib .OptionArg .NONE , "Copy translated text to clipboard" , None
61+ )
5962
6063 self .setup_actions ()
6164
@@ -111,6 +114,7 @@ def process_command_line(self):
111114 text = ""
112115 langs : dict [str , str | None ] = {"src" : None , "dest" : None }
113116 selection = "selection" in self .argv
117+ copy_to_clipboard = "copy" in self .argv # Verificando a opção --copy
114118
115119 if "text" in self .argv :
116120 text = self .argv ["text" ]
@@ -123,11 +127,21 @@ def process_command_line(self):
123127 if not text and selection :
124128 self .window .queue_selection_translation (langs ["src" ], langs ["dest" ])
125129 elif text :
126- self .window .translate (text , langs ["src" ], langs ["dest" ])
130+ translated_text = self .window .translate (text , langs ["src" ], langs ["dest" ])
127131
128- # Clean CLI args
132+ # Se o comando --copy for passado, copia o texto traduzido para a área de transferência
133+ if copy_to_clipboard :
134+ self .copy_to_clipboard (translated_text )
135+
136+ # Limpar argumentos da linha de comando
129137 self .argv = {}
130138
139+ def copy_to_clipboard (self , text : str ):
140+ """Função para copiar o texto para a área de transferência."""
141+ clipboard = Gio .Clipboard .get (Gio .SELECTION_CLIPBOARD )
142+ clipboard .set_text (text , - 1 ) # Copiar para a área de transferência
143+ clipboard .store ()
144+
131145 def setup_actions (self ):
132146 """Setup menu actions"""
133147
0 commit comments