From b1b31dff621845bb93384fb1acade6ddef6c5e48 Mon Sep 17 00:00:00 2001 From: Richard Burke Date: Wed, 13 Mar 2019 22:25:05 +0000 Subject: Added diff-view-file variable The diff-view-file variable contains the currently selected file in the diff view --- cmd/grv/abstract_window_view_test.go | 4 ++++ cmd/grv/diff_view.go | 18 ++++++++++++++++++ cmd/grv/grv_variables.go | 12 ++++++++++++ doc/documentation.md | 25 +++++++++++++------------ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/cmd/grv/abstract_window_view_test.go b/cmd/grv/abstract_window_view_test.go index abfe2c2..ef1008b 100644 --- a/cmd/grv/abstract_window_view_test.go +++ b/cmd/grv/abstract_window_view_test.go @@ -237,6 +237,10 @@ func (variables *MockGRVVariableSetter) SetViewVariable(variable GRVVariable, va variables.Called(variable, value, viewState) } +func (variables *MockGRVVariableSetter) ClearViewVariable(variable GRVVariable, viewState ViewState) { + variables.Called(variable, viewState) +} + func (variables *MockGRVVariableSetter) VariableValues() map[GRVVariable]string { args := variables.Called() return args.Get(0).(map[GRVVariable]string) diff --git a/cmd/grv/diff_view.go b/cmd/grv/diff_view.go index 590b4b2..4bde79c 100644 --- a/cmd/grv/diff_view.go +++ b/cmd/grv/diff_view.go @@ -331,6 +331,18 @@ func (diffView *DiffView) RenderHelpBar(lineBuilder *LineBuilder) (err error) { return } +// OnStateChange updates whether this view is currently active +func (diffView *DiffView) OnStateChange(viewState ViewState) { + diffView.AbstractWindowView.OnStateChange(viewState) + + diffView.lock.Lock() + defer diffView.lock.Unlock() + + if viewState != ViewStateInvisible { + diffView.setVariables() + } +} + // ViewID returns the diff views ID func (diffView *DiffView) ViewID() ViewID { return ViewDiff @@ -849,6 +861,12 @@ func (diffView *DiffView) setVariables() { filePart = strings.TrimRight(filePart, " ") diffView.variables.SetViewVariable(VarFile, filePart, diffView.viewState) + + if diffView.viewState != ViewStateInvisible { + diffView.variables.SetViewVariable(VarDiffViewFile, filePart, diffView.viewState) + } + } else if diffView.viewState != ViewStateInvisible { + diffView.variables.ClearViewVariable(VarDiffViewFile, diffView.viewState) } return diff --git a/cmd/grv/grv_variables.go b/cmd/grv/grv_variables.go index ec3040f..778e640 100644 --- a/cmd/grv/grv_variables.go +++ b/cmd/grv/grv_variables.go @@ -14,6 +14,7 @@ const ( VarTag VarCommit VarFile + VarDiffViewFile VarLineText VarLineNumer VarLineCount @@ -56,6 +57,11 @@ var variableDescriptors = []variableDescriptor{ name: "file", description: "Selected file", }, + { + variable: VarDiffViewFile, + name: "diff-view-file", + description: "Selected DiffView file", + }, { variable: VarLineText, name: "line-text", @@ -123,6 +129,7 @@ type GRVVariableGetter interface { type GRVVariableSetter interface { GRVVariableGetter SetViewVariable(variable GRVVariable, value string, viewState ViewState) + ClearViewVariable(variable GRVVariable, viewState ViewState) } // GRVVariables stores the values of all variables @@ -153,6 +160,11 @@ func (grvVariables *GRVVariables) SetViewVariable(variable GRVVariable, value st } } +// ClearViewVariable clears the value of a GRV variable for a view +func (grvVariables *GRVVariables) ClearViewVariable(variable GRVVariable, viewState ViewState) { + grvVariables.SetViewVariable(variable, "", viewState) +} + // VariableValues returns the current values of all variables func (grvVariables *GRVVariables) VariableValues() map[GRVVariable]string { grvVariables.lock.Lock() diff --git a/doc/documentation.md b/doc/documentation.md index 141d0b7..7b6de4e 100644 --- a/doc/documentation.md +++ b/doc/documentation.md @@ -760,18 +760,19 @@ These variables represent the current state of the visible views. The set of variables available is: ``` - Variable | Description - -------------+------------------------------------ - head | Value of HEAD - branch | Selected branch - tag | Selected tag - commit | Selected commit - file | Selected file - line-text | Selected lines content - line-number | Selected line number - line-count | Number of lines in the active view - repo-path | Repository file path - repo-workdir | Work directory path + Variable | Description + ---------------+------------------------------------ + head | Value of HEAD + branch | Selected branch + tag | Selected tag + commit | Selected commit + file | Selected file + diff-view-file | Selected DiffView file + line-text | Selected lines content + line-number | Selected line number + line-count | Number of lines in the active view + repo-path | Repository file path + repo-workdir | Work directory path ``` Variables can be specified in shell commands using the syntax: -- cgit v1.2.3