MCPcopy Create free account
hub / github.com/bajrangCoder/setu / duplicate_request

Method duplicate_request

src/views/main_view.rs:1803–1895  ·  view source on GitHub ↗
(&mut self, window: &mut Window, cx: &mut Context<Self>)

Source from the content-addressed store, hash-verified

1801
1802 /// Switch the active tab's protocol (REST <-> WebSocket).
1803 pub fn set_active_protocol(
1804 &mut self,
1805 protocol: ProtocolType,
1806 window: &mut Window,
1807 cx: &mut Context<Self>,
1808 ) {
1809 let Some(tab) = self.tabs.get(self.active_tab_index) else {
1810 return;
1811 };
1812 let current = tab.protocol();
1813 if current == protocol || matches!(tab.content, TabContent::Environment { .. }) {
1814 return;
1815 }
1816 if !matches!(protocol, ProtocolType::Rest | ProtocolType::WebSocket) {
1817 return;
1818 }
1819
1820 // Convert empty-ish tabs in place; otherwise open a fresh tab of the target type.
1821 let is_emptyish = match &tab.content {
1822 TabContent::Request {
1823 request, url_input, ..
1824 } => {
1825 let url = url_input
1826 .as_ref()
1827 .map(|i| i.read(cx).text().to_string())
1828 .unwrap_or_else(|| request.read(cx).url().to_string());
1829 url.trim().is_empty() && !tab.is_custom_name
1830 }
1831 TabContent::WebSocket { view } => {
1832 view.read(cx).current_url(cx).trim().is_empty() && !tab.is_custom_name
1833 }
1834 TabContent::Environment { .. } => false,
1835 };
1836
1837 if !is_emptyish {
1838 // Ask before discarding non-empty configuration.
1839 let this = cx.entity().clone();
1840 let target = protocol;
1841 open_dialog(window, cx, move |dialog, _, _| {
1842 let this_click = this.clone();
1843 dialog
1844 .title("Switch protocol?")
1845 .child(
1846 "Switching protocols opens a new tab so your current request is kept. Continue?",
1847 )
1848 .footer({
1849 DialogFooter::new()
1850 .child(
1851 Button::new("switch-protocol-confirm")
1852 .primary()
1853 .label("Open new tab")
1854 .on_click(move |_, window, cx| {
1855 this_click.update(cx, |view, cx| match target {
1856 ProtocolType::WebSocket => {
1857 view.new_websocket_tab(window, cx);
1858 }
1859 ProtocolType::Rest => {
1860 view.new_tab(cx);

Callers 1

renderMethod · 0.80

Calls 15

get_body_typeMethod · 0.80
methodMethod · 0.80
headersMethod · 0.80
bodyMethod · 0.80
textMethod · 0.80
urlMethod · 0.80
with_headersMethod · 0.80
with_methodMethod · 0.80
active_tabMethod · 0.45

Tested by

no test coverage detected