Beispiel #1
0
 def addsnippet(self, filename, type='open', expand=True):
     files = self.getTopSnippets()
     filename = common.uni_file(filename)
     if filename not in files:
         self.deal_recent(filename)
         
         def f():
             self.read_snippet_file(filename, type, expand)
         d = Casing.Casing(f)
         d.start_thread()
         
     self.callplugin('after_addsnippetfile', self)
Beispiel #2
0
 def addsnippet(self, filename, type='open', expand=True):
     #test if the filename is existed
     if not os.path.exists(filename):
         common.showerror(tr("Can't open the file %s") % filename)
         return
     files = self.getTopSnippets()
     filename = common.uni_file(filename)
     if filename not in files:
         self.deal_recent(filename)
         
         def f():
             self.read_snippet_file(filename, type, expand)
         d = Casing.Casing(f)
         d.start_thread()
         
     self.callplugin('after_addsnippetfile', self)
Beispiel #3
0
    def addpath(self, path, expand=True):
        self.tree.Freeze()
        dirs = self.getTopDirs()
        path = common.uni_file(path)
        if path not in dirs:
            if path in self.pref.recent_dir_paths:
                self.pref.recent_dir_paths.remove(path)
            self.pref.recent_dir_paths.insert(0, path)
            self.pref.recent_dir_paths = self.pref.recent_dir_paths[:self.pref.recent_dir_paths_num]
            self.pref.save()
            node = self.add_first_level_node(self.root, '', path, self.close_image, self.open_image, self.getid())
            self.tree.SetItemHasChildren(node, True)
            if expand:
                self.addpathnodes(path, node)
#                wx.CallAfter(self.tree.Expand, node)
                wx.CallAfter(self.tree.SelectItem, node)
            self.callplugin('after_addpath', self, node)
        self.tree.Thaw()
Beispiel #4
0
 def OnSaveAsSnippet(self, event):
     item = self.tree.GetSelection()
     if not self.is_ok(item): return
     dlg = wx.FileDialog(self, tr("Save Snippet File As..."), self.pref.snippet_lastdir, '', 'Snippet File(*.spt)|*.spt|All Files(*.*)|*.*', wx.SAVE|wx.OVERWRITE_PROMPT)
     dlg.SetFilterIndex(0)
     filename = None
     if dlg.ShowModal() == wx.ID_OK:
         filename = dlg.GetPath()
         self.pref.snippet_lastdir = os.path.dirname(filename)
         self.pref.save()
     dlg.Destroy()
     files = self.getTopSnippets()
     filename = common.uni_file(filename)
     if filename in files:
         common.showerror(tr('The file %s has been existed, so please rename it.') % filename)
         return
     data = self.get_node_data(item)
     data['filename'] = filename
     self.save_snippet(item)
Beispiel #5
0
 def addpath(self, path, expand=True):
     self.tree.Freeze()
     dirs = self.getTopDirs()
     path = common.uni_file(path)
     if path not in dirs:
         if path in self.pref.recent_dir_paths:
             self.pref.recent_dir_paths.remove(path)
         self.pref.recent_dir_paths.insert(0, path)
         self.pref.recent_dir_paths = self.pref.recent_dir_paths[:self.pref.
                                                                 recent_dir_paths_num]
         self.pref.save()
         node = self.add_first_level_node(self.root, '', path,
                                          self.close_image, self.open_image,
                                          self.getid())
         self.tree.SetItemHasChildren(node, True)
         if expand:
             self.addpathnodes(path, node)
             #                wx.CallAfter(self.tree.Expand, node)
             wx.CallAfter(self.tree.SelectItem, node)
         self.callplugin('after_addpath', self, node)
     self.tree.Thaw()
Beispiel #6
0
class EditorFactory(FNB.FlatNotebook, Mixin.Mixin):

    __mixinname__ = 'editctrl'
    popmenulist = []
    imagelist = {}
    panellist = {}
    pageimagelist = {}
    _id = 0

    def __init__(self, parent, mainframe):
        self.initmixin()

        self.parent = parent
        self.mainframe = mainframe
        self.pref = self.mainframe.pref
        self.app = self.mainframe.app
        self.mainframe.editctrl = self
        self.document = None
        self.lastfilename = None
        self.lastlanguagename = ''
        self.lastdocument = None

        if self.pref.notebook_direction == 0:
            style = 0
        else:
            style = FNB.FNB_BOTTOM
        FNB.FlatNotebook.__init__(
            self,
            parent,
            -1,
            style=style | FNB.FNB_SMART_TABS | FNB.FNB_VC8 | FNB.FNB_X_ON_TAB
            | FNB.FNB_NO_X_BUTTON | FNB.FNB_DROPDOWN_TABS_LIST
            | FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS)
        self.id = self.GetId()

        #make popup menu
        #@add_menu menulist
        self.callplugin_once('add_menu', EditorFactory.popmenulist)
        #@add_menu_image_list imagelist
        self.callplugin_once('add_menu_image_list', EditorFactory.imagelist)
        #@add_panel_list panellist
        self.callplugin_once('add_panel_list', EditorFactory.panellist)

        self.popmenu = makemenu.makepopmenu(self, EditorFactory.popmenulist,
                                            EditorFactory.imagelist)
        #        self.SetRightClickMenu(self.popmenu)
        FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED(self, self.id, self.OnChanged)
        FNB.EVT_FLATNOTEBOOK_PAGE_CLOSING(self, self.id, self.OnClose)
        wx.EVT_LEFT_DCLICK(self._pages, self.OnDClick)
        FNB.EVT_FLATNOTEBOOK_PAGE_CONTEXT_MENU(self, self.id, self.OnPopup)

        self.imageindex = {}
        pageimages = wx.ImageList(16, 16)
        for i, v in enumerate(self.pageimagelist.items()):
            name, imagefilename = v
            image = common.getpngimage(imagefilename)
            pageimages.Add(image)
            self.imageindex[name] = i
        self.pageimages = pageimages

        #        self.AssignImageList(self.pageimages)
        self.SetImageList(self.pageimages)
        self.skip_closing = False
        self.skip_page_change = False
        self.full = False
        self.last_side_panel_status = None

        #set FlatNotebook style
        x = common.get_config_file_obj()
        tab_color = x.default.get('editor_tab_color', '#98FB98')
        self.SetActiveTabColour(tab_color)


#        self.SetActiveTabTextColour('white')
#        self.SetNonActiveTabTextColour('black')
#        self.SetAllPagesShapeAngle(15)

    def openPage(self):
        self.callplugin('init', self)

        if not self.execplugin('openpage', self):
            self.new()

        for file in self.mainframe.filenames:
            self.new(os.path.join(self.app.workpath, file))

    def changeDocument(self, document, delay=False):
        if not delay:
            #open delayed document
            if not document.opened:
                try:
                    document.openfile(document.filename, document.locale,
                                      False)
                    #add restore session process
                    for v in self.pref.sessions:
                        if len(v) == 4:
                            filename, row, col, bookmarks = v
                            state = row
                        else:
                            filename, state, bookmarks = v
                        if filename == document.filename:
                            wx.CallAfter(setStatus, document, state, bookmarks)
                except MyUnicodeException, e:
                    error.traceback()
                    e.ShowMessage()
                    wx.CallAfter(self.closefile, document)
                    return
                except:
                    error.traceback()
                    filename = document.filename
                    common.showerror(
                        self,
                        tr("Can't open the file %s.") %
                        common.uni_file(filename))
                    wx.CallAfter(self.closefile, document)
                    return