diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 18749e7f7..0fe9af630 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -922,6 +922,7 @@ void QETApp::messageReceived(const QString &message) { void QETApp::openFiles(const QETArguments &args) { openProjectFiles(args.projectFiles()); openElementFiles(args.elementFiles()); + openTitleBlockTemplateFiles(args.titleBlockTemplateFiles()); } /** @@ -966,7 +967,7 @@ void QETApp::openProjectFiles(const QStringList &files_list) { /** Ouvre les fichiers elements passes en parametre. Si un element est deja - ouvert, la fentre qui l'edite est activee. + ouvert, la fenetre qui l'edite est activee. @param files_list Fichiers a ouvrir */ void QETApp::openElementFiles(const QStringList &files_list) { @@ -1062,6 +1063,45 @@ void QETApp::openTitleBlockTemplate(const QString &filepath) { qet_template_editor -> showMaximized(); } +/** + Open provided title block template files. If a title block template is already + opened, the adequate window is activated. + @param files_list Files to be opened +*/ +void QETApp::openTitleBlockTemplateFiles(const QStringList &files_list) { + if (files_list.isEmpty()) return; + + // avoid duplicates in the provided files list + QSet files_set; + foreach (QString file, files_list) { + QString canonical_filepath = QFileInfo(file).canonicalFilePath(); + if (!canonical_filepath.isEmpty()) files_set << canonical_filepath; + } + // here, we can assume all files in the set exist and are different + if (files_set.isEmpty()) return; + + // opened title block template editors + QList tbt_editors = titleBlockTemplateEditors(); + + foreach(QString tbt_file, files_set) { + bool already_opened_in_existing_tbt_editor = false; + foreach(QETTitleBlockTemplateEditor *tbt_editor, tbt_editors) { + if (tbt_editor -> isEditing(tbt_file)) { + // this file is already opened + already_opened_in_existing_tbt_editor = true; + tbt_editor -> setVisible(true); + tbt_editor -> raise(); + tbt_editor -> activateWindow(); + break; + } + } + if (!already_opened_in_existing_tbt_editor) { + // this file is not opened yet + openTitleBlockTemplate(tbt_file); + } + } +} + /** Permet a l'utilisateur de configurer QET en lancant un dialogue approprie. @see ConfigDialog diff --git a/sources/qetapp.h b/sources/qetapp.h index 82c9504f1..195148df0 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -203,6 +203,7 @@ class QETApp : public QETSingleApplication { void openElementLocations(const QList &); void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false); void openTitleBlockTemplate(const QString &); + void openTitleBlockTemplateFiles(const QStringList &); void configureQET(); void aboutQET(); diff --git a/sources/qetarguments.cpp b/sources/qetarguments.cpp index f25933a04..97c1b28af 100644 --- a/sources/qetarguments.cpp +++ b/sources/qetarguments.cpp @@ -16,6 +16,7 @@ along with QElectroTech. If not, see . */ #include "qetarguments.h" +#include "titleblock/templatescollection.h" /** Constructeur par defaut @@ -51,6 +52,7 @@ QETArguments::QETArguments(const QETArguments &qet_arguments) : QObject(qet_arguments.parent()), project_files_(qet_arguments.project_files_), element_files_(qet_arguments.element_files_), + tbt_files_(qet_arguments.tbt_files_), options_(qet_arguments.options_), unknown_options_(qet_arguments.unknown_options_), #ifdef QET_ALLOW_OVERRIDE_CED_OPTION @@ -76,6 +78,7 @@ common_tbt_dir_(qet_arguments.common_tbt_dir_), QETArguments &QETArguments::operator=(const QETArguments &qet_arguments) { project_files_ = qet_arguments.project_files_; element_files_ = qet_arguments.element_files_; + tbt_files_ = qet_arguments.tbt_files_; options_ = qet_arguments.options_; unknown_options_ = qet_arguments.unknown_options_; #ifdef QET_ALLOW_OVERRIDE_CED_OPTION @@ -115,7 +118,7 @@ void QETArguments::setArguments(const QList &args) { projet puis element. */ QList QETArguments::arguments() const { - return(options_ + unknown_options_ + project_files_ + element_files_); + return(options_ + unknown_options_ + project_files_ + element_files_ + tbt_files_); } /** @@ -123,7 +126,7 @@ QList QETArguments::arguments() const { Les fichiers de type projet viennent avant les fichiers de type element. */ QList QETArguments::files() const { - return(project_files_ + element_files_); + return(project_files_ + element_files_ + tbt_files_); } /** @@ -140,6 +143,13 @@ QList QETArguments::elementFiles() const { return(element_files_); } +/** + @return title block template files +*/ +QList QETArguments::titleBlockTemplateFiles() const { + return(tbt_files_); +} + /** @return les options reconnues */ @@ -203,6 +213,10 @@ void QETArguments::handleFileArgument(const QString &file) { if (!element_files_.contains(file)) { element_files_ << file; } + } else if (file.endsWith(TITLEBLOCKS_FILE_EXTENSION)) { + if (!tbt_files_.contains(file)) { + tbt_files_ << file; + } } else { if (!project_files_.contains(file)) { project_files_ << file; diff --git a/sources/qetarguments.h b/sources/qetarguments.h index c051d3b11..38880ef0c 100644 --- a/sources/qetarguments.h +++ b/sources/qetarguments.h @@ -42,6 +42,7 @@ class QETArguments : public QObject { virtual QList files() const; virtual QList projectFiles() const; virtual QList elementFiles() const; + virtual QList titleBlockTemplateFiles() const; #ifdef QET_ALLOW_OVERRIDE_CED_OPTION virtual bool commonElementsDirSpecified() const; virtual QString commonElementsDir() const; @@ -72,6 +73,7 @@ class QETArguments : public QObject { private: QList project_files_; QList element_files_; + QList tbt_files_; QList options_; QList unknown_options_; #ifdef QET_ALLOW_OVERRIDE_CED_OPTION diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index 79db84fbd..7325dd002 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -60,6 +60,26 @@ TitleBlockTemplateLocation QETTitleBlockTemplateEditor::location() const { return(location_); } +/** + @return true if the provided filepath matches the currently edited template. + @param filepath path of a title block template on the filesystem +*/ +bool QETTitleBlockTemplateEditor::isEditing(const QString &filepath) { + QString current_filepath; + if (opened_from_file_) { + current_filepath = filepath_; + } else { + current_filepath = QETApp::realPath(location_.toString()); + } + + return( + QET::compareCanonicalFilePaths( + current_filepath, + filepath + ) + ); +} + /** @param true for this editor to prompt the user for a new template name as soon as the window appears in order to duplicate the edited one. diff --git a/sources/titleblock/qettemplateeditor.h b/sources/titleblock/qettemplateeditor.h index 3f0a879c6..f912bb67c 100644 --- a/sources/titleblock/qettemplateeditor.h +++ b/sources/titleblock/qettemplateeditor.h @@ -84,6 +84,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow { // methods public: TitleBlockTemplateLocation location() const; + bool isEditing(const QString &ilepath); void setOpenForDuplication(bool); bool openForDuplication() const;