Enable "Open Config"/"Close Project" always if just one project is loaded
ClosedPublic

Authored by kossebau on Jan 20 2017, 12:06 AM.

Diff Detail

Repository
R33 KDevPlatform
Branch
enableOpenConfigCloseForSingleProject
Lint
No Linters Available
Unit
No Unit Test Coverage
kossebau updated this revision to Diff 10374.Jan 20 2017, 12:06 AM
kossebau retitled this revision from to Enable "Open Config"/"Close Project" always if just one project is loaded.
kossebau updated this object.
kossebau added a reviewer: KDevelop.
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptJan 20 2017, 12:06 AM
brauch accepted this revision.Jan 20 2017, 5:50 AM
brauch added a reviewer: brauch.
This revision is now accepted and ready to land.Jan 20 2017, 5:50 AM
flherne added a subscriber: flherne.EditedJan 20 2017, 9:37 AM

More generally, it might be better to create a selectedProjects() (or so) method instead and use it instead of all the Core::self()->selectionController()->currentSelection() stuff?

EDIT: I meant including the single-project-always-selected behaviour, so perhaps my suggested name is misleading.

As I mentioned on IRC, there are other features that act on the currently-selected project, adding this sort of logic in every such call would be quite ugly.

shell/projectcontroller.cpp
228

Aargh. Maybe something like this?

int itemCount = m_projects.size();
if ( itemCount > 1 ) {
    // if only one project loaded, this is always our target, otherwise base on selection
    if ( auto itemContext = dynamic_cast<ProjectItemContext*>(ICore::self()->selectionController()->currentSelection()) ) {
        itemCount = itemContext->items().count();
    }
}
m_openConfig->setEnabled(itemCount == 1);
m_closeProject->setEnabled(itemCount > 0);

More generally, it might be better to create a selectedProjects() (or so) method instead and use it instead of all the Core::self()->selectionController()->currentSelection() stuff?

EDIT: I meant including the single-project-always-selected behaviour, so perhaps my suggested name is misleading.

As I mentioned on IRC, there are other features that act on the currently-selected project, adding this sort of logic in every such call would be quite ugly.

Agreed, this should see some general improvement, not only for consistency. Partially this patch is also testing acceptance of if-one-project-then-always-selected-one :)
Let's get this one in already though, so it is fixed for now.

shell/projectcontroller.cpp
228

Smaller code looks nice :)
But:
What if itemContext is nullptr? I have no idea when this could happen, but if it does, itemCount would not be updated, so m_openConfig->setEnabled(itemCount == 1); would not behave as wanted.

kossebau updated this object.Jan 20 2017, 6:31 PM
kossebau edited edge metadata.
This revision was automatically updated to reflect the committed changes.