13 import glob |
13 import glob |
14 import fnmatch |
14 import fnmatch |
15 import copy |
15 import copy |
16 import zipfile |
16 import zipfile |
17 import contextlib |
17 import contextlib |
|
18 import pathlib |
18 |
19 |
19 from PyQt6.QtCore import ( |
20 from PyQt6.QtCore import ( |
20 pyqtSlot, QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, |
21 pyqtSlot, QFile, pyqtSignal, QCryptographicHash, QIODevice, QByteArray, |
21 QByteArray, QObject, QProcess |
22 QObject, QProcess |
22 ) |
23 ) |
23 from PyQt6.QtGui import QKeySequence, QAction |
24 from PyQt6.QtGui import QKeySequence, QAction |
24 from PyQt6.QtWidgets import ( |
25 from PyQt6.QtWidgets import ( |
25 QLineEdit, QToolBar, QDialog, QInputDialog, QMenu |
26 QLineEdit, QToolBar, QDialog, QInputDialog, QMenu |
26 ) |
27 ) |
690 self.recent = [] |
691 self.recent = [] |
691 Preferences.Prefs.rsettings.sync() |
692 Preferences.Prefs.rsettings.sync() |
692 rp = Preferences.Prefs.rsettings.value(recentNameProject) |
693 rp = Preferences.Prefs.rsettings.value(recentNameProject) |
693 if rp is not None: |
694 if rp is not None: |
694 for f in rp: |
695 for f in rp: |
695 if QFileInfo(f).exists(): |
696 if pathlib.Path(f).exists(): |
696 self.recent.append(f) |
697 self.recent.append(f) |
697 |
698 |
698 def __saveRecent(self): |
699 def __saveRecent(self): |
699 """ |
700 """ |
700 Private method to save the list of recently opened filenames. |
701 Private method to save the list of recently opened filenames. |
3127 self.tr("Project Files (*.epj)"), |
3128 self.tr("Project Files (*.epj)"), |
3128 defaultFilter, |
3129 defaultFilter, |
3129 EricFileDialog.DontConfirmOverwrite) |
3130 EricFileDialog.DontConfirmOverwrite) |
3130 |
3131 |
3131 if fn: |
3132 if fn: |
3132 ext = QFileInfo(fn).suffix() |
3133 fpath = pathlib.Path(fn) |
3133 if not ext: |
3134 if not fpath.suffix: |
3134 ex = selectedFilter.split("(*")[1].split(")")[0] |
3135 ex = selectedFilter.split("(*")[1].split(")")[0] |
3135 if ex: |
3136 if ex: |
3136 fn += ex |
3137 fpath = fpath.with_suffix(ex) |
3137 if QFileInfo(fn).exists(): |
3138 if fpath.exists(): |
3138 res = EricMessageBox.yesNo( |
3139 res = EricMessageBox.yesNo( |
3139 self.ui, |
3140 self.ui, |
3140 self.tr("Save File"), |
3141 self.tr("Save File"), |
3141 self.tr("""<p>The file <b>{0}</b> already exists.""" |
3142 self.tr("""<p>The file <b>{0}</b> already exists.""" |
3142 """ Overwrite it?</p>""").format(fn), |
3143 """ Overwrite it?</p>""").format(str(fpath)), |
3143 icon=EricMessageBox.Warning) |
3144 icon=EricMessageBox.Warning) |
3144 if not res: |
3145 if not res: |
3145 return False |
3146 return False |
3146 |
3147 |
3147 self.name = QFileInfo(fn).baseName() |
3148 self.name = fpath.stem() |
3148 ok = self.__writeProject(fn) |
3149 ok = self.__writeProject(str(fpath)) |
3149 |
3150 |
3150 if ok: |
3151 if ok: |
3151 # create management directory if not present |
3152 # create management directory if not present |
3152 self.createProjectManagementDir() |
3153 self.createProjectManagementDir() |
3153 |
3154 |
4645 act = self.recentMenu.addAction( |
4646 act = self.recentMenu.addAction( |
4646 formatStr.format( |
4647 formatStr.format( |
4647 idx, |
4648 idx, |
4648 Utilities.compactPath(rp, self.ui.maxMenuFilePathLen))) |
4649 Utilities.compactPath(rp, self.ui.maxMenuFilePathLen))) |
4649 act.setData(rp) |
4650 act.setData(rp) |
4650 act.setEnabled(QFileInfo(rp).exists()) |
4651 act.setEnabled(pathlib.Path(rp).exists()) |
4651 |
4652 |
4652 self.recentMenu.addSeparator() |
4653 self.recentMenu.addSeparator() |
4653 self.recentMenu.addAction(self.tr('&Clear'), self.clearRecent) |
4654 self.recentMenu.addAction(self.tr('&Clear'), self.clearRecent) |
4654 |
4655 |
4655 def __openRecent(self, act): |
4656 def __openRecent(self, act): |