
    Je:@                       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 ddlmZmZmZmZmZmZmZmZmZ ddl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$m%Z%m&Z&m'Z'm(Z( ddl)m*Z* ddl+m,Z,m-Z- dd	l.m/Z/ dd
l0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZBmCZC ddlDmEZEmFZFmGZGmHZHmIZI ddlJmKZK ddlLmMZM ddlNmOZO ddlPmQZQ ddlRmSZS ddlTmUZUmVZV ddlWmXZXmYZYmZZZ ddl[m\Z\ ddl]m^Z^ ddl_m`Z`maZambZbmcZcmdZdmeZemfZf ddlgmhZhmiZimjZj ddlkmlZl ddlmmnZn  ej                  ep      Zq G d d e%      Zr G d! d"e$      Zs G d# d$e"      Zt G d% d&e"      Zu G d' d(e      Zv G d) d*e"      Zwd+ Zxepd,k(  r ex        yy)-zEditor Widget    N)getsavefilename)	
QByteArrayQEvent	QFileInfoQPointQSizeQtQTimerSignalSlot)QFontQTextCursor)QActionQApplicationQFileDialogQHBoxLayoutQLabelQMainWindowQMessageBoxQMenu	QSplitterQVBoxLayoutQWidgetQListWidgetQListWidgetItemQSizePolicyQToolBar)Panel)_running_under_pytest)is_dark_interface)CONF)get_edit_filetypesget_edit_filters
get_filteris_kde_desktopis_anaconda)AutosaveForStack)get_file_language)EditorSwitcherManager)
codeeditor)ThreadManagerFileInfoStackHistory)CursorPositionStatusEncodingStatus	EOLStatusReadWriteStatus	VCSStatus)show_in_external_file_explorer)fixpath)OutlineExplorerWidget)OutlineExplorerProxyEditor)	cell_name)qbytearray_to_strto_text_string)encoding
sourcecodesyntaxhighlighters)ima)QStylePalette)add_actionscreate_actioncreate_toolbuttonMENU_SEPARATORmimedata2urlset_menu_iconscreate_waitspinner)APP_STYLESHEETAPP_TOOLBAR_STYLESHEETPANES_TABBAR_STYLESHEET)FindReplace)BaseTabsc                   B    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zy)TabSwitcherWidgetz/Show tabs in mru order and change between them.c                 n    t        j                   |        j                  t        j                  t        j
                  z         | _        | _        | _         j                  t         j                          j                  j                   j                         g  _         j                          t!        j"                  dd      }  j$                  |   j'                           j)                  d       t!        j*                   fddd        t!        j*                   fddd	        y )
Nmainzcompletion/sizer   c                  &     j                  d      S N
select_rowselfs   F/usr/lib/python3/dist-packages/spyder/plugins/editor/widgets/editor.py<lambda>z,TabSwitcherWidget.__init__.<locals>.<lambda>\   s    T__R%8     EditorGo to previous filecontextnameparentc                  &     j                  d      S N   rS   rU   s   rW   rX   z,TabSwitcherWidget.__init__.<locals>.<lambda>^   s    T__Q%7 rY   Go to next file)r   __init__setWindowFlagsr	   FramelessWindowHintDialogeditorstack_historytabssetSelectionModeSingleSelectionitemActivatedconnectitem_selectedid_list	load_datar"   getresizeset_dialog_positionsetCurrentRowconfig_shortcut)rV   r_   ri   rj   sizes   `    rW   rd   zTabSwitcherWidget.__init__J   s    T6*B22RYY>?*	k99:""4#5#56xx 12T  "18("7	F7"3D	BrY   c                     t        | j                        D ]_  }| j                  j                  |      }|j	                  dd      }t        t        j                  d      |      }| j                  |       a y)zfFill ListWidget with the tabs texts.

        Add elements in inverse order of stack_history.
        & TextFileIconN)	reversedri   rj   tabTextreplacer   r>   iconaddItem)rV   indextextitems       rW   rq   zTabSwitcherWidget.load_dataa   sc    
 d001 	E99$$U+D<<R(D"388N#;TBDLL		rY   Nc                    || j                         }	 | j                  | j                         dz       }| j                  j	                  |       | j                  j                  |       | j                          y# t        $ r Y w xY w)z5Change to the selected document and hide this widget.Nrb   )currentItemri   
currentRowrh   set_stack_indexcurrent_changed
IndexErrorhide)rV   r   r   s      rW   ro   zTabSwitcherWidget.item_selectedl   s|    <##%D	/&&):1)<'=>E KK''.KK''.		  		s   !A< <	BBc                 n    | j                         |z   | j                         z  }| j                  |       y)zVMove selected row a number of steps.

        Iterates in a cyclic behaviour.
        N)r   countru   )rV   stepsrows      rW   rT   zTabSwitcherWidget.select_row{   s.    
  5(DJJL83rY   c                    t        | j                  j                         j                         dz  | j                         dz  z
        }t        | j                  j                  j                         j                         j                         | j                  j                  j                         j                         z         }| j                  | j                  j                  t        ||                   y)z;Positions the tab switcher in the top-center of the editor.   N)intrh   geometrywidthrj   tabBarheightfname_labelmovemapToGlobalr   )rV   lefttops      rW   rt   z%TabSwitcherWidget.set_dialog_position   s    4;;'')//1!3djjl1nDE$++""))+446==?++))224;;=> ? 			$++))&s*;<=rY   c                 z   | j                         rt        j                  dd      }|j                  d      D ]p  }|j	                         }|dk(  r!|j                         t        j                  k(  s(|dk(  s?|j                         t        j                  k(  sa| j                          r |j                          y)zReimplement Qt method.

        Handle "most recent used" tab behavior,
        When ctrl is released and tab_switcher is visible, tab will be changed.
        rZ   rc   r]   r^   +ctrlaltN)	isVisibler"   get_shortcutsplitlowerkeyr	   Key_ControlKey_Altro   accept)rV   eventqscr   s       rW   keyReleaseEventz!TabSwitcherWidget.keyReleaseEvent   s     >>##H;LMCyy~ )iikF]uyy{bnn'D%))+*C&&(	)
 	rY   c                     |j                         t        j                  k(  r| j                  d       y|j                         t        j                  k(  r| j                  d       yy)z/Reimplement Qt method to allow cyclic behavior.rb   rR   N)r   r	   Key_DownrT   Key_UprV   r   s     rW   keyPressEventzTabSwitcherWidget.keyPressEvent   sC    99;"++%OOAYY[BII%OOB &rY   c                     |j                          t        j                  dk(  r3|j                         t        j
                  k7  r| j                          yy| j                          y)z=Reimplement Qt method to close the widget when loosing focus.darwinN)ignoresysplatformreasonr	   ActiveWindowFocusReasoncloser   s     rW   focusOutEventzTabSwitcherWidget.focusOutEvent   sD    <<8#||~!;!;;

 < JJLrY   N)__name__
__module____qualname____doc__rd   rq   ro   rT   rt   r   r   r    rY   rW   rM   rM   G   s.    9B.	 >  rY   rM   c                      e Zd Z e       Z ee      Z ee      Z ee	e	      Z
 ee      Z ee      Z ee      Z ee      Z ee      Z eee      Z eeeeee      Z eeeeee      Z e       Z e       Z e       Z e       Z e       Z ee      Z eee      Z eeee      Z eeee      Z e       Z ee      Z  e       Z! e       Z" e       Z# e       Z$ e       Z% eee	      Z& eee	e	e	      Z' eefd      Z( eee	e      Z) e       Z* e       Z+ eefd      Z, e       Z- e       Z. e       Z/ e       Z0 e       Z1 e       Z2 eee	e	      Z3 eeee      Z4 eee      Z5 ee	      Z6 ee	      Z7 eee      Z8 ee      Z9	 d Z: e;       dd       Z<d Z=d Z>d Z?d Z@d	 ZA e;       d
        ZBd ZC e;       d        ZDd ZEd ZFd ZG e;        e;e      dd              ZH e;       d        ZId ZJd ZKddZLd ZMd ZNd ZO e;        e;e      dd              ZP e;ee      d        ZQd ZRd ZSd ZTd ZUd ZVd ZWd  ZXd! ZYd" ZZdd#Z[dd$Z\d% Z]d& Z^d' Z_d( Z`d) Zad* Zbd+ Zcd, Zdd- Zed. Zfd/ Zgd0 Zhdd1Zid2 Zjd3 Zkd4 Zld5 Zmd6 Znd7 Zod8 Zpd9 Zqd: Zrd; Zsd< Ztd= Zud> Zvd? Zwd@ ZxdA ZydB ZzdC Z{dD Z|dE Z}dF Z~dG ZdH ZdI ZdJ ZdK ZddLZdM ZdN ZdO ZdP ZddQZdR ZdS ZdT ZddUZddVZddWZdX ZdY ZdZ Zd[ Zd\ Zd] Zd^ Zd_ Zd` Zda Zdb Zdc ZdddZddeZdf Z e;e	e	      dg        ZddhZdi Zdj Zdk Zdl Zdm Zdn Zdo Zdp Zdq Zdr Zds ZddtZdu Zdv ZddwZdx Zdy Zdz Zdd{Zdd|Zdd}Zd~ ZddZd Zd Zd Zd ZddZd ZddZd Zd Zd Zd Zd ZddZddZd Zd Zd Z	 	 ddZd Z e;eee      dd       Z	 	 ddZ	 	 ddZddZddZddZddZddZddZd Zd Zd Zd ZddZd Zd ZddZd ZddZd Zd Zej                  j                  ddZy)EditorStackr   c           
      V
    t        j                   |        j                  t        j                         t                _        d _        d  _        d  _	        d  _
         j                          t               }|j                  dddd        j                  |       d  _        d  _        d  _        d  _        d  _        t)                _        g  _         j/                  ||       d  _        g  _        t5         t7        d      t9        j:                  d       j<                        }t5         t7        d      t9        j:                  d       j>                        }t5         t7        d      t9        j:                  d	       fd
      }t5         t7        d       j@                        }t5         t7        d       jB                        }t5         t7        d       jD                        }	tF        jH                  dk(  rt7        d      }
nt7        d      }
t5         |
 jJ                  tM        jN                  dd      t        jP                        }||d |||d |||	g	z    _)        d  _*        d _+        d  _,        d  _-        d  _.        d  _/        d  _0        t7        d       _1        d _2        d _3        d _4        d _5        d _6        d _7        d _8        d _9        d _:        d _;        d _<        d _=        d _>        d _?        d _@        d  _A        d _B        d _C        d _D        d _E        d _F        d _G        d _H        d _I        d _J        d _K        d _L        d _M        d _N        d _O        d _P        d _Q        d _R        d _S        d _T        d _U        d _V        d _W        d _X        d _Y        d _Z        d _[        d _\        d _]        d _^        t               rdnd }|t        j                  vrt        j                  d   }| _b        t                _d         j                  j                  d        j                  j                  d!        j                  j                  j                   j                          j                  j                   j                          j                  d        j                          _n        g  _o        d  _p        d  _q        d  _r        t                 _t        t                _v        d  _w        y )"NFr   zFile switcher...filelistr   	triggeredzFind symbols in file...symbol_findzCopy path to clipboardeditcopyc                  f    t        j                         j                   j                               S r   )r   	clipboardsetTextget_current_filenamerU   s   rW   rX   z&EditorStack.__init__.<locals>.<lambda>$  s(    &&(001J1J1LM rY   zClose all to the right)r   zClose all but thiszSort tabs alphabeticallyr   zShow in FinderzShow in external file explorerrZ   show in external file explorerr   )r   shortcutr]   T)O             i,  i  i  LFzspyder/darkspyderi  )xr   rd   setAttributer	   WA_DeleteOnCloser,   threadmanager
new_windowhorsplit_actionversplit_actionclose_action_EditorStack__get_split_actionsr   setContentsMargins	setLayoutmenuswitcher_dlgswitcher_managerrj   tabs_switcherr.   ri   external_panelssetup_editorstackfind_widgetdatarA   r   r>   r   open_switcher_dlgopen_symbolfinder_dlgclose_all_rightclose_all_but_thissort_file_tabs_alphabeticallyr   r   r4   r"   r   WidgetShortcutmenu_actionsoutlineexploreris_closable
new_actionopen_actionsave_actionrevert_actiontempfile_pathtitletodolist_enabledis_analysis_donelinenumbers_enabledblanks_enabledscrollpastend_enablededgeline_enablededgeline_columnsclose_parentheses_enabledclose_quotes_enabledadd_colons_enabledauto_unindent_enabledindent_charstab_stop_width_spacesshow_class_func_dropdownhelp_enableddefault_fontwrap_enabledtabmode_enabledstripmode_enabledintelligent_backspace_enabledautomatic_completions_enabledautomatic_completion_charsautomatic_completion_mscompletions_hint_enabledcompletions_hint_after_mshover_hints_enabledformat_on_savecode_snippets_enabledcode_folding_enabledunderline_errors_enabledhighlight_current_line_enabledhighlight_current_cell_enabledoccurrence_highlighting_enabledoccurrence_highlighting_timeoutcheckeolchars_enabledalways_remove_trailing_spacesadd_newlineremove_trailing_newlinesconvert_eol_on_saveconvert_eol_on_save_tofocus_to_editorrun_cell_copycreate_new_file_if_emptyindent_guides_EditorStack__file_status_flagr!   r=   COLOR_SCHEME_NAMEScolor_schemer
   analysis_timersetSingleShotsetIntervaltimeoutrn   analyze_scripteditor_focus_changedupdate_fname_labelsetAcceptDropscreate_shortcuts	shortcutslast_closed_filesmsgboxedit_filetypesedit_filtersr    save_dialog_on_testsr(   autosavelast_cell_call)rV   r_   actionslayoutswitcher_actionsymbolfinder_actioncopy_to_cb_actionclose_rightr   	sort_tabsr   external_fileexp_actionr"  s   `            rW   rd   zEditorStack.__init__   s   v&"--.*40##   "!!!Q1-v	  $	!)$/  "vv.	' !*%,,	.
 ,'(-(00	2
 *$2J0KXXj)NO $D!,D*E.2.B.BD*43G1H595L5LN "$*D(E,0,N,NP	 <<8#%&D56D"/$99&&x,LN%%#' $'>'+_':'8$'99	'F F
  $ !!x[
 $ %#' #%*" $ %)-&$(!"&%)"!%&"(-%! !$!&-1*-1**+''*$(,%),&#' #%)"$(!(-%.3+.3+/3,/3,%)"-2* (-%#( &*##"(,%""' ):(;}1DDD-@@CL( %Tl))$/''-##++D,?,?@ 	!!))$*A*AB 	D! ..0 "$  #  )=(>$>! )."rY   Nc                 P   |t        |t              r| j                         }	 t        |       y# t        $ rl}t        |      j                  d      d   }d|v rAt        d      }t        d      }t        j                  | ||t        j                         Y d}~yY d}~yd}~ww xY w)z#Show file in external file explorerN'rb   zxdg-openWarningzSpyder can't show this file in the external file explorer because the <tt>xdg-utils</tt> package is not available on your system.)
isinstanceboolr   r4   FileNotFoundErrorstrr   r   r   informationOk)rV   fnameserrorfile	msg_titlemsgs         rW   r4   z*EditorStack.show_in_external_file_explorer  s     >Z5..0F
	8*62  	8u:##C(+DT!iL	 8 9 ''i(38 8 "	8s   0 	B%AB  B%c                 
    t        j                   j                  dd       }t        j                   j                  dd       }t        j                   j                  dd       }t        j                   j
                  dd       }t        j                   fddd       }t        j                   j                  dd	       }t        j                   fd
dd       }t        j                   fddd       }t        j                   j                  dd       }	t        j                   j                  dd       }
t        j                   j                  dd       }t        j                   j                  d   dd       }t        j                   j                  d   dd       }t        j                   j                  dd       }t        j                   j                  dd       }t        j                   j                  dd       }t        j                   j                  dd       }t        j                   j                   dd       }t        j                   j"                  dd       }t        j                   j$                  dd       }t        j                   j&                  dd       }t        j                   j&                  dd       }t        j                   j(                  dd       }t        j                   j*                  dd       }t        j                   j,                  dd       }t        j                   j,                  dd        }t        j                   j.                  dd!       }t        j                   j0                  dd"       }t        j                   j2                  dd#       }t        j                   j4                  dd$       }t        j                   fd%dd&       }t        j                   j6                  dd'       } t        j                   j8                  dd(       }!t        j                   j:                  dd)       }"t        j                   j<                  dd*       }#t        j                   j>                  dd+       }$t        j                   j@                  dd,       }%t        j                   jB                  dd-       }&g |||||||	|
|||||||||||||||||||||| |!|"|#|$|%|||&S ).zCreate local shortcutsrZ   zInspect current objectr\   
BreakpointzConditional breakpointz
Go to linec                  (     j                  d      S )NF)forward)tab_navigation_mrurU   s   rW   rX   z.EditorStack.create_shortcuts.<locals>.<lambda>  s    D++E+: rY   r[   rc   c                  :     j                   j                  d      S rQ   rj   tab_navigaterU   s   rW   rX   z.EditorStack.create_shortcuts.<locals>.<lambda>  s    DII**2. rY   zCycle to previous filec                  :     j                   j                  d      S ra   rP  rU   s   rW   rX   z.EditorStack.create_shortcuts.<locals>.<lambda>  s    DII**1- rY   zCycle to next filezRun selectionzRun to linezRun from liner   zNew filez	Open file	Save filezSave allzSave Asz	Close allzLast edit locationzPrevious cursor positionzNext cursor positionz	zoom in 1z	zoom in 2zzoom outz
zoom resetzclose file 1zclose file 2zrun cellz
debug cellzrun cell and advancezgo to next cellc                  (     j                  d      S )NT)reverse)advance_cellrU   s   rW   rX   z.EditorStack.create_shortcuts.<locals>.<lambda>d  s    D%%d%3 rY   zgo to previous cellzre-run last cellzPrevious warningzNext warningsplit verticallysplit horizontallyclose split panelr   )"r"   rv   inspect_current_objectset_or_clear_breakpoint"set_or_edit_conditional_breakpoint
go_to_linerN  run_selectionrun_to_linerun_from_linesig_new_fileplugin_loadsavesave_allsig_save_asclose_all_filessig_prev_edit_possig_prev_cursorsig_next_cursorzoom_inzoom_out
zoom_reset
close_filerun_cell
debug_cellrun_cell_and_advancerV  re_run_last_cellsig_prev_warningsig_next_warningsig_split_verticallysig_split_horizontallyclose_splitr4   )'rV   inspectset_breakpointset_cond_breakpointgotolinetabtabshiftprevtabnexttabr^  r_  r`  new_file	open_file	save_filerd  save_as	close_allprev_edit_posprev_cursornext_cursor	zoom_in_1	zoom_in_2rk  rl  close_file_1close_file_2rn  ro  rp  go_to_next_cellgo_to_previous_cellrq  prev_warningnext_warningsplit_verticallysplit_horizontallyrv  external_fileexps'   `                                      rW   r+  zEditorStack.create_shortcuts  s    &&'')	 --((	 #2233)	 ''OO	 "":&	 ''##"	 &&.)	 &&-%	 ,, 	 **	 ,, 	 ''b!	 ((R 		 ((II		 ''MM	 &&	 ((  		 ,,""%	 **  +	 **  '	 ((LL		 ((LL		 ''MM	 ))OO	
 ++OO	 ++OO	 ''MM	 ))OO	
  $33%%'	  .."	 #223&	  //!!#	 ++!!#	 ++!!	  //%%#	 "11''%	 **$	  ////1		4 	4 	4)< 	4h 	4 	4	4'	4)4	46C	4EM	4	4$	4&.	407	49B	4 	4  +	4 -8	4 :C	4 EN	4 		4 %		4 '3		4 5A		4 CK		4
 	4
 1	4  	4 "5	4 7G	4 	4 +	4 -=	4 #	4 %0	4 	4 !	4 #3	4 		4rY   c                 T    | j                   D cg c]  }|j                   c}S c c}w )z
        Returns shortcut data, a list of tuples (shortcut, text, default)
        shortcut (QShortcut or QAction instance)
        text (string): action/shortcut description
        default (string): default key sequence
        )r,  r   )rV   scs     rW   get_shortcut_datazEditorStack.get_shortcut_data  s      #'..1B111   %c                    |j                  d       | j                          |j                  | j                         t	        | t        j                  d      t        d            }|j                  t        t                     t        |       | _        |j                  | j                         |j                  |j                         | j                  j                   j#                  | j$                         t&        j(                  |gi}t+        | | j                  d|      | _        | j,                  j/                  | j0                         | j,                  j3                         j4                  j#                  | j6                         | j,                  j9                  d       | j:                  j=                          t?        | j,                  d      r.t@        jB                  dk(  s| j,                  jE                  d       | j,                  jF                  j#                  | jH                         tK               }|jM                  d	       tO        |      }|jQ                  dddd       |j                  | j,                         |j                  |       t@        jB                  dk(  r3| j                  jR                  j#                  | j                  fd
       yy)zSetup editorstack's layoutr   tooloptionsOptions)r   tipT)r   menu_use_tooltipscorner_widgetssetDocumentModer   ztab-containerc                     t        | d      S NF)rE   )r   s    rW   rX   z/EditorStack.setup_editorstack.<locals>.<lambda>  s    tU+ rY   N)*
setSpacingcreate_top_widgets	addWidgettop_toolbarrB   r>   r   r   setStyleSheetrB  rI   r   r   setMenusetPopupModeInstantPopupaboutToShowrn   _EditorStack__setup_menur	   TopRightCornerrK   rj   set_close_functionrm  r   tabMovedmove_editorstack_data
setMovableri   refreshhasattrr   r   r  currentChangedr   r   setObjectNamer   r   aboutToHide)rV   r_   r5  menu_btnr  tab_container
tab_layouts          rW   r   zEditorStack.setup_editorstack  s   ! 	! 	))* %T0G)*97s#:;<$K	#h334		%%d&7&78++hZ8T		T,:<			$$T__5		##++D,F,FG		T"""$499/0<<8+ II%%d+		  (()=)=>	##O4 /
%%aAq1TYY'' <<8#II!!)) II ,- $rY   c                    t               | _        t               }|j                  t        j
                  t        j                         t        d| j                        | _        t        |       | _
        | j                  j                  | j                         | j                  j                  |       | j                  j                  | j                         t        j                  j                         }|j                  j                  dddt         j"                          | j                  j%                  |j'                                y )N   )rw   r_   0px4pxz
1px solid )marginpaddingborderBottom)r   r   r   setSizePolicyr   	Expanding	PreferredrF   spinnerr   r  r  	qstylizerstyle
StyleSheet	setValuesr?   COLOR_BACKGROUND_4r  toString)rV   spacercsss      rW   r  zEditorStack.create_top_widgets  s    !8 [22K4I4IJ *r$:J:JK $D>""4#3#34""6*""4<<0 oo((*%m&F&F%GH 	 	

 	&&s||~6rY   c                 Z    | j                   D ]  }|j                  j                           y)zHide any open tooltips.N)r   rh   hide_tooltiprV   finfos     rW   r  zEditorStack.hide_tooltip  s%    YY 	(ELL%%'	(rY   c                     t        | j                               }t        |      dkD  r	d|dd z   }n|}| j                  j	                  |       y)zUpdate file name label.d   z...iN)r:   r   lenr   r   )rV   filenameshorten_filenames      rW   r)  zEditorStack.update_fname_label  sO     "$";";"=>x=3%7'  !12rY   c                 :    | j                   j                  |       y r   )rj   add_corner_widgets)rV   widgetss     rW   add_corner_widgets_to_tabbarz(EditorStack.add_corner_widgets_to_tabbar  s    		$$W-rY   c                 >    | j                   r| j                          yy)z8Closes the editorstack if it is not the last one opened.N)r   r   rU   s    rW   rv  zEditorStack.close_split  s     JJL rY   c                 T   | j                   j                          | j                  j                  j	                  | j
                         | j                  {| j                  D ]l  }| j                  j                  |j                  j                         |j                  j                  sI|j                  j                  j                          n | j                  D ]3  }|j                  j                  r|j                  j                          5 t        j                  | |       y)zOverrides QWidget closeEvent().N)r   close_all_threadsr#  r&  
disconnectr'  r   r   remove_editorrh   oe_proxy	is_cloneddeleteLaternotify_closer   
closeEvent)rV   r   r  s      rW   r  zEditorStack.closeEvent  s    ,,.##..t/B/BC + 8$$225<<3H3HI <<))LL))5578 YY 	,E<<))))+	, 	4'rY   c                     |j                   }|j                  }|j                  }| j                  ||d|||j                        }|j                  |j                         |j                  S )Nrz   )set_currentnewcloned_from)r  r;   newly_createdcreate_new_editorrh   set_todo_resultstodo_results)rV   other_finfor  fnameencr  r  s          rW   clone_editor_fromzEditorStack.clone_editor_from!  sm    $$""''&&uc23>C3>3E3E ' G 	{778||rY   c                     |j                   D ]  }| j                  |d        | j                  |j                                y)z%Clone EditorStack from other instanceT)r  N)r   r  r   get_stack_index)rV   otherr  s      rW   
clone_fromzEditorStack.clone_from+  sA     :: 	BK"";D"A	BU2245rY   c                 |     j                   j                         sy j                  O j                  j                         r5 j                  j	                           j                  j                          y j                  [ddlm}  |        _        t         j                          j                   j                   fd j                                _        t        |t              rd} j                  j                  |        j                  j!                           j                  j#                           j                   j%                         j'                         j)                          j*                  j'                         j)                         z   dz   } j                  j-                  |       y)z$Open file list management dialog boxNr   )Switcherc                       S r   r   rU   s   rW   rX   z/EditorStack.open_switcher_dlg.<locals>.<lambda>B  s     rY   )sectionrz   rb   )rj   r   r   r   r   clearspyder.widgets.switcherr  r*   
get_pluginget_current_editorget_plugin_titler   r?  r@  set_search_textsetupshowr   r   r   r   set_position)rV   initial_textr  	delta_tops   `   rW   r   zEditorStack.open_switcher_dlg1  sV    yy (T->->-H-H-J""$##%$8 (D$9!!!''--/%1D! lD)L)),7! YY%%'00299;%%..0779:<=>	&&y1rY   c                 (    | j                  d       y )N@)r  )r   rU   s    rW   r   z!EditorStack.open_symbolfinder_dlgP  s    C0rY   c                 6    | j                         j                  S )z$Get the plugin of the parent widget.)r_   pluginrU   s    rW   r  zEditorStack.get_pluginT  s     {{}###rY   c                 >    | j                         j                         S )z*Get the plugin title of the parent widget.)r  r  rU   s    rW   r  zEditorStack.get_plugin_titleZ  s      1133rY   c                     | | j                         j                  |       y| j                  r| j                         j                          yy)zGo to line dialogN)r  r]  r   exec_gotolinedialog)rV   lines     rW   r]  zEditorStack.go_to_line`  sB     ##%006yy'')==? rY   c                 r    | j                   r+| j                         }|j                  j                          yy)zSet/clear breakpointNr   r  debuggertoogle_breakpointrV   rh   s     rW   r[  z#EditorStack.set_or_clear_breakpointj  s,    99,,.FOO--/ rY   c                 v    | j                   r-| j                         }|j                  j                  d       yy)zSet conditional breakpointT)edit_conditionNr  r  s     rW   r\  z.EditorStack.set_or_edit_conditional_breakpointp  s1    99,,.FOO--T-B rY   c                 `    | j                   r"| j                         }|j                  |       yy)z(Bookmark current position to given slot.N)r   r  add_bookmark)rV   slot_numrh   s      rW   set_bookmarkzEditorStack.set_bookmarkv  s*    99,,.F) rY   c                 4   | j                         }|j                  j                  | j                         d}|j	                  d      }|r$|j                         }|r|j                         }ny|j                  |      \  }}|j                  |||d|       y)z)Inspect current object in the Help pluginNcursorF)	show_hintclicked)	r  sig_display_object_inforn   display_helpget_positionget_last_hover_cursorpositionget_cursor_line_columnrequest_hover)rV   r  rh   r  offsetr  cols          rW   rZ  z"EditorStack.inspect_current_object|  s     ((*&&..t/@/@A$$X.113F*11&9	cT3',g 	 	?rY   c                     | j                         }|r|j                         }n|j                  d      }	 |j                  j	                  | j
                         | j                  ||d       y # t        $ r Y  w xY w)NT)help_reqforce)r  get_last_hover_wordget_current_wordr  r  r  	TypeErrorsend_to_help)rV   	help_textr  rh   r^   s        rW   r  zEditorStack.display_help  s    ((*--/D**D*9D	**55d6G6GH 	$	6  	 	s   %A1 1	A=<A=c                     || _         y)z,Parent widget must handle the closable stateN)r   rV   states     rW   set_closablezEditorStack.set_closable  s
     rY   c                 <    || _         || _        || _        || _        y r   )r   r   r   r   )rV   r   r   r   r   s        rW   set_io_actionszEditorStack.set_io_actions  s!    $&&*rY   c                     || _         y r   )r   )rV   r   s     rW   set_find_widgetzEditorStack.set_find_widget  s
    &rY   c                     || _         y r   )r   )rV   r   s     rW   set_outlineexplorerzEditorStack.set_outlineexplorer  s
    .rY   c                     || _         y r   )r   )rV   paths     rW   set_tempfile_pathzEditorStack.set_tempfile_path  s
    !rY   c                     || _         y r   )r   )rV   r   s     rW   	set_titlezEditorStack.set_title  s	    
rY   c                     || _         | j                  rR| j                  D ]B  }|j                  j                         s|j                  j                  j                  |       D y y r   )r  r   rh   is_python_likeclassfuncdropdown
setVisiblerV   r*  r  s      rW   set_classfunc_dropdown_visiblez*EditorStack.set_classfunc_dropdown_visible  sS    (-%99 E<<..0LL22==eDE rY   c                 n    |j                   j                  | j                  | j                                y )N)linenumbersmarkers)linenumberareasetup_marginsr   has_markersr  s     rW   __update_editor_marginsz#EditorStack.__update_editor_margins  s0    ++00$:J:J:L 	, 	NrY   c                     | j                   S )zVReturn True if this editorstack has a marker margin for TODOs or
        code analysis)r   rU   s    rW   rB  zEditorStack.has_markers  s     $$$rY   c                     || _         | j                  rX| j                  D ]H  }| j                  |j                         |j	                          |s1|4||us9|j                          J y y r   )r   r   #_EditorStack__update_editor_marginsrh   cleanup_todo_resultsrun_todo_finderrV   r*  current_finfor  s       rW   set_todolist_enabledz EditorStack.set_todolist_enabled  sc     %99 0,,U\\:**,]6$E1--/0 rY   c                     || _         | j                  r-| j                  D ]  }| j                  |j                          y y r   )r   r   rF  rh   rI  s       rW   set_linenumbers_enabledz#EditorStack.set_linenumbers_enabled  s;    #( 99 ;,,U\\:; rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r   r   rh   set_blanks_enabledr;  s      rW   rO  zEditorStack.set_blanks_enabled  s;    #99 7//67 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r   r   rh   set_scrollpastend_enabledr;  s      rW   rQ  z%EditorStack.set_scrollpastend_enabled  s;    %*"99 >66u=> rY   c                     || _         | j                  r7| j                  D ]'  }|j                  j                  j	                  |       ) y y r   )r   r   rh   	edge_lineset_enabledr;  s      rW   set_edgeline_enabledz EditorStack.set_edgeline_enabled  sA     %99 :&&2259: rY   c                     || _         | j                  r7| j                  D ]'  }|j                  j                  j	                  |       ) y y r   )r   r   rh   rS  set_columns)rV   columnsr  s      rW   set_edgeline_columnsz EditorStack.set_edgeline_columns  sA     '99 <&&227;< rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_identation_guidesr;  s      rW   set_indent_guideszEditorStack.set_indent_guides  s;    "99 =55e<= rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r   r   rh   set_close_parentheses_enabledr;  s      rW   r^  z)EditorStack.set_close_parentheses_enabled  s=    ).&99 B::5AB rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r   r   rh   set_close_quotes_enabledr;  s      rW   r`  z$EditorStack.set_close_quotes_enabled  s;    $)!99 =55e<= rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r   r   rh   set_add_colons_enabledr;  s      rW   rb  z"EditorStack.set_add_colons_enabled  s;    "'99 ;33E:; rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r   r   rh   set_auto_unindent_enabledr;  s      rW   rd  z%EditorStack.set_auto_unindent_enabled  s;    %*"99 >66u=> rY   c                     |dd }|| _         | j                  r-| j                  D ]  }|j                  j                  |        y y )Nrb   rR   )r   r   rh   set_indent_chars)rV   r   r  s      rW   rf  zEditorStack.set_indent_chars  sG    #Ab)(99 <--l;< rY   c                     || _         | j                  r=| j                  D ]-  }||j                  _         |j                  j                          / y y r   )r   r   rh   update_tab_stop_width_spaces)rV   r   r  s      rW   set_tab_stop_width_spacesz%EditorStack.set_tab_stop_width_spaces  sE    %:"99 <5J299;< rY   c                     || _         y r   )r  r)  s     rW   set_help_enabledzEditorStack.set_help_enabled&  s
    !rY   c                     || _         ||| _        | j                  r.| j                  D ]  }|j                  j	                  ||         y y r   )r  r"  r   rh   set_font)rV   fontr"  r  s       rW   set_default_fontzEditorStack.set_default_font)  sK     # ,D99 :%%dL9: rY   c                    || _         | j                  r| j                  D ]  }|j                  j                  |       |j                  j	                          |j                  j                          |j                  j                          | j                  r|j                  j                          | j                  r|j                  j                          | j                  s|j                  j                           y y r   )r"  r   rh   set_color_schemeunhighlight_current_lineunhighlight_current_cellclear_occurrencesr  highlight_current_liner  highlight_current_cellr  mark_occurrences)rV   r"  r  s      rW   rq  zEditorStack.set_color_scheme1  s    (99 4--l; 557557..066LL77966LL77977LL1134 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_wrap_moder;  s      rW   set_wrap_enabledzEditorStack.set_wrap_enabledD  s;    !99 5--e45 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_tab_moder;  s      rW   set_tabmode_enabledzEditorStack.set_tabmode_enabledK  s;    $99 1))%01 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_strip_moder;  s      rW   set_stripmode_enabledz!EditorStack.set_stripmode_enabledR  s;    !&99 3++E23 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_intelligent_backspacer;  s      rW   !set_intelligent_backspace_enabledz-EditorStack.set_intelligent_backspace_enabledY  s=    -2*99 A99%@A rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_code_snippetsr;  s      rW   set_code_snippets_enabledz%EditorStack.set_code_snippets_enabled`  s;    %*"99 911%89 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_code_foldingr;  s      rW   set_code_folding_enabledz$EditorStack.set_code_folding_enabledf  s;    $)!99 80078 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_automatic_completionsr;  s      rW   !set_automatic_completions_enabledz-EditorStack.set_automatic_completions_enabledl  s=    -2*99 A99%@A rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r	  r   rh   %set_automatic_completions_after_chars)rV   charsr  s      rW   r  z1EditorStack.set_automatic_completions_after_charsr  s=    */'99 JBB5IJ rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_completions_hintr;  s      rW   set_completions_hint_enabledz(EditorStack.set_completions_hint_enabledx  s;    (-%99 <44U;< rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_completions_hint_after_ms)rV   msr  s      rW   r  z)EditorStack.set_completions_hint_after_ms~  s;    )+&99 ?::2>? rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_hover_hintsr;  s      rW   set_hover_hints_enabledz#EditorStack.set_hover_hints_enabled  s;    #( 99 7//67 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   toggle_format_on_saver;  s      rW   set_format_on_savezEditorStack.set_format_on_save  s;    #99 :2259: rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_occurrence_highlightingr;  s      rW   #set_occurrence_highlighting_enabledz/EditorStack.set_occurrence_highlighting_enabled  s=    /4,99 @88?@ rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_occurrence_timeout)rV   r&  r  s      rW   #set_occurrence_highlighting_timeoutz/EditorStack.set_occurrence_highlighting_timeout  s;    /6,99 =33G<= rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_underline_errors_enabledr;  s      rW   r  z(EditorStack.set_underline_errors_enabled  =    (-%99 A99%@A rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_highlight_current_liner;  s      rW   "set_highlight_current_line_enabledz.EditorStack.set_highlight_current_line_enabled  ;    .3+99 ?77>? rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_highlight_current_cellr;  s      rW   "set_highlight_current_cell_enabledz.EditorStack.set_highlight_current_cell_enabled  r  rY   c                     || _         y r   )r  r)  s     rW   set_checkeolchars_enabledz%EditorStack.set_checkeolchars_enabled  s
    %*"rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_remove_trailing_spacesr;  s      rW   !set_always_remove_trailing_spacesz-EditorStack.set_always_remove_trailing_spaces  s;    -2*99 ?77>? rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_add_newliner;  s      rW   r  zEditorStack.set_add_newline  s;     99 4,,U34 rY   c                     || _         | j                  r-| j                  D ]  }|j                  j                  |        y y r   )r  r   rh   set_remove_trailing_newlinesr;  s      rW   r  z(EditorStack.set_remove_trailing_newlines  r  rY   c                     || _         y)z=If `state` is `True`, saving files will convert line endings.N)r  r)  s     rW   set_convert_eol_on_savez#EditorStack.set_convert_eol_on_save  s     $) rY   c                     || _         y)z*`state` can be one of ('LF', 'CRLF', 'CR')N)r  r)  s     rW   set_convert_eol_on_save_toz&EditorStack.set_convert_eol_on_save_to  s     ',#rY   c                     || _         y r   )r  r)  s     rW   set_focus_to_editorzEditorStack.set_focus_to_editor  s
    $rY   c                     || _         y)zAIf `state` is ``True``, code cells will be copied to the console.N)r  r)  s     rW   set_run_cell_copyzEditorStack.set_run_cell_copy  s
    "rY   c                 \    | j                   D ]  }|j                  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)r   rh   set_current_project_path)rV   	root_pathr  s      rW   r  z$EditorStack.set_current_project_path  s)     YY 	=ELL11)<	=rY   c                 6    | j                   j                         S r   )rj   currentIndexrU   s    rW   r  zEditorStack.get_stack_index  s    yy%%''rY   c                 V    | j                   r| j                   | j                            S y r   )r   r  rU   s    rW   get_current_finfozEditorStack.get_current_finfo  s&    9999T11344 rY   c                 6    | j                   j                         S r   )rj   currentWidgetrU   s    rW   r  zEditorStack.get_current_editor  s    yy&&((rY   c                 6    | j                   j                         S r   )rj   r   rU   s    rW   get_stack_countzEditorStack.get_stack_count  s    yy  rY   c                 P    || k(  s|d k(  r| j                   j                  |       y y r   )rj   setCurrentIndex)rV   r   instances      rW   r   zEditorStack.set_stack_index  s(    tx4/II%%e,  0rY   c                 V    | j                   j                         j                  |       y r   )rj   r   r:  r)  s     rW   set_tabbar_visiblezEditorStack.set_tabbar_visible  s    		%%e,rY   c                     | j                   j                  d       | j                   j                  |       | j                  j	                  |       | j                   j                  d       | j                          y NTF)rj   blockSignals	removeTabr   popupdate_actions)rV   r   s     rW   remove_from_datazEditorStack.remove_from_data  sT    		t$		E"		e		u%rY   c                 *    ||r|dz  }||rd|z  }|S )N*z(%s)r   )rV   r   is_modifiedis_readonlys       rW   __modified_readonly_titlez%EditorStack.__modified_readonly_title   s)    "{SLE"{UNErY   c                     | j                   D cg c]  }|j                   }}| j                   |   j                  }t        j                  ||      }| j	                  |||      S c c}w )zReturn tab title.)r   r  r<   disambiguate_fname%_EditorStack__modified_readonly_title)rV   r   r  r  r  files_path_listr  s          rW   get_tab_textzEditorStack.get_tab_text  se    7;yyAe5>>AA		% ))--ouE--e.9;H 	H Bs   A&c                 ,   d}| j                  |||      }| j                  G|t        j                  | j                        k(  r%t	        t        d            }||| j                  fz  S |t        j                  |      t        j                  |      fz  S )zReturn tab menu titleu	   %s — %szTemporary file)	r  r   r;   to_unicode_from_fsr:   r   ospbasenamedirname)rV   r  r  r  r   temp_file_strs         rW   get_tab_tipzEditorStack.get_tab_tip  s    --d.9;H)866t7I7IJJ*1-=+>?M=$*<*<===3<<13;;x3HIIIrY   c                    d |j                   _        |dk(  rdnt        | j                        }| j                  j	                  ||       | j                  j                  |      }|j                   }| j                  j                  ||| j                  |             | j                  |d       |r"| j                  |       | j                  |       | j                          y )Nstartr   F)rh   r  r  r   insertr   rj   	insertTabr  set_stack_titler   r   r  )rV   r  r  	add_wherer   rh   s         rW   add_to_datazEditorStack.add_to_data  s     $')s499~		&		&		E64+<+<U+CDUE*  '  'rY   c                    | j                   j                  d       | j                   j                          | j                  D ]  }|j                  rd}nd }| j                  j                  |      }| j                  ||      }| j                  |j                        }| j                   j                  |j                  |      }| j                   j                  ||        | j                   j                  d       y r  )rj   r  r  r   r  r   r  r  r  addTabrh   setTabToolTip)rV   r  r  r   tab_texttab_tips         rW   __repopulate_stackzEditorStack.__repopulate_stack(  s    		t$		YY 		4E""""IIOOE*E((<H&&u~~6GII$$U\\8<EII##E73		4 			u%rY   c                    | j                  |      }|y | j                  |   }|j                  j                          ||_        ||j                  _        t        j                  |      d   }t        j                  |      d   }||k7  rt        |j                  j                               }t        ||      }|j                  j                  ||       |j                  j                          |||j                  d}	| j                  j                  |	       |j                  j                  d|       |j                  j                          |j                  j!                          n|j                  j#                          || j%                         k(  }
| j'                         }||j                  _        | j                  j)                  |      }| j+                          |
r| j-                  |       n| j/                  |       | j0                  :| j0                  j3                  |j                  j4                  |j                         |S )Nrb   languager  r+   T)show_debug_panelr  )has_filenamer   rh   r  r  r  splitextr:   get_text_with_eolr)   set_languagerun_pygments_highlightersig_open_fileemitset_debug_panelcleanup_code_analysiscleanup_foldingdocument_did_openr  r   r   _EditorStack__repopulate_stackr   set_current_filenamer   file_renamedr  )rV   original_filenamenew_filenamer   r  original_extnew_exttxtr  optionsset_new_indexcurrent_fname	new_indexs                rW   rename_in_datazEditorStack.rename_in_data7  s   !!"34=		%  	!!# & , ||$56q9,,|,Q/7" !?!?!ABC(s;HLL%%h=LL113 %(#llG
 ##G, LL((!% ) :LL..0LL((* LL**,!5!5!77113 ,IIOOE*	!  + %%m4+  --%%u~~7rY   c                    | j                   |   }|j                  }|xs |j                  xr |j                   }|j                  j                         }| j                  |||      }| j                  |||      }|| j                  j                  |      k7  r| j                  j                  ||       | j                  j                  ||       y r   )r   r  r  defaultrh   
isReadOnlyr  r  rj   r}   
setTabTextr  )rV   r   r  r  r  r  r  r  s           rW   r  zEditorStack.set_stack_titleq  s    		% "9e&9&9P5==?Pll--/$$UKE""5+{C tyy((//II  1		w/rY   c                    | j                   j                          | j                  r| j                  }n(| j                  | j
                  f}| j                          t        | j                   t        |      | j                         z          | j                  j                  | j                         t        j                  dk(  rt        | j                   d       yy)z(Setup tab context menu before showing itr   TN)r   r  r   r   r   r   setFocusr@   listr   r   
setEnabledr   r   r   rE   )rV   r4  s     rW   __setup_menuzEditorStack.__setup_menu  s    		99''G(8(89GMMODIItG}t/G/G/IIJ$$T%5%56<<8#499d+ $rY   c                 &   | j                         | j                         j                  }nd }|Dt        | t        d      t	        j
                  d      t        d      |j                        | _        t        | t        d      t	        j
                  d      t        d      | j                  t        j                  dd	
      t        j                        | _        t        | t        d      t	        j
                  d      t        d      | j                  t        j                  dd
      t        j                        | _        t        | t        d      t	        j
                  d      | j                   t        j                  dd
      t        j                        | _        t$        | j                  | j                  | j"                  g}| j&                  r]| j)                         }t        | t        d      t	        j
                  d      |j*                        }|t$        | j                  |gz  }|S |Y|j,                  |t$        |j.                  gz  }|S |t$        | j                  |j0                  |j2                  |j4                  gz  }|S )Nz
New window	newwindowzCreate a new editor windowr   r  r   zSplit verticallyversplitz#Split vertically this editor windowrZ   rW  r   )r   r  r   r   r]   zSplit horizontallyhorsplitz%Split horizontally this editor windowrX  zClose this panelclose_panelrY  )r   r   r   r]   Close window
close_paner   )r_   r  rA   r   r>   r   create_new_windownew_window_actionrt  r"   r   r	   r   r   ru  r   rv  r   rC   r   windowr   _undocked_window_dock_action_lock_unlock_action_undock_action_close_plugin_action)rV   r  r4  r!  close_window_actions        rW   __get_split_actionszEditorStack.__get_split_actions  sL   ;;=$[[]))FF %2aoXXk*23 22	&4D"  - !*%78//&&x,>@%% '  -"#*%9:11&&x,@B%% ' * !-(&&&&x,?A%%' "4#7#7''):):< ??[[]F"/a'XXl+ ,,#( (>(>+- -G  &&2NF,?,?@@  ND,B,B"66"11"779 9
 rY   c                 p    | j                   j                  d       | j                  j                  d       y )NT)r   r  r   rU   s    rW   reset_orientationzEditorStack.reset_orientation  s*    ''-''-rY   c                     | j                   j                  |t        j                  k(         | j                  j                  |t        j
                  k(         y r   )r   r  r	   
Horizontalr   Vertical)rV   orientations     rW   set_orientationzEditorStack.set_orientation  s<    ''r}}(DE''r{{(BCrY   c                     | j                         dkD  }| j                  j                  |       | j                  j                  |       y Nr   )r  r   r  r   r)  s     rW   r  zEditorStack.update_actions  s=    $$&*''.''.rY   c                 j    | j                   r'| j                   | j                            j                  S y r   )r   r  r  rU   s    rW   r   z EditorStack.get_current_filename  s,    9999T1134=== rY   c                 ~    | j                   r1| j                   | j                            j                  j                  S y r   )r   r  rh   r  rU   s    rW   get_current_languagez EditorStack.get_current_language  s2    9999T1134;;DDD rY   c                 T    | j                   D cg c]  }|j                   c}S c c}w )zl
        Return a list with the names of all the files currently opened in
        the editorstack.
        )r   r  r  s     rW   get_filenameszEditorStack.get_filenames  s     
 -1II65666r  c                     | j                         }	 |j                  |      S # t        $ rG 	 t        |      }n# t        $ r Y Y yw xY wt        |      D ]  \  }}|t        |      k(  s|c cY S  Y yw xY w)a  Return the self.data index position for the filename.

        Args:
            filename: Name of the file to search for in self.data.

        Returns:
            The self.data index for the filename.  Returns None
            if the filename is not found in self.data.
        N)r6  r   
ValueErrorr5   OSError	enumerate)rV   r  data_filenamesr   editor_filenames        rW   r  zEditorStack.has_filename  s     ++-	!''11 	"8,  +4N*C !&w77 L! 	s;   # 	A39A3	AA3A"A3)A3/A32A3c                    	 | j                  |      }|]|r| j                  |       | j                  |   j
                  }|r|j                          |S | j                  j                  |       |S y# t        t        f$ r d}Y sw xY w)z?Set current filename and return the associated editor instance.N)	r  rA  r9  r   r   rh   r  ri   remove_and_append)rV   r  focusr   rh   s        rW   r  z EditorStack.set_current_filename
  s    	%%h/E $$U+YYu%,,F! M ""44U;M  "7+ 	E	s   A3 3BBc                 X    |t        | j                        dkD  S | j                  |      S )a  Return if filename is in the editor stack.

        Args:
            filename: Name of the file to search for.  If filename is None,
                then checks if any file is open.

        Returns:
            True: If filename is None and a file is open.
            False: If filename is None and no files are open.
            None: If filename is not None and the file isn't found.
            integer: Index of file name in editor stack.
        r   )r  r   r  )rV   r  s     rW   is_file_openedzEditorStack.is_file_opened$  s.     tyy>A%%$$X..rY   c                 t    | j                   D cg c]  }|j                   }}|j                  |      S c c}w )zn
        Return the position index of a file in the tab bar of the editorstack
        from its name.
        )r   r  r   )rV   r  d	filenamess       rW   get_index_from_filenamez#EditorStack.get_index_from_filename7  s3    
 *.3AQZZ3	3x(( 4s   5c                    |dk  s|dk  ryt        ||z
        }||z
  |z  }| j                  }| j                  d       t        |||      D ]  }|||z      ||   c||<   |||z   <    | j                  d       | j	                          y)z\Reorder editorstack.data so it is synchronized with the tab bar when
        tabs are moved.r   NTF)absr   r  ranger  )rV   r  endr   	directionr   is          rW   r  z!EditorStack.move_editorstack_data?  s     19ae$EUu,Iyy$uc9- 	DA)-a	k):DG&DGT!I+&	D 	% rY   c                    | j                         }| j                         }|$|dkD  r|}n| j                  j                  d       yd}|dkD  r||k(  r| j	                         }n|}| j                         r@| j                         j                  j                  | j                  |   j                        nd}|xs | j                  d|      xr |}|rT| j                  |   }| j                  j                  |       | j                  /| j                  j                  |j                  j                          | j                  |   j                  }	| j#                  |       |j                  }
|
j%                          |
j'                  d       |
j(                  j'                  d       | j                         r| j+                         j-                  |
       | j.                  j1                  t3        t5        |             |	       | j6                  j1                          | j8                  j1                          | j:                  j1                          | j<                  j1                          |||k  r|dz  }| j?                  |       | jA                         }
|
r+tC        jD                          d| _#        |
jI                          | jK                  |j                         |j                  | jL                  jN                  v r!| jL                  jN                  |j                  = | j                         dk(  r:| jP                  r.| jR                  d   j1                          | jU                          y| jW                          |S )zClose file (index=None -> close current file)
        Keep current file index unchanged (if current file
        that is being closed)Nr   rb   T)
cancelabler   Fr   ),r  r  r   
set_editor_get_previous_file_indexr_   r  can_close_filer   r  save_if_changedr   close_threadsr   r  rh   r  r  r  	setParentcompletion_widgetr  unregister_widget_shortcutssig_close_filer  rB  idopened_files_list_changed sig_update_code_analysis_actionsrefresh_file_dependent_actionsupdate_plugin_titler   r  r   processEventsr   r  add_last_closed_filer2  file_hashesr  ra  r)   _EditorStack__modify_stack_title)rV   r   r"  current_indexr   r  rP  is_okr  r  rh   s              rW   rm  zEditorStack.close_fileS  s    ,,.$$&=qy%  ++D1	19% 99;	)	 +/++- --<<IIe%%'=A 	 $$..$e.L $# 	IIe$E,,U3##/$$225<<3H3HIyy'00H!!%(\\F!T"$$..t4{{}!==fE $$SD]H=**//111668//446$$))+$9$NI$$Y/ ,,.F **, +0'!%%enn5~~!:!::MM--enn=!Q&4+H+Hb!&&(##%!!#rY   c                     t        | j                               D ]L  }| j                  j                  |      }|j                  j                         |k(  s<|j                  |       N y)aA  
        Register completion server capabilities across all editors.

        Parameters
        ----------
        capabilities: dict
            Capabilities supported by a language server.
        language: str
            Programming language for the language server (it has to be
            in small caps).
        N)rH  r  rj   widgetr  r    register_completion_capabilities)rV   capabilitiesr  r   rh   s        rW   rd  z,EditorStack.register_completion_capabilities  sZ     4//12 	FEYY%%e,F$$&(277E	FrY   c                     t        | j                               D ]K  }| j                  j                  |      }|j                  j                         |k(  s<|j                          M y)z4Notify language server availability to code editors.N)rH  r  rj   rc  r  r   start_completion_servicesrV   r  r   rh   s       rW   rg  z%EditorStack.start_completion_services  sT    4//12 	3EYY%%e,F$$&(2002	3rY   c                     t        | j                               D ]K  }| j                  j                  |      }|j                  j                         |k(  s<|j                          M y)z6Notify language server unavailability to code editors.N)rH  r  rj   rc  r  r   stop_completion_servicesrh  s       rW   rj  z$EditorStack.stop_completion_services  sT    4//12 	2EYY%%e,F$$&(2//1	2rY   c                 J    | j                         r	 | j                         ryy)zClose all opened scriptsN)rm  rU   s    rW   rf  zEditorStack.close_all_files  s    oo oorY   c                     | j                         }| j                         }t        ||dz
        D ]  }| j                  |dz           y)z% Close all files opened to the right rb   N)r  r  rH  rm  )rV   numn__s       rW   r   zEditorStack.close_all_right  sG    ""$  "QqS/ 	#BOOCE"	#rY   c                     | j                          t        d| j                         dz
        D ]  }| j                  d        y)z#Close all files but the current oner   rb   N)r   rH  r  rm  )rV   ro  s     rW   r   zEditorStack.close_all_but_this  s>    4//1A56 	BOOA	rY   c                    | j                         du rt        d| j                  j                         j	                               D ]  }| j                  j                         j                  |      | j                  j                         j                  |dz         kD  sZ| j                  j                         j                  ||dz           | j                         du ryy)zSort open tabs alphabetically.Fr   rb   N)sortedrH  rj   r   r   r}   moveTabrV   rK  s     rW   r   z)EditorStack.sort_file_tabs_alphabetically  s    kkmu$1dii..06689 999##%--a0		((*221q59:II$$&..q!a%89 kkmu$rY   c                 (   t        d| j                  j                         j                         dz
        D ]Z  }| j                  j                         j	                  |      | j                  j                         j	                  |dz         kD  sZ y y)z5Utility function for sort_file_tabs_alphabetically().r   rb   FT)rH  rj   r   r   r}   rt  s     rW   rr  zEditorStack.sorted  sz    q$))**,224q89 	A		  "**1-II$$&..q1u56	 rY   c                     || j                   v r| j                   j                  |       | j                   j                  d|       t        | j                         dkD  r| j                   j	                  d       yy)zAdd to last closed file list.r   
   rR   N)r-  remover  r  r  )rV   r  s     rW   r]  z EditorStack.add_last_closed_file  sf    D***""))%0%%a/t%%&+""&&r* ,rY   c                     | j                   S r   r-  rU   s    rW   get_last_closed_filesz!EditorStack.get_last_closed_files  s    %%%rY   c                     || _         y r   rz  )rV   rE  s     rW   set_last_closed_filesz!EditorStack.set_last_closed_files  s
    !'rY   c           	         |#t        t        | j                                     }n|g}t        j                  t        j
                  z  }|r|t        j                  z  }d}|D ]=  }| j                  |   j                  j                         j                         s9|dz  }? |sy|dkD  r-|t        t        j                  t        j                  z        z  }dx}}|D ]  }| j                  |       	 | j                  |   }|j                   | j"                  k(  s|r| j%                  |      rR y|r| j&                  j)                  |       r|j                  j                         j                         s| j*                  st        t        j,                  | j.                  t1        d      t3        j4                  |j                         z  ||       | _        | j6                  j9                         }	|	t        j                  k(  r| j%                  |      r> y|	t        j
                  k(  r'| j&                  j)                  |j                          z|	t        j                  k(  r| j%                  |      s yd}|	t        j                  k(  r)| j&                  j)                  |j                          d}|	t        j                  k(  s y y# t        $ r Y  yw xY w)aa  Ask user to save file if modified.

        Args:
            cancelable: Show Cancel button.
            index: File to check for modification.

        Returns:
            False when save() fails or is cancelled.
            True when save() is successful, there are no modifications,
                or user selects No or NoToAll.

        This function controls the message box prompt for saving
        changed files.  The actual save is performed in save() for
        each index processed. This function also removes autosave files
        corresponding to files the user chooses not to save.
        r   rb   TFz<<b>%s</b> has been modified.<br>Do you want to save changes?r_   )r  rH  r  r   YesNoCancelr   rh   document
isModifiedr   YesToAllNoToAllr   r   r  r   rc  r2  remove_autosave_filer1  Questionr   r   r  r  r.  exec_)
rV   rM  r   indexesbuttons
unsaved_nbyes_allno_allr  answers
             rW   rQ  zEditorStack.save_if_changed  sb   " =5!5!5!789GgG//KNN2{)))G
 	 Eyy&&//1<<>a
	  >s;//+2E2EEFFG  & *	!E  '
		%( ~~!3!33wyy' 2259,,'')446++)#,,

 =  \\%..9: "!%' **,[__,99U+${~~-MM66u~~F{33399U+$"G{222MM66u~~F!F{111 U*	!V G  s   4K	K$#K$c                 ^    t        |j                  j                               }t        |      S )zCompute hash of contents of editor.

        Args:
            fileinfo: FileInfo object associated to editor whose hash needs
                to be computed.

        Returns:
            int: computed hash.
        )r:   rh   r  hash)rV   fileinfor  s      rW   compute_hashzEditorStack.compute_hashF  s%     X__>>@ACyrY   c                     t        |j                  j                               }t        j                  |||j                        |_        y)aQ  Low-level function for writing text of editor to file.

        Args:
            fileinfo: FileInfo object associated to editor to be saved
            filename: str with filename to save to

        This is a low-level function that only saves the text to file in the
        correct encoding without doing any error handling.
        N)r:   rh   r  r;   write)rV   r  r  r  s       rW   _write_to_filezEditorStack._write_to_fileS  s6     X__>>@A$NN3(:K:KLrY   c           
         	 |! j                         sy j                         } j                  |   		j                  j	                         j                         s	j                  s|syt        j                  	j                        s|s|r j                  |      S y j                  r j                  s j                  |        j                  r j                  s j                  |        j                   r j                  s j#                  |        j$                  r'dddd}| j&                     } j)                  |       	  j                  rW	j                  j*                  r@	j                  j-                         r%	j                  j.                  }	j                  j0                  }|j3                  d       |j4                  j7                  |j8                         	j                  j:                  j7                  	 fd	       	j                  j:                  j7                  |j<                         	j                  j:                  j7                  |j8                         |j?                  d
       	j                  jA                          |jC                          y jE                  	       y# tF        $ r}tI        tH        jJ                  tM        d      tM        d      t        jN                  	j                        tQ        |      fz          _)         jR                  jC                          Y d}~yd}~ww xY w)a  Write text of editor to a file.

        Args:
            index: self.data index to save.  If None, defaults to
                currentIndex().
            force: Force save regardless of file state.

        Returns:
            True upon successful save or when file doesn't need to be saved.
            False if save failed.

        If the text isn't modified and it's not newly created, then the save
        is aborted.  If the file hasn't been saved before, then save_as()
        is invoked.  Otherwise, the file is written using the file name
        currently in self.data.  This function doesn't change the file name.
        NTr   posixntmac)r   CRLFCR)osnamec                  &    j                         S r   )
_save_file)r  rV   s   rW   rX   z"EditorStack.save.<locals>.<lambda>  s    DOOE2 rY   i'  
Save Error;<b>Unable to save file '%s'</b><br><br>Error message:<br>%sr  F)*r  r  r   rh   r  r  r  r  isfiler  r  r  r  remove_trailing_spacesr  trim_trailing_newlinesr  add_newline_to_filer  r  set_os_eol_charsformatting_enabled	is_pythonformat_eventloopformat_timerr$  r&  rn   quitsig_stop_operation_in_progressstopr  format_documentr  r  EnvironmentErrorr   Criticalr   r  rB  r.  )
rV   r   r"  save_new_filesosname_lookupr  r  r  rF  r  s
   `        @rW   rc  zEditorStack.save`  s   " ='')((*E		% %%'224##Uzz%..)%||%|00 --d6I6I''.((1D1D''.D$7$7$$U+## $+DFM"4#>#>?F!!!0*	##LL33LL**, $)<<#@#@ $||88**40$$,,-=-B-BC;;CC24;;CC %%';;CC$))+ ""5),,. &&(  & 
	%((lO 5 <<7(+E
44  !DK KK
	s    E#K 5K 	MA9MMc                     | j                   j                  |      }| j                  ||j                         | j	                  |      }|| j
                  j                  |j                  <   | j
                  j                  |j                         d|_        | j                  j                  |j                         t        |j                        j                         |_        | j                  j                  t!        t#        |             |j                  |j                         |j$                  j'                         j)                  d       | j+                  |       | j-                  |       |j$                  j/                          y )NFr  )r   r   r  r  r  r2  r^  r  r  encoding_changedr  r;   r   lastModifiedlastmodified
file_savedrB  rW  rh   r  setModifiedmodification_changedr'  notify_save)rV   r  r   	file_hashs       rW   r  zEditorStack._save_file  s   		&E5>>2%%e,	4=!!%..1**5>>:#""5>>2&u~~6CCE 	SD]"^^U^^	= 	++E2!!!.%(  "rY   c                     | j                  |      }|y| j                  |   }d|_        t        |      |_        t        |j                        j                         |_        y)a  
        File was just saved in another editorstack, let's synchronize!
        This avoids file being automatically reloaded.

        The original filename is passed instead of an index in case the tabs
        on the editor stacks were moved and are now in a different order - see
        spyder-ide/spyder#5703.
        Filename is passed in case file was just saved as another name.
        NF)r  r   r  r:   r  r   r  r  )rV   r  r  r   r  s        rW   file_saved_in_other_editorstackz+EditorStack.file_saved_in_other_editorstack  sY     !!"34=		% #'1&u~~6CCErY   c                    | j                   t               | _         | j                  t               | _        t	               rt               sd}d}n8| j                  }t        | j                   t        j                  |      d         }| j                  j                  d       t        | t        d      |||t        j                        \  }}| j                  j                  d       |rt        j                  |      S y)a  Select a name to save a file.

        Args:
            original_filename: Used in the dialog to display the current file
                    path and name.

        Returns:
            Normalized path for the selected file name or None if no name was
            selected.
        Nrz   rb   FrS  )filtersselectedfilterr	  T)r/  r#   r0  r$   r&   r'   r%   r  r  redirect_stdior  r   r   r   HideNameFilterDetailsnormpath)rV   r  r  r  r  
_selfilters         rW   select_savenamezEditorStack.select_savename  s     &"4"6D$ 0 2D
 KMGN''G'(;(;(+5F(G(JLN 	  '.tQ{^$5,33A,7,M,M	 O*
 	  &<<))rY   c                    || j                         }| j                  |   }|j                  }d|_        |j                  }| j	                  |      }|r| j                  |      }|!||k7  r| j                  |      sy||k  r|dz  }| j                  ||      }| j                  j                  t        t        |             ||       | j                  |d      }| j                  |       | j                  |       |S ||_        y)a  Save file as...

        Args:
            index: self.data index for the file to save.

        Returns:
            False if no file name was selected or if save() was unsuccessful.
            True is save() was successful.

        Gets the new file name from select_savename().  If no name is chosen,
        then the save_as() aborts.  Otherwise, the current stack is checked
        to see if the selected name already exists and, if so, then the tab
        with that name is closed.

        The current stack (self.data) and current tabs are updated with the
        new name and other file info.  The text is written with the new
        name using save() and the name change is propagated to the other stacks
        via the file_renamed_in_data signal.
        NTrb   )r  )r   r"  F)r  r   r  r  r  r  rm  r  file_renamed_in_datar  rB  rW  rc  r  r   )	rV   r   r  original_newly_createdr  r  ao_indexr  oks	            rW   r  zEditorStack.save_as  s   ( =((*E		% !&!4!4 #!NN''(9:((2H#E(9x0e#QJE++,=9A , CI %%**3r$x=+<hH $7BLL#  +I"8ErY   c           
      h   || j                         }| j                  |   }|j                  }| j                  |      }|rc| j	                  |      }|!||k7  r| j                  |      sy||k  r|dz  }	 | j                  ||       | j                  j                  |       yy# t        $ r}t        t        j                  t        d      t        d      t        j                  |j                        t        |      fz  |       | _        | j                   j#                          Y d}~yd}~ww xY w)a  Save copy of file as...

        Args:
            index: self.data index for the file to save.

        Returns:
            False if no file name was selected or if save() was unsuccessful.
            True is save() was successful.

        Gets the new file name from select_savename().  If no name is chosen,
        then the save_copy_as() aborts.  Otherwise, the current stack is
        checked to see if the selected name already exists and, if so, then the
        tab with that name is closed.

        Unlike save_as(), this calls write() directly instead of using save().
        The current file and tab aren't changed at all.  The copied file is
        opened in a new tab.
        Nrb   Tr  r  r  F)r  r   r  r  r  rm  r  rb  r  r  r   r  r   r  r  rB  r.  r  )rV   r   r  r  r  r  rF  s          rW   save_copy_aszEditorStack.save_copy_asK  s'   & =((*E		% !NN''(9:((2H#E(9x0e#QJE$##E84  %%h/  $ 	$)((lO 5 <<7(+E
44  ! !!##	$s   6-B% %	D1.A9D,,D1c                     d}t        | j                               D ]N  }| j                  |   j                  j	                         j                         s9|| j                  ||      z  }P |S )ziSave all opened files.

        Iterate through self.data and call save() on any modified files.
        T)r  )rH  r  r   rh   r  r  rc  )rV   r  	all_savedr   s       rW   rd  zEditorStack.save_all~  sk    
 	4//12 	MEyy&&//1<<>TYYu^YLL		M rY   c                 z    d| _         | j                  j                          | j                  j                          y r  )r   r#  r  r  rU   s    rW   start_stop_analysis_timerz%EditorStack.start_stop_analysis_timer  s.     %  "!!#rY   c                     | j                   ry|| j                         }| j                  rCt        | j                        |kD  r+| j                  |   }| j                  r|j                          d| _         y)z!Analyze current script for TODOs.NT)r   r  r   r  r   rH  rV   r   r  s      rW   r'  zEditorStack.analyze_script  sb      =((*E99TYY%/IIe$E$$%%' $rY   c                 h    | j                  |      }|y| j                  |   j                  |       y)z-Synchronize todo results between editorstacksN)r  r   r  )rV   r  r  r   s       rW   r  zEditorStack.set_todo_results  s1    !!(+=		%)),7rY   c                 j    | j                   r'| j                   | j                            j                  S y r   )r   r  r  rU   s    rW   get_todo_resultszEditorStack.get_todo_results  s,    9999T1134AAA rY   c                    | j                         }|dk7  r3|j                          t        j                  d|j                  z         n| j
                  j                          | j                  j                          | j                  j                          | j                  j                  |       	 t        j                  d|| j                  |   j                  j                  fz         | j                  j                          | j                  j!                  |d       | j                  j#                          | j                  j%                          |Y	 |j'                         \  }}| j(                  j                  | j                  |   j                  |j+                  d      ||       yy# t        $ r Y w xY w# t        $ r Y yw xY w)zStack index has changedrR   zSet focus to: %szCurrent changed: %d - %sFr  Nr  )r  r  loggerdebugr  reset_statusbarr  rX  ri   r  r>  r   rh   r   r[  r   rN  highlight_matchesupdate_matchesr  current_file_changedr  )rV   r   rh   r  r  s        rW   r   zEditorStack.current_changed  s   ((*B;OOLL+foo=>  %%'&&++-""$,,U3
	LL35!1!8!8!A!ABC D
 	  %%' 	##FE#: 	**,'')"99;	c))..tyy/?/H/H/5/B/B8/L/3S:   		*  s%   3;F5 AG 5	G G	GGc                 @    	 | j                   d   S # t        $ r Y yw xY w)z4Return the penultimate element of the stack history.N)ri   r   rU   s    rW   rO  z$EditorStack._get_previous_file_index  s*    	%%b)) 		s    	c                     t        | | j                  | j                        | _        | j                  j	                          | j                  j                  |rdnd       | j                  j                          y)a  
        Tab navigation with "most recently used" behaviour.

        It's fired when pressing 'go to previous file' or 'go to next file'
        shortcuts.

        forward:
            True: move to next file
            False: move to previous file
        rb   rR   N)rM   ri   rj   r   r  rT   r  )rV   rM  s     rW   rN  zEditorStack.tab_navigation_mru  s^     /tT5G5G/3yy:!%%7a;##%rY   c                 V   t        j                         }| j                  D ]l  }||j                  u s|j                  j                  r| j
                  j                          n| j
                  j                          | j                          n | j                  j                          y)zEditor focus has changedN)r   focusWidgetr   rh   operation_in_progressr  r  r  r  r(  r  )rV   fwidgetr  s      rW   focus_changedzEditorStack.focus_changed  sy    **,YY 	E%,,&<<55LL&&(LL%%'	 	!!&&(rY   c                    | j                   }|y|| j                         }| j                  rt        | j                        |kD  rn| j                  |   }|j	                  d       |j                  |j                  j                  ||       || j                         k7  r| j                  d       y| j                          y)zRefresh outline explorer panelNT)updater  Fr  )
r   r  r   r  r  set_current_editorrh   r  _refresh_outlineexplorer _sync_outlineexplorer_file_order)rV   r   r  r  oer  s         rW   r  z$EditorStack._refresh_outlineexplorer  s    !!:=((*E99TYY%/IIe$EMM$!!%,,"7"7)/u " >,,.. --U-;--/rY   c                     | j                   V| j                   j                  j                  | j                  D cg c]  }|j                  j                          c}       yyc c}w )zx
        Order the root file items of the outline explorer as in the tabbar
        of the current EditorStack.
        N)r   
treewidgetset_editor_ids_orderr   rh   get_document_idr  s     rW   r  z,EditorStack._sync_outlineexplorer_file_order	  sR    
 +  ++@@=AYYGE--/GI ,Gs   !A$c                 *   | j                   rt        | j                         |kD  rn| j                   |   }| j                  j                  |j                         |j
                  j                         \  }}| j                  j                  ||       yyy)zRefreshing statusbar widgetsN)r   r  r  r  r;   rh   r  "sig_editor_cursor_position_changed)rV   r   r  r  s       rW   __refresh_statusbarzEditorStack.__refresh_statusbar	  sq    99TYY%/IIe$E!!&&u~~6,,==?KD%3388uE 09rY   c                 B   | j                   rt        | j                         |kD  r| j                   |   }t        |j                        j	                          }t        j                  |j                        sd}nWt        j                  dk(  rD	 t        j                  |j                  t        j                        }t        j                  |       |j                  j                  |       | j                   j#                  |       y y y # t        t        f$ r d}Y Lw xY w)NFr  T)r   r  r   r  
isWritabler  r  osr^   openO_RDWRr   IOErrorr9  rh   setReadOnlyreadonly_changedr  )rV   r   r  	read_onlyfds        rW   __refresh_readonlyzEditorStack.__refresh_readonly	  s    99TYY%/IIe$E%enn5@@BBI::enn-!	D% ;BHHRL LL$$Y/!!&&y1! 09  ) % $I%s   AD
 
DDc                    | j                   ryd| _         t        | j                        |k  r| j                         }| j                  |   }t	        j
                  |j                        }|j                  r		 d| _         yt	        j                  |j                        st        t        j                  | j                  t        d      |z  t        j                  t        j                  z  |       | _        | j                  j!                         }|t        j                  k(  r| j#                  |d       d| _         yd|_        |j$                  j'                         j)                  d       | j+                  |       d| _         yt-        |j                        j/                         }t1        |j3                               t1        |j4                  j3                               k7  r	 |j$                  j'                         j7                         rt        t        j8                  | j                  t        d      j;                  |      t        j                  t        j                  z  |       | _        | j                  j!                         }|t        j                  k(  r| j=                  |       n||_        n| j=                  |       d| _         yd| _         y# t>        $ r t        t        j                  | j                  t        d      j;                  |      t        j@                  |       | _        | j                  j!                          | j#                  |d       Y d| _         yw xY w)	z
        Check if file has been changed in any way outside Spyder.

        Notes
        -----
        Possible ways are:
        * The file was removed, moved or renamed outside Spyder.
        * The file was modified outside Spyder.
        NTzThe file <b>%s</b> is unavailable.<br><br>It may have been removed, moved or renamed outside Spyder.<br><br>Do you want to close it?r!  r  zoThe file <b>{}</b> has been modified outside Spyder.<br><br>Do you want to reload it and lose all your changes?z~The file <b>{}</b> has been modified outside Spyder but it was not possible to reload it.<br><br>Therefore, it will be closed.F)!r   r  r   r  r  r  r  r  r  r   r>  r   r   r  r  r.  r  rm  rh   r  r  r  r   r  rB  r  r  r  r  formatreload	ExceptionrD  )rV   r   r  r^   r  lastms         rW   __check_file_statuszEditorStack.__check_file_status0	  s    "" "&tyy>U"((*E		% ||ENN+ D #(C ENN+%##

 - . 15	5
 +..0
DK [[&&(F(T2b #(_ '+#%%'33D9)))6Z #(U enn-::<E5>>#$E,>,>,G,G,I(JJ
!7||,,.99;&1'00 JJ ) * +1&,'OOknn< 
' "&!2!2!4![__4 KK.16E.E*  #(% ! 7"-#++

 : ; <B6$<#	#DK KK%%'OOEO6 #(7s   )C#K BM.-M.c                     t        | j                        D ]?  \  }}|j                  j                         j	                         }| j                  ||       A y r   )r:  r   rh   r  r  r  )rV   r   r  r*  s       rW   __modify_stack_titlez EditorStack.__modify_stack_title	  sI    %dii0 	/LE5LL))+668E  .	/rY   c                 \   t         j                  d       || j                         }| j                         r| j                         }| j                  |   }|j
                  }|j                          | j                  |d       | j                  j                          | j                  |       | j                  |       | j                  |       | j                          | j                  j                          nd}| j                          | j                   j#                  |d       y)zRefresh tabwidgetzRefresh EditorStackNFr  r  )r  r  r  r  r   rh   r  r  rY  r  _EditorStack__refresh_statusbar_EditorStack__refresh_readonly_EditorStack__check_file_statusr_  r[  r  r   rN  )rV   r   r  rh   s       rW   r  zEditorStack.refresh	  s    *+=((*E !((*EIIe$E\\FOO))%)>11668$$U+##E*$$U+%%'$$))+F 	!!# 	##FE#:rY   c                    |7t        | j                        D ]  \  }}t        |j                        |k(  s n | j                  j                          || j                         }|dk(  ry| j                  |   }|6|j                  j                         j                         xs |j                  }| j                  ||       | j                  j                  |       | j                  j                          |j                  j                         }| j                  |       | j                   j#                          y)z
        Current editor's modification state has changed
        --> change tab title depending on new modification state
        --> enable/disable save/save all actions
        NrR   )r:  r   rW  rh   rX  r  r  r  r  r  r  r   r  refresh_save_all_actionget_line_separatorrefresh_eol_charsri   r  )rV   r*  r   	editor_id_finfor  	eol_charss          rW   r  z EditorStack.modification_changed	  s     !*499!5 vfmm$	1 	&&++- =((*EB;		% =LL))+668OE<O<OEUE* 	##E*$$))+ LL335	y)""$rY   c                 d    t        j                  |      }| j                  j                  |       y r   )r<   get_os_name_from_eol_charssig_refresh_eol_charsr  )rV   r  os_names      rW   r  zEditorStack.refresh_eol_chars	  s&    77	B""''0rY   c                    | j                   |   }t        j                  dj                  |j                               t        j                  |j                        \  }|_        t        |j                        j                         |_	        |j                  j                  d      }|j                  j                  |       |j                  j                         j                  d       t        |      | j                   j"                  |j                  <   |j                  j%                  |       |j                  j'                          y)zReload file from disk.zReloading {}r  FN)r   r  r  r  r  r;   readr   r  r  rh   r  set_textr  r  r  r2  r^  set_cursor_positionrehighlight)rV   r   r  r  r  s        rW   r  zEditorStack.reload	  s    		% ^**5>>:;&mmENN;U^&u~~6CCE<<,,X6c"++E248I!!%..1((2 	  "rY   c           	         | j                         }| j                  |   }t        j                  dj	                  |j
                               |j
                  }|j                  j                         j                         rt        t        j                  | j                  t        d      t        j                  |      z  t        j                  t        j                   z  |       | _        | j"                  j%                         }|t        j                  k7  ry	 | j'                  |       y# t(        $ rQ t        j*                  | t        d      t        d      t        j                  |      z  t        j,                         Y yw xY w)zRevert file from disk.zReverting {}zRAll changes to file <b>%s</b> will be lost.<br>Do you want to revert it from disk?NErrorz=File <b>%s</b> is not saved on disk, so it can't be reverted.)r  r   r  r  r  r  rh   r  r  r   r>  r   r   r  r  r  r  r.  r  r  rA  criticalrD  )rV   r   r  r  r  s        rW   revertzEditorStack.revert	  s*   $$&		% ^**5>>:;>><<  "--/%##

 8 9,,x() +..0DK [[&&(F(
		KK  	  '
  !$h!78	s   D- -AFFc                     t        j                         j                  j                   fd       t	        ||| j
                        } j                  |||       |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   fd       |j                  j                   fd       j                  j                   j                         j                   j                   j"                         j$                  j                   j&                         j(                  j                   j*                         j,                  j                   j.                         j0                  j                   j2                         j4                  j                   j6                         j8                  j                   j8                         j:                  j                   j:                         j<                  j                   j>                         j@                  j                   j@                         jB                  j                   jD                         tG        ||      }	 jH                  d4i d jJ                  d jL                  d jN                  d jP                  d jR                  d	 jT                  d
|	d jW                         d jX                  d jZ                  d j\                  d j^                  d j`                  d jb                  d jd                  d jf                  d jh                  d jj                  d jl                  d jn                  d jp                  d jr                  d jt                  d jv                  d jx                  d jz                  d j|                  d j~                  d  j                  d! j                  d"|d#|d$ j                  d% j                  d& j                  d' j                  d( j                  d) j                  d* j                   |0j                  |       j                         j                  d+       |j                  j                   fd,       j                  j                   j                         j                  j                   j                          j                  D ]  \  }
}}}  j                  |
g|d-|i| !  fd.}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                   fd0       j                  j                   j                         j                  j                   j                          j                  j                          j                  j                           j                   j                  j                  |      1       t        j                        _k         j                  % j                  j                  j                         ||j                  j                  j                  j                  j                         |j                  j                  j                  j                         |j                  j                  j                  j                  j                         |j                          j                          j                  j                  d2} j                  j                  |        j                         d3k(  r j                  d3       |S )5zw
        Create a new editor instance
        Returns finfo object (instead of editor as in previous releases)
        c                 >    j                   j                  | ||      S r   )sig_go_to_definitionr  )r  r  columnrV   s      rW   rX   z/EditorStack.create_new_editor.<locals>.<lambda>
  s    (A(A(F(FtV)% rY   c                 >    j                   j                  | ||      S r   )	edit_gotor  )r  linenor^   rV   s      rW   rX   z/EditorStack.create_new_editor.<locals>.<lambda>"
  s     $ 3 3E64 H rY   c                 <    j                   j                  | |      S r   )sig_save_bookmarksr  )s1s2rV   s     rW   rX   z/EditorStack.create_new_editor.<locals>.<lambda>$
  s    )-)@)@)E)Eb")M rY   r>  show_blanksunderline_errorsscroll_past_endrS  edge_line_columnsr  r?  rn  r"  wraptab_mode
strip_modeintelligent_backspaceautomatic_completions!automatic_completions_after_charscode_snippetscompletions_hintr  hover_hintsru  rv  occurrence_highlightingoccurrence_timeoutclose_parenthesesclose_quotes
add_colonsauto_unindentr   r   r  r  r  r  foldingr  r  r  r  Fc                 <    j                   j                  | |      S r   )text_changed_atr  )r  r  rV   s     rW   rX   z/EditorStack.create_new_editor.<locals>.<lambda>b
  s      %%eX6 rY   r  c                 @    j                   j                  | ||       y r   )sig_perform_completion_requestr  )langmethodparamsrV   s      rW   perform_completion_requestzAEditorStack.create_new_editor.<locals>.perform_completion_requestm
  s    //44T66JrY   c                 <    j                  | t                    S )N)r  )r  rW  )r*  rh   rV   s    rW   rX   z/EditorStack.create_new_editor.<locals>.<lambda>u
  s     $33F 4 - rY   c                 &    j                  |       S r   )r  )r  rV   s    rW   rX   z/EditorStack.create_new_editor.<locals>.<lambda>|
  s    d44Y? rY   r  r  r   r   )yr+   
CodeEditorgo_to_definitionrn   r-   r   r  sig_send_to_helpr&  sig_show_object_inforZ  todo_results_changedr%  r(  sig_run_selectionr^  sig_run_to_liner_  sig_run_from_liner`  sig_run_cellrn  sig_debug_cellro  sig_run_cell_and_advancerp  sig_re_run_last_cellrq  ra  sig_breakpoints_savedsig_process_code_analysisrY  sig_refresh_formattingsig_save_requestedrc  r)   setup_editorr   r   r  r   r   r   rB  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@  sig_cursor_position_changededitor_cursor_position_changedtextChangedr  r   register_panelrB  sig_start_operation_in_progressr  r  r  r  modificationChangedfocus_inr  rj  rk  rl  sig_eol_chars_changedri  rh  r   rN  rZ  r  r  r   r   r7   r  r  r   register_editor!sig_outline_explorer_data_changedupdate_outline_info_update_classfuncdropdownsig_start_outline_spinneremit_request_in_progressdocument_did_changer  r  r  r  r   )rV   r  r  r  r  r  r  r  r  r  panel_classargskwargsr  rF  r	  rh   s   `               @rW   r  zEditorStack.create_new_editor
  s    &&t,''%	& VS$2D2DEY7&&t'8'89""**4+F+FG""**4+D+DE !I 	J  (( *N 	O  ((););<&&t'7'78  ((););<##DMM2%%doo6''//0I0IJ##++D,A,AB##D$5$56$$,,T-G-GH((0011	3%%--d.I.IJ!!))$))4$UC0 (	
00(	
++(	
 "::(	
 !66	(	

 ++(	
 #33(	
 (	
 $$&(	
 ""(	
 **(	
 ""(	
 ))(	
 --(	
 #'"D"D(	
 #'"D"D(	
  /3.M.M!(	
" 44#(	
$ "::%(	
& '+&D&D'(	
( 00)(	
* $(#F#F+(	
, $(#F#F-(	
. %)$H$H/(	
0  $CC1(	
2 #<<3(	
4 225(	
6 ..7(	
8 449(	
: **;(	
< #'"<"<=(	
> $?(	
@ A(	
B &*%B%BC(	
D ,,E(	
F --G(	
H $(#E#EI(	
J &*%B%BK(	
L ((M(	
N  ..O(	
T OOC OO))%0%%7	8 	**22//	1""4#A#AB 483G3G 	A/KvxDA"A-5A9?A	A	K 	--55&	(..66t||7I7IJ--55dll6G6GH""**-	. 	 2 23t||,.!!$//2$$,,?	A&&t';';<&&t';';<##F+++002!!		(>!? 5VV__M+  00A"   BBJJ335  BBJJ002  ::BB88:
 ++- 	'') 

 	(!Q&  #rY   c                 <    | j                   j                  ||       y)z=Cursor position of one of the editor in the stack has changedN)r  r  )rV   r  r   s      rW   r[  z*EditorStack.editor_cursor_position_changed
  s    //44T5ArY   c                    |s| j                   sy| j                         }|j                  j                         }t	        |      }t        j                  d|      }|j                  d      }|d   }dj                  |dd       }d}	d|v r|dk(  r||j                  d      d }	n|}d||	d|||j                  d	}
| j                  j                  |
       y)
z>qstr1: obj_text, qstr2: argpspec, qstr3: note, qstr4: doc_textNNFKDz

r   rb   rz   (python)obj_textr^   argspecnote	docstringforce_refreshr3  )r  r  r  r   r:   unicodedata	normalizer   joinfindr  sig_help_requestedr  )rV   r^   	signaturer"  rh   r  parts
definitiondocumentationrj  docs              rW   r&  zEditorStack.send_to_help
  s     T..((*??((*"9-	))&)<	'1X
E!"I.*X!5jooc234D%M &"OO
 	$$S)rY   c                 "   | j                  |||dd      }|j                  j                  d       |s)|j                  j                  t        j
                         |r0d|_        |j                  j                         j                  d       |S )z@
        Create new filename with *encoding* and *text*
        FT)r  r  eof)	r  rh   r  insert_textr  linesepr  r  r  )rV   r  r;   r   default_contentemptyr  s          rW   r  zEditorStack.new
  sz    
 &&x438d ' D((/LL$$RZZ0 EMLL!!#//6rY   c                    t        j                  t        |            }|r'| j                  j	                  t        d      |z         	 t        j                  |      \  }}t        |      | j                  j                  |<   | j                  |||||      }| j                  j                  |      }|r| j                  j	                  d       | j!                         r| j"                  rt%        j&                  |      rt        j(                  |      }	t+        t*        j,                  | j.                  t        d      |	z  t*        j0                  |       | _        | j2                  j5                          | j7                  |       d| _        | j;                  |       |j<                  j?                          |j<                  jA                          | jB                  r|j<                  jE                          |S # t        $ r Y yw xY w)z
        Load filename, create an editor instance and return it.

        This also sets the hash of the loaded file in the autosave component.
        zLoading %s...N)r  rz   zW<b>%s</b> contains mixed end-of-line characters.<br>Spyder will fix this automatically.F)#r  abspathr:   starting_long_processr  r   r;   r  r  r  r2  r^  r  r   r   ending_long_processr   r  r<   has_mixed_eol_charsr  r   r>  r   rD  r.  r  r  r   r'  rh   $set_sync_symbols_and_folding_timeoutrr  r  ru  )
rV   r  r  r  processeventsr   r  r  r   r^   s
             rW   loadzEditorStack.load
  s    ;;~h78&&++Ao,>,IJ
	 h/ID#
 /34j!!(+ &&xdK1: ' <		&$$))"- NN!;!;..t4<<)D%##

 8 9;?@DK KK!!%( !&E" 	99;
 	--/..LL//1[  		s   	G< <	HHc                    |.t         j                  dk(  rd}nt        j                  dk(  rd}nd}|| j	                         }| j
                  |   }t        j                  |      }t        j                  d| d|j                          |j                  j                  |       |j                  j                         j                  d	       y)
z
        Sets the EOL character(s) based on the operating system.

        If `osname` is None, then the default line endings for the current
        operating system will be used.

        `osname` can be one of: 'posix', 'nt', 'mac'.
        Nr  r   r  r  zSet OS eol chars z
 for file )r  T)r  r^   r   r   r  r   r<   get_eol_chars_from_os_namer  r  r  rh   set_eol_charsr  r  )rV   r   r  r  r  s        rW   r  zEditorStack.set_os_eol_chars  s     >ww$) =((*E		% 99&A	(:enn=MNO""Y"7++D1rY   c                     || j                         }| j                  |   }t        j                  d|j                          |j
                  j                          y)zRemove trailing spacesNz Remove trailing spaces for file )r  r   r  r  r  rh   trim_trailing_spacesr  s      rW   r  z"EditorStack.remove_trailing_spaces3  sL    =((*E		% 77GHI))+rY   c                     || j                         }| j                  |   }t        j                  d|j                          |j
                  j                          y )Nz!Trim trailing new lines for file )r  r   r  r  r  rh   r  r  s      rW   r  z"EditorStack.trim_trailing_newlines;  sL    =((*E		% 88HIJ++-rY   c                     || j                         }| j                  |   }t        j                  d|j                          |j
                  j                          y )NzAdd new line to file )r  r   r  r  r  rh   r  r  s      rW   r  zEditorStack.add_newline_to_fileB  sL    =((*E		% ,U^^,<=>((*rY   c                     || j                         }| j                  |   }t        j                  d|j                          |j
                  j                          y)z Replace tab characters by spacesNzFix indentation for file )r  r   r  r  r  rh   fix_indentationr  s      rW   r  zEditorStack.fix_indentationI  sL    =((*E		% 00@AB$$&rY   c                     || j                         }| j                  |   }t        j                  d|j                          |j
                  j                          y )NzRun formatting in file )r  r   r  r  r  rh   format_document_or_ranger  s      rW   format_document_or_selectionz(EditorStack.format_document_or_selectionQ  sL    =((*E		% .u~~.>?@--/rY   c                    | j                         }|j                         }|j                  t        j                         |dk(  r/|j                  t        j
                  t        j                         n3|dk(  r.|j                  t        j                  t        j                         |j                  |      }|r5| j                  j                  |j                         | j                         yy)z8 Select and run all lines from cursor in given directionupdownN)r  
textCursormovePositionr   StartOfLineStart
KeepAnchorEnd get_selection_as_executable_codeexec_in_extconsoler  rstripr  )rV   rJ  rh   r  	code_texts        rW   _run_lines_cursorzEditorStack._run_lines_cursorY  s    ((* ""$K334 1 1;3I3IJ& 1G1GH;;FC	##(()9)9);)-)=)=? rY   c                 (    | j                  d       y)zb
        Run all lines from the beginning up to, but not including, current
        line.
        r  rJ  Nr  rU   s    rW   r_  zEditorStack.run_to_linel  s    
 	.rY   c                 (    | j                  d       y)zg
        Run all lines from and including the current line to the end of
        the document.
        r  r  Nr  rU   s    rW   r`  zEditorStack.run_from_lines  s    
 	0rY   c                    | j                         j                         }|r5| j                  j                  |j	                         | j
                         y| j                         }|j                         }|j                         }|r&| j                  j                  || j
                         |j                         r!|r|j                  |j                                | j
                  r|j                  dd       yy)a  
        Run selected text or current line in console.

        If some text is selected, then execute that text in console.

        If no text is selected, then execute current line, unless current line
        is empty. Then, advance cursor to next line. If cursor is on last line
        and that line is not empty, then add a new blank line and move the
        cursor there. If cursor is on last line and that line is empty, then do
        not move cursor.
        Nr  r  )r  r  r  r  r  r  get_current_linelstripis_cursor_on_last_lineappendr  move_cursor_to_next)rV   r   rh   r  s       rW   r^  zEditorStack.run_selectionz  s     &&(IIK##((8L8LM((*&&({{}##((t/C/CD((*tMM&3356&&vv6  rY   c                     | j                         j                         \  }}| j                         }| j                         }t        |      }|j                  }| j                  ||||f|       y)zRun current cell.N)r  get_cell_as_executable_coder  r8   r  _run_cell_text)rV   r  r   blockr  rh   r^   r  s           rW   rn  zEditorStack.run_cell  se    --/KKMe&&(((*>>D&8T*:EBrY   c                 (    | j                  d       y)zDebug current cell.T)r  N)rn  rU   s    rW   ro  zEditorStack.debug_cell  s    D!rY   c                 D    | j                          | j                          y)z,Run current cell and advance to the next oneN)rn  rV  rU   s    rW   rp  z EditorStack.run_cell_and_advance  s    rY   c                     |s| j                         j                  }n| j                         j                  } |        y)zSAdvance to the next cell.

        reverse = True --> go to previous cell.
        N)r  r  r  )rV   rU  	move_funcs      rW   rV  zEditorStack.advance_cell  s4    
 //1AAI//1EEIrY   c                    | j                   y| j                   \  }}| j                  |      }|y| j                  |   j                  }	 |j	                  |      }| j                  ||||f       y# t
        $ r Y yw xY w)zRun the previous cell again.N)r3  r  r   rh   get_cell_codeRuntimeErrorr  )rV   r  r8   r   rh   r   s         rW   rq  zEditorStack.re_run_last_cell  s    &"11)!!(+=5!((	''	2D 	D&8Y*?@  		s   A2 2	A>=A>c                     |\  }}|j                         rQ|||| j                  | j                  f}|r | j                  j                  |  y | j
                  j                  |  yy)a  Run cell code in the console.

        Cell code is run in the console by copying it to the console if
        `self.run_cell_copy` is ``True`` otherwise by using the `run_cell`
        function.

        Parameters
        ----------
        text : str
            The code in the cell as a string.
        line : int
            The starting line number of the cell in the file.
        N)is_python_or_ipythonr  r  debug_cell_in_ipyclientr  run_cell_in_ipyclient)rV   r   rh   cell_idr  r  r8   rj  s           rW   r  zEditorStack._run_cell_text  sm     !(9&&()Xt/A/A((*D1,,1148/**//6 )rY   c                    t         j                  d       |j                         }|j                         }|j	                         }|j                         }t        |      }t         j                  dj                  |             t         j                  dj                  |             t         j                  dj                  |             t         j                  dj                  |             |r|r~|r||D cg c]  }t        j                  |       }}t         j                  dj                  t        |                   t        |      r|j                          y
|j                          y
|j	                         r|j                          y
t        j                  dk(  r&t         j                  d       |j                          y
t         j                  d	       |j                          y
c c}w )zn
        Reimplemented Qt method.

        Inform Qt about the types of data that the widget accepts.
        zdragEnterEvent was receivedzDrag event source has_urls: {}zDrag event source urls: {}zDrag event source all_urls: {}zDrag event source has_text: {}zAccept proposed action?: {}r  z!Accept proposed action on WindowszIgnore drag eventN)r  r  mimeDatahasUrlshasTexturlsrD   r  r;   is_text_fileanyacceptProposedActionr   r  r^   )	rV   r   sourcehas_urlshas_textr  all_urlsurlr   s	            rW   dragEnterEventzEditorStack.dragEnterEvent  sa    	23! >>#>>#{{}'5<<XFG188>?5<<XFG5<<XFG:BC3H))#.CDCLL6==c$iHI4y**,^^&&(WW_
 LL<=&&(LL,-LLN# Ds   ;G3c                    t         j                  d       |j                         }|j                         rmt	        |      rbt	        |      }|D cg c]  }t        j                  |      s| }}t        |xs g       }|D ]  }| j                  j                  |        nR|j                         r2| j                         }|0|j                  |j                                n|j                          |j                          yc c}w )zT
        Reimplement Qt method.

        Unpack dropped data and handle it.
        zdropEvent was receivedN)r  r  r  r  rD   r;   r  setrb  r  r  r  r  r   r   r  )rV   r   r  filesfr  rh   s          rW   	dropEventzEditorStack.dropEvent  s     	-.! >>V 4 (E %B1)>)>q)AQBEB$E -  %%e,-^^,,.F!""6;;=1LLN""$ Cs   D+Dr  c                &   ||||f| j                   vr| j                   j                  ||||f       | j                  D ]Q  }|j                  j                  j                   ||i ||      }|j                         rA|j                  d       S y)z$Register a panel in all codeeditors.r  TN)r   r  r   rh   panelsregisterr   r:  )rV   ri  r  rj  rk  r  	cur_panels          rW   r]  zEditorStack.register_panel  s     vx08L8LL  ''dFH(MNYY 	+E++44T,V,x 5 AI&&($$T*		+rY   r   )rz   )F)NN)rI  )Tr  )FN)NFTr  )NNN)FNrI  )FF)TrI  T)r   r   r   r   r  r@  r  rB  r  r   r  r  rW  r  r  r  r  objectr  r  r[  r(  rj  rk  rl  dictr  rV  r  r  rX  r  active_languages_statsrM  rY  rZ  r  rU  r@  r  rb  r%  rt  ru  ra  re  rg  rh  ri  rr  rs  r"  rB  sig_option_changedsig_save_bookmarksig_load_bookmarkr(  rz  rd   r   r4   r+  r  r   r  r  r)  r  rv  r  r  r  r   r   r  r  r]  r[  r\  r  rZ  r  r+  r-  r/  r1  r4  r6  r<  rF  rB  rK  rM  rO  rQ  rU  rY  r\  r^  r`  rb  rd  rf  ri  rk  ro  rq  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r   r*  r/  r  r   r4  r6  r  r  rA  rE  r  rm  rd  rg  rj  rf  r   r   r   rr  r]  r{  r}  rQ  r  r  rc  r  r  r  r  r  rd  r  r'  r  r  r   rO  rN  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^  rn  ro  rp  rV  rq  r  r  r  r   PositionLEFTr]  r   rY   rW   r   r      sX   hOd|c{)/S)9&"3K#D\"3K +D\NT*"3T4@$S&#tTB (!8hGxHJ4LMC%NS#&J!#sC0 &#C[!8'-x$%+X"$h"HS#&O!#sC5#$KsC%I!8#X3&"%L(KhOhOxx!#sC0%+Cd%;"V,ssS)2b#H 
V8 8 q4f2/-b74(
 
V3 3. 
V 
(,6 
V	#Y2  2: 
V1 1$4@0C* 
V	$Z?  ?" 
#t_7 7"!+'/"EN%
	0;7>:<=B=;><<":4&513A98AJ<?7:@=A??+?4A)
,
%#
=(5)!--H
J&8t0,AF.D/>E764/&) 
#s^ &RhF"32
#9+&(M^M^@#2F$$L8t1f	$

%8B)V&"
)0,IF2&\(|/
;:"%H1
#("H CH6;SjB 
#sD* *< =B :??B24,.+'0?&/174C"

A"70'R%4 !& 3 3	+rY   r   c                       e Zd ZdZ	 	 ddZd Zd Z e       d        Zd Z	e
j                  fdZd	 Zd
 ZddZed        Zy)EditorSplitterzQSplitter for editor windows.Nc                     t        j                   |        j                  t        j                          j                  d       d _        d _        | _        | j                  j                  }| _
        | j                  j                  }| _        | _        t         |       _         j                   j                         |s& j                  j!                   j                          j                  j"                  j%                   j&                          j                  j(                  j%                   fd        j                  j*                  j%                   fd        j-                   j                         t/               s) j                  j1                  |j3                                 j5                   j6                         y)a  Create a splitter for dividing an editor window into panels.

        Adds a new EditorStack instance to this splitter.  If it's not
        the first splitter, clones the current EditorStack from the plugin.

        Args:
            parent: Parent widget.
            plugin: Plugin this widget belongs to.
            menu_actions: QActions to include from the parent.
            first: Boolean if this is the first splitter in the editor.
            register_editorstack_cb: Callback to register the EditorStack.
                        Defaults to plugin.register_editorstack() to
                        register the EditorStack with the Editor plugin.
            unregister_editorstack_cb: Callback to unregister the EditorStack.
                        Defaults to plugin.unregister_editorstack() to
                        unregister the EditorStack with the Editor plugin.
        FN)editorstackc                  D     j                  t        j                        S N)r.  )r   r	   r-  rU   s   rW   rX   z)EditorSplitter.__init__.<locals>.<lambda>X  s    DJJ2;;J7 rY   c                  D     j                  t        j                        S r  )r   r	   r,  rU   s   rW   rX   z)EditorSplitter.__init__.<locals>.<lambda>Z  s    DJJ2==J9 rY   )r   rd   r   r	   r   setChildrenCollapsibletoolbar_list	menu_listr  register_editorstackregister_editorstack_cbunregister_editorstackunregister_editorstack_cbr   r   r  clone_editorstack	destroyedrn   editorstack_closedrt  ru  r  r    rq  get_color_schemer  _stylesheet)rV   r_   r  r   firstr  r  s   `      rW   rd   zEditorSplitter.__init__-  su   ( 	4("--.##E* "*&*kk&F&F#'>$$,(,(J(J%)B&(&t\:$$T%5%56KK))d6F6F)G""**4+B+BC--557	9//779	;t''(#%--f.E.E.GH4++,rY   c                 0    t        j                  | |       y)zOverride QWidget closeEvent().

        This event handler is called with the given event when Qt
        receives a window close request from a top-level widget.
        N)r   r  r   s     rW   r  zEditorSplitter.closeEventb  s     	T5)rY   c                 ^    | j                   j                         }||j                          y y r   )r  get_focus_widgetr  )rV   focus_widgets     rW    __give_focus_to_remaining_editorz/EditorSplitter.__give_focus_to_remaining_editorj  s+    {{335#!!# $rY   c                 
   t         j                  d       	 | j                  | j                         d | _        | j	                         dk(  }|r| j                          y | j                          y # t        t        f$ r Y y w xY w)NzClosing EditorStackrb   )	r  r  r  r  r   r   /_EditorSplitter__give_focus_to_remaining_editorr  AttributeErrorrV   close_splitters     rW   r  z!EditorSplitter.editorstack_closedo  st    *+	**4+;+;<#D!ZZ\Q.N

113n- 	 	s   AA0 A0 0BBc                 L   t         j                  d       	 | j                         dk(  xr | j                  d u }|r| j                          y | j                         dk(  r&| j                  r| j                  j                          | j                          y # t        $ r Y y w xY w)NzClosing EditorSplitterrb   r   )r  r  r   r  r  r   r*  r  r  s     rW   editorsplitter_closedz$EditorSplitter.editorsplitter_closed  s    -.	!ZZ\Q.K43C3Ct3KN JJLZZ\Q4#3#3 ..0--/  	 	s   #B 	B#"B#c                    t         j                  d       | j                  |       | j                  j	                  |       t        | j                         | j                  | j                  | j                  | j                        }| j                  |       |j                  j                  | j                         |j                  j                         }||j!                          yy)a  Create and attach a new EditorSplitter to the current EditorSplitter.

        The new EditorSplitter widget will contain an EditorStack that
        is a clone of the current EditorStack.

        A single EditorSplitter instance can be split multiple times, but the
        orientation will be the same for all the direct splits.  If one of
        the child splits is split, then that split can have a different
        orientation.
        zCreate a new EditorSplitterr  r  N)r  r  setOrientationr  r/  r  r_   r  r   r  r  r  r  rn   r  r  r  )rV   r.  editorsplittercurrent_editors       rW   r   zEditorSplitter.split  s     	23K(((5'KKMKK$($@$@&*&D&D
 	~&  (()C)CD'33FFH%##% &rY   c                     | j                  d      | j                         fg}| j                         dkD  r$| j                  d      }||j                         z  }|S )a6  Return the editor stacks for this splitter and every first child.

        Note: If a splitter contains more than one splitter as a direct
              child, only the first child's editor stack is included.

        Returns:
            List of tuples containing (EditorStack instance, orientation).
        r   rb   )rc  r.  r   iter_editorstacks)rV   editorstacksr  s      rW   r  z EditorSplitter.iter_editorstacks  sV     Q)9)9);<=::<!![[^NN<<>>LrY   c                    g }| j                         D ]}  \  }}g }d}d}t        |d      rA|j                  D cg c]  }|j                  j	                          }}|j                         }|j                  |t        j                  k(  ||f        t        t        | j                               | j                         |      S c c}w )az  Return the layout state for this splitter and its children.

        Record the current state, including file names and current line
        numbers, of the splitter panels.

        Returns:
            A dictionary containing keys {hexstate, sizes, splitsettings}.
                hexstate: String of saveState() for self.
                sizes: List for size() for self.
                splitsettings: List of tuples of the form
                       (orientation, cfname, clines) for each EditorSplitter
                       and its EditorStack.
                           orientation: orientation() for the editor
                                 splitter (which may be a child of self).
                           cfname: EditorStack current file name.
                           clines: Current line number for each file in the
                               EditorStack.
        rz   Fr   )hexstatesizessplitsettings)r  r  r   rh   get_cursor_line_numberr   r  r	   r-  r  r9   	saveStater  )rV   r  r  r.  clinescfnamer  s          rW   get_layout_settingsz"EditorSplitter.get_layout_settings  s    & (,(>(>(@ 		O$KFFK{F+'2'7'79#  ,,==? 9 9$99;  +"<ff!MN		O .t~~/?@**,mE 	E	9s   !Cc                    |j                  d      }|y| }d}t        |      D ]  \  }\  }}}	|dkD  rB|j                  |rt        j                  nt        j
                         |j                  d      }|j                  d      }
t        |
j                        D ])  \  }}|j                  }|	 |j                  |	|          +  |j                  d      }|@| j                  t               j                  t        |      j                  d                   |j                  d      }|| j!                  |       |!|j#                          |j%                          yy# t        $ r Y w xY w)a  Restore layout state for the splitter panels.

        Apply the settings to restore a saved layout within the editor.  If
        the splitsettings key doesn't exist, then return without restoring
        any settings.

        The current EditorSplitter (self) calls split() for each element
        in split_settings, thus recreating the splitter panels from the saved
        state.  split() also clones the editorstack, which is then
        iterated over to restore the saved line numbers on each file.

        The size and positioning of each splitter panel is restored from
        hexstate.

        Args:
            settings: A dictionary with keys {hexstate, sizes, orientation}
                    that define the layout for the EditorSplitter panels.
            dont_goto: Defaults to None, which positions the cursor to the
                    end of the editor.  If there's a value, positions the
                    cursor on the saved line number for each editor.
        r  Nr   rb   r  utf-8r  )rr   r:  r   r	   r-  r,  rc  r   rh   r]  r   restoreStater   fromHexrB  encodesetSizes
clearFocusr  )rV   settings	dont_gotor  splitterrh   rK  is_verticalr  r  r  jr  r  r  s                  rW   set_layout_settingsz"EditorSplitter.set_layout_settings  sc   , !_5 09-0H 	,A,VV1ukr{{r}}M#??1-"//!,K%k&6&67 5 ())&)4	$ <<
+z|33M((1 3 5W%MM% OO  & s   1E$$	E0/E0c                     t         j                  j                         }|j                  j	                  t
        j                         |j                         S )N)
background)r  r  r  r   r  r?   COLOR_BACKGROUND_1r  )rV   r  s     rW   r  zEditorSplitter._stylesheet  sB    oo((*$77 	  	
 ||~rY   )FNNr   )r   r   r   r   rd   r  r  r   r  r  r	   r-  r   r  r  r  propertyr  r   rY   rW   r  r  *  sj    ';@IM3-j*$
 
V "0( !# &6EB6p  rY   r  c                   P    e Zd ZdZd Zd Zd Zd Zd Z e	e
      d        Zd Zy	)
EditorWidgetrh   c                     t        j                   |        j                  t        j                         |j                         }t                _        t                _	        t                _        t                _        t                _        |j!                  d j                         |j!                  d j                         |j!                  d j                         |j!                  d j                         |j!                  d j                         g  _         _        t'         d       _         j$                  j+                   j(                          j(                  j-                          d  _        |7t1        d| dt3        t5                             _         j.                  j7                           j.                  j9                           j.                  j;                           j.                  j=                           j.                  j?                         }dD ]  }|jA                  |         j.                  jB                  jE                   fd       |jG                         D ]  } j.                  jI                  |         j.                  jK                  d       tM               }	tO               }
|
jQ                  d       |
jS                  dddd       |	jU                  |
       tW         | jX                   jZ                  	       _.        |
j_                   j\                         |
j_                   j(                         t                _0         j`                  jS                  dddd        j`                  j_                  |	       |% j`                  j_                   j.                          j`                  jc                  dd
        j`                  jc                  dd        j`                  jd                  jE                   jf                         y )Nr   Tenable_replaceoutline_explorereditor_window_)r]   )undock_paner  lock_unlock_positionc                 J    j                  | ||j                               S )N)rD  gotowordeditorwindow)r  r_   )rD  r.  r/  r  rV   s      rW   rX   z'EditorWidget.__init__.<locals>.<lambda>U  s(    id)-  8 rY   r     rb   )4r   rd   r   r	   r   	statusBarr3   
vcs_statusr/   cursorpos_statusr0   encoding_statusr1   
eol_statusr2   readwrite_statusinsertPermanentWidgetr	  r  rJ   r   register_widget_shortcutsr   r   r6   rB  rW  r  r  _setuprender_toolbarsget_options_menuremove_actionr%  rn   get_supported_languagesstart_symbol_serviceschange_tree_visibilityr   r   r  r   r   r  r  r  r  r  r  setStretchFactorsplitterMovedon_splitter_moved)rV   r_   r  r   outline_plugin	statusbaroptions_menuactionr  editor_widgetseditor_layouts   ` `        rW   rd   zEditorWidget.__init__$  sm   4("--.$$&	#D/ 4T :-d3#D/ / 5''4+@+@A''4??;''4+?+?@''4+@+@A''4??;&tDA--d.>.>?  $%#8"(RX8	$D    &&(  //1  '')  002  //@@BL3 3**623   **228 +BBD E$$::8DE   77= #  #((Aq!4  /,$($=$=&*&A&A
 	 3 34 0 01!$((Aq!4/%MM##D$8$89&&q!,&&q!,##++D,B,BCrY   c                 T   t         j                  d       | j                          | j                  j	                  |       || j
                  j                  | 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.                         |j0                  j                  | j&                  j2                         |j4                  j                  | j6                  j8                         | j
                  j;                  |       y )NzRegistering editorstackrb   )r  r  !_EditorWidget__print_editorstacksr	  r  r  last_focused_editorstackr_   r+  r  r1  r   r/  r   r  rn   r7  r   r5  r4  r  update_readonlyr  update_encodingr  update_cursor_positionr  r6  
update_eolr  rV   r  s     rW   r  z!EditorWidget.register_editorstacky  s   ./!!#  ->I,,T[[];  T%6%6!7!!;<''(<(<=##D$4$45##++D,A,A,F,FG##++D,@,@,E,EF##++D,A,A,F,FG$$,,!!11	3$$,,  00	266>>!!88	:))11$//2L2LM((5rY   c                     t         j                  t        | j                         d       | j                  D ]  }t         j                  d|         y )Nz  editorstack(s) in EditorWidget:r   )r  r  r  r	  rV   ess     rW   __print_editorstacksz!EditorWidget.__print_editorstacks  sN    4$$%&&FG	
 ## 	&BLL4t%	&rY   c                     t         j                  d       | j                  j                  |       | j                  j                  | j                  j                  |             | j                          y )NzUnregistering editorstack)r  r  r  r  r	  r  r   rK  rQ  s     rW   r  z#EditorWidget.unregister_editorstack  sR    01**;7d//55kBC!!#rY   c                 p    t         j                  d       | j                  D ]  }|j                           y )NzUnregistering all editorstacks)r  r  r	  r   rS  s     rW   unregister_all_editorstacksz(EditorWidget.unregister_all_editorstacks  s-    56## 	BHHJ	rY   c                     |t         j                  k(  r| j                  j                  d       y| j                  j                  d       y)zK
        Actions to take when the parent window state has changed.
        FTN)r	   WindowMinimizedr   r@  )rV   window_states     rW   on_window_state_changedz$EditorWidget.on_window_state_changed  s:     2---  77>  77=rY   c                     |dz   | j                         j                         kD  r| j                  j                  d       y| j                  j                  d       y)z+Actions to take when the splitter is moved.   FTN)rw   r   r   r@  )rV   r  r   s      rW   rC  zEditorWidget.on_splitter_moved  sG     rMTYY[..00  77>  77=rY   N)r   r   r   CONF_SECTIONrd   r  rK  r  rX  r   r  r\  rC  r   rY   rW   r%  r%  !  s@    LSDj6*&$
 
&\> >
>rY   r%  c                   b     e Zd Z ee      Z	 d
dZd Zd Zd Z	d Z
d Z fdZd Zd	 Z xZS )EditorMainWindowc                    t        j                  | |       | j                  t        j                         || _        d | _        t        | |||      | _        | j                  j                  | j                  j                         | j                  | j                         | j                  t        t                     | j                  j                   j"                  }|j%                         }||j'                          | j)                  d|j+                         z         | j-                  |j/                                g | _        |r|D ]~  \  }	}
}| j3                  |	      }|j5                  |
       |j                  t        t6                     |j9                  d       t;        ||       | j0                  j=                  |        g | _        |rtA        | tC        d      tE        jF                  d      tC        d      | jH                        }tK        |      D ]e  \  }\  }	}| jM                         jO                  |	      }|dk(  rt;        ||d |gz          nt;        ||       | j>                  j=                  |       g y y )NzSpyder - %sFr  r  zClose this windowr  r   )(r   rd   r   r	   r   r  window_sizer%  editorwidgetsig_window_state_changedrn   r\  setCentralWidgetr  rB  rG   r  r  r  r  setWindowTitlewindowTitlesetWindowIcon
windowIcontoolbars
addToolBarr  rH   r  r@   r  menusrA   r   r>   r   r   r:  menuBaraddMenu)rV   r  r   r  r  rD  r_   r  rh   r   object_namer4  toolbarquit_actionr   r   s                   rW   rd   zEditorMainWindow.__init__  s*    	T6*"--.(v|)79%%--55	7d//0 	3~./ ''66BB//1OOMF,>,>,@@A6,,.//; .+{G//%0%%k2%%c*@&AB""5)GW-$$W-. 
'a.?-0XXl-C,-.A,B26**>K ,5Y+? (''w||~--e4A:gt[.A&ABg.

!!$'( rY   c                     | j                   S )zGet the toolbars.)rk  rU   s    rW   get_toolbarszEditorMainWindow.get_toolbars  s    }}rY   c                    | j                   rt| j                   d   }|j                  d       || j                  k(  rD|rAg }| j                  D ]#  }|j                         }|j	                  |       % t        ||       yyyy)zAdd toolbars to a menu.   zcheckbox-paddingN)rm  r  rk  toggleViewActionr  r@   )rV   
menu_titler4  	view_menurk  rq  rG  s          rW   add_toolbars_to_menuz%EditorMainWindow.add_toolbars_to_menu  s     ::

1I##$67$--'I#}} ,G$557FOOF+, Ix0 -6' rY   c                 j   t        j                  ddg       }|ri }| j                  D ]E  }|||j                         <   |j	                         j                  d       |j                  d       G |D ]=  }||v s||   j	                         j                  d       ||   j                  d       ? yy)z3Loads the last visible toolbars from the .ini file.rO   last_visible_toolbars)r  FTN)r"   rr   rk  
objectNamerw  
setCheckedr:  )rV   toolbars_namesdicrq  r^   s        rW   load_toolbarszEditorMainWindow.load_toolbars  s    &*A2NC== *,3G&&()((*55e<""5)* ' /3;I..0;;DAI((./ rY   c                     | j                         s%| j                         s| j                         | _        t	        j
                  | |       y)Reimplement Qt methodN)isMaximizedisFullScreenrw   rc  r   resizeEventr   s     rW   r  zEditorMainWindow.resizeEvent  s7    !$*;*;*=#yy{De,rY   c                    | j                   j                          | j                  j                  T| j                  j                  j                  | j                         | j                  j                  j                  d       | j                  j                          t        j                  | |       | j                  j                  d| j                  _        yy)r  NT)
rd  rX  r  r"  
dockwidget	setWidgetr:  switch_to_pluginr   r  r   s     rW   r  zEditorMainWindow.closeEvent  s    557;;''3KK"",,T[[9KK""--d3$$&tU+;;''3+/DKK( 4rY   c                     |j                         t        j                  k(  r)| j                  j	                  | j                                t        |   |       y)z
        Override Qt method to emit a custom `sig_windowstate_changed` signal
        when there's a change in the window state.
        N)typer   WindowStateChangere  r  windowStatesuperchangeEvent)rV   r   	__class__s     rW   r  zEditorMainWindow.changeEvent!  sC    
 ::<6333))..t/?/?/ABE"rY   c           
         | j                   j                  j                         }t        | j                  j                         | j                  j                         f| j                         j                         | j                         j                         f| j                         | j                         t        | j                               |      S )zReturn layout state)rw   posis_maximizedis_fullscreenr  r  )rd  r  r  r  rc  r   r   r  xyr  r  r9   r  )rV   r  s     rW   r  z$EditorMainWindow.get_layout_settings*  s    ))88LLN$**002D4D4D4K4K4MN8!%!1!1!3"&"3"3"5.t~~/?@"/1 	1rY   c                    |j                  d      }|,| j                  t        |        | j                         | _        |j                  d      }|| j                  t        |        |j                  d      }|@| j                  t               j                  t        |      j                  d                   |j                  d      r| j                  t        j                         |j                  d      r| j                  t        j                         |j                  d      }|&| j                   j"                  j%                  |       yy)	zRestore layout staterw   Nr  r  r  r  r  r  )rr   rs   r   rw   rc  r   r   r  r   r  rB  r  setWindowStater	   WindowMaximizedWindowFullScreenrd  r  r  )rV   r  rw   r  r  r  s         rW   r  z$EditorMainWindow.set_layout_settings4  s   ||F#KK'#yy{Dll5!?IIvs|%<<
+z|33M((1 3 5<<' 2 23<<( 3 34 _5$,,@@O %rY   r   )r   r   r   r   r  re  rd   rt  rz  r  r  r  r  r  r  __classcell__)r  s   @rW   ra  ra    sA    %f~ )-3(j1/-	0#1PrY   ra  c                       e Zd Zd ZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Z eee      d        Z eeee      d        Z eeee      d        Zd Zd Zy)EditorPluginExamplec                    t        j                  |        d | _        d | _        d | _        d | _        d | _        g }g | _        g | _        i | _	        t        | d      | _        t        d | |       | _        | j                  j                  j                  | j                          t#        | | |d      | _        t'        |       }t)               }|j+                  d       |j-                  dddd       |j/                  |       |j1                  | j$                         |j1                  | j                         | j-                  dddd       | j1                  |       | j1                  | j                         | j3                  dd       | j3                  dd       || _        d | _        d | _        | j;                  g g        y )NTr'  )r  r   r1  rb   )r   rd   r#  r%  r&  r"  r$  r	  editorwindowsrL  rJ   r   r6   r   r%  rn   
go_to_filer  editor_splitterr   r   r  r   r   r  rA  r   r  r  setup_window)rV   r   rH  rI  s       rW   rd   zEditorPluginExample.__init__K  s   4  "$(! $#' (*%&tDA4T4F&&..t?-dD,48 : !#  #((Aq!4  / 4 45 0 011a+~&t++,a#a#( "b!rY   Nc                     | j                   d   }|j                  t        |             |j                         }|j	                  |||       y )Nr   )r/  start_column)r	  r  r:   r  r]  )rV   r  r&  r   r  r  rh   s          rW   r  zEditorPluginExample.go_to_filet  sH    ''*(()>?//1&t,GrY   c                 H   | j                   d d  D ]  }|j                           t        j                  dt	        | j                         | j                   fz         t        j                  dt	        | j
                        | j
                  fz         |j                          y )Nz%d: %r)r  r   r  r  r  r	  r   )rV   r   wins      rW   r  zEditorPluginExample.closeEventz  s|    %%a( 	CIIK	XT%7%7!8$:L:L MMNXT%6%6!79J9J KKLrY   c                     t        j                          | j                  d   }|j                  |       |j	                          y r1  )r   r\  r	  r  r'  )rV   r  r  s      rW   r  zEditorPluginExample.load  s8    ""$''*""$rY   c                 F   t         j                  d|z         | j                  j                  |       | j	                  |      r{|j                  t        | j                        dkD         |j                  | j                         |j                  | j                         t        |       }|j                  d|g       t        |       }|j                  ||||       t        d      }|j!                  d       |j#                  |d       |j$                  j'                  | j(                         |j*                  j'                  | j,                         |j.                  j'                  | j0                         |j2                  j'                  | j4                         y )Nz#FakePlugin.register_editorstack: %rrb   r1  zCourier Newrw  Spyder)r"  )r  r  r	  r  isAncestorOfr+  r  r1  r   r/  r   rB   r  r   r-  r   setPointSizero  rV  rn   close_file_in_all_editorstacksr  file_saved_in_editorstackr  #file_renamed_in_data_in_editorstackrb  r  )rV   r  oe_btnrG  rn  s        rW   r  z(EditorPluginExample.register_editorstack  sJ   :[HI  -[)$$S):):%;a%?@++D,@,@A''(8(89&t,F44a[A""6666B]#"$$T$A""**4+N+NO&&t'E'EF((00&*&N&N	P''		2rY   c                     t         j                  d|z         | j                  j                  | j                  j	                  |             y )Nz%FakePlugin.unregister_editorstack: %r)r  r  r	  r  r   rQ  s     rW   r  z*EditorPluginExample.unregister_editorstack  s9    <{JKd//55kBCrY   c                 @    |j                  | j                  d          y r1  )r  r	  rQ  s     rW   r  z%EditorPluginExample.clone_editorstack  s    t0034rY   c                      || _         || _        y r   )r  r  )rV   r  r  s      rW   r  z EditorPluginExample.setup_window  s    ("rY   c                 *    t          j                   j                   j                  ddddd	      j	                   j                                j                           j                         j                  j                   fd       y )NFT)show_fullpathshow_all_filesgroup_cellsshow_commentssort_files_alphabeticallyc                  &     j                        S r   )unregister_editorwindowrV   r!  s   rW   rX   z7EditorPluginExample.create_new_window.<locals>.<lambda>  s    )E)Ef)M rY   )
ra  r   r  r  rs   rw   r  register_editorwindowr  rn   r  s   `@rW   r  z%EditorPluginExample.create_new_window  st    !$(9(9"&"3"3T^^05e.2$<A	C
 	diik"""6*  !MNrY   c                 j    t         j                  d|z         | j                  j                  |       y )Nz!register_editorwindowQObject*: %r)r  r  r  r  r  s     rW   r  z)EditorPluginExample.register_editorwindow  s(    86AB!!&)rY   c                     t         j                  d|z         | j                  j                  | j                  j	                  |             y )Nzunregister_editorwindow: %r)r  r  r  r  r   r  s     rW   r  z+EditorPluginExample.unregister_editorwindow  s9    2V;<t1177?@rY   c                      y r   r   rU   s    rW   r  z$EditorPluginExample.get_focus_widget      rY   c                     | j                   D ]`  }t        t        |            |k7  s|j                  d       |j	                  |      }|j                  |d       |j                  d       b y )NTr!  F)r	  rB  rW  r  rE  rm  )rV   editorstack_id_strr  r  r   s        rW   r  z2EditorPluginExample.close_file_in_all_editorstacks  sh    ,, 	0K2k?#'99((.#;;HE&&uD&9((/	0rY   c                 z    | j                   D ],  }t        t        |            |k7  s|j                  ||       . y)z5A file was saved in editorstack, this notifies othersN)r	  rB  rW  r  rV   r  r  r  r  s        rW   r  z-EditorPluginExample.file_saved_in_editorstack  sB      ,, 	FK2k?#'99;;<M<DF	FrY   c                 z    | j                   D ],  }t        t        |            |k7  s|j                  ||       . y)z?A file was renamed in data in editorstack, this notifies othersN)r	  rB  rW  r  r  s        rW   r  z7EditorPluginExample.file_renamed_in_data_in_editorstack  s>      ,, 	HK2k?#'99**+<hG	HrY   c                      y)zFake!Nr   )rV   rc  s     rW   r9  z-EditorPluginExample.register_widget_shortcuts  s    rY   c                      y r   r   rU   s    rW   r  z$EditorPluginExample.get_color_scheme  r  rY   )rz   N)r   r   r   rd   r  r  r  r  r  r  r  r  r  r  r  r   rB  r  r  r  r9  r  r   rY   rW   r  r  J  s    '"RH%3.D5#	O*A 
#s^0 0 
#sCF F 
#sCH HrY   r  c            	      ~   ddl m}  ddlm}  |d      } | d      }t	               }|j                  dd       |j                          dd l}|j                         }|j                  t        j                  |d	d
             |j                  t        j                  |ddd	d             |j                  t        j                  |ddd	d             |j                  t        j                  |ddd	d             t        d|j                         |z
  z         t        j                  |j                                y )Nr   )qapplication)get_module_pathr      )	test_timei  i  r  zcollectionseditor.pypluginsrh   z	editor.pyexplorerzexplorer.pyzcodeeditor.pyzElapsed time: %.3f s)spyder.utils.qthelpersr  spyder.config.baser  r  rs   r  timer  r  rx  printr   exitr  )r  r  
spyder_dirapptestr  t0s          rW   r  r    s    32 *J

#C DKKSIIK	BIIchhz9.DEFIIchhz9h	"$ %IIchhz9j)$& 'IIchhz9h	&( )	
 DIIKN
34HHSYY[rY   __main__)yr   loggingr  os.pathr3  r  r   rv  qstylizer.styler  qtpy.compatr   qtpy.QtCorer   r   r   r   r   r	   r
   r   r   
qtpy.QtGuir   r   qtpy.QtWidgetsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   spyder.api.panelr   r  r   r    spyder.config.guir!   spyder.config.managerr"   spyder.config.utilsr#   r$   r%   r&   r'   $spyder.plugins.editor.utils.autosaver(   "spyder.plugins.editor.utils.editorr)   $spyder.plugins.editor.utils.switcherr*   spyder.plugins.editor.widgetsr+   1spyder.plugins.editor.widgets.editorstack_helpersr,   r-   r.   $spyder.plugins.editor.widgets.statusr/   r0   r1   r2   r3   (spyder.plugins.explorer.widgets.explorerr4   %spyder.plugins.explorer.widgets.utilsr5   *spyder.plugins.outlineexplorer.main_widgetr6   %spyder.plugins.outlineexplorer.editorr7   "spyder.plugins.outlineexplorer.apir8   spyder.py3compatr9   r:   spyder.utilsr;   r<   r=   spyder.utils.icon_managerr>   spyder.utils.paletter?   r  r@   rA   rB   rC   rD   rE   rF   spyder.utils.stylesheetrG   rH   rI   spyder.widgets.findreplacerJ   spyder.widgets.tabsrK   	getLoggerr   r  rM   r   r  r%  ra  r  r  r   rY   rW   <module>r     sZ     	  
   '/ / / )D D D D D # 6 / &J J A @ F 4+ +N N$ 9 L L 8 > A A ) .8 8 8E E 2 ( 
		8	$b bJ{-+' {-+|[tY tnT>9 T>nOP{ OPdX) Xv2 zF rY   