| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /**
- * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
- *
- * This file is part of the QCAD project.
- *
- * QCAD is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * QCAD is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with QCAD.
- */
- /**
- * Fills the list widget "listWidgetName", a child of pageWidget with
- * directories (from where?)
- */
- function DirectoryList(pageWidget, listWidgetName, fileDlgTitle) {
- this.doInit(pageWidget, listWidgetName, fileDlgTitle);
- }
- DirectoryList.prototype.doInit = function(pageWidget, listWidgetName, fileDlgTitle) {
- var widgets = getWidgets(pageWidget);
- var listWidget = widgets[listWidgetName];
- listWidget.dragDropMode = QAbstractItemView.InternalMove;
- listWidget.itemClicked.connect(this, function(item) {
- var btRemove = widgets["btRemove"];
- btRemove.enabled = true;
- this.checkButtonStatus(listWidget, widgets);
- });
- var btAdd = widgets["btAdd"];
- btAdd.clicked.connect(this, function() {
- // getExistingDirectory is broken in KDE when it uses the native dialog.
- /*
- var dir = QFileDialog.getExistingDirectory(this, fileDlgTitle);
- if (dir.length===0) {
- return;
- }
- */
- var fileDialog = new QFileDialog(pageWidget, fileDlgTitle, "", "");
- fileDialog.setOption(QFileDialog.DontUseNativeDialog, getDontUseNativeDialog());
- fileDialog.fileMode = QFileDialog.Directory;
- fileDialog.setOption(QFileDialog.ShowDirsOnly, true);
- fileDialog.setOption(QFileDialog.DontResolveSymlinks, true);
- if (!isNull(QFileDialog.DontUseCustomDirectoryIcons)) {
- fileDialog.setOption(QFileDialog.DontUseCustomDirectoryIcons, true);
- }
- if (!fileDialog.exec()) {
- destr(fileDialog);
- EAction.activateMainWindow();
- return;
- }
- var files = fileDialog.selectedFiles();
- if (files.length===0) {
- destr(fileDialog);
- EAction.activateMainWindow();
- return;
- }
- var dir = files[0];
- var found = false;
- for ( var i = 0; i < listWidget.count; ++i) {
- var item = listWidget.item(i);
- if (item.text() == dir) {
- found = true;
- break;
- }
- }
- if (!found) {
- listWidget.addItem(dir);
- } else {
- var text = qsTr("The folder\n\"%1\"\nis already in the list.").arg(dir);
- var appWin = EAction.getMainWindow();
- QMessageBox.information(appWin, qsTr("Folder not added"), text);
- }
- this.checkButtonStatus(listWidget, widgets);
- });
- var btRemove = widgets["btRemove"];
- btRemove.enabled = false;
- btRemove.clicked.connect(this, function() {
- var currentRow = listWidget.currentRow;
- if (currentRow == -1) {
- this.checkButtonStatus(listWidget, widgets);
- return;
- }
- listWidget.model().removeRow(currentRow);
- if (listWidget.count == 0) {
- btRemove.enabled = false;
- }
- this.checkButtonStatus(listWidget, widgets);
- });
- var btUp = widgets["btUp"];
- btUp.clicked.connect(this, function() {
- var currentRow = listWidget.currentRow;
- if (currentRow == -1) {
- return;
- }
- var item = listWidget.takeItem(currentRow);
- if (isNull(item)) {
- return;
- }
- listWidget.insertItem(currentRow - 1, item);
- listWidget.setCurrentItem(item);
- this.checkButtonStatus(listWidget, widgets);
- });
- var btDown = widgets["btDown"];
- btDown.clicked.connect(this, function() {
- var currentRow = listWidget.currentRow;
- if (currentRow == -1) {
- return;
- }
- var item = listWidget.takeItem(currentRow);
- if (isNull(item)) {
- return;
- }
- listWidget.insertItem(currentRow + 1, item);
- listWidget.setCurrentItem(item);
- this.checkButtonStatus(listWidget, widgets);
- });
- };
- DirectoryList.prototype.checkButtonStatus = function(listWidget, widgets) {
- var currentRow = listWidget.currentRow;
- var btUp = widgets["btUp"];
- if (currentRow < 1) {
- btUp.enabled = false;
- } else {
- btUp.enabled = true;
- }
- var btDown = widgets["btDown"];
- if (currentRow == listWidget.count - 1) {
- btDown.enabled = false;
- } else {
- btDown.enabled = true;
- }
- };
|