
    Je                         d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ  G d
 d      Z G d de      Zd Zedk(  r e        yy)z
Find in Files Plugin.
    )Qt)QApplication)PluginsSpyderDockablePlugin)on_plugin_availableon_plugin_teardown_)FindInFilesWidget)ApplicationMenus)getcwd_or_homec                       e Zd ZdZy)FindInFilesActionszfind in filesN)__name__
__module____qualname__FindInFiles     C/usr/lib/python3/dist-packages/spyder/plugins/findinfiles/plugin.pyr   r      s    !Kr   r   c                      e Zd ZdZdZg Zej                  ej                  ej                  gZ
ej                  gZeZeZdZdZed        Zd Zd Zd Z eej                  	      d
        Z eej                  	      d        Z eej                  	      d        Z eej                  	      d        Z eej                  	      d        Z eej                  	      d        ZddZd Z d Z!d Z"ddZ#d Z$d Z%y)r   z#
    Find in files DockWidget.
    find_in_filesFTc                      t        d      S )NFindr	   r   r   r   get_namezFindInFiles.get_name/   s    yr   c                     t        d      S )Nz$Search for strings of text in files.r	   selfs    r   get_descriptionzFindInFiles.get_description3   s    788r   c                 $    | j                  d      S )Nfindf)create_iconr   s    r   get_iconzFindInFiles.get_icon6   s    ((r   c                     | j                  t        j                  t        d      t        d      | j                  dt
        j                         | j                          y )NzFind in fileszSearch text in multiple filesT)texttip	triggeredregister_shortcutcontext)create_actionr   r   r
   findr   WindowShortcutrefresh_search_directoryr   s    r   on_initializezFindInFiles.on_initialize9   sP    **?#12ii"%% 	 	
 	%%'r   )pluginc                     | j                         }| j                  t        j                        |j                  j                  fd       j                  j                  | j                         y )Nc                 .    j                  | |||      S )N)start_column
end_column)load)filenamelinenosearch_textcolnocolendeditors        r   <lambda>z1FindInFiles.on_editor_available.<locals>.<lambda>I   s"    &u BM BI r   )
get_widget
get_pluginr   Editorsig_edit_goto_requestedconnect!sig_file_opened_closed_or_updatedset_current_opened_filer   widgetr:   s     @r   on_editor_availablezFindInFiles.on_editor_availableD   s[    "0&&..I	J 	0088((	*r   c                     | j                  t        j                        }|j                  j	                  | j
                         |j                  j	                  | j                         y N)r=   r   Projectssig_project_loadedr@   set_project_pathsig_project_closedunset_project_pathr   projectss     r   on_projects_availablez!FindInFiles.on_projects_availableN   sJ    ??7#3#34##++D,A,AB##++D,C,CDr   c                     | j                  t        j                        }| j                  t        j
                        }|j                  |t        j                         y N)menu_id)	r=   r   MainMenu
get_actionr   r   add_item_to_application_menur   Search)r   mainmenufindinfiles_actions      r   on_main_menu_availablez"FindInFiles.on_main_menu_availableT   sK    ??7#3#34!__-?-K-KL--$++ 	. 	
r   c                     | j                         }| j                  t        j                        }|j                  j                          |j                  j                  | j                         y rG   )r<   r=   r   r>   r?   
disconnectrA   rB   rC   s      r   on_editor_teardownzFindInFiles.on_editor_teardown^   sO    "0&&11300;;((	*r   c                     | j                  t        j                        }|j                  j	                  | j
                         |j                  j	                  | j                         y rG   )r=   r   rH   rI   r[   rJ   rK   rL   rM   s     r   #on_projects_teardon_plugin_teardownz/FindInFiles.on_projects_teardon_plugin_teardownf   sJ    ??7#3#34##..t/D/DE##..t/F/FGr   c                     | j                  t        j                        }|j                  t        j
                  t        j                         y rQ   )r=   r   rS   !remove_item_from_application_menur   r   r   rV   )r   rW   s     r   on_main_menu_teardownz!FindInFiles.on_main_menu_teardownl   s;    ??7#3#3422**$++ 	3 	
r   c                     | j                         j                          | j                         j                  r | j                         j                  d       y)NT)ignore_results)r<   _update_optionsrunning_stop_and_reset_thread)r   
cancelables     r   on_closezFindInFiles.on_closeu   s@    ))+??$$OO44D4Ir   c                 R    | j                         j                  t                      y)z+
        Refresh search directory.
        N)r<   set_directoryr   r   s    r   r-   z$FindInFiles.refresh_search_directory}   s     	''(89r   c                 B    | j                         j                  |       y)z
        Set path of current opened file in editor.

        Parameters
        ----------
        path: str
            Path of editor file.
        N)r<   set_file_path)r   path	_languages      r   rB   z#FindInFiles.set_current_opened_file   s     	''-r   c                 B    | j                         j                  |       y)z
        Set and refresh current project path.

        Parameters
        ----------
        path: str
            Opened project path.
        N)r<   rJ   )r   rm   s     r   rJ   zFindInFiles.set_project_path   s     	**40r   Nc                 B    | j                         j                  |       y)z
        Set maximum amount of results to add to the result browser.

        Parameters
        ----------
        value: int, optional
            Number of results. If None an input dialog will be used.
            Default is None.
        N)r<   set_max_results)r   values     r   rq   zFindInFiles.set_max_results   s     	))%0r   c                 @    | j                         j                          y)z-
        Unset current project path.
        N)r<   disable_project_searchr   s    r   rL   zFindInFiles.unset_project_path   s     	002r   c                    t        j                         }d}	 |j                         r|j                         }| j                          | j                         }|r|j                  |       |j                          y# t        $ r Y Ow xY w)z
        Search text in multiple files.

        Notes
        -----
        Find in files using the currently selected text of the focused widget.
         N)	r   focusWidgethas_selected_textget_selected_textAttributeErrorswitch_to_pluginr<   set_search_textr+   )r   focus_widgetr%   rD   s       r   r+   zFindInFiles.find   s~     $//1	--/#557
 	"""4(  		s    A< <	BB)FrG   )&r   r   r   __doc__NAMEREQUIRESr   r>   rH   rS   OPTIONALVariableExplorerTABIFYr   WIDGET_CLASSCONF_SECTION	CONF_FILERAISE_AND_FOCUSstaticmethodr   r   r#   r.   r   rE   rO   rY   r   r\   r^   ra   rh   r-   rB   rJ   rq   rL   r+   r   r   r   r   r       sQ    DH 0 0'2B2BCH&&'F$LLIO  9)	( /* 0*  0 01E 2E
  0 01
 2
 w~~.* /* w//0H 1H
 w//0
 1
:	.	1
13r   r   c                      dd l } ddlm} ddlm}  |       }t        d |      }|j                          | j                  |j                                y )Nr   )CONF)qapplication)	sysspyder.config.managerr   spyder.utils.qthelpersr   r   showexitexec_)r   r   r   apprD   s        r   testr      s9    *3
.Ct$F
KKMHHSYY[r   __main__N)r~   qtpy.QtCorer   qtpy.QtWidgetsr   spyder.api.pluginsr   r   )spyder.api.plugin_registration.decoratorsr   r   spyder.api.translationsr
   .spyder.plugins.findinfiles.widgets.main_widgetr   spyder.plugins.mainmenu.apir   spyder.utils.miscr   r   r   r   r   r   r   r   <module>r      s[   
  ' =- % L 8 ,
" "b& bJ	 zF r   