L'application active desormais l'editeur d'element adequat au lieu de permettre l'ouverture d'un meme element plusieurs fois en simultane.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@878 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2010-03-04 21:04:23 +00:00
parent df079a62bf
commit 176256adf6
8 changed files with 135 additions and 20 deletions

View File

@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "qetelementeditor.h" #include "qetelementeditor.h"
#include "qet.h"
#include "qetapp.h" #include "qetapp.h"
#include "elementscene.h" #include "elementscene.h"
#include "elementview.h" #include "elementview.h"
@@ -837,6 +838,46 @@ bool QETElementEditor::toLocation(const ElementsLocation &location) {
return(true); return(true);
} }
/**
@param location Emplacement d'un element
@return true si cet editeur est en train d'editer l'element dont
l'emplacement est location, false sinon
*/
bool QETElementEditor::isEditing(const ElementsLocation &provided_location) {
if (opened_from_file) {
return(
QET::compareCanonicalFilePaths(
filename_,
QETApp::realPath(provided_location.toString())
)
);
} else {
return(provided_location == location_);
}
}
/**
@param provided_filepath Chemin d'un element sur un filesystem
@return true si cet editeur est en train d'editer l'element dont
le chemin est filepath, false sinon
*/
bool QETElementEditor::isEditing(const QString &provided_filepath) {
// determine le chemin canonique de l'element actuelle edite, si applicable
QString current_filepath;
if (opened_from_file) {
current_filepath = filename_;
} else {
current_filepath = QETApp::realPath(location_.toString());
}
return(
QET::compareCanonicalFilePaths(
current_filepath,
provided_filepath
)
);
}
/** /**
specifie si l'editeur d'element doit etre en mode lecture seule specifie si l'editeur d'element doit etre en mode lecture seule
@param ro true pour activer le mode lecture seule, false pour le desactiver @param ro true pour activer le mode lecture seule, false pour le desactiver
@@ -872,9 +913,7 @@ void QETElementEditor::slot_open() {
// demande le chemin virtuel de l'element a ouvrir a l'utilisateur // demande le chemin virtuel de l'element a ouvrir a l'utilisateur
ElementsLocation location = ElementDialog::getOpenElementLocation(this); ElementsLocation location = ElementDialog::getOpenElementLocation(this);
if (location.isNull()) return; if (location.isNull()) return;
QETElementEditor *cee = new QETElementEditor(); QETApp::instance() -> openElementLocations(QList<ElementsLocation>() << location);
cee -> fromLocation(location);
cee -> show();
} }
/** /**
@@ -908,12 +947,11 @@ void QETElementEditor::openRecentFile(const QString &filepath) {
Cette methode ne controle pas si le fichier est deja ouvert Cette methode ne controle pas si le fichier est deja ouvert
@param filepath Fichier a ouvrir @param filepath Fichier a ouvrir
@see fromFile @see fromFile
@see QETApp::openElementFiles
*/ */
void QETElementEditor::openElement(const QString &filepath) { void QETElementEditor::openElement(const QString &filepath) {
if (filepath.isEmpty()) return; if (filepath.isEmpty()) return;
QETElementEditor *cee = new QETElementEditor(); QETApp::instance() -> openElementFiles(QStringList() << filepath);
cee -> fromFile(filepath);
cee -> show();
} }
/** /**

View File

@@ -115,6 +115,8 @@ class QETElementEditor : public QMainWindow {
void fromLocation(const ElementsLocation &); void fromLocation(const ElementsLocation &);
bool toFile(const QString &); bool toFile(const QString &);
bool toLocation(const ElementsLocation &); bool toLocation(const ElementsLocation &);
bool isEditing(const ElementsLocation &);
bool isEditing(const QString &);
ElementScene *elementScene() const; ElementScene *elementScene() const;
void readSettings(); void readSettings();
void writeSettings(); void writeSettings();

View File

@@ -255,9 +255,7 @@ void ElementsPanelWidget::importElement() {
// Ouverture de l'element dans l'editeur pour pouvoir ensuite l'enregistrer dans la categorie voulue // Ouverture de l'element dans l'editeur pour pouvoir ensuite l'enregistrer dans la categorie voulue
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QETElementEditor *editor = new QETElementEditor(); QETApp::instance() -> openElementFiles(QStringList() << fileName);
editor -> fromFile(fileName);
editor -> show();
} }
} }
@@ -530,9 +528,7 @@ void ElementsPanelWidget::deleteElement() {
@param location Emplacement de l'element a editer @param location Emplacement de l'element a editer
*/ */
void ElementsPanelWidget::launchElementEditor(const ElementsLocation &location) { void ElementsPanelWidget::launchElementEditor(const ElementsLocation &location) {
QETElementEditor *editor = new QETElementEditor(); QETApp::instance() -> openElementLocations(QList<ElementsLocation>() << location);
editor -> fromLocation(location);
editor -> show();
} }
/** /**

View File

@@ -434,3 +434,25 @@ QString QET::pointerString(void *ptr) {
) )
); );
} }
/**
@param first Un premier chemin vers un fichier
@param second Un second chemin vers un fichier
@return true si les deux chemins existent existent et sont identiques
lorsqu'ils sont exprimes sous forme canonique
*/
bool QET::compareCanonicalFilePaths(const QString &first, const QString &second) {
QString first_canonical_path = QFileInfo(first).canonicalFilePath();
if (first_canonical_path.isEmpty()) return(false);
QString second_canonical_path = QFileInfo(second).canonicalFilePath();
if (second_canonical_path.isEmpty()) return(false);
#ifdef Q_WS_WIN
// sous Windows, on ramene les chemins en minuscules
first_canonical_path = first_canonical_path.toLower();
second_canonical_path = second_canonical_path.toLower();
#endif
return(first_canonical_path == second_canonical_path);
}

View File

@@ -121,5 +121,6 @@ namespace QET {
QString diagramAreaToString(const QET::DiagramArea &); QString diagramAreaToString(const QET::DiagramArea &);
QET::DiagramArea diagramAreaFromString(const QString &); QET::DiagramArea diagramAreaFromString(const QString &);
QString pointerString(void *); QString pointerString(void *);
bool compareCanonicalFilePaths(const QString &, const QString &);
} }
#endif #endif

View File

@@ -730,10 +730,68 @@ void QETApp::openProjectFiles(const QStringList &files_list) {
void QETApp::openElementFiles(const QStringList &files_list) { void QETApp::openElementFiles(const QStringList &files_list) {
if (files_list.isEmpty()) return; if (files_list.isEmpty()) return;
// creation et affichage d'un ou plusieurs editeurs d'element // evite autant que possible les doublons dans la liste fournie
foreach(QString element_file, files_list) { QSet<QString> files_set;
QETElementEditor *element_editor = new QETElementEditor(); foreach(QString file, files_list) {
element_editor -> fromFile(element_file); QString canonical_filepath = QFileInfo(file).canonicalFilePath();
if (!canonical_filepath.isEmpty()) files_set << canonical_filepath;
}
// a ce stade, tous les fichiers dans le Set existent et sont a priori differents
if (files_set.isEmpty()) return;
// liste des editeurs d'element ouverts
QList<QETElementEditor *> element_editors = elementEditors();
// on traite les fichiers a la queue leu leu...
foreach(QString element_file, files_set) {
bool already_opened_in_existing_element_editor = false;
foreach(QETElementEditor *element_editor, element_editors) {
if (element_editor -> isEditing(element_file)) {
// ce fichier est deja ouvert dans un editeur
already_opened_in_existing_element_editor = true;
element_editor -> setVisible(true);
element_editor -> raise();
element_editor -> activateWindow();
break;
}
}
if (!already_opened_in_existing_element_editor) {
// ce fichier n'est ouvert dans aucun editeur
QETElementEditor *element_editor = new QETElementEditor();
element_editor -> fromFile(element_file);
}
}
}
/**
Ouvre les elements dont l'emplacement est passe en parametre. Si un element
est deja ouvert, la fentre qui l'edite est activee.
@param locations_list Emplacements a ouvrir
*/
void QETApp::openElementLocations(const QList<ElementsLocation> &locations_list) {
if (locations_list.isEmpty()) return;
// liste des editeurs d'element ouverts
QList<QETElementEditor *> element_editors = elementEditors();
// on traite les emplacements a la queue leu leu...
foreach(ElementsLocation element_location, locations_list) {
bool already_opened_in_existing_element_editor = false;
foreach(QETElementEditor *element_editor, element_editors) {
if (element_editor -> isEditing(element_location)) {
// cet emplacement est deja ouvert dans un editeur
already_opened_in_existing_element_editor = true;
element_editor -> setVisible(true);
element_editor -> raise();
element_editor -> activateWindow();
break;
}
}
if (!already_opened_in_existing_element_editor) {
// cet emplacement n'est ouvert dans aucun editeur
QETElementEditor *element_editor = new QETElementEditor();
element_editor -> fromLocation(element_location);
}
} }
} }

View File

@@ -159,6 +159,7 @@ class QETApp : public QETSingleApplication {
void openFiles(const QETArguments &); void openFiles(const QETArguments &);
void openProjectFiles(const QStringList &); void openProjectFiles(const QStringList &);
void openElementFiles(const QStringList &); void openElementFiles(const QStringList &);
void openElementLocations(const QList<ElementsLocation> &);
void configureQET(); void configureQET();
void aboutQET(); void aboutQET();

View File

@@ -1757,12 +1757,9 @@ void QETDiagramEditor::findElementInPanel(const ElementsLocation &location) {
@param location Emplacement de l'element a editer @param location Emplacement de l'element a editer
*/ */
void QETDiagramEditor::editElementInEditor(const ElementsLocation &location) { void QETDiagramEditor::editElementInEditor(const ElementsLocation &location) {
QETElementEditor *editor = new QETElementEditor(); QETApp::instance() -> openElementLocations(QList<ElementsLocation>() << location);
editor -> fromLocation(location);
editor -> show();
} }
/** /**
@return Les proprietes par defaut pour le cartouche d'un schema @return Les proprietes par defaut pour le cartouche d'un schema
*/ */