Skip to content

Commit

Permalink
Merge pull request #78 from MHNightCat/help-menu
Browse files Browse the repository at this point in the history
Help menu
  • Loading branch information
yorukot authored Apr 27, 2024
2 parents ee28584 + c061ca9 commit d20f203
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/components/config_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ var (
modalCancelBGColor lipgloss.Color
modalConfirmFGColor lipgloss.Color
modalConfirmBGColor lipgloss.Color

helpMenuHotkeyColor lipgloss.Color
helpMenuTitleColor lipgloss.Color
)

// Theme configuration
Expand Down Expand Up @@ -98,6 +101,9 @@ type ThemeType struct {
ModalCancelBG string `toml:"modal_cancel_bg"`
ModalConfirmFG string `toml:"modal_confirm_fg"`
ModalConfirmBG string `toml:"modal_confirm_bg"`

HelpMenuHotkey string `toml:"help_menu_hotkey"`
HelpMenuTitle string `toml:"help_menu_title"`
}

// Configuration settings
Expand Down Expand Up @@ -125,6 +131,7 @@ type HotkeysType struct {
FocusOnMetaData []string `toml:"focus_on_meta_data"`

ChangePanelMode []string `toml:"change_panel_mode" comment:"\n"`
OpenHelpMenu []string `toml:"open_help_menu"`

FilePanelDirectoryCreate []string `toml:"file_panel_directory_create" comment:"\n"`
FilePanelFileCreate []string `toml:"file_panel_file_create"`
Expand Down
195 changes: 194 additions & 1 deletion src/components/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ focus_on_side_bar = ['b', '']
focus_on_meta_data = ['m', '']
#
change_panel_mode = ['v', '']
open_help_menu = ['?', '']
#
file_panel_directory_create = ['f', '']
file_panel_file_create = ['c', '']
Expand Down Expand Up @@ -62,4 +63,196 @@ footer_panel_list = ['processessssssssssss', 'metadata', 'clipboard']
#
# Show more detailed metadata, please install exiftool before enabling this plugin!
metadata = false
`
`

func getHelpMenuData() []helpMenuModalData {
data := []helpMenuModalData{
{
subTitle: "General",
},
{
hotkey: hotkeys.Quit,
description: "Quit",
hotkeyWorkType: globalType,
},
{
subTitle: "Panel navigation",
},
{
hotkey: hotkeys.PinnedDirectory,
description: "Pin or Unpin folder to sidebar (can be auto saved)",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.CreateNewFilePanel,
description: "Create new file panel",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.CloseFilePanel,
description: "Close the focused file panel",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.NextFilePanel,
description: "Focus on the next file panel",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.PreviousFilePanel,
description: "Focus on the previous file panel",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.FocusOnProcessBar,
description: "Focus on the processbar panel",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.FocusOnSideBar,
description: "Focus on the sidebar",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.FocusOnMetaData,
description: "Focus on the metadata panel",
hotkeyWorkType: globalType,
},
{
subTitle: "Panel movement",
},
{
hotkey: hotkeys.ChangePanelMode,
description: "Change between selection mode or normal mode",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.ListUp,
description: "Up",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.ListDown,
description: "Down",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.SelectItem,
description: "Go to folder",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.ParentDirectory,
description: "Return to parent folder",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.FilePanelSelectAllItem,
description: "Select all items in focused file panel",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.FilePanelSelectModeItemSelectUp,
description: "Select with your course",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.SelectItem,
description: "Select with your course",
hotkeyWorkType: selectType,
},
{
hotkey: hotkeys.FilePanelSelectModeItemSingleSelect,
description: "Select the item where the current cursor is located",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.ToggleDotFile,
description: "Toggle dot file display",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.SearchBar,
description: "Toggle active search bar",
hotkeyWorkType: globalType,
},
{
subTitle: "File operations",
},
{
hotkey: hotkeys.FilePanelDirectoryCreate,
description: "Create a new folder",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.FilePanelFileCreate,
description: "Create a new file",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.FilePanelItemRename,
description: "Rename file or folder",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.ExtractFile,
description: "Extract zip file",
hotkeyWorkType: normalType,
},
{
hotkey: hotkeys.CompressFile,
description: "Zip file or folder to .zip file",
hotkeyWorkType: normalType,
},
{
hotkey: hotkeys.DeleteItem,
description: "Delete file or folder (or both)",
hotkeyWorkType: normalType,
},
{
hotkey: hotkeys.CopySingleItem,
description: "Copy file or folder (or both)",
hotkeyWorkType: normalType,
},
{
hotkey: hotkeys.FilePanelSelectModeItemCut,
description: "Cut file or folder (or both)",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.PasteItem,
description: "Paste all items in your clipboard",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.SelectItem,
description: "Open file with your default application",
hotkeyWorkType: selectType,
},
{
hotkey: hotkeys.OpenFileWithEditor,
description: "Open file with your default editor",
hotkeyWorkType: normalType,
},
{
hotkey: hotkeys.OpenCurrentDirectoryWithEditor,
description: "Open current directory with default editor",
hotkeyWorkType: normalType,
},
{
subTitle: "Special",
},
{
hotkey: hotkeys.Confirm,
description: "Confirm rename or create item or exit search bar",
hotkeyWorkType: globalType,
},
{
hotkey: hotkeys.Cancel,
description: "Cancel rename or create item or exit search bar and clear search bar value",
hotkeyWorkType: globalType,
},
}

return data
}
1 change: 0 additions & 1 deletion src/components/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,6 @@ func generateSearchBar() textinput.Model {
}

func moveElement(src, dst string) error {
// 移动文件
err := os.Rename(src, dst)
if err != nil {
return fmt.Errorf("failed to move file: %v", err)
Expand Down
10 changes: 10 additions & 0 deletions src/components/global_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,14 @@ func openDirectoryWithEditor(m model) tea.Cmd {
return tea.ExecProcess(c, func(err error) tea.Msg {
return editorFinishedMsg{err}
})
}

func openHelpMenu(m model) model {
if m.helpMenu.open {
m.helpMenu.open = false
return m
}

m.helpMenu.open = true
return m
}
15 changes: 15 additions & 0 deletions src/components/key_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func mainKey(msg string, m model, cmd tea.Cmd) (model, tea.Cmd) {
go func() {
m = compressFile(m)
}()
case hotkeys.OpenHelpMenu[0], hotkeys.OpenHelpMenu[1]:
m = openHelpMenu(m)
case hotkeys.OpenFileWithEditor[0], hotkeys.OpenFileWithEditor[1]:
cmd = openFileWithEditor(m)
case hotkeys.OpenCurrentDirectoryWithEditor[0], hotkeys.OpenCurrentDirectoryWithEditor[1]:
Expand Down Expand Up @@ -199,3 +201,16 @@ func focusOnSearchbarKey(msg string, m model) model {
}
return m
}

func helpMenuKey(msg string, m model) model {
switch msg {
case hotkeys.ListUp[0], hotkeys.ListUp[1]:
m = helpMenuListUp(m)
case hotkeys.ListDown[0], hotkeys.ListDown[1]:
m = helpMenuListDown(m)
case hotkeys.Quit[0], hotkeys.Quit[1]:
m = quitHelpMenu(m)
}

return m
}
28 changes: 27 additions & 1 deletion src/components/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func InitialModel(dir string) model {
},
width: 10,
},
helpMenu: helpMenuModal{
renderIndex: 0,
cursor: 1,
data: getHelpMenuData(),
open: false,
},
toggleDotFile: toggleDotFileBool,
}
}
Expand All @@ -96,7 +102,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
switch msg := msg.(type) {
case channelMessage:
if msg.returnWarnModal {
if msg.returnWarnModal {
m.warnModal = msg.warnModal
} else if msg.loadMetadata {
m.fileMetaData.metaData = msg.metadata
Expand All @@ -108,16 +114,30 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
forceReloadElement = true
case tea.WindowSizeMsg:

if msg.Height < 30 {
footerHeight = 10
} else {
footerHeight = 14
}

m.mainPanelHeight = msg.Height - footerHeight + 1
m.fileModel.width = (msg.Width - sidebarWidth - (4 + (len(m.fileModel.filePanels)-1)*2)) / len(m.fileModel.filePanels)
m.fullHeight = msg.Height
m.fullWidth = msg.Width
m.fileModel.maxFilePanel = (msg.Width - 20) / 24

m.helpMenu.height = m.fullHeight -2
m.helpMenu.width = m.fullWidth -2

if m.fullHeight > 32 {
m.helpMenu.height = 30
}

if m.fullWidth > 92 {
m.helpMenu.width = 90
}

if m.fileModel.maxFilePanel >= 10 {
m.fileModel.maxFilePanel = 10
}
Expand All @@ -131,12 +151,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m = renamingKey(msg.String(), m)
} else if panel.searchBar.Focused() {
m = focusOnSearchbarKey(msg.String(), m)
} else if m.helpMenu.open {
m = helpMenuKey(msg.String(), m)
} else {
// return superfile
if msg.String() == hotkeys.Quit[0] || msg.String() == hotkeys.Quit[1] {
return m, tea.Quit
}

m, cmd = mainKey(msg.String(), m, cmd)

if m.editorMode {
m.editorMode = false
return m, cmd
Expand Down Expand Up @@ -196,6 +220,8 @@ func (m model) View() string {
return typineModalRender(m)
} else if m.warnModal.open {
return warnModalRender(m)
} else if m.helpMenu.open {
return helpMenuRender(m)
} else {
sidebar := sidebarRender(m)

Expand Down
Loading

0 comments on commit d20f203

Please sign in to comment.