github.com/oam-dev/kubevela@v1.9.11/references/cli/top/view/page_stack.go (about)

     1  /*
     2  Copyright 2022 The KubeVela Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package view
    18  
    19  import (
    20  	"github.com/oam-dev/kubevela/references/cli/top/component"
    21  	"github.com/oam-dev/kubevela/references/cli/top/model"
    22  )
    23  
    24  // PageStack store views of app's main view, and it's a high level packing of "component.Pages"
    25  type PageStack struct {
    26  	*component.Pages
    27  	app *App
    28  }
    29  
    30  // NewPageStack returns a new page stack.
    31  func NewPageStack(app *App) *PageStack {
    32  	ps := &PageStack{
    33  		Pages: component.NewPages(),
    34  		app:   app,
    35  	}
    36  	return ps
    37  }
    38  
    39  // Init the pageStack
    40  func (ps *PageStack) Init() {
    41  	ps.Stack.AddListener(ps)
    42  }
    43  
    44  // StackPop change itself when accept "pop" notify from app's main view
    45  func (ps *PageStack) StackPop(old, new model.View) {
    46  	if new == nil {
    47  		return
    48  	}
    49  	ps.app.QueueUpdateDraw(new.Start)
    50  	ps.app.SetFocus(new)
    51  	go old.Stop()
    52  }
    53  
    54  // StackPush change itself when accept "pop" notify from app's main view
    55  func (ps *PageStack) StackPush(old, new model.View) {
    56  	ps.app.QueueUpdateDraw(new.Start)
    57  	ps.app.SetFocus(new)
    58  	if old != nil {
    59  		go old.Stop()
    60  	}
    61  }