
Gc           @   s   d  e  f d     YZ d S(   t   DescriptionTreeViewc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   sH  |  i  | |  |  i   | i d |  i  |  _ | i d |  i  |  _ | i d |  i  |  _	 |  i
 i d |  i  |  _ |  i
 i d |  i  |  _ | i d |  i  |  _ | i d |  i  |  _ | i d |  i  |  _ | i d	 |  i  |  _ |  i
 i d
 |  i  |  _ d d k l } l } | |  i | |  i  |  _ d  S(   Nt   destroys   language-selectedt   shows   notify::sensitives   cursor-changeds   remove-templates   export-templates   trigger-selectedt	   sensitives   drag-data-geti(   t   monitor_addt   MONITOR_FILE(   t%   _DescriptionTreeView__init_attributest$   _DescriptionTreeView__set_propertiest   connectt    _DescriptionTreeView__destroy_cbt!   _DescriptionTreeView__signal_id_1t*   _DescriptionTreeView__language_selected_cbt!   _DescriptionTreeView__signal_id_2t   connect_aftert   _DescriptionTreeView__show_cbt!   _DescriptionTreeView__signal_id_3t   _DescriptionTreeView__treeviewt"   _DescriptionTreeView__sensitive_cbt!   _DescriptionTreeView__signal_id_4t'   _DescriptionTreeView__cursor_changed_cbt!   _DescriptionTreeView__signal_id_5t(   _DescriptionTreeView__remove_template_cbt!   _DescriptionTreeView__signal_id_6t(   _DescriptionTreeView__export_template_cbt!   _DescriptionTreeView__signal_id_7t)   _DescriptionTreeView__trigger_selected_cbt!   _DescriptionTreeView__signal_id_8t*   _DescriptionTreeView__manager_sensitive_cbt!   _DescriptionTreeView__signal_id_9t&   _DescriptionTreeView__drag_data_get_cbt"   _DescriptionTreeView__signal_id_10t   gnomevfsR   R   t"   _DescriptionTreeView__database_urit)   _DescriptionTreeView__database_changed_cbt    _DescriptionTreeView__monitor_id(   t   selft   managert   editorR   R   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __init__%   s    
c   	      C   s_  | |  _  | |  _ d  |  _ t |  _ d  |  _ |  i   |  _ |  i	   |  _
 |  i   |  _ |  i	   |  _ |  i   |  _ | i i d  |  _ d d k l } |   i   } g  } | D] } | | i   q ~ |  _ | i d } d d k l } | |  |  _ d  |  _ d  |  _ |  _ d  |  _ |  _  d  |  _! |  _" d  |  _# |  _$ d  |  _% |  _& d  S(   NR    i(   t   SourceLanguagesManagers   templates.gdb(   t   get_uri_from_local_path('   t   _DescriptionTreeView__managert   _DescriptionTreeView__editort   Nonet   _DescriptionTreeView__languaget   Truet    _DescriptionTreeView__can_updatet   _DescriptionTreeView__triggert"   _DescriptionTreeView__create_modelt   _DescriptionTreeView__modelt%   _DescriptionTreeView__create_renderert#   _DescriptionTreeView__name_renderert(   _DescriptionTreeView__create_name_columnt!   _DescriptionTreeView__name_columnt*   _DescriptionTreeView__description_renderert/   _DescriptionTreeView__create_description_columnt(   _DescriptionTreeView__description_columnt   gladet
   get_widgetR   t   gtksourceviewR'   t   get_available_languagest   get_idt   _DescriptionTreeView__languagest   metadata_folderR   R(   R    R"   R
   R   R   R   R   R   R   R   R   R   (	   R#   R$   R%   R'   t   language_listt   _[1]t   namet   database_pathR(   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __init_attributesB   s0    					*	c         C   s   d d k  l } |  i i   } | i |  d d k l } l } l } d
 d g } |  i i	 | | | | B |  i i
 d |  i  |  i i |  i  |  i i |  i  |  i i d	  |  i i   d  S(   Ni(   t   SELECTION_MULTIPLE(   t   BUTTON1_MASKt   ACTION_COPYt   ACTION_DEFAULTs
   text/plaini    i{   t   STRINGt   modelR   (   s
   text/plaini    i{   (   RI   i    i{   (   t   gtkRE   R   t   get_selectiont   set_modet   gtk.gdkRF   RG   RH   t   enable_model_drag_sourcet   set_propertyR1   t   append_columnR5   R8   t   notifyt   clicked(   R#   RE   t	   selectionRF   RG   RH   t   targets(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __set_propertiesi   s    c         C   s#   d d k  l } | t t  } | S(   Ni(   t	   ListStore(   RK   RW   t   str(   R#   RW   RJ   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __create_model}   s    
c         C   s   d d k  l } |   } | S(   Ni(   t   CellRendererText(   RK   RZ   (   R#   RZ   t   renderer(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __create_renderer   s    
	c         C   s   d d k  l } l } d d k  l } d d k l } | | |  i d d } | i d t  | i d |  | i d	 t	  | i
 d  | i d
 t	  | i d |  | S(   Ni(   t   TreeViewColumnt   TREE_VIEW_COLUMN_GROW_ONLY(   t   SORT_ASCENDING(   t   msg0002t   texti    t   expandt   sizingt	   clickables   sort-indicators
   sort-order(   RK   R]   R^   R_   t   i18nR`   R3   RP   t   FalseR-   t   set_sort_column_id(   R#   R]   R^   R_   R`   t   column(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __create_name_column   s    
c         C   sr   d d k  l } l } d d k  l } d d k l } | | |  i d d } | i d t  | i d |  | S(	   Ni(   R]   R^   (   R_   (   t   msg0003Ra   i   Rb   Rc   (	   RK   R]   R^   R_   Re   Rj   R6   RP   R-   (   R#   R]   R^   R_   Rj   Rh   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __create_description_column   s    
c            s  t  } |  i i d |  |  i i   d d k l } d d k l } d d k l	 } l
 } l    f d   }    f d   } t | t | |  i   }	 |   }
 x |
 i   D] } t  } x) |	 D]! } | i |  o t } Pq q W| o q n | i    o@ t } | i   d  } |
 | d	 } |  i i | | g  q q W| |
  |  i i d |  | |  o d  Sn |  i   d  S(
   NR   i(   t   open_template_database(   t   close_template_database(   t   eqt   not_t   nec            s   |  i     S(    (   t
   startswith(   t   x(   t   language(    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   <lambda>   s    c            s     |    S(    (    (   Rr   (   Rp   Rs   (    s-   plugins/TemplateEditor/DescriptionTreeView.pyRt      s    t    i    (   Rf   R   RP   R1   t   cleart   MetadataRl   Rm   t   operatorRn   Ro   Rp   t   filterR>   t   keysRq   R-   t   replacet   appendt    _DescriptionTreeView__select_row(   R#   Rs   t   booleanRl   Rm   Rn   Ro   t   same_prefixt   remove_languaget   similar_prefixt   databaset   keyt   skipt   valueRB   t   description(    (   Rs   Rp   s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __populate_model   s:    
	  	

c      	   C   s   y |  i  i   } | i d  |  i i   } |  i i |  } |  i  i | |  i  i d  t d d  |  i  i	 | |  i  i d   |  i  i
   |  i  i   Wn t j
 o n Xd  S(   Ni    g      ?g        (   R   RL   t   select_pathR1   t   get_iter_firstt   get_patht   scroll_to_cellt
   get_columnR-   t
   set_cursort   columns_autosizet
   grab_focust	   TypeError(   R#   RT   t   iteratort   path(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __select_row   s    (c         C   s  |  i  i   } | i   |  i o|  i } | i   } | i | d  } d d k l } l	 } | | |  i  og | i
 |  | i |  } |  i  i | |  i  i d  t d d  |  i  i | |  i  i d   qx t o | i |  } | |  o |  i   Pn | i | d  } | | |  i  oh | i
 |  | i |  } |  i  i | |  i  i d  t d d  |  i  i | |  i  i d   Pq q Wn |  i   d  |  _ |  i i d t  |  i  i   |  i  i   d  S(   Ni    i(   Rn   Ro   g      ?g        R   (   R   RL   t   unselect_allR/   R1   R   t	   get_valueRx   Rn   Ro   t   select_iterR   R   R   R-   R   t	   iter_nextR}   R+   R)   t   emitR   R   (   R#   RT   RJ   R   t   triggerRn   Ro   R   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __select_new_row   s<    

	(#

(
	c         C   s   d d k  l } l } l } l } d d k l } | i |  } | | |  t j o
 |  n | | |  t j o
 |  n d  S(   Ni(   t   accesst   F_OKt   W_OKR   (   t   ExportPermissionError(	   t   osR   R   R   R   t
   ExceptionsR   t   dirnameRf   (   R#   t   filenameR   R   R   R   R   t   folder(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __check_permission  s    
"

c      	      s     i  i   } | i   \  } d d k l } d d k l } | |  o
 |  n  f d   } t | |  } d d k l	 } d d k l
 } |       f d   }	 t |	 |  }
 |   |
 S(   Ni(   Ro   (   t   ExportSelectionErrorc            s     i    i |   d   S(   i    (   R   t   get_iter(   R   (   RJ   (    s-   plugins/TemplateEditor/DescriptionTreeView.pyRt   ?  s    (   Rl   (   Rm   c            s     i  |    S(    (   t"   _DescriptionTreeView__get_template(   R   (   R#   R   (    s-   plugins/TemplateEditor/DescriptionTreeView.pyRt   D  s    (   R   RL   t   get_selected_rowsRx   Ro   R   R   t   mapRw   Rl   Rm   (   R#   RT   t   pathsRo   R   t   get_triggert   triggersRl   Rm   t   get_templatet	   templates(    (   R#   R   RJ   s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __get_template_info0  s    
	
c         C   s1   |  i  | | |  i  | d | |  i  | d f S(   Ni    i   (   R,   (   R#   R   R   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __get_templateI  s    c         C   s*  |  i  i |  i |  |  i  i |  i |  |  i  i |  i |  |  i  i |  i |  i  |  i  i |  i |  i  |  i  i |  i |  |  i  i |  i	 |  |  i  i |  i
 |  |  i  i |  i |  |  i  i |  i |  i  |  i o! d d k l } | |  i  n |  i i   ~  d  }  d  S(   Ni(   t   monitor_cancel(   R*   t   disconnect_signalR
   R   R   R   R   R   R   R   R   R   R   R"   R   R   R   R+   (   R#   R$   R   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __destroy_cbL  s"    

c         C   s'   | |  _  |  i |  |  i i   d  S(   N(   R,   t$   _DescriptionTreeView__populate_modelR   R   (   R#   R$   Rs   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __language_selected_cbh  s    	c         G   s(   |  i  i d  o |  i  i   n d  S(   NR   (   R   t   get_propertyR   (   R#   t   args(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt	   __show_cbz  s    $c         C   s    |  i  i d | i d   d  S(   Ns    description-treeview-sensitivityR   (   R)   R   R   (   R#   t   treeviewt   data(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __sensitive_cb  s    c         C   s   | i    } | i   \ } } d d k l } | |  o d  Sn | i | d  } | i | d  } |  i i d |  i | f  d  S(   Ni(   Ro   i    s   template-selected(	   RL   R   Rx   Ro   R   R   R)   R   R,   (   R#   R   RT   RJ   R   Ro   R   R   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __cursor_changed_cb  s    
c      
      s  | i  d t    i i   } | i   \  } d d k l } l } | |  o d  Sn    f d   } t | |  } d d k	 l
 } d d k	 l }	 | d  }
 d d k l } l } x8 |
 i   D]* } | | | |   o q n |
 | =q W|	 |
  d  S(	   NR   i(   Ro   t   containsc            s      i   i  i |   d   S(   i    (   R,   R   R   (   R   (   R#   RJ   (    s-   plugins/TemplateEditor/DescriptionTreeView.pyRt     s    (   Rl   (   Rm   t   w(   Rn   Ro   (   R   Rf   R   RL   R   Rx   Ro   R   R   Rw   Rl   Rm   Rn   Rz   (   R#   R$   RT   R   Ro   R   t   get_keysRz   Rl   Rm   R   Rn   R   (    (   R#   RJ   s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __remove_template_cb  s"    
 
c   	      C   s   d d k  l } d d k  l } d d k  l } d d k l } | | | g } | | |  o+ |  i |  i  |  i   |  i	 i
   n d  S(   Ni(   t   MONITOR_EVENT_DELETED(   t   MONITOR_EVENT_CREATED(   t   MONITOR_EVENT_CHANGED(   R   (   R   R   R   R   Rx   R   R   R,   t$   _DescriptionTreeView__select_new_rowR   R   (	   R#   t   monitor_urit   info_urit
   event_typeR   R   R   R   t   events(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __database_changed_cb  s    
c   	      C   s   y` d d k  l } l } | i d t  |  i |  |  i   } d d k l } | | |  Wnk | j
 o* d d k	 l
 } |  i i i |  n7 | j
 o* d d k	 l } |  i i i |  n X| i d t  d  S(   Ni(   R   R   R   (   t   create_template_file(   t   msg0011(   t   msg0012(   R   R   R   R   Rf   t&   _DescriptionTreeView__check_permissiont'   _DescriptionTreeView__get_template_infot   WriteXMLTemplateR   Re   R   R*   t   error_dialogt   show_messageR   R-   (	   R#   R$   R   R   R   R   R   R   R   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __export_template_cb  s    
c         C   s   | |  _  d  S(   N(   R/   (   R#   R$   R   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __trigger_selected_cb  s    	c         C   s]   |  i  i   |  i i   d d k l } | |  o d  Sn |  i  i   |  i i   d  S(   Ni(   Ro   (   R*   t   responseR   R   Rx   Ro   (   R#   R$   R   Ro   (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __manager_sensitive_cb  s    c   	      C   sB   |  i    } d d k l } | |  } | i | i d |  t S(   Ni(   t   create_template_stringi   (   R   R   R   t   sett   targetRf   (	   R#   R   t   contextR   t   infot   timeR   R   t   string(    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyt   __drag_data_get_cb  s
    (   t   __name__t
   __module__R&   R   R   R0   R2   R4   R7   R   R}   R   R   R   R   R	   R   R   R   R   R   R!   R   R   R   R   (    (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pyR        s0   		'						&		"						
								N(   t   objectR    (    (    (    s-   plugins/TemplateEditor/DescriptionTreeView.pys   <module>    s    