
    G@dK                       d Z ddlZddlZddlmZ ddlZddlZddlZddl	m
Z
mZmZ ddlmZmZmZmZmZ ddlmZ ddlmZmZmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& dd	l'm(Z( dd
l)m*Z* ddl+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZF ddlGmHZH ddlImJZJ ddlKmLZL ddlMmNZN ddlOmPZP ddlQmRZRmSZSmTZT ddlUmVZVmWZW ddlXmYZYmZZZ ddl[m\Z\m]Z] ddl^m_Z_m`Z`maZambZbmcZc ddldmeZemfZfmgZgmhZhmiZi ddljmkZk dd llmmZm  ejn        eo          Zp G d! d"e-e(          ZqdS )#zEditor Plugin    N)from_qvariantgetopenfilenamesto_qvariant)
QByteArrayQtSignalSlotQDir)QTextCursor)QAbstractPrintDialogQPrintDialogQPrinter)QActionQActionGroupQApplicationQDialogQFileDialogQInputDialogQMenu	QSplitterQToolBarQVBoxLayoutQWidget)on_conf_change)SpyderConfigurationObserver)Panel)PluginsSpyderPluginWidget)_get_conf_pathrunning_under_pytest)CONF)get_edit_filetypesget_edit_filters
get_filter)qbytearray_to_strto_text_string)encodingprograms
sourcecode)ima)create_actionadd_actionsMENU_SEPARATOR)getcwd_or_home)FindReplace)EditorConfigPage)AutosaveForPlugin)EditorSwitcherManager)
CodeEditor)EditorMainWindowEditorSplitterEditorStack)SpyderPrinterSpyderPrintPreviewDialog)load_bookmarkssave_bookmarks)clear_all_breakpointsclear_breakpoint)CursorPositionStatusEncodingStatus	EOLStatusReadWriteStatus	VCSStatus)ALWAYS_OPEN_FIRST_RUN_OPTIONget_run_configurationRunConfigDialogRunConfigurationRunConfigOneDialog)ApplicationMenus)SimpleCodeEditorc                       e Zd ZdZdZeZdZ ed          Z	 ed          Z
dZdZej        gZej        ej        gZ eeeeeeeeee	  	        Z eeeeee          Z eeeeee          Z eee          Z ee          Z ee          Z	  e            Z eee          Z	  e            Z e            Z  ee!          Z"	  e            Z#	 ddZ$d Z% e&            d             Z'd	 Z(d
 Z) e&e!          d             Z* e&e!e          d             Z+d Z,d Z-d Z. e&ee/e!          d             Z0e1d             Z2d Z3d Z4d Z5d Z6ddZ7d Z8d Z9d Z:d Z;d Z<d Z=ddZ> e&eee          d             Z?d  Z@d! ZAdd#ZBd$ ZCd% ZDd& ZEd' ZFd( ZG e&ee          d)             ZH e&eee          d*             ZI e&eee          d+             ZJd, ZK fd-ZLd. ZMd/ ZNd0 ZOd1 ZPd2 ZQdd3ZRd4 ZSd5 ZTd6 ZUd7 ZVdd8ZWdd:ZXd; ZYd< ZZd= Z[d> Z\d? Z]d@ Z^dA Z_dB Z`dC ZadD ZbdE Zc e&ed          dF             ZedG ZfdH Zg e&            dI             ZhdJ ZidK Zj e&             e&e          ddL                        ZkdM ZldN Zm e&            dO             Zn e&            dP             Zo e&             e&e           e&eepe           e&eepee          	 	 	 ddR                                                ZqdS Zr e&            dT             Zs e&            dU             ZtddVZu e&            dW             Zv e&            dX             Zw e&            ddY            Zx e&            dZ             Zy e&            d[             Zz e&            dd\            Z{ e&            d]             Z| e&            d^             Z} e&            d_             Z~ e&            d`             Z e&            da             Zdb Zdc Zdd Zde Zdf Zdg Z e&            dh             Z e&            di             Z e&            dj             Z e&            dk             Z e&            dl             Z e&            dm             Z e&            dn             Z e&            do             Z e&            dp             Z e&            dq             Zdr Z e&            ds             Z e&            dt             Z e&            du             Zdv ZddwZdx Zdy Zdz Zd{ Z e&            d|             Zd} Zd~ Zd Z e&            d             Z e&            d             Z e&            dd            Z e&            d             Z e&            d             Z e&            d             Zd Zd Zd Zd Zd Zd Zd Zd ZddZ e&            d             Z e&            dd            Zd Z e&            d             Z e&            dd            Z e&            d             Z e&            d             Z e&            d             Z e&            d             Z e&            d             Z e&            d             Z e&            d             Z e&ep          d             Z e&ep          d             Zd Zd Z ed          d             Z edd          d             Z edd          d             Z ed          d             Z ed          d             Z ed          d             Z ed          d             Z edd          d             Z edd          d             Z ed          d             Z edddg          d             Zd ZddZd Zd Z e&            d             Z e&            d             ZddZej        j        ddÄZdĄ ZՈ xZS )Editorz"
    Multi-file Editor widget
    editorFztemp.pyztemplate.pyc                    t          j        | |           d| _        t          j        | j                  sgt          j        dk    rg }ndg}|g dz   }	 t          j	        t          j
                            |          | j        d           n# t          $ r Y nw xY wd | _        d | _        g | _        g | _        d | _        d | _        d | _        i | _        d| _        g | _        i | _        g | _        g | _        d | _        d | _        |                                  | j                                         d | _        tA          |           | _!        tE          |           | _#        tI          |           | _%        tM          |           | _'        tQ          |           | _)        | j*        +                    tX          j-        d          }|r|.                    | j)                   |.                    | j'                   |.                    | j%                   |.                    | j#                   |.                    | j!                   t_                      }ta          |           | _1        te          | j1        | j                   |3                    | j1                   d | _4        g | _5        g | _6        d| _7        i | _8        | j*        j9        :                    | j;                   ty          | d          | _=        | j=                                         | >                    | j=                   t          |           | _@        | j@        A                                 | B                    d	          d
z  | j@        _C        | B                    d          | j@        _D        | E                                | _F        | jF                                         t          |           }t_                      }|H                    d           |I                    dddd           |J                    |           t          | | | j        d          | _L        |3                    | jL                   |3                    | j=                   |3                    | jF                   t          |           | _N        | jN        I                    dddd           | jN        3                    |           | jN        O                    dd           | jN        O                    dd           |3                    | jN                   | J                    |           | P                    t          jR                   | B                    dd           }	|	Y| jN        S                    t                      U                    t          |	          W                    d                               | B                    dg           | _X        d| _Y        d | _Z        d | _[        d | _\        d | _]        d| _7        | ^                                }
|
>| _                                }|
`                                }| a                    ||           | b                                 d S )NTntz#!/usr/bin/env python3)# -*- coding: utf-8 -*-"""zCreated on %(date)s z@author: %(username)srP   rQ   rQ   utf-8Ferror)enable_replaceautosave_interval  autosave_enabledr   )first      splitter_staterecent_files)cr   __init___Editor__set_eol_charsospisfileTEMPLATE_PATHosnamer(   writelinesepjoinEnvironmentErrorprojectsoutlineexplorerfile_dependent_actionspythonfile_dependent_actionsdock_toolbar_actionsedit_menu_actionsstack_menu_actionscheckable_actions_Editor__first_open_files_setupeditorstackslast_focused_editorstackeditorwindowseditorwindows_to_be_createdtoolbar_list	menu_list_setupoptions_buttonhidedialog_sizerB   
vcs_statusr>   cursorpos_statusr?   encoding_statusr@   
eol_statusrA   readwrite_statusmain
get_pluginr   	StatusBaradd_status_widgetr   r   dock_toolbarr-   	addWidgetlast_edit_cursor_poscursor_undo_historycursor_redo_history_Editor__ignore_cursor_historycompletion_capabilitiesall_actions_definedconnectsetup_other_windowsr0   find_widgetregister_widget_shortcutsr2   autosavetry_recover_from_autosave
get_optionintervalenabled_create_print_editor_print_editorr   
setSpacingsetContentsMargins	setLayoutr6   editorsplitterr   splittersetStretchFactorsetFocusPolicyr   
ClickFocusrestoreStater   fromHexstrencoder]   untitled_num_Editor__last_ic_exec_Editor__last_ec_execedit_filetypesedit_filtersget_current_editorget_current_filename
textCursoradd_cursor_to_historyupdate_cursorpos_actions)selfparentignore_last_opened_filesshebangheader	statusbarlayouteditor_widgetseditor_layoutstatecurrent_editorfilenamecursors                <lib/python3.11/site-packages/spyder/plugins/editor/plugin.pyr^   zEditor.__init__   s!   #D&111# z$,-- 	w$34  8  8  8 8Frzv668J&( ( ( (#    #&(#,.)$(!!%"&!#(,%(*%+-(  	  """  #D// 4T : :-d33#D// / 5 5 I(():%(HH	 	9''(=>>>''888''(<===''(=>>>''888$TNND%t'@AAA*+++$(!#% #% '+$ (*$ 		%--d.FGGG 'tDAAA&&t'7888 *$////111 "&1D!E!E!L $0B C C "6688!!! !#  ###((Aq!444  ///,T4)-)@N N N 3444 0111 2333 "$((Aq!444///&&q!,,,&&q!,,,'''vBM***  0$77M&&
(<(<JJ%%g..)0 )0 2 2 2 !OONB?? #" # ',$0022%0022H#..00F&&x888%%'''''s   8B 
BBc                     || _         d S N)ri   )r   ri   s     r   set_projectszEditor.set_projects1  s         c                     | j         s| j         j        }|                                r|                                 n(|                                 |                                 |                                  d S d S r   )ri   
dockwidget	isVisiblerz   showraise_switch_to_plugin)r   dws     r   show_hide_projectszEditor.show_hide_projects4  sm    =$)B||~~ 									!!##### %$r   c                 R    | _          j        D ].}|                     j                                                    / j                                         j                             fd            j                                         j                             fd           d S )Nc                 6                         | ||          S )N)	filenamesgotowordeditorwindowload)r   r   r   r   s      r   <lambda>z,Editor.set_outlineexplorer.<locals>.<lambda>F  s'    99yt$26 % 8 8 r   c                 2                         |           S )N)r   r   r   )r   r   s    r   r   z,Editor.set_outlineexplorer.<locals>.<lambda>J  s    !YYYNN r   )rj   rr   set_outlineexplorer
get_widget	edit_gotor   edit)r   rj   editorstacks   `  r   r   zEditor.set_outlineexplorer?  s    ., 	O 	OK ++D,@,K,K,M,MNNNN''))3;;8 8 8 8	9 	9 	9 	'')).66O O O O	P 	P 	P 	P 	Pr   c                 v    	 |                                                                   dS # t          $ r Y dS w xY w)z9Restoring scrollbar position after main window is visibleN)r   centerCursorAttributeErrorr   s    r   restore_scrollbar_positionz!Editor.restore_scrollbar_positionN  sM    	##%%2244444 	 	 	DD	s   &* 
88c                 P   |d         }|d         }|d         }d}| j                             t          j        d          rd| j         j                            |                                          }| j         j                            |                                ||           |r|                                | j        v rH|	                    | j        |                                                    |
                                 dS | j         j                            |                                          r|
                                 dS dS |j        |                                k    r6t                              d                    |                     d|_        dS dS )z8Report that a file was opened to the completion manager.r   language
codeeditorNFrS   zSetting {0} completions off)r   r   r   Completionscompletions&start_completion_services_for_languagelowerregister_filer    register_completion_capabilitiesstart_completion_servicesis_fallback_onlyr   loggerdebugformatcompletions_available)r   optionsr   r   r   statuss         r   report_open_filezEditor.report_open_fileV  s    :&:&\*
9 35AA 	8	%LLNN$$& &  I!//  (J8 8 8 	9~~4#??? ;;01A1ABD D D4466666&778H8HII 7 44666667 7
 "hnn&6&666:AA(KKLLL38
000 76r   c                 r   t                               d                    ||                     | j                            t
          j        d          }|r|                                 t          |          | j	        |<   | j
        D ]}|                    ||           |                     |           dS )aB  
        Register completion server capabilities in all editorstacks.

        Parameters
        ----------
        capabilities: dict
            Capabilities supported by a language server.
        language: str
            Programming language for the language server (it has to be
            in small caps).
        z1Completion server capabilities for {!s} are: {!r}FrS   N)r   r   r   r   r   r   Projectsstart_workspace_servicesdictr   rr   r   r   )r   capabilitiesr   ri   r   s        r   r   z'Editor.register_completion_capabilitiess  s     	?FF,( (	
 	
 	
 9''(8'FF 	0--///15l1C1C$X., 	( 	(K88h( ( ( ( 	&&x00000r   c                 D    | j         D ]}|                    |           dS )z6Notify all editorstacks about LSP server availability.N)rr   r   r   r   r   s      r   r   z Editor.start_completion_services  s5    , 	< 	<K11(;;;;	< 	<r   c                 D    | j         D ]}|                    |           dS )z8Notify all editorstacks about LSP server unavailability.N)rr   stop_completion_servicesr   s      r   r   zEditor.stop_completion_services  s5    , 	; 	;K00::::	; 	;r   c                     t                               d                    ||d                              	 | j        j                            |||           d S # t          $ r Y d S w xY w)NzPerform request {0} for: {1}file)r   r   r   r   r   send_requestr   )r   r   requestparamss       r   send_completion_requestzEditor.send_completion_request  s~    3::VF^% % 	& 	& 	&	I!..x&IIIII 	 	 	DD	s   !A 
A'&A'c                 6    t          | |          } ||i | d S r   )getattr)r   methodargskwargsmeths        r   	_rpc_callzEditor._rpc_call  s,    tV$$dfr   c                  $    t          d          } | S )zReturn widget titlerK   )r   )titles    r   get_plugin_titlezEditor.get_plugin_title  s    
 (r   c                 *    t          j        d          S )zReturn widget icon.r   )r+   iconr   s    r   get_plugin_iconzEditor.get_plugin_icon  s    xr   c                 *    |                                  S )z|
        Return the widget to give focus to.

        This happens when plugin's dockwidget is raised on top-level.
        )r   r   s    r   get_focus_widgetzEditor.get_focus_widget  s     &&(((r   c                 8   t          j        | |           | j        dS | j                                        r| j                                         n| j                                         |r|                                  | j        	                                 dS )z!DockWidget visibility has changedN)
r   _visibility_changedr   isWindowr   r   rz   refresh_pluginsig_update_plugin_titleemit)r   enables     r   r  zEditor._visibility_changed  s    .tV<<<?"F?##%% 	%""$$$$""$$$ 	"!!!$))+++++r   c                 ~    |                                  }|                                 |                                  dS )zRefresh editor pluginN)get_current_editorstackrefreshrefresh_save_all_actionr   r   s     r   r  zEditor.refresh_plugin  s=    2244$$&&&&&r   c                 6   | j                                         }|                     dt          |                     | j        d         }d}| j        | j                                        }|s+|                                 }|                     d|           n)| j                            d |j	        D                        |                     d| j
                                                   |                     dd | j        D                        |                     d	| j                   | j                                         	 |                    |          s|rd
S | j        dd         D ]}|                                 dS # t$          $ r Y dS w xY w)z3Perform actions before parent main window is closedr\   r   Nr   c                     g | ]	}|j         
S  r   .0finfos     r   
<listcomp>z)Editor.closing_plugin.<locals>.<listcomp>  s    >>>E>>>r   layout_settingswindows_layout_settingsc                 6    g | ]}|                                 S r  )get_layout_settings)r  wins     r   r  z)Editor.closing_plugin.<locals>.<listcomp>  s$    MMM3S,,..MMMr   r]   FT)r   	saveState
set_optionr&   rr   ri   get_active_project_pathget_open_filenamesset_project_filenamesdatar   r#  rt   r]   r   stop_autosave_timersave_if_changedclose
IndexError)r   
cancelabler   r   active_project_pathr   r$  s          r   closing_pluginzEditor.closing_plugin  s   ''))(*;E*B*BCCC'*"=$"&-"G"G"I"I" 	@//11IOOK3333M//>>[-=>>>@ @ @ 	)+??AA	C 	C 	C1MM$:LMMM	O 	O 	O 	(9::: 	))+++	..z:: z u-aaa0    CIIKKKKt 	 	 	44	s   	F
 "&F
 

FFc                 l9    t           t          d          t          j        d          t          d           j        t
          j                   _                              j        ddd           t           t          d          t          d	           j	        
           _
                              j
        dd	           t           t          d          t          j        d          t          d           j        t
          j                   _                              j        ddd           t           t          d          t          j        d          t          d           j                   _        t           t          d          t          j        d          t          d           j        t
          j                   _                              j        ddd           t           t          d          t          j        d          t          d           j        t
          j                   _                              j        ddd           t           t          d          dt          j        d          t          d           j        t
          j                  }                     |dd           t           t          d           dt          j        d          t          d!           j        "          }t           t          d#          t          d#           j        
          }t           t          d$          t          j        d%          t          d&           j                   _        t           t          d'          t          j        d(          t          d)           j                   _        t           t          d*          t          j        d+          t          d,           j        t
          j                   _                              j        dd-           t          d.          }t           |t          j        d/          | j        t
          j                  }                     |d0d1d           t           t          d2          t          j        d3           j        t
          j        4          }                     |d0d5           t           t          d6          t          j        d7           j        t
          j        4          }                     |d0d8           t          d9          }t           |t          j        d:          | j        t
          j                  }                     |d0d;           t           t          d<          t          j        d=           j         t
          j        4          }	                     |	dd>           t           t          d?          t          j        d@           j!        t
          j        4          }
                     |
ddA           t           t          dB           j"        "          }t           t          dC          t          j        dD          t          dE           j#                   _$                              j$        dFdGd           t           t          dH          t          j        dI          t          dJ           fdK           _%                              j%        dFdLdM           t           t          dN          t          j        dO          t          dP           fdQ           _&                              j&        dFdRdM           t           t          dS          t          j        dT          t          dU           fdV           _'                              j'        dFdWdM           t           t          dX          t          j        dY          t          dZ           fd[           _(                              j(        dFd\dM           t           t          d]          t          j        d^          t          d_           j)                   _*                              j*        dFd`dM           t           t          da          t          j        db          t          dc           j+                  }                     |dFddd           t           t          de          t          j        df          t          dg          tX          j-         j.        h          }                     |dFdid           t           t          dj          t          j        dk          t          dl           j/                  }                     |dFdmd           t           t          dn          t          j        do          t          dp           j0        t
          j                  }                     |ddqd           t           t          dr          t          ds           j1        t
          j                  }                     |ddtd           t           t          du          t          dv           j2        t
          j                  }                     |ddwd           t           t          dx          t          j        dy          t          dz           j3        t
          j                  }                     |ddxd           t           t          d{          t          j        d|          t          d}           j4        t
          j                  }                     |dd{d           t           t          d~          t          j        d          t          d           j5        t
          j                   _6                              j6        dd~d           t           t          d          t          d           j7        t
          j                  }                     |ddd           t           t          d          t          j        d          t          d           j8                   _9        tu                      _;         j;        <                    d            j9        =                     j;                    j;        j>        ?                     j@                   t           t          d          t          j        d          t          d           jA                   _B        tu                      _C         jC        <                    d            jB        =                     jC                    jC        j>        ?                     jD                   t           t          d          t          j        d          t          d           jE        t
          j                   _F                              jF        ddd           t           t          d          t          j        d          t          d           jA        t
          j                   _G                              jG        ddd           t           t          d          t          j        d          t          d           jH        t
          j                   _I                              jI        ddd           t           t          d          t          j        d          t          d           jJ        t
          j                   _K                              jK        ddd           t           t          d          t          j        d          t          d           jL        t
          j                   _M                              jM        ddd           t           t          d          dz   t          d          z   t          j        d          t          d           jN        t
          j                   _O                              jO        dd           t           t          d          t          d           jP        t
          j                  }                     |dd           t           t          d          t          d           jQ        t
          j                  }                     |dd           t           t          d          dt          j        d          t          d           jR        t
          j                   _S        t           t          d          dt          j        d          t          d           jT        t
          j                   _U        t           t          d          t          j        d          t          d           jV        t
          j                   _W                              jW        dd           t           t          d          t          j        d          t          d           jX        t
          j                   _Y                              jY        dd           t           t          d           fd           _Z        t           t          d           fd           _[        t           t          d           fd           _\        t                     } jZ         j[         j\        f}t          ||           tu          t          d                     }|_                    d           t          ||           t           t          d           j`        "          }t          jb        dddĦ          }t           t          dŦ          c                    |d                                          t          je        ddǦ          t
          j         jf        Ȧ           _g         jg        h                    dɦ            i                    t          dʦ          dd̦          } i                    t          dͦ          ddϦ          } i                    t          dЦ          ddҦ          } i                    t          dӦ          ddզ          } i                    t          d֦          ddئ          }  i                    t          d٦          dڦ          }! i                    t          dۦ          dܦ          }" i                    t          dݦ          ddߦ          }#||||| |!|"|#d _j        t           t          d          t          d           jk        
          }$t           t          d          t          j        d           jl        t
          j        4          }%                     |%dd           t           t          d          t          j        d          t          d           jm                  }&t           t          d           jn        "           _o        t           t          d          t          d           jp        
           _q        g  _r        t          jt        dk    rt           t          d          t          je        dd           ju                   _v        t           t          d          t          je        dd           jw                   _x                              jv        dd                                 jx        dd           t           jx         jv        g _r        tu          t          d                      _z         jz        j>        ?                     j{                   ddl|m}}'m~}(  j        j                             j        |'j        |(j        |(j        d            j         j
         jz        g})|)D ]5}* j        j                            |*|'j        |(j        |(j        d           6 j         j        || j        g}+|+D ]5}, j        j                            |,|'j        |(j        |(j        d           6| j        g}-|-D ]5}. j        j                            |.|'j        |(j        |(j        d           6 j         j        g}/|/D ]5}0 j        j                            |0|'j        |(j        |(j        d           6t          jt        dk    r8 j        j                             jr        |'j        |(j        |(j        d            j         j         j         j        g j        j        z   }1 j        xj        |1z  c_        |||||%g}2|||g j        _         jO        || jS         jU         jW         jY        g _        t           j        d          sg  j        _        |2 j        j        z    j        _        ||||t          |||||t          g}3|3 j        j        z    j        _        ||||g}4 j        xj        |4z  c_         j$         j6         j%         j'         j(         j&         j*        t          |	|
|g}5|5 j        j        z    j        _         j$         j%         j'         j(         j&         j*        g}6 j        xj        |6z  c_        ||||| |!|"|#t           j9         jB         jF         jG        t           jI         jK         jM        t          |||$ jg        g}7|7 j        j        z    j        _        |1t          gz   |4z   t          gz   |6z    _        |||	|
 j$         j6        ||||||g _        ||g _         j         j        ||| j         j        |%|& j         j         jO         j         jS         jU        gz    _        |%|&g _         j        S )z*Return a list of actions related to pluginz&New file...filenewzNew file)r  tip	triggeredcontextrK   T)r6  rd   add_shortcut_to_tipzO&pen last closedzOpen last closed)r4  r5  )r6  rd   z&Open...fileopen	Open filez&RevertrevertzRevert file from disk)r  r4  r5  z&Savefilesave	Save filez	Sav&e allsave_allzSave all fileszSave allzSave &as...N
filesaveaszSave current file as...)r4  r5  r6  zSave AszSave copy as...zSave copy of current file as...)r5  zPrint preview...z	&Print...printzPrint current file...z&Close	filecloseClose current filez
C&lose allfilecloseallzClose all opened filesz	Close allz
&Find textfindfind_replacez	Find textz
Find &nextfindnext)r  r5  r6  z	Find nextzFind &previousfindpreviouszFind previousz&Replace textreplacezReplace textSet/Clear breakpointbreakpoint_big
BreakpointSet/Edit conditional breakpointbreakpoint_cond_bigzConditional breakpointClear breakpoints in all filesz&Debugr   z
Debug filer   DebugStepzarrow-step-overzRun current linec                  .                          d          S )Nnextdebug_commandr   s   r   r   z+Editor.get_plugin_actions.<locals>.<lambda>|      d0088 r   zDebug Step Over)r7  Continuezarrow-continuez(Continue execution until next breakpointc                  .                          d          S )NcontinuerR  r   s   r   r   z+Editor.get_plugin_actions.<locals>.<lambda>  s    d00<< r   zDebug Continuez	Step Intozarrow-step-inz,Step into function or method of current linec                  .                          d          S )NsteprR  r   s   r   r   z+Editor.get_plugin_actions.<locals>.<lambda>  rT  r   zDebug Step IntozStep Returnzarrow-step-outz,Run until current function or method returnsc                  .                          d          S )NreturnrR  r   s   r   r   z+Editor.get_plugin_actions.<locals>.<lambda>  s    d00:: r   zDebug Step ReturnStop
stop_debugStop debuggingz
Debug Exit&RunrunzRun fileRunz&Configuration per file...run_settingszRun settings)r  r4  menuroler5  	ConfigurezRe-run &last script	run_againzRun again last fileRe-run last scriptzRun &selection or current linerun_selectionzRun selection or current linezRun selectionzRun &to current linezRun to current linezRun to linezRun &from current linezRun from current linezRun from linezRun cellrun_cellz+Run current cell 
[Use #%% to create cells]zRun cell and advancerun_cell_advancez(Run current cell and go to the next one z
Debug cell
debug_cellz$Debug current cell (Alt+Shift+Enter)zRe-run last cellzRe run last cell zre-run last cellzShow todo list	todo_listzLShow comments list (TODO/FIXME/XXX/HINT/TIP/@todo/HACK/BUG/OPTIMIZE/!!!/???)zQMenu {menu-scrollable: 1;}zShow warning/error listwng_listz"Show code analysis warnings/errorszPrevious warning/errorprev_wngz*Go to previous code analysis warning/errorzPrevious warningzNext warning/errornext_wngz&Go to next code analysis warning/errorzNext warningzLast edit locationlast_edit_locationzGo to last edit locationzPrevious cursor positionprev_cursorzGo to previous cursor positionzNext cursor positionnext_cursorzGo to next cursor positionComment/	Uncommentcomment!Comment current line or selectionzToggle commentzAdd &block commentz2Add block comment around current line or selectionBlockcommentzR&emove block commentz5Remove comment block around current line or selectionUnblockcommentIndentTabindent Indent current line or selectionUnindentz	Shift+Tabunindent"Unindent current line or selectionzToggle Uppercasetoggle_uppercasez-Change to uppercase current line or selectionztransform to uppercasezToggle Lowercasetoggle_lowercasez-Change to lowercase current line or selectionztransform to lowercasezCRLF (Windows)c                 0                         d|           S )NrN   toggle_eol_charscheckedr   s    r   r   z+Editor.get_plugin_actions.<locals>.<lambda>w  s    D$9$9$$H$H r   toggledz	LF (Unix)c                 0                         d|           S )Nposixr  r  s    r   r   z+Editor.get_plugin_actions.<locals>.<lambda>|  s    D$9$9'7$K$K r   z
CR (macOS)c                 0                         d|           S )Nmacr  r  s    r   r   z+Editor.get_plugin_actions.<locals>.<lambda>  s    D$9$9%$I$I r   zConvert end-of-line characterszcheckbox-paddingzRemove trailing spacesr   provider_configurationlspvalues
formattingrQ   !Format file or selection with {0}rL   autoformatting)shortcutr6  r5  FzShow blank spacesblank_spacesset_blanks_enabledzScroll past the endscroll_past_endset_scrollpastend_enabledzShow indent guidesindent_guidesset_indent_guideszShow code foldingcode_foldingset_code_folding_enabledz'Show selector for classes and functionsshow_class_func_dropdownset_classfunc_dropdown_visiblezShow code style warningspycodestylezShow docstring style warnings
pydocstylezUnderline errors and warningsunderline_errorsset_underline_errors_enabled)r  r  r  r  r  r  r  r  zFix indentationz*Replace tab characters by space characterszGo to line...gotolinez
Go to linezSet console working directoryDirOpenIconzUSet current console (and file explorer) working directory to current script directoryz!Maximum number of recent files...zClear this listClear recent files listdarwinzGo to next filezgo to previous file)r  r5  zGo to previous filezgo to next filezOpen &recentr   )rH   FileMenuSections)menu_idsectionbefore_sectionomit_idsearch_menu_actions)r,   r   r+   r  newr   WidgetShortcut
new_actionregister_shortcutopen_last_closedopen_last_closed_actionr   open_actionr:  revert_actionsavesave_actionr=  save_all_actionsave_assave_copy_asprint_preview
print_fileprint_action
close_fileclose_actionclose_all_filesclose_all_actionrC  	find_nextfind_previousrG  set_or_clear_breakpoint"set_or_edit_conditional_breakpointr<   
debug_filedebug_actiondebug_next_actiondebug_continue_actiondebug_step_actiondebug_return_actionstop_debuggingdebug_exit_actionrun_filer   NoRoleedit_run_configurationsre_run_filerg  run_to_linerun_from_linerh  run_cell_and_advancerj  debug_cell_actionre_run_last_cellgo_to_next_todotodo_list_actionr   	todo_menusetStyleSheetsetMenuaboutToShowr   update_todo_menugo_to_next_warningwarning_list_actionwarning_menuupdate_warning_menugo_to_previous_warningprevious_warning_actionnext_warning_actiongo_to_last_edit_locationprevious_edit_cursor_actiongo_to_previous_cursor_positionprevious_cursor_actiongo_to_next_cursor_positionnext_cursor_actiontoggle_commenttoggle_comment_actionblockcommentunblockcommentr{  indent_actionr~  unindent_actiontext_uppercasetext_uppercase_actiontext_lowercasetext_lowercase_actionwin_eol_actionlinux_eol_actionmac_eol_actionr   r-   setObjectNameremove_trailing_spacesr"   getr   
capitalizeget_shortcutformat_document_or_selectionformatting_action
setEnabled_create_checkable_actionrp   fix_indentation
go_to_line_Editor__set_workdirchange_max_recent_filesmax_recent_actionclear_recent_filesclear_recent_actiontab_navigation_actionssysplatformgo_to_next_filego_to_next_file_actiongo_to_previous_filego_to_previous_file_actionr.   recent_file_menuupdate_recent_file_menuspyder.plugins.mainmenu.apirH   r  r   mainmenuadd_item_to_application_menuFileNewRestartOpenSavePrintClose
Navigationfile_toolbar_actionssearch_toolbar_actionsrn   hasattrr  run_menu_actionsrun_toolbar_actionsdebug_menu_actionsdebug_toolbar_actionssource_menu_actionsrm   rl   cythonfile_compatible_actionsrk   ro   )8r   save_as_actionsave_copy_as_actionprint_preview_action_textfind_actionfind_next_actionfind_previous_actionreplace_actionset_clear_breakpoint_actionset_cond_breakpoint_actionclear_all_breakpoints_action
run_actionconfigure_actionre_run_actionrun_selected_actionrun_to_line_actionrun_from_line_actionrun_cell_actionrun_cell_advance_actionre_run_last_cell_actionblockcomment_actionunblockcomment_actioneol_action_groupeol_actionseol_menutrailingspaces_action	formattershowblanks_actionscrollpastend_actionshowindentguides_actionshowcodefolding_actionshow_classfunc_dropdown_actionshow_codestyle_warnings_actionshow_docstring_warnings_actionr  fixindentation_actiongotoline_actionworkdir_actionrH   r  open_actionsr  save_actionsr  print_actionsr  close_actionsr  r  r  r  r  r   r!  r"  s8   `                                                       r   get_plugin_actionszEditor.get_plugin_actions  s    (.!!Xi((a
mm()
 
 
 	t$.D 	 	J 	J 	J (5%&&())/	(
 (
 (
$ 	t;X$6 	 	8 	8 	8 )q}}Xj))q~~))+ + + 	t/$/T 	 	K 	K 	K +49Xh''Q/F-G-G+' ' ' )qzzXj))q~~))+ + + 	t/$/T 	 	K 	K 	K  -T1[>>Xj))q1A/B/B-) +  +  + 	t3X$.D 	 	J 	J 	J 'tQ}-=-=t&&A.G,H,H,)+ + + 	~xCCC+D!4E2F2F&&*K(L(L+- - -  -T15G3H3H())T5G I  I  I)$+Xg&&A.E,F,F/+ + + *$(Xk**2F0G0G/+ + + !.dAlOOXn--15M3N3N.)!+ !+ !+ 	t4h$/ 	 	1 	1 	1 ,#D%chv6F6F(-,.,=? ? ? 	{N$/T 	 	K 	K 	K(q.1hz.B.B37>131BD D D 	/$/ 	 	1 	1 	1,T15E3F3F25(>2J2J7;7I575F H  H  H 	3^$3 	 	5 	5 	5/""&tU)9L9L+0DL/1/@B B B 	~~$2 	 	4 	4 	4 '4D$%&<$=$=),2B)C)C.2.J,.,=	'? '? '?#
 	:H$0 	 	2 	2 	2 &34?@@!$*?!@!@&*&M$&$5	&7 &7 &7"
 	98$< 	 	> 	> 	> (5T$%&F$G$G.2.H(J (J (J$
 *!H++'"",o	' ' '
 	t0#G37 	 	9 	9 	9 "/!F))+,,!4F2G2G8888": ": ": 	t5s<M37 	 	9 	9 	9 &3!J--*++<==<<<<	&> &> &>"
 	&-= $ 	 	& 	& 	& "/!K../**@AA8888	": ": ":
 	t5s<M37 	 	9 	9 	9 $1!M""*++@AA::::	$< $< $< 
 	$c+> $ 	 	& 	& 	& "/!F)),''Q/?-@-@)"+ "+ "+ 	t5sL37 	 	9 	9 	9 #46%'(}}-1]< < <
 	z3U37 	 	9 	9 	9 )*++.)).!!^24 4 4 	/$/T 	 	K 	K 	K &dA.C,D,D+.8K+@+@ !"7 8 8&*&68 8 8 	}c$837 	 	9 	9 	9 ,D! 5C 3D 3D14/1J1J01 3A 1B 1B6:6H464EG G G 	2H$3 	 	O 	O 	O +43I1J1J/01F/G/G595E353DF F F 	18$1t 	 	M 	M 	M  -T15M3N3N123J1K1K7;7I575F H  H  H 	3X$3 	 	O 	O 	O (jMM!$*!5!5 ! #> !? !?&*m$&$57 7 7 	$.D 	 	J 	J 	J #0$%%,--<==/%#' #' #' 	6$:37 	 	9 	9 	9 "/lOO,'' & ' 'o%"' "' "' 	t5x$037 	 	9 	9 	9 #0'((,--!2,	#. #. #.
 	6'/$637 	 	9 	9 	9 !.d"###(;*?*? 3 4 4.	!0 !0 !0
 t$$%BCCC%%dn555"**4+@AAA#0+,,38J3G3G:;;1$3 $3 $3  "$KK''(EFFF (():;;;%--d.FGGG'4T*++#(:2F2FBCC5)	(+ (+ (+$
 	t;'/$637 	 	9 	9 	9 $1&''chz.B.B>??1)	$+ $+ $+ 
 	t7'/$237 	 	9 	9 	9
 ,9&''ch7K.L.L0117)	,+ ,+ ,+(
 	t?'/$837 	 	9 	9 	9 '4D,--CH]4K4K677=)	'+ '+ '+#
 	t:'/$>37 	 	9 	9 	9 #0())0G0G2339)	#+ #+ #+
 	t6'/$:37 	 	9 	9 	9 &34)S ;/chy6I6I9::-r7H&J &J &J" 	t98$4 	 	6 	6 	6+D!4H2I2I 8 9 9+R5FH H H 	2H$2 	 	4 	4 	4 -d)** : ; ;-r7H	!J !J !J
 	4h$4 	 	6 	6 	6 +4(U(););899+r/@B B B  -T*{*1E1E:;;-1B D  D  D
 &34$%%CH5G,H,HEFF-r7H&J &J &J" 	t98$< 	 	> 	> 	> &34$%%CH5G,H,HEFF-r7H&J &J &J" 	t98$< 	 	> 	> 	> ,HHHH
 
 

 !.kNNKKKK!
 !
 !

 ,lOOIIII
 
 

 (--*D,A*,$k222;<<dCC1222Hk*** -&''1!3 !3 !3
 HE 	 "/12299$$&&( (&x1ABB%7"9 "9 "9 	))%000 !99!""N4HJ J  $<<#$$&7' )  ) #'"?"?"##_6I#K #K "&!>!>!""N4N"P "P *.)F)F788&(H*J *J& *.)F)F())=*; *;& *.)F)F-..*> *>&  88-.. >@ @
 !2#7!8 6,J=<$4"6 "6 !.dA6G4H4HHII $ 4!6 !6 !6 (a.@.@-0Xj-A-A26/020AC C C 	$0 	 	2 	2 	2 't122Xm,, D E E,. . . "/t1222"4 "4 "4 $1  a(A&B&B-$/ $/ $/  ')#<8##*7#$$*85JKK.	+ + +D' /<'((*85FGG2	/ / /D+ ""+ & #   
 ""/ * #    /++D' !&a&7&7 > >)11$2NOOO	0 	0 	0 	0 	0 	0 	0 	0 		77O$)$(+3 	8 	 	 	 (!

 ( 	 	KI;;(-(-/7 <      
 ( 	 	KI;;(-(-/7 <     !
 * 	 	LI;;(-(./7 <     !
 * 	 	LI;;(-(./7 <     <8##I;;+(-(3/7 <    "&$2B $ 0$2F!H $	 >!? 		&&*>>&&  +/3-.	0 -8,<,:,<	(
 #'"<"57L"&"4d6J"&"<"&"<	"> ty"788 	/,.DI)  $)"?? 		% '33^/1C0-,n> ty99 		")?68KM	%%)<<%% """$&"'&(
 !== 		$ ""$&"!
 		''+@@''  #"***!$($,'#!!"-
2  $)"?? 		%
 !   "	" 	! '&"##!-
) /9:J-K*- #$!$!%*""$ 	#& $3N"C**r   c                 b    |                                  }|r|                    ||           dS dS )a  
        Enable/disable debugging actions and handle pdb state change.

        Some examples depending on the debugging state:
        self.debug_action.setEnabled(not state)
        self.debug_cell_action.setEnabled(not state)
        self.debug_next_action.setEnabled(state)
        self.debug_step_action.setEnabled(state)
        self.debug_return_action.setEnabled(state)
        self.debug_continue_action.setEnabled(state)
        self.debug_exit_action.setEnabled(state)
        N)r   update_debugger_panel_state)r   r   	last_stepr   s       r   update_pdb_statezEditor.update_pdb_state  sF     0022 	I66uiHHHHH	I 	Ir   c                 Z   | j                             t          j        d          }| j                             t          j        d          }| j                             t          j        d          }| j         j                            | j                   | j         j        j	                            | j
                   | j                            | j         j                   |r| j         j        j                            | j                   | j         j        j                            | j
                   | j         j        j                            | j                   | j         j        j                            | j                   | j                            | j         j        j                   |r|                     | j         j                   |rl|                    d| j                   |                    d| j                   |                    d| j                   |                    d| j                   |                                  |                     di            tA          | | j         j!        | j"        | j#        | $                                          | _%        dS )	z'Register plugin in Spyder's main windowFrS   
cell_countcurrent_filenameget_file_coderh  r  N)&r   r   r   r   OutlineExplorerIPythonConsoler   r   consolesig_edit_goto_requestedr   redirect_stdioredirect_internalshell_stdior   "sig_language_completions_availabler   sig_open_filesig_editor_rpcr  sig_stop_completionsr   !sig_file_opened_closed_or_updatedfile_opened_closed_or_updatedr   rj   #register_spyder_kernel_call_handlerhandle_cell_counthandle_current_filenamehandle_get_file_codehandle_run_celladd_dockwidgetrQ  r3   switcherr   r  r  switcher_manager)r   r   rj   
ipyconsoles       r   register_pluginzEditor.register_plugin  s   i**7+>e*LL)..#5 / 2 2Y))'*@)NN
	,44+	- 	- 	-	199$)DDD##DI$JKKK 		EI!DLL57 7 7I!/77	BBBI!088HHHI!6>>-/ / / 2::	%CE E E  	@$$TY%>??? 	2::d46 6 6::"D$@B B B::!:< < <::D02 2 2 	eR((( !6I#())++!- !- !-r   c                 t   d |D             }t          t          ||                    }| j                                        D ]t\  }}||v rk|dk    rd}d}n
d}||         }|                     ||          }	|                    d           |                    |	           |                    d           ud S )Nc                 L    g | ]!}t          |t                    r|d          n|"S ))
isinstancetuple)r  opts     r   r  z-Editor.update_source_menu.<locals>.<listcomp>  s?     , , , $.c5#9#9BBs , , ,r   r  rL   r   rV  TF)r   ziprp   itemsr   blockSignals
setChecked)
r   r   r  option_namesnamed_optionsrd   actionr  rr  r   s
             r   update_source_menuzEditor.update_source_menu  s    , ,#*, , ,Sw7788 288:: 	+ 	+LD&}$$---&G,CC+G'-CW== ##D)))!!%(((##E***	+ 	+r   c                    |                                  }|                                 }| j        D ]Y}|                    ||           t	          j        dd          }|j        D ]$}|j        j        }|	                    ||           %ZdS )zUpdate font from Preferencesr   zcompletion/sizeN)
get_fontget_color_schemerr   set_default_fontr"   r  r*  rL   completion_widgetsetup_appearance)r   fontcolor_schemer   completion_sizer  comp_widgets          r   update_fontzEditor.update_font,  s    }},,.., 	D 	DK((|<<<"hv/@AAO$) D D#l<,,_dCCCCD	D 	Dr   c                     | j         D ]>}|j        D ]4}|j        j        }	 |                    |           %# t
          $ r Y 1w xY w?dS )z
        Set ancestor of child widgets like the CompletionWidget.

        Needed to properly set position of the widget based on the correct
        parent/ancestor.

        See spyder-ide/spyder#11076
        N)rr   r*  rL   r  	setParentRuntimeError)r   ancestorr   r  r  s        r   set_ancestorzEditor.set_ancestor7  s}      , 	 	K$) 
 
#l<))(3333#   D
	 	s   6
AArQ   c                 J     fd}t           ||          }|                    d           dvr)|                                                              n/t	          j        ddddfd	          }|                    |           |                    d	           |S )
a`  Helper function to create a checkable action.

        Args:
            text (str): Text to be displayed in the action.
            conf_name (str): configuration setting associated with the
                action
            method (str): name of EditorStack class that will be used
                to update the changes in each editorstack.
        c                 ^                                                          |            d S r   )r   _toggle_checkable_action)r  	conf_namer   r   s    r   tooglez/Editor._create_checkable_action.<locals>.toogleW  s3    !!###))'69EEEEEr   r  Tr  r  r   r  r  r  F)r,   ru  rv  r   r"   r  )r   textr  r   r  ry  rr  s   ` ``   r   r  zEditor._create_checkable_actionM  s    	F 	F 	F 	F 	F 	F 	F tT6:::D!!!999dooi889999()5(IF C
 c"""E"""r   c                    |rx| j         rY| j         D ]Q}	 t          ||          } ||           # t          $ r&}t                              |d           Y d}~Jd}~ww xY w|                     ||           dS |dv rt          j        dddd|f|           | j        	                    t          j        d	
          r#| j        j        }|                    g            dS dS )a  
        Handle the toogle of a checkable action.

        Update editorstacks, PyLS and CONF.

        Args:
            checked (bool): State of the action.
            method_name (str): name of EditorStack class that will be used
                to update the changes in each editorstack.
            conf_name (str): configuration setting associated with the
                action.
        T)exc_infoNr  r   r  r  r  FrS   )rr   r   r   r   rT   r&  r"   setr   r   r   r   r   after_configuration_update)r   r  method_namer  r   r   er   s           r   r  zEditor._toggle_checkable_actionl  s,     	;  7#'#4 7 7K7!(k!B!Bw) 7 7 7Q666666667OOIw/////999!-uh	J   y##G$7u#EE ;"i366r:::::; ;s   0
A AA c                     t          j                    }t          |t                    r|S | j        D ]}|                    |          r|c S d S r   )r   focusWidgetrp  r7   rr   isAncestorOf)r   fwidgetr   s      r   __get_focused_editorstackz Editor.__get_focused_editorstack  sj    *,,g{++ 	'N#0 ' '++G44 '&&&&'' 'r   c                 .    || j         |<   || j         d <   d S r   rs   r   r   r   s      r   set_last_focused_editorstackz#Editor.set_last_focused_editorstack  s"    6A%l3.9%d+++r   Nc                     | j         |         S r   r  )r   r   s     r   get_last_focused_editorstackz#Editor.get_last_focused_editorstack  s    ,\::r   c                 z    t          | j                                                  D ]\  }}||u r
d | j        |<   d S r   )listrs   rt  )r   r   r   widgets       r   remove_last_focused_editorstackz&Editor.remove_last_focused_editorstack  sY    $(-3355%7 %7 	C 	C L&$$>B-l;	C 	Cr   c                     |                                  }|9| g| j        z   D ]/}|                    |          r|                     ||           .d S d S r   ) _Editor__get_focused_editorstackrt   r  r  )r   r   r$  s      r   save_focused_editorstackzEditor.save_focused_editorstack  sv    4466"vd00 H H##K00 H55c;GGG #"H Hr   c                 N    t                               d            j                            |                                |                                |          r                      |           |                    t           j                  dk                j	        ,|
                     j	                                                   |                     j                   |j                             j        j                   |j                             j        j                   |j                             j        j                   |j                             j        j                   |j                             j        j                   |j                             j        j                   |j                             j                   |j                             j        j                   |j                             j        j                    |j!                             j        j"                   |#                     j$         j%         j&         j'                   |(                     j)                   d}|D ]1\  }} tU          ||           +                    |                     2|,                    t[          j.        dd                     t[          j.        ddd          }t[          j.        dd	d
          }t[          j.        ddd          }|/                    |           |0                    |           |1                    |            2                                }|3                     4                                |           |j5                             j5                   |j6                             j6                   |j7                             j7                   |j8                             fd           |j9                             fd           |j:                             j:                   |j;                             j;                   |j<                             j=                   |j>                             j?                   |j>                             j@        jA                   |j>                             jB                   |jC                             fd           |jD                             fd           |jE                             fd           |jF                             jG                   |jH                             fd           |jH        d                              jI                   |jJ                             jK                   |jJ                             jL                   |j!                             jM                   |jN                             jO                   |jP                             jP                   |jQ                             jR                   |jS                             fd           |jT                             jU                   |jV                             jV                   |jW                             jX                   |jW                             jY                   |jZ                             jZ                   |j[                             j[                   |j                             j\                   |j]                             j^                   |j_                             j`                   |ja                             ja                   |j                             j                   |jb                             jc                   |jb        d                              jc                   |jd                             jc                   |je                             jf                   |jg                             jh                   |ji                             jj                   |jk                             jl                   |jm                             jn                   |jo                             jp                   |jq                             jr                   |js                             jt                   |ju                             jv                   |jw                             jw                    jx        y                    |jx                   d S )NzRegistering new EditorStackr[   )$)set_todolist_enabledrk  )r  r  )r  r  )r  r  )set_linenumbers_enabledline_numbers)set_edgeline_enabled	edge_line)r  r  )r  r  )set_focus_to_editorfocus_to_editor)set_run_cell_copyrun_cell_copy)set_close_parentheses_enabledclose_parentheses)set_close_quotes_enabledclose_quotes)set_add_colons_enabled
add_colons)set_auto_unindent_enabledauto_unindent)set_indent_charsindent_chars)set_tab_stop_width_spacestab_stop_width_spaces)set_wrap_enabledwrap)set_tabmode_enabledtab_always_indent)set_stripmode_enabledstrip_trailing_spaces_on_modify)!set_intelligent_backspace_enabledintelligent_backspace)!set_automatic_completions_enabledautomatic_completions)%set_automatic_completions_after_chars!automatic_completions_after_chars)set_completions_hint_enabledcompletions_hint)set_completions_hint_after_mscompletions_hint_after_ms)"set_highlight_current_line_enabledhighlight_current_line)"set_highlight_current_cell_enabledhighlight_current_cell)#set_occurrence_highlighting_enabledoccurrence_highlighting)#set_occurrence_highlighting_timeoutoccurrence_highlighting/timeout)set_checkeolchars_enabledcheck_eol_chars)set_tabbar_visibleshow_tab_bar)r  r  )!set_always_remove_trailing_spacesalways_remove_trailing_spaces)set_remove_trailing_newlinesalways_remove_trailing_newlines)set_add_newlineadd_newline)set_convert_eol_on_saveconvert_eol_on_save)set_convert_eol_on_save_toconvert_eol_on_save_tohelpconnect/editorr   r  r  r  enable_hover_hintsTr  r  r  format_on_saveFr  r  r  zpycodestyle/max_line_lengthO   c                 8    j                             |           S r   )r[  r  )r   r   s    r   r   z-Editor.register_editorstack.<locals>.<lambda>  s    t/B/G/G/N/N r   c                 :    j                             | |          S r   )exec_in_extconsoler  )r  optionr   s     r   r   z-Editor.register_editorstack.<locals>.<lambda>   s    $($;$@$@v$N$N r   c                  .                          d          S )Nr[   zoomr   s   r   r   z-Editor.register_editorstack.<locals>.<lambda>)  s    DIIaLL r   c                  .                          d          S )Nro  r  r   s   r   r   z-Editor.register_editorstack.<locals>.<lambda>*  s    TYYr]] r   c                  .                          d          S Nr   r  r   s   r   r   z-Editor.register_editorstack.<locals>.<lambda>+  s    tyy|| r   c                 0                         |           S )N)r  )r  sr   s    r   r   z-Editor.register_editorstack.<locals>.<lambda>-  s    48883C3C r   r  c                 4                         | ||          S )N)start_columnr   )fnamelinecolr   s      r   r   z-Editor.register_editorstack.<locals>.<lambda>9  s!    TYYt# &/ &/ &/ r   )zr   r   rr   appendr   r  r  set_closablelenrj   r   r   set_find_widgetr   reset_statusbarr   r   rz   r~   r}   readonly_changedupdate_readonlyencoding_changedupdate_encoding"sig_editor_cursor_position_changedupdate_cursor_positioncurrent_editor_cursor_changedsig_refresh_eol_charsr   
update_eolcurrent_file_changedr|   
update_vcs
file_savedupdate_vcs_stateset_io_actionsr  r  r  r  set_tempfile_pathTEMPFILE_PATHr   r   set_help_enabledr"   r  set_hover_hints_enabledset_format_on_saveset_edgeline_columnsr}  r~  r|  starting_long_processending_long_processsig_option_changedr[  r  run_cell_in_ipyclientdebug_cell_in_ipyclientupdate_plugin_titler  editor_focus_changedr  r   plugin_focus_changedsig_editor_focus_changedzoom_inzoom_out
zoom_resetr^  r   sig_new_filer  sig_close_fileclose_file_in_all_editorstacksremove_file_cursor_historyfile_saved_in_editorstackfile_renamed_in_data#file_renamed_in_data_in_editorstackopened_files_list_changedactive_languages_statsupdate_active_languagessig_go_to_definitionsig_perform_completion_requestr   todo_results_changed sig_update_code_analysis_actionsupdate_code_analysis_actionsupdate_todo_actionsrefresh_file_dependent_actionsr  refresh_eol_charssig_refresh_formattingrefresh_formattingsig_breakpoints_savedbreakpoints_savedtext_changed_atplugin_loadr   r   sig_save_asr  sig_prev_edit_posr  sig_prev_cursorr  sig_next_cursorr  sig_prev_warningr  sig_next_warningr  sig_save_bookmarksave_bookmarksig_load_bookmarkload_bookmarksig_save_bookmarksr;   sig_help_requestedr   register_autosave_for_stack)	r   r   settingsr   settinghover_hintsr  edge_line_columnsr  s	   `        r   register_editorstackzEditor.register_editorstack  sS	   2333  ---&&{333[)) 	2--dK@@@$$S):%;%;a%?@@@#///(33557 7 7''(8999'//0E0JKKK'//0D0IJJJ'//0E0JKKK(00(,(=(MO O O(00)-)=)MO O O:BB!%!6!MO O O:BB24 4 4-55*, , ,,44*, , ,"**02 2 2 	""4?D4D#'#3T5G	I 	I 	I%%d&8999'R  ( 	C 	COFG(GK(()A)ABBBB$$TXf6F%G%GHHHh&	
 
 I
 
 !H,	
 
 	++K888&&~666(():;;;,,..$$T]]__lCCC)11$2LMMM'//0HIII 	&..t/FGGG"**!N!N!N!N	P 	P 	P&..%O %O %O %O	P 	P 	P 	)11$2LMMM+33(	* 	* 	*'//0LMMM(001NOOO(001OPPP(001NOOO##$8$8$8$8999$$%:%:%:%:;;;&&';';';';<<<!))$*?@@@ (()C)C)C)CDDD $,,TX666"**4+NOOO"**4+JKKK&&t'EFFF(00&*&N	P 	P 	P-55040N	P 	P 	P*22(	* 	* 	*(00/ / / /	0 	0 	0 	2::(	* 	* 	*(001JKKK4<<-	/ 	/ 	/4<<$	& 	& 	&2::+/+N	P 	P 	P+33D4PQQQ)11$2HIII*2243JKKK)11$2HIII#++D,@AAA(001JKKK''	222#++DI666%%di000''555%--d.KLLL#++D,OPPP#++D,KLLL$,,T-HIII$,,T-DEEE%--d.@AAA%--d.@AAA&..t/BCCC&..t/FGGG 	11+2FGGGGGr   c                 X   t                               d           |                     |           t          | j                  dk    rb| j                            |          }| j                            |           | j                            | 	                                           dS dS )z8Removing editorstack only if it's not the last remainingzUnregistering EditorStackr[   TF)
r   r   r  r  rr   indexpopr   
set_editorr   )r   r   rP  s      r   unregister_editorstackzEditor.unregister_editorstack\  s    0111,,[999t !!A%%%++K88E!!%(((''(?(?(A(ABBB4 5r   c                     |                     | j        d                    |j        D ]}|                     |j                   d S r  )
clone_fromrr   r*  r   rL   )r   r   r  s      r   clone_editorstackzEditor.clone_editorstacki  sS    t03444 % 	9 	9E**5<8888	9 	9r   c                    | j         D ]x}t          t          |                    |k    rV|                    d           |                    |          }|                    |d           |                    d           yd S )NTforceF)rr   r   idru  get_index_from_filenamer  )r   editorstack_id_strr   r   rP  s        r   r'  z%Editor.close_file_in_all_editorstacksn  s    , 	0 	0K2k??##'999((...#;;HEE&&uD&999((///	0 	0r   c                     | j         D ]8}t          t          |                    |k    r|                    ||           9dS )z5A file was saved in editorstack, this notifies othersN)rr   r   rZ  file_saved_in_other_editorstackr   r\  original_filenamer   r   s        r   r)  z Editor.file_saved_in_editorstackw  s`      , 	F 	FK2k??##'999;;<M<DF F F	F 	Fr   c                     | j         D ]8}t          t          |                    |k    r|                    ||           9dS )z?A file was renamed in data in editorstack, this notifies othersN)rr   r   rZ  rename_in_datar_  s        r   r+  z*Editor.file_renamed_in_data_in_editorstack  sV      , 	H 	HK2k??##'999**+<hGGG	H 	Hr   c           
         | j         j                            t          j                                                  }| j         j                            t          j                                                  }| j         j                            t          j                                                  }t          d          d| j         j	        ft          d          d| j         j
        ft          d          d| j         j        ff| _        t          d          |ft          d          | j         j        ft          d	          | j         j        ft          d
          | j         j        ft          d          | j         j        ft          d          |ft          d          g ft          d          |ff| _        | j        D ]+}|                                 }|                    |           ,dS )z3Setup toolbars and menus for 'New window' instanceszFile toolbarfile_toolbarzRun toolbarrun_toolbarzDebug toolbardebug_toolbarz&Filez&Editz&SearchzSour&cer_  z&Tools&Viewz&HelpN)r   r  get_application_menurH   r  get_actionsToolsHelpr   r  r  r!  rv   rn   r  r"  r  rw   ru   create_new_windowset_layout_settings)r   file_menu_actionstools_menu_actionshelp_menu_actionsr   r$  s         r   r   zEditor.setup_other_windows  s    !I.CC!# ##.;== 	!Y/DD"$ $$/KMM 	 I.CC!# ##.;== 	  //"i<>.."i;=00/"i=?	@ W::'89W::ty'BCY<<)FGY<<)FGV99di&@AX;;(:;W::r*W::'89;  $? 	5 	5O((**C##O4444	5 	5r   c                 h    | j         s)t          t          |                                            dS dS )z`
        Reimplemented method to deactivate shortcut when
        opening a new window.
        N)rt   superrK   r   )r   	__class__s    r   r   zEditor.switch_to_plugin  s<    
 ! 	3&$0022222	3 	3r   c                     t            j         j         j         j                                      d                                                                                                 	                                           
                                 dj        j        j        _                                        j                             fd           S )zCreate a new editor window.)outline_pluginrg  Tc                  .                                    S r   )unregister_editorwindowr   windows   r   r   z*Editor.create_new_window.<locals>.<lambda>  s    )E)Ef)M)M r   )r5   ro   rv   rw   rj   add_toolbars_to_menuget_toolbarsload_toolbarsresizesizer   editorwidgetr   r   
new_windowregister_editorwindow	destroyedr   rx  s   `@r   rl  zEditor.create_new_window  s    !#N/
 
 
 	##GV-@-@-B-BCCCdiikk"""DH*6A""6***  !M!M!M!M!MNNNr   c                 n    t                               d           | j                            |           dS )zRegister a new editor window.zRegistering new windowN)r   r   rt   r   rx  s     r   r  zEditor.register_editorwindow  s2    -...!!&)))))r   c                     t                               d           | j                            |          }d| j        |<   | j                            |           dS )zUnregister editor window.zUnregistering windowN)r   r   rt   rP  rQ  )r   ry  idxs      r   rw  zEditor.unregister_editorwindow  sU    +,,, &&v.."&3s#####r   c                 :    d | j         d         j        D             S )Nc                     g | ]	}|j         
S r  r  r  s     r   r  z(Editor.get_filenames.<locals>.<listcomp>  s    FFF5FFFr   r   rr   r*  r   s    r   get_filenameszEditor.get_filenames  s!    FFD,=a,@,EFFFFr   c                 B    | j         d                             |          S r  )rr   has_filenamer   r   s     r   get_filename_indexzEditor.get_filename_index  s     #00:::r   c                     | j         dt          | j                   dk    r| j         d         }n<|                                 }||$|                     |          }|| j         d         }|S d S )Nr[   r   )rr   r  r  r  r  s      r   r  zEditor.get_current_editorstack  s    (4$%%**"/2"<<>>&,*B"&"C"C$#& #&K"*&*&7&: )(r   c                 Z    |                                  }||                                S d S r   )r  r   r  s     r   r   zEditor.get_current_editor  s3    2244"11333 #"r   c                 Z    |                                  }||                                S d S r   )r  get_current_finfor  s     r   r  zEditor.get_current_finfo  s3    2244"00222 #"r   c                 Z    |                                  }||                                S d S r   )r  r   r  s     r   r   zEditor.get_current_filename  3    2244"33555 #"r   c                 Z    |                                  }||                                S d S r   )r  get_current_languager  s     r   r  zEditor.get_current_language  r  r   c                 B    | j         d                             |          S r  )rr   is_file_openedr  s     r   r  zEditor.is_file_opened  s     #228<<<r   Tc                 X    |                      |          }|                    ||          S )z|Set focus to *filename* if this file has been opened.

        Return the editor instance associated to *filename*.
        )r  set_current_filename)r   r   r   focusr   s        r   r  zEditor.set_current_filename  s-    
 22<@@//%@@@r   c                     | j         rN| j                                         r7|                                 du}| j        D ]}|                    |           dS dS dS )zMEnable/disable file dependent actions
        (only if dockwidget is visible)N)r   r   r   rk   r  )r   r  ry  s      r   r5  z%Editor.refresh_file_dependent_actions  s     ? 	*t88:: 	*,,..d:F5 * *!!&))))	* 	* 	* 	** *r   c                     |                                  }|r:t          d |j        D                       }| j                            |           dS dS )z0Enable 'Save All' if there are files to be savedc              3   z   K   | ]6}|j                                                                         p|j        V  7d S r   )rL   document
isModifiednewly_createdr  s     r   	<genexpr>z1Editor.refresh_save_all_action.<locals>.<genexpr>  sX       7 7! --//::<<S@S 7 7 7 7 7 7r   N)r  anyr*  r  r  )r   r   r   s      r   r  zEditor.refresh_save_all_action  sp    2244 	3 7 7%0%57 7 7 7 7E ++E22222	3 	3r   c                     
                                   }|                                } j                                                                          
|D ]\  }}d|v }|dd                                         |dd         z   }|rt          j        d          nt          j        d          }|f
 fd	}t           ||          }	|	j	        t                                       |            j                            |	           dS )zUpdate warning list menusyntaxNr[   rT   warningc                 2                         |          S Nr   r   _checked_lr   r   s     r   r   z,Editor.update_warning_menu.<locals>.<lambda>  s    DIIhRI4P4P r   r  r  )r   get_current_warningsr  clearr   upperr+   r  r,   r5  boolr   	addAction)r   rL   check_resultsmessageline_numberrT   r  r  slotry  r   s   `         @r   r  zEditor.update_warning_menu  s   ((**3355!!!,,..$1 	0 	0 G['E2A2;$$&&4D(-F38G$$$38I3F3FD'2PPPPPPD"4d>>>FT"**4000''////	0 	0r   c                                                       }|                                } j                                                                          |D ]r\  }}t          j        d          }|f fd	}t           ||          }|j        t                   
                    |            j                            |           s                                  dS )zUpdate todo list menutodoc                 2                         |          S r  r   r  s     r   r   z)Editor.update_todo_menu.<locals>.<lambda>+  s    diiri.J.J r   r  N)r  get_todo_resultsr  r  r   r+   r  r,   r5  r  r   r  r4  )	r   r   resultsr  line0r  r  ry  r   s	   `       @r   r  zEditor.update_todo_menu#  s    2244..00,,.." 	- 	-KD%8F##D',JJJJJJD"4d>>>FT"**4000N$$V,,,,  """""r   c                    |                                  }|                                }|                                }|dk    r6|j        |         j        }| j        D ]}||ur|                    ||           |                                  dS )zl
        Synchronize todo results between editorstacks
        Refresh todo list navigation buttons
        ro  N)r  r  get_stack_indexr*  r   rr   set_todo_resultsr4  )r   r   r  rP  r   other_editorstacks         r   r1  zEditor.todo_results_changed1  s    
 2244..00++--B;;"'.7H%)%6 J J!$K77%66xIII  """""r   c                     t          |          }d| _        |dk    r| j                            d           n;|dk    r| j                            d           n| j                            d           d| _        d S )NFrN   Tr  )r'   r_   r  rv  r  r  )r   os_names     r   r6  zEditor.refresh_eol_chars@  s     ))$d??**40000!,,T2222**4000#r   c                 :    | j                             |           d S r   )r  r  )r   r   s     r   r8  zEditor.refresh_formattingK  s    ))&11111r   c                     t          j        ddd          }| j                            t	          d                              |                                                     d S )Nr   r  rQ   r  )r"   r  r  setTextr   r   r  )r   r>  s     r   refresh_formatter_namezEditor.refresh_formatter_nameN  sn    HE 	 	&&12299$$&&( (	) 	) 	) 	) 	)r   c                    |                                  }|r|                                }|p't          j        d          o|                                }| j        D ]%}|| j        v r|}n|}|                    |           &| j        	                    | 
                                |                                            dS dS )z
        Opened files list has changed:
        --> open/close file action
        --> modification ('*' added to title)
        --> current edited file has changed
        CythonN)r   is_python_or_ipythonr)   is_module_installed	is_cythonrl   r#  r  ra  r  r   r  )r   rL   python_enablecython_enablery  r  s         r   r,  z Editor.opened_files_list_changedX  s     ((** 	J"7799M) O,X66M6;K;K;M;M ; * *T???*FF*F!!&))))277))++T-F-F-H-HJ J J J J	J 	Jr   c                     |                                  }|dS | j        | j        | j        fD ])}|                    |                                           *dS )z$Update actions in the warnings menu.N)r   r  r  r  r  errors_present)r   rL   ry  s      r   r3  z#Editor.update_code_analysis_actionsn  sp    ((** >F /1M/1 	7 	7Ff33556666	7 	7r   c                     |                                  }|                                }|                     d          o|d uot          |          }|| j                            |           d S d S )Nrk  )r  r  r   r  r  r  )r   r   r  r   s       r   r4  zEditor.update_todo_actions{  s~    2244..00-- 6$6),W 	!,,U33333 r   c                     | j                             t          j        d          r!| j         j                            |           d S d S NFrS   )r   r   r   r   r   update_client_status)r   	languagess     r   r.  zEditor.update_active_languages  sN    9 35AA 	BI!66yAAAAA	B 	Br   c                     t          |          }t          |          }t          j        t          j        |                    }t	          |          }t          ||           dS )z'Receive bookmark changes and save them.N)r'   r`   normpathabspathevalr;   )r   r   	bookmarkss      r   r;   zEditor.save_bookmarks  sV    !(++"9--	<H 5 566OO	x+++++r   c                    t          j        | j                  sddt          d          dt          d          dddg}t          j                            d |D                       }	 t          j        t          |          | j        d           n%# t          $ r |                                  Y dS w xY w|                     | j                   dS )	z;Load temporary file from a text file in user home directoryrO   rP   zSpyder EditorrQ   z This is a temporary script file.c                 6    g | ]}t          j        |          S r  )r(   
to_unicode)r  qstrs     r   r  z+Editor.__load_temp_file.<locals>.<listcomp>  s3     $9 $9 $9(, %-$7$=$= $9 $9 $9r   rR   N)r`   ra   r  r   rc   rf   rg   r(   re   r'   rh   r  r   )r   defaultr  s      r   __load_temp_filezEditor.__load_temp_file  s    z$,-- 	0a00";<<b"&G :?? $9 $907$9 $9 $9 : :D~d33T5G&( ( ( (#   


 			$$%%%%%s   ((B B32B3c                     |                                  }|Bt          j        t          j        |                    }| j                            |           dS dS )z1Set current script directory as working directoryN)r   r`   dirnamer  sig_dir_openedr  )r   r  	directorys      r   __set_workdirzEditor.__set_workdir  sY     ))++CK$6$677I$$Y///// r   c                    |dS || j         v r| j                             |           | j                             d|           t          | j                   |                     d          k    r| j                             d           dS dS )zAdd to recent file listNr   max_recent_filesro  )r]   removeinsertr  r   rQ  )r   r  s     r   __add_recent_filezEditor.__add_recent_file  s    =FD%%%$$U+++  E***t !!DOO4F$G$GGG!!"%%%%% HGr   c                     | j         dd         D ].}|                    |d          }|                     |           /dS )zClone file (*src_editor* widget) in all editorstacks
        Cloning from the first editorstack in which every single new editor
        is created (when loading or creating a new file)r[   NF)set_current)rr   clone_editor_fromr   )r   r  r   rL   s       r   _clone_file_everywherezEditor._clone_file_everywhere  sX      ,QRR0 	3 	3K 225e2LLF**62222	3 	3r   c                 \   	 |d}t          j        | j                  \  }}t          j        d|          }|r|                    d          }t          j        t          j        	                    dd                    }|s2t          j        t          j        	                    dd                    }t          j                    |d	}	 ||z  }n1# t          $ r Y n%w xY wd
}t          j        | j                  d         }n# t          t          f$ r	 d}d}d}Y nw xY wd }	||                                 }
n|}
|du }|r| j        dk    r|
j        D ]}|j        j        }t)          d          |v rrt+          j        |          }	 t/          |d                             t)          d                    d                   }|dz   | _        z# t2          $ r
 d| _        Y w xY w	  |	| j                  }| xj        dz  c_        t+          j        |          sn6t7                      }| j                            t<          j        d
          }|r)|                                 |!                                }n5| "                                }||| j#        k    rt+          j$        |          }t+          j%        t+          j&        ||                    }nOt+          j%        tO          |                    }|
(                    |          }||
)                    |          sdS | j*        d         +                    ||||d          }| ,                    |           |
-                    |j                  }| .                    |           |s| /                    d           dS dS )z
        Create a new file - Untitled

        fname=None --> fname will be 'untitledXX.py' but do not create file
        fname=<basestring> --> create file
        NTz!-*- coding: ?([a-z0-9A-Z\-]*) -*-r[   USERNAMErQ   USER-)dateusernameFrR   c                 F    t          t          d                    d| z  z   S )Nuntitledz%d.py)r'   r   )ns    r   r   zEditor.new.<locals>.<lambda>  s    *!>!>'A+!N r   r   r  ro  rS   )emptyrX  )0r(   readrb   researchgroupto_unicode_from_fsrc   environr  timectime	ExceptionIOErrorOSErrorr  r   r*  rL   r   r   r`   splitextintsplit
ValueErrorra   r/   r   r   r   r   get_active_projectr'  r   r  r  r  rg   r'   r  r  rr   r  r  r  r   r  )r   r  r   r  default_contentenc	enc_matchr  VARScreate_fname
current_escreated_from_herer  rT  
fname_dataact_numbasedirri   c_fnamerP  r   s                        r   r  z
Editor.new  s   	#|"&$M$*<==	cI&J&*, ,	 -#//!,,C $6 "
z2 > >@ @   @':#%:>>&##>#> @  @H !JLL ( $;DD    D #(mD$677:! 	# 	# 	#DC"OOO	#
 ON5577JJ$J!TM '	 A%%'_ 2 2E',|'<$}}(888 &)\2B%C%C
	2&) *1 3 3AjMM B B2 F'H 'HG07!D--) 2 2 2
 12D---2 9$T%677!!Q&!!z%(( 	
 %&&Gy++G,<E+JJH 3H7799E"::<<3355&7d6H+H+H!k'22GK% 8 899EE Ku 5 566E++E22E )>)>u)E)E  !!$((T?/3 ) 5 5##E***#88HH&&~666  	"IIDI!!!!!	" 	"sI   CD C D 
CD C$D DD	AGG#"G#c                 :    |                      | j                   dS )zEdit new file templateN)r   rb   r   s    r   edit_templatezEditor.edit_template(  s    		$$%%%%%r   c           	      b   g }| j         D ]+}t          j        |          r|                    |           ,| j                                         |r|D ]}t          | |t          j        |d                    }|j	        t                                       | j                   |                    t          |                     | j                            |           | j                            t%          |          dk               t'          | j        d| j        | j        f           dS )zUpdate recent file menug      ?)scale_factor)r  r   N)r]   r`   ra   r   r  r  r,   r+   get_icon_by_extension_or_typer5  r  r   r   setDatar   r  r  r  r  r-   r  )r   r]   r  ry  s       r   r  zEditor.update_recent_file_menu,  sP   & 	+ 	+Ez%   +##E***##%%% 	8% 8 8&%:C1 1 12 2 2  &..ty999{511222%//7777 ++C,=,=,ABBBD)D$2H,0,D,F 	G 	G 	G 	G 	Gr   c                     g | _         dS )r  N)r]   r   s    r   r  zEditor.clear_recent_files@  s     r   c                     |                                  }t          j        |t          d          t          d          |                     d          dd          \  }}|r|                     d|           dS dS )zChange max recent files entriesrK   zMaximum number of recent filesr  r[   #   N)r  r   getIntr   r   r&  )r   r   mrfvalids       r   r  zEditor.change_max_recent_filesE  s     2244!(akk !ABB#/ABBArK K
U  	5OO.44444	5 	5r   endc
                    | j         }
d| _         	 |                                  n# t          t          f$ r Y nw xY w|                                 }||                                 }nd}|sP|                                 }t          |t                    r't          |
                                t                    }|st                      }| j        t                      | _        | j        t!                      | _        |                                 }||| j        k    rt%          j        |          }| j                            d           |                                 }|.t/          | j        t%          j        |          d                   }nd}t3                      s?t4          j        dk    rt9          |t;          d          |          }|                    | j                            d	                     |                     t8          j!        d           |"                    tF          j$        tF          j%        z  tF          j&        z  tF          j'        z             |(                    t8          j)                   |*                                r|+                                }ntY          |t;          d          || j        |t8          j!        
          \  }}nQt9          |t;          d          t8          j-                  }|*                                r|+                                }| j                            d           |rd |D             }n	|
| _         dS t]          j/                    }| j0        rX| j1        2                                s?|| j0        vr| j0        d         }|3                                 |4                                 nQ| j1        rJ| j5        sC| j1        6                    |          s)t          |tn                    s|                                  d tq          |d          rts          |          }t          |tr                    s |          g}nfdts          |          D             }t          |tt                    r|g}n$|"tw          |          tw          |          k    rd}ty          |          D ]c\  }}|o|dk    }| =                    |||          }|t%          j>        |          s=|                     |          }| j?        d         @                    |d|	|          }|y| A                    |           |=                    ||          }|jB        C                                 |D                    t          |                     | F                    |           |G                                 | H                    |           ||I                    ||         |||           |J                                 |3                                 |K                                4                                 |rt]          jL                     |jM                            ||                    | jN        O                    t          jQ        d          }|rw|R                                }|jS        T                    |jM        d                    |U                                }|V                                }| W                    ||           e|
| _         | X                                 dS )a  
        Load a text file
        editorwindow: load in this editorwindow (useful when clicking on
        outline explorer with multiple editor windows)
        processevents: determines if processEvents() should be called at the
        end of this method (set to False to prevent keyboard events from
        creeping through to the editor during debugging)
        If goto is not none it represent a line to go to. start_column is
        the start position in this line and end_column the length
        (So that the end position is start_column + end_column)
        Alternatively, the first match of word is used as a position.
        TNFr[   rQ   r  r9  )r   captionr  z;;)selectedfilterr   )r   c                 6    g | ]}t          j        |          S r  )r`   r  )r  r  s     r   r  zEditor.load.<locals>.<listcomp>  s"    HHHUS\%00HHHr   r   c                     t          j        t          j        |                     } t          j        dk    rDt          |           dk    r1| d         dk    r%| d                                         | dd          z   } | S )NrN      r[   :r   )r`   r  r(   r  rc   rd   r  r  )r  s    r   _convertzEditor.load.<locals>._convert  sf    K ;E B BCCEw$3u::??uQx3a((qrr2Lr   replaceInStringsc                 &    g | ]} |          S r  r  )r  r  r&  s     r   r  zEditor.load.<locals>.<listcomp>  s!    FFFU%FFFr   )r  )r  	add_whereprocessevents)r   r  
end_columnrS   r  )Yr   r   r   r  r   r   senderrp  r   r   r*  r'   r/   r   r#   r   r$   r  r`   r  r[  r  r  r%   r  r!   r  r	  r   r   setNameFiltersr  	setOptionHideNameFilterDetails	setFilterr
   AllDirsFilesDrivesHiddensetFileModeExistingFilesexec_selectedFilesr   DontUseNativeDialogr   r  rt   r   r   setFocusr   _ismaximizedr  r4   r  r  r  r  	enumerater  ra   rr   r   r  debuggerload_breakpointsset_bookmarksr:   r   analyze_script_Editor__add_recent_filer  
clearFocusry  processEventssig_debug_stopr   r   r   rX  get_current_shellwidgetsig_prompt_readyr   get_pdb_stateget_pdb_last_steprQ  r   ) r   r   r   r   r   r*  r  r+  	set_focusr)  cursor_history_stateeditor0	filename0ry  r  r  parent_widgetr!  dialog_sffocus_widgetrP  r   r  r   r  r  rk  
current_swcurrent_pdb_statepdb_last_stepr&  s                                   @r   r   zEditor.loadO  s   &  $;'+$
	!!####- 	 	 	D	 ))++1133III 	I[[]]F&'** I)&++--HH	 9	$&&G"*&8&:&:# ($4$6$6!//11G"w$2D'D'D+g..$$U+++ 88::M$!+D,?,/L,C,CA,F"H "H "$')) 7<8++(, !+")  F
 ))$*;*A*A$*G*GHHH$$[%FMMM$$T\DJ%>%L'+{&3 4 4 4&&{'@AAA||~~ ;$*$8$8$:$:	%5%+)'5 + A& & &NIss %]AkNN-8-LN N N<<>> 7 & 4 4 6 6I$$T*** HHiHHH		/C,#/11 	$do&?&?&A&A 	$ 4#555#1!4!!###!!!!o 	$d&7 	$o22<@@	$ z::	$ !!###	 	 	 9011 	(YI)T** 	G!),,-IIFFFFd9ooFFFIdC   	6DD#d))s9~~"="=D(33 9	L 9	LOE8,%1*E!66x7C=B 7 D DN %z(++ !99,GG

 )!,11%9"/ 2 1 1 =++E222!+!@!@GL "A "N "N'88:::,,^H-E-EFFF..~>>>))+++&&x000))$u+D7C5? * A A A %%'''##%%%!!##**,,, L*,,,, -224;???!Y11*% 2 9 9
 L!+!C!C!E!EJ/77&5b9; ; ;(2(@(@(B(B%$.$@$@$B$BM))*;]KKK';$""$$$$$s   & ::c                 R    t          |           }|                    dd           |S )z:Create a SimpleCodeEditor instance to print file contents.	scintillaF)r  r  )rI   setup_editorr   rL   s     r   r   zEditor._create_print_editor	  s8    !$''$U 	 	
 	
 	
 r   c                 H   |                                  }|                                 }| j                            |                                           | j                            |j                   | j                            |                                            t          t          j        |                                           }t          || j                  }|                                r|                    t          j        d           |                                }|                                |                                }}| j                                        }|                    |           |                    |t*          j                   | j                            |           | j                            d           |                                }	| j                            d           |	t6          j        k    re|                     t=          d                     |                    |           | j                             |           | !                                 | j                                        "                                 dS )zPrint current file.modeheader_fontTFzPrinting...N)#r   r   r   set_texttoPlainTextset_languager   set_fontr|  r8   r   HighResolutionr   has_selected_textr.  r   PrintSelectionr   selectionStartselectionEndsetPositionr   
KeepAnchorsetTextCursorr[  r  r7  r   Acceptedr  r   
setDocNameprint_r  removeSelectedText)
r   rL   r   printerprint_dialogcursor_1startr  cursor_2answers
             r   r  zEditor.print_file	  sH    ((**,,.. 	##F$6$6$8$8999''888##DMMOO444  X%<,0MMOO= = =#GT-?@@ ##%% 
	7""#7#FMMM ((**H!0022H4I4I4K4K3E)4466H  '''  k&<===,,X666 	  '''##%%  &&&W%%%&&q'7'7888x(((%%g...$$&&& 	%%''::<<<<<r   c                                                       } j                            |                                            j                            |j                    j                                                                        t          t          j
                                                   }t          |           }|                    t          j                   |j                             fd            j                            d           |                                  j                            d           dS )zPrint preview for current file.rY  c                 8    j                             |           S r   )r   rj  )rl  r   s    r   r   z&Editor.print_preview.<locals>.<lambda>U	  s    D.55g>> r   FTN)r   r   r\  r]  r^  r   r_  r|  r8   r   r`  r9   setWindowFlagsr   WindowpaintRequestedr   r[  r  r7  )r   rL   rl  previews   `   r   r  zEditor.print_previewC	  s*    ((** 	##F$6$6$8$8999''888##DMMOO444  X%<,0MMOO= = = +7D99ry)))&&>>>>	
 	
 	

 	  '''  &&&&&r   c                    t          j        dd          sdS | j                            t          j        d          }d}i }|r(|                                }|                                }d}|rRd|v rN|rLt          j	        |d                   t          j	        |          k    rd}| j
                                         n|rd}| j
                                         |S )zT
        Check if a file can be closed taking into account debugging state.
        ipython_consolepdb_prevent_closingTFrS   r  )r"   r  r   r   r   rX  rG  rH  r`   normcase sig_file_debug_message_requestedr  )r   r   rk  	debugginglast_pdb_step	can_closes         r   can_close_filezEditor.can_close_file]	  s     x)+@AA 	4Y))'*@)NN
	 	;"0022I&88::M	 	9M11h1|M'233s|H7M7MMM!	5::<<< 	9I166888r   c                     |                                  }|                     |          r*|                                 }|                                 dS dS )rA  r  N)r   r  r  r  )r   r   r   s      r   r  zEditor.close_fileu	  sa     ,,..11 	%6688K""$$$$$	% 	%r   c                 D    | j         d                                          dS )zClose all opened scriptsr   N)rr   r  r   s    r   r  zEditor.close_all_files}	  s$     	!,,.....r   c                 X    |                                  }|                    ||          S )r<  )rP  rY  )r  r  )r   rP  rY  r   s       r   r  zEditor.save	  s.     2244e5999r   c                     |                                  }|                                r+|                                }|                     |           dS dS )z#Save *as* the currently edited fileN)r  r  r   rA  )r   r   r  s      r   r  zEditor.save_as	  s^     2244   	*4466E""5)))))	* 	*r   c                 V    |                                  }|                                 dS )z(Save *copy as* the currently edited fileN)r  r  r  s     r   r  zEditor.save_copy_as	  s-     2244  """""r   c                 V    |                                                      |           dS )zSave all opened filessave_new_filesN)r  r=  )r   r  s     r   r=  zEditor.save_all	  s-     	$$&&//~/NNNNNr   c                 V    |                                  }|                                 dS )z*Revert the currently edited file from diskN)r  r:  r  s     r   r:  zEditor.revert	  s-     2244r   c                     |                                  }|j                                         |j        j                                         dS )z	Find slotN)r  r   r   search_textr:  r  s     r   rC  zEditor.find	  sH     2244$$&&&+4466666r   c                 `    |                                  }|j                                         dS )zFnd next slotN)r  r   r  r  s     r   r  zEditor.find_next	  s0     2244))+++++r   c                 `    |                                  }|j                                         dS )zFind previous slotN)r  r   r  r  s     r   r  zEditor.find_previous	  s0     2244--/////r   c                 `    |                                  }|j                                         dS )zReplace slotN)r  r   show_replacer  s     r   rG  zEditor.replace	  s0     2244,,.....r   c                    |                                  }|                                }t          |          dk    rI|d         }|                    |           |                    |           |                     |           dS dS )z Reopens the last closed tab.r   N)r  get_last_closed_filesr  r  set_last_closed_filesr   )r   r   last_closed_filesfile_to_opens       r   r  zEditor.open_last_closed	  s    2244'==??!""Q&&,Q/L$$\222--.?@@@IIl#####	 '&r   c                     t          j        t          |                    }| j        d                             |          }|"| j        d                             |           dS dS )zClose file from its namer   N)r`   r  r'   rr   r  r  )r   r   rP  s      r   close_file_from_namezEditor.close_file_from_name	  sd    ;~h7788!!$11(;;a ++E22222 r   c                 0    |                      |           dS )z?File was removed in file explorer widget or in project explorerN)r  r  s     r   removedzEditor.removed	  s    !!(+++++r   c                     t          j        t          |                    }|                                 D ]>}t          j        |                              |          r|                     |           ?dS )z0Directory was removed in project explorer widgetN)r`   r  r'   r  
startswithr  )r   r  r  s      r   removed_treezEditor.removed_tree	  ss    +nW5566'')) 	1 	1E{5!!,,W55 1))%000	1 	1r   c                 R   t          j        t          |                    }| j        d                             |          }|c| j        D ]&}|                    |t          |                     '| j        d         j                            |t          |                     dS dS )z
        Propagate file rename to editor stacks and autosave component.

        This function is called when a file is renamed in the file explorer
        widget or the project explorer. The file may not be opened in the
        editor.
        r   N)new_filename)r`   r  r'   rr   r  rb  r   file_renamed)r   sourcedestr   rP  r   s         r   renamedzEditor.renamed	  s     ;~f5566!!$11(;;#0 N N**88Ft8L8L + N N N Na )66...0 0 0 0 0	 r   c                 <   t          j        t          |                    }t          |          }|                                 D ]V}t          j        |                              |          r-|                    ||          }|                     ||           WdS )z>Directory was renamed in file explorer or in project explorer.)r  r  N)r`   r  r'   r  r  rG  r  )r   r  r  r  tofiler  r  s          r   renamed_treezEditor.renamed_tree	  s    +nV4455%%'')) 	> 	>E{5!!,,W55 >$}}Wf==E===	> 	>r   c                 ^    |                                  }||                                 dS dS )r|  N)r   r{  rW  s     r   r{  zEditor.indent	  s4     ((**MMOOOOO r   c                 ^    |                                  }||                                 dS dS )r  N)r   r~  rW  s     r   r~  zEditor.unindent	  s9     ((**OO r   c                 ^    |                                  }||                                 dS dS )z.Change current line or selection to uppercase.N)r   transform_to_uppercaserW  s     r   r  zEditor.text_uppercase 
  ;     ((**))+++++ r   c                 ^    |                                  }||                                 dS dS )z.Change current line or selection to lowercase.N)r   transform_to_lowercaserW  s     r   r  zEditor.text_lowercase
  r  r   c                 ^    |                                  }||                                 dS dS )rv  N)r   r  rW  s     r   r  zEditor.toggle_comment
  ;     ((**!!##### r   c                 ^    |                                  }||                                 dS dS )z'Block comment current line or selectionN)r   r  rW  s     r   r  zEditor.blockcomment
  s;     ((**!!!!! r   c                 ^    |                                  }||                                 dS dS )z*Un-block comment current line or selectionN)r   r  rW  s     r   r  zEditor.unblockcomment
  r  r   c                     |                                   |                                 }|                                 |                                 }|                                }|                     ||           d S r   )r   r   r  r   r   r   r   rL   r   r   s       r   r  zEditor.go_to_next_todo"
  su    ((**   ,,..""$$""8V44444r   c                     |                                   |                                 }|                                 |                                 }|                                }|                     ||           d S r   )r   r   r  r   r   r   r  s       r   r  zEditor.go_to_next_warning+
  su    ((**!!###,,..""$$""8V44444r   c                     |                                   |                                 }|                                 |                                 }|                                }|                     ||           d S r   )r   r   r  r   r   r   r  s       r   r  zEditor.go_to_previous_warning4
  su    ((**%%''',,..""$$""8V44444r   c                     |rY|                                  }| j        r@|                                  |                    t	          j        |                     d S d S d S )N)	eol_chars)r   r_   r   set_eol_charsr*   get_eol_chars_from_os_name)r   r  r  rL   s       r   r  zEditor.toggle_eol_chars=
  s     	,,..F# %%'''$$(CGLL %     		 	 r   c                 ~    |                                   |                                 }|                                 d S r   )r   r  r  r  s     r   r  zEditor.remove_trailing_spacesF
  s=    2244**,,,,,r   c                 ~    |                                   |                                 }|                                 d S r   )r   r  r  r  s     r   r  z#Editor.format_document_or_selectionL
  s=    22440022222r   c                 ~    |                                   |                                 }|                                 d S r   )r   r  r   r  s     r   r   zEditor.fix_indentationR
  s=    2244##%%%%%r   c                    | j                             | j        d u           | j                            t	          | j                  dk               | j                            t	          | j                  dk               d S r  )r  r  r   r  r  r   r  r   r   s    r   r   zEditor.update_cursorpos_actionsY
  s    (33%T1	3 	3 	3#..())A-	/ 	/ 	/**())A-	/ 	/ 	/ 	/ 	/r   c                     | j         rd S ||                                 }|-|                     |          }|d S |                                }d}t	          | j                  dk    rB| j        d         \  }}||k    r,|                                |                                k    rd}|r| j                                         ng | _        | j        	                    ||f           | 
                                 d S )NFr   ro  T)r   r   _get_editorr   r  r   blockNumberrQ  r   r   r   )r   r   r   rL   replace_last_entryr  hist_cursors          r   r   zEditor.add_cursor_to_historya
  s   ' 	F0022H>%%h//F~&&((F"t'((1,,!%!9"!=E;  %%'';+B+B+D+DDD)-& 	*$((**** (*D$ ''6(:;;;%%'''''r   c                 2    t          |          |f| _        d S r   )r'   r   )r   r   positions      r   r;  zEditor.text_changed_at}
  s    %3H%=%=x$H!!!r   c                    |                                  }|r|                                }|                     t          |          |           |                                 }||                                 | j                            t          j	        d          }|B|
                                }	|                                }
|                     |	|
           d S d S d S r  )r   r   r   r'   r  hide_tooltipr   r   r   rX  rG  rH  rQ  )r   r   r  r  columnrL   r   current_stackrk  	pdb_staterS  s              r   r  zEditor.current_file_changed
  s    ((**  	@&&((F&&~h'?'?HHH !88::M(**,,, --g.D49 . ; ;J%&4466	 * < < > >%%i?????	@ 	@ &%r   c                     |                                  }|rT|                                  }|j        }|                                }|                     t	          |          |           dS dS )z;Handles the change of the cursor inside the current editor.N)r   r   r   r   r'   )r   r  r  rL   code_editorr   r   s          r   r  z$Editor.current_editor_cursor_changed
  s    ((**  	21133K"+H ++--F&&x((&2 2 2 2 2		2 	2r   c                    g }t          | j                  D ]%\  }\  }}||k    r|                    ||f           &|| _        g }t          | j                  D ]%\  }\  }}||k    r|                    ||f           &|| _        dS )z:Remove the cursor history of a file if the file is closed.N)r<  r   r   r   )r   rZ  r   new_historyicur_filenamer   new_redo_historys           r   r(  z!Editor.remove_file_cursor_history
  s    )2(** ** 	; 	;%A%fx''""L&#9:::#. )2(** ** 	@ 	@%A%fx'' ''v(>???#3   r   c                 n   | j         d S | j         \  }}d }t          j        |          r*|                     |           |                                 }n|                     |          }|	d | _         d S ||                                                                k     r|                    |           d S d S r   )	r   r`   ra   r   r   r  r  characterCountset_cursor_position)r   r   r  rL   s       r   r  zEditor.go_to_last_edit_location
  s    $,F!6(:h 	9IIh,,..FF..x88F>(,D%Ffoo''668888&&x00000 98r   c                     |rM|                                 \  }}||k    s*|                                |                                k    r||fS |MdS )z@Get the next cursor from history that is different from current.NN)rQ  r  )r   historyrT  current_cursorr   r   s         r   _pop_next_cursor_diffzEditor._pop_next_cursor_diff
  se     	(&{{}}Hf,,,OO%%)@)@)B)BBB''	  	(
 zr   c                     t          |          D ]F}t          |          dk    r1|                    ||f           |                     |||          \  }}G||                                \  }}||fS )zW
        Move number_steps in the forwards_history, filling backwards_history.
        r   )ranger  r   r  rQ  )r   number_stepsbackwards_historyforwards_historyrT  r  r  s          r   _history_stepszEditor._history_steps
  s     |$$ 		; 		;A#$$q((!((%~68 8 8 ..((.: : 1 . ! "%%'' -n//r   c                 2   d| _         | j        r| j                                         |                                 }|                                                                 }|dk     r(|                     | | j        | j        ||          \  }}n&|                     || j        | j        ||          \  }}| j                            ||f           | 	                                
                                }t          j        |          s||vr| j                                         nR|                     |           |                                 }|                    |           |                                 d| _         |                                  dS )z
        Move the cursor position forward or backward in the cursor
        position history by the specified index increment.
        Tr   FN)r   r   rQ  r   r   r   r  r   r   r  r  r`   ra   r   rg  ensureCursorVisibler   )r   
index_moverT  r  r   rL   s         r   __move_cursor_positionzEditor.__move_cursor_position
  s   
 (,$# 	+$((***  44660022==??>>/3/B/B(( .	02 02,nn 04/B/B(( .	02 02,n 	 ''~.	0 	0 	00022@@BB	
+,, 	)$I55$((****II&''',,..F  000&&(((',$%%'''''r   c                 f    d| _         |                                  |                     d           d S )NTro  r   r   _Editor__move_cursor_positionr   s    r   r  z%Editor.go_to_previous_cursor_position  s6    '+$##B'''''r   c                 f    d| _         |                                  |                     d           d S )NTr[   r  r   s    r   r  z!Editor.go_to_next_cursor_position  s6    '+$##A&&&&&r   c                     t          |t                    rd}|                                 }||                    |           dS dS )zOpen 'go to line' dialogN)rp  r  r  r  )r   r  r   s      r   r  zEditor.go_to_line   sT     dD!! 	D2244"""4((((( #"r   c                     |                                  }|*|                                  |                                 dS dS )rH  N)r  r   r  r  s     r   r  zEditor.set_or_clear_breakpoint)  sM     2244"!!###//11111 #"r   c                     |                                  }|*|                                  |                                 dS dS )rK  N)r  r   r  r  s     r   r  z)Editor.set_or_edit_conditional_breakpoint1  sM     2244"!!###::<<<<< #"r   c                     |                                   t                       | j                                         |                                 }|(|j        D ] }|j        j                                         !| 	                                 dS )rM  N)
r   r<   r:  r  r  r*  rL   r=  clear_breakpointsr  )r   r   r*  s      r   r<   zEditor.clear_all_breakpoints9  s     	##%%%2244"#( 9 9$668888r   c                    t          ||           | j                                         |                                 }|C|                     |          }|.|j        |         j        j                            |           dS dS dS )zRemove a single breakpointN)	r=   r:  r  r  r  r*  rL   r=  toogle_breakpoint)r   r   linenor   rP  s        r   r=   zEditor.clear_breakpointE  s    6***##%%%2244"''11E  '.7II          #"  r   c                     | j                             t          j        d          }|r|                                 dS dS )r^  FrS   N)r   r   r   rX  r  )r   rk  s     r   r  zEditor.stop_debuggingP  sI    Y))'*@)NN
 	(%%'''''	( 	(r   c                     | j                             t          j        d          }|r,|                    ||                     d                     dS dS )zDebug actionsFrS   r  )r  N)r   r   r   rX  pdb_execute_commandr   )r   commandrk  s      r   rS  zEditor.debug_commandV  sr    Y))'*@)NN
 	M**9J)K)K + M M M M M	M 	Mr   c                 P    |                                  }|t          d          |S )zk
        Get the current editorstack.

        Raises an exception in case no editorstack is found
        NzNo editorstack found.)r  r  r  s     r   _get_editorstackzEditor._get_editorstack^  s0     22446777r   c                     |                                  }|dS |sdS |                    |          }|dS |j        |         j        S )z9Get editor for filename and set it as the current editor.N)r  r  r*  rL   )r   r   r   rP  s       r   r  zEditor._get_editorj  sY    ++--4 	4((22=4&--r   c                     |                                  }|                     |          }|"t          d                    |                    ||f|_        |                    |          S )z=
        Get cell code from cell name and file name.
        NFile {} not open in the editor)r  r  r  r   last_cell_callget_cell_code)r   	cell_namer   r   rL   s        r   rg  zEditor.handle_run_celly  sx     ++--!!(++>077AAC C C '/	%:" ##I...r   c                     |                      |          }|"t          d                    |                    |                                S )z$Get number of cells in file to loop.Nr  )r  r  r   get_cell_count)r   r   rL   s      r   rd  zEditor.handle_cell_count  sT    !!(++>077AAC C C $$&&&r   c                 X    |                                                                  j        S )zGet the current filename.)r  r  r   r   s    r   re  zEditor.handle_current_filename  s#    $$&&88::CCr   c                    |                                  }|r-t          j        ddd          r|                    d           |                     |          }|t          j        |          \  }}|S |                                S )z
        Return the bytes that compose the file.

        Bytes are returned instead of str to support non utf-8 files.
        rL   save_all_before_runTr  Fr  )r  r"   r  r=  r  r(   r  r]  )r   r   r=  r   rL   r  _encs          r   rf  zEditor.handle_get_file_code  s     ++-- 	7/? ? ? 	7   666!!(++>!x00JD$K!!###r   c                     t                     }|j                             fd            j        |                     j                   t          j                                                   }|                    |           |	                                r4|j
        }|-                     |                                             d S d S d S )Nc                 .                         |           S r   set_dialog_sizer  s    r   r   z0Editor.edit_run_configurations.<locals>.<lambda>  s    T-A-A!-D-D r   )rE   size_changer   r{   r}  r`   r  r   setupr7  file_to_runr   r  )r   rN  r  s   `  r   r  zEditor.edit_run_configurations  s     &&""#D#D#D#DEEE'MM$*+++D557788U<<>> 	 &E 		%   		  	   r   c                     t          j                                                   }t          j        |          }|                    dd                              dd          }|                    dd                              dd          }t          |          }|t                     }|j                             fd            j	        |
                     j	                   |                    |           t          j        ddt                                 rd	}t          j        ddd
           nt          j        dt                     }|r|                                sdS |                                }|j        rt)                      }|                                }|                                }|j        }	|j        }
|j        }|j        }|j        }|j        }|j        r|}n-|j        rd}n#t          j        |j                   r|j         }nd}d	}||||	||||||
||f _!         "                    d
           dS )z5Run script inside current interpreter or in a new one'z\'"z\"Nc                 .                         |           S r   r  r  s    r   r   z!Editor.run_file.<locals>.<lambda>  s    1E1Ea1H1H r   r`  open_at_least_onceTFrQ   r  )#r`   r  r   r  rG  rD   rG   r  r   r{   r}  r  r"   r  r!   r  rC   r7  get_configurationr  rF   get_argumentsget_python_argumentsinteractpost_mortemcurrentsystermclear_namespaceconsole_namespacefile_dircw_dirisdirdirr   r  )r   r   r  r  runconfrN  show_dlgr   python_argsr  r  r  r  r  r  wdirpythons   `                r   r  zEditor.run_file  sd    D557788 +e$$ c5))11#u==//#u--55c5AA'..?'--F&&'H'H'H'HIII+d.///LLx302224 4 
I
   4e<<<<  8E+GHH  ..00G? 	)&((G$$&&2244#)//!1#5 	DD^ 	DDYw{## 	;DDD$dD(E%{GW*O02 	.....r   c                     || _         d S r   )r{   )r   r~  s     r   r  zEditor.set_dialog_size  s    r   c                     |                                  }||j                                         |                     d           dS )zDebug current scriptNT)r   )r   sig_debug_startr  r  )r   r   s     r   r  zEditor.debug_file  sJ     0022%*//111D!!!!!r   c                 \   |                      d          r|                     |          }||sdS | j        dS | j        \  }}}}}}}	}
}}}}|                      d          }|s$| j                            ||||||
|||	  	         dS | j                            |||||||	||	  	         dS )rf  r  r  Nr  )r   r=  r   run_in_current_ipyclientr  r   open_external_console)r   r  	all_savedr  r  r   r  r   r  r  r  r  r  r  r  r  s                   r   r  zEditor.re_run_file  s     ??011 	^DDI$Y$&F
 #1	dHe	gw	o	//*;<< 		)..tT5+w!2O    
 I++tT8UFK    r   c                 V    |                                  }|                                 dS )z1Run selection or current line in external consoleN)r  rg  r  s     r   rg  zEditor.run_selection"  -     2244!!#####r   c                 V    |                                  }|                                 dS )z/Run all lines from beginning up to current lineN)r  r  r  s     r   r  zEditor.run_to_line(  s-     2244!!!!!r   c                 V    |                                  }|                                 dS )z&Run all lines from current line to endN)r  r  r  s     r   r  zEditor.run_from_line.  r&  r   c                 V    |                                  }|                                 dS )zRun current cellN)r  rh  r  s     r   rh  zEditor.run_cell4  s-     2244r   c                 V    |                                  }|                                 dS )z,Run current cell and advance to the next oneN)r  r  r  s     r   r  zEditor.run_cell_and_advance:  s-     2244((*****r   c                 V    |                                  }|                                 dS )zDebug Current cell.N)r  rj  r  s     r   rj  zEditor.debug_cell@  s-     2244     r   c                 V    |                                  }|                                 dS )zRun last executed cell.N)r  r  r  s     r   r  zEditor.re_run_last_cellF  s-     2244$$&&&&&r   c                    t          j        dd          }|                                 }||v r||         \  }}}t          j        |          r|                    |          }|m|j                            |                                          	                    |          }|
                                j                            ||f           |+|                                  |                    |           dS dS )z+Save current line and position as bookmark.rL   r  N)r"   r  r  r`   ra   r  tabsr  r  findBlockByNumberuserDatar  r  r   set_bookmark)	r   slot_numr  r   r   line_numr  rP  blocks	            r   rD  zEditor.save_bookmarkM  s    HX{33	2244y  )28)<&Hhz(## J#00::$(-44U;;DDFF//99 NN$$.55x6HIII"!!###$$X..... #"r   c                 :   t          j        dd          }||v r||         \  }}}ndS t          j        |          s	d| _        dS |                     |           |                                 }||                                                                k     rt          |                                
                    |                                                    }||k    r|                    |dz   |           dS |                    |dz   |           dS dS )z+Set cursor to bookmarked file and position.rL   r  Nr[   )r"   r  r`   ra   r   r   r   r  	lineCountr  r/  r  r  )r   r2  r  r   r3  r  rL   
linelengths           r   rF  zEditor.load_bookmark^  s#    HX{33	y  )28)<&HhFz(## 	(,D%F		(((**foo''113333V__..//99$$&&B BJ##!!(Q,77777 !!(Q,
;;;;; 43r   c                    |                                                                  }|dk    r*|                                 }|                    |           n[|                                }|                                |z   }|dk    r*|                    |           |                    |           |                                 dS )zZoom in/out/resetr   N)r  r   r|  r_  r  	pointSizesetPointSizeupdate_tab_stop_width_spaces)r   factorrL   r  r~  s        r   r  zEditor.zoomu  s    --//BBDDQ;;==??DOOD!!!!;;==D>>##f,Daxx!!$'''%%%++-----r   c                 j   | j         d}|                     |          }d}|                     |          }d}|                     |          }d}|                     |          }	d}
|                     |
          }| j         D ]}||v r|                    |           ||v r|                    |           ||v r|                    |           ||v r|                    |	           |
|v r|                    |           d}|                     |          }d}|                     |          }d	}|                     |          }d
}|                     |          }d}|                     |          }d}|                     |          }d}|                     |          }d}|                     |          }d}|                     |          }d}|                     |          } d}!|                     |!          }"d}#|                     |#          }$d}%|                     |%          }&d}'|                     |'          }(d})|                     |)          }*d}+|                     |+          },d}-|                     |-          }.d}/|                     |/          }0d}1|                     |1          }2d}3|                     |3          }4d}5|                     |5          }6d}7|                     |7          }8d}9|                     |9          }:d};t          j        dd           }<d!}=|                     |=          }>| 	                                }?| j         D ]x}||v r|
                    |           ||v r|                    |           ||v r|                    |           ||v r|                    |           ||v r|                    |           ||v r|                    |           ||v r|                    ||?"           ||v r|                    |           ||v r|                    |           ||v r|                    |            |!|v r|                    |"           |#|v r|                    |$           |%|v r|                    |&           |'|v r|                    |(           |)|v r|                    |*           |+|v r|                    |,           |-|v r|                    |.           |/|v r|                    |0           |1|v r|                    |2           |3|v r|                    |4           |5|v r|                    |6           |7|v r|                    |8           |9|v r|                     |:           |;|v r|!                    |<           |=|v r|"                    |>|?"           z| j#        $                                D ]]\  }@}A|@|v rT|A%                    d#           |                     |@          }B|A&                    |B           |A%                    d$           ^|                     d%          d&z  | j'        _(        |                     d'          | j'        _)        |?|=|v r|>r|?*                                 dS dS dS dS dS )(z*Apply configuration file's plugin settingsNr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  connect_to_oir  r  rk  )current_finfoTFrV   rW   rX   )+rr   r   r  r  r  r  r  r"   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rp   rt  ru  rv  r   r   r   run_todo_finder)Cr   r   currentline_ncurrentline_ocurrentcell_ncurrentcell_ooccurrence_noccurrence_ooccurrence_timeout_noccurrence_timeout_ofocus_to_editor_nfocus_to_editor_or   tabbar_ntabbar_oclassfuncdropdown_nclassfuncdropdown_olinenb_nlinenb_oblanks_nblanks_oscrollpastend_nscrollpastend_owrap_nwrap_oindentguides_nindentguides_ocodefolding_ncodefolding_otabindent_ntabindent_ostripindent_nstripindent_oibackspace_nibackspace_oremovetrail_nremovetrail_oadd_newline_nadd_newline_oremovetrail_newlines_nremovetrail_newlines_oconverteol_nconverteol_oconverteolto_nconverteolto_oruncellcopy_nruncellcopy_o
closepar_n
closepar_oclose_quotes_nclose_quotes_oadd_colons_nadd_colons_oautounindent_nautounindent_oindent_chars_nindent_chars_otab_stop_width_spaces_ntab_stop_width_spaces_ohelp_nhelp_otodo_ntodo_or  rd   ry  r   sC                                                                      r   apply_plugin_settingszEditor.apply_plugin_settings  s   (4M OOM::M4M OOM::M4L??<88L#D #'??3G#H#H  1 $0A B B#0 G G G++BB@MO O O G++BB@MO O O7**CCLQQQ'722CC;OQ Q Q$//334EFFF &Hx00H"<"&//2E"F"F%Hx00H%Hx00H/O"ooo>>OF__V,,F,N!__^<<N*M OOM::M-K//+66K=M OOM::M2L??<88L;M OOM::M)M OOM::M%F"%)__5K%L%L"0L??<88L5N!__^<<N+M OOM::M,J44J+N!__^<<N'L??<88L,N!__^<<N+N!__^<<N&=#&*oo6M&N&N#$FXf&677F F__V,,F**,,E#0 7J 7Jw&&228<<<"g--99/JJJ!W,,11.AAA G++88GGG&'11>>+- - -w&&228<<<w&&77FK 8 M M MW$$00888'))33K@@@ G++55mDDD7**AA,OOO G++AA-PPP G++//>>>)W44<<.0 0 07**77EEE!W,,::>JJJ G++11-@@@((==jIII!W,,88HHH7**66|DDD!W,,99.III!W,,00@@@*g5599:QRRRW$$00888W$$44VCH 5 J J J !% 6 < < > > / /f7??''--- OOD11E%%e,,,''...
 OO$7884? M"$(OO4F$G$GDM!
  W$$$))+++++} )(x ! $$$$r   r  )r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet edge line to )rr   r   r   r  r   valuer   s      r   r  zEditor.set_edgeline_enabled&  sa    (LL4U44555#0 8 8007777 )(8 8r   r  r   )r  r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet edge line columns to )rr   r   r   r  r  s      r   r  zEditor.set_edgeline_columns-  sc     (LL<U<<===#0 8 8007777 )(8 8r   enable_code_snippetsc                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet code snippets to )rr   r   r   set_code_snippets_enabledr  s      r   r  z Editor.set_code_snippets_enabled8  sa    (LL888999#0 = =55e<<<< )(= =r   r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet automatic completions to )rr   r   r   r  r  s      r   r  z(Editor.set_automatic_completions_enabled?  se    (LL@@@AAA#0 E E==eDDDD )(E Er   r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )Nz'Set chars for automatic completions to )rr   r   r   r  r  s      r   r  z,Editor.set_automatic_completions_after_charsF  se    (LLJ5JJKKK#0 I IAA%HHHH )(I Ir   r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet completions hint to )rr   r   r   r  r  s      r   r  z#Editor.set_completions_hint_enabledM  e    (LL;E;;<<<#0 @ @88???? )(@ @r   r  c                     | j         =t                              d| d           | j         D ]}|                    |           d S d S )NzSet completions hint after z ms)rr   r   r   r  r  s      r   r  z$Editor.set_completions_hint_after_msT  sh    (LLAuAAABBB#0 A A99%@@@@ )(A Ar   r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet hover hints to )rr   r   r   r  r  s      r   r  zEditor.set_hover_hints_enabled[  sc     (LL6u66777#0 ; ;33E:::: )(; ;r   r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet format on save to )rr   r   r   r  r  s      r   r  zEditor.set_format_on_savef  sc    
 (LL9%99:::#0 6 6..u5555 )(6 6r   r  c                     | j         <t                              d|            | j         D ]}|                    |           d S d S )NzSet underline errors to )rr   r   r   r  r  s      r   r  z#Editor.set_underline_errors_enabledp  r  r   
appearanceselectedui_theme)r  r  c                     |dk    r|                      dd          }| j        <t                              d|            | j        D ]}|                    |           d S d S )Nr  r  r  rV  zSet color scheme to )get_confrr   r   r   set_color_scheme)r   r  r  r   s       r   r  zEditor.set_color_schemew  s    ZMM*lMCCE(LL777888#0 4 4,,U3333 )(4 4r   c                 L    | j         d         }g }|d |j        D             z  }|S )z/Get the list of open files in the current stackr   c                     g | ]	}|j         
S r  r  r  s     r   r  z-Editor.get_open_filenames.<locals>.<listcomp>  s    CCCenCCCr   r  )r   r   r   s      r   r(  zEditor.get_open_filenames  s6    '*	CC+2BCCCC	r   c                    |                      d           d}| j        | j                                        }|r| j                                        }n|                     dg           }|r|                                  | j        j        |z   }|rt          d |D                       r|                     dd          }|rc|	                    d          d         \  }}}||v rt          |          t          |          k    r|                    |          }	|                     ||	         ||	         d	
           |	dk    r+|                     ||	dd         ||	dd         dd           |	t          |          dz
  k     r,|                     ||	dz   d         ||	d         dd           | j        j        r"|                     | j        j        dd           n|r|                     ||           | j        j        r|                     | j        j                   nB|r|                     |           | j        j        r|                     | j        j                   | j        rd| _        |"| j                            ||d                    |                     dg           }
|
r|
D ]}| j                            |           |                     | | j        d                    |                                 }|r&|                                                                  n|                                  |                      d	           | j                                         dS )z
        Open the list of saved files per project.

        Also open any files that the user selected in the recovery dialog.
        FNr   r  c                 6    g | ]}t          j        |          S r  )r`   ra   )r  fs     r   r  z+Editor.setup_open_files.<locals>.<listcomp>  s     !G!G!GA#*Q--!G!G!Gr   r   splitsettingsr   T)r   rI  ro  ro  )r   rI  r)  r[   r  )rI  r)  r  )	dont_gotor!  )set_create_new_file_if_emptyri   r'  get_project_filenamesr   r  r   recover_files_to_openr  r  r  rP  r   rq   r   rm  ru   r   r  rr   r  r  _Editor__load_temp_filesig_open_files_finishedr  )r   close_previous_filesr0  r   all_filenamesr   is_verticalcfnameclinesrP  
win_layoutr   r   s                r   setup_open_fileszEditor.setup_open_files  s    	))%000"=$"&-"G"G"I"I 	A;;==IIR@@I 	#  """;iG <	$S!G!G!G!G!GHH <	$__%6==F  "C.4jj.I.I!.L+VV Y&&3y>>S[[+H+H%OOF33EIIi.VE]dISSS qyy		)EI2I"6VEI2I=N,1W " F F F
 I 233		)E!GHH"5F566N,1U " D D D }: D		$-"E,1U " D D D ! :		)&	999}: G		$-"EFFF )IIi(((=6 CIIdmABBB, N05-%';;"+A, < 0 0 0 "__-FKK
 -+5 - -8??+- - - -11$8I!8LMMM 6688K 9,,..66888!!###))$///$))+++++r   c                 V    |                      d|                                            dS )zSave the list of open filesr   N)r&  r(  r   s    r   save_open_fileszEditor.save_open_files  s(    T%<%<%>%>?????r   c                 (    | j         D ]	}||_        
dS )z,Change the value of create_new_file_if_emptyN)rr   create_new_file_if_emptyr  s      r   r  z#Editor.set_create_new_file_if_empty  s)    , 	9 	9K38K00	9 	9r   c                 b    |                                  }|j                            d           dS )z4Switch to next file tab on the current editor stack.r[   Nr  r.  tab_navigater  s     r   r
  zEditor.go_to_next_file  2     2244%%b)))))r   c                 b    |                                  }|j                            d           dS )z8Switch to previous file tab on the current editor stack.ro  Nr  r  s     r   r  zEditor.go_to_previous_file  r  r   c                 D    | j         D ]}|                    |           dS )z
        Set the current active project root path.

        Parameters
        ----------
        root_path: str or None, optional
            Path to current project root path. Default is None.
        N)rr   set_current_project_path)r   	root_pathr   s      r   r  zEditor.set_current_project_path  s7      , 	< 	<K00;;;;	< 	<r   )r  c                @    | j         D ]} |j        |g|R d|i| dS )z?Register a panel in all the editorstacks in the given position.r  N)rr   register_panel)r   panel_classr  r   r  r   s         r   r  zEditor.register_panel  sn      , 	A 	AK&K&A"A A A-5A9?A A A A	A 	Ar   c                     d S r   r  r   s    r   on_mainwindow_visiblezEditor.on_mainwindow_visible  s    r   )F)rQ   r   )NT)NNN)	NNrQ   NTNNTr  )NF)Tr  )__name__
__module____qualname____doc__CONF_SECTIONr1   CONFIGWIDGET_CLASS	CONF_FILEr    r  rb   DISABLE_ACTIONS_WHEN_HIDDENNAMEr   ConsoleREQUIRESr   rW  OPTIONALr   r   r  r"  objectr  r  r  r[  r  r:  ra  r|  r!  r   rH  r  r^   r   r	   r   r   r   r   r   r   r   r   rq  r  staticmethodr  r	  r  r  r  r1  rM  rQ  rl  rz  r  r  r  r  r  r  r  r  r  rN  rS  rV  r'  r)  r+  r   r   rl  r  rw  r  r  r  r   r  r   r  r  r  r5  r  r  r  r1  r6  r8  r  r,  r3  r4  r  r.  r;   r  r  rA  r  r  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r  r=  r:  rC  r  r  rG  r  r  r  r  r  r  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r;  r  r  r(  r  r  r  r  r  r  r  r  r  r<   r=   r  rS  r  r  rg  rd  re  rf  r  r  r  r  r  rg  r  r  rh  r  rj  r  rD  rF  r  r}  r   r  r  r  r  r  r  r  r  r  r  r  r(  r  r  r  r
  r  r  r   PositionLEFTr  r  __classcell__)rs  s   @r   rK   rK   H   s         L)I!M),,M!M-00M"' D H#W%<=H  &vS#tT4tT ;  ;"F3T4@@$fS&#tTBBT**VD\\NVC[[N (.sC(8(8% (.vxx$  &vxx2 %fhhM( M( M( M(^! ! ! 
TVV$ $ V$P P P   
T$ZZ9 9 Z98 
T$__1 1 _1>< < <
; ; ;
   
T#ud  
   \     ) ) ), , ,' ' '" " " "H^+ ^+ ^+@I I I"-- -- --^+ + +*	D 	D 	D  ,   > 
T$S; ; ;B' ' ': : :
; ; ; ;C C CH H HmH mH mH^  9 9 9
 
T#s^^0 0 ^0 
T#sCF F F 
T#sCH H H5 5 5>3 3 3 3 3  &* * *
$ $ $G G G; ; ;   4 4 4
3 3 3
6 6 6
6 6 6
= = = =A A A A* * *3 3 30 0 0# # ## # #	$ 	$ 	$2 2 2) ) )J J J,7 7 74 4 4 
T#YYB B YB
, , ,& & && 
TVV0 0 V0& & &3 3 3 
TVV	T#YYd" d" d" Y Vd"L& & &G G G( 
TVV  V 
TVV5 5 V5 
TVV	T#YY	T#sC	T#sC  35AE8={% {% {% !   Y V{%z   
TVV(= (= V(=T 
TVV' ' V'2   0 
TVV% % V% 
TVV/ / V/ 
TVV: : : V:
 
TVV* * V* 
TVV# # V#
 
TVVO O O VO 
TVV  V
 
TVV7 7 V7 
TVV, , V,
 
TVV0 0 V0
 
TVV/ / V/
$ $ $3 3 3, , ,1 1 10 0 0"> > > 
TVV  V 
TVV  V 
TVV, , V, 
TVV, , V, 
TVV$ $ V$ 
TVV" " V" 
TVV$ $ V$
 
TVV5 5 V5 
TVV5 5 V5 
TVV5 5 V5   
TVV- - V-
 
TVV3 3 V3
 
TVV& & V&/ / /( ( ( (8I I I@ @ @,2 2 24 4 4  
TVV1 1 V1&  0 0 0.+( +( +(Z 
TVV( ( V(
 
TVV' ' V'
 
TVV) ) ) V) 
TVV2 2 V2 
TVV= = V= 
TVV	 	 V		  	  	 ( ( (M M M
 
 
. . ./ / / 	' 	' 	'D D D$ $ $ $( 
TVV    V  
TVV?/ ?/ ?/ V?/B      
TVV" " V" 
TVV   V4 
TVV$ $ V$
 
TVV" " V"
 
TVV$ $ V$
 
TVV  V
 
TVV+ + V+
 
TVV! ! V!
 
TVV' ' V' 
T#YY/ / Y/  
T#YY< < Y<,. . .`, `, `,D ^;'''8 8 ('8 ^/  
8 8 
8 ^1=III= = JI= ^2333E E 43E ^>???I I @?I ^-...@ @ /.@ ^6777A A 87A ^&  
; ; 
; ^L  6 6	 6 ^-...@ @ /.@ ^L*j1IJJJ4 4 KJ4  R, R, R, R,h@ @ @9 9 9 
TVV* * V*
 
TVV* * V*

< 
< 
< 
< ;@.:M A A A A A      r   rK   )rr  loggingrc   os.pathpathr`   r  r  r  qtpy.compatr   r   r   qtpy.QtCorer   r   r   r	   r
   
qtpy.QtGuir   qtpy.QtPrintSupportr   r   r   qtpy.QtWidgetsr   r   r   r   r   r   r   r   r   r   r   spyder.api.config.decoratorsr   spyder.api.config.mixinsr   spyder.api.panelr   spyder.api.pluginsr   r   spyder.config.baser   r    r!   spyder.config.managerr"   spyder.config.utilsr#   r$   r%   spyder.py3compatr&   r'   spyder.utilsr(   r)   r*   spyder.utils.icon_managerr+   spyder.utils.qthelpersr,   r-   r.   spyder.utils.miscr/   spyder.widgets.findreplacer0   spyder.plugins.editor.confpager1   $spyder.plugins.editor.utils.autosaver2   $spyder.plugins.editor.utils.switcherr3   (spyder.plugins.editor.widgets.codeeditorr4   $spyder.plugins.editor.widgets.editorr5   r6   r7   %spyder.plugins.editor.widgets.printerr8   r9   %spyder.plugins.editor.utils.bookmarksr:   r;   $spyder.plugins.editor.utils.debuggerr<   r=   $spyder.plugins.editor.widgets.statusr>   r?   r@   rA   rB   spyder.plugins.run.widgetsrC   rD   rE   rF   rG   r  rH   spyder.widgets.simplecodeeditorrI   	getLoggerr  r   rK   r  r   r   <module>r     s      				       				 



  E D D D D D D D D D : : : : : : : : : : : : : : " " " " " " L L L L L L L L L L< < < < < < < < < < < < < < < < < < < < < < < < < <
 8 7 7 7 7 7 @ @ @ @ @ @ " " " " " " : : : : : : : : E E E E E E E E E E & & & & & &- - - - - - - - - - > > > > > > > > 7 7 7 7 7 7 7 7 7 7 ) ) ) ) ) ) M M M M M M M M M M , , , , , , 2 2 2 2 2 2 ; ; ; ; ; ; B B B B B B F F F F F F ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ?- - - - - - - -C C C C C C C CD D D D D D D DN N N N N N N N N N N N N NN N N N N N N N N N N N N N 9 8 8 8 8 8 < < < < < < 
	8	$	$@7 @7 @7 @7 @7!< @7 @7 @7 @7 @7r   