Skip to content

Commit

Permalink
Cleanup/Refactor: Moved some project config handling from GenioWindow…
Browse files Browse the repository at this point in the history
… to ProjectBrowser.

Register ProjectBrowser to also receive config changes.
Handle invalidation of OutlineView in there.

This should fix some issue reported by @Freaxed regarding missing invalidation / spurious expanding of collapsed items in ProjectBrowser
  • Loading branch information
jackburton79 committed Nov 21, 2024
1 parent 6ac6b6b commit 9fe05b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
10 changes: 1 addition & 9 deletions src/ui/GenioWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4244,11 +4244,6 @@ GenioWindow::_UpdateProjectActivation(bool active)
ActionManager::SetEnabled(MSG_PROJECT_SETTINGS, false);
fFileNewMenuItem->SetViewMode(TemplatesMenu::ViewMode::SHOW_ALL_VIEW_MODE);
}

BMessage noticeMessage(MSG_NOTIFY_PROJECT_SET_ACTIVE);
noticeMessage.AddPointer("active_project", fActiveProject);
noticeMessage.AddString("active_project_name", fActiveProject ? fActiveProject->Name() : "");
SendNotices(MSG_NOTIFY_PROJECT_SET_ACTIVE, &noticeMessage);
}


Expand Down Expand Up @@ -4522,6 +4517,7 @@ GenioWindow::_HandleConfigurationChanged(BMessage* message)
void
GenioWindow::_HandleProjectConfigurationChanged(BMessage* message)
{
// TODO: This could go into ProjectBrowser in part or entirely
const ProjectFolder* project
= reinterpret_cast<const ProjectFolder*>(message->GetPointer("project_folder", nullptr));
if (project == nullptr) {
Expand All @@ -4535,8 +4531,6 @@ GenioWindow::_HandleProjectConfigurationChanged(BMessage* message)
if (project == fActiveProject || fActiveProject == nullptr) {
// Update debug/release
_UpdateProjectActivation(fActiveProject != nullptr);
} else {
fProjectsFolderBrowser->Invalidate();
}

// TODO: refactor
Expand All @@ -4549,8 +4543,6 @@ GenioWindow::_HandleProjectConfigurationChanged(BMessage* message)
}
}
}
// Save project settings
const_cast<ProjectFolder*>(project)->SaveSettings();
}


Expand Down
29 changes: 26 additions & 3 deletions src/ui/ProjectBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ ProjectBrowser::MessageReceived(BMessage* message)
case MSG_NOTIFY_PROJECT_SET_ACTIVE:
if (gCFG["auto_expand_collapse_projects"]) {
// Expand active project, collapse other
ExpandActiveProjects();
BString activeProject = message->GetString("active_project_name", nullptr);
ExpandProjectCollapseOther(activeProject);
}
fOutlineListView->Invalidate();
break;
Expand Down Expand Up @@ -506,6 +507,26 @@ ProjectBrowser::MessageReceived(BMessage* message)
bool building = false;
message->FindBool("building", &building);
fIsBuilding = building;
fOutlineListView->Invalidate();
break;
}
case kMsgProjectSettingsUpdated:
{
const ProjectFolder* project
= reinterpret_cast<const ProjectFolder*>(message->GetPointer("project_folder", nullptr));
if (project == nullptr) {
LogError("Update project configuration message without a project folder pointer!");
break;
}
// Save project settings
const_cast<ProjectFolder*>(project)->SaveSettings();

BString key(message->GetString("key", ""));
if (key.IsEmpty())
break;
if (key == "color") {
fOutlineListView->Invalidate();
}
break;
}
default:
Expand Down Expand Up @@ -689,6 +710,7 @@ ProjectBrowser::AttachedToWindow()
Window()->StartWatching(this, MSG_NOTIFY_BUILDING_PHASE);
Window()->StartWatching(this, MSG_NOTIFY_FILE_SAVE_STATUS_CHANGED);
Window()->StartWatching(this, MSG_NOTIFY_PROJECT_SET_ACTIVE);
be_app->StartWatching(this, kMsgProjectSettingsUpdated);
Window()->UnlockLooper();
}

Expand Down Expand Up @@ -719,6 +741,7 @@ ProjectBrowser::DetachedFromWindow()
Window()->StopWatching(this, MSG_NOTIFY_FILE_SAVE_STATUS_CHANGED);
Window()->StopWatching(this, MSG_NOTIFY_BUILDING_PHASE);
Window()->StopWatching(this, MSG_NOTIFY_PROJECT_SET_ACTIVE);
be_app->StopWatching(this, kMsgProjectSettingsUpdated);
Window()->UnlockLooper();
}
}
Expand Down Expand Up @@ -775,12 +798,12 @@ ProjectBrowser::ProjectFolderPopulate(ProjectFolder* project)


void
ProjectBrowser::ExpandActiveProjects()
ProjectBrowser::ExpandProjectCollapseOther(const BString& project)
{
for (int32 i = 0; i < CountProjects(); i++) {
ProjectFolder* prj = ProjectAt(i);
ProjectItem* item = GetProjectItemForProject(prj);
if (prj->Active())
if (prj->Name() == project)
fOutlineListView->Expand(item);
else
fOutlineListView->Collapse(item);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ProjectBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ProjectBrowser : public BView {
void ProjectFolderPopulate(ProjectFolder* project);
void ProjectFolderDepopulate(ProjectFolder* project);

void ExpandActiveProjects();
void ExpandProjectCollapseOther(const BString& projectName);

void InitRename(ProjectItem *item);
private:
Expand Down

0 comments on commit 9fe05b6

Please sign in to comment.