Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
Vivy
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Elliu
Vivy
Validations
e1a61d80
Vérifiée
Valider
e1a61d80
rédigé
3 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
LIB: Reduce the number of lines of code with a copyOrRenameWith utility
parent
76f6952f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!18
Implement the VivyDocument specification
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/Lib/AbstractDocument.hh
+38
-47
38 ajouts, 47 suppressions
src/Lib/AbstractDocument.hh
avec
38 ajouts
et
47 suppressions
src/Lib/AbstractDocument.hh
+
38
−
47
Voir le fichier @
e1a61d80
...
...
@@ -16,22 +16,7 @@ class AbstractDocument : public QObject {
Q_OBJECT
VIVY_UNMOVABLE_OBJECT
(
AbstractDocument
)
public:
enum
class
Type
:
quint64
{
Vivy
=
Utils
::
toUnderlying
(
Utils
::
DocumentType
::
Vivy
),
Script
=
Utils
::
toUnderlying
(
Utils
::
DocumentType
::
VivyScript
)
};
protected
:
AbstractDocument
(
Type
childType
,
const
QString
&
documentName
)
:
type
(
childType
)
,
name
(
documentName
)
{
}
// Automate a part of the rename process, just need to provide a "success"
// callback and the new file info.
void
copyWith
(
const
QFileInfo
&
newFile
,
auto
success
)
void
copyOrRenameWith
(
const
QFileInfo
&
newFile
,
auto
action
,
auto
success
)
{
const
QFileInfo
oldFile
(
getName
());
...
...
@@ -43,6 +28,10 @@ protected:
dirOp
.
mkpath
(
newAbsDirPath
);
}
if
(
newFile
.
absoluteFilePath
()
==
oldFile
.
absoluteFilePath
())
{
throw
std
::
runtime_error
(
"Can't rename or copy a file to itself!"
);
}
if
(
newFile
.
exists
())
{
qWarning
()
<<
"Deleting the already existing"
<<
newFile
;
if
(
!
dirOp
.
remove
(
newFile
.
absoluteFilePath
()))
...
...
@@ -50,47 +39,49 @@ protected:
newFile
.
absoluteFilePath
().
toStdString
());
}
if
(
QFile
::
copy
(
oldFile
.
absoluteFilePath
(),
newFile
.
absoluteFilePath
()))
{
if
(
action
(
oldFile
.
absoluteFilePath
(),
newFile
.
absoluteFilePath
()))
{
success
();
save
();
}
else
throw
std
::
runtime_error
(
"Failed to copy "
+
oldFile
.
absoluteFilePath
().
toStdString
()
+
" to "
+
newFile
.
absoluteFilePath
().
toStdString
());
else
{
throw
std
::
runtime_error
(
"Failed to copy or rename "
+
oldFile
.
absoluteFilePath
().
toStdString
()
+
" to "
+
newFile
.
absoluteFilePath
().
toStdString
());
}
}
public
:
enum
class
Type
:
quint64
{
Vivy
=
Utils
::
toUnderlying
(
Utils
::
DocumentType
::
Vivy
),
Script
=
Utils
::
toUnderlying
(
Utils
::
DocumentType
::
VivyScript
)
};
protected
:
AbstractDocument
(
Type
childType
,
const
QString
&
documentName
)
:
type
(
childType
)
,
name
(
documentName
)
{
}
// Automate a part of the rename process, just need to provide a "success"
// callback and the new file info.
void
rename
With
(
const
QFileInfo
&
newFile
,
auto
success
)
void
copy
With
(
const
QFileInfo
&
newFile
,
auto
success
)
{
const
QFileInfo
oldFile
(
getName
());
// Create folder if needed
QDir
dirOp
;
const
QString
newAbsDirPath
=
newFile
.
dir
().
absolutePath
();
if
(
!
dirOp
.
exists
(
newAbsDirPath
))
{
qInfo
()
<<
"Create folder "
<<
newAbsDirPath
;
dirOp
.
mkpath
(
newAbsDirPath
);
}
if
(
newFile
.
exists
())
{
qWarning
()
<<
"Deleting the already existing"
<<
newFile
;
dirOp
.
remove
(
newFile
.
absoluteFilePath
());
if
(
!
dirOp
.
remove
(
newFile
.
absoluteFilePath
()))
throw
std
::
runtime_error
(
"Failed to remove "
+
newFile
.
absoluteFilePath
().
toStdString
());
}
if
(
dirOp
.
rename
(
oldFile
.
absoluteFilePath
(),
newFile
.
absoluteFilePath
()))
{
success
();
save
();
}
auto
action
=
[](
const
QString
&
oldFile
,
const
QString
&
newFileName
)
noexcept
->
bool
{
return
QFile
::
copy
(
oldFile
,
newFileName
);
};
copyOrRenameWith
(
newFile
,
action
,
success
);
}
else
throw
std
::
runtime_error
(
"Failed to rename "
+
oldFile
.
absoluteFilePath
().
toStdString
()
+
" to "
+
newFile
.
absoluteFilePath
().
toStdString
());
// Automate a part of the rename process, just need to provide a "success"
// callback and the new file info.
void
renameWith
(
const
QFileInfo
&
newFile
,
auto
success
)
{
auto
action
=
[](
const
QString
&
oldFile
,
const
QString
&
newFileName
)
noexcept
->
bool
{
return
QFile
::
rename
(
oldFile
,
newFileName
);
};
copyOrRenameWith
(
newFile
,
action
,
success
);
}
Type
type
;
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter