mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
refactor custom commands
more custom command refactoring
This commit is contained in:
56
pkg/gui/services/custom_commands/session_state_loader.go
Normal file
56
pkg/gui/services/custom_commands/session_state_loader.go
Normal file
@ -0,0 +1,56 @@
|
||||
package custom_commands
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||
)
|
||||
|
||||
// loads the session state at the time that a custom command is invoked, for use
|
||||
// in the custom command's template strings
|
||||
type SessionStateLoader struct {
|
||||
contexts *context.ContextTree
|
||||
helpers *helpers.Helpers
|
||||
}
|
||||
|
||||
func NewSessionStateLoader(contexts *context.ContextTree, helpers *helpers.Helpers) *SessionStateLoader {
|
||||
return &SessionStateLoader{
|
||||
contexts: contexts,
|
||||
helpers: helpers,
|
||||
}
|
||||
}
|
||||
|
||||
// SessionState captures the current state of the application for use in custom commands
|
||||
type SessionState struct {
|
||||
SelectedLocalCommit *models.Commit
|
||||
SelectedReflogCommit *models.Commit
|
||||
SelectedSubCommit *models.Commit
|
||||
SelectedFile *models.File
|
||||
SelectedPath string
|
||||
SelectedLocalBranch *models.Branch
|
||||
SelectedRemoteBranch *models.RemoteBranch
|
||||
SelectedRemote *models.Remote
|
||||
SelectedTag *models.Tag
|
||||
SelectedStashEntry *models.StashEntry
|
||||
SelectedCommitFile *models.CommitFile
|
||||
SelectedCommitFilePath string
|
||||
CheckedOutBranch *models.Branch
|
||||
}
|
||||
|
||||
func (self *SessionStateLoader) call() *SessionState {
|
||||
return &SessionState{
|
||||
SelectedFile: self.contexts.Files.GetSelectedFile(),
|
||||
SelectedPath: self.contexts.Files.GetSelectedPath(),
|
||||
SelectedLocalCommit: self.contexts.LocalCommits.GetSelected(),
|
||||
SelectedReflogCommit: self.contexts.ReflogCommits.GetSelected(),
|
||||
SelectedLocalBranch: self.contexts.Branches.GetSelected(),
|
||||
SelectedRemoteBranch: self.contexts.RemoteBranches.GetSelected(),
|
||||
SelectedRemote: self.contexts.Remotes.GetSelected(),
|
||||
SelectedTag: self.contexts.Tags.GetSelected(),
|
||||
SelectedStashEntry: self.contexts.Stash.GetSelected(),
|
||||
SelectedCommitFile: self.contexts.CommitFiles.GetSelectedFile(),
|
||||
SelectedCommitFilePath: self.contexts.CommitFiles.GetSelectedPath(),
|
||||
SelectedSubCommit: self.contexts.SubCommits.GetSelected(),
|
||||
CheckedOutBranch: self.helpers.Refs.GetCheckedOutRef(),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user