Skip to content

Commit

Permalink
Welcome page: colour the workspace different properties (type, host)
Browse files Browse the repository at this point in the history
Signed-off-by: Eran Ifrah <[email protected]>
  • Loading branch information
eranif committed Oct 10, 2024
1 parent 84dd6dd commit 90d9adc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
34 changes: 17 additions & 17 deletions CodeLiteIDE-MSW.workspace
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"workspace_type": "File System Workspace",
"name": "CodeLiteIDE-MSW",
"configs": [{
"name": "Debug",
"targets": [["build", "cd $(WorkspacePath)\\build-debug && mingw32-make -j24 install"], ["clean", "cd $(WorkspacePath)\\build-debug && mingw32-make -j24 clean"]],
"file_extensions": "*.cpp;*.c;*.txt;*.json;*.hpp;*.cc;*.cxx;*.xml;*.h;*.wxcp;*.py;*.php;*.rb;*.html;*.js;*.ts;*.rs;*.iss;*.md;*.bat",
"excludeFilesPattern": "*.o;*.pyc;*.obj;*.workspace;*.o.d;*.exe;*.dll;*.project",
"excludePaths": "",
"debugger": "lldb-vscode"
}, {
"name": "Release",
"targets": [["build", "cd $(WorkspacePath)\\build-release && mingw32-make -j24 install"], ["clean", "cd $(WorkspacePath)\\build-release && mingw32-make -j24 clean && rm -fr install"]],
"file_extensions": "*.cpp;*.c;*.txt;*.json;*.hpp;*.cc;*.cxx;*.xml;*.h;*.wxcp;*.py;*.php;*.rb;*.html;*.js;*.ts;*.rs;*.iss;*.md;*.bat;*.sh;*.xrc;*.cmake;*.rc;*.plist;*.in",
"excludeFilesPattern": "*.o;*.pyc;*.obj;*.workspace;*.o.d;*.exe;*.dll;*.project",
"excludePaths": "",
"debugger": ""
}]
"workspace_type": "File System Workspace",
"name": "CodeLiteIDE-MSW",
"configs": [{
"name": "Debug",
"targets": [["build", "cd $(WorkspacePath)\\build-debug && mingw32-make -j24 install"], ["clean", "cd $(WorkspacePath)\\build-debug && mingw32-make -j24 clean"]],
"file_extensions": "*.cpp;*.c;*.txt;*.json;*.hpp;*.cc;*.cxx;*.xml;*.h;*.wxcp;*.py;*.php;*.rb;*.html;*.js;*.ts;*.rs;*.iss;*.md;*.bat",
"excludeFilesPattern": "*.o;*.pyc;*.obj;*.workspace;*.o.d;*.exe;*.dll;*.project",
"excludePaths": "",
"debugger": "lldb-vscode"
}, {
"name": "Release",
"targets": [["build", "cd $(WorkspacePath)\\build-release && mingw32-make -j24 install"], ["clean", "cd $(WorkspacePath)\\build-release && mingw32-make -j24 clean && rm -fr install"]],
"file_extensions": "*.cpp;*.c;*.txt;*.json;*.hpp;*.cc;*.cxx;*.xml;*.h;*.wxcp;*.py;*.php;*.rb;*.html;*.js;*.ts;*.rs;*.iss;*.md;*.bat;*.sh;*.xrc;*.cmake;*.rc;*.plist;*.in",
"excludeFilesPattern": "*.o;*.pyc;*.obj;*.workspace;*.o.d;*.exe;*.dll;*.project",
"excludePaths": "",
"debugger": ""
}]
}
28 changes: 28 additions & 0 deletions LiteEditor/WelcomePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ void get_caption_colours(wxColour* bg_colour, wxColour* text_colour)
*bg_colour = clSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
*text_colour = clSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
}

std::unordered_map<wxString, wxColour> colours;

/// Return a random colour for account
wxColour GetColourForAccount(const wxString& accountName)
{
if (colours.count(accountName) == 0) {
colours.insert({ accountName, ::GetRandomColour() });
}
return colours.find(accountName)->second;
}

} // namespace

WelcomePage::WelcomePage(wxWindow* parent)
Expand Down Expand Up @@ -171,9 +183,13 @@ void WelcomePage::UpdateRecentWorkspaces()
clRecentWorkspaceEvent other_workspaces_event{ wxEVT_RECENT_WORKSPACE };
EventNotifier::Get()->ProcessEvent(other_workspaces_event);

wxColour local_workspace_colour{ "GOLD" };
wxColour remote_workspace_colour{ "CYAN" };

// TODO: fire event here to collect other workspaces as well
auto locals = m_dvTreeCtrlWorkspaces->AppendItem(m_dvTreeCtrlWorkspaces->GetRootItem(), _("Local workspaces"));
int image_index = wxNOT_FOUND;

for (const wxString& filepath : files) {

wxFileName fn{ filepath };
Expand Down Expand Up @@ -210,9 +226,13 @@ void WelcomePage::UpdateRecentWorkspaces()
auto cd = new WelcomePageItemData();
cd->type = WorkspaceSource::BUILTIN;
cd->path = fn.GetFullPath();

auto workspaceItem = m_dvTreeCtrlWorkspaces->AppendItem(locals, fn.GetName(), image_index, image_index, cd);
m_dvTreeCtrlWorkspaces->SetItemText(workspaceItem, "localhost", 1);
m_dvTreeCtrlWorkspaces->SetItemTextColour(workspaceItem, GetColourForAccount("localhost"), 1);

m_dvTreeCtrlWorkspaces->SetItemText(workspaceItem, workspace_type, 2);
m_dvTreeCtrlWorkspaces->SetItemTextColour(workspaceItem, clSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 2);
m_dvTreeCtrlWorkspaces->SetItemText(workspaceItem, filepath, 3);
}
m_dvTreeCtrlWorkspaces->Expand(locals);
Expand Down Expand Up @@ -241,9 +261,17 @@ void WelcomePage::UpdateRecentWorkspaces()
name = name.AfterLast('/');
name = name.BeforeLast('.');

if (colours.count(cd->account) == 0) {
colours.insert({ cd->account, ::GetRandomColour() });
}

auto workspaceItem = m_dvTreeCtrlWorkspaces->AppendItem(parent_item, name, image_index, image_index, cd);
m_dvTreeCtrlWorkspaces->SetItemText(workspaceItem, cd->account, 1);
m_dvTreeCtrlWorkspaces->SetItemTextColour(workspaceItem, GetColourForAccount(cd->account), 1);

m_dvTreeCtrlWorkspaces->SetItemText(workspaceItem, _("Other"), 2);
m_dvTreeCtrlWorkspaces->SetItemTextColour(workspaceItem, clSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT),
2);
m_dvTreeCtrlWorkspaces->SetItemText(workspaceItem, w.path, 3);
}
m_dvTreeCtrlWorkspaces->Expand(parent_item);
Expand Down
16 changes: 16 additions & 0 deletions Plugin/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,3 +1831,19 @@ bool IsChildOf(wxWindow* child, wxWindow* parent)
}
return false;
}

wxColour GetRandomColour()
{
int r = std::rand() % 256;
int g = std::rand() % 256;
int b = std::rand() % 256;

wxColour c(r, g, b);
if (clSystemSettings::GetAppearance().IsDark() && DrawingUtils::IsDark(c)) {
return c.ChangeLightness(130);
} else if (!clSystemSettings::GetAppearance().IsDark() && !DrawingUtils::IsDark(c)) {
return c.ChangeLightness(70);
} else {
return c;
}
}
3 changes: 3 additions & 0 deletions Plugin/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,7 @@ WXDLLIMPEXP_SDK Notebook* FindNotebookParentOf(wxWindow* child);

/// Return true if `child` is a child (does not have to be a direct child) of `parent`
WXDLLIMPEXP_SDK bool IsChildOf(wxWindow* child, wxWindow* parent);

/// Return a random colour suited for the current theme
WXDLLIMPEXP_SDK wxColour GetRandomColour();
#endif // GLOBALS_H

0 comments on commit 90d9adc

Please sign in to comment.