Implement Add Request to create new tab for project
This commit is contained in:
parent
bd444ea0e5
commit
8cd7eefdd8
@ -1,5 +1,5 @@
|
|||||||
project('roster',
|
project('roster',
|
||||||
version: '0.6.1',
|
version: '0.6.2',
|
||||||
meson_version: '>= 1.0.0',
|
meson_version: '>= 1.0.0',
|
||||||
default_options: [ 'warning_level=2', 'werror=false', ],
|
default_options: [ 'warning_level=2', 'werror=false', ],
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1082,7 +1082,7 @@ class RosterWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
|
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
|
||||||
|
|
||||||
# Check if current tab has a saved request (for pre-filling)
|
# Check if current tab has a saved request or project (for pre-filling)
|
||||||
current_tab = None
|
current_tab = None
|
||||||
preselect_project_index = 0
|
preselect_project_index = 0
|
||||||
prefill_name = ""
|
prefill_name = ""
|
||||||
@ -1097,7 +1097,13 @@ class RosterWindow(Adw.ApplicationWindow):
|
|||||||
preselect_project_index = i
|
preselect_project_index = i
|
||||||
prefill_name = current_tab.name
|
prefill_name = current_tab.name
|
||||||
break
|
break
|
||||||
elif current_tab.name and current_tab.name != "New Request":
|
elif current_tab.project_id:
|
||||||
|
# Tab associated with a project (e.g., from "Add Request")
|
||||||
|
for i, p in enumerate(projects):
|
||||||
|
if p.id == current_tab.project_id:
|
||||||
|
preselect_project_index = i
|
||||||
|
break
|
||||||
|
if current_tab.name and current_tab.name != "New Request":
|
||||||
# Copy tab or named unsaved tab - prefill with tab name
|
# Copy tab or named unsaved tab - prefill with tab name
|
||||||
prefill_name = current_tab.name
|
prefill_name = current_tab.name
|
||||||
|
|
||||||
@ -1261,48 +1267,18 @@ class RosterWindow(Adw.ApplicationWindow):
|
|||||||
dialog.present(self)
|
dialog.present(self)
|
||||||
|
|
||||||
def _on_add_to_project(self, widget, project):
|
def _on_add_to_project(self, widget, project):
|
||||||
"""Save current request to specific project."""
|
"""Create a new empty request tab associated with the project."""
|
||||||
request = self._build_request_from_ui()
|
# Get default environment for the project
|
||||||
|
default_env_id = project.environments[0].id if project.environments else None
|
||||||
|
|
||||||
if not request.url.strip():
|
# Create a new tab with project_id set so Save will pre-select this project
|
||||||
self._show_toast("Cannot save: URL is empty")
|
self._create_new_tab(
|
||||||
return
|
name="New Request",
|
||||||
|
project_id=project.id,
|
||||||
|
selected_environment_id=default_env_id
|
||||||
|
)
|
||||||
|
|
||||||
dialog = Adw.AlertDialog()
|
self._show_toast(f"New request for '{project.name}'")
|
||||||
dialog.set_heading(f"Save to {project.name}")
|
|
||||||
dialog.set_body("Enter a name for this request:")
|
|
||||||
|
|
||||||
entry = Gtk.Entry()
|
|
||||||
entry.set_placeholder_text("Request name")
|
|
||||||
dialog.set_extra_child(entry)
|
|
||||||
|
|
||||||
dialog.add_response("cancel", "Cancel")
|
|
||||||
dialog.add_response("save", "Save")
|
|
||||||
dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED)
|
|
||||||
|
|
||||||
def on_response(dlg, response):
|
|
||||||
if response == "save":
|
|
||||||
name = entry.get_text().strip()
|
|
||||||
is_valid, error_msg = self._validate_request_name(name)
|
|
||||||
if is_valid:
|
|
||||||
# Check for duplicate name
|
|
||||||
existing = self.project_manager.find_request_by_name(project.id, name)
|
|
||||||
if existing:
|
|
||||||
# Show overwrite confirmation
|
|
||||||
self._show_overwrite_dialog(project, name, existing.id, request)
|
|
||||||
else:
|
|
||||||
# No duplicate, save normally
|
|
||||||
saved_request = self.project_manager.add_request(project.id, name, request)
|
|
||||||
self._load_projects()
|
|
||||||
self._show_toast(f"Saved as '{name}'")
|
|
||||||
|
|
||||||
# Clear modified flag on current tab
|
|
||||||
self._mark_tab_as_saved(saved_request.id, name, request)
|
|
||||||
else:
|
|
||||||
self._show_toast(error_msg)
|
|
||||||
|
|
||||||
dialog.connect("response", on_response)
|
|
||||||
dialog.present(self)
|
|
||||||
|
|
||||||
def _on_load_request(self, widget, saved_request):
|
def _on_load_request(self, widget, saved_request):
|
||||||
"""Load saved request - smart loading based on current tab state."""
|
"""Load saved request - smart loading based on current tab state."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user