Skip to content

Commit

Permalink
feature: add new history navigation style, fix broken logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksey-hoffman committed Sep 12, 2021
1 parent a631a66 commit 1e886e1
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 17 deletions.
52 changes: 35 additions & 17 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ export default new Vuex.Store({
openDirItemSecondClickDelay: 500,
tabs: {
closeAppWindowWhenLastWorkspaceTabIsClosed: false
},
historyStyle: {
selected: 'sigma-default',
list: [
'sigma-default',
'traditional',
]
}
},
tips: [
Expand Down Expand Up @@ -1436,17 +1443,34 @@ export default new Vuex.Store({
const value = utils.getDeepProperty(state, key)
utils.setDeepProperty(state, key.split('.'), !value)
},
ADD_TO_HISTORY (state, options) {
UPDATE_NAVIGATOR_HISTORY (state, options) {
let historyItems = state.navigatorView.history.items
let historyItemsRaw = state.navigatorView.history.itemsRaw
let lastHistoryElement = historyItems[historyItems.length - 1]
let pathMatchesLastHistoryPath = lastHistoryElement === options.path
// Add path to "raw" list
historyItemsRaw.push(options.path)
// Add path to "no-consecutive-dups" list
if (!pathMatchesLastHistoryPath && !options.skipHistory) {
historyItems.push(options.path)
state.navigatorView.history.currentIndex = historyItems.length - 1
if (!pathMatchesLastHistoryPath) {
if (store.state.storageData.settings.navigator.historyStyle.selected === 'sigma-default') {
if (options.goForwardInHistory) {return}
else if (options.goBackwardInHistory) {
historyItems.push(options.path)
}
else {
historyItems.push(options.path)
state.navigatorView.history.currentIndex = historyItems.length - 1
}
}
if (store.state.storageData.settings.navigator.historyStyle.selected === 'traditional') {
if (options.goForwardInHistory) {return}
else if (options.goBackwardInHistory) {return}
else {
historyItems.splice(state.navigatorView.history.currentIndex + 1, historyItems.length - 1)
historyItems.push(options.path)
state.navigatorView.history.currentIndex = historyItems.length - 1
}
}
}
},
SET_WORKSPACES (state, workspaces) {
Expand Down Expand Up @@ -2911,7 +2935,7 @@ export default new Vuex.Store({
method: 'startWatchingCurrentDir',
params: options.path
})
store.commit('ADD_TO_HISTORY', options)
store.commit('UPDATE_NAVIGATOR_HISTORY', options)
store.dispatch('ADD_TO_DIR_ITEMS_TIMELINE', dirInfo.path)
store.dispatch('SORT_DIR_ITEMS')
store.dispatch('CLEAR_FILTER_FIELD')
Expand Down Expand Up @@ -3269,28 +3293,22 @@ export default new Vuex.Store({
store.state.globalSearch.widget = true
}
},
LOAD_PREVIOUS_HISTORY_PATH ({ state, commit, dispatch, getters }) {
async LOAD_PREVIOUS_HISTORY_PATH ({ state, commit, dispatch, getters }) {
const historyItems = state.navigatorView.history.items
const currentHistoryIndex = state.navigatorView.history.currentIndex
const previousHistoryPath = historyItems[currentHistoryIndex - 1]
if (currentHistoryIndex > 0) {
dispatch('LOAD_DIR', { path: previousHistoryPath, skipHistory: true })
dispatch('SET', {
key: 'navigatorView.history.currentIndex',
value: currentHistoryIndex - 1
})
await dispatch('LOAD_DIR', {path: previousHistoryPath, goBackwardInHistory: true})
state.navigatorView.history.currentIndex = currentHistoryIndex - 1
}
},
LOAD_NEXT_HISTORY_PATH ({ state, commit, dispatch, getters }) {
async LOAD_NEXT_HISTORY_PATH ({ state, commit, dispatch, getters }) {
const historyItems = state.navigatorView.history.items
const currentHistoryIndex = state.navigatorView.history.currentIndex
const nextHistoryPath = historyItems[currentHistoryIndex + 1]
if (currentHistoryIndex < historyItems.length - 1) {
dispatch('LOAD_DIR', { path: nextHistoryPath, skipHistory: true })
dispatch('SET', {
key: 'navigatorView.history.currentIndex',
value: currentHistoryIndex + 1
})
await dispatch('LOAD_DIR', {path: nextHistoryPath, goForwardInHistory: true})
state.navigatorView.history.currentIndex = currentHistoryIndex + 1
}
},
GO_UP_DIRECTORY ({ state, commit, dispatch, getters }) {
Expand Down
84 changes: 84 additions & 0 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,88 @@ Copyright © 2021 - present Aleksey Hoffman. All rights reserved.
</section-settings>
</v-tab-item>

<!-- tab::navigation -->
<v-tab-item transition="fade-in" reverse-transition="fade-in">
<!-- section::window-controls -->
<section-settings
class="content-area__content-card__section"
:header="{
icon: {
name: 'mdi-tab',
},
title: 'History'
}"
>
<template v-slot:content>
<div class="text--sub-title-1 mt-2">
Navigator history style
</div>
<v-radio-group
class="py-0 mt-0"
v-model="navigatorHistoryStyleSelected"
hide-details
>
<v-tooltip bottom max-width="400px">
<template v-slot:activator="{ on }">
<v-radio
v-on="on"
label="Sigma default"
value="sigma-default"
></v-radio>
</template>
<span>
This custom Sigma history style allows you to get back to previously opened paths,
even after inserting a new path into the history while navigating the history stack.
<br><b>Example:</b>
<br>- Open directory <span class="inline-code--light py-0">"/user"</span>
<br>- Open directory <span class="inline-code--light py-0">"/user/pictures"</span>
<br>- Open directory <span class="inline-code--light py-0">"/user/pictures/screenshots"</span>
<br>If you now go back to directory
<span class="inline-code--light py-0">"/user/pictures"</span>
and then go back again to
<span class="inline-code--light py-0">"/user"</span>
and then open
<span class="inline-code--light py-0">"/user/videos"</span>,
you will still be able to go back in history to the previous directories by pressing
"go back" or "go forward" button.
</span>
</v-tooltip>

<v-tooltip bottom max-width="400px">
<template v-slot:activator="{ on }">
<v-radio
v-on="on"
label="Traditional"
value="traditional"
></v-radio>
</template>
<span>
This is a traditional history style, used in vast majority of apps.
It overwrites all succeding paths when you insert a new path anywhere other than the end,
which means once you go back in history and open some other directory, all succedding entries will be gone.
<br><b>Example:</b>
<br>- Open directory <span class="inline-code--light py-0">"/user"</span>
<br>- Open directory <span class="inline-code--light py-0">"/user/pictures"</span>
<br>- Open directory <span class="inline-code--light py-0">"/user/pictures/screenshots"</span>
<br>If you now go back to directory
<span class="inline-code--light py-0">"/user/pictures"</span>
and then go back again to
<span class="inline-code--light py-0">"/user"</span>
and then open
<span class="inline-code--light py-0">"/user/videos"</span>,
you will NOT be able to go back in history to the previous directories by pressing
"go back" or "go forward" button, because
they were overwritten and the history now only has 2 directories:
<span class="inline-code--light py-0">"/user"</span>
and
<span class="inline-code--light py-0">"/user/videos"</span>.
</span>
</v-tooltip>
</v-radio-group>
</template>
</section-settings>
</v-tab-item>

<!-- tab::input -->
<v-tab-item transition="fade-in" reverse-transition="fade-in">
<section-settings
Expand Down Expand Up @@ -1446,6 +1528,7 @@ export default {
{ text: 'General' },
{ text: 'UI appearance' },
{ text: 'Tabs & workspaces' },
{ text: 'Navigation' },
{ text: 'Input' },
{ text: 'Search' },
{ text: 'Data & storage' },
Expand Down Expand Up @@ -1477,6 +1560,7 @@ export default {
themeType: 'storageData.settings.theme.type',
navigatorLayout: 'storageData.settings.navigatorLayout',
closeAppWindowWhenLastWorkspaceTabIsClosed: 'storageData.settings.navigator.tabs.closeAppWindowWhenLastWorkspaceTabIsClosed',
navigatorHistoryStyleSelected: 'storageData.settings.navigator.historyStyle.selected',
navigatorShowHiddenDirItems: 'storageData.settings.navigator.showHiddenDirItems',
navigatorOpenDirItemWithSingleClick: 'storageData.settings.navigator.openDirItemWithSingleClick',
dirItemHoverEffect: 'storageData.settings.dirItemHoverEffect',
Expand Down

0 comments on commit 1e886e1

Please sign in to comment.