2018-03-20 10:12:48 -04:00
|
|
|
<script>
|
2021-02-18 13:10:41 -05:00
|
|
|
import { GlIcon, GlTab } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
2019-12-06 19:07:51 -05:00
|
|
|
import { __, sprintf } from '~/locale';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-10-03 05:05:43 -04:00
|
|
|
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import FileIcon from '~/vue_shared/components/file_icon.vue';
|
2018-04-03 06:10:01 -04:00
|
|
|
import FileStatusIcon from './repo_file_status_icon.vue';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-03-29 09:52:40 -04:00
|
|
|
export default {
|
|
|
|
components: {
|
2018-04-03 06:10:01 -04:00
|
|
|
FileStatusIcon,
|
|
|
|
FileIcon,
|
2020-08-24 11:10:11 -04:00
|
|
|
GlIcon,
|
2018-04-03 06:10:01 -04:00
|
|
|
ChangedFileIcon,
|
2021-02-18 13:10:41 -05:00
|
|
|
GlTab,
|
2018-03-29 09:52:40 -04:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
tab: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2018-03-29 09:52:40 -04:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tabMouseOver: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2020-09-14 08:09:34 -04:00
|
|
|
...mapGetters(['getUrlForPath']),
|
2018-03-29 09:52:40 -04:00
|
|
|
closeLabel() {
|
|
|
|
if (this.fileHasChanged) {
|
2020-10-21 05:08:50 -04:00
|
|
|
return sprintf(__('%{tabname} changed'), { tabname: this.tab.name });
|
2018-03-29 09:52:40 -04:00
|
|
|
}
|
2020-10-21 05:08:50 -04:00
|
|
|
return sprintf(__('Close %{tabname}'), { tabname: this.tab.name });
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2018-03-29 09:52:40 -04:00
|
|
|
showChangedIcon() {
|
2018-05-02 06:47:36 -04:00
|
|
|
if (this.tab.pending) return true;
|
|
|
|
|
2018-04-09 11:05:21 -04:00
|
|
|
return this.fileHasChanged ? !this.tabMouseOver : false;
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2018-03-29 09:52:40 -04:00
|
|
|
fileHasChanged() {
|
2018-07-26 10:56:56 -04:00
|
|
|
return this.tab.changed || this.tab.tempFile || this.tab.staged || this.tab.deleted;
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2018-03-29 09:52:40 -04:00
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2018-03-29 09:52:40 -04:00
|
|
|
methods: {
|
2018-03-23 07:37:34 -04:00
|
|
|
...mapActions(['closeFile', 'updateDelayViewerUpdated', 'openPendingTab']),
|
2018-03-29 09:52:40 -04:00
|
|
|
clickFile(tab) {
|
2018-06-25 06:58:24 -04:00
|
|
|
if (tab.active) return;
|
|
|
|
|
2018-03-23 07:37:34 -04:00
|
|
|
this.updateDelayViewerUpdated(true);
|
|
|
|
|
|
|
|
if (tab.pending) {
|
2018-04-05 05:46:19 -04:00
|
|
|
this.openPendingTab({ file: tab, keyPrefix: tab.staged ? 'staged' : 'unstaged' });
|
2018-03-23 07:37:34 -04:00
|
|
|
} else {
|
2020-09-14 08:09:34 -04:00
|
|
|
this.$router.push(this.getUrlForPath(tab.path));
|
2018-03-23 07:37:34 -04:00
|
|
|
}
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2018-03-29 09:52:40 -04:00
|
|
|
mouseOverTab() {
|
|
|
|
if (this.fileHasChanged) {
|
|
|
|
this.tabMouseOver = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mouseOutTab() {
|
|
|
|
if (this.fileHasChanged) {
|
|
|
|
this.tabMouseOver = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2018-03-20 10:12:48 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2021-02-18 13:10:41 -05:00
|
|
|
<gl-tab
|
|
|
|
:active="tab.active"
|
|
|
|
:disabled="tab.pending"
|
|
|
|
:title="tab.name"
|
2019-01-10 16:56:37 -05:00
|
|
|
@click="clickFile(tab)"
|
2018-03-20 10:12:48 -04:00
|
|
|
@mouseover="mouseOverTab"
|
|
|
|
@mouseout="mouseOutTab"
|
|
|
|
>
|
2021-02-18 13:10:41 -05:00
|
|
|
<template #title>
|
|
|
|
<div :title="getUrlForPath(tab.path)" class="multi-file-tab">
|
|
|
|
<file-icon :file-name="tab.name" :size="16" />
|
|
|
|
{{ tab.name }}
|
|
|
|
<file-status-icon :file="tab" />
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
:aria-label="closeLabel"
|
|
|
|
:disabled="tab.pending"
|
|
|
|
type="button"
|
|
|
|
class="multi-file-tab-close"
|
|
|
|
@click.stop.prevent="closeFile(tab)"
|
|
|
|
>
|
|
|
|
<gl-icon v-if="!showChangedIcon" :size="12" name="close" />
|
|
|
|
<changed-file-icon v-else :file="tab" />
|
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
</gl-tab>
|
2018-03-20 10:12:48 -04:00
|
|
|
</template>
|