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