示例#1
0
    def OnMenu(self, evt):
        """Handle the context menu events for performing
        filesystem operations

        """
        e_id = evt.GetId()
        path = self.GetItemPath(self._treeId)
        paths = self.GetPaths()
        ok = (False, '')
        if e_id == ID_EDIT:
            self.OpenFiles(paths)
        elif e_id == ID_OPEN:
            worker = OpenerThread(paths)
            worker.start()
        elif e_id == ID_REVEAL:
            worker = OpenerThread([os.path.dirname(fname) for fname in paths])
            worker.start()
        elif e_id == ID_SEARCH_DIR:
            paths = self.GetPaths()
            if len(paths):
                path = paths[0] # Go off of the first selected item
                if not os.path.isdir(path):
                    path = os.path.dirname(path)
                mdata = dict(mainw=self._mw, lookin=path)
                ed_msg.PostMessage(ed_msg.EDMSG_FIND_SHOW_DLG, mdata) 
        elif e_id == ID_GETINFO:
            last = None
            for fname in paths:
                info = ed_mdlg.EdFileInfoDlg(self.GetTopLevelParent(), fname)
                if last is None:
                    info.CenterOnParent()
                else:
                    lpos = last.GetPosition()
                    info.SetPosition((lpos[0] + 14, lpos[1] + 14))
                info.Show()
                last = info
        elif e_id == ID_RENAME:
            self._tree.EditLabel(self._treeId)
        elif e_id == ID_NEW_FOLDER:
            ok = ebmlib.MakeNewFolder(path, _("Untitled_Folder"))
        elif e_id == ID_NEW_FILE:
            ok = ebmlib.MakeNewFile(path, _("Untitled_File") + ".txt")
        elif e_id == ID_DUPLICATE:
            for fname in paths:
                ok = DuplicatePath(fname)
        elif e_id == ID_ARCHIVE:
            ok = MakeArchive(path)
        elif e_id == ID_DELETE:
            ebmlib.MoveToTrash(paths)
            ok = (True, os.path.dirname(path))
        else:
            evt.Skip()
            return

        if e_id in (ID_NEW_FOLDER, ID_NEW_FILE, ID_DUPLICATE, ID_ARCHIVE,
                    ID_DELETE):
            if ok[0]:
                self.ReCreateTree()
                self._SCommand(self.SetPath, ok[1])
示例#2
0
    def OnMenu(self, evt):
        """Handle the context menu events for performing
        filesystem operations

        """
        e_id = evt.GetId()
        path = self.GetItemPath(self._treeId)
        paths = self.GetPaths()
        ok = (False, '')
        if e_id == ID_EDIT:
            self.OpenFiles(paths)
        elif e_id == ID_OPEN:
            worker = OpenerThread(paths)
            worker.start()
        elif e_id == ID_REVEAL:
            worker = OpenerThread([os.path.dirname(fname) for fname in paths])
            worker.start()
        elif e_id == ID_GETINFO:
            last = None
            for fname in paths:
                info = ed_mdlg.EdFileInfoDlg(self.GetTopLevelParent(), fname)
                if last is None:
                    info.CenterOnParent()
                else:
                    lpos = last.GetPosition()
                    info.SetPosition((lpos[0] + 14, lpos[1] + 14))
                info.Show()
                last = info
        elif e_id == ID_RENAME:
            self._tree.EditLabel(self._treeId)
        elif e_id == ID_NEW_FOLDER:
            ok = util.MakeNewFolder(path, _("Untitled_Folder"))
        elif e_id == ID_NEW_FILE:
            ok = util.MakeNewFile(path, _("Untitled_File") + ".txt")
        elif e_id == ID_DUPLICATE:
            for fname in paths:
                ok = DuplicatePath(fname)
        elif e_id == ID_ARCHIVE:
            ok = MakeArchive(path)
        elif e_id == ID_DELETE:
            Trash.moveToTrash(paths)
            ok = (True, os.path.dirname(path))
        else:
            evt.Skip()
            return

        if e_id in (ID_NEW_FOLDER, ID_NEW_FILE, ID_DUPLICATE, ID_ARCHIVE,
                    ID_DELETE):
            if ok[0]:
                self.ReCreateTree()
                self._SCommand(self.SetPath, ok[1])
示例#3
0
    def OnMenu(self, evt):
        """Handle the context menu events for performing
        filesystem operations

        """
        e_id = evt.Id
        path = self._menu.GetUserData('active_node')
        paths = self._menu.GetUserData('selected_nodes')

        def Opener(paths):
            """File opener job
            @param paths: list of paths

            """
            for fname in paths:
                subprocess.call([FILEMAN_CMD, fname])

        if e_id == ID_EDIT:
            self.OpenFiles(paths)
        elif e_id == ID_OPEN:
            ed_thread.EdThreadPool().QueueJob(Opener, paths)
        elif e_id == ID_REVEAL:
            dpaths = [os.path.dirname(fname) for fname in paths]
            dpaths = list(set(dpaths))
            ed_thread.EdThreadPool().QueueJob(Opener, dpaths)
        elif e_id == wx.ID_REFRESH:
            # Refresh the view
            self.RefreshView()
        elif e_id == ID_SEARCH_DIR:
            if len(paths):
                path = paths[0]  # Go off of the first selected item
                if not os.path.isdir(path):
                    path = os.path.dirname(path)
                mdata = dict(mainw=self._mw, lookin=path)
                ed_msg.PostMessage(ed_msg.EDMSG_FIND_SHOW_DLG, mdata)
        elif e_id == ID_GETINFO:
            last = None
            for fname in paths:
                info = ed_mdlg.EdFileInfoDlg(self.TopLevelParent, fname)
                if last is None:
                    info.CenterOnParent()
                else:
                    lpos = last.GetPosition()
                    info.SetPosition((lpos[0] + 14, lpos[1] + 14))
                info.Show()
                last = info
        elif e_id == ID_RENAME:
            item = self._menu.GetUserData('item_id')
            self.EditLabel(item)
        elif e_id == ID_NEW_FOLDER:
            name = wx.GetTextFromUser(_("Enter folder name:"),
                                      _("New Folder"),
                                      parent=self.TopLevelParent)
            if name:
                err, msg = ebmlib.MakeNewFolder(path, name)
                if not err:
                    wx.MessageBox(msg,
                                  _("Failed to create folder"),
                                  style=wx.OK | wx.CENTER | wx.ICON_ERROR)

        elif e_id == ID_NEW_FILE:
            name = wx.GetTextFromUser(_("Enter file name:"),
                                      _("New File"),
                                      parent=self.TopLevelParent)
            if name:
                err, msg = ebmlib.MakeNewFile(path, name)
                if not err:
                    wx.MessageBox(msg,
                                  _("Failed to create file"),
                                  style=wx.OK | wx.CENTER | wx.ICON_ERROR)
        elif e_id == ID_DUPLICATE:
            for fname in paths:
                DuplicatePath(fname)
        elif e_id == ID_ARCHIVE:
            MakeArchive(path)
        elif e_id == ID_DELETE:
            ebmlib.MoveToTrash(paths)
        else:
            evt.Skip()
            return