Fix tabview

pull/6/head
reionwong 4 years ago
parent 6d59082ad9
commit 3ce786fd12

@ -43,7 +43,6 @@ FishUI.Window {
readonly property QMLTermWidget currentTerminal: currentItem ? currentItem.terminal : null readonly property QMLTermWidget currentTerminal: currentItem ? currentItem.terminal : null
GlobalSettings { id: settings } GlobalSettings { id: settings }
ObjectModel { id: tabsModel }
ExitPromptDialog { ExitPromptDialog {
id: exitPrompt id: exitPrompt
@ -77,8 +76,8 @@ FishUI.Window {
} }
// Exit prompt. // Exit prompt.
for (var i = 0; i < tabsModel.count; ++i) { for (var i = 0; i < _tabView.contentModel.count; ++i) {
var obj = tabsModel.get(i) var obj = _tabView.contentModel.get(i)
if (obj.session.hasActiveProcess) { if (obj.session.hasActiveProcess) {
exitPrompt.index = -1 exitPrompt.index = -1
exitPrompt.visible = true exitPrompt.visible = true
@ -126,7 +125,7 @@ FishUI.Window {
} }
onCloseClicked: { onCloseClicked: {
_tabView.closeTab(index) root.closeProtection(index)
} }
} }
} }
@ -152,23 +151,19 @@ FishUI.Window {
} }
function openTab(path) { function openTab(path) {
if (tabsModel.count > 7) if (_tabView.contentModel.count > 7)
return return
const component = Qt.createComponent("Terminal.qml"); const component = Qt.createComponent("Terminal.qml");
if (component.status === Component.Ready) { if (component.status === Component.Ready) {
// const object = component.createObject(tabsModel, {'path': path}) const index = _tabView.contentModel.count
// tabsModel.append(object) const object = _tabView.addTab(component, {})
// const index = tabsModel.count - 1 object.terminalClosed.connect(() => closeTab(index))
// _view.currentIndex = index
// object.terminalClosed.connect(() => closeTab(index))
_tabView.addTab(component, {})
} }
} }
function closeProtection(index) { function closeProtection(index) {
var obj = tabsModel.get(index) var obj = _tabView.contentModel.get(index)
if (obj.session.hasActiveProcess) { if (obj.session.hasActiveProcess) {
exitPrompt.index = index exitPrompt.index = index
exitPrompt.visible = true exitPrompt.visible = true
@ -179,17 +174,9 @@ FishUI.Window {
} }
function closeTab(index) { function closeTab(index) {
tabsModel.remove(index) _tabView.closeTab(index)
if (index === tabsModel.count) {
_tabView.currentIndex = tabsModel.count - 1
} else if (index === _tabView.currentIndex) {
// Reion: Need to reset index.
_tabView.currentIndex = -1
_tabView.currentIndex = index
}
if (tabsModel.count == 0) if (_tabView.contentModel.count === 0)
Qt.quit() Qt.quit()
} }
@ -200,7 +187,7 @@ FishUI.Window {
function toggleTab() { function toggleTab() {
var nextIndex = _tabView.currentIndex var nextIndex = _tabView.currentIndex
++nextIndex ++nextIndex
if (nextIndex > tabsModel.count - 1) if (nextIndex > _tabView.contentModel.count - 1)
nextIndex = 0 nextIndex = 0
_tabView.currentIndex = nextIndex _tabView.currentIndex = nextIndex

Loading…
Cancel
Save