
    JegL                       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j                  eo      Zp G d! d"e-e(      Zqy)#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                   T    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- ZNd. ZOd/ ZPd0 ZQdd1ZRd2 ZSd3 ZTd4 ZUd5 ZVdd6ZWdd7ZXd8 ZYd9 ZZd: Z[d; Z\d< Z]d= Z^d> Z_d? Z`d@ ZadA ZbdB Zc e&ed      dC        ZedD ZfdE Zg e&       dF        ZhdG ZidH Zj e&        e&e      ddI              ZkdJ ZldK Zm e&       dL        Zn e&       dM        Zo e&        e&e       e&eepe       e&eepee      	 	 	 ddN                            ZqdO Zr e&       dP        Zs e&       dQ        ZtddRZu e&       dS        Zv e&       dT        Zw e&       ddU       Zx e&       dV        Zy e&       dW        Zz e&       ddX       Z{ e&       dY        Z| e&       dZ        Z} e&       d[        Z~ e&       d\        Z e&       d]        Zd^ Zd_ Zd` Zda Zdb Zdc Z e&       dd        Z e&       de        Z e&       df        Z e&       dg        Z e&       dh        Z e&       di        Z e&       dj        Z e&       dk        Z e&       dl        Z e&       dm        Zdn Z e&       do        Z e&       dp        Z e&       dq        Zdr ZddsZdt Zdu Zdv Zdw Z e&       dx        Zdy Zdz 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Zeѐj                  j                  ddZd ZՈ xZS )Editorz"
    Multi-file Editor widget
    editorFztemp.pyztemplate.pyc                    t        j                  | |       d| _        t        j                  | j
                        s_t        j                  dk(  rg }ndg}|g dz   }	 t        j                  t        j                  j                  |      | j
                  d       d | _        d | _        g | _        g | _        d | _        d | _        d | _        i | _        d| _        g | _        i | _        g | _        g | _        d | _        d | _        | j9                          | j:                  j=                          d | _        tA        |       | _!        tE        |       | _#        tI        |       | _%        tM        |       | _'        tQ        |       | _)        | jT                  jW                  tX        jZ                  d      }|r|j]                  | jR                         |j]                  | jN                         |j]                  | jJ                         |j]                  | jF                         |j]                  | jB                         t_               }ta        |       | _1        te        | jb                  | j"                         |jg                  | jb                         d | _4        g | _5        g | _6        d| _7        i | _8        | jT                  jr                  ju                  | jv                         ty        | d      | _=        | jz                  j=                          | j}                  | jz                         t        |       | _@        | j                  j                          | j                  d	      d
z  | j                  _C        | j                  d      | j                  _D        | j                         | _F        | j                  j=                          t        |       }t_               }|j                  d       |j                  dddd       |j                  |       t        | | | j&                  d      | _L        |jg                  | j                         |jg                  | jz                         |jg                  | j                         t        |       | _N        | j                  j                  dddd       | j                  jg                  |       | j                  j                  dd       | j                  j                  dd       |jg                  | j                         | j                  |       | j                  t        j                         | j                  dd       }	|	J| j                  j                  t               j                  t        |	      j                  d                   | j                  dg       | _X        d| _Y        d | _Z        d | _[        d | _\        d | _]        d| _7        | j                         }
|
2| j                         }|
j                         }| j                  ||       | j                          y # t        $ r Y w xY w)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                >/usr/lib/python3/dist-packages/spyder/plugins/editor/plugin.pyr^   zEditor.__init__   s4   ##D&1# zz$,,-ww$34  8 8Frzzv68J8J&(
 #&(#,.)$(!!%"&!#(,%(*%+-(  	  "  #D/ 4T :-d3#D/ / 5 II(():):%(H	''(=(=>''8''(<(<=''(=(=>''8$TND%%t'@'@A**+$(!#% #% '+$ (*$ 			%%--d.F.FG 'tDA&&t'7'78 *$///1 "&1D!E!L $0B C "668! !#  #((Aq!4  /,T4)-)@)@N 3 34 0 01 2 23 "$((Aq!4/&&q!,&&q!,'vBMM*  0$7MM&&
(<(<J%%g.)0 2 !OONB? #" # ',$002%002H#..0F&&x8%%'w $ s   >X> >	Y
Yc                     || _         y N)ri   )r   ri   s     r   set_projectszEditor.set_projects1  s	         c                     | j                   h| j                   j                  }|j                         r|j                          n |j	                          |j                          | j                          y y r   )ri   
dockwidget	isVisiblerz   showraise_switch_to_plugin)r   dws     r   show_hide_projectszEditor.show_hide_projects4  sP    ==$))B||~				!!# %r   c                 `    | _          j                  D ]+  }|j                   j                   j                                -  j                   j                         j                  j                   fd        j                   j                         j                  j                   fd       y )Nc                 .    j                  | ||      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 r   c                 *    j                  |       S )N)r   r   r   )r   r   s    r   r   z,Editor.set_outlineexplorer.<locals>.<lambda>J  s    !YYYN r   )rj   rr   set_outlineexplorer
get_widget	edit_gotor   edit)r   rj   editorstacks   `  r   r   zEditor.set_outlineexplorer?  s    .,, 	OK ++D,@,@,K,K,MN	O 	'')33;;8	9 	'')..66O	Pr   c                 `    	 | j                         j                          y# t        $ r Y y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  s.    	##%224 		s   ! 	--c                    |d   }|d   }|d   }d}| j                   j                  t        j                  d      rh| j                   j                  j                  |j                               }| j                   j                  j                  |j                         ||       |r|j                         | j                  v r=|j                  | j                  |j                                   |j                          y| j                   j                  j                  |j                               r|j                          yy|j                  |j                         k(  r,t        j                  dj                  |             d|_        yy)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  sL    :&:&\*
99 3 35A		%%LLNN$&  II!!// (J8~~4#?#?? ;;001ABD446&&778HI 446 J
 ""hnn&66:AA(KL38
0 7r   c                 `   t         j                  dj                  ||             | j                  j	                  t
        j                  d      }|r|j                          t        |      | j                  |<   | j                  D ]  }|j                  ||        | j                  |       y)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,(	
 99''(8(8'F--/15l1C$$X.,, 	(K88h(	( 	&&x0r   c                 H    | j                   D ]  }|j                  |        y)z6Notify all editorstacks about LSP server availability.N)rr   r   r   r   r   s      r   r   z Editor.start_completion_services  s%    ,, 	<K11(;	<r   c                 H    | j                   D ]  }|j                  |        y)z8Notify all editorstacks about LSP server unavailability.N)rr   stop_completion_servicesr   s      r   r   zEditor.stop_completion_services  s%    ,, 	;K00:	;r   c                     t         j                  dj                  ||d                	 | j                  j                  j                  |||       y # t        $ r Y y 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  sX    3::VF^% 	&	II!!..x&I 		s   'A 	AAc                 ,    t        | |      } ||i | y 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    xxr   c                 "    | j                         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                 @   t        j                  | |       | j                  y| j                  j                         r| j                  j                          n| j                  j                          |r| j                          | j                  j                          y)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  st    ..tV<??"??##%""$""$!$$))+r   c                 d    | j                         }|j                          | j                          y)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$$&r   c                 t   | j                   j                         }| j                  dt        |             | j                  d   }d}| j
                  | j
                  j                         }|s#| j                         }| j                  d|       n=| j
                  j                  |j                  D cg c]  }|j                   c}       | j                  d| j                  j                                | j                  d| j                  D cg c]  }|j                          c}       | j                  d| j                         | j                  j!                          	 |j#                  |      s|ry| j                  dd D ]  }|j%                           y	c c}w c c}w # t&        $ r Y y	w xY w)
z3Perform actions before parent main window is closedr\   r   Nr   layout_settingswindows_layout_settingsr]   FT)r   	saveState
set_optionr&   rr   ri   get_active_project_pathget_open_filenamesset_project_filenamesdatar   r   get_layout_settingsrt   r]   r   stop_autosave_timersave_if_changedclose
IndexError)r   
cancelabler   r   active_project_pathr   finfowins           r   closing_pluginzEditor.closing_plugin  s|   '')(*;E*BC''*"==$"&--"G"G"I"//1IOOK3MM//-8-=-=>E>@ 	)++??A	C1:>:L:LM3S,,.M	O 	(9(9: 	))+	..z:z--a0  CIIK % ?
 N  		s$   5F!F&
(F+ <$F+ +	F76F7c                 N;    t         t        d      t        j                  d      t        d       j                  t
        j                         _         j                   j                  ddd       t         t        d      t        d	       j                  
       _
         j                   j                  dd	       t         t        d      t        j                  d      t        d       j                  t
        j                         _         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                   j                   ddd       t         t        d      t        j                  d      t        d       j"                  t
        j                         _         j                   j$                  ddd       t         t        d      dt        j                  d      t        d       j&                  t
        j                        } 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)       j0                         _        t         t        d*      t        j                  d+      t        d,       j4                  t
        j                         _         j                   j6                  dd-       t        d.      }t         |t        j                  d/      | j8                  t
        j                        } j                  |d0d1d       t         t        d2      t        j                  d3       j:                  t
        j                  4      } j                  |d0d5       t         t        d6      t        j                  d7       j<                  t
        j                  4      } j                  |d0d8       t        d9      }t         |t        j                  d:      | j>                  t
        j                        } j                  |d0d;       t         t        d<      t        j                  d=       j@                  t
        j                  4      }	 j                  |	dd>       t         t        d?      t        j                  d@       jB                  t
        j                  4      }
 j                  |
ddA       t         t        dB       jD                  "      }t         t        dC      t        j                  dD      t        dE       jF                         _$         j                   jH                  dFdGd       t         t        dH      t        j                  dI      t        dJ       fdK       _%         j                   jJ                  dFdLdM       t         t        dN      t        j                  dO      t        dP       fdQ       _&         j                   jL                  dFdRdM       t         t        dS      t        j                  dT      t        dU       fdV       _'         j                   jN                  dFdWdM       t         t        dX      t        j                  dY      t        dZ       fd[       _(         j                   jP                  dFd\dM       t         t        d]      t        j                  d^      t        d_       jR                         _*         j                   jT                  dFd`dM       t         t        da      t        j                  db      t        dc       jV                        } j                  |dFddd       t         t        de      t        j                  df      t        dg      tX        jZ                   j\                  h      } j                  |dFdid       t         t        dj      t        j                  dk      t        dl       j^                        } j                  |dFdmd       t         t        dn      t        j                  do      t        dp       j`                  t
        j                        } j                  |ddqd       t         t        dr      t        ds       jb                  t
        j                        } j                  |ddtd       t         t        du      t        dv       jd                  t
        j                        } j                  |ddwd       t         t        dx      t        j                  dy      t        dz       jf                  t
        j                        } j                  |ddxd       t         t        d{      t        j                  d|      t        d}       jh                  t
        j                        } j                  |dd{d       t         t        d~      t        j                  d      t        d       jj                  t
        j                         _6         j                   jl                  dd~d       t         t        d      t        d       jn                  t
        j                        } j                  |ddd       t         t        d      t        j                  d      t        d       jp                         _9        tu                _;         jv                  jy                  d        jr                  j{                   jv                          jv                  j|                  j                   j                         t         t        d      t        j                  d      t        d       j                         _B        tu                _C         j                  jy                  d        j                  j{                   j                          j                  j|                  j                   j                         t         t        d      t        j                  d      t        d       j                  t
        j                         _F         j                   j                  ddd       t         t        d      t        j                  d      t        d       j                  t
        j                         _G         j                   j                  ddd       t         t        d      t        j                  d      t        d       j                  t
        j                         _I         j                   j                  ddd       t         t        d      t        j                  d      t        d       j                  t
        j                         _K         j                   j                  ddd       t         t        d      t        j                  d      t        d       j                  t
        j                         _M         j                   j                  ddd       t         t        d      dz   t        d      z   t        j                  d      t        d       j                  t
        j                         _O         j                   j                  dd       t         t        d      t        d       j                  t
        j                        } j                  |dd       t         t        d      t        d       j                  t
        j                        } j                  |dd       t         t        d      dt        j                  d      t        d       j                  t
        j                         _S        t         t        d      dt        j                  d      t        d       j                  t
        j                         _U        t         t        d      t        j                  d      t        d       j                  t
        j                         _W         j                   j                  dd       t         t        d      t        j                  d      t        d       j                  t
        j                         _Y         j                   j                  dd       t         t        d       fd       _Z        t         t        d       fd       _[        t         t        d       fd       _\        t               } j                   j                   j                  f}t        ||       tu        t        d             }|j                  d       t        ||       t         t        d       j                  "      }t        j                  dddī      }t         t        dū      j                  |j                               t        j                  ddǫ      t
        j                   j                  ȫ       _g         j                  j                  dɫ        j                  t        dʫ      dd̫      } j                  t        dͫ      ddϫ      } j                  t        dЫ      ddҫ      } j                  t        dӫ      ddի      } j                  t        d֫      ddث      }  j                  t        d٫      dګ      }! j                  t        d۫      dܫ      }" j                  t        dݫ      dd߫      }#||||| |!|"|#d _j        t         t        d      t        d       j                  
      }$t         t        d      t        j                  d       j                  t
        j                  4      }% j                  |%dd       t         t        d      t        j                  d      t        d       j                        }&t         t        d       j                  "       _o        t         t        d      t        d       j                  
       _q        g  _r        t        j                  dk(  rt         t        d      t        j                  dd       j                         _v        t         t        d      t        j                  dd       j                         _x         j                   j                  dd        j                   j                  dd       t         j                   j                  g _r        tu        t        d              _z         j                  j|                  j                   j                         ddl|m}}'m~}(  j                  j                   j                   j                  |'j                  |(j                  |(j                  d        j                   j                   j                  g})|)D ]O  }* j                  j                   j                  |*|'j                  |(j
                  |(j                  d       Q  j                    j$                  || j                  g}+|+D ]O  }, j                  j                   j                  |,|'j                  |(j                  |(j                  d       Q | j.                  g}-|-D ]O  }. j                  j                   j                  |.|'j                  |(j                  |(j                  d       Q  j2                   j6                  g}/|/D ]O  }0 j                  j                   j                  |0|'j                  |(j                  |(j                  d       Q t        j                  dk(  rW j                  j                   j                   j                  |'j                  |(j                  |(j                  d        j                   j                   j                    j$                  g j                  j                  z   }1 j                  xj                  |1z  c_        |||||%g}2|||g j                  _         j                  || j                   j                   j                   j                  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_         jH                   jl                   jJ                   jN                   jP                   jL                   jT                  t        |	|
|g}5|5 j                  j"                  z    j                  _         jH                   jJ                   jN                   jP                   jL                   jT                  g}6 j                  xj$                  |6z  c_        ||||| |!|"|#t         jr                   j                   j                   j                  t         j                   j                   j                  t        |||$ j                  g}7|7 j                  j&                  z    j                  _        |1t        gz   |4z   t        gz   |6z    _        |||	|
 jH                   jl                  ||||||g _        ||g _         j*                   j                   ||| j.                   j$                  |%|& j2                   j6                   j                   j                   j                   j                  gz    _        |%|&g _         j.                  S )z*Return a list of actions related to pluginz&New file...filenewzNew file)r  tip	triggeredcontextrK   T)r/  rd   add_shortcut_to_tipzO&pen last closedzOpen last closed)r-  r.  )r/  rd   z&Open...fileopen	Open filez&RevertrevertzRevert file from disk)r  r-  r.  z&Savefilesave	Save filez	Sav&e allsave_allzSave all fileszSave allzSave &as...N
filesaveaszSave current file as...)r-  r.  r/  zSave AszSave copy as...zSave copy of current file as...)r.  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  r.  r/  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                  &     j                  d      S )Nnextdebug_commandr   s   r   r   z+Editor.get_plugin_actions.<locals>.<lambda>|      d008 r   zDebug Step Over)r0  Continuezarrow-continuez(Continue execution until next breakpointc                  &     j                  d      S )NcontinuerK  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                  &     j                  d      S )NsteprK  r   s   r   r   z+Editor.get_plugin_actions.<locals>.<lambda>  rM  r   zDebug Step IntozStep Returnzarrow-step-outz,Run until current function or method returnsc                  &     j                  d      S )NreturnrK  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  r-  menuroler.  	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                 (    j                  d|       S )NrN   toggle_eol_charscheckedr   s    r   r   z+Editor.get_plugin_actions.<locals>.<lambda>w  s    D$9$9$$H r   toggledz	LF (Unix)c                 (    j                  d|       S )Nposixr|  r~  s    r   r   z+Editor.get_plugin_actions.<locals>.<lambda>|  s    D$9$9'7$K r   z
CR (macOS)c                 (    j                  d|       S )Nmacr|  r~  s    r   r   z+Editor.get_plugin_actions.<locals>.<lambda>  s    D$9$9%$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)shortcutr/  r.  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  r.  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_actionr3  revert_actionsavesave_actionr6  save_all_actionsave_assave_copy_asprint_preview
print_fileprint_action
close_fileclose_actionclose_all_filesclose_all_actionr<  	find_nextfind_previousr@  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_filer`  run_to_linerun_from_linera  run_cell_and_advancerc  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unblockcommentrt  indent_actionrw  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  sl    (.!XXi(a
m(())
 	t$.D 	 	J (5%&()//	(
$ 	t;;X$6 	 	8 )q}XXj)q~))))+ 	t//$/T 	 	K +49XXh'Q/F-G++' )qzXXj)q~))))+ 	t//$/T 	 	K  -T1[>XXj)q1A/B--)) + 	t33X$.D 	 	J 'tQ}-=t&A.G,H,,))+ 	~xC+D!4E2F&*K(L++-  -T15G3H()T5G5G I)$+XXg&A.E,F//+ *$(XXk*2F0G//+ !.dAlOXXn-15M3N..))!+ 	t44h$/ 	 	1 ,#D%chhv6F(-,.,=,=? 	{N$/T 	 	K(q.1hhz.B37>>131B1BD 	/$/ 	 	1,T15E3F25((>2J7;7I7I575F5F H 	3^$3 	 	5/"&tU)9L+0DLL/1/@/@B 	~~$2 	 	4 '4D$%&<$=),2B)C.2.J.J,.,=,=	'?#
 	:H$0 	 	2 &34?@!$*?!@&*&M&M$&$5$5	&7"
 	98$< 	 	> (5T$%&F$G.2.H.H(J$
 *!H+'",oo	'
 	t00#G37 	 	9 "/!F)+,!4F2G8": 	t55s<M37 	 	9 &3!J-*+<=<	&>"
 	&&-= $ 	 	& "/!K./*@A8	":
 	t55s<M37 	 	9 $1!M"*+@A:	$< 
 	$$c+> $ 	 	& "/!F),'Q/?-@))"+ 	t55sL37 	 	9 #46%'(}-1]]<
 	z3U37 	 	9 )*+.).!^^224 	/$/T 	 	K &dA.C,D+.88K+@ !"7 8&*&6&68 	}c$837 	 	9 ,D! 5C 3D14/1J01 3A 1B6:6H6H464E4EG 	2H$3 	 	O +43I1J/01F/G595E5E353D3DF 	18$1t 	 	M  -T15M3N123J1K7;7I7I575F5F H 	3X$3 	 	O (jM!$*!5 ! #> !?&*mm$&$5$57 	$.D 	 	J #0$%,-<=//%%#' 	6$:37 	 	9 "/lO,' & 'oo%%"' 	t55x$037 	 	9 #0'(,-!22,,	#.
 	6'/$637 	 	9 !.d"##((;*? 3 4..	!0
 t$$%BC%%dnn5""**4+@+@A#0+,388J3G:;11$3  "$K''(EF  (():):;%%--d.F.FG'4T*+#((:2FBC55))	(+$
 	t;;'/$637 	 	9 $1&'chhz.B>?11))	$+ 
 	t77'/$237 	 	9
 ,9&'chh7K.L0177))	,+(
 	t??'/$837 	 	9 '4D,-CHH]4K67==))	'+#
 	t::'/$>37 	 	9 #0()0G2399))	#+
 	t66'/$:37 	 	9 &34)S ;/chhy6I9:--r7H7H&J" 	t998$4 	 	6+D!4H2I 8 9++R5F5FH 	2H$2 	 	4 -d)* : ;--r7H7H	!J
 	4h$4 	 	6 +4(U();89++r/@/@B  -T*{*1E:;--1B1B D
 &34$%CHH5G,HEF--r7H7H&J" 	t998$< 	 	> &34$%CHH5G,HEF--r7H7H&J" 	t998$< 	 	> ,H

 !.kNK!

 ,lOI

 (-**D,A,A**,$k2;<dC12Hk* -&'11!3
 HHE	 "/1299$$&(&&x1AB%%77"9 	))%0 !99!"N4HJ  $<<#$&7' ) #'"?"?"#_6I#K "&!>!>!"N4N"P *.)F)F78&(H*J& *.)F)F()=*;& *.)F)F-.*>&  88-. >@
 !2#7!8 6,J=<$4"6 !.dA6G4HHI $ 4 4!6 (a.@-0XXj-A26//020A0AC 	$0 	 	2 't12XXm, D E,,. "/t1222"4 $1 a(A&B--$/  ')#<<8#*7#$**85JK..	+D' /<'(**85FG22	/D+ ""++ & # 
 ""// * #  //+++D' !&a&7 >))11$2N2NO	0 			77OO$))$((+33 	8 	 ((!!

 ( 	KII;;(--(--/77 < 	   
 ( 	KII;;(--(--/77 < 	 !
 * 	LII;;(--(../77 < 	 !!
 * 	LII;;(--(../77 < 	 <<8#II;;++(--(33/77 <  "&$2B2B $ 0 0$2F2F!H $		 > >!? 			&&*>>&  +/3-.	0 -8,<,:,<		(
 #'"<"<"57L"&"4"4d6J6J"&"<"<"&"<"<	"> tyy"78,.DII)  $))"?"?? 			% '33^/1C0-,n> tyy999 			")?68KM		%%)<<% """"""$$&&""'&(
 !=!== 			$ """"$$&&""!
 			''+@@'  #"***!!$$(($$,,''##!!""-
2  $))"?"?? 			%
 !   "	" 	! '&""##!-
) /9:J-K*--  #$!!$$!!%%**""""$$ 	#& $3N"C***r   c                 N    | j                         }|r|j                  ||       yy)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  s*     00266uiH r   c                    | j                   j                  t        j                  d      }| j                   j                  t        j                  d      }| j                   j                  t        j
                  d      }| j                   j                  j                  | 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(                         | j*                  j                  | j                   j                  j,                         |r%| j/                  | j                   j0                         |rp|j3                  d| j4                         |j3                  d| j6                         |j3                  d| j8                         |j3                  d| j:                         | j=                          | j?                  di        tA        | | j                   jB                  | jD                  | jF                  | jI                               | _%        y)	z'Register plugin in Spyder's main windowFrS   
cell_countcurrent_filenameget_file_codera  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_dockwidgetrJ  r3   switcherr   r  r  switcher_manager)r   r   rj   
ipyconsoles       r   register_pluginzEditor.register_plugin  sd   ii**7+>+>e*L))..##5 / 2YY))'*@*@)N
		,,44++	-		1199$))D##DII$J$JKII!!DDLL557II!!//77		BII!!0088HII!!66>>--/ 22::		%%CCE $$TYY%>%>?::d446::"D$@$@B::!:!:<::D002 	eR( !6II##(())+!-r   c                 |   |D cg c]  }t        |t              r|d   n| }}t        t        ||            }| j                  j                         D ]a  \  }}||v s|dk(  rd}d}nd}||   }| j                  ||      }	|j                  d       |j                  |	       |j                  d       c y c c}w )Nr  rL   r   rO  TF)	
isinstancetupler   ziprp   itemsr   blockSignals
setChecked)
r   r   r  optoption_namesnamed_optionsrd   actionr  r   s
             r   update_source_menuzEditor.update_source_menu  s    #*, $.c5#9BsB , ,Sw78 2288: 	+LD&}$--&G,C+G'-CW= ##D)!!%(##E*	+,s   B9c                 (   | j                         }| j                         }| j                  D ]c  }|j                  ||       t	        j
                  dd      }|j                  D ]*  }|j                  j                  }|j                  ||       , e y)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K((|<"hhv/@AO$)) D#ll<<,,_dCD	Dr   c                     | j                   D ];  }|j                  D ]*  }|j                  j                  }	 |j	                  |       , = y# t
        $ r Y ;w xY w)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   rw  	setParentRuntimeError)r   ancestorr   r(  r|  s        r   set_ancestorzEditor.set_ancestor7  sd      ,, 	K$)) 
#ll<<))(3
	 $ s   A	AAc                      fd}t         ||      }|j                  d       dvr!|j                   j                               n,t	        j
                  ddddfd	      }|j                  |       |j                  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                 L    j                          j                  |        y r   )r   _toggle_checkable_action)r  	conf_namer   r   s    r   tooglez/Editor._create_checkable_action.<locals>.toogleW  s!    !!#))'69Er   r  Tr  r  r   r  r  r  F)r,   rl  rm  r   r"   r  )r   textr  r   r  rq  rn  s   ` ``   r   r  zEditor._create_checkable_actionM  s    	F tT6:D!99dooi89(()5(IFC
 c"E"r   c                    |rE| j                   r&| j                   D ]  }	 t        ||      } ||        | j                  ||       y|dv rt        j                  dddd|f|       | j                  j                  t        j                  d	
      r(| j                  j                  }|j                  g        yy# t        $ r!}t        j	                  |d       Y d}~d}~ww xY w)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       #'#4#4 7K7!(k!Bw7 OOIw/99!-uh	J yy##G$7$7u#E"ii3366r: F * 7Q667s   B;;	C%C  C%c                     t        j                         }t        |t              r|S | j                  D ]  }|j                  |      s|c S  y r   )r   focusWidgetrh  r7   rr   isAncestorOf)r   fwidgetr   s      r   __get_focused_editorstackz Editor.__get_focused_editorstack  sH    **,g{+N#00 '++G4&&'r   c                 @    || j                   |<   || j                   d <   y r   rs   r   r   r   s      r   set_last_focused_editorstackz#Editor.set_last_focused_editorstack  s"    6A%%l3.9%%d+r   c                      | j                   |   S r   r  )r   r   s     r   get_last_focused_editorstackz#Editor.get_last_focused_editorstack  s    ,,\::r   c                     t        | j                  j                               D ]  \  }}||u sd | j                  |<    y r   )listrs   rk  )r   r   r   widgets       r   remove_last_focused_editorstackz&Editor.remove_last_focused_editorstack  sG    $(--335%7 	C L&$>B--l;	Cr   c                     | j                         }|:| g| j                  z   D ]&  }|j                  |      s| j                  ||       ( y y r   ) _Editor__get_focused_editorstackrt   r  r  )r   r   r)  s      r   save_focused_editorstackzEditor.save_focused_editorstack  sW    446"vd000 H##K055c;GH #r   c                     t         j                  d        j                  j                  |        j	                  |        j                  |      rU j                   |       |j                  t         j                        dkD          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.                         |j0                  j                   j&                  j2                         |j0                  j                   j4                         |j6                  j                   j8                  j:                         |j<                  j                   j>                  j@                         |jB                  j                   j>                  jD                         |jG                   jH                   jJ                   jL                   jN                         |jQ                   jR                         d}|D ]&  \  }} tU        ||       jW                  |             ( |jY                  t[        j\                  dd             t[        j\                  ddd      }t[        j\                  dd	d
      }t[        j\                  ddd      }|j_                  |       |ja                  |       |jc                  |        je                         }|jg                   ji                         |       |jj                  j                   jj                         |jl                  j                   jl                         |jn                  j                   jn                         |jp                  j                   fd       |jr                  j                   fd       |jt                  j                   jt                         |jv                  j                   jv                         |jx                  j                   jz                         |j|                  j                   j~                         |j|                  j                   j                  j                         |j|                  j                   j                         |j                  j                   fd       |j                  j                   fd       |j                  j                   fd       |j                  j                   j                         |j                  j                   fd       |j                  d   j                   j                         |j                  j                   j                         |j                  j                   j                         |jB                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   fd       |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j6                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j<                  j                   j<                         |j                  j                   j                         |j                  d   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                  |j                         y )NzRegistering new EditorStackr[   )$)set_todolist_enabledrd  )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                 :    j                   j                  |       S r   )rT  r  )r   r   s    r   r   z-Editor.register_editorstack.<locals>.<lambda>  s    t/B/B/G/G/N r   c                 <    j                   j                  | |      S r   )exec_in_extconsoler  )r  optionr   s     r   r   z-Editor.register_editorstack.<locals>.<lambda>   s    $($;$;$@$@v$N r   c                  &     j                  d      S )Nr[   zoomr   s   r   r   z-Editor.register_editorstack.<locals>.<lambda>)  s    DIIaL r   c                  &     j                  d      S )Nrg  r  r   s   r   r   z-Editor.register_editorstack.<locals>.<lambda>*  s    TYYr] r   c                  &     j                  d      S Nr   r  r   s   r   r   z-Editor.register_editorstack.<locals>.<lambda>+  s    tyy| r   c                 (    j                  |       S )N)r  )r  sr   s    r   r   z-Editor.register_editorstack.<locals>.<lambda>-  s    48883C r    c                 ,    j                  | ||      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_columnsru  rv  rt  starting_long_processending_long_processsig_option_changedrT  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_resetrW  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_columnsrz  s	   `        r   register_editorstackzEditor.register_editorstack  s;   23  -&&{3[)--dK@$$S):):%;a%?@##///((3357''(8(89''//0E0E0J0JK''//0D0D0I0IJ''//0E0E0J0JK((00(,(=(=(M(MO((00)-)=)=)M)MO::BB!%!6!6!M!MO::BB224--55**,,,44**,""**002 	""4??D4D4D#'#3#3T5G5G	I%%d&8&89'R  ( 	COFG(GK()AB	C 	$$TXXf6F%GHhh&	
 I
 !HH,	
 	++K8&&~6(():;,,.$$T]]_lC))11$2L2LM''//0H0HI 	&&..t/F/FG""**!N	P&&..%O	P 	))11$2L2LM++33((	*''//0L0LM((001N1NO((001O1OP((001N1NO##$89$$%:;&&';<!!))$*?*?@  (()CD  $,,TXX6""**4+N+NO""**4+J+JK&&t'E'EF((00&*&N&N	P--55040N0N	P**22((	*((00/	0 	22::((	*((001J1JK44<<--	/44<<$$	&22::+/+N+N	P++33D4P4PQ))11$2H2HI**2243J3JK))11$2H2HI##++D,@,@A((001J1JK''		2#++DII6%%dii0''5%%--d.K.KL##++D,O,OP##++D,K,KL$$,,T-H-HI$$,,T-D-DE%%--d.@.@A%%--d.@.@A&&..t/B/BC&&..t/F/FG 	11+2F2FGr   c                 @   t         j                  d       | j                  |       t        | j                        dkD  r`| j                  j                  |      }| j                  j                  |       | j                  j                  | j                                yy)z8Removing editorstack only if it's not the last remainingzUnregistering EditorStackr[   TF)
r   r   r  r  rr   indexpopr   
set_editorr   )r   r   rI  s      r   unregister_editorstackzEditor.unregister_editorstack\  s    01,,[9t  !A%%%++K8E!!%(''(?(?(AB r   c                     |j                  | j                  d          |j                  D ]  }| j                  |j                          y r  )
clone_fromrr   r   r   rL   )r   r   r(  s      r   clone_editorstackzEditor.clone_editorstacki  sB    t0034 %% 	9E**5<<8	9r   c                     | j                   D ]`  }t        t        |            |k7  s|j                  d       |j	                  |      }|j                  |d       |j                  d       b y )NTforceF)rr   r   idrl  get_index_from_filenamer  )r   editorstack_id_strr   r   rI  s        r   r   z%Editor.close_file_in_all_editorstacksn  sh    ,, 	0K2k?#'99((.#;;HE&&uD&9((/	0r   c                 z    | j                   D ],  }t        t        |            |k7  s|j                  ||       . y)z5A file was saved in editorstack, this notifies othersN)rr   r   rS  file_saved_in_other_editorstackr   rU  original_filenamer   r   s        r   r"  z Editor.file_saved_in_editorstackw  sB      ,, 	FK2k?#'99;;<M<DF	Fr   c                 z    | j                   D ],  }t        t        |            |k7  s|j                  ||       . y)z?A file was renamed in data in editorstack, this notifies othersN)rr   r   rS  rename_in_datarX  s        r   r$  z*Editor.file_renamed_in_data_in_editorstack  s>      ,, 	HK2k?#'99**+<hG	Hr   c           
      0   | j                   j                  j                  t        j                        j                         }| j                   j                  j                  t        j                        j                         }| j                   j                  j                  t        j                        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 ]#  }| j'                         }|j)                  |       % y)z3Setup toolbars and menus for 'New window' instanceszFile toolbarfile_toolbarzRun toolbarrun_toolbarzDebug toolbardebug_toolbarz&Filez&Editz&SearchzSour&cerX  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    !II..CC!!##.;= 	!YY//DD""$$/KM 	 II..CC!!##.;= 	  /"ii<<>."ii;;=0/"ii==?	@ W:'89W:tyy'B'BCY<)F)FGY<)F)FGV9dii&@&@AX;(:;W:r*W:'89;  $?? 	5O((*C##O4	5r   c                 D    | j                   st        t        |           yy)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     
 !!&$02 "r   c                     t          j                   j                   j                   j                        j                  dj                                j                          j                   j                                j                          dj                  j                  j                  _         j                         j                   j#                   fd       S )zCreate a new editor window.)outline_pluginr`  Tc                  &     j                        S r   )unregister_editorwindowr   windows   r   r   z*Editor.create_new_window.<locals>.<lambda>  s    )E)Ef)M r   )r5   ro   rv   rw   rj   add_toolbars_to_menuget_toolbarsload_toolbarsresizesizer   editorwidgetr   r   
new_windowregister_editorwindow	destroyedr   rq  s   `@r   re  zEditor.create_new_window  s    !##NN//
 	##GV-@-@-BCdiik"DH**66A""6*  !MNr   c                 d    t         j                  d       | j                  j                  |       y)zRegister a new editor window.zRegistering new windowN)r   r   rt   r  rq  s     r   rz  zEditor.register_editorwindow  s#    -.!!&)r   c                     t         j                  d       | j                  j                  |      }d| j                  |<   | j                  j	                  |       y)zUnregister editor window.zUnregistering windowN)r   r   rt   rI  rJ  )r   rr  idxs      r   rp  zEditor.unregister_editorwindow  sI    +,  &&v."&3s#r   c                 n    | j                   d   j                  D cg c]  }|j                   c}S c c}w r  rr   r   r   )r   r(  s     r   get_filenameszEditor.get_filenames  s+    ,0,=,=a,@,E,EF5FFFs   2c                 >    | j                   d   j                  |      S r  )rr   has_filenamer   r   s     r   get_filename_indexzEditor.get_filename_index  s      #00::r   c                     | j                   at        | j                         dk(  r| j                   d   }|S | j                         }||"| j                  |      }|| j                   d   }|S y )Nr[   r   )rr   r  r  r  r  s      r   r  zEditor.get_current_editorstack  s    (4$$%*"//2  #<<>&,*B"&"C"C$#&K"*&*&7&7&: )r   c                 H    | j                         }||j                         S y r   )r  r   r  s     r   r   zEditor.get_current_editor  s*    224"1133 #r   c                 H    | j                         }||j                         S y r   )r  get_current_finfor  s     r   r  zEditor.get_current_finfo  s*    224"0022 #r   c                 H    | j                         }||j                         S y r   )r  r   r  s     r   r   zEditor.get_current_filename  *    224"3355 #r   c                 H    | j                         }||j                         S y r   )r  get_current_languager  s     r   r  zEditor.get_current_language  r  r   c                 >    | j                   d   j                  |      S r  )rr   is_file_openedr  s     r   r  zEditor.is_file_opened  s      #228<<r   c                 H    | j                  |      }|j                  ||      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                   rP| j                   j                         r5| j                         du}| j                  D ]  }|j	                  |        yyy)zMEnable/disable file dependent actions
        (only if dockwidget is visible)N)r   r   r   rk   r  )r   r  rq  s      r   r.  z%Editor.refresh_file_dependent_actions  sW     ??t88:,,.d:F55 *!!&)*  ;?r   c                     | j                         }|r8t        d |j                  D              }| j                  j	                  |       yy)z0Enable 'Save All' if there are files to be savedc              3      K   | ]:  }|j                   j                         j                         xs |j                   < y wr   )rL   document
isModifiednewly_created).0r(  s     r   	<genexpr>z1Editor.refresh_save_all_action.<locals>.<genexpr>  s<      7! --/::<S@S@SS 7s   A AN)r  anyr   r  r  )r   r   r   s      r   r  zEditor.refresh_save_all_action  sI    224 7%0%5%57 7E  ++E2 r   c                    
  j                         }|j                         } j                  j                           j	                         
|D ]  \  }}d|v }|dd j                         |dd z   }|rt        j                  d      nt        j                  d      }|f
 fd	}t         ||      }	|	j                  t           j                  |        j                  j                  |	        y)zUpdate warning list menusyntaxNr[   rT   warningc                 *    j                  |      S Nr   r   _checked_lr   r   s     r   r   z,Editor.update_warning_menu.<locals>.<lambda>  s    DIIhRI4P r   r  r  )r   get_current_warningsr  clearr   upperr+   r  r,   r.  boolr   	addAction)r   rL   check_resultsmessageline_numberrT   r  r  slotrq  r   s   `         @r   r  zEditor.update_warning_menu  s    ((*335!,,.$1 	0 G['E2A;$$&4D(-388G$388I3FD'2PD"4d>FT"**40''/	0r   c                      j                         }|j                         } j                  j                           j	                         |D ]m  \  }}t        j                  d      }|f fd	}t         ||      }|j                  t           j                  |        j                  j                  |       o  j                          y)zUpdate todo list menutodoc                 *    j                  |      S r  r   r  s     r   r   z)Editor.update_todo_menu.<locals>.<lambda>+  s    diiri.J r   r  N)r  get_todo_resultsr  r  r   r+   r  r,   r.  r  r   r  r-  )	r   r   resultsr  line0r  r  rq  r   s	   `       @r   r  zEditor.update_todo_menu#  s    224..0,,." 	-KD%88F#D',JD"4d>FT"**40NN$$V,	- 	  "r   c                    | j                         }|j                         }|j                         }|dk7  rA|j                  |   j                  }| j
                  D ]  }||us|j                  ||        | j                          y)zl
        Synchronize todo results between editorstacks
        Refresh todo list navigation buttons
        rg  N)r  r  get_stack_indexr   r   rr   set_todo_resultsr-  )r   r   r  rI  r   other_editorstacks         r   r*  zEditor.todo_results_changed1  s    
 224..0++-B;"''.77H%)%6%6 J!$K7%66xIJ 	  "r   c                    t        |      }d| _        |dk(  r#| j                  j                  d       d| _        y |dk(  r#| j                  j                  d       d| _        y | j
                  j                  d       d| _        y )NFrN   Tr  )r'   r_   r  rm  r  r  )r   os_names     r   r/  zEditor.refresh_eol_chars@  s     )$d?**40
  $	 !!,,T2  $ **40#r   c                 :    | j                   j                  |       y r   )r  r  )r   r   s     r   r1  zEditor.refresh_formattingK  s    ))&1r   c                     t        j                  ddd      }| j                  j                  t	        d      j                  |j                                      y )Nr   r  rQ   r  )r"   r  r  setTextr   r   r  )r   r7  s     r   refresh_formatter_namezEditor.refresh_formatter_nameN  sO    HHE	 	&&1299$$&(	)r   c                 z   | j                         }|r|j                         }|xs' t        j                  d      xr |j	                         }| j
                  D ]&  }|| j                  v r|}n|}|j                  |       ( | j                  j                  | j                         | j                                yy)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  rZ  r  r   r  )r   rL   python_enablecython_enablerq  r  s         r   r%  z Editor.opened_files_list_changedX  s     ((*"779M) O,,X6M6;K;K;M ;; *T???*F*F!!&)* 2277))+T-F-F-HJ r   c                     | j                         }|y| j                  | j                  | j                  fD ]!  }|j	                  |j                                # y)z$Update actions in the warnings menu.N)r   r  r  r  r  errors_present)r   rL   rq  s      r   r,  z#Editor.update_code_analysis_actionsn  s^    ((* > //1M1M//1 	7Ff3356	7r   c                     | j                         }|j                         }| j                  d      xr |d uxr t        |      }|| j                  j                  |       y y )Nrd  )r  r  r   r  r  r  )r   r   r  r   s       r   r-  zEditor.update_todo_actions{  sg    224..0- 6$6),W 	!!,,U3 r   c                     | j                   j                  t        j                  d      r&| j                   j                  j                  |       y y NFrS   )r   r   r   r   r   update_client_status)r   	languagess     r   r'  zEditor.update_active_languages  s=    99 3 35AII!!66yA Br   c                     t        |      }t        |      }t        j                  t        j                  |            }t	        |      }t        ||       y)z'Receive bookmark changes and save them.N)r'   r`   normpathabspathevalr;   )r   r   	bookmarkss      r   r;   zEditor.save_bookmarks  s@    !(+"9-	<<H 56O	x+r   c                    t        j                  | j                        sddt        d      dt        d      dddg}t        j
                  j                  |D cg c]  }t        j                  |       c}      }	 t        j                  t        |      | j                  d       | j                  | j                         yc c}w # t        $ r | j                          Y yw xY w)z;Load temporary file from a text file in user home directoryrO   rP   zSpyder EditorrQ   z This is a temporary script file.rR   N)r`   ra   r  r   rc   rf   rg   r(   
to_unicodere   r'   rh   r  r   )r   defaultqstrr  s       r   __load_temp_filezEditor.__load_temp_file  s    zz$,,-0a0";<b"&G ::??07$9(, %-$7$7$= $9 :D~d3T5G5G&( 			$$$%$9
 $ 
s   C=*C C$#C$c                     | j                         }|Dt        j                  t        j                  |            }| j                  j                  |       yy)z1Set current script directory as working directoryN)r   r`   dirnamer  sig_dir_openedr  )r   r  	directorys      r   __set_workdirzEditor.__set_workdir  sH     ))+CKK$67I$$Y/ r   c                    |y|| j                   v r| j                   j                  |       | j                   j                  d|       t        | j                         | j	                  d      kD  r| j                   j                  d       yy)zAdd to recent file listNr   max_recent_filesrg  )r]   removeinsertr  r   rJ  )r   r  s     r   __add_recent_filezEditor.__add_recent_file  sy    =D%%%$$U+  E*t  !DOO4F$GG!!"% Hr   c                 t    | j                   dd D ]&  }|j                  |d      }| j                  |       ( y)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  sC      ,,QR0 	3K 225e2LF**62	3r   c                 4   	 |d}t        j                  | j                        \  }}t        j                  d|      }|r|j                  d      }t        j                  t        j                  j                  dd            }|s3t        j                  t        j                  j                  dd            }t        j                         |d	}	 ||z  }n$d
}t        j                  | j                        d   }d }	|| j                         }
n|}
|du }|r| j                   dk(  r~|
j"                  D ]o  }|j$                  j&                  }t)        d      |v s't+        j,                  |      }	 t/        |d   j1                  t)        d            d         }|dz   | _        q 	  |	| j                         }| xj                   dz  c_        t+        j4                  |      sn>t7               }| j8                  j;                  t<        j>                  d
      }|r!|jA                         |jC                         }n6| jE                         }|$|| jF                  k7  rt+        jH                  |      }t+        jJ                  t+        jL                  ||            }nCt+        jJ                  tO        |            }|
jQ                  |      }||
jS                  |      sy| jT                  d   jW                  ||||d      }| jY                  |       |
j[                  |j&                        }| j]                  |       |s| j_                  d       yy# t        $ r Y hw xY w# t        t        f$ r
 d}d}d}Y w xY w# t2        $ r d| _        Y aw xY w)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                 6    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  rg  rS   )emptyrQ  )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(  rM  
fname_dataact_numbasedirri   c_fnamerI  r   s                        r   r  z
Editor.new  s]   	#|"&$MM$*<*<=	cII&J&*,	#//!,C $66 "

z2 >@  '::#%::>>&##> @H !JJL ($;D #(mmD$6$67: O557J$J!TM  A%'__ 2E',||'<'<$}(88 &)\\2B%C
	2&) *1 3 3AjM B2 F'HG07!D-2" $T%6%67!!Q&!zz%(	 
 %&Gyy++G,<,<E+JHH779E"::<335&7d6H6H+H!kk'2GKK% 89E KKu 56E++E2E )>)>u)E !!!$((T?/3 ) 5##E*#88H&&~6 IIDI! !K ! 
 ! 	#DC"O	#2  * 2
 12D-2sH   CM' M %M' 23N	M$ M' #M$$M' 'N ?N NNc                 :    | j                  | j                         y)zEdit new file templateN)r   rb   r   s    r   edit_templatezEditor.edit_template(  s    		$$$%r   c           	      n   g }| j                   D ])  }t        j                  |      s|j                  |       + | j                  j                          |r|D ]  }t        | |t        j                  |d            }|j                  t           j                  | j                         |j                  t        |             | j                  j                  |        | j                   j#                  t%        |      dkD         t'        | j                  d| j(                  | j                   f       y)zUpdate recent file menug      ?)scale_factor)r  r   N)r]   r`   ra   r  r  r  r,   r+   get_icon_by_extension_or_typer.  r  r   r   setDatar   r  r  r  r  r-   r  )r   r]   r  rq  s       r   r  zEditor.update_recent_file_menu,  s   && 	+Ezz% ##E*	+ 	##%% 8&%::C12   &..tyy9{512%%//78 	  ++C,=,ABD))D$2H2H,0,D,D,F 	Gr   c                     g | _         y)r  N)r]   r   s    r   r  zEditor.clear_recent_files@  s     r   c                     | j                         }t        j                  |t        d      t        d      | j	                  d      dd      \  }}|r| j                  d|       yy)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  sb     224!((ak !AB#/ABArK
U OO.4 r   c
                    | j                   }
d| _         	 | j                          | j	                         }|| j                         }nd}|s>| j                         }t        |t              rt        |j                         t              }|st               }| j                  t               | _        | j                  t!               | _        | j                         }|$|| j"                  k7  rt%        j&                  |      }| j(                  j+                  d       | j-                         }|-t/        | j                  t%        j0                  |      d         }nd}t3               s<t4        j6                  dk(  rt9        |t;        d      |      }|j=                  | j                  j?                  d	             |jA                  t8        jB                  d       |jE                  tF        jH                  tF        jJ                  z  tF        jL                  z  tF        jN                  z         |jQ                  t8        jR                         |jU                         r|jW                         }n{tY        |t;        d      || j                  |t8        jB                  
      \  }}nEt9        |t;        d      t8        jZ                        }|jU                         r|jW                         }| j(                  j+                  d       |r#|D cg c]  }t%        j\                  |       }}n|
| _         yt_        j`                         }| jb                  rX| jd                  jg                         s>|| jb                  vr| jb                  d   }|ji                          |jk                          nS| jd                  rG| jl                  s;| jd                  jo                  |      s t        |tp              s| j                          d }ts        |d      rtu        |      }t        |tt              s
 ||      g}ntu        |      D cg c]
  } ||       }}t        |tv              r|g}n|ty        |      ty        |      k7  rd}t{        |      D ]"  \  }}|xr |dk(  }| j}                  |||      }|t%        j~                  |      s<| j-                  |      }| j                  d   j                  |d|	|      }|r| j                  |       |j}                  ||      }|j                  j                          |j                  t        |             | j                  |       |j                          | j                  |       ||j                  ||   |||       |j                          |ji                          |j                         jk                          |rt_        j                          l|j                  j+                  ||          | j                  j                  t        j                  d      }|s|j                         }|j                  j                  |j                  d          |j                         }|j                         } | j                  ||        % |
| _         | j                          y# t        t        f$ r Y w xY wc c}w c c}w )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  r2  )r   captionr  z;;)selectedfilterr   )r   r   c                     t        j                  t        j                  |             } t        j
                  dk(  r/t        |       dk\  r!| d   dk(  r| d   j                         | dd  z   } | S )NrN      r[   :r   )r`   r  r(   r  rc   rd   r  r  )r  s    r   _convertzEditor.load.<locals>._convert  sZ    KK ; ;E BCEww$3u:?uQx3a(qr2Lr   replaceInStrings)r  )r  	add_whereprocessevents)r   r  
end_columnrS   r  )Zr   r   r   r  r   r   senderrh  r   r   r   r'   r/   r   r#   r   r$   r  r`   r  rT  r  r  r%   r  r!   r  r  r   r   setNameFiltersr  	setOptionHideNameFilterDetails	setFilterr
   AllDirsFilesDrivesHiddensetFileModeExistingFilesexec_selectedFilesr   DontUseNativeDialogr  r   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  
clearFocusrr  processEventssig_debug_stopr   r   r   rQ  get_current_shellwidgetsig_prompt_readyr   get_pdb_stateget_pdb_last_steprJ  r   )!r   r   r   r   r   r  r  r   	set_focusr  cursor_history_stateeditor0	filename0rq  r  r	  parent_widgetr  dialog_sfr  focus_widgetr  rI  r   r  r   r  r(  rd  
current_swcurrent_pdb_statepdb_last_steps!                                    r   r   zEditor.loadO  s   &  $;;'+$
	!!# ))+113II[[]F&'*)&++-H	$&G""*&8&:#  ($4$6!//1G"w$2D2D'D++g.$$U+ 88:M$!+D,?,?,/LL,CA,F"H "$')<<8+(, !+")F
 ))$*;*;*A*A$*GH$$[%F%FM$$T\\DJJ%>%L'+{{&3 4&&{'@'@A||~$*$8$8$:	%5%+))'5 + A A&NIs %]AkN-8-L-LN<<> & 4 4 6I$$T*>GHUS\\%0H	H/C,#//1doo&?&?&A 4#5#55#11!4!!#!ood&7&7oo22<@ z:!!#	 901YI)T*!),-I6:9oFU%FIFdC 6D#d)s9~"=D(3 9	LOE8,%1*E!66x7C=B 7 DN %zz(+!99,G

 ))!,11%9"/ 2 1 =++E2!+!@!@GL "A "N''88:,,^H-EF..~>))+&&x0))$u+D7C5? * A %%'##%!!#**,**, --224;?!YY11**% 2 9
!+!C!C!EJ//77&55b9;(2(@(@(B%$.$@$@$BM))*;]Ks9	Lv (<$""$I - 		F I> Gs   [ [?[#[[c                 B    t        |       }|j                  dd       |S )z:Create a SimpleCodeEditor instance to print file contents.	scintillaF)rz  r  )rI   setup_editorr   rL   s     r   r   zEditor._create_print_editor	  s+    !$'$U 	 	
 r   c                    | j                         }| j                         }| j                  j                  |j	                                | j                  j                  |j                         | j                  j                  | j                                t        t        j                  | j                               }t        || j                        }|j                         r|j                  t        j                   d       |j#                         }|j%                         |j'                         }}| j                  j#                         }|j)                  |       |j)                  |t*        j,                         | j                  j/                  |       | j0                  j3                  d       |j5                         }	| j0                  j3                  d       |	t6        j8                  k(  rV| j;                  t=        d             |j?                  |       | j                  jA                  |       | jC                          | j                  j#                         jE                          y)zPrint current file.modeheader_fontTFzPrinting...N)#r   r   r   set_texttoPlainTextset_languager   set_fontrt  r8   r   HighResolutionr   has_selected_textr#  r   PrintSelectionr   selectionStartselectionEndsetPositionr   
KeepAnchorsetTextCursorrT  r  r,  r   Acceptedr  r   
setDocNameprint_r  removeSelectedText)
r   rL   r   printerprint_dialogcursor_1startendcursor_2answers
             r   r  zEditor.print_file	  s    ((*,,. 	##F$6$6$89''8##DMMO4  X%<%<,0MMO=#GT-?-?@ ##%""#7#F#FM ((*H!002H4I4I4K3E))446H  '  k&<&<=,,X6 	  '##%  &W%%%&&q'78x(%%g.$$& 	%%'::<r   c                      j                         } j                  j                  |j                                 j                  j	                  |j
                          j                  j                   j                                t        t        j                   j                               }t        |       }|j                  t        j                         |j                  j!                   fd        j"                  j%                  d       |j'                           j"                  j%                  d       y)zPrint preview for current file.rN  c                 :    j                   j                  |       S r   )r   r_  )ra  r   s    r   r   z&Editor.print_preview.<locals>.<lambda>U	  s    D..55g> r   FTN)r   r   rQ  rR  rS  r   rT  rt  r8   r   rU  r9   setWindowFlagsr   WindowpaintRequestedr   rT  r  r,  )r   rL   ra  previews   `   r   r  zEditor.print_previewC	  s     ((* 	##F$6$6$89''8##DMMO4  X%<%<,0MMO= +7D9ryy)&&>	

 	  '  &r   c                    t        j                  dd      sy| j                  j                  t        j
                  d      }d}i }|r |j                         }|j                         }d}|rRd|v rN|rLt        j                  |d         t        j                  |      k(  rd}| j                  j                          |S |rd}| j                  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   rQ  r<  r=  r`   normcase sig_file_debug_message_requestedr  )r   r   rd  	debugginglast_pdb_step	can_closes         r   can_close_filezEditor.can_close_file]	  s     xx)+@AYY))'*@*@)N
	"002I&88:M	M1h||M'23s||H7MM!	55::<  I11668r   c                     | j                         }| j                  |      r!| j                         }|j                          yy)r:  )r   N)r   rv  r  r  )r   r   r   s      r   r  zEditor.close_fileu	  sB     ,,.1668K""$ 2r   c                 >    | j                   d   j                          y)zClose all opened scriptsr   N)rr   r  r   s    r   r  zEditor.close_all_files}	  s     	!,,.r   c                 H    | j                         }|j                  ||      S )r5  )rI  rR  )r  r  )r   rI  rR  r   s       r   r  zEditor.save	  s(     224e599r   c                     | j                         }|j                         r"|j                         }| j                  |       yy)z#Save *as* the currently edited fileN)r  r  r   r6  )r   r   r  s      r   r  zEditor.save_as	  s?     224 446E""5) !r   c                 D    | j                         }|j                          y)z(Save *copy as* the currently edited fileN)r  r  r  s     r   r  zEditor.save_copy_as	  s     224  "r   c                 D    | j                         j                  |       y)zSave all opened filessave_new_filesN)r  r6  )r   r~  s     r   r6  zEditor.save_all	  s     	$$&//~/Nr   c                 D    | j                         }|j                          y)z*Revert the currently edited file from diskN)r  r3  r  s     r   r3  zEditor.revert	  s     224r   c                     | j                         }|j                  j                          |j                  j                  j	                          y)z	Find slotN)r  r   r   search_textr/  r  s     r   r<  zEditor.find	  s<     224$$&++446r   c                 X    | j                         }|j                  j                          y)zFnd next slotN)r  r   r  r  s     r   r  zEditor.find_next	  s$     224))+r   c                 X    | j                         }|j                  j                          y)zFind previous slotN)r  r   r  r  s     r   r  zEditor.find_previous	  s$     224--/r   c                 X    | j                         }|j                  j                          y)zReplace slotN)r  r   show_replacer  s     r   r@  zEditor.replace	  s$     224,,.r   c                     | j                         }|j                         }t        |      dkD  r9|d   }|j                  |       |j	                  |       | j                  |       yy)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	  se    224'==?!"Q&,Q/L$$\2--.?@IIl#	 'r   c                     t        j                  t        |            }| j                  d   j	                  |      }|| j                  d   j                  |       yy)zClose file from its namer   N)r`   r  r'   rr   r  r  )r   r   rI  s      r   close_file_from_namezEditor.close_file_from_name	  sT    ;;~h78!!!$11(;a ++E2 r   c                 &    | j                  |       y)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        |            }| j                         D ]8  }t        j                  |      j	                  |      s(| j                  |       : y)z0Directory was removed in project explorer widgetN)r`   r  r'   r  
startswithr  )r   r  r  s      r   removed_treezEditor.removed_tree	  sR    ++nW56'') 	1E{{5!,,W5))%0	1r   c                 @   t        j                  t        |            }| j                  d   j	                  |      }|`| j                  D ]  }|j                  |t        |               | j                  d   j                  j                  |t        |             yy)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  r[  r   file_renamed)r   sourcedestr   rI  r   s         r   renamedzEditor.renamed	  s     ;;~f56!!!$11(;#00 N**88Ft8L + NN a ))66..0	 r   c                 r   t        j                  t        |            }t        |      }| j                         D ]{  }t        j                  |      j	                  |      s(dt        j                  |      z   }|j                  dd      }t        j                  |||      }| j                  ||       } y)z>Directory was renamed in file explorer or in project explorer.^\z\\)r  r  N)
r`   r  r'   r  r  r  escaper@  subr  )	r   r  r  r  tofiler  	source_redest_quotedr  s	            r   renamed_treezEditor.renamed_tree	  s    ++nV45%'') 	>E{{5!,,W5"))F"33	"ll47!vvieDE=	>r   c                 J    | j                         }||j                          yy)ru  N)r   rt  rL  s     r   rt  zEditor.indent	  s&     ((*MMO r   c                 J    | j                         }||j                          yy)rx  N)r   rw  rL  s     r   rw  zEditor.unindent	  s'     ((*OO r   c                 J    | j                         }||j                          yy)z.Change current line or selection to uppercase.N)r   transform_to_uppercaserL  s     r   r  zEditor.text_uppercase
  )     ((*))+ r   c                 J    | j                         }||j                          yy)z.Change current line or selection to lowercase.N)r   transform_to_lowercaserL  s     r   r  zEditor.text_lowercase	
  r  r   c                 J    | j                         }||j                          yy)ro  N)r   r  rL  s     r   r  zEditor.toggle_comment
  )     ((*!!# r   c                 J    | j                         }||j                          yy)z'Block comment current line or selectionN)r   r  rL  s     r   r  zEditor.blockcomment
  s)     ((*! r   c                 J    | j                         }||j                          yy)z*Un-block comment current line or selectionN)r   r  rL  s     r   r  zEditor.unblockcomment
  r  r   c                     | j                          | j                         }|j                          | j                         }|j	                         }| j                  ||       y r   )r   r   r  r   r   r   r   rL   r   r   s       r   r  zEditor.go_to_next_todo$
  sT    ((* ,,.""$""8V4r   c                     | j                          | j                         }|j                          | j                         }|j	                         }| j                  ||       y r   )r   r   r  r   r   r   r  s       r   r  zEditor.go_to_next_warning-
  sT    ((*!!#,,.""$""8V4r   c                     | j                          | j                         }|j                          | j                         }|j	                         }| j                  ||       y r   )r   r   r  r   r   r   r  s       r   r  zEditor.go_to_previous_warning6
  sT    ((*%%',,.""$""8V4r   c                     |rS| j                         }| j                  r6| j                          |j                  t	        j
                  |             y y y )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?
  sS    ,,.F##%%'$$(CCGL %  $ r   c                 d    | j                          | j                         }|j                          y r   )r   r  r  r  s     r   r  zEditor.remove_trailing_spacesH
  s(    224**,r   c                 d    | j                          | j                         }|j                          y r   )r   r  r  r  s     r   r  z#Editor.format_document_or_selectionN
  s(    224002r   c                 d    | j                          | j                         }|j                          y r   )r   r  r  r  s     r   r  zEditor.fix_indentationT
  s(    224##%r   c                    | j                   j                  | j                  d u       | j                  j                  t	        | j
                        dkD         | j                  j                  t	        | j                        dkD         y r  )r  r  r   r  r  r   r  r   r   s    r   r   zEditor.update_cursorpos_actions[
  sr    ((33%%T1	3##..(()A-	/**(()A-	/r   c                    | j                   ry || j                         }|$| j                  |      }|y |j                         }d}t	        | j
                        dkD  r:| j
                  d   \  }}||k(  r#|j                         |j                         k(  rd}|r| j
                  j                          ng | _        | j
                  j                  ||f       | j                          y )NFr   rg  T)r   r   _get_editorr   r  r   blockNumberrJ  r   r  r   )r   r   r   rL   replace_last_entryr  hist_cursors          r   r   zEditor.add_cursor_to_historyc
  s    ''002H>%%h/F~&&(F"t''(1,!%!9!9"!=E; %%';+B+B+DD)-&$$((* (*D$  ''6(:;%%'r   c                 (    t        |      |f| _        y r   )r'   r   )r   r   positions      r   r4  zEditor.text_changed_at
  s    %3H%=x$H!r   c                    | j                         }|r|j                         }| j                  t        |      |       | j	                         }||j                          | j                  j                  t        j                  d      }|3|j                         }	|j                         }
| j                  |	|
       y y y r  )r   r   r   r'   r  hide_tooltipr   r   r   rQ  r<  r=  rJ  )r   r   r  r  columnrL   r   current_stackrd  	pdb_staterH  s              r   r  zEditor.current_file_changed
  s    ((* &&(F&&~h'?H !88:M(**, --g.D.D49 . ;J%&446	 * < < >%%i? & r   c                     | j                         }|rH| j                         }|j                  }|j                         }| j                  t	        |      |       yy)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
  sY    ((* 113K"++H ++-F&&x(&2	 r   c                    g }t        | j                        D ]!  \  }\  }}||k7  s|j                  ||f       # || _        g }t        | j                        D ]!  \  }\  }}||k7  s|j                  ||f       # || _        y)z:Remove the cursor history of a file if the file is closed.N)r1  r   r  r   )r   rS  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(>?	@ $4 r   c                 J   | j                   y | j                   \  }}d }t        j                  |      r"| j                  |       | j	                         }n| j                  |      }|d | _         y ||j                         j                         k  r|j                  |       y y 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    $$,!66(::hIIh,,.F..x8F>(,D%foo'6688&&x0 9r   c                     |r@|j                         \  }}||k7  s!|j                         |j                         k7  r||fS |r@y)z@Get the next cursor from history that is different from current.NN)rJ  r  )r   historyrM  current_cursorr   r   s         r   _pop_next_cursor_diffzEditor._pop_next_cursor_diff
  sK    &{{}Hf,,OO%)@)@)BB''	 
 r   c                     t        |      D ]:  }t        |      dkD  s|j                  ||f       | j                  |||      \  }}< ||j	                         \  }}||fS )zW
        Move number_steps in the forwards_history, filling backwards_history.
        r   )ranger  r  r  rJ  )r   number_stepsbackwards_historyforwards_historyrM  r  r  s          r   _history_stepszEditor._history_steps
  s     |$ 		;A#$q(!((%~68 ..((.: 1 .		; ! "%%' -n//r   c                    d| _         | j                  r| j                  j                          | j                         }| j	                         j                         }|dk  r.| j                  | | j                  | j                  ||      \  }}n,| j                  || j                  | j                  ||      \  }}| j                  j                  ||f       | j                         j                         }t        j                  |      s||vr| j                  j                          nB| j                  |       | j	                         }|j                  |       |j                          d| _         | j!                          y)z
        Move the cursor position forward or backward in the cursor
        position history by the specified index increment.
        Tr   FN)r   r   rJ  r   r   r   r  r   r  r  r  r`   ra   r   r\  ensureCursorVisibler   )r   
index_moverM  r  r   rL   s         r   __move_cursor_positionzEditor.__move_cursor_position
  s_   
 (,$##$$((*  446002==?>/3/B/B(((( .	02,n 04/B/B(((( .	02,n 	  ''~.	0002@@B	

+,$I5$$((*II&',,.F  0&&(',$%%'r   c                 T    d| _         | j                          | j                  d       y )NTrg  r   r   _Editor__move_cursor_positionr   s    r   r  z%Editor.go_to_previous_cursor_position  s$    '+$##B'r   c                 T    d| _         | j                          | j                  d       y )NTr[   r  r   s    r   r  z!Editor.go_to_next_cursor_position  s$    '+$##A&r   c                 p    t        |t              rd}| j                         }||j                  |       yy)zOpen 'go to line' dialogN)rh  r  r  r  )r   r  r   s      r   r  zEditor.go_to_line"  s:     dD!D224"""4( #r   c                 j    | j                         }|!| j                          |j                          yy)rA  N)r  r   r  r  s     r   r  zEditor.set_or_clear_breakpoint+  s5     224"!!#//1 #r   c                 j    | j                         }|!| j                          |j                          yy)rD  N)r  r   r  r  s     r   r  z)Editor.set_or_edit_conditional_breakpoint3  s5     224"!!#::< #r   c                    | j                          t                | j                  j                          | j	                         }|5|j
                  D ]&  }|j                  j                  j                          ( | j                          y)rF  N)
r   r<   r3  r  r  r   rL   r2  clear_breakpointsr  )r   r   r   s      r   r<   zEditor.clear_all_breakpoints;  ss     	##%224"#(( 9$$6689r   c                    t        ||       | j                  j                          | j                         }|G| j	                  |      }|3|j
                  |   j                  j                  j                  |       yyy)zRemove a single breakpointN)	r=   r3  r  r  r  r   rL   r2  toogle_breakpoint)r   r   linenor   rI  s        r   r=   zEditor.clear_breakpointG  sz    6*##%224"''1E   '..77II  ! #r   c                     | j                   j                  t        j                  d      }|r|j	                          yy)rW  FrS   N)r   r   r   rQ  r  )r   rd  s     r   r  zEditor.stop_debuggingR  s5    YY))'*@*@)N
%%' r   c                     | j                   j                  t        j                  d      }|r#|j	                  || j                  d             yy)zDebug actionsFrS   r  )r  N)r   r   r   rQ  pdb_execute_commandr   )r   commandrd  s      r   rL  zEditor.debug_commandX  sL    YY))'*@*@)N
**9J)K + M r   c                 @    | j                         }|t        d      |S )zk
        Get the current editorstack.

        Raises an exception in case no editorstack is found
        zNo editorstack found.)r  r  r  s     r   _get_editorstackzEditor._get_editorstack`  s*     224677r   c                     | j                         }|y|sy|j                  |      }|y|j                  |   j                  S )z9Get editor for filename and set it as the current editor.N)r  r  r   rL   )r   r   r   rI  s       r   r  zEditor._get_editorl  sN    ++-((2=&---r   c                     | j                         }| j                  |      }|t        dj                  |            ||f|_        |j                  |      S )z=
        Get cell code from cell name and file name.
        File {} not open in the editor)r  r  r  r   last_cell_callget_cell_code)r   	cell_namer   r   rL   s        r   r`  zEditor.handle_run_cell{  sf     ++-!!(+>077AC C '/	%:" ##I..r   c                 |    | j                  |      }|t        dj                  |            |j                         S )z$Get number of cells in file to loop.r  )r  r  r   get_cell_count)r   r   rL   s      r   r]  zEditor.handle_cell_count  sE    !!(+>077AC C $$&&r   c                 R    | j                         j                         j                  S )zGet the current filename.)r  r  r   r   s    r   r^  zEditor.handle_current_filename  s     $$&88:CCCr   c                     | j                         }|r*t        j                  ddd      r|j                  d       | j	                  |      }|t        j                  |      \  }}|S |j                         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  r6  r  r(   r  rR  )r   r   r6  r   rL   r  _encs          r   r_  zEditor.handle_get_file_code  st     ++-/?   6!!(+>!x0JD$K!!##r   c                     t               }|j                  j                   fd        j                  |j	                   j                         t        j                   j                               }|j                  |       |j                         r1|j                  }|" j                  |        j                          y y y )Nc                 &    j                  |       S r   set_dialog_sizer  s    r   r   z0Editor.edit_run_configurations.<locals>.<lambda>  s    T-A-A!-D r   )rE   size_changer   r{   rv  r`   r  r   setupr,  file_to_runr   r  )r   rC  r  s   `  r   r  zEditor.edit_run_configurations  s     &""#DE'MM$**+D5578U<<>&&E 		%  ! r   c                     t        j                   j                               }t        j                  |      }|j	                  dd      j	                  dd      }|j	                  dd      j	                  dd      }t        |      }|t               }|j                  j                   fd        j                  |j                   j                         |j                  |       t        j                  ddt                      rd	}t        j                  ddd
       nt        j                  dt               }|r|j#                         sy|j%                         }|j&                  r
t)               }|j+                         }|j-                         }|j.                  }	|j0                  }
|j2                  }|j4                  }|j6                  }|j8                  }|j:                  r|}n=|j<                  rd}n.t        j>                  |j@                        r|j@                  }nd}d	}||||	||||||
||f _!         jE                  d
       y)z5Run script inside current interpreter or in a new one'z\'"z\"Nc                 &    j                  |       S r   r  r  s    r   r   z!Editor.run_file.<locals>.<lambda>  s    1E1Ea1H r   rY  open_at_least_onceTFrQ   r}  )#r`   r  r   r  r@  rD   rG   r   r   r{   rv  r  r"   r  r!   r  rC   r,  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  runconfrC  show_dlgr   python_argsr  r  r  r  r  r  wdirpythons   `                r   r  zEditor.run_file  s    D5578 ++e$ c5)11#u=//#u-55c5A'.?'-F&&'HI+d../LLxx30224
   4e<  88E+GH..0G??&(G$$&224##))////!11#55D^^DYYw{{#;;DD$dD(E%{GW*O02 	.r   c                     || _         y r   )r{   )r   rw  s     r   r  zEditor.set_dialog_size  s
    r   c                     | j                         }||j                  j                          | j                  d       y)zDebug current scriptNT)r   )r   sig_debug_startr  r  )r   r   s     r   r  zEditor.debug_file  s8     002%**//1D!r   c                 T   | j                  d      r| j                  |      }||sy| j                  y| j                  \  }}}}}}}	}
}}}}| j                  d      }|s$| j                  j	                  ||||||
|||	       y| j
                  j                  |||||||	||	       y)r_  r  r}  Nr  )r   r6  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^DI$Y&
 #11	dHe	gw	o	//*;<))..tT5+w!2O
 II++tT8UFKr   c                 D    | j                         }|j                          y)z1Run selection or current line in external consoleN)r  r`  r  s     r   r`  zEditor.run_selection$       224!!#r   c                 D    | j                         }|j                          y)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!r   c                 D    | j                         }|j                          y)z&Run all lines from current line to endN)r  r  r  s     r   r  zEditor.run_from_line0  r"  r   c                 D    | j                         }|j                          y)zRun current cellN)r  ra  r  s     r   ra  zEditor.run_cell6  s     224r   c                 D    | j                         }|j                          y)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((*r   c                 D    | j                         }|j                          y)zDebug Current cell.N)r  rc  r  s     r   rc  zEditor.debug_cellB  s     224 r   c                 D    | j                         }|j                          y)zRun last executed cell.N)r  r  r  s     r   r  zEditor.re_run_last_cellH  s     224$$&r   c                    t        j                  dd      }| j                         }||v r||   \  }}}t        j                  |      rv|j                  |      }|c|j                  j                  |      j                         j                  |      }|j                         j                  j                  ||f       |"| j                          |j                  |       yy)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  rI  blocks	            r   r=  zEditor.save_bookmarkO  s     HHX{3	224y )28)<&Hhzz(##00:$(--44U;DDF//9 NN$..55x6HI"!!#$$X. #r   c                    t        j                  dd      }||v r
||   \  }}}nyt        j                  |      sd| _        y| j                  |       | j                         }||j                         j                         k  rgt        |j                         j                  |      j                               }||k  r|j                  |dz   |       y|j                  |dz   |       yy)z+Set cursor to bookmarked file and position.rL   r  Nr[   )r"   r  r`   ra   r   r   r   r  	lineCountr  r+  r  r  )r   r.  r  r   r/  r  rL   
linelengths           r   r?  zEditor.load_bookmark`  s     HHX{3	y )28)<&Hhzz(#(,D%		(((*foo'1133V__.//9$$&BJ#!!(Q,7 !!(Q,
; 4r   c                 B   | j                         j                         }|dk(  r"| j                         }|j                  |       nJ|j	                         }|j                         |z   }|dkD  r"|j                  |       |j                  |       |j                          y)zZoom in/out/resetr   N)r  r   rt  rT  ry  	pointSizesetPointSizeupdate_tab_stop_width_spaces)r   factorrL   ry  rw  s        r   r  zEditor.zoomw  s    --/BBDQ;==?DOOD!;;=D>>#f,Dax!!$'%++-r   c                    | j                   d}| j                  |      }d}| j                  |      }d}| j                  |      }d}| j                  |      }	d}
| j                  |
      }| j                   D ]l  }||v r|j                  |       ||v r|j                  |       ||v r|j	                  |       ||v r|j                  |	       |
|v s\|j                  |       n d}| j                  |      }d}| j                  |      }d	}| j                  |      }d
}| j                  |      }d}| j                  |      }d}| j                  |      }d}| j                  |      }d}| j                  |      }d}| j                  |      }d}| j                  |      } d}!| j                  |!      }"d}#| j                  |#      }$d}%| j                  |%      }&d}'| j                  |'      }(d})| j                  |)      }*d}+| j                  |+      },d}-| j                  |-      }.d}/| j                  |/      }0d}1| j                  |1      }2d}3| j                  |3      }4d}5| j                  |5      }6d}7| j                  |7      }8d}9| j                  |9      }:d};t        j                  dd       }<d!}=| j                  |=      }>| j                         }?| j                   D ]  }||v r|j                  |       ||v r|j                  |       ||v r|j                  |       ||v r|j                  |       ||v r|j                  |       ||v r|j                  |       ||v r|j!                  ||?"       ||v r|j#                  |       ||v r|j%                  |       ||v r|j'                  |        |!|v r|j)                  |"       |#|v r|j+                  |$       |%|v r|j-                  |&       |'|v r|j/                  |(       |)|v r|j1                  |*       |+|v r|j3                  |,       |-|v r|j5                  |.       |/|v r|j7                  |0       |1|v r|j9                  |2       |3|v r|j;                  |4       |5|v r|j=                  |6       |7|v r|j?                  |8       |9|v r|jA                  |:       |;|v r|jC                  |<       |=|v s|jE                  |>|?"        | jF                  jI                         D ]N  \  }@}A|@|v sAjK                  d#       | j                  @      }B|AjM                  |B       |AjK                  d$       P | j                  d%      d&z  | jN                  _(        | j                  d'      | jN                  _)        |?|=|v r|>r|?jU                          yyyyy)(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  rd  )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   rk  rl  rm  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   rq  r   sC                                                                      r   apply_plugin_settingszEditor.apply_plugin_settings  s"   (4M OOM:M4M OOM:M4L??<8L#D #'??3G#H  1 $0A B#00 G G+BB@MO G+BB@MO7*CCLQ'72CC;OQ$/334EFG  &Hx0H"<"&//2E"F%Hx0H%Hx0H/O"ooo>OF__V,F,N!__^<N*M OOM:M-K//+6K=M OOM:M2L??<8L;M OOM:M)M OOM:M%F"%)__5K%L"0L??<8L5N!__^<N+M OOM:M,J4J+N!__^<N'L??<8L,N!__^<N+N!__^<N&=#&*oo6M&N#$FXXf&67F F__V,F**,E#00 7Jw&228<"g-99/J!W,11.A G+88G&'1>>+-w&228<w&77FK 8 MW$008')33K@ G+55mD7*AA,O G+AA-P G+//>)W4<<.07*77E!W,::>J G+11-@(==jI!W,88H7*66|D!W,99.I!W,00@*g599:QRW$008W$44VCH 5 Jm7Jr !% 6 6 < < > /f7?''- OOD1E%%e,''./ OO$784? MM"$(OO4F$GDMM!
  W$))+ *0$ !y )r   r  )r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet edge line to )rr   r   r   r  r   valuer   s      r   r  zEditor.set_edgeline_enabled(  sJ    (LL,UG45#00 80078 )r   r  r   )r  r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet edge line columns to )rr   r   r   r  r{  s      r   r  zEditor.set_edgeline_columns/  sL     (LL4UG<=#00 80078 )r   enable_code_snippetsc                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet code snippets to )rr   r   r   set_code_snippets_enabledr{  s      r   r  z Editor.set_code_snippets_enabled:  sJ    (LL089#00 =55e<= )r   r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet automatic completions to )rr   r   r   r  r{  s      r   r  z(Editor.set_automatic_completions_enabledA  sL    (LL8@A#00 E==eDE )r   r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )Nz'Set chars for automatic completions to )rr   r   r   r  r{  s      r   r  z,Editor.set_automatic_completions_after_charsH  sL    (LLB5'JK#00 IAA%HI )r   r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet completions hint to )rr   r   r   r  r{  s      r   r  z#Editor.set_completions_hint_enabledO  L    (LL3E7;<#00 @88?@ )r   r  c                     | j                   <t        j                  d| d       | j                   D ]  }|j                  |        y y )NzSet completions hint after z ms)rr   r   r   r  r{  s      r   r  z$Editor.set_completions_hint_after_msV  sN    (LL6ugSAB#00 A99%@A )r   r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet hover hints to )rr   r   r   r  r{  s      r   r  zEditor.set_hover_hints_enabled]  sL     (LL.ug67#00 ;33E:; )r   r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet format on save to )rr   r   r   r  r{  s      r   r  zEditor.set_format_on_saveh  sL    
 (LL1%9:#00 6..u56 )r   r  c                     | j                   ;t        j                  d|        | j                   D ]  }|j                  |        y y )NzSet underline errors to )rr   r   r   r  r{  s      r   r  z#Editor.set_underline_errors_enabledr  r  r   
appearanceselectedui_theme)r  r  c                     |dk(  r| j                  dd      }| j                  ;t        j                  d|        | j                  D ]  }|j	                  |        y y )Nr  r  r  rO  zSet color scheme to )get_confrr   r   r   set_color_scheme)r   r  r|  r   s       r   r  zEditor.set_color_schemey  sd    ZMM*lMCE(LL/w78#00 4,,U34 )r   c                     | j                   d   }g }||j                  D cg c]  }|j                   c}z  }|S c c}w )z/Get the list of open files in the current stackr   r  )r   r   r   r(  s       r   r  zEditor.get_open_filenames  sB    ''*	+2B2BCennCC	 Ds   ;c                    | j                  d       d}| j                  | j                  j                         }|r| j                  j                         }n| j	                  dg       }|r| j                          | j                  j                  |z   }|rt        |D cg c]  }t        j                  |       c}      ra| j	                  dd      }|rC|j                  d      d   \  }}}	||v rt        |      t        |	      k(  r|j                  |      }
| j                  ||
   |	|
   d	       |
dkD  r!| j                  ||
dd
   |	|
dd
   dd       |
t        |      dz
  k  r| j                  ||
dz   d |	|
d dd       | j                  j                  r| j                  | j                  j                  dd       n|r| j                  ||	       | j                  j                  rt| j                  | j                  j                         nN|r| j                  |       | j                  j                  r%| j                  | j                  j                         | j                  r~d| _        | | j                   j#                  ||d          | j	                  dg       }|r"|D ]  }| j$                  j'                  |        | j)                  | | j*                  d          | j-                         }|r/| j-                         j/                          n| j1                          | j                  d       | j2                  j5                          yc c}w )z
        Open the list of saved files per project.

        Also open any files that the user selected in the recovery dialog.
        FNr   r  r  splitsettingsr   T)r   r>  rg  rd  )r   r>  r  r[   re  )r>  r  r  )	dont_gotor  )set_create_new_file_if_emptyri   r  get_project_filenamesr   r  r   recover_files_to_openr  r`   ra   r  r  rI  r   rq   r   rf  ru   r  r  rr   r  r  _Editor__load_temp_filesig_open_files_finishedr  )r   close_previous_filesr'  r   all_filenamesfr   is_verticalcfnameclinesrI  
win_layoutr  r   s                 r   setup_open_fileszEditor.setup_open_files  s    	))%0"==$"&--"G"G"I;;=IR@I  ";;iGS!GA#**Q-!GH__%6=F .4jj.I!.L+VV Y&3y>S[+H%OOF3EIIi.VE]dIS qy		)EI2I"6VEI2I=N,1W " F
 I 23		)E!GH"5F56N,1U " D }}::		$--"E"E,1U " D !		)&	9}}::		$--"E"EFIIi(==66IIdmmAAB,,05-%'';;"+A, < 0 "__-FK
+5 -88??+-- 11$8I8I!8LM 668K,,.668!!#))$/$$))+} "Hs   !M"c                 D    | j                  d| j                                y)zSave the list of open filesr   N)r  r  r   s    r   save_open_fileszEditor.save_open_files  s    T%<%<%>?r   c                 4    | j                   D ]	  }||_         y)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    ,, 	9K38K0	9r   c                 Z    | j                         }|j                  j                  d       y)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4%%b)r   c                 Z    | j                         }|j                  j                  d       y)z8Switch to previous file tab on the current editor stack.rg  Nr  r  s     r   r  zEditor.go_to_previous_file  r  r   c                 H    | j                   D ]  }|j                  |        y)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  s'      ,, 	<K00;	<r   )r  c                V    | j                   D ]  } |j                  |g|d|i|  y)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  sJ      ,, 	AK&K&&A"A-5A9?A	Ar   c                      y r   r  r   s    r   on_mainwindow_visiblezEditor.on_mainwindow_visible	  s    r   )F)rQ   r   )NT)NNN)	NNrQ   NTNNTre  )NF)Tr  )__name__
__module____qualname____doc__CONF_SECTIONr1   CONFIGWIDGET_CLASS	CONF_FILEr    r  rb   DISABLE_ACTIONS_WHEN_HIDDENNAMEr   ConsoleREQUIRESr   rP  OPTIONALr   r   r  r  objectr  r  r  rT  r  r3  rZ  rr  r  r   rA  r  r^   r   r	   r   r   r   r   r   r   r   r   ri  r  staticmethodr  r	  r  r  r  r*  rF  rJ  re  rr  r}  r  r  r  r  r  r  r  r  rG  rL  rO  r   r"  r$  r   r   re  rz  rp  r  r  r  r   r  r   r  r  r  r.  r  r  r  r*  r/  r1  r  r%  r,  r-  r  r'  r;   r  r  r6  r  r  r  r  r  r  r  r   r   r  r  rv  r  r  r  r  r  r6  r3  r<  r  r  r@  r  r  r  r  r  r  rt  rw  r  r  r  r  r  r  r  r  r}  r  r  r  r   r   r4  r  r  r!  r  r  r  r  r  r  r  r  r  r<   r=   r  rL  r  r  r`  r]  r^  r_  r  r  r  r  r  r`  r  r  ra  r  rc  r  r=  r?  r  ry  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   PositionLEFTr  r  __classcell__)rl  s   @r   rK   rK   H   sL
    L)I!),M!-0M"' D H##W%<%<=H  &S#tT4tT ;"3T4@$S&#tTBT*D\NC[N (.sC(8% (.x$  &x2 %hM(^! 
V$ $P 
$Z9 98 
$_1 1><
;
 
#ud 
   ),'"H^+@I"--^+*	D,> 
$S; ;B':
;CHmH^9
 
#s^0 0 
#sCF F 
#sCH H5>3&*
$G;4
3
6
6
=A*30##	$2)J,74 
#YB B
,&& 
V0 0&3 
V	#Yd"  d"L&G( 
V  
V5 5 
V	#Y	#sC	#sC 35AE8={% !   {%z 
V(= (=T 
V' '20 
V% % 
V/ / 
V: :
 
V* * 
V# #
 
VO O 
V 
 
V7 7 
V, ,
 
V0 0
 
V/ /
$3,10"	> 
V  
V  
V, , 
V, , 
V$ $ 
V" " 
V$ $
 
V5 5 
V5 5 
V5 5 
V- -
 
V3 3
 
V& &/(8I@,24  
V1 1&0.+(Z 
V( (
 
V' '
 
V) ) 
V2 2 
V= = 
V	 		 (M
./ 	'D$( 
V    
V?/ ?/B  
V" " 
V 4 
V$ $
 
V" "
 
V$ $
 
V 
 
V+ +
 
V! !
 
V' ' 
#Y/ /  
#Y< <,.`,D ;'8 (8 /
8
8 1=I= J= 23E 4E >?I @I -.@ /@ 67A 8A &
;
; L6	6 -.@ /@ L*j1IJ4 K4R,h@9 
V* *
 
V* *

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