Skip to content

Commit

Permalink
Download new URLs immediately. Easily download simple sites.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfstr committed Aug 25, 2024
2 parents 924f9af + 83e8ce4 commit ea99172
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 147 deletions.
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Release Notes ⋮

### main

* Workflow improvements
* New URLs are downloaded immediately by default.
* Can immediately download the site for a newly created URL
with 1 extra click.

* Minor fixes
* Fix closing a project to no longer have a couple of heap-use-after-free
issues which could corrupt memory, potentially crashing Crystal later.
Expand Down
26 changes: 25 additions & 1 deletion src/crystal/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,14 @@ def _on_new_root_url_dialog_ok(self,
name: str,
url: str,
change_prefix_command: ChangePrefixCommand,
download_immediately: bool,
create_group: bool,
) -> None:
if url == '':
raise ValueError('Invalid blank URL')

try:
RootResource(self.project, name, Resource(self.project, url))
rr = RootResource(self.project, name, Resource(self.project, url))
except RootResource.AlreadyExists:
raise ValueError('Invalid duplicate URL')

Expand All @@ -534,13 +536,25 @@ def _on_new_root_url_dialog_ok(self,
self.entity_tree.clear_default_url_prefix()
else:
self.entity_tree.set_default_url_prefix(*change_prefix_command)

if create_group:
assert url.endswith('/')
rg = ResourceGroup(self.project, '', url + '**', source=rr)

if download_immediately:
rg.download(needs_result=False)
else:
if download_immediately:
rr.download(needs_result=False)

@fg_affinity
def _on_edit_root_url_dialog_ok(self,
rr: RootResource,
name: str,
url: str,
change_prefix_command: ChangePrefixCommand,
download_immediately: bool,
create_group: bool,
) -> None:
if url != rr.url:
raise ValueError()
Expand All @@ -558,6 +572,9 @@ def _on_edit_root_url_dialog_ok(self,
self.entity_tree.clear_default_url_prefix()
else:
self.entity_tree.set_default_url_prefix(*change_prefix_command)

assert download_immediately == False
assert create_group == False

# === Entity Pane: New/Edit Group ===

Expand All @@ -580,13 +597,17 @@ def _on_new_group_dialog_ok(self,
url_pattern: str,
source: ResourceGroupSource,
do_not_download: bool,
download_immediately: bool,
) -> None:
# TODO: Validate user input:
# * Is url_pattern empty?
# * Is url_pattern already taken?
rg = ResourceGroup(
self.project, name, url_pattern, source,
do_not_download=do_not_download)

if download_immediately:
rg.download(needs_result=False)

@fg_affinity
def _on_edit_group_dialog_ok(self,
Expand All @@ -595,6 +616,7 @@ def _on_edit_group_dialog_ok(self,
url_pattern: str,
source: ResourceGroupSource,
do_not_download: bool,
download_immediately: bool,
) -> None:
if url_pattern != rg.url_pattern:
raise ValueError()
Expand All @@ -603,6 +625,8 @@ def _on_edit_group_dialog_ok(self,
# TODO: This update should happen in response to an event
# fired by the entity itself.
self.entity_tree.root.update_title_of_descendants() # update names in titles

assert download_immediately == False

def _saving_source_would_create_cycle(self, rg: ResourceGroup, source: ResourceGroupSource) -> bool:
ancestor_source = source # type: ResourceGroupSource
Expand Down
46 changes: 41 additions & 5 deletions src/crystal/browser/new_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NewGroupDialog:

def __init__(self,
parent: wx.Window,
on_finish: Callable[[str, str, ResourceGroupSource, bool], None],
on_finish: Callable[[str, str, ResourceGroupSource, bool, bool], None],
project: Project,
saving_source_would_create_cycle_func: Callable[[ResourceGroupSource], bool],
initial_url_pattern: str='',
Expand All @@ -59,6 +59,7 @@ def __init__(self,
self._project = project
self._on_finish = on_finish
self._saving_source_would_create_cycle_func = saving_source_would_create_cycle_func
self._is_edit = is_edit

# Show progress dialog in advance if will need to load all project URLs
try:
Expand Down Expand Up @@ -91,9 +92,16 @@ def __init__(self,
flag=wx.EXPAND|preview_box_flags,
border=preview_box_border)

self._options_sizer = self._create_advanced_options(dialog, initial_do_not_download)
if not is_edit:
new_options_sizer = self._create_new_options(dialog)
content_sizer.Add(
new_options_sizer,
flag=wx.EXPAND|wx.TOP,
border=_ABOVE_OPTIONS_PADDING)

self._advanced_options_sizer = self._create_advanced_options(dialog, initial_do_not_download)
content_sizer.Add(
self._options_sizer,
self._advanced_options_sizer,
flag=wx.EXPAND|wx.TOP,
border=_ABOVE_OPTIONS_PADDING)

Expand Down Expand Up @@ -238,6 +246,28 @@ def _create_preview_box_content(self, parent: wx.Window) -> wx.Sizer:

return content_sizer

def _create_new_options(self, parent: wx.Window) -> wx.StaticBoxSizer:
options_sizer = wx.StaticBoxSizer(wx.VERTICAL, parent, label='New Group Options')
options_sizer.Add(
wrap_static_box_sizer_child(
self._create_new_options_content(
options_sizer.GetStaticBox())),
flag=wx.EXPAND)
return options_sizer

def _create_new_options_content(self, parent: wx.Window) -> wx.Sizer:
options_sizer = wx.BoxSizer(wx.VERTICAL)

self._download_immediately_checkbox = wx.CheckBox(parent,
label='Download Group Immediately',
name='cr-new-group-dialog__download-immediately-checkbox')
self._download_immediately_checkbox.Value = False
options_sizer.Add(self._download_immediately_checkbox,
flag=wx.BOTTOM,
border=_FORM_LABEL_INPUT_SPACING)

return options_sizer

def _create_advanced_options(self, parent: wx.Window, *args, **kwargs) -> wx.StaticBoxSizer:
options_sizer = wx.StaticBoxSizer(wx.VERTICAL, parent, label='Advanced Options')
options_sizer.Add(
Expand Down Expand Up @@ -455,7 +485,13 @@ def _on_ok(self) -> None:
assert wx.ID_OK == choice
return
do_not_download = self.do_not_download_checkbox.Value
self._on_finish(name, url_pattern, source, do_not_download)
if self._is_edit:
download_immediately = False
else:
download_immediately = self._download_immediately_checkbox.Value
self._on_finish(
name, url_pattern, source, do_not_download,
download_immediately)

self.dialog.Destroy()

Expand All @@ -465,7 +501,7 @@ def _on_cancel(self) -> None:

@fg_affinity
def _on_options_toggle(self) -> None:
options = self._options_sizer.GetStaticBox()
options = self._advanced_options_sizer.GetStaticBox()
if options.Shown:
# Hide
self._options_button.Label = _OPTIONS_NOT_SHOWN_LABEL
Expand Down
Loading

0 comments on commit ea99172

Please sign in to comment.