a
    a                     @   s   d Z ddlmZ ddl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 dd	lmZ dd
lmZ edZG dd dZG dd deZdd Zedkre  dS )z
Find in Files Plugin.
    )Qt)QApplication)PluginsSpyderDockablePlugin)on_plugin_available)get_translation)FindInFilesWidget)ApplicationMenus)ApplicationToolbars)getcwd_or_homeZspyderc                   @   s   e Zd ZdZdS )FindInFilesActionszfind in filesN)__name__
__module____qualname__FindInFiles r   r   @lib/python3.9/site-packages/spyder/plugins/findinfiles/plugin.pyr      s   r   c                   @   s   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d Zdd Zdd	 Zd
d Zeejddd Zeejddd Zeej	ddd Zd"ddZdd Zdd Zdd Zd#ddZdd Zd d! ZdS )$r   z#
    Find in files DockWidget.
    Zfind_in_filesFc                 C   s   t dS )NZFind_selfr   r   r   get_name1   s    zFindInFiles.get_namec                 C   s   t dS )Nz$Search for strings of text in files.r   r   r   r   r   get_description4   s    zFindInFiles.get_descriptionc                 C   s
   |  dS )NZfindf)Zcreate_iconr   r   r   r   get_icon7   s    zFindInFiles.get_iconc                 C   s0   | j tjtdtd| jdtjd |   d S )NzFind in fileszSearch text in multiple filesT)textZtipZ	triggeredZregister_shortcutcontext)Zcreate_actionr   r   r   findr   ZWindowShortcutrefresh_search_directoryr   r   r   r   on_initialize:   s    zFindInFiles.on_initialize)Zpluginc                    s:   |   }| tj |j fdd  j| j d S )Nc                    s    j | |||dS )N)Zstart_columnZ
end_column)load)filenamelinenoZsearch_textcolnoZcolendZeditorr   r   <lambda>J   s   z1FindInFiles.on_editor_available.<locals>.<lambda>)
get_widget
get_pluginr   EditorZsig_edit_goto_requestedconnectZ!sig_file_opened_closed_or_updatedset_current_opened_file)r   widgetr   r#   r   on_editor_availableE   s    
zFindInFiles.on_editor_availablec                 C   s,   |  tj}|j| j |j| j d S )N)r&   r   ProjectsZsig_project_loadedr(   set_project_pathZsig_project_closedunset_project_path)r   Zprojectsr   r   r   on_projects_availableO   s    z!FindInFiles.on_projects_availablec                 C   s,   |  tj}| tj}|j|tjd d S )N)Zmenu_id)	r&   r   MainMenuZ
get_actionr   r   Zadd_item_to_application_menur	   ZSearch)r   ZmainmenuZfindinfiles_actionr   r   r   on_main_menu_availableU   s    z"FindInFiles.on_main_menu_availablec                 C   s    |     |   jdd dS )NT)Zignore_results)r%   Z_update_optionsZ_stop_and_reset_thread)r   Z
cancelabler   r   r   on_close_   s    zFindInFiles.on_closec                 C   s   |   t  dS )z+
        Refresh search directory.
        N)r%   Zset_directoryr   r   r   r   r   r   f   s    z$FindInFiles.refresh_search_directoryc                 C   s   |   | dS )z
        Set path of current opened file in editor.

        Parameters
        ----------
        path: str
            Path of editor file.
        N)r%   Zset_file_path)r   pathZ	_languager   r   r   r)   l   s    	z#FindInFiles.set_current_opened_filec                 C   s   |   | dS )z
        Set and refresh current project path.

        Parameters
        ----------
        path: str
            Opened project path.
        N)r%   r-   )r   r3   r   r   r   r-   w   s    	zFindInFiles.set_project_pathNc                 C   s   |   | dS )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   valuer   r   r   r4      s    
zFindInFiles.set_max_resultsc                 C   s   |     dS )z-
        Unset current project path.
        N)r%   Zdisable_project_searchr   r   r   r   r.      s    zFindInFiles.unset_project_pathc                 C   s^   t  }d}z| r| }W n ty2   Y n0 |   |  }|rR|| |  dS )z
        Search text in multiple files.

        Notes
        -----
        Find in files using the currently selected text of the focused widget.
         N)	r   ZfocusWidgetZhas_selected_textZget_selected_textAttributeErrorZswitch_to_pluginr%   Zset_search_textr   )r   Zfocus_widgetr   r*   r   r   r   r      s    
zFindInFiles.find)F)N) r   r   r   __doc__NAMEZREQUIRESr   r'   r,   r0   ZOPTIONALZVariableExplorerZTABIFYr   ZWIDGET_CLASSZCONF_SECTIONZ	CONF_FILEr   r   r   r   r   r+   r/   r1   r2   r   r)   r-   r4   r.   r   r   r   r   r   r   #   s2   

	



	

r   c                  C   sJ   dd l } ddlm} ddlm} | }td |}|  | |  d S )Nr   )CONF)qapplication)	sysZspyder.config.managerr:   Zspyder.utils.qthelpersr;   r   ZshowexitZexec_)r<   r:   r;   Zappr*   r   r   r   test   s    
r>   __main__N)r8   Zqtpy.QtCorer   Zqtpy.QtWidgetsr   Zspyder.api.pluginsr   r   Z)spyder.api.plugin_registration.decoratorsr   Zspyder.api.translationsr   Z"spyder.plugins.findinfiles.widgetsr   Zspyder.plugins.mainmenu.apir	   Zspyder.plugins.toolbar.apir
   Zspyder.utils.miscr   r   r   r   r>   r   r   r   r   r   <module>   s     