From 5042d9d006283585f017d9a56579ee72424c215e Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Thu, 5 Mar 2020 11:33:03 +0100 Subject: [PATCH] fix bug where if a tab was opened when it was already open an error was created and nothing happened --- src/+gui_tabs/add_tab.m | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/+gui_tabs/add_tab.m b/src/+gui_tabs/add_tab.m index 37ecfb1..106282a 100644 --- a/src/+gui_tabs/add_tab.m +++ b/src/+gui_tabs/add_tab.m @@ -34,17 +34,7 @@ function [newTab, created] = add_tab(hObject, title) handles = guidata(hObject); if isfield(handles, 'tabGroup') == 0 - - hTabGroup = uitabgroup(handles.figure1,'Position',[0 0 1 1]); %, 'SelectionChangeFcn', {@selection_tab_changed}); - panel = handles.uipanel_welcome; - set(panel,'Visible','off'); - - drawnow; - handles.tabGroup = hTabGroup; - setappdata(0,'tabGroup', hTabGroup); - - % Update handles structure - guidata(hObject, handles); + handles = createTabGroup(handles, hObject); end created = 1; @@ -55,10 +45,11 @@ tab = checkIfExistsTab(tabGroup, title); if ~isempty(tab) % close existing tab so that it'll be redrawn gui_tabs.delete_tab(tab); -% set(handles.tabGroup, 'SelectedTab' , tab); -% newTab = tab; -% created = 0; -% return; + tabGroup = getappdata(0, 'tabGroup'); + if isempty(tabGroup) + handles = createTabGroup(handles, hObject); + tabGroup = getappdata(0, 'tabGroup'); + end end newTab = uitab(handles.tabGroup, 'Title', title); @@ -80,3 +71,16 @@ setappdata(0, 'tabGroup', tabGroup); end end end + +function handles = createTabGroup(handles, hObject) + hTabGroup = uitabgroup(handles.figure1,'Position',[0 0 1 1]); %, 'SelectionChangeFcn', {@selection_tab_changed}); + panel = handles.uipanel_welcome; + set(panel,'Visible','off'); + + drawnow; + handles.tabGroup = hTabGroup; + setappdata(0,'tabGroup', hTabGroup); + + % Update handles structure + guidata(hObject, handles); +end \ No newline at end of file -- GitLab