Ejemplo n.º 1
0
    def _onAddGroup(self, event):
        '''
        Add group button click
        '''
        selectedItem = self._getSelectedItemData()
        assert selectedItem is not None
        rootdir = selectedItem.path

        if not os.path.isdir(rootdir):
            rootdir = os.path.dirname(rootdir)

        # Find unique directory for snippets
        newpath = findUniquePath(rootdir, _(defines.NEW_DIR_NAME))

        try:
            os.mkdir(newpath)
            snippets_tree = self._loadSnippetsTree()
            self._fillSnippetsTree(snippets_tree, newpath)
            newitem = self.snippetsTree.GetSelection()
            self.snippetsTree.EditLabel(newitem)
            self._updateMenu()
            self._scrollToSelectedItem()
        except EnvironmentError:
            MessageBox(
                _(u"Can't create directory\n{}").format(newpath),
                _(u"Error"),
                wx.ICON_ERROR | wx.OK)
Ejemplo n.º 2
0
    def _onAddGroup(self, event):
        '''
        Add group button click
        '''
        selectedItem = self._getSelectedItemData()
        assert selectedItem is not None
        rootdir = selectedItem.path

        if not os.path.isdir(rootdir):
            rootdir = os.path.dirname(rootdir)

        # Find unique directory for snippets
        newpath = findUniquePath(rootdir, _(defines.NEW_DIR_NAME))

        try:
            os.mkdir(newpath)
            snippets_tree = self._loadSnippetsTree()
            self._fillSnippetsTree(snippets_tree, newpath)
            newitem = self.snippetsTree.GetSelection()
            self.snippetsTree.EditLabel(newitem)
            self._updateMenu()
            self._scrollToSelectedItem()
        except EnvironmentError:
            MessageBox(
                _(u"Can't create directory\n{}").format(newpath), _(u"Error"),
                wx.ICON_ERROR | wx.OK)
Ejemplo n.º 3
0
    def test_findUniquePath_03(self):
        from snippets.utils import findUniquePath, createFile
        fname = u'Имя файла'

        createFile(os.path.join(self._tmpdir, fname))

        uniquePath = findUniquePath(self._tmpdir, fname)
        self.assertEqual(uniquePath, os.path.join(self._tmpdir,
                                                  fname + u' (1)'))
Ejemplo n.º 4
0
    def test_findUniquePath_06(self):
        from snippets.utils import findUniquePath, createFile
        fname = 'Имя файла.txt'

        createFile(os.path.join(self._tmpdir, fname))

        uniquePath = findUniquePath(self._tmpdir, fname, '.txt')
        self.assertEqual(uniquePath,
                         os.path.join(self._tmpdir, 'Имя файла (1).txt'))
Ejemplo n.º 5
0
    def test_findUniquePath_08(self):
        from snippets.utils import findUniquePath, createFile
        fname = u'Имя файла.txt'

        createFile(os.path.join(self._tmpdir, fname))

        uniquePath = findUniquePath(self._tmpdir, fname, u'.dat')
        self.assertEqual(uniquePath,
                         os.path.join(self._tmpdir, u'Имя файла.txt (1).dat'))
Ejemplo n.º 6
0
    def test_findUniquePath_03(self):
        from snippets.utils import findUniquePath, createFile
        fname = u'Имя файла'

        createFile(os.path.join(self._tmpdir, fname))

        uniquePath = findUniquePath(self._tmpdir, fname)
        self.assertEqual(uniquePath,
                         os.path.join(self._tmpdir, fname + u' (1)'))
Ejemplo n.º 7
0
    def _onRenameEnd(self, event):
        '''
        Rename button event handler
        '''
        if event.IsEditCancelled():
            return

        item = event.GetItem()
        newlabel = event.GetLabel()
        selectedItem = self._getSelectedItemData()
        assert selectedItem is not None
        oldpath = selectedItem.path
        isdir = os.path.isdir(oldpath)

        if not self._checkName(newlabel):
            event.Veto()
            return

        if isdir:
            # Rename directory
            newpath = findUniquePath(os.path.dirname(oldpath), newlabel)
        else:
            # Rename snippet
            newpath = findUniquePath(os.path.dirname(oldpath), newlabel, u'')

        try:
            self._getItemData(item).path = newpath
            os.rename(oldpath, newpath)
            self._updateSnippetsTree(newpath)
            self._scrollToSelectedItem()
        except EnvironmentError as e:
            MessageBox(
                _(u"Can't rename the snippet '{}'\n{}").format(oldpath, e),
                _(u"Error"),
                wx.ICON_ERROR | wx.OK)

        event.Veto()
        self._updateMenu()
Ejemplo n.º 8
0
    def _onRenameEnd(self, event):
        '''
        Rename button event handler
        '''
        if event.IsEditCancelled():
            return

        item = event.GetItem()
        newlabel = event.GetLabel()
        selectedItem = self._getSelectedItemData()
        assert selectedItem is not None
        oldpath = selectedItem.path
        isdir = os.path.isdir(oldpath)

        if not self._checkName(newlabel):
            event.Veto()
            return

        if isdir:
            # Rename directory
            newpath = findUniquePath(os.path.dirname(oldpath), newlabel)
        else:
            # Rename snippet
            newpath = findUniquePath(os.path.dirname(oldpath), newlabel, u'')

        try:
            self._getItemData(item).path = newpath
            os.rename(oldpath, newpath)
            self._updateSnippetsTree(newpath)
            self._scrollToSelectedItem()
        except EnvironmentError as e:
            MessageBox(
                _(u"Can't rename the snippet '{}'\n{}").format(oldpath, e),
                _(u"Error"),
                wx.ICON_ERROR | wx.OK)

        event.Veto()
        self._updateMenu()
Ejemplo n.º 9
0
    def _onAddSnippet(self, event):
        selectedItem = self._getSelectedItemData()
        assert selectedItem is not None
        rootdir = selectedItem.path

        if not os.path.isdir(rootdir):
            rootdir = os.path.dirname(rootdir)

        # Find unique file name for snippets
        newpath = findUniquePath(rootdir, _(defines.NEW_SNIPPET_NAME), u'')

        try:
            createFile(newpath)
            snippets_tree = self._loadSnippetsTree()
            self._fillSnippetsTree(snippets_tree, newpath)
            newitem = self.snippetsTree.GetSelection()
            self.snippetsTree.EditLabel(newitem)
            self._updateMenu()
            self._scrollToSelectedItem()
        except EnvironmentError:
            MessageBox(
                _(u"Can't create snippet\n{}").format(newpath), _(u"Error"),
                wx.ICON_ERROR | wx.OK)
Ejemplo n.º 10
0
    def _onAddSnippet(self, event):
        selectedItem = self._getSelectedItemData()
        assert selectedItem is not None
        rootdir = selectedItem.path

        if not os.path.isdir(rootdir):
            rootdir = os.path.dirname(rootdir)

        # Find unique file name for snippets
        newpath = findUniquePath(rootdir, _(defines.NEW_SNIPPET_NAME), u'')

        try:
            createFile(newpath)
            snippets_tree = self._loadSnippetsTree()
            self._fillSnippetsTree(snippets_tree, newpath)
            newitem = self.snippetsTree.GetSelection()
            self.snippetsTree.EditLabel(newitem)
            self._updateMenu()
            self._scrollToSelectedItem()
        except EnvironmentError:
            MessageBox(
                _(u"Can't create snippet\n{}").format(newpath),
                _(u"Error"),
                wx.ICON_ERROR | wx.OK)
Ejemplo n.º 11
0
    def test_findUniquePath_05(self):
        from snippets.utils import findUniquePath
        fname = 'Имя файла.txt'

        uniquePath = findUniquePath(self._tmpdir, fname, '.txt')
        self.assertEqual(uniquePath, os.path.join(self._tmpdir, fname))
Ejemplo n.º 12
0
    def test_findUniquePath_05(self):
        from snippets.utils import findUniquePath
        fname = u'Имя файла.txt'

        uniquePath = findUniquePath(self._tmpdir, fname, u'.txt')
        self.assertEqual(uniquePath, os.path.join(self._tmpdir, fname))