-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow creation of new folders from the Settings Dialog. #2897
Allow creation of new folders from the Settings Dialog. #2897
Conversation
src/gui/foldercreationdialog.cpp
Outdated
|
||
if (!QDir(_destination).mkdir(ui->newFolderNameEdit->text())) { | ||
QMessageBox messageBox; | ||
messageBox.critical(0, tr("Error"), tr("Could not create a folder! Check your write permissions.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullptr and not 0
That said you could have used this, since we want this message box to stack up on on top of the current dialog. Also you're calling a static method, you don't need an instance of QMessageBox for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/gui/foldercreationdialog.cpp
Outdated
if (!QDir(_destination).mkdir(ui->newFolderNameEdit->text())) { | ||
QMessageBox messageBox; | ||
messageBox.critical(0, tr("Error"), tr("Could not create a folder! Check your write permissions.")); | ||
messageBox.setFixedSize(500,200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call is unneeded since you used the static method anyway it's not doing anything (well forcing just a fixed size on a message box which was never displayed).
src/gui/accountsettings.cpp
Outdated
@@ -333,6 +334,43 @@ void AccountSettings::slotEditCurrentIgnoredFiles() | |||
openIgnoredFilesDialog(f->path()); | |||
} | |||
|
|||
void AccountSettings::slotOpenMkFolderDialog() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: I'd spell "Make" fully not "Mk".
I think I'd even favor "Create" to "Make" (your call).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin I'll go with "Make" as "OpenCreate" really sounds for me like -Open and Create, instead of Open Create Folder Dialog" :)
src/gui/accountsettings.cpp
Outdated
return; | ||
} | ||
|
||
QString fileName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use an Immediately Invoked Lambda (IIL) here to have the filename as const. I'd even do the chop()
call below in said lambda
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin Although, I don't consider "having something as const" as a good reason for using lambda, I'm going to add this nitpick.
src/gui/accountsettings.cpp
Outdated
|
||
QString fileName; | ||
|
||
if (classification == FolderStatusModel::RootFolder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively I guess we could have added support for FolderPathRole also on the RootFolder? This way we wouldn't need that if in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin Hmmmmmm, I don't know. This will introduce significantly more work and more QA + more chances for an error. Do we really need this sacrifice for the sake of not having if/else
? I mean, if there were no other way, or if we've happened to become in need of using the same condition somewhere else, then I'd certainly vote for such refactoring, but, now, I see more evil than good if I do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, let's not do this. It came mostly out of my sheer surprise that this role wasn't supported on said roots... feels like it was overlooked back then.
src/gui/foldercreationdialog.cpp
Outdated
delete ui; | ||
} | ||
|
||
void FolderCreationDialog::setDestination(const QString& destination) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space before and not after &
src/gui/foldercreationdialog.cpp
Outdated
|
||
void FolderCreationDialog::showEvent(QShowEvent *event) | ||
{ | ||
const auto newFolderFullPath = _destination + "/" + SuggestedFolderNamePrefix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense to have that inside setDestination
instead?
I mean we could always construct cases where the dialog is displayed first and setDestination called a bit later asynchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin My intent was to make sure the dialog is always initialized when it is shown. But, I haven't made this intent clear. I will change the constructor and remove the setter now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note I didn't mind the setter. But OK let's go with a ctor parameter instead. You won't need show event anymore though, this can all be done in the ctor then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin Alrighty then. Removed.
src/gui/foldercreationdialog.cpp
Outdated
QDialog::accept(); | ||
} | ||
|
||
void FolderCreationDialog::on_newFolderNameEdit_textEdited(const QString &) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a matter of personal taste... but I think also a question of benefiting from compile time checks. I'd not rely on such connect via convention but have my slot named on my own convention and use and explicit connect in the ctor.
This way if it should break because something changed in the ui file (for instance) the compiler would catch it.
@@ -0,0 +1,80 @@ | |||
#include "foldercreationdialog.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright header missing
@@ -0,0 +1,34 @@ | |||
#ifndef FOLDERCREATIONDIALOG_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright header missing
src/gui/accountsettings.cpp
Outdated
{ | ||
const auto selected = _ui->_folderList->selectionModel()->currentIndex(); | ||
const QString fileName = [this] () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, probably my fault for being unclear. :-/
What I meant if that the IIL would be nicely used for the part starting now from QString result
. Using it all the way to selected, classification and friend goes overboard and hinder readability in my opinion. This is pattern which works only for short things where typically the ternary operator wouldn't be enough but not for full blown initialization of many intermediate variables.
src/gui/accountsettings.cpp
Outdated
FolderCreationDialog folderCreationDialog; | ||
folderCreationDialog.setDestination(fileName); | ||
folderCreationDialog.exec(); | ||
FolderCreationDialog(fileName).exec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note it is still on the stack, without parent and using exec. It should really go the other way around and be on the heap with a parent and using show + delete on close attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin Changed
src/gui/foldercreationdialog.cpp
Outdated
@@ -10,30 +24,29 @@ namespace { | |||
const QString SuggestedFolderNamePrefix = QObject::tr("New folder"); | |||
}; | |||
|
|||
FolderCreationDialog::FolderCreationDialog(QWidget *parent) : | |||
FolderCreationDialog::FolderCreationDialog(const QString &destination, QWidget *parent) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow didn't notice it earlier but we seem to use mostly that convention in our code base (although it's not my favorite):
Foo::Foo(QWidget *parent)
: Base(parent)
, _member1(...)
, _member2(...)
{
src/gui/foldercreationdialog.cpp
Outdated
|
||
void FolderCreationDialog::showEvent(QShowEvent *event) | ||
{ | ||
const auto newFolderFullPath = _destination + "/" + SuggestedFolderNamePrefix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note I didn't mind the setter. But OK let's go with a ctor parameter instead. You won't need show event anymore though, this can all be done in the ctor then.
ccc9272
to
0dd9be6
Compare
src/gui/accountsettings.cpp
Outdated
return; | ||
} | ||
|
||
const QString fileName = [this, &selected, &classification] () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't necessarily go change it, it is more a "by the way for next time" comment. So you know you can omit the parenthesis for lambdas not taking any parameter. It's a tiny bit less syntactic noise which is always welcome.
src/gui/accountsettings.cpp
Outdated
result = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString(); | ||
} | ||
|
||
if (!result.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that if is redundant. Indeed if result.endsWith('/')
is true then !result.isEmpty()
is necessarily true. Also if you're concerned about performances all the implementations of endsWith
have a fast path for the empty case so it's checked in some way.
src/gui/accountsettings.cpp
Outdated
|
||
if (!fileName.isEmpty()) { | ||
const auto folderCreationDialog = new FolderCreationDialog(fileName, this); | ||
folderCreationDialog->open(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: I'd open last.
Not that it'd matter in practice it's more of a readability thing IMHO.
src/gui/foldercreationdialog.cpp
Outdated
#include <QMessageBox> | ||
|
||
namespace { | ||
const QString SuggestedFolderNamePrefix = QObject::tr("New folder"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needs to be moved as a local variable in the ctor.
src/gui/foldercreationdialog.cpp
Outdated
QDialog::accept(); | ||
} | ||
|
||
void FolderCreationDialog::slotNewFolderNameEditTextEdited(const QString &) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have that parameter at all since we don't use it?
ca478bf
to
1c0c1be
Compare
src/gui/foldercreationdialog.cpp
Outdated
|
||
connect(ui->newFolderNameEdit, &QLineEdit::textChanged, this, &FolderCreationDialog::slotNewFolderNameEditTextEdited); | ||
|
||
const QString SuggestedFolderNamePrefix = QObject::tr("New folder"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please start the name with a lowercase s like any other variable.
261c9bb
to
eef9f68
Compare
src/gui/accountsettings.cpp
Outdated
if (classification == FolderStatusModel::RootFolder) { | ||
const auto alias = _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString(); | ||
const auto folderMan = FolderMan::instance(); | ||
if (const QPointer<Folder> folder = folderMan->folder(alias)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either this is back or I missed the fact that the comment wasn't addressed but you don't need a QPointer here, a raw pointer is enough. There's no chance that object will be destroyed between the folder
and path
calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin I guess you missed it. Alright. This was copy-pasted from another method :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin Was blindly copy-pasted from void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I guess it made sense there at some point in time if one of slots connected to the actions were receiving that pointer, but not anymore since none of them use it (the folder is refetched in the slots anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@er-vin Ok. Removed it. And, accidentally, cleared the history. But you can locate this change I am sure. This was the only one.
You can start cleaning up the history BTW. I'm confident it'll be good to go on the next iteration. ;-) |
@er-vin I guess I can do it before the merge. Let's not be in hurry. |
Signed-off-by: allexzander <blackslayer4@gmail.com>
eae63dd
to
81a090b
Compare
AppImage file: Nextcloud-PR-2897-81a090b362f10df8d208924c97148b0bcff135ad-x86_64.AppImage |
Signed-off-by: allexzander blackslayer4@gmail.com
Also fixed incorrect path for SubFolderInfo that was resulting in an inability to open encrypted subfolder and create a new folder inside it via the Settings Dialog's context menu.