2018-05-09 12:01:36 +05:30
|
|
|
<script>
|
2021-04-17 20:07:23 +05:30
|
|
|
import { GlIcon, GlTab } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { __, sprintf } from '~/locale';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import FileIcon from '~/vue_shared/components/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,
|
2021-04-17 20:07:23 +05:30
|
|
|
GlTab,
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
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) {
|
2021-01-29 00:20:46 +05:30
|
|
|
return sprintf(__('%{tabname} changed'), { tabname: this.tab.name });
|
2018-05-09 12:01:36 +05:30
|
|
|
}
|
2021-01-29 00:20:46 +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>
|
2021-04-17 20:07:23 +05:30
|
|
|
<gl-tab
|
|
|
|
:active="tab.active"
|
|
|
|
:disabled="tab.pending"
|
|
|
|
:title="tab.name"
|
2019-03-02 22:35:43 +05:30
|
|
|
@click="clickFile(tab)"
|
2018-05-09 12:01:36 +05:30
|
|
|
@mouseover="mouseOverTab"
|
|
|
|
@mouseout="mouseOutTab"
|
|
|
|
>
|
2021-04-17 20:07:23 +05:30
|
|
|
<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-05-09 12:01:36 +05:30
|
|
|
</template>
|