Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Mergin/data_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,38 @@ def __init__(self, parent, project, project_manager, plugin):
self.project_name = posixpath.join(project["namespace"], project["name"]) # posix path for server API calls
self.path = mergin_project_local_path(self.project_name)
display_name = project["name"]
open_project_path = mergin_project_local_path()
self.is_open = (
self.path is not None and open_project_path is not None and same_dir(self.path, open_project_path)
)
if self.is_open:
display_name = f"{project['name']} • open"
QgsDirectoryItem.__init__(self, parent, display_name, self.path, "/Mergin/" + self.project_name)
self.setSortKey(f"0 {self.name()}")
# put the opened project at the beginning of local entries.
self.setSortKey(f" 0 {project['name']}" if self.is_open else f"0 {self.name()}")
# QgsDirectoryItem.icon() ignores setIcon(), so cache the override and serve it from icon() instead.
self._open_icon = (
QIcon(os.path.join(os.path.dirname(__file__), "images", "folder-open.svg")) if self.is_open else None
)
self.project = project
self.project_manager = project_manager
if self.project_manager is not None:
self.mc = self.project_manager.mc
else:
self.mc = None

def icon(self):
"""Provide the custom icon for the currently-open project; fall back to the default folder otherwise."""
if self.is_open and self._open_icon is not None:
return self._open_icon
return super().icon()

def equal(self, other):
"""Called when the browser tree refreshes; also compare is_open so the diff detects open/close transitions."""
if not super().equal(other):
return False
return getattr(other, "is_open", False) == self.is_open

def open_project(self):
self.project_manager.open_project(self.path)

Expand Down Expand Up @@ -507,6 +530,11 @@ def fetch_more(self):
self.fetch_projects(page=page_to_get)
self.refresh()

def reload_local(self):
"""Re-read local projects from settings and refresh the tree."""
self.local_projects = []
self.refresh()

def reload(self):
if not self.plugin.current_workspace:
self.plugin.choose_active_workspace()
Expand Down
3 changes: 3 additions & 0 deletions Mergin/images/folder-open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Mergin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ def on_qgis_project_changed(self):
if self.mergin_proj_dir is not None:
self.enable_toolbar_actions()
set_qgis_project_mergin_variables(self.mergin_proj_dir)
# re-render Browser items so the opened-project indicator follows the active QGIS project.
if self.has_browser_item():
self.data_item_provider.root_item.reload_local()

def add_context_menu_actions(self, layers):
provider_names = "vectortile"
Expand Down
Loading