9 |
9 |
10 import enum |
10 import enum |
11 import fnmatch |
11 import fnmatch |
12 import re |
12 import re |
13 |
13 |
14 from PyQt6.QtCore import QLocale, Qt, pyqtSlot, QPoint |
14 from PyQt6.QtCore import QLocale, QPoint, Qt, pyqtSlot |
15 from PyQt6.QtWidgets import ( |
15 from PyQt6.QtWidgets import ( |
16 QDialog, QTreeWidgetItem, QAbstractItemView, QCompleter, QLineEdit, QInputDialog, |
16 QAbstractItemView, |
17 QMenu |
17 QCompleter, |
|
18 QDialog, |
|
19 QInputDialog, |
|
20 QLineEdit, |
|
21 QMenu, |
|
22 QTreeWidgetItem, |
18 ) |
23 ) |
19 |
24 |
20 from eric7.EricGui import EricPixmapCache |
25 from eric7.EricGui import EricPixmapCache |
21 from eric7.EricGui.EricFileIconProvider import EricFileIconProvider |
26 from eric7.EricGui.EricFileIconProvider import EricFileIconProvider |
22 from eric7.EricWidgets import EricMessageBox |
27 from eric7.EricWidgets import EricMessageBox |
29 |
34 |
30 class AcceptMode(enum.Enum): |
35 class AcceptMode(enum.Enum): |
31 """ |
36 """ |
32 Class defining the dialog accept modes. |
37 Class defining the dialog accept modes. |
33 """ |
38 """ |
|
39 |
34 AcceptOpen = 0 |
40 AcceptOpen = 0 |
35 AcceptSave = 1 |
41 AcceptSave = 1 |
36 |
42 |
37 |
43 |
38 class FileMode(enum.Enum): |
44 class FileMode(enum.Enum): |
39 """ |
45 """ |
40 Class defining what the user may select in the file dialog. |
46 Class defining what the user may select in the file dialog. |
41 """ |
47 """ |
|
48 |
42 AnyFile = 0 |
49 AnyFile = 0 |
43 ExistingFile = 1 |
50 ExistingFile = 1 |
44 Directory = 2 |
51 Directory = 2 |
45 ExistingFiles = 3 |
52 ExistingFiles = 3 |
46 |
53 |
|
54 |
47 class EricServerFileDialog(QDialog, Ui_EricServerFileDialog): |
55 class EricServerFileDialog(QDialog, Ui_EricServerFileDialog): |
48 """ |
56 """ |
49 Class implementing a file dialog showing the file system of the eric-ide server. |
57 Class implementing a file dialog showing the file system of the eric-ide server. |
50 """ |
58 """ |
51 |
59 |
52 IsDirectoryRole = Qt.ItemDataRole.UserRole |
60 IsDirectoryRole = Qt.ItemDataRole.UserRole |
53 |
61 |
54 def __init__(self, parent=None, caption="", directory="", filter=""): |
62 def __init__(self, parent=None, caption="", directory="", filter=""): # noqa: M132 |
55 """ |
63 """ |
56 Constructor |
64 Constructor |
57 |
65 |
58 @param parent reference to the parent widget (defaults to None) |
66 @param parent reference to the parent widget (defaults to None) |
59 @type QWidget (optional) |
67 @type QWidget (optional) |
179 ] |
187 ] |
180 |
188 |
181 self.filterCombo.clear() |
189 self.filterCombo.clear() |
182 self.filterCombo.addItems(filters) |
190 self.filterCombo.addItems(filters) |
183 |
191 |
184 def setNameFilter(self, filter): |
192 def setNameFilter(self, filter): # noqa: M132 |
185 """ |
193 """ |
186 Public method to set the current name filter. |
194 Public method to set the current name filter. |
187 |
195 |
188 @param filter filter text to make current |
196 @param filter filter text to make current |
189 @type str |
197 @type str |
455 self.accept() |
463 self.accept() |
456 |
464 |
457 @pyqtSlot(int) |
465 @pyqtSlot(int) |
458 def on_filterCombo_currentIndexChanged(self, index): |
466 def on_filterCombo_currentIndexChanged(self, index): |
459 """ |
467 """ |
460 Slot documentation goes here. |
468 Private slot handling the selection of a new file filter.. |
461 |
469 |
462 @param index DESCRIPTION |
470 @param index index of the selected entry |
463 @type int |
471 @type int |
464 """ |
472 """ |
465 filters = self.__filters[index] |
473 filters = self.__filters[index] |
466 self.__filterList(filters) |
474 self.__filterList(filters) |
467 |
475 |
474 server's current directory. |
482 server's current directory. |
475 @type str |
483 @type str |
476 """ |
484 """ |
477 self.__filenameCache.clear() |
485 self.__filenameCache.clear() |
478 self.__directoryCache.clear() |
486 self.__directoryCache.clear() |
479 |
|
480 |
487 |
481 try: |
488 try: |
482 directory, sep, dirListing = self.__fsInterface.listdir(directory) |
489 directory, sep, dirListing = self.__fsInterface.listdir(directory) |
483 |
490 |
484 self.__sep = sep |
491 self.__sep = sep |
501 |
508 |
502 # 2. populate the directory listing |
509 # 2. populate the directory listing |
503 self.listing.clear() |
510 self.listing.clear() |
504 for dirEntry in sorted( |
511 for dirEntry in sorted( |
505 dirListing, |
512 dirListing, |
506 key=lambda d: " " + d['name'].lower() if d["is_dir"] else d["name"].lower(), |
513 key=lambda d: ( |
|
514 " " + d['name'].lower() if d["is_dir"] else d["name"].lower() |
|
515 ), |
507 ): |
516 ): |
508 if dirEntry["is_dir"]: |
517 if dirEntry["is_dir"]: |
509 type_ = self.tr("Directory") |
518 type_ = self.tr("Directory") |
510 iconName = "dirClosed" |
519 iconName = "dirClosed" |
511 sizeStr = "" |
520 sizeStr = "" |
522 itm.setIcon(0, EricPixmapCache.getIcon(iconName)) |
531 itm.setIcon(0, EricPixmapCache.getIcon(iconName)) |
523 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) |
532 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) |
524 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignHCenter) |
533 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignHCenter) |
525 itm.setData(0, EricServerFileDialog.IsDirectoryRole, dirEntry["is_dir"]) |
534 itm.setData(0, EricServerFileDialog.IsDirectoryRole, dirEntry["is_dir"]) |
526 |
535 |
527 |
|
528 filters = self.__filters[self.filterCombo.currentIndex()] |
536 filters = self.__filters[self.filterCombo.currentIndex()] |
529 self.__filterList(filters) |
537 self.__filterList(filters) |
530 |
538 |
531 # 3. add the directory to the history |
539 # 3. add the directory to the history |
532 self.__addToHistory(directory) |
540 self.__addToHistory(directory) |
538 self.tr( |
546 self.tr( |
539 "<p>The directory <b>{0}</b> could not be listed due to an error" |
547 "<p>The directory <b>{0}</b> could not be listed due to an error" |
540 " reported by the eric-ide server.</p><p>Reason: {1}</p>" |
548 " reported by the eric-ide server.</p><p>Reason: {1}</p>" |
541 ).format(directory, str(err)), |
549 ).format(directory, str(err)), |
542 ) |
550 ) |
543 |
|
544 |
551 |
545 # 4. update some dependent states |
552 # 4. update some dependent states |
546 self.nameEdit.clear() |
553 self.nameEdit.clear() |
547 self.__updateUpButton() |
554 self.__updateUpButton() |
548 |
555 |
549 @pyqtSlot(QPoint) |
556 @pyqtSlot(QPoint) |
550 def on_listing_customContextMenuRequested(self, pos): |
557 def on_listing_customContextMenuRequested(self, pos): |
551 """ |
558 """ |
552 Priovate slot to show a context menu. |
559 Private slot to show a context menu. |
553 |
560 |
554 @param pos mouse pointer position to show the menu at |
561 @param pos mouse pointer position to show the menu at |
555 @type QPoint |
562 @type QPoint |
556 """ |
563 """ |
557 self.__contextMenu.clear() |
564 self.__contextMenu.clear() |