summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-12-30 23:24:24 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:52 +1000
commit8edad826caf2fa48bfad33f9f8c4f3ba49a052da (patch)
tree0b49145e4f656e72441199b5a5c30176c898d7a7 /pkg/gui
parent826128a8e03fb50f7287029ebac93c85712faecb (diff)
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the gui package purely for the sake of better encapsulation
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/app_status_manager.go3
-rw-r--r--pkg/gui/arrangement.go100
-rw-r--r--pkg/gui/background.go59
-rw-r--r--pkg/gui/branches_panel.go23
-rw-r--r--pkg/gui/commit_files_panel.go52
-rw-r--r--pkg/gui/commit_message_panel.go3
-rw-r--r--pkg/gui/commits_panel.go88
-rw-r--r--pkg/gui/confirmation_panel.go15
-rw-r--r--pkg/gui/context.go304
-rw-r--r--pkg/gui/context/base_context.go38
-rw-r--r--pkg/gui/context/branches_context.go32
-rw-r--r--pkg/gui/context/commit_files_context.go62
-rw-r--r--pkg/gui/context/local_commits_context.go21
-rw-r--r--pkg/gui/context/menu_context.go10
-rw-r--r--pkg/gui/context/reflog_commits_context.go21
-rw-r--r--pkg/gui/context/remote_branches_context.go21
-rw-r--r--pkg/gui/context/remotes_context.go21
-rw-r--r--pkg/gui/context/simple_context.go34
-rw-r--r--pkg/gui/context/stash_context.go21
-rw-r--r--pkg/gui/context/sub_commits_context.go21
-rw-r--r--pkg/gui/context/submodules_context.go10
-rw-r--r--pkg/gui/context/suggestions_context.go10
-rw-r--r--pkg/gui/context/tags_context.go21
-rw-r--r--pkg/gui/context/working_tree_context.go10
-rw-r--r--pkg/gui/context_config.go76
-rw-r--r--pkg/gui/controllers.go60
-rw-r--r--pkg/gui/controllers/attach.go3
-rw-r--r--pkg/gui/controllers/base_controller.go12
-rw-r--r--pkg/gui/controllers/branches_controller.go24
-rw-r--r--pkg/gui/controllers/confirmation_controller.go53
-rw-r--r--pkg/gui/controllers/files_controller.go73
-rw-r--r--pkg/gui/controllers/helpers/diff_helper.go114
-rw-r--r--pkg/gui/controllers/helpers/helpers.go47
-rw-r--r--pkg/gui/controllers/helpers/merge_conflicts_helper.go39
-rw-r--r--pkg/gui/controllers/helpers/patch_building_helper.go57
-rw-r--r--pkg/gui/controllers/helpers/record_directory_helper.go38
-rw-r--r--pkg/gui/controllers/helpers/refresh_helper.go617
-rw-r--r--pkg/gui/controllers/helpers/repos_helper.go175
-rw-r--r--pkg/gui/controllers/helpers/snake_helper.go76
-rw-r--r--pkg/gui/controllers/helpers/staging_helper.go119
-rw-r--r--pkg/gui/controllers/helpers/update_helper.go98
-rw-r--r--pkg/gui/controllers/helpers/view_helper.go33
-rw-r--r--pkg/gui/controllers/helpers/window_helper.go138
-rw-r--r--pkg/gui/controllers/local_commits_controller.go63
-rw-r--r--pkg/gui/controllers/menu_controller.go8
-rw-r--r--pkg/gui/controllers/merge_conflicts_controller.go18
-rw-r--r--pkg/gui/controllers/reflog_commits_controller.go53
-rw-r--r--pkg/gui/controllers/remote_branches_controller.go23
-rw-r--r--pkg/gui/controllers/remotes_controller.go26
-rw-r--r--pkg/gui/controllers/snake_controller.go21
-rw-r--r--pkg/gui/controllers/stash_controller.go22
-rw-r--r--pkg/gui/controllers/status_controller.go198
-rw-r--r--pkg/gui/controllers/sub_commits_controller.go70
-rw-r--r--pkg/gui/controllers/submodules_controller.go41
-rw-r--r--pkg/gui/controllers/suggestions_controller.go43
-rw-r--r--pkg/gui/controllers/switch_to_diff_files_controller.go28
-rw-r--r--pkg/gui/controllers/tags_controller.go23
-rw-r--r--pkg/gui/custom_patch_options_panel.go6
-rw-r--r--pkg/gui/diff_context_size_test.go182
-rw-r--r--pkg/gui/diffing.go103
-rw-r--r--pkg/gui/extras_panel.go4
-rw-r--r--pkg/gui/file_watching.go8
-rw-r--r--pkg/gui/files_panel.go95
-rw-r--r--pkg/gui/filtering_menu_panel.go4
-rw-r--r--pkg/gui/global_handlers.go35
-rw-r--r--pkg/gui/gui.go177
-rw-r--r--pkg/gui/gui_common.go68
-rw-r--r--pkg/gui/keybindings.go43
-rw-r--r--pkg/gui/layout.go39
-rw-r--r--pkg/gui/list_context_config.go45
-rw-r--r--pkg/gui/main_panels.go4
-rw-r--r--pkg/gui/modes.go7
-rw-r--r--pkg/gui/options_map.go56
-rw-r--r--pkg/gui/options_menu_panel.go2
-rw-r--r--pkg/gui/presentation/working_tree.go14
-rw-r--r--pkg/gui/quitting.go43
-rw-r--r--pkg/gui/recent_repos_panel.go150
-rw-r--r--pkg/gui/refresh.go739
-rw-r--r--pkg/gui/remote_branches_panel.go22
-rw-r--r--pkg/gui/remotes_panel.go29
-rw-r--r--pkg/gui/searching.go5
-rw-r--r--pkg/gui/side_window.go22
-rw-r--r--pkg/gui/snake.go56
-rw-r--r--pkg/gui/stash_panel.go21
-rw-r--r--pkg/gui/status_panel.go141
-rw-r--r--pkg/gui/sub_commits_panel.go43
-rw-r--r--pkg/gui/submodules_panel.go51
-rw-r--r--pkg/gui/suggestions_panel.go2
-rw-r--r--pkg/gui/tags_panel.go22
-rw-r--r--pkg/gui/tasks_adapter.go8
-rw-r--r--pkg/gui/types/common.go60
-rw-r--r--pkg/gui/types/context.go17
-rw-r--r--pkg/gui/types/refresh.go3
-rw-r--r--pkg/gui/types/views.go42
-rw-r--r--pkg/gui/updates.go85
-rw-r--r--pkg/gui/view_helpers.go76
-rw-r--r--pkg/gui/views.go50
-rw-r--r--pkg/gui/whitespace-toggle.go2
-rw-r--r--pkg/gui/window.go121
99 files changed, 3326 insertions, 2865 deletions
diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go
index 097a19438..02ba7779a 100644
--- a/pkg/gui/app_status_manager.go
+++ b/pkg/gui/app_status_manager.go
@@ -99,7 +99,8 @@ func (gui *Gui) renderAppStatus() {
for range ticker.C {
appStatus := gui.statusManager.getStatusString()
gui.c.OnUIThread(func() error {
- return gui.renderString(gui.Views.AppStatus, appStatus)
+ gui.c.SetViewContent(gui.Views.AppStatus, appStatus)
+ return nil
})
if appStatus == "" {
diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go
index ac6f2d9c1..d656f16d5 100644
--- a/pkg/gui/arrangement.go
+++ b/pkg/gui/arrangement.go
@@ -13,10 +13,14 @@ import (
const INFO_SECTION_PADDING = " "
-func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map[string]boxlayout.Dimensions {
- width, height := gui.g.Size()
+type WindowArranger struct {
+ gui *Gui
+}
+
+func (self *WindowArranger) getWindowDimensions(informationStr string, appStatus string) map[string]boxlayout.Dimensions {
+ width, height := self.gui.g.Size()
- sideSectionWeight, mainSectionWeight := gui.getMidSectionWeights()
+ sideSectionWeight, mainSectionWeight := self.getMidSectionWeights()
sidePanelsDirection := boxlayout.COLUMN
portraitMode := width <= 84 && height > 45
@@ -25,13 +29,13 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map
}
mainPanelsDirection := boxlayout.ROW
- if gui.splitMainPanelSideBySide() {
+ if self.splitMainPanelSideBySide() {
mainPanelsDirection = boxlayout.COLUMN
}
- extrasWindowSize := gui.getExtrasWindowSize(height)
+ extrasWindowSize := self.getExtrasWindowSize(height)
- showInfoSection := gui.c.UserConfig.Gui.ShowBottomLine || gui.State.Searching.isSearching || gui.isAnyModeActive() || gui.statusManager.showStatus()
+ showInfoSection := self.gui.c.UserConfig.Gui.ShowBottomLine || self.gui.State.Searching.isSearching || self.gui.isAnyModeActive() || self.gui.statusManager.showStatus()
infoSectionSize := 0
if showInfoSection {
infoSectionSize = 1
@@ -47,7 +51,7 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map
{
Direction: boxlayout.ROW,
Weight: sideSectionWeight,
- ConditionalChildren: gui.sidePanelChildren,
+ ConditionalChildren: self.sidePanelChildren,
},
{
Direction: boxlayout.ROW,
@@ -55,7 +59,7 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map
Children: []*boxlayout.Box{
{
Direction: mainPanelsDirection,
- Children: gui.mainSectionChildren(),
+ Children: self.mainSectionChildren(),
Weight: 1,
},
{
@@ -69,7 +73,7 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map
{
Direction: boxlayout.COLUMN,
Size: infoSectionSize,
- Children: gui.infoSectionChildren(informationStr, appStatus),
+ Children: self.infoSectionChildren(informationStr, appStatus),
},
},
}
@@ -91,12 +95,12 @@ func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
return result
}
-func (gui *Gui) mainSectionChildren() []*boxlayout.Box {
- currentWindow := gui.currentWindow()
+func (self *WindowArranger) mainSectionChildren() []*boxlayout.Box {
+ currentWindow := self.gui.helpers.Window.CurrentWindow()
// if we're not in split mode we can just show the one main panel. Likewise if
// the main panel is focused and we're in full-screen mode
- if !gui.isMainPanelSplit() || (gui.State.ScreenMode == SCREEN_FULL && currentWindow == "main") {
+ if !self.gui.isMainPanelSplit() || (self.gui.State.ScreenMode == SCREEN_FULL && currentWindow == "main") {
return []*boxlayout.Box{
{
Window: "main",
@@ -117,27 +121,27 @@ func (gui *Gui) mainSectionChildren() []*boxlayout.Box {
}
}
-func (gui *Gui) getMidSectionWeights() (int, int) {
- currentWindow := gui.currentWindow()
+func (self *WindowArranger) getMidSectionWeights() (int, int) {
+ currentWindow := self.gui.helpers.Window.CurrentWindow()
// we originally specified this as a ratio i.e. .20 would correspond to a weight of 1 against 4
- sidePanelWidthRatio := gui.c.UserConfig.Gui.SidePanelWidth
+ sidePanelWidthRatio := self.gui.c.UserConfig.Gui.SidePanelWidth
// we could make this better by creating ratios like 2:3 rather than always 1:something
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
sideSectionWeight := 1
- if gui.splitMainPanelSideBySide() {
+ if self.splitMainPanelSideBySide() {
mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side
}
if currentWindow == "main" {
- if gui.State.ScreenMode == SCREEN_HALF || gui.State.ScreenMode == SCREEN_FULL {
+ if self.gui.State.ScreenMode == SCREEN_HALF || self.gui.State.ScreenMode == SCREEN_FULL {
sideSectionWeight = 0
}
} else {
- if gui.State.ScreenMode == SCREEN_HALF {
+ if self.gui.State.ScreenMode == SCREEN_HALF {
mainSectionWeight = 1
- } else if gui.State.ScreenMode == SCREEN_FULL {
+ } else if self.gui.State.ScreenMode == SCREEN_FULL {
mainSectionWeight = 0
}
}
@@ -145,8 +149,8 @@ func (gui *Gui) getMidSectionWeights() (int, int) {
return sideSectionWeight, mainSectionWeight
}
-func (gui *Gui) infoSectionChildren(informationStr string, appStatus string) []*boxlayout.Box {
- if gui.State.Searching.isSearching {
+func (self *WindowArranger) infoSectionChildren(informationStr string, appStatus string) []*boxlayout.Box {
+ if self.gui.State.Searching.isSearching {
return []*boxlayout.Box{
{
Window: "searchPrefix",
@@ -162,7 +166,7 @@ func (gui *Gui) infoSectionChildren(informationStr string, appStatus string) []*
appStatusBox := &boxlayout.Box{Window: "appStatus"}
optionsBox := &boxlayout.Box{Window: "options"}
- if !gui.c.UserConfig.Gui.ShowBottomLine {
+ if !self.gui.c.UserConfig.Gui.ShowBottomLine {
optionsBox.Weight = 0
appStatusBox.Weight = 1
} else {
@@ -172,7 +176,7 @@ func (gui *Gui) infoSectionChildren(informationStr string, appStatus string) []*
result := []*boxlayout.Box{appStatusBox, optionsBox}
- if gui.c.UserConfig.Gui.ShowBo