mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 17:50:52 +01:00
L'application verifie desormais que le fichier n'est pas deja ouvert dans tous les editeurs de schemas.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@353 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
28
qetapp.cpp
28
qetapp.cpp
@@ -76,6 +76,13 @@ QETApp::~QETApp() {
|
||||
delete qsti;
|
||||
}
|
||||
|
||||
/**
|
||||
@return l'instance de la QETApp
|
||||
*/
|
||||
QETApp *QETApp::instance() {
|
||||
return(static_cast<QETApp *>(qApp));
|
||||
}
|
||||
|
||||
/**
|
||||
Change le langage utilise par l'application.
|
||||
@param desired_language langage voulu
|
||||
@@ -266,6 +273,25 @@ QString QETApp::symbolicPath(const QString &real_path) {
|
||||
return(chemin);
|
||||
}
|
||||
|
||||
/**
|
||||
@param filepath Un chemin de fichier
|
||||
Note : si filepath est une chaine vide, cette methode retourne 0.
|
||||
@return le QETDiagramEditor editant le fichier filepath, ou 0 si ce fichier
|
||||
n'est pas edite par l'application.
|
||||
*/
|
||||
QETDiagramEditor *QETApp::diagramEditorForFile(const QString &filepath) {
|
||||
if (filepath.isEmpty()) return(0);
|
||||
|
||||
QETApp *qet_app(QETApp::instance());
|
||||
foreach (QETDiagramEditor *diagram_editor, qet_app -> diagramEditors()) {
|
||||
if (diagram_editor -> viewForFile(filepath)) {
|
||||
return(diagram_editor);
|
||||
}
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
||||
/**
|
||||
Redefinit le chemin du dossier des elements communs
|
||||
@@ -795,5 +821,5 @@ QIcon QETStyle::standardIconImplementation(StandardPixmap standardIcon, const QS
|
||||
|
||||
/// @return une reference vers les parametres de QElectroTEch
|
||||
QSettings &QETApp::settings() {
|
||||
return(*(static_cast<QETApp *>(qApp) -> qet_settings));
|
||||
return(*(instance() -> qet_settings));
|
||||
}
|
||||
|
||||
6
qetapp.h
6
qetapp.h
@@ -38,6 +38,7 @@ class QETApp : public QETSingleApplication {
|
||||
|
||||
// methodes
|
||||
public:
|
||||
static QETApp *instance();
|
||||
void setLanguage(const QString &);
|
||||
static void printHelp();
|
||||
static void printVersion();
|
||||
@@ -51,6 +52,9 @@ class QETApp : public QETSingleApplication {
|
||||
static QString languagesPath();
|
||||
static QString realPath(const QString &);
|
||||
static QString symbolicPath(const QString &);
|
||||
static QETDiagramEditor *diagramEditorForFile(const QString &);
|
||||
QList<QETDiagramEditor *> diagramEditors() const;
|
||||
QList<QETElementEditor *> elementEditors() const;
|
||||
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
||||
public:
|
||||
static void overrideCommonElementsDir(const QString &);
|
||||
@@ -123,8 +127,6 @@ class QETApp : public QETSingleApplication {
|
||||
void cleanup();
|
||||
|
||||
private:
|
||||
QList<QETDiagramEditor *> diagramEditors() const;
|
||||
QList<QETElementEditor *> elementEditors() const;
|
||||
QList<QWidget *> floatingToolbarsAndDocksForMainWindow(QMainWindow *) const;
|
||||
void parseArguments();
|
||||
void initLanguage();
|
||||
|
||||
@@ -574,13 +574,18 @@ bool QETDiagramEditor::openAndAddDiagram(const QString &nom_fichier) {
|
||||
if (nom_fichier.isEmpty()) return(false);
|
||||
|
||||
open_dialog_dir = QDir(nom_fichier);
|
||||
// verifie que le fichier n'est pas deja ouvert
|
||||
QString chemin_fichier = QFileInfo(nom_fichier).canonicalFilePath();
|
||||
foreach (QWidget *fenetre, workspace.windowList()) {
|
||||
DiagramView *fenetre_en_cours = qobject_cast<DiagramView *>(fenetre);
|
||||
if (QFileInfo(fenetre_en_cours -> file_name).canonicalFilePath() == chemin_fichier) {
|
||||
workspace.setActiveWindow(fenetre);
|
||||
// verifie que le fichier n'est pas deja ouvert dans un editeur
|
||||
if (QETDiagramEditor *diagram_editor = QETApp::diagramEditorForFile(nom_fichier)) {
|
||||
if (diagram_editor == this) {
|
||||
if (DiagramView *diagram_view = viewForFile(nom_fichier)) {
|
||||
workspace.setActiveWindow(diagram_view);
|
||||
show();
|
||||
activateWindow();
|
||||
}
|
||||
return(false);
|
||||
} else {
|
||||
// demande a l'autre editeur d'afficher le fichier
|
||||
return(diagram_editor -> openAndAddDiagram(nom_fichier));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -840,6 +845,52 @@ void QETDiagramEditor::addDiagramView(DiagramView *dv) {
|
||||
else p -> show();
|
||||
}
|
||||
|
||||
/**
|
||||
@return la liste des schemas edites par cet editeur de schemas
|
||||
*/
|
||||
QList<DiagramView *> QETDiagramEditor::diagramViews() const {
|
||||
QList<DiagramView *> diagram_views_list;
|
||||
foreach (QWidget *window, workspace.windowList()) {
|
||||
if (DiagramView *diagram_view = qobject_cast<DiagramView *>(window)) {
|
||||
diagram_views_list << diagram_view;
|
||||
}
|
||||
}
|
||||
return(diagram_views_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@return la liste des fichiers edites par cet editeur de schemas
|
||||
*/
|
||||
QList<QString> QETDiagramEditor::editedFiles() const {
|
||||
QList<QString> edited_files_list;
|
||||
foreach (DiagramView *diagram_view, diagramViews()) {
|
||||
QString diagram_file(diagram_view -> file_name);
|
||||
if (!diagram_file.isEmpty()) {
|
||||
edited_files_list << QFileInfo(diagram_file).canonicalFilePath();
|
||||
}
|
||||
}
|
||||
return(edited_files_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@param filepath Un chemin de fichier
|
||||
Note : si filepath est une chaine vide, cette methode retourne 0.
|
||||
@return le DiagramView editant le fichier filepath, ou 0 si ce fichier n'est
|
||||
pas edite par cet editeur de schemas.
|
||||
*/
|
||||
DiagramView *QETDiagramEditor::viewForFile(const QString &filepath) const {
|
||||
if (filepath.isEmpty()) return(0);
|
||||
|
||||
QString searched_can_file_path = QFileInfo(filepath).canonicalFilePath();
|
||||
foreach (DiagramView *diagram_view, diagramViews()) {
|
||||
QString diagram_can_file_path = QFileInfo(diagram_view -> file_name).canonicalFilePath();
|
||||
if (diagram_can_file_path == searched_can_file_path) {
|
||||
return(diagram_view);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
met a jour le menu "Fenetres"
|
||||
*/
|
||||
|
||||
@@ -43,6 +43,9 @@ class QETDiagramEditor : public QMainWindow {
|
||||
public:
|
||||
void closeEvent(QCloseEvent *);
|
||||
void addDiagramView(DiagramView *);
|
||||
QList<DiagramView *> diagramViews() const;
|
||||
QList<QString> editedFiles() const;
|
||||
DiagramView *viewForFile(const QString &) const;
|
||||
static InsetProperties defaultInsetProperties();
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user