From 512946a397da63434ce84e0573a3d5291199d5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20Kr=C3=B6ger?= Date: Wed, 9 Jun 2021 15:23:48 +0200 Subject: [PATCH] Allow to close tabs using middle-clicks (#2995) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luca Kröger --- src/renderer/components/dock/dock-tab.tsx | 6 ++-- src/renderer/utils/index.ts | 1 + src/renderer/utils/isMiddleClick.ts | 36 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/renderer/utils/isMiddleClick.ts diff --git a/src/renderer/components/dock/dock-tab.tsx b/src/renderer/components/dock/dock-tab.tsx index 4160073882..bf3fea3016 100644 --- a/src/renderer/components/dock/dock-tab.tsx +++ b/src/renderer/components/dock/dock-tab.tsx @@ -23,7 +23,7 @@ import "./dock-tab.scss"; import React from "react"; import { observer } from "mobx-react"; -import { boundMethod, cssNames, prevDefault } from "../../utils"; +import { boundMethod, cssNames, prevDefault, isMiddleClick } from "../../utils"; import { dockStore, IDockTab } from "./dock.store"; import { Tab, TabProps } from "../tabs"; import { Icon } from "../icon"; @@ -88,13 +88,13 @@ export class DockTab extends React.Component { const { className, moreActions, ...tabProps } = this.props; const { title, pinned } = tabProps.value; const label = ( -
+
{title} {moreActions} {!pinned && ( )} diff --git a/src/renderer/utils/index.ts b/src/renderer/utils/index.ts index 3933ff94b6..a0b20d1e2d 100755 --- a/src/renderer/utils/index.ts +++ b/src/renderer/utils/index.ts @@ -38,3 +38,4 @@ export * from "./convertMemory"; export * from "./convertCpu"; export * from "./metricUnitsToNumber"; export * from "./display-booleans"; +export * from "./isMiddleClick"; diff --git a/src/renderer/utils/isMiddleClick.ts b/src/renderer/utils/isMiddleClick.ts new file mode 100644 index 0000000000..1fcb3ccff8 --- /dev/null +++ b/src/renderer/utils/isMiddleClick.ts @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import type React from "react"; + +// Helper for inlining middleClick checks +//
console.log('do some action'))}> +// +// +//
+ +export function isMiddleClick(callback: (evt: E) => any) { + return function (evt: E) { + if(evt.button === 1) { + return callback(evt); + } + }; +}