B
    nôb\ÆÜ ã               @   s   d Z ddlmZ ddlZddlmZ ddlZddlm	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m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"m#Z#m$Z$m%Z% dd	l&m'Z'm(Z(m)Z)m*Z*m+Z+ dd
l,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z: ddl8m;Z;m<Z<m=Z=m>Z> ddl?m@Z@mAZAmBZBmCZC ddlDmEZE ddlFmGZG ddlHmIZI ddlJmKZK ddlLmMZM ddlNmOZO ddlNmPZP ddlQmRZRmSZSmTZTmUZU ddlVmWZW ddlXmYZY ddlZm[Z[ e(dkZ\G dd„ deƒZ]G dd„ deƒZ^G d d!„ d!eƒZ_G d"d#„ d#e	ƒZ`G d$d%„ d%e$ƒZaG d&d'„ d'e#ƒZbG d(d)„ d)e!ƒZcG d*d+„ d+e!ƒZdG d,d-„ d-eƒZeG d.d/„ d/e!ƒZfd0d1„ Zgehd2krœegƒ  dS )3zEditor Widgeté    )Úprint_functionN)ÚMutableSequence)Úgetsavefilename)
Ú
QByteArrayÚ	QFileInfoÚQObjectÚQPointÚQSizeÚQtÚQThreadÚQTimerÚSignalÚSlot)ÚQFont)ÚQActionÚQApplicationÚQFileDialogÚQHBoxLayoutÚQMainWindowÚQMessageBoxÚQMenuÚ	QSplitterÚQVBoxLayoutÚQWidgetÚQListWidgetÚQListWidgetItem)Ú_ÚDEBUGÚSTDERRÚSTDOUTÚrunning_under_pytest)Úconfig_shortcutÚget_shortcut)Úget_edit_filetypesÚget_edit_filtersÚ
get_filterÚis_kde_desktopÚis_anaconda)Úqbytearray_to_strÚto_text_string)Úicon_manager)ÚcodeanalysisÚencodingÚ
sourcecodeÚsyntaxhighlighters)Úadd_actionsÚcreate_actionÚcreate_toolbuttonÚmimedata2url)ÚOutlineExplorerWidget)ÚFileSwitcher)ÚFindReplace)Ú
codeeditor)ÚTextEditBaseWidget)ÚPrinter)Úget_file_language)ÚCursorPositionStatusÚEncodingStatusÚ	EOLStatusÚReadWriteStatus)ÚBaseTabs)ÚCONF)Úshow_in_external_file_exploreré   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚAnalysisThreadzAnalysis threadc                s&   t t| ƒ |¡ || _d | _|| _d S )N)ÚsuperrB   Ú__init__ÚcheckerÚresultsÚsource_code)ÚselfÚparentrE   rG   )Ú	__class__© ú4lib/python3.7/site-packages/spyder/widgets/editor.pyrD   ;   s    zAnalysisThread.__init__c             C   sD   y|   | j¡| _W n, tk
r>   tr:ddl}|jtd Y nX dS )zRun analysisr   N)Úfile)rE   rG   rF   Ú	ExceptionÚDEBUG_EDITORÚ	tracebackÚ	print_excr   )rH   rP   rK   rK   rL   ÚrunA   s    zAnalysisThread.run)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rD   rR   Ú__classcell__rK   rK   )rJ   rL   rB   9   s   rB   c                   sB   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Z‡  Z	S )ÚThreadManagerzAnalysis thread manageré   c                s,   t t| ƒ |¡ || _i | _g | _i | _d S )N)rC   rX   rD   Úmax_simultaneous_threadsÚstarted_threadsÚpending_threadsÚend_callbacks)rH   rI   rZ   )rJ   rK   rL   rD   M   s
    zThreadManager.__init__c                s¬   t rtdtd |dkrDg | _g }xLt| j ¡ ƒD ]}||7 }q2W n,t|ƒ‰ ‡ fdd„| jD ƒ| _| j ˆ g ¡}x6|D ].}t rŽtd| td x| 	¡ r¢t
 ¡  qW qvW dS )z%Close threads associated to parent_idzCall to 'close_threads')rM   Nc                s    g | ]\}}|ˆ kr||f‘qS rK   rK   )Ú.0Z_thÚ_id)Ú	parent_idrK   rL   ú
<listcomp>`   s    z/ThreadManager.close_threads.<locals>.<listcomp>zWaiting for thread %r to finish)rO   Úprintr   r\   Úlistr[   ÚvaluesÚidÚgetZ	isRunningr   ÚprocessEvents)rH   rI   Ú
threadlistZthreadsÚthreadrK   )r`   rL   Úclose_threadsT   s     


zThreadManager.close_threadsc             C   s   t rtdtd |  d¡ dS )zClose all threadszCall to 'close_all_threads')rM   N)rO   rb   r   rj   )rH   rK   rK   rL   Úclose_all_threadsk   s    zThreadManager.close_all_threadsc             C   sX   t |ƒ}t| ||ƒ}|| jt |ƒ< | j ||f¡ trFtd| td t 	d| j
¡ dS )zAdd thread to queuezAdded thread %r to queue)rM   é2   N)re   rB   r]   r\   ÚappendrO   rb   r   r   Z
singleShotÚupdate_queue)rH   rE   Úend_callbackrG   rI   r`   ri   rK   rK   rL   Ú
add_threadq   s    zThreadManager.add_threadc             C   sB  d}xšt | j ¡ ƒD ]ˆ\}}g }xZ|D ]R}| ¡ rf| j t|ƒ¡}|jdk	rV||jƒ | d¡ d}q&| 	|¡ |d7 }q&W d}|r|| j|< q| j |¡ qW t
rÒtdtd td|td tdt| jƒtd | jr>|| jk r>| j d¡\}}|j | j¡ | j |g ¡}||g | j|< t
r6td|td | ¡  dS )	zUpdate queuer   Né   zUpdating queue:)rM   z    started:z    pending:z===>starting:)rc   r[   ÚitemsZ
isFinishedr]   Úpopre   rF   Z	setParentrm   rO   rb   r   Úlenr\   rZ   ZfinishedÚconnectrn   rf   Ústart)rH   Zstartedr`   rh   Zstill_runningri   ro   rK   rK   rL   rn   {   s8    




zThreadManager.update_queue)rY   )
rS   rT   rU   rV   rD   rj   rk   rp   rn   rW   rK   rK   )rJ   rL   rX   K   s   
rX   c               @   s¼   e Zd ZdZeƒ Zeƒ ZeeeƒZeee	ƒZ
eee	eƒZeeeeeeƒZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚFileInfozFile propertiesc             C   sŠ   t  | ¡ || _|| _|| _d| _|| _|| _g | _|d d f| _	g | _
g | _t|ƒ ¡ | _| jj | j¡ | jj | j¡ d | _d | _d S )NF)r   rD   ÚthreadmanagerÚfilenameÚnewly_createdÚdefaultr,   ÚeditorÚpathÚclassesÚanalysis_resultsÚtodo_resultsr   ÚlastModifiedÚlastmodifiedÚtextChangedru   Útext_changedÚbreakpoints_changedÚpyflakes_resultsÚpep8_results)rH   ry   r,   r|   Únewrx   Zintrospection_pluginrK   rK   rL   rD   §   s     
zFileInfo.__init__c             C   s"   d| _ | j | j| j d¡¡ dS )zEditor's text has changedFÚcursorN)r{   Útext_changed_atÚemitry   r|   Úget_position)rH   rK   rK   rL   r„   ½   s    
zFileInfo.text_changedc             C   s   t | j ¡ ƒS )z$Return associated editor source code)r)   r|   ZtoPlainText)rH   rK   rK   rL   Úget_source_codeÃ   s    zFileInfo.get_source_codec             C   sª   |o
t  ¡ }|ot  d¡dk	}g | _g | _| j ¡ r¦| j dd¡ dd¡}t 	|  
¡ |¡\}}|rhd| _|rrd| _|rŒ| j t j| j|| ¡ |r¦| j t j| j|| ¡ dS )zRun code analysisZpycodestyleNz-guessedÚ z-bom)r+   Zis_pyflakes_installedZget_checker_executabler†   r‡   r|   Ú	is_pythonr,   ÚreplaceÚencoder   rx   rp   Zcheck_with_pyflakesÚpyflakes_analysis_finishedZcheck_with_pep8Úpep8_analysis_finished)rH   Úrun_pyflakesÚrun_pep8ÚencrG   rK   rK   rL   Úrun_code_analysisÇ   s(    


zFileInfo.run_code_analysisc             C   s   || _ | jdk	r|  ¡  dS )z*Pyflakes code analysis thread has finishedN)r†   r‡   Úcode_analysis_finished)rH   rF   rK   rK   rL   r’   Þ   s    
z#FileInfo.pyflakes_analysis_finishedc             C   s   || _ | jdk	r|  ¡  dS )z&Pep8 code analysis thread has finishedN)r‡   r†   r˜   )rH   rF   rK   rK   rL   r“   ä   s    
zFileInfo.pep8_analysis_finishedc             C   s    |   | j| j ¡ | j ¡  dS )z!Code analysis thread has finishedN)Úset_analysis_resultsr†   r‡   Úanalysis_results_changedr‹   )rH   rK   rK   rL   r˜   ê   s    zFileInfo.code_analysis_finishedc             C   s   || _ | j |¡ dS )z9Set analysis results and update warning markers in editorN)r   r|   Zprocess_code_analysis)rH   rF   rK   rK   rL   r™   ï   s    zFileInfo.set_analysis_resultsc             C   s   g | _ | j ¡  dS )zClean-up analysis resultsN)r   r|   Zcleanup_code_analysis)rH   rK   rK   rL   Úcleanup_analysis_resultsô   s    z!FileInfo.cleanup_analysis_resultsc             C   s(   | j  ¡ r$| j tj| j|  ¡ | ¡ dS )zRun TODO finderN)r|   r   rx   rp   r+   Z
find_tasksÚtodo_finishedr   )rH   rK   rK   rL   Úrun_todo_finderù   s    

zFileInfo.run_todo_finderc             C   s   |   |¡ | j ¡  dS )z!Code analysis thread has finishedN)Úset_todo_resultsÚtodo_results_changedr‹   )rH   rF   rK   rK   rL   rœ      s    
zFileInfo.todo_finishedc             C   s   || _ | j |¡ dS )z-Set TODO results and update markers in editorN)r€   r|   Zprocess_todo)rH   rF   rK   rK   rL   rž     s    zFileInfo.set_todo_resultsc             C   s
   g | _ dS )zClean-up TODO finder resultsN)r€   )rH   rK   rK   rL   Úcleanup_todo_results
  s    zFileInfo.cleanup_todo_resultsc             C   s6   | j  ¡ }| j j|kr2|| j _| j | jt|ƒ¡ dS )zBreakpoint list has changedN)r|   Zget_breakpointsÚbreakpointsÚsave_breakpointsr‹   ry   Úrepr)rH   r¡   rK   rK   rL   r…     s    
zFileInfo.breakpoints_changedN)rS   rT   rU   rV   r   rš   rŸ   Ústrr¢   ÚintrŠ   Ú	edit_gotoÚboolÚsend_to_helprD   r„   r   r—   r’   r“   r˜   r™   r›   r   rœ   rž   r    r…   rK   rK   rK   rL   rw   ž   s*   

rw   c               @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚStackHistoryz–Handles editor stack history.

    Works as a list of numbers corresponding to tab indexes.
    Internally elements are saved using objects id's.
    c             C   s   t ƒ | _t ƒ | _|| _d S )N)rc   ÚhistoryÚid_listr|   )rH   r|   rK   rK   rL   rD     s    zStackHistory.__init__c                s$   ‡ fdd„t ˆ jj ¡ ƒD ƒˆ _dS )z+Update list of corresponpding ids and tabs.c                s   g | ]}t ˆ jj |¡ƒ‘qS rK   )re   r|   ÚtabsÚwidget)r^   Z_i)rH   rK   rL   ra   $  s   z0StackHistory._update_id_list.<locals>.<listcomp>N)Úranger|   r¬   Úcountr«   )rH   rK   )rH   rL   Ú_update_id_list"  s    
zStackHistory._update_id_listc             C   s:   |   ¡  x,| jdd… D ]}|| jkr| j |¡ qW dS )z(Remove editors that are not longer open.N)r°   rª   r«   Úremove)rH   r_   rK   rK   rL   Úrefresh'  s    
zStackHistory.refreshc             C   s
   t | jƒS )N)rt   rª   )rH   rK   rK   rL   Ú__len__.  s    zStackHistory.__len__c             C   s@   |   ¡  y| j | j| ¡S  tk
r:   |  ¡  t‚Y nX d S )N)r°   r«   Úindexrª   Ú
ValueErrorr²   Ú
IndexError)rH   ÚirK   rK   rL   Ú__getitem__1  s    zStackHistory.__getitem__c             C   s   | j |= d S )N)rª   )rH   r·   rK   rK   rL   Ú__delitem__9  s    zStackHistory.__delitem__c             C   s    t | jj |¡ƒ}|| j|< d S )N)re   r|   r¬   r­   rª   )rH   r·   Úvr_   rK   rK   rL   Ú__setitem__<  s    zStackHistory.__setitem__c             C   s   t t| ƒƒS )N)r¤   rc   )rH   rK   rK   rL   Ú__str__@  s    zStackHistory.__str__c             C   s$   t | jj |¡ƒ}| j ||¡ dS )z;Insert the widget (at tab index) in the position i (index).N)re   r|   r¬   r­   rª   Úinsert)rH   r·   Ú	tab_indexr_   rK   rK   rL   r½   C  s    zStackHistory.insertc             C   s,   t | jj |¡ƒ}|| jkr(| j |¡ dS )z1Remove the widget at the corresponding tab_index.N)re   r|   r¬   r­   rª   r±   )rH   r¾   r_   rK   rK   rL   r±   H  s    
zStackHistory.removeN)rS   rT   rU   rV   rD   r°   r²   r³   r¸   r¹   r»   r¼   r½   r±   rK   rK   rK   rL   r©     s   r©   c               @   sR   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚTabSwitcherWidgetz/Show tabs in mru order and change between them.c                s´   t  ˆ |¡ ˆ  tjtjB ¡ |ˆ _|ˆ _|ˆ _ˆ  	t j
¡ ˆ j ˆ j¡ g ˆ _ˆ  ¡  t dd¡}ˆ j|Ž  ˆ  ¡  ˆ  d¡ t‡ fdd„ddˆ d t‡ fd	d„dd
ˆ d d S )NÚmainzcompletion/sizer   c                  s
   ˆ   d¡S )Néÿÿÿÿ)Ú
select_rowrK   )rH   rK   rL   Ú<lambda>d  s    z,TabSwitcherWidget.__init__.<locals>.<lambda>ÚEditorzGo to previous file)ÚcontextÚnamerI   c                  s
   ˆ   d¡S )Nrq   )rÂ   rK   )rH   rK   rL   rÃ   f  s    zGo to next file)r   rD   ZsetWindowFlagsr
   ZFramelessWindowHintZDialogr|   Ústack_historyr¬   ZsetSelectionModeZSingleSelectionZitemActivatedru   Úitem_selectedr«   Ú	load_datar?   rf   ÚresizeÚset_dialog_positionÚsetCurrentRowr!   )rH   rI   rÇ   r¬   ÚsizerK   )rH   rL   rD   R  s"    


zTabSwitcherWidget.__init__c             C   sJ   xDt | jƒD ]6}| j |¡}| dd¡}tt d¡|ƒ}|  |¡ qW dS )zfFill ListWidget with the tabs texts.

        Add elements in inverse order of stack_history.
        ú&rŽ   ÚTextFileIconN)	ÚreversedrÇ   r¬   ÚtabTextr   r   ÚimaÚiconZaddItem)rH   r´   ÚtextÚitemrK   rK   rL   rÉ   i  s
    zTabSwitcherWidget.load_dataNc             C   sb   |dkr|   ¡ }y| j|  ¡ d   }W n tk
r<   Y nX | j |¡ | j |¡ |  ¡  dS )z5Change to the selected document and hide this widget.Nrq   )ZcurrentItemrÇ   Ú
currentRowr¶   r|   Úset_stack_indexÚcurrent_changedÚhide)rH   rÕ   r´   rK   rK   rL   rÈ   t  s    zTabSwitcherWidget.item_selectedc             C   s"   |   ¡ | |  ¡  }|  |¡ dS )zVMove selected row a number of steps.

        Iterates in a cyclic behaviour.
        N)rÖ   r¯   rÌ   )rH   ÚstepsÚrowrK   rK   rL   rÂ   ƒ  s    zTabSwitcherWidget.select_rowc             C   sN   | j  ¡  ¡ d |  ¡ d  }| j j ¡  ¡  ¡ }|  | j  t||ƒ¡¡ dS )z;Positions the tab switcher in the top-center of the editor.rY   N)	r|   ZgeometryÚwidthr¬   ÚtabBarÚheightÚmoveZmapToGlobalr   )rH   ÚleftÚtoprK   rK   rL   rË   ‹  s    z%TabSwitcherWidget.set_dialog_positionc             C   sp   |   ¡ rdtddd}xN| d¡D ]@}| ¡ }|dkrB| ¡ tjksX|dkr | ¡ tjkr |  ¡  q W | 	¡  dS )z Reimplement Qt method.

        Handle "most recent used" tab behavior,
        When ctrl is released and tab_switcher is visible, tab will be changed.
        rÄ   zGo to next file)rÅ   rÆ   ú+ZctrlZaltN)
Ú	isVisibler"   ÚsplitÚlowerÚkeyr
   ZKey_ControlZKey_AltrÈ   Úaccept)rH   ÚeventZqscræ   rK   rK   rL   ÚkeyReleaseEvent’  s    z!TabSwitcherWidget.keyReleaseEventc             C   s6   |  ¡ tjkr|  d¡ n|  ¡ tjkr2|  d¡ dS )z/Reimplement Qt method to allow cyclic behavior.rq   rÁ   N)ræ   r
   ZKey_DownrÂ   ZKey_Up)rH   rè   rK   rK   rL   ÚkeyPressEvent¢  s    zTabSwitcherWidget.keyPressEventc             C   s6   |  ¡  tjdkr*| ¡ tjkr2|  ¡  n|  ¡  dS )z=Reimplement Qt method to close the widget when loosing focus.ÚdarwinN)ÚignoreÚsysÚplatformÚreasonr
   ZActiveWindowFocusReasonÚclose)rH   rè   rK   rK   rL   ÚfocusOutEvent©  s
    

zTabSwitcherWidget.focusOutEvent)N)rS   rT   rU   rV   rD   rÉ   rÈ   rÂ   rË   ré   rê   rñ   rK   rK   rK   rL   r¿   O  s   
r¿   c               @   s   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eƒZeƒ Zeƒ Zeƒ Zeƒ Zeƒ ZeeeƒZeeeeƒZeeeeƒZeƒ Zeƒ Zeƒ Zeƒ Zeƒ Zeƒ Zeƒ ZeeeƒZeee	ƒZ 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ƒ Z*dd„ Z+e,ƒ ddd„ƒZ-dd„ Z.d	d
„ Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3dd„ Z4e,ƒ dd„ ƒZ5e,ƒ dd„ ƒZ6dd„ Z7ddd„Z8dd„ Z9dd „ Z:d!d"„ Z;d#d$„ Z<d%d&„ Z=d'd(„ Z>d)d*„ Z?d+d,„ Z@d-d.„ ZAd/d0„ ZBd1d2„ ZCd3d4„ ZDd5d6„ ZEd7d8„ ZFdd9d:„ZGdd;d<„ZHd=d>„ ZIdd?d@„ZJdAdB„ ZKdCdD„ ZLddEdF„ZMdGdH„ ZNdIdJ„ ZOdKdL„ ZPdMdN„ ZQdOdP„ ZRdQdR„ ZSdSdT„ ZTdUdV„ ZUdWdX„ ZVdYdZ„ ZWd[d\„ ZXd]d^„ ZYd_d`„ ZZdadb„ Z[dcdd„ Z\ddedf„Z]dgdh„ Z^didj„ Z_dkdl„ Z`dmdn„ Zadodp„ Zbdqdr„ Zcdsdt„ Zddudv„ Zedwdx„ Zfdydz„ Zgd{d|„ Zhd}d~„ Zidd€„ Zjdd‚„ Zkdƒd„„ Zld…d†„ Zmdd‡dˆ„Znd‰dŠ„ Zod‹dŒ„ ZpddŽ„ Zqddd„Zrdd‘d’„Zsd“d”„ Ztd•d–„ Zud—d˜„ Zvd™dš„ Zwd›dœ„ Zxddž„ ZydŸd „ Zzd¡d¢„ Z{d£d¤„ Z|d¥d¦„ Z}d§d¨„ Z~d©dª„ Zdd«d¬„Z€d­d®„ Ze,e	e	ƒd¯d°„ ƒZ‚d d²d³„Zƒd´dµ„ Z„d¶d·„ Z…d¸d¹„ Z†dºd»„ Z‡d¼d½„ Zˆd¾d¿„ Z‰d!dÀdÁ„ZŠd"dÂdÃ„Z‹dÄdÅ„ ZŒdÆdÇ„ Zd#dÈdÉ„ZŽd$dÊdË„ZdÌdÍ„ ZdÎdÏ„ Z‘d%dÐdÑ„Z’dÒdÓ„ Z“dÔdÕ„ Z”dÖd×„ Z•dØdÙ„ Z–dÚdÛ„ Z—dÜdÝ„ Z˜d&dßdà„Z™dádâ„ Zšd'dãdä„Z›dådæ„ Zœdçdè„ Zdédê„ Zždëdì„ ZŸd(dídî„Z d)dïdð„Z¡dñdò„ Z¢dódô„ Z£dõdö„ Z¤d*d÷dø„Z¥dùdú„ Z¦d+dûdü„Z§d,dýdþ„Z¨d-dÿd „Z©d.dd„Zªd/dd„Z«d0dd„Z¬dd„ Z­d	d
„ Z®dd„ Z¯d1dd„Z°dd„ Z±dd„ Z²dd„ Z³dS (2  ÚEditorStackrK   c          	      s  t  ˆ |¡ ˆ  tj¡ tˆ ƒˆ _d ˆ _d ˆ _d ˆ _	d ˆ _
ˆ  ¡  tƒ }| dddd¡ ˆ  |¡ d ˆ _d ˆ _d ˆ _d ˆ _tˆ ƒˆ _ˆ  ||¡ d ˆ _g ˆ _tˆ tdƒt d¡ˆ jd}tˆ tdƒt d¡ˆ jd}tˆ tdƒt d¡‡ fd	d
„d}tˆ tdƒˆ jd}tˆ tdƒˆ jd}t j!dkr4tdƒ}	ntdƒ}	tˆ |	ˆ j"d}
||
d |||d ||g ˆ _#d ˆ _$d ˆ _%d ˆ _&dˆ _'d ˆ _(d ˆ _)d ˆ _*d ˆ _+d ˆ _,tdƒˆ _-dˆ _.dˆ _/dˆ _0dˆ _1dˆ _2dˆ _3dˆ _4dˆ _5dˆ _6dˆ _7dˆ _8dˆ _9dˆ _:dˆ _;dˆ _<dˆ _=dˆ _>dˆ _?dˆ _@dˆ _Adˆ _Bd ˆ _Cdˆ _Ddˆ _Edˆ _Fdˆ _Gdˆ _Hdˆ _Idˆ _Jdˆ _Kdˆ _Ldˆ _Mdˆ _Nd}|tOjPkr†tOjPd }|ˆ _Qd ˆ _Rdˆ _StTˆ ƒˆ _Uˆ jU Vd¡ ˆ jU Wd¡ ˆ jUjX Yˆ jZ¡ ˆ  [d¡ ˆ  \¡ ˆ _]g ˆ _^d ˆ __d ˆ _`d ˆ _atbƒ  ˆ _cd S )Nr   zFile switcher...Zfilelist)rÓ   Ú	triggeredzFind symbols in file...Zsymbol_findzCopy path to clipboardZeditcopyc                  s   t  ¡  ˆ  ¡ ¡S )N)r   Z	clipboardZsetTextÚget_current_filenamerK   )rH   rK   rL   rÃ     s    z&EditorStack.__init__.<locals>.<lambda>zClose all to the right)ró   zClose all but thisrë   zShow in FinderzShow in external file explorerFrÄ   TéO   z    é   iÜ  ÚSpyderiÐ  )dr   rD   ÚsetAttributer
   ÚWA_DeleteOnCloserX   rx   Únewwindow_actionÚhorsplit_actionÚversplit_actionÚclose_actionÚ_EditorStack__get_split_actionsr   ÚsetContentsMarginsÚ	setLayoutÚmenuÚfileswitcher_dlgr¬   Útabs_switcherr©   rÇ   Úsetup_editorstackÚfind_widgetÚdatar0   r   rÒ   rÓ   Úopen_fileswitcher_dlgÚopen_symbolfinder_dlgÚclose_all_rightÚclose_all_but_thisrí   rî   r@   Úmenu_actionsÚoutlineexplorerÚhelpZunregister_callbackÚis_closableÚ
new_actionÚopen_actionÚsave_actionÚrevert_actionÚtempfile_pathÚtitleÚpyflakes_enabledÚpep8_enabledÚtodolist_enabledÚrealtime_analysis_enabledÚis_analysis_doneÚlinenumbers_enabledÚblanks_enabledÚedgeline_enabledÚedgeline_columnÚcodecompletion_auto_enabledÚcodecompletion_case_enabledÚcodecompletion_enter_enabledÚcalltips_enabledÚgo_to_definition_enabledÚclose_parentheses_enabledÚclose_quotes_enabledÚadd_colons_enabledÚauto_unindent_enabledÚindent_charsÚtab_stop_width_spacesÚhelp_enabledÚdefault_fontÚwrap_enabledÚtabmode_enabledÚintelligent_backspace_enabledÚhighlight_current_line_enabledÚhighlight_current_cell_enabledÚoccurrence_highlighting_enabledÚoccurrence_highlighting_timeoutÚcheckeolchars_enabledÚalways_remove_trailing_spacesÚfocus_to_editorÚcreate_new_file_if_emptyr.   ZCOLOR_SCHEME_NAMESÚcolor_schemeÚintrospectorÚ_EditorStack__file_status_flagr   Úanalysis_timerZsetSingleShotÚsetIntervalÚtimeoutru   Úanalyze_scriptZsetAcceptDropsÚcreate_shortcutsÚ	shortcutsÚlast_closed_filesÚmsgboxÚedit_filetypesÚedit_filtersr    Úsave_dialog_on_tests)rH   rI   ÚactionsÚlayoutZfileswitcher_actionZsymbolfinder_actionZcopy_to_cb_actionZclose_rightr
  rÔ   Zexternal_fileexp_actionZccsrK   )rH   rL   rD   Û  sÎ    


















zEditorStack.__init__Nc             C   s   |dkr|   ¡ }t|ƒ dS )z#Show file in external file explorerN)rô   r@   )rH   ÚfnamesrK   rK   rL   r@   b  s    z*EditorStack.show_in_external_file_explorerc                sœ  t ˆ jddˆ d}t ˆ jddˆ d}t ˆ jddˆ d}t ˆ jddˆ d}t ‡ fdd„dd	ˆ d}t ˆ jdd
ˆ d}t ‡ fdd„ddˆ d}t ‡ fdd„ddˆ d}t ˆ jddˆ d}	t ‡ fdd„ddˆ d}
t ‡ fdd„ddˆ d}t ˆ jddˆ d}t ˆ jddˆ d}t ‡ fdd„ddˆ d}t ˆ j	ddˆ d}t ‡ fdd„ddˆ d}t ‡ fdd„ddˆ d}t ‡ fdd„ddˆ d}t ‡ fdd„dd ˆ d}t ‡ fd!d„dd"ˆ d}t ‡ fd#d„dd$ˆ d}t ‡ fd%d„dd&ˆ d}t ˆ j
dd'ˆ d}t ˆ j
dd(ˆ d}t ˆ jdd)ˆ d}t ˆ jdd*ˆ d}t ˆ jdd+ˆ d}t ‡ fd,d„dd-ˆ d}t ˆ jdd.ˆ d}|||||||	|
|||||||||||||||||||||gS )/zCreate local shortcutsrÄ   zInspect current object)rÅ   rÆ   rI   Z
BreakpointzConditional breakpointz
Go to linec                  s   ˆ j ddS )NF)Úforward)Útab_navigation_mrurK   )rH   rK   rL   rÃ   x  s    z.EditorStack.create_shortcuts.<locals>.<lambda>zGo to previous filezGo to next filec                  s   ˆ j  d¡S )NrÁ   )r¬   Útab_navigaterK   )rH   rK   rL   rÃ   }  s    zCycle to previous filec                  s   ˆ j  d¡S )Nrq   )r¬   rI  rK   )rH   rK   rL   rÃ   €  s    zCycle to next filezRun selectionc                  s   ˆ j d  ¡ S )NrK   )Úsig_new_filer‹   rK   )rH   rK   rL   rÃ   …  s    zNew filec                  s   ˆ j d  ¡ S )NrK   )Úplugin_loadr‹   rK   )rH   rK   rL   rÃ   ˆ  s    z	Open filez	Save filezSave allc                  s
   ˆ j  ¡ S )N)Úsig_save_asr‹   rK   )rH   rK   rL   rÃ     s    zSave Asz	Close allc                  s
   ˆ j  ¡ S )N)Úsig_prev_edit_posr‹   rK   )rH   rK   rL   rÃ   ”  s    zLast edit locationc                  s
   ˆ j  ¡ S )N)Úsig_prev_cursorr‹   rK   )rH   rK   rL   rÃ   ˜  s    zPrevious cursor positionc                  s
   ˆ j  ¡ S )N)Úsig_next_cursorr‹   rK   )rH   rK   rL   rÃ   œ  s    zNext cursor positionc                  s
   ˆ j  ¡ S )N)Úzoom_inr‹   rK   )rH   rK   rL   rÃ      s    z	zoom in 1c                  s
   ˆ j  ¡ S )N)rP  r‹   rK   )rH   rK   rL   rÃ   ¤  s    z	zoom in 2c                  s
   ˆ j  ¡ S )N)Úzoom_outr‹   rK   )rH   rK   rL   rÃ   ¨  s    zzoom outc                  s
   ˆ j  ¡ S )N)Ú
zoom_resetr‹   rK   )rH   rK   rL   rÃ   ¬  s    z
zoom resetzclose file 1zclose file 2zrun cellzrun cell and advancezgo to next cellc                  s   ˆ j ddS )NT)Úreverse)Úadvance_cellrK   )rH   rK   rL   rÃ   Ä  s    zgo to previous cellzre-run last cell)r!   Úinspect_current_objectÚset_or_clear_breakpointÚ"set_or_edit_conditional_breakpointÚ
go_to_linerH  Úrun_selectionÚsaveÚsave_allÚclose_all_filesÚ
close_fileÚrun_cellÚrun_cell_and_advancerT  Úre_run_last_cell)rH   ÚinspectZset_breakpointZset_cond_breakpointZgotolineZtabZtabshiftZprevtabZnexttabrY  Znew_fileZ	open_fileZ	save_filer[  Úsave_asZ	close_allZprev_edit_posZprev_cursorZnext_cursorZ	zoom_in_1Z	zoom_in_2rQ  rR  Zclose_file_1Zclose_file_2r^  r_  Úgo_to_next_cellÚgo_to_previous_cellr`  rK   )rH   rL   r=  i  sÎ    













zEditorStack.create_shortcutsc             C   s   dd„ | j D ƒS )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
        c             S   s   g | ]
}|j ‘qS rK   )r  )r^   ZscrK   rK   rL   ra   Ý  s    z1EditorStack.get_shortcut_data.<locals>.<listcomp>)r>  )rH   rK   rK   rL   Úget_shortcut_dataÖ  s    zEditorStack.get_shortcut_datac             C   s@  t | t d¡tdƒd}t| ƒ| _| | j¡ | |j¡ | jj	 
| j¡ tj|gi}t| | jd|d| _| j ¡  d¡ | j | j¡ | j ¡ j 
| j¡ | j d¡ | j ¡  t| jdƒrÔtjdksÔ| j d¡ | jj 
| j¡ tjdkr0tƒ }| d	¡ t |ƒ}| !d
d
d
d
¡ | "| j¡ | "|¡ n| "| j¡ dS )zSetup editorstack's layoutZtooloptionsZOptions)rÓ   ÚtipT)r  Zmenu_use_tooltipsÚcorner_widgetsz
plugin-tabÚsetDocumentModerë   ztab-containerr   N)#r1   rÒ   rÓ   r   r   r  ZsetMenuZsetPopupModeZInstantPopupZaboutToShowru   Ú_EditorStack__setup_menur
   ZTopRightCornerr>   r¬   rÝ   ÚsetObjectNameZset_close_functionr]  ZtabMovedÚmove_editorstack_dataZ
setMovablerÇ   r²   Úhasattrrí   rî   rh  ZcurrentChangedrØ   r   r   rÿ   Ú	addWidget)rH   rI   rE  Zmenu_btnrg  Ztab_containerZ
tab_layoutrK   rK   rL   r  ß  s4    





zEditorStack.setup_editorstackc             C   s   | j  |¡ d S )N)r¬   Zadd_corner_widgets)rH   ÚwidgetsrK   rK   rL   Úadd_corner_widgets_to_tabbar  s    z(EditorStack.add_corner_widgets_to_tabbarc             C   sR   | j  ¡  | jj | j¡ | jd k	rBx| jD ]}| j |j	¡ q,W t
 | |¡ d S )N)rx   rk   r9  r;  Z
disconnectr<  r  r  Úremove_editorr|   r   Ú
closeEvent)rH   rè   ÚfinforK   rK   rL   rq    s    

zEditorStack.closeEventc             C   sH   |j }|j}|j}| j||d|||jd}| |j¡ | |j¡ |jS )NrŽ   )Úset_currentrˆ   Úcloned_from)	ry   r,   rz   Úcreate_new_editorr|   r™   r   rž   r€   )rH   Úother_finfors  Úfnamer–   rˆ   rr  rK   rK   rL   Úclone_editor_from%  s    

zEditorStack.clone_editor_fromc             C   s0   x|j D ]}| j|dd qW |  | ¡ ¡ dS )z%Clone EditorStack from other instanceT)rs  N)r  rx  r×   Úget_stack_index)rH   Úotherrv  rK   rK   rL   Ú
clone_from0  s    zEditorStack.clone_fromc             C   sx   | j  ¡ sdS | jdk	r6| jjr6| j ¡  d| j_dS t| | | j | jt d¡ƒ| _| jj	 
| j¡ | j ¡  d| j_dS )z$Open file list management dialog boxNFrÏ   T)r¬   r¯   r  Z
is_visiblerÙ   r4   r  rÒ   rÓ   Zsig_goto_fileru   r×   Úshow)rH   rK   rK   rL   r  6  s    



z!EditorStack.open_fileswitcher_dlgc             C   s   |   ¡  | j d¡ d S )Nú@)r  r  Zset_search_text)rH   rK   rK   rL   r  F  s    z!EditorStack.open_symbolfinder_dlgc             C   s   | S )z,Get the widget with the TabWidget attribute.rK   )rH   rK   rK   rL   Úget_current_tab_managerK  s    z#EditorStack.get_current_tab_managerc             C   s.   |dk	r|   ¡  |¡ n| jr*|   ¡  ¡  dS )zGo to line dialogN)Úget_current_editorrX  r  Zexec_gotolinedialog)rH   ÚlinerK   rK   rL   rX  O  s    zEditorStack.go_to_linec             C   s   | j r|  ¡ }| ¡  dS )zSet/clear breakpointN)r  r  Úadd_remove_breakpoint)rH   r|   rK   rK   rL   rV  Y  s    z#EditorStack.set_or_clear_breakpointc             C   s   | j r|  ¡ }|jdd dS )zSet conditional breakpointT)Zedit_conditionN)r  r  r  )rH   r|   rK   rK   rL   rW  _  s    z.EditorStack.set_or_edit_conditional_breakpointc             C   sV   | j r4|  ¡ }| d¡}| j ¡  | j j|dd n|  ¡  ¡ }|rR| j|dd dS )z)Inspect current object in the Help pluginr‰   F)ÚautoT)ÚforceN)r7  r  rŒ   r  Zswitch_to_editor_sourceÚshow_object_infoZget_current_objectr¨   )rH   r|   ÚpositionrÔ   rK   rK   rL   rU  e  s    

z"EditorStack.inspect_current_objectc             C   s
   || _ dS )z,Parent widget must handle the closable stateN)r  )rH   ÚstaterK   rK   rL   Úset_closabler  s    zEditorStack.set_closablec             C   s   || _ || _|| _|| _d S )N)r  r  r  r  )rH   r  r  r  r  rK   rK   rL   Úset_io_actionsv  s    zEditorStack.set_io_actionsc             C   s
   || _ d S )N)r  )rH   r  rK   rK   rL   Úset_find_widget}  s    zEditorStack.set_find_widgetc             C   s   || _ | j j | j¡ d S )N)r  Zoutlineexplorer_is_visibleru   Ú_refresh_outlineexplorer)rH   r  rK   rK   rL   Úset_outlineexplorer€  s    zEditorStack.set_outlineexplorerc             C   s2   x,t |  ¡ ƒD ]}||  ¡ kr| j|d qW dS )zŒThis method is called separately from 'set_oulineexplorer' to avoid
        doing unnecessary updates when there are multiple editor windows)r´   N)r®   Úget_stack_country  rŠ  )rH   r´   rK   rK   rL   Úinitialize_outlineexplorer…  s    z&EditorStack.initialize_outlineexplorerc             C   s(   t |ƒ}| | jj¡ |  d|g¡ d S )Né   )r1   ÚsetDefaultActionr  Úvisibility_actionro  )rH   Zeditor_pluginÚoe_btnrK   rK   rL   Úadd_outlineexplorer_buttonŒ  s    z&EditorStack.add_outlineexplorer_buttonc             C   s
   || _ d S )N)r  )rH   Zhelp_pluginrK   rK   rL   Úset_help‘  s    zEditorStack.set_helpc             C   s
   || _ d S )N)r  )rH   r}   rK   rK   rL   Úset_tempfile_path”  s    zEditorStack.set_tempfile_pathc             C   s
   || _ d S )N)r  )rH   rÔ   rK   rK   rL   Ú	set_title—  s    zEditorStack.set_titlec             C   s   |j | j|  ¡ d d S )N)ÚlinenumbersÚmarkers)Zsetup_marginsr  Úhas_markers)rH   r|   rK   rK   rL   Z__update_editor_marginsš  s    z#EditorStack.__update_editor_marginsc             C   s`   | j r\| j| j }}xF| j D ]<}|  |j¡ | ¡  |s<|r|d k	r||k	r| ||¡ qW d S )N)r  r  r  Ú#_EditorStack__update_editor_marginsr|   r›   r—   )rH   Úcurrent_finfor”   r•   rr  rK   rK   rL   Z__codeanalysis_settings_changedž  s    z+EditorStack.__codeanalysis_settings_changedc             C   s   || _ |  |¡ d S )N)r  Ú+_EditorStack__codeanalysis_settings_changed)rH   r†  rš  rK   rK   rL   Úset_pyflakes_enabled¨  s    z EditorStack.set_pyflakes_enabledc             C   s   || _ |  |¡ d S )N)r  r›  )rH   r†  rš  rK   rK   rL   Úset_pep8_enabled­  s    zEditorStack.set_pep8_enabledc             C   s   | j p| jp| jS )zVReturn True if this editorstack has a marker margin for TODOs or
        code analysis)r  r  r  )rH   rK   rK   rL   r˜  ²  s    zEditorStack.has_markersc             C   sP   || _ | jrLx>| jD ]4}|  |j¡ | ¡  |r|d k	r||k	r| ¡  qW d S )N)r  r  r™  r|   r    r   )rH   r†  rš  rr  rK   rK   rL   Úset_todolist_enabled¸  s    z EditorStack.set_todolist_enabledc             C   s
   || _ d S )N)r  )rH   r†  rK   rK   rL   Úset_realtime_analysis_enabledÃ  s    z)EditorStack.set_realtime_analysis_enabledc             C   s   | j  |¡ d S )N)r9  r:  )rH   r;  rK   rK   rL   Úset_realtime_analysis_timeoutÆ  s    z)EditorStack.set_realtime_analysis_timeoutc             C   s,   || _ | jr(x| jD ]}|  |j¡ qW d S )N)r  r  r™  r|   )rH   r†  rš  rr  rK   rK   rL   Úset_linenumbers_enabledÉ  s    z#EditorStack.set_linenumbers_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r  r  r|   Úset_blanks_enabled)rH   r†  rr  rK   rK   rL   r¢  Ð  s    zEditorStack.set_blanks_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r  r  r|   Zset_edge_line_enabled)rH   r†  rr  rK   rK   rL   Úset_edgeline_enabledÖ  s    z EditorStack.set_edgeline_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r  r  r|   Zset_edge_line_column)rH   Úcolumnrr  rK   rK   rL   Úset_edgeline_columnÝ  s    zEditorStack.set_edgeline_columnc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r  r  r|   Zset_codecompletion_auto)rH   r†  rr  rK   rK   rL   Úset_codecompletion_auto_enabledä  s    z+EditorStack.set_codecompletion_auto_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r  r  r|   Zset_codecompletion_case)rH   r†  rr  rK   rK   rL   Úset_codecompletion_case_enabledë  s    z+EditorStack.set_codecompletion_case_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r   r  r|   Zset_codecompletion_enter)rH   r†  rr  rK   rK   rL   Ú set_codecompletion_enter_enabledñ  s    z,EditorStack.set_codecompletion_enter_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r!  r  r|   Zset_calltips)rH   r†  rr  rK   rK   rL   Úset_calltips_enabled÷  s    z EditorStack.set_calltips_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r"  r  r|   Úset_go_to_definition_enabled)rH   r†  rr  rK   rK   rL   rª  þ  s    z(EditorStack.set_go_to_definition_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r#  r  r|   Úset_close_parentheses_enabled)rH   r†  rr  rK   rK   rL   r«    s    z)EditorStack.set_close_parentheses_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r$  r  r|   Úset_close_quotes_enabled)rH   r†  rr  rK   rK   rL   r¬    s    z$EditorStack.set_close_quotes_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r%  r  r|   Úset_add_colons_enabled)rH   r†  rr  rK   rK   rL   r­    s    z"EditorStack.set_add_colons_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r&  r  r|   Úset_auto_unindent_enabled)rH   r†  rr  rK   rK   rL   r®    s    z%EditorStack.set_auto_unindent_enabledc             C   s8   |dd… }|| _ | jr4x| jD ]}|j |¡ q W d S )Nrq   rÁ   )r'  r  r|   Úset_indent_chars)rH   r'  rr  rK   rK   rL   r¯  !  s
    zEditorStack.set_indent_charsc             C   s2   || _ | jr.x | jD ]}||j_ |j ¡  qW d S )N)r(  r  r|   Zupdate_tab_stop_width_spaces)rH   r(  rr  rK   rK   rL   Úset_tab_stop_width_spaces)  s
    z%EditorStack.set_tab_stop_width_spacesc             C   s
   || _ d S )N)r)  )rH   r†  rK   rK   rL   Úset_help_enabled1  s    zEditorStack.set_help_enabledc             C   s<   || _ |d k	r|| _| jr8x| jD ]}|j ||¡ q"W d S )N)r*  r6  r  r|   Zset_font)rH   Úfontr6  rr  rK   rK   rL   Úset_default_font4  s    zEditorStack.set_default_fontc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r6  r  r|   Úset_color_scheme)rH   r6  rr  rK   rK   rL   r´  <  s    zEditorStack.set_color_schemec             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r+  r  r|   Ztoggle_wrap_mode)rH   r†  rr  rK   rK   rL   Úset_wrap_enabledB  s    zEditorStack.set_wrap_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r,  r  r|   Zset_tab_mode)rH   r†  rr  rK   rK   rL   Úset_tabmode_enabledI  s    zEditorStack.set_tabmode_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r-  r  r|   Ztoggle_intelligent_backspace)rH   r†  rr  rK   rK   rL   Ú!set_intelligent_backspace_enabledP  s    z-EditorStack.set_intelligent_backspace_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r0  r  r|   Zset_occurrence_highlighting)rH   r†  rr  rK   rK   rL   Ú#set_occurrence_highlighting_enabledW  s    z/EditorStack.set_occurrence_highlighting_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r1  r  r|   Zset_occurrence_timeout)rH   r;  rr  rK   rK   rL   Ú#set_occurrence_highlighting_timeout^  s    z/EditorStack.set_occurrence_highlighting_timeoutc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r.  r  r|   Zset_highlight_current_line)rH   r†  rr  rK   rK   rL   Ú"set_highlight_current_line_enablede  s    z.EditorStack.set_highlight_current_line_enabledc             C   s,   || _ | jr(x| jD ]}|j |¡ qW d S )N)r/  r  r|   Zset_highlight_current_cell)rH   r†  rr  rK   rK   rL   Ú"set_highlight_current_cell_enabledk  s    z.EditorStack.set_highlight_current_cell_enabledc             C   s
   || _ d S )N)r2  )rH   r†  rK   rK   rL   Úset_checkeolchars_enabledq  s    z%EditorStack.set_checkeolchars_enabledc             C   s
   || _ d S )N)r3  )rH   r†  rK   rK   rL   Ú!set_always_remove_trailing_spacesu  s    z-EditorStack.set_always_remove_trailing_spacesc             C   s
   || _ d S )N)r4  )rH   r†  rK   rK   rL   Úset_focus_to_editory  s    zEditorStack.set_focus_to_editorc             C   s
   || _ d S )N)r7  )rH   r7  rK   rK   rL   Úset_introspector|  s    zEditorStack.set_introspectorc             C   s
   | j  ¡ S )N)r¬   ZcurrentIndex)rH   rK   rK   rL   ry  €  s    zEditorStack.get_stack_indexc             C   s   | j r| j |  ¡  S d S )N)r  ry  )rH   rK   rK   rL   Úget_current_finfoƒ  s    zEditorStack.get_current_finfoc             C   s
   | j  ¡ S )N)r¬   ZcurrentWidget)rH   rK   rK   rL   r  ‡  s    zEditorStack.get_current_editorc             C   s
   | j  ¡ S )N)r¬   r¯   )rH   rK   rK   rL   rŒ  Š  s    zEditorStack.get_stack_countc             C   s    || ks|d kr| j  |¡ d S )N)r¬   ZsetCurrentIndex)rH   r´   ÚinstancerK   rK   rL   r×     s    zEditorStack.set_stack_indexc             C   s   | j  ¡  |¡ d S )N)r¬   rÝ   Ú
setVisible)rH   r†  rK   rK   rL   Úset_tabbar_visible‘  s    zEditorStack.set_tabbar_visiblec             C   s<   | j  d¡ | j  |¡ | j |¡ | j  d¡ |  ¡  d S )NTF)r¬   ÚblockSignalsZ	removeTabr  rs   Úupdate_actions)rH   r´   rK   rK   rL   Úremove_from_data”  s
    zEditorStack.remove_from_datac             C   s,   |d k	r|r|d7 }|d k	r(|r(d| }|S )NÚ*z(%s)rK   )rH   r  Úis_modifiedÚis_readonlyrK   rK   rL   Z__modified_readonly_title›  s
    z%EditorStack.__modified_readonly_titlec             C   s6   dd„ | j D ƒ}| j | j}t ||¡}|  |||¡S )zReturn tab title.c             S   s   g | ]
}|j ‘qS rK   )ry   )r^   rr  rK   rK   rL   ra   ¤  s    z,EditorStack.get_tab_text.<locals>.<listcomp>)r  ry   r-   Zdisambiguate_fnameÚ%_EditorStack__modified_readonly_title)rH   r´   rÈ  rÉ  Zfiles_path_listrw  rK   rK   rL   Úget_tab_text¢  s
    zEditorStack.get_tab_textc             C   sb   d}|   |||¡}| jdk	rF|t | j¡krFttdƒƒ}||| jf S |t |¡t |¡f S dS )zReturn tab menu titleu	   %s â€” %sNzTemporary file)	rÊ  r  r,   Zto_unicode_from_fsr)   r   ÚospÚbasenameÚdirname)rH   ry   rÈ  rÉ  rÔ   Ztemp_file_strrK   rK   rL   Úget_tab_tipª  s    
zEditorStack.get_tab_tipc             C   sd   | j  |¡ | j  |¡}|j}| j |||  |¡¡ |  |d¡ |rX|  |¡ |  	|¡ |  
¡  d S )NF)r  rm   r´   r|   r¬   Z	insertTabrË  Úset_stack_titler×   rØ   rÅ  )rH   rr  rs  r´   r|   rK   rK   rL   Úadd_to_data¶  s    

zEditorStack.add_to_datac             C   sˆ   | j  d¡ | j  ¡  x`| jD ]V}|jr.d}nd }| j |¡}|  ||¡}|  |j¡}| j  	|j
|¡}| j  ||¡ qW | j  d¡ d S )NTF)r¬   rÄ  Úclearr  rz   r´   rË  rÏ  ry   ZaddTabr|   ÚsetTabToolTip)rH   rr  rÈ  r´   Útab_textÚtab_tiprK   rK   rL   Z__repopulate_stackÁ  s    
zEditorStack.__repopulate_stackc       
      C   sÊ   |   |¡}|d krd S | j| }t |j¡d t |¡d krbt|j ¡ ƒ}t||ƒ}|j 	|¡ ||  
¡ k}|  ¡ }||_| j |¡}	|  ¡  |r |  |	¡ n
|  |¡ | jd k	rÆ| j |j|j¡ |	S )Nrq   )Úhas_filenamer  rÌ  Úsplitextry   r)   r|   Úget_text_with_eolr9   Zset_languagery  rô   r´   Ú_EditorStack__repopulate_stackr×   Úset_current_filenamer  Zfile_renamed)
rH   Úoriginal_filenameÚnew_filenamer´   rr  ÚtxtÚlanguageZset_new_indexZcurrent_fnameÚ	new_indexrK   rK   rL   Úrename_in_dataÐ  s&    




zEditorStack.rename_in_datac             C   sx   | j | }|j}|s|jo |j }|j ¡ }|  |||¡}|  |||¡}|| j 	|¡krf| j 
||¡ | j ||¡ d S )N)r  ry   rz   r{   r|   Z
isReadOnlyrË  rÏ  r¬   rÑ   Z
setTabTextrÓ  )rH   r´   rÈ  rr  rw  rÉ  rÔ  rÕ  rK   rK   rL   rÐ  è  s    

zEditorStack.set_stack_titlec             C   sV   | j  ¡  | jr| j}n| j| jf}|  ¡  t| j t|ƒ|  	¡  ƒ | j
 | j¡ dS )z(Setup tab context menu before showing itN)r  rÒ  r  r  r  r  ÚsetFocusr/   rc   rþ   rý   Ú
setEnabledr  )rH   rD  rK   rK   rL   Z__setup_menuø  s    
zEditorStack.__setup_menuc                s´   t ˆ tdƒt d¡tdƒ‡ fdd„dˆ _t ˆ tdƒt d¡td	ƒ‡ fd
d„dˆ _t ˆ tdƒt d¡tdƒ‡ fdd„dˆ _t ˆ tdƒt d¡ˆ jdˆ _d ˆ jd ˆ jˆ jˆ jgS )Nz
New windowZ	newwindowzCreate a new editor windowc                  s
   ˆ j  ¡ S )N)Úcreate_new_windowr‹   rK   )rH   rK   rL   rÃ   	  s    z1EditorStack.__get_split_actions.<locals>.<lambda>)rÓ   rf  ró   zSplit verticallyZversplitz#Split vertically this editor windowc                  s
   ˆ j  ¡ S )N)Úsplit_verticallyr‹   rK   )rH   rK   rL   rÃ     s    zSplit horizontallyZhorsplitz%Split horizontally this editor windowc                  s
   ˆ j  ¡ S )N)Úsplit_horizontallyr‹   rK   )rH   rK   rL   rÃ     s    zClose this panelZclose_panel)rÓ   ró   )	r0   r   rÒ   rÓ   rú   rü   rû   rð   rý   )rH   rK   )rH   rL   Z__get_split_actions  s    



zEditorStack.__get_split_actionsc             C   s   | j  d¡ | j d¡ d S )NT)rû   râ  rü   )rH   rK   rK   rL   Úreset_orientation  s    zEditorStack.reset_orientationc             C   s(   | j  |tjk¡ | j |tjk¡ d S )N)rû   râ  r
   Ú
Horizontalrü   ÚVertical)rH   ÚorientationrK   rK   rL   Úset_orientation  s    zEditorStack.set_orientationc             C   s(   |   ¡ dk}| j |¡ | j |¡ d S )Nr   )rŒ  rû   râ  rü   )rH   r†  rK   rK   rL   rÅ     s    zEditorStack.update_actionsc             C   s   | j r| j |  ¡  jS d S )N)r  ry  ry   )rH   rK   rK   rL   rô   &  s    z EditorStack.get_current_filenamec             C   s:   dd„ }x,t | jƒD ]\}}||ƒ||jƒkr|S qW dS )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.
        c             S   s   t  t  | ¡¡S )N)rÌ  ÚnormcaseÚrealpath)r}   rK   rK   rL   rÃ   4  s    z*EditorStack.has_filename.<locals>.<lambda>N)Ú	enumerater  ry   )rH   ry   Zfixpathr´   rr  rK   rK   rL   rÖ  *  s
    
zEditorStack.has_filenamec             C   s8   |   |¡}|dk	r4|  |¡ | j| j}| ¡  |S dS )z>Set current filename and return the associated editor instanceN)rÖ  r×   r  r|   rá  )rH   ry   r´   r|   rK   rK   rL   rÚ  :  s    

z EditorStack.set_current_filenamec             C   s$   |dkrt | jƒdkS |  |¡S d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.
        Nr   )rt   r  rÖ  )rH   ry   rK   rK   rL   Úis_file_openedC  s    zEditorStack.is_file_openedc             C   s   dd„ | j D ƒ}| |¡S )zn
        Return the position index of a file in the tab bar of the editorstack
        from its name.
        c             S   s   g | ]
}|j ‘qS rK   )ry   )r^   ÚdrK   rK   rL   ra   [  s    z7EditorStack.get_index_from_filename.<locals>.<listcomp>)r  r´   )rH   ry   Ú	filenamesrK   rK   rL   Úget_index_from_filenameV  s    z#EditorStack.get_index_from_filenamec             C   sŠ   |dk s|dk rdS t || ƒ}|| | }| j}|  d¡ x6t|||ƒD ]&}|||  ||  ||< ||| < qJW |  d¡ |  ¡  dS )z\Reorder editorstack.data so it is synchronized with the tab bar when
        tabs are moved.r   NTF)Úabsr  rÄ  r®   r²   )rH   rv   ÚendrÚ   Ú	directionr  r·   rK   rK   rL   rk  ^  s    
&
z!EditorStack.move_editorstack_dataFc       
      C   sv  |   ¡ }|  ¡ }|dkr6|dkr&|}n| j d¡ dS d}|dkrX||krT|  ¡ }n|}|ph| jd|d}|rB| j| }| j |¡ | j	dk	rž| j	 
|j¡ | j| j}|  |¡ | j tt| ƒƒ|¡ | j ¡  | j ¡  |  ¡  | j ¡  | j ¡  |  ¡ }	|	r|	 ¡  |dk	r6||k r,|d8 }|  |¡ |  |j¡ |  ¡ dkrj| jrj| jd  ¡  dS |  ¡  |S )z†Close file (index=None -> close current file)
        Keep current file index unchanged (if current file
        that is being closed)Nr   rq   T)Ú
cancelabler´   rK   F)ry  rŒ  r  Ú
set_editorÚ_get_previous_file_indexÚsave_if_changedr  rx   rj   r  rp  r|   ry   rÆ  Úsig_close_filer‹   r¤   re   Úopened_files_list_changedÚupdate_code_analysis_actionsrŠ  Úrefresh_file_dependent_actionsÚupdate_plugin_titler  rá  r×   Úadd_last_closed_filer5  rJ  Ú _EditorStack__modify_stack_title)
rH   r´   rƒ  Zcurrent_indexr¯   rß  Zis_okrr  ry   r|   rK   rK   rL   r]  s  sN    










zEditorStack.close_filec             C   s   x|   ¡ rqW dS )zClose all opened scriptsN)r]  )rH   rK   rK   rL   r\  °  s    
zEditorStack.close_all_filesc             C   s:   |   ¡ }|  ¡ }x$t||d ƒD ]}|  |d ¡ q W dS )z% Close all files opened to the right rq   N)ry  rŒ  r®   r]  )rH   ZnumÚnr·   rK   rK   rL   r	  µ  s    zEditorStack.close_all_rightc             C   s2   |   ¡  x$td|  ¡ d ƒD ]}|  d¡ qW dS )z#Close all files but the current oner   rq   N)r	  r®   rŒ  r]  )rH   r·   rK   rK   rL   r
  ¼  s    zEditorStack.close_all_but_thisc             C   sB   || j kr| j  |¡ | j  d|¡ t| j ƒdkr>| j  d¡ dS )zAdd to last closed file list.r   é
   rÁ   N)r?  r±   r½   rt   rs   )rH   rw  rK   rK   rL   rþ  Â  s
    
z EditorStack.add_last_closed_filec             C   s   | j S )N)r?  )rH   rK   rK   rL   Úget_last_closed_filesÊ  s    z!EditorStack.get_last_closed_filesc             C   s
   || _ d S )N)r?  )rH   rF  rK   rK   rL   Úset_last_closed_filesÍ  s    z!EditorStack.set_last_closed_filesc       	      C   sv  |dkrt t|  ¡ ƒƒ}n|g}tjtjB }|r:|tjO }d}x(|D ] }| j| j 	¡  
¡ rD|d7 }qDW |spdS |dkrˆ|tjtjB O }d}xä|D ]Ü}|  |¡ | j| }|j| jksº|rÊ|  |¡sÈdS q’|j 	¡  
¡ r’| jr’ttj| jtdƒt |j¡ || d| _| j ¡ }|tjkr.|  |¡sndS q’|tjkrP|  |¡sJdS d}q’|tjkr`dS |tjkr’dS q’W dS )aú  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.
        Nr   rq   TFz<<b>%s</b> has been modified.<br>Do you want to save changes?)rI   )rc   r®   rŒ  r   ÚYesÚNoZCancelr  r|   ÚdocumentÚ
isModifiedZYesAllZNoAllr×   ry   r  rZ  rC  ÚQuestionr  r   rÌ  rÍ  r@  Úexec_)	rH   rõ  r´   ZindexesZbuttonsZ
unsaved_nbZyes_allrr  ÚanswerrK   rK   rL   rø  Ñ  sV    








zEditorStack.save_if_changedc          
   C   s|  |dkr|   ¡ sdS |  ¡ }| j| }|j ¡  ¡ sB|jsB|sBdS t |j	¡s^|s^| j
|dS | jrn|  |¡ t|j ¡ ƒ}yœt ||j	|j¡|_d|_| j |j¡ t|j	ƒ ¡ |_| j tt| ƒƒ|j	|j	¡ |j ¡  d¡ | j|d |  |¡ | j ¡  |j ¡  |  |¡ dS  t k
rv } z>t!t!j"t#dƒt#dƒt $|j	¡t|ƒf | d| _%| j% &¡  dS d}~X Y nX dS )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´   Fz
Save Errorz;<b>Unable to save file '%s'</b><br><br>Error message:<br>%s)rI   )'rŒ  ry  r  r|   r  r  rz   rÌ  Úisfilery   rb  r3  Úremove_trailing_spacesr)   rØ  r,   ÚwriteÚencoding_changedr‹   r   r   r‚   Ú
file_savedr¤   re   ÚsetModifiedÚmodification_changedr<  r7  ÚvalidateÚrehighlightrŠ  ÚEnvironmentErrorr   ÚCriticalr   rÍ  r@  r	  )rH   r´   rƒ  rr  rÝ  ÚerrorrK   rK   rL   rZ    sL    












zEditorStack.savec             C   sD   |   |¡}|dkrdS | j| }d|_t|ƒ|_t|jƒ ¡ |_dS )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
        issue 5703.
        Filename is passed in case file was just saved as another name.
        NF)rÖ  r  rz   r)   ry   r   r   r‚   )rH   rÛ  ry   r´   rr  rK   rK   rL   Úfile_saved_in_other_editorstack]  s    



z+EditorStack.file_saved_in_other_editorstackc             C   sž   | j dkrtƒ | _ | jdkr$tƒ | _tƒ r:tƒ s:d}d}n| j}t| j t |¡d ƒ}| j	 
d¡ t| tdƒ|||tjd\}}| j	 
d¡ |ršt |¡S dS )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.
        NrŽ   rq   Fz	Save file)ÚfiltersÚselectedfilterZoptionsT)rA  r#   rB  r$   r&   r'   r%   rÌ  r×  Úredirect_stdior‹   r   r   r   ZHideNameFilterDetailsÚnormpath)rH   rÛ  r  r  ry   Z
_selfilterrK   rK   rL   Úselect_savenameo  s(    



zEditorStack.select_savenamec             C   sÀ   |dkr|   ¡ }| j| }d|_|j}|  |¡}|r¸|  |¡}|dk	rl||krl|  |¡s\dS ||k rl|d8 }| j||d}| j 	t
t| ƒƒ||¡ | j|dd}|  |¡ |  |¡ |S dS dS )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.
        NTrq   )rÜ  )r´   rƒ  F)ry  r  rz   ry   r  rÖ  r]  rà  Úfile_renamed_in_datar‹   r¤   re   rZ  r²   r×   )rH   r´   rr  rÛ  ry   Úao_indexrß  ÚokrK   rK   rL   rb  •  s,    





zEditorStack.save_asc          
   C   sþ   |dkr|   ¡ }| j| }|j}|  |¡}|rö|  |¡}|dk	rf||krf|  |¡sVdS ||k rf|d8 }t|j ¡ ƒ}y"t	 
|||j	¡|_	| j |¡ dS  tk
rò } z>ttjtdƒtdƒt |j¡t|ƒf | d| _| j ¡  W dd}~X Y qúX ndS dS )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.
        Nrq   Tz
Save Errorz;<b>Unable to save file '%s'</b><br><br>Error message:<br>%s)rI   F)ry  r  ry   r  rÖ  r]  r)   r|   rØ  r,   r  rK  r‹   r  r   r  r   rÌ  rÍ  r¤   r@  r	  )rH   r´   rr  rÛ  ry   r  rÝ  r  rK   rK   rL   Úsave_copy_asÍ  s6    






zEditorStack.save_copy_asc             C   s8   x2t |  ¡ ƒD ]"}| j| j ¡  ¡ r|  |¡ qW dS )ziSave all opened files.

        Iterate through self.data and call save() on any modified files.
        N)r®   rŒ  r  r|   r  r  rZ  )rH   r´   rK   rK   rL   r[    s    zEditorStack.save_allc             C   s$   d| _ | jr | j ¡  | j ¡  d S )NF)r  r  r9  Ústoprv   )rH   rK   rK   rL   Ústart_stop_analysis_timer  s    
z%EditorStack.start_stop_analysis_timerc             C   sd   | j r
dS |dkr|  ¡ }| jrZ| j| }| j| j }}|s@|rL| ||¡ | jrZ| ¡  d| _ dS )z1Analyze current script with pyflakes + find todosNT)r  ry  r  r  r  r—   r  r   )rH   r´   rr  r”   r•   rK   rK   rL   r<    s    
zEditorStack.analyze_scriptc             C   s*   |   |¡}|dkrdS | j|  |¡ dS )z1Synchronize analysis results between editorstacksN)rÖ  r  r™   )rH   ry   r   r´   rK   rK   rL   r™      s    
z EditorStack.set_analysis_resultsc             C   s   | j r| j |  ¡  jS d S )N)r  ry  r   )rH   rK   rK   rL   Úget_analysis_results'  s    z EditorStack.get_analysis_resultsc             C   s*   |   |¡}|dkrdS | j|  |¡ dS )z-Synchronize todo results between editorstacksN)rÖ  r  rž   )rH   ry   r€   r´   rK   rK   rL   rž   +  s    
zEditorStack.set_todo_resultsc             C   s   | j r| j |  ¡  jS d S )N)r  ry  r€   )rH   rK   rK   rL   Úget_todo_results2  s    zEditorStack.get_todo_resultsc             C   sô   |   ¡ }|dkr,| ¡  tr6td|td n
| j ¡  | j ¡  | j 	¡  x|| jkrd| j 
|¡ qLW | j |¡ tr¨td|| j| jdtd t| j| j ¡ td | j ¡  |dk	rðy | j | j| j| d¡¡ W n tk
rî   Y nX dS )	zStack index has changedrÁ   zsetfocusto:)rM   zcurrent_changed:ú )ró  rM   Nr‰   )r  rá  rO   rb   r   Úreset_statusbarr‹   rú  rÇ   r²   r±   rm   r  r|   Zget_document_idrý  Úcurrent_file_changedry   rŒ   r¶   )rH   r´   r|   rK   rK   rL   rØ   6  s*    



zEditorStack.current_changedc             C   s$   y
| j d S  tk
r   dS X dS )z4Return the penultimate element of the stack history.éþÿÿÿN)rÇ   r¶   )rH   rK   rK   rL   r÷  X  s    
z$EditorStack._get_previous_file_indexTc             C   s>   t | | j| jƒ| _| j ¡  | j |r*dnd¡ | j ¡  dS )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
        rq   rÁ   N)r¿   rÇ   r¬   r  r|  rÂ   rá  )rH   rG  rK   rK   rL   rH  _  s
    

zEditorStack.tab_navigation_mruc             C   s8   t  ¡ }x | jD ]}||jkr|  ¡  qW | j ¡  dS )zEditor focus has changedN)r   ÚfocusWidgetr  r|   r²   Úeditor_focus_changedr‹   )rH   Zfwidgetrr  rK   rK   rL   Úfocus_changedp  s
    
zEditorStack.focus_changedc             C   sv   | j }|dkrdS |dkr"|  ¡ }d}| jrd| j| }|j ¡ rdd}| d¡ |j|j|j||d |sr| d¡ dS )zRefresh outline explorer panelNFT)ÚupdaterÒ  )r  ry  r  r|   r   râ  Zset_current_editorry   )rH   r´   r,  rÒ  ZoeÚenablerr  rK   rK   rL   rŠ  x  s    



z$EditorStack._refresh_outlineexplorerc             C   s8   | j | }| j |j¡ |j ¡ \}}| j ||¡ dS )zRefreshing statusbar widgetsN)r  r  r‹   r,   r|   Zget_cursor_line_columnÚ"sig_editor_cursor_position_changed)rH   r´   rr  r€  rK   rK   rL   Z__refresh_statusbarŠ  s    
zEditorStack.__refresh_statusbarc             C   sF   | j | }t|jƒ ¡  }t |j¡s*d}|j |¡ | j 	|¡ d S )NF)
r  r   ry   Z
isWritablerÌ  r  r|   ZsetReadOnlyÚreadonly_changedr‹   )rH   r´   rr  Z	read_onlyrK   rK   rL   Z__refresh_readonly’  s    
zEditorStack.__refresh_readonlyc             C   sD  | j r
dS d| _ | j| }t |j¡}|jr0n
t |j¡s¦ttj| j	t
dƒ| tjtjB | ƒ| _| j ¡ }|tjkr‚|  |¡ n"d|_|j ¡  d¡ | j|d n”t|jƒ ¡ }t| ¡ ƒt|j ¡ ƒkr:|j ¡  ¡ r0ttj| j	t
dƒ| tjtjB | ƒ| _| j ¡ }|tjkr(|  |¡ n||_n
|  |¡ d| _ dS )zCheck if file has been changed in any way outside Spyder:
        1. removed, moved or renamed outside Spyder
        2. modified outside SpyderNTzx<b>%s</b> is unavailable (this file may have been removed, moved or renamed outside Spyder).<br>Do you want to close it?)r´   zb<b>%s</b> has been modified outside Spyder.<br>Do you want to reload it and lose all your changes?F)r8  r  rÌ  rÍ  ry   rz   r  r   ÚWarningr  r   r  r  r@  r	  r]  r|   r  r  r  r   r   r)   ZtoStringr‚   r  r  Úreload)rH   r´   rr  rÆ   r
  ZlastmrK   rK   rL   Z__check_file_status›  sL    







zEditorStack.__check_file_statusc             C   s6   x0t | jƒD ]"\}}|j ¡  ¡ }|  ||¡ qW d S )N)rí  r  r|   r  r  rÐ  )rH   r´   rr  r†  rK   rK   rL   Z__modify_stack_titleÚ  s    z EditorStack.__modify_stack_titlec             C   s¢   |dkr|   ¡ }|  ¡ r‚|   ¡ }| j| }|j}| ¡  | j|dd | j ¡  |  |¡ |  	|¡ |  
|¡ |  ¡  | j ¡  nd}|  ¡  | jj|dd dS )zRefresh tabwidgetNF)r,  )r²   )ry  rŒ  r  r|   rá  rŠ  rû  r‹   Ú_EditorStack__refresh_statusbarÚ_EditorStack__refresh_readonlyÚ_EditorStack__check_file_statusrÿ  rý  r  r  rö  )rH   r´   rr  r|   rK   rK   rL   r²   ß  s"    




zEditorStack.refreshc             C   sÀ   |dk	r0x&t | jƒD ]\}}t|jƒ|krP qW | j ¡  |dkrJ|  ¡ }|dkrVdS | j| }|dkr||j ¡  ¡ pz|j	}|  
||¡ | j |¡ | j ¡  |j ¡ }|  |¡ | j ¡  dS )z³
        Current editor's modification state has changed
        --> change tab title depending on new modification state
        --> enable/disable save/save all actions
        NrÁ   )rí  r  re   r|   rú  r‹   ry  r  r  rz   rÐ  r  râ  Úrefresh_save_all_actionÚget_line_separatorÚrefresh_eol_charsrÇ   r²   )rH   r†  r´   Ú	editor_idZ_finforr  Ú	eol_charsrK   rK   rL   r  ÷  s$    




z EditorStack.modification_changedc             C   s   t  |¡}| j |¡ d S )N)r-   Zget_os_name_from_eol_charsÚsig_refresh_eol_charsr‹   )rH   r9  Zos_namerK   rK   rL   r7    s    
zEditorStack.refresh_eol_charsc             C   s‚   | j | }t |j¡\}|_t|jƒ ¡ |_|j d¡}|j 	|¡ |j 
¡  d¡ |j |¡ | j ¡  |j ¡  |  |¡ dS )zReload file from diskr‰   FN)r  r,   Úreadry   r   r   r‚   r|   rŒ   Úset_textr  r  Úset_cursor_positionr7  r  r  rŠ  )rH   r´   rr  rÝ  r…  rK   rK   rL   r1    s    


zEditorStack.reloadc             C   sx   |   ¡ }| j| }|j}|j ¡  ¡ rjttj| jt	dƒt
 |¡ tjtjB | ƒ| _| j ¡ }|tjkrjdS |  |¡ dS )zRevert file from diskzOAll changes to <b>%s</b> will be lost.<br>Do you want to revert file from disk?N)ry  r  ry   r|   r  r  r   r0  r  r   rÌ  rÍ  r  r  r@  r	  r1  )rH   r´   rr  ry   r
  rK   rK   rL   Úrevert/  s    




zEditorStack.revertc       
         s~  t  ˆ¡‰ ˆj}ˆ j |j¡ ˆ j |j¡ ˆ j |j¡ t||ˆ |ˆj	ˆjƒ}ˆ 
||¡ |j ˆj¡ |j ‡fdd„¡ |j ‡fdd„¡ |j ‡fdd„¡ |j ‡fdd„¡ ˆ j ˆj¡ ˆ j ˆj¡ ˆ j ˆj¡ ˆ j ˆj¡ ˆ j ˆjj¡ t||ƒ}	ˆ 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||d |dkr¤ˆ  1|¡ ˆ  2¡  3d¡ |j4 ‡fd	d„¡ ˆ j5 ˆj6¡ ˆ j7 ˆj8¡ ˆ j9 ‡ ‡fd
d„¡ ˆ j: ˆj;¡ ˆ j< ‡fdd„¡ ˆ j= ‡fdd„¡ ˆ j> ‡fdd„¡ ˆ j? ‡fdd„¡ ˆj@ Aˆ ¡ ˆjB ¡  ˆjCˆjD E|¡d ˆ  F¡  |S )zw
        Create a new editor instance
        Returns finfo object (instead of editor as in previous releases)
        c                  s
   ˆ j  ¡ S )N)rš   r‹   rK   )rH   rK   rL   rÃ   T  s    z/EditorStack.create_new_editor.<locals>.<lambda>c                  s
   ˆ j  ¡ S )N)rŸ   r‹   rK   )rH   rK   rL   rÃ   V  s    c                s   ˆ j  | ||¡S )N)r¦   r‹   )rw  ÚlinenorÆ   )rH   rK   rL   rÃ   W  s    c                s   ˆ j  | |¡S )N)r¢   r‹   )Ús1Ús2)rH   rK   rL   rÃ   Y  s    )r–  Zshow_blanksZ	edge_lineZedge_line_columnrÞ  r—  r²  r6  ZwrapZtab_modeZintelligent_backspaceZhighlight_current_lineZhighlight_current_cellZoccurrence_highlightingZoccurrence_timeoutZcodecompletion_autoZcodecompletion_caseZcodecompletion_enterZcalltipsÚgo_to_definitionZclose_parenthesesZclose_quotesZ
add_colonsZauto_unindentr'  r(  rt  ry   NFc                s   ˆ j  | |¡S )N)rŠ   r‹   )rw  r…  )rH   rK   rL   rÃ     s    c                s   ˆj | tˆ ƒdS )N)r8  )r  re   )r†  )r|   rH   rK   rL   rÃ   …  s   c                  s
   ˆ j  ¡ S )N)rP  r‹   rK   )rH   rK   rL   rÃ   ˆ  s    c                  s
   ˆ j  ¡ S )N)rQ  r‹   rK   )rH   rK   rL   rÃ   ‰  s    c                  s
   ˆ j  ¡ S )N)rR  r‹   rK   )rH   rK   rL   rÃ   Š  s    c                s
   ˆ   | ¡S )N)r7  )r9  )rH   rK   rL   rÃ   ‹  s    )r´   )Gr6   Z
CodeEditorr7  Zget_completionsru   Zsig_show_object_infor„  rB  rw   rx   rÑ  r¨   rš   rŸ   r¦   r¢   rY  r^  r_  r`  rJ  r‹   r9   Zsetup_editorr  r  r  r  r˜  r*  r6  r+  r,  r-  r.  r/  r0  r1  r  r  r   r!  r"  r#  r$  r%  r&  r'  r(  r<  r  r  rŠ   Zsig_cursor_position_changedÚeditor_cursor_position_changedrƒ   r"  ZmodificationChangedZfocus_inr+  rP  rQ  rR  Zsig_eol_chars_changedr  rö  rü  r  r  r´   Zrun_pygments_highlighter)
rH   rw  r–   rÝ  rs  rˆ   rt  r7  rr  rÞ  rK   )r|   rH   rL   ru  B  s†    





zEditorStack.create_new_editorc             C   s   | j  ||¡ dS )z=Cursor position of one of the editor in the stack has changedN)r.  r‹   )rH   r€  r´   rK   rK   rL   rC  ˜  s    z*EditorStack.editor_cursor_position_changedc             C   s¦   |s| j sdS | jdk	r¢|s(| jj ¡ r¢|dkrD| jj|d|d nNt|ƒ}| d¡d }t|ƒ}t|ƒ}	t|ƒ}
||||	|
dœ}| jj||d |  ¡ }| 	¡  dS )z>qstr1: obj_text, qstr2: argpspec, qstr3: note, qstr4: doc_textNT)Zignore_unknownÚforce_refreshÚ.rÁ   )Zobj_textrÆ   ÚargspecÚnoteÚ	docstring)rD  )
r)  r  Z
dockwidgetrã   Zset_object_textr)   rä   Zset_editor_docr  rá  )rH   Zqstr1Zqstr2Zqstr3Zqstr4rƒ  ZobjtxtrÆ   rF  rG  rH  Údocr|   rK   rK   rL   r¨   œ  s"    




zEditorStack.send_to_helpc             C   sP   | j |||ddd}|j d¡ |s2|j tj¡ |rLd|_|j ¡  d¡ |S )z@
        Create new filename with *encoding* and *text*
        FT)rs  rˆ   Úeof)	ru  r|   r=  Úinsert_textÚosÚlinesepr{   r  r  )rH   ry   r,   rÔ   Zdefault_contentÚemptyrr  rK   rK   rL   rˆ   ³  s    

zEditorStack.newc             C   sÆ   t  t|ƒ¡}| j tdƒ| ¡ t |¡\}}|  ||||¡}| j	 
|¡}| j|dd | j d¡ |  ¡ r¼| jr¼t |¡r¼t  |¡}ttj| jtdƒ| tj| ƒ| _| j ¡  |  |¡ d| _|S )a"  
        Load filename, create an editor instance and return it
        *Warning* This is loading file, creating editor but not executing
        the source code analysis -- the analysis must be done by the editor
        plugin (in case multiple editorstack instances are handled)
        zLoading %s...T)r,  rŽ   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;  ru  r  r´   rŠ  Úending_long_processrã   r2  r-   Zhas_mixed_eol_charsrÍ  r   r0  r  ZOkr@  r	  Úset_os_eol_charsr  )rH   ry   rs  rÔ   r–   rr  r´   rÆ   rK   rK   rL   ÚloadÂ  s*    



zEditorStack.loadc             C   sF   |d kr|   ¡ }| j| }t tj¡}|j |¡ |j ¡  	d¡ d S )NT)
ry  r  r-   Zget_eol_chars_from_os_namerL  rÆ   r|   Zset_eol_charsr  r  )rH   r´   rr  r9  rK   rK   rL   rR  à  s    
zEditorStack.set_os_eol_charsc             C   s(   |dkr|   ¡ }| j| }|j ¡  dS )zRemove trailing spacesN)ry  r  r|   r  )rH   r´   rr  rK   rK   rL   r  è  s    
z"EditorStack.remove_trailing_spacesc             C   s(   |dkr|   ¡ }| j| }|j ¡  dS )z Replace tab characters by spacesN)ry  r  r|   Úfix_indentation)rH   r´   rr  rK   rK   rL   rT  ï  s    
zEditorStack.fix_indentationc             C   sz   |   ¡  ¡ }|r$| j || j¡ dS |   ¡ }| ¡ }| ¡ }|rP| j || j¡ | ¡ rj|rj| | 	¡ ¡ | 
dd¡ dS )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€  Zdown)r  Z get_selection_as_executable_codeÚexec_in_extconsoler‹   r4  Zget_current_lineÚlstripZis_cursor_on_last_linerm   r6  Zmove_cursor_to_next)rH   rÔ   r|   r€  rK   rK   rL   rY  ÷  s    zEditorStack.run_selectionc             C   s6   |   ¡  ¡ }|  ¡ }|j ¡ r2|r2| j || j¡ dS )zRun current cellN)r  Zget_cell_as_executable_coderÀ  r|   r   rU  r‹   r4  )rH   rÔ   rr  rK   rK   rL   r^  	  s    zEditorStack.run_cellc             C   s   |   ¡  |  ¡  dS )z,Run current cell and advance to the next oneN)r^  rT  )rH   rK   rK   rL   r_  	  s    z EditorStack.run_cell_and_advancec             C   sX   |s|   ¡ j}n
|   ¡ j}| jr(|ƒ  n,t ¡ }|ƒ  | ¡  t ¡ }|ƒ  | ¡  dS )zSAdvance to the next cell.

        reverse = True --> go to previous cell.
        N)r  rc  rd  r4  r   r)  rá  )rH   rS  Z	move_funcZtermrK   rK   rL   rT  	  s    
zEditorStack.advance_cellc             C   s6   |   ¡  ¡ }|  ¡ }|j ¡ r2|r2| j || j¡ d S )N)r  Z get_last_cell_as_executable_coderÀ  r|   r   rU  r‹   r4  )rH   rÔ   rr  rK   rK   rL   r`  0	  s    zEditorStack.re_run_last_cellc             C   s„   |  ¡ }| ¡ rR| ¡ rRt|ƒrRt|ƒ}dd„ |D ƒ}t|ƒrH| ¡  q€| ¡  n.| ¡ rd| ¡  ntj	dkrx| ¡  n| ¡  dS )zWReimplement Qt method
        Inform Qt about the types of data that the widget acceptsc             S   s   g | ]}t  |¡‘qS rK   )r,   Úis_text_file)r^   ZurlrK   rK   rL   ra   B	  s    z.EditorStack.dragEnterEvent.<locals>.<listcomp>ÚntN)
ÚmimeDataÚhasUrlsZurlsr2   ÚanyÚacceptProposedActionrì   ÚhasTextrL  rÆ   )rH   rè   ÚsourceZall_urlsrÔ   rK   rK   rL   ÚdragEnterEvent7	  s    




zEditorStack.dragEnterEventc             C   s’   |  ¡ }| ¡ rVt|ƒrVt|ƒ}dd„ |D ƒ}t|p6g ƒ}xJ|D ]}| j |¡ q@W n0| ¡ r~|  ¡ }|dk	r†| | 	¡ ¡ n| 
¡  | ¡  dS )z?Reimplement Qt method
        Unpack dropped data and handle itc             S   s   g | ]}t  |¡r|‘qS rK   )r,   rW  )r^   ÚfrK   rK   rL   ra   [	  s    z)EditorStack.dropEvent.<locals>.<listcomp>N)rY  rZ  r2   ÚsetrK  r‹   r]  r  rK  rÔ   rì   r\  )rH   rè   r^  Úfilesrw  r|   rK   rK   rL   Ú	dropEventR	  s    
zEditorStack.dropEvent)N)N)N)N)N)N)N)N)NN)NN)N)NF)FN)NF)N)N)N)T)NTF)N)NNN)FN)NNNF)FF)T)N)N)N)F)´rS   rT   rU   r   r&  r§   r/  r¤   r  r¥   r.  r:  rP  rQ  r  rU  rý  r*  rP  rQ  rR  rù  r  r  rã  rú  rš   rŸ   rû  rü  r5  r¢   rŠ   r'  rK  r¦   rä  rå  rJ  rL  rM  rN  rO  rD   r   r@   r=  re  r  ro  rq  rx  r{  r  r  r~  rX  rV  rW  rU  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¾  r¿  ry  rÀ  r  rŒ  r×   rÃ  rÆ  rÊ  rË  rÏ  rÑ  rÙ  rà  rÐ  ri  rþ   ræ  rê  rÅ  rô   rÖ  rÚ  rî  rñ  rk  r]  r\  r	  r
  rþ  r  r  rø  rZ  r  r  rb  r   r[  r"  r<  r™   r#  rž   r$  rØ   r÷  rH  r+  rŠ  r2  r3  r4  rÿ  r²   r  r7  r1  r>  ru  rC  r¨   rˆ   rS  rR  r  rT  rY  r^  r_  rT  r`  r_  rc  rK   rK   rK   rL   rò   µ  sb  





 m	8

	=AK&84
"	? U  rò   c               @   s\   e Zd Zddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zej	fdd„Z
dd„ Zdd„ Zdd„ ZdS )ÚEditorSplitterFNc                sä   t  ˆ |¡ ˆ  tj¡ ˆ  d¡ d ˆ _d ˆ _|ˆ _|d krDˆ jj	}|ˆ _
|d krZˆ jj}|ˆ _|ˆ _tˆ |ƒˆ _ˆ  
ˆ j¡ |s’ˆ jjˆ jd ˆ jj ‡ fdd„¡ ˆ jj ‡ fdd„¡ ˆ jj ‡ fdd„¡ ˆ  ˆ j¡ d S )NF)Úeditorstackc                  s   ˆ   ¡ S )N)Úeditorstack_closedrK   )rH   rK   rL   rÃ   €	  s    z)EditorSplitter.__init__.<locals>.<lambda>c                  s   ˆ j tjdS )N)ré  )rä   r
   rè  rK   )rH   rK   rL   rÃ   ‚	  s    c                  s   ˆ j tjdS )N)ré  )rä   r
   rç  rK   )rH   rK   rL   rÃ   „	  s    )r   rD   rø   r
   rù   ZsetChildrenCollapsibleÚtoolbar_listÚ	menu_listÚpluginÚregister_editorstackÚregister_editorstack_cbÚunregister_editorstackÚunregister_editorstack_cbr  rò   re  Úclone_editorstackÚ	destroyedru   rä  rå  rm  )rH   rI   ri  r  Úfirstrk  rm  rK   )rH   rL   rD   i	  s.    
zEditorSplitter.__init__c             C   s   t  | |¡ d S )N)r   rq  )rH   rè   rK   rK   rL   rq  ‡	  s    zEditorSplitter.closeEventc             C   s   | j  ¡ }|d k	r| ¡  d S )N)ri  Úget_focus_widgetrá  )rH   Zfocus_widgetrK   rK   rL   Z __give_focus_to_remaining_editorŠ	  s    
z/EditorSplitter.__give_focus_to_remaining_editorc             C   sr   t rtdtd td| td y"|  | j¡ d | _|  ¡ dk}W n tk
rT   d S X |rf|  ¡  d S |  ¡  d S )Nzmethod 'editorstack_closed':)rM   z    self  :rq   )	rO   rb   r   rm  re  r¯   ÚRuntimeErrorrð   Ú/_EditorSplitter__give_focus_to_remaining_editor)rH   Úclose_splitterrK   rK   rL   rf  	  s    z!EditorSplitter.editorstack_closedc             C   s†   t rtdtd td| td y|  ¡ dko4| jd k}W n tk
rL   d S X |r^|  ¡  d S |  ¡ dkrz| jrz| j ¡  |  ¡  d S )Nzmethod 'editorsplitter_closed':)rM   z    self  :rq   rY   )	rO   rb   r   r¯   re  rr  rð   ræ  rs  )rH   rt  rK   rK   rL   Úeditorsplitter_closed¢	  s    
z$EditorSplitter.editorsplitter_closedc                sp   ˆ   |¡ ˆ j |¡ tˆ  ¡ ˆ jˆ jˆ jˆ jd}ˆ  	|¡ |j
 ‡ fdd„¡ |j ¡ }|d k	rl| ¡  d S )N)rk  rm  c                  s   ˆ   ¡ S )N)ru  rK   )rH   rK   rL   rÃ   ¿	  s    z&EditorSplitter.split.<locals>.<lambda>)ZsetOrientationre  rê  rd  rI   ri  r  rk  rm  rm  ro  ru   r  rá  )rH   ré  ÚeditorsplitterZcurrent_editorrK   )rH   rL   rä   ·	  s    



zEditorSplitter.splitc             C   s:   |   d¡|  ¡ fg}|  ¡ dkr6|   d¡}|| ¡ 7 }|S )Nr   rq   )r­   ré  r¯   Úiter_editorstacks)rH   Úeditorstacksrv  rK   rK   rL   rw  Ä	  s
    
z EditorSplitter.iter_editorstacksc             C   sx   g }xX|   ¡ D ]L\}}g }d}d}t|dƒrDdd„ |jD ƒ}| ¡ }| |tjk||f¡ qW tt|  	¡ ƒ|  
¡ |dS )zReturn layout staterŽ   Fr  c             S   s   g | ]}|j  ¡ ‘qS rK   )r|   Zget_cursor_line_number)r^   rr  rK   rK   rL   ra   Ó	  s   z6EditorSplitter.get_layout_settings.<locals>.<listcomp>)ÚhexstateÚsizesÚsplitsettings)rw  rl  r  rô   rm   r
   rè  Údictr(   Ú	saveStaterz  )rH   r{  re  ré  ÚclinesÚcfnamerK   rK   rL   Úget_layout_settingsË	  s    

z"EditorSplitter.get_layout_settingsc          
   C   s&  |  d¡}|dkrdS | }d}xœt|ƒD ]\}\}}}|dkr^| |rLtjntj¡ | d¡}| d¡}	xDt|	jƒD ]6\}}
|
j}y| 	|| ¡ W qt t
k
r¨   Y qtX qtW |	 |¡ q(W |  d¡}|dk	rê|  tƒ  t|ƒ d¡¡¡ |  d¡}|dk	r|  |¡ |dk	r"| ¡  | ¡  dS )zRestore layout stater{  Nr   rq   ry  zutf-8rz  )rf   rí  rä   r
   rè  rç  r­   r  r|   rX  r¶   rÚ  ÚrestoreStater   ÚfromHexr¤   r‘   ZsetSizesZ
clearFocusrá  )rH   Úsettingsr{  Úsplitterr|   r´   Zis_verticalr  r~  re  rr  ry  rz  rK   rK   rL   Úset_layout_settingsÚ	  s6    









z"EditorSplitter.set_layout_settings)FNN)rS   rT   rU   rD   rq  rs  rf  ru  r
   rè  rä   rw  r€  r…  rK   rK   rK   rL   rd  h	  s    
rd  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚEditorWidgetc                sZ  t  ˆ|¡ ˆ tj¡ | ¡ }tˆ|ƒˆ_tˆ|ƒˆ_	t
ˆ|ƒˆ_tˆ|ƒˆ_g ˆ_ˆ ˆ_tˆddˆ_ˆj ˆj¡ ˆj ¡  tˆ|||dˆ_ˆjj ‡ ‡fdd„¡ tˆƒ}tƒ }	|	 dddd¡ | |	¡ tˆˆ |ˆjˆjd}
|
ˆ_|	  |
¡ |	  ˆj¡ t ˆƒ}| dddd¡ |  |¡ |  ˆj¡ | !dd¡ | !d	d	¡ |
j" #¡  d S )
NT)Úenable_replace)Úshow_fullpathÚshow_all_filesÚshow_commentsc                s   ˆ j | ||ˆ ¡ dS )N)rð  ÚgotoÚwordZeditorwindow)rS  rI   )rð  r‹  rŒ  )ri  rH   rK   rL   rÃ   
  s    
z'EditorWidget.__init__.<locals>.<lambda>r   )rk  rm  rŽ  rq   )$r   rD   rø   r
   rù   Z	statusBarr=   Úreadwrite_statusr<   Ú
eol_statusr;   Úencoding_statusr:   Úcursorpos_statusrx  ri  r5   r  Úregister_widget_shortcutsrÙ   r3   r  r¦   ru   r   r   rÿ   r   rd  rj  rl  rv  rm  ÚsetStretchFactorre  r  )rH   rI   ri  r  rˆ  r‰  rŠ  Z	statusbarÚeditor_widgetsÚeditor_layoutrv  r„  rK   )ri  rH   rL   rD   û	  sF    





zEditorWidget.__init__c             C   s  | j  |¡ tr&td|td |  ¡  || jj|  ¡ < | 	t
| j ƒdk¡ | | j¡ | | j¡ |j | jj¡ |j | jj¡ |j | jj¡ |j | jj¡ |j | jj¡ |j | jj¡ |j | jj¡ | j |¡ t| ƒ}| | jj¡ |  d|g¡ d S )Nz"EditorWidget.register_editorstack:)rM   rq   rŽ  )!rx  rm   rO   rb   r   Ú!_EditorWidget__print_editorstacksri  Úlast_focus_editorstackrI   r‡  rt   r‹  r  r‰  r  r&  ru   r  rÙ   r  r  r/  r  r.  Zcursor_position_changedr:  rŽ  Zeol_changedrj  r1   r  r  ro  )rH   re  r‘  rK   rK   rL   rj  +
  s,    


z!EditorWidget.register_editorstackc             C   s8   t dt| jƒ td x| jD ]}t d|td qW d S )Nz"%d editorstack(s) in editorwidget:)rM   z    )rb   rt   rx  r   )rH   ZedstrK   rK   rL   Z__print_editorstacksC
  s    z!EditorWidget.__print_editorstacksc             C   sB   t rtd|td | j |¡ | j | j |¡¡ t r>|  ¡  d S )Nz$EditorWidget.unregister_editorstack:)rM   )	rO   rb   r   ri  rl  rx  rs   r´   r•  )rH   re  rK   rK   rL   rl  I
  s    z#EditorWidget.unregister_editorstackN)rS   rT   rU   rD   rj  r•  rl  rK   rK   rK   rL   r†  ú	  s   0r†  c               @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚEditorMainWindowc             C   sN  t  | ¡ |  tj¡ d | _t| |||||ƒ| _|  | j¡ | jj	j
}| ¡ }	|	d k	r^|	 ¡  |  d| ¡  ¡ |  | ¡ ¡ |rÆg | _x<|D ]4\}
}}|  |
¡}| |¡ t||ƒ | j |¡ qŽW |rJt| tdƒdtdƒ| jd}g | _xZt|ƒD ]N\}\}
}|  ¡  |
¡}|dkr0t||d |g ƒ n
t||ƒ | j |¡ qøW d S )NzSpyder - %szClose windowzclose_panel.pngzClose this window)rÓ   rf  ró   r   )r   rD   rø   r
   rù   Úwindow_sizer†  ÚeditorwidgetZsetCentralWidgetrv  re  r  rá  ZsetWindowTitleZwindowTitleZsetWindowIconZ
windowIconÚtoolbarsZ
addToolBarrj  r/   rm   r0   r   rð   Úmenusrí  ZmenuBarZaddMenu)rH   ri  r  rg  rh  rˆ  r‰  rŠ  re  r|   r  Zobject_namerD  ÚtoolbarZquit_actionr´   r  rK   rK   rL   rD   S
  s@    








zEditorMainWindow.__init__c             C   s   | j S )zGet the toolbars.)rš  )rH   rK   rK   rL   Úget_toolbars~
  s    zEditorMainWindow.get_toolbarsc             C   sL   | j d }|| jkrH|rHg }x | jD ]}| ¡ }| |¡ q$W t||ƒ dS )zAdd toolbars to a menu.é   N)r›  rš  ÚtoggleViewActionrm   r/   )rH   Z
menu_titlerD  Z	view_menurš  rœ  ÚactionrK   rK   rL   Úadd_toolbars_to_menu‚
  s    
z%EditorMainWindow.add_toolbars_to_menuc             C   s†   t jddg d}|r‚i }x2| jD ](}||| ¡ < | ¡  d¡ | d¡ q W x4|D ],}||krR||  ¡  d¡ ||  d¡ qRW dS )z3Loads the last visible toolbars from the .ini file.rÀ   Zlast_visible_toolbars)r{   FTN)r?   rf   rš  Z
objectNamerŸ  Z
setCheckedrÂ  )rH   Ztoolbars_namesZdicrœ  rÆ   rK   rK   rL   Úload_toolbarsŽ
  s    
zEditorMainWindow.load_toolbarsc             C   s*   |   ¡ s|  ¡ s|  ¡ | _t | |¡ dS )zReimplement Qt methodN)ÚisMaximizedÚisFullScreenrÍ   r˜  r   ÚresizeEvent)rH   rè   rK   rK   rL   r¥  œ
  s    
zEditorMainWindow.resizeEventc             C   s   t  | |¡ dS )zReimplement Qt methodN)r   rq  )rH   rè   rK   rK   rL   rq  ¢
  s    zEditorMainWindow.closeEventc             C   sT   | j j ¡ }t| j ¡ | j ¡ f|  ¡  ¡ |  ¡  	¡ f|  
¡ |  ¡ t|  ¡ ƒ|dS )zReturn layout state)rÍ   ÚposÚis_maximizedÚis_fullscreenry  r{  )r™  rv  r€  r|  r˜  rÜ   rÞ   r¦  ÚxÚyr£  r¤  r(   r}  )rH   r{  rK   rK   rL   r€  ¦
  s    
z$EditorMainWindow.get_layout_settingsc             C   sÈ   |  d¡}|dk	r*|  t|Ž ¡ |  ¡ | _|  d¡}|dk	rJ|  t|Ž ¡ |  d¡}|dk	rx|  tƒ  	t
|ƒ d¡¡¡ |  d¡rŽ|  tj¡ |  d¡r¤|  tj¡ |  d¡}|dk	rÄ| jj |¡ dS )	zRestore layout staterÍ   Nr¦  ry  zutf-8r§  r¨  r{  )rf   rÊ   r	   rÍ   r˜  rß   r   r  r   r‚  r¤   r‘   ZsetWindowStater
   ZWindowMaximizedZWindowFullScreenr™  rv  r…  )rH   rƒ  rÍ   r¦  ry  r{  rK   rK   rL   r…  °
  s$    







z$EditorMainWindow.set_layout_settingsN)rS   rT   rU   rD   r  r¡  r¢  r¥  rq  r€  r…  rK   rK   rK   rL   r—  R
  s   +
r—  c               @   s®   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zeeeƒdd„ ƒZeeeeƒdd„ ƒZeeeeƒdd„ ƒZdd „ Zd!S )"ÚEditorPluginExamplec             C   s   t  | ¡ g }g | _g | _i | _t| dd| _t| ddd| _| jj	 
| j¡ t| | |dd| _t| ƒ}tƒ }| dddd¡ | |¡ | | j¡ | | j¡ |  dddd¡ |  |¡ |  | j¡ |  dd¡ |  dd¡ || _d | _d | _|  g g ¡ d S )	NT)r‡  F)rˆ  r‰  )rp  r   rŽ  rq   )r   rD   rx  Úeditorwindowsr–  r5   r  r3   r  r¦   ru   Ú
go_to_filerd  Úeditor_splitterr   r   rÿ   r   rm  r’  r  rg  rh  Úsetup_window)rH   r  r“  r”  rK   rK   rL   rD   Ç
  s4    




zEditorPluginExample.__init__c             C   s2   | j d }| t|ƒ¡ | ¡ }|j||d d S )Nr   )rŒ  )rx  rÚ  r)   r  rX  )rH   rw  r?  rÔ   re  r|   rK   rK   rL   r­  ë
  s    
zEditorPluginExample.go_to_filec             C   s`   x| j d d … D ]}| ¡  qW trTtt| j ƒd| j td tt| jƒd| jtd | ¡  d S )Nú:)rM   )r¬  rð   rO   rb   rt   r   rx  rç   )rH   rè   ÚwinrK   rK   rL   rq  ñ
  s    zEditorPluginExample.closeEventc             C   s(   t  ¡  | jd }| |¡ | ¡  d S )Nr   )r   rg   rx  rS  r<  )rH   rw  re  rK   rK   rL   rS  ú
  s    

zEditorPluginExample.loadc             C   sú   t rtd|td | j |¡ |  |¡rx| t| jƒdk¡ | | j	¡ | 
| j¡ t| ƒ}| | j	j¡ | d|g¡ t| ƒ}| ||||¡ tdƒ}| d¡ |j|dd |j | j¡ |j | j¡ |j | j¡ |j | j¡ |j | j¡ d S )	Nz FakePlugin.register_editorstack:)rM   rq   rŽ  zCourier Newr  r÷   )r6  )rO   rb   r   rx  rm   ZisAncestorOfr‡  rt   r‹  r  r‰  r  r1   r  r  ro  r   rˆ  r   ZsetPointSizer³  rù  ru   Úclose_file_in_all_editorstacksr  Úfile_saved_in_editorstackr  Ú#file_renamed_in_data_in_editorstackrã  rK  rS  )rH   re  r‘  r   r²  rK   rK   rL   rj     s*    

z(EditorPluginExample.register_editorstackc             C   s*   t rtd|td | j | j |¡¡ d S )Nz"FakePlugin.unregister_editorstack:)rM   )rO   rb   r   rx  rs   r´   )rH   re  rK   rK   rL   rl    s    z*EditorPluginExample.unregister_editorstackc             C   s   |  | jd ¡ d S )Nr   )r{  rx  )rH   re  rK   rK   rL   rn    s    z%EditorPluginExample.clone_editorstackc             C   s   || _ || _d S )N)rg  rh  )rH   rg  rh  rK   rK   rL   r¯  "  s    z EditorPluginExample.setup_windowc          	      sV   t ˆ ˆ jˆ jˆ jdddd‰ˆ ˆ  ¡ ¡ ˆ ¡  ˆ  ˆ¡ ˆj 	‡ ‡fdd„¡ d S )NFT)rˆ  r‰  rŠ  c                  s
   ˆ   ˆ¡S )N)Úunregister_editorwindowrK   )rH   ÚwindowrK   rL   rÃ   .  s    z7EditorPluginExample.create_new_window.<locals>.<lambda>)
r—  r  rg  rh  rÊ   rÍ   r|  Úregister_editorwindowro  ru   )rH   rK   )rH   r¶  rL   rã  &  s    
z%EditorPluginExample.create_new_windowc             C   s"   t rtd|td | j |¡ d S )Nzregister_editorwindowQObject*:)rM   )rO   rb   r   r¬  rm   )rH   r¶  rK   rK   rL   r·  0  s    z)EditorPluginExample.register_editorwindowc             C   s*   t rtd|td | j | j |¡¡ d S )Nzunregister_editorwindow:)rM   )rO   rb   r   r¬  rs   r´   )rH   r¶  rK   rK   rL   rµ  5  s    z+EditorPluginExample.unregister_editorwindowc             C   s   d S )NrK   )rH   rK   rK   rL   rq  :  s    z$EditorPluginExample.get_focus_widgetc             C   sP   xJ| j D ]@}tt|ƒƒ|kr| d¡ | |¡}|j|dd | d¡ qW d S )NT)rƒ  F)rx  r¤   re   rÄ  rñ  r]  )rH   Úeditorstack_id_strry   re  r´   rK   rK   rL   r²  =  s    

z2EditorPluginExample.close_file_in_all_editorstacksc             C   s0   x*| j D ] }tt|ƒƒ|kr| ||¡ qW dS )z5A file was saved in editorstack, this notifies othersN)rx  r¤   re   r  )rH   r¸  rÛ  ry   re  rK   rK   rL   r³  H  s    z-EditorPluginExample.file_saved_in_editorstackc             C   s0   x*| j D ] }tt|ƒƒ|kr| ||¡ qW dS )z?A file was renamed in data in editorstack, this notifies othersN)rx  r¤   re   rà  )rH   r¸  rÛ  ry   re  rK   rK   rL   r´  S  s    z7EditorPluginExample.file_renamed_in_data_in_editorstackc             C   s   dS )zFake!NrK   )rH   r­   rK   rK   rL   r‘  [  s    z-EditorPluginExample.register_widget_shortcutsN)rS   rT   rU   rD   r­  rq  rS  rj  rl  rn  r¯  rã  r·  rµ  rq  r   r¤   r²  r³  r´  r‘  rK   rK   rK   rL   r«  Æ
  s    $	
r«  c        
      C   sü   ddl m}  ddlm} ddlm} t |dƒd¡}| dd}|ƒ }tƒ }| 	d	d
¡ | 
¡  |jj}| |¡ | |¡ dd l}| ¡ }	| t |d¡¡ | t |d¡¡ | t |dd¡¡ | t |dd¡¡ td| ¡ |	  ƒ t | ¡ ¡ d S )Nr   )Úqapplication)Úget_module_path)ÚIntrospectionManagerZspyderrn  é   )Z	test_timei„  i¼  z	editor.pyzexplorer.pyZvariableexplorerzcollectionseditor.pyr-   zcodeeditor.pyzElapsed time: %.3f s)Úspyder.utils.qthelpersr¹  Úspyder.config.baserº  Z"spyder.utils.introspection.managerr»  rÌ  Újoinr«  rÊ   r|  r®  re  r¿  Zset_editor_widgetÚtimerS  rb   rí   Úexitr	  )
r¹  rº  r»  Zcur_dirZappr7  Útestre  rÀ  Zt0rK   rK   rL   rÂ  `  s(    


rÂ  Ú__main__)irV   Z
__future__r   rL  Úos.pathr}   rÌ  rí   Úcollectionsr   Zqtpy.compatr   Zqtpy.QtCorer   r   r   r   r	   r
   r   r   r   r   Z
qtpy.QtGuir   Zqtpy.QtWidgetsr   r   r   r   r   r   r   r   r   r   r   r   r¾  r   r   r   r   r    Zspyder.config.guir!   r"   Zspyder.config.utilsr#   r$   r%   r&   r'   Zspyder.py3compatr(   r)   Zspyder.utilsr*   rÒ   r+   r,   r-   r.   r½  r/   r0   r1   r2   Zspyder.widgets.editortoolsr3   Zspyder.widgets.fileswitcherr4   Zspyder.widgets.findreplacer5   Zspyder.widgets.sourcecoder6   Zspyder.widgets.sourcecode.baser7   Z$spyder.widgets.sourcecode.codeeditorr8   r9   Zspyder.widgets.statusr:   r;   r<   r=   Zspyder.widgets.tabsr>   Zspyder.config.mainr?   Zspyder.widgets.explorerr@   rO   rB   rX   rw   r©   r¿   rò   rd  r†  r—  r«  rÂ  rS   rK   rK   rK   rL   Ú<module>   st   08Sx9f               B Xt 
