Skip to content

Commit

Permalink
Add option to enable/disable automatic copy to clipboard
Browse files Browse the repository at this point in the history
closes #145
  • Loading branch information
sedwards2009 committed Dec 31, 2018
1 parent 6102503 commit f002365
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions extraterm/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface GeneralConfig {
windowConfiguration?: WindowConfiguration;

frameByDefault?: boolean;
autoCopySelectionToClipboard?: boolean;
}

// This is the format of the user config JSON file as stored on the filesystem.
Expand Down
4 changes: 4 additions & 0 deletions extraterm/src/main_process/MainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ export function setupUserConfig(themeManager: ThemeManager, configDatabase: Conf
userStoredConfig.minimizeToTray = false;
}

if (userStoredConfig.autoCopySelectionToClipboard == null) {
userStoredConfig.autoCopySelectionToClipboard = true;
}

if (userStoredConfig.frameByDefault !== true && userStoredConfig.frameByDefault !== false) {
userStoredConfig.frameByDefault = true;
}
Expand Down
13 changes: 11 additions & 2 deletions extraterm/src/render_process/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { COMMAND_OPEN_COMMAND_PALETTE, COMMAND_OPEN_CONTEXT_MENU } from './comma
import {Logger, getLogger} from "extraterm-logging";
import { log as LogDecorator} from "extraterm-logging";
import * as DomUtils from './DomUtils';
import {doLater} from '../utils/DoLater';
import {doLater, DebouncedDoLater} from '../utils/DoLater';
import * as Term from './emulator/Term';
import * as TermApi from 'term-api';
import {ScrollBar} from './gui/ScrollBar';
Expand Down Expand Up @@ -211,9 +211,14 @@ export class EtTerminal extends ThemeableElementBase implements Commandable, Acc
private _inputStreamFilters: InputStreamFilter[] = [];
private _dialogStack: HTMLElement[] = [];

private _copyToClipboardLater: DebouncedDoLater = null;


constructor() {
super();
this._log = getLogger(EtTerminal.TAG_NAME, this);
this._copyToClipboardLater = new DebouncedDoLater(() => this.copyToClipboard(), 100);

this._childFocusHandlerFunc = this._handleChildFocus.bind(this);
this._fetchNextTag();
}
Expand Down Expand Up @@ -342,6 +347,7 @@ export class EtTerminal extends ThemeableElementBase implements Commandable, Acc
}

dispose(): void {
this._copyToClipboardLater.cancel();
this._disposeChildren();
}

Expand Down Expand Up @@ -775,7 +781,10 @@ export class EtTerminal extends ThemeableElementBase implements Commandable, Acc
});

if (ev.detail.originMouse) {
doLater( () => { this.copyToClipboard() } ); // FIXME This should be debounced slightly.
const generalConfig = this._configDatabase.getConfig("general");
if (generalConfig.autoCopySelectionToClipboard) {
this._copyToClipboardLater.trigger();
}
}
}

Expand Down
18 changes: 15 additions & 3 deletions extraterm/src/render_process/ViewerTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {WebComponent} from 'extraterm-web-component-decorators';

import { COMMAND_OPEN_COMMAND_PALETTE } from './command/CommandUtils';
import { isCommandable, Commandable, BoundCommand} from './command/CommandTypes';
import {doLater} from '../utils/DoLater';
import {doLater, DebouncedDoLater} from '../utils/DoLater';
import * as DomUtils from './DomUtils';
import {EmbeddedViewer} from './viewers/EmbeddedViewer';
import {Logger, getLogger} from "extraterm-logging";
Expand All @@ -26,6 +26,7 @@ import {ViewerElement} from "./viewers/ViewerElement";
import * as ViewerElementTypes from './viewers/ViewerElementTypes';
import * as VirtualScrollArea from './VirtualScrollArea';
import * as WebIpc from './WebIpc';
import { AcceptsConfigDatabase, ConfigDatabase } from '../Config';


type VirtualScrollable = VirtualScrollArea.VirtualScrollable;
Expand Down Expand Up @@ -58,7 +59,7 @@ const SCROLL_STEP = 1;
* A viewer tab which can contain any ViewerElement.
*/
@WebComponent({tag: "et-viewer-tab"})
export class EtViewerTab extends ViewerElement implements Commandable,
export class EtViewerTab extends ViewerElement implements Commandable, AcceptsConfigDatabase,
AcceptsKeybindingsManager, SupportsClipboardPaste.SupportsClipboardPaste,
SupportsDialogStack.SupportsDialogStack {

Expand All @@ -71,16 +72,19 @@ export class EtViewerTab extends ViewerElement implements Commandable,
private _tag: string = null;

private _keyBindingManager: KeybindingsManager = null;
private _configDatabase: ConfigDatabase = null;
private _resizePollHandle: Disposable = null;
private _elementAttached = false;
private _needsCompleteRefresh = true;
private _fontSizeAdjustment = 0;
private _armResizeCanary = false; // Controls when the resize canary is allowed to chirp.
private _dialogStack: HTMLElement[] = [];
private _copyToClipboardLater: DebouncedDoLater = null;

constructor() {
super();
this._log = getLogger(EtViewerTab.TAG_NAME, this);
this._copyToClipboardLater = new DebouncedDoLater(() => this.copyToClipboard(), 100);
}

getMetadata(): ViewerMetadata {
Expand Down Expand Up @@ -172,6 +176,7 @@ export class EtViewerTab extends ViewerElement implements Commandable,
}

dispose(): void {
this._copyToClipboardLater.cancel();
const element = this.getViewerElement();
if (element !== null) {
element.dispose();
Expand All @@ -182,6 +187,10 @@ export class EtViewerTab extends ViewerElement implements Commandable,
}
}

setConfigDatabase(newConfigDatabase: ConfigDatabase): void {
this._configDatabase = newConfigDatabase;
}

// FIXME delete
setTitle(newTitle: string): void {
this._title = newTitle;
Expand Down Expand Up @@ -546,7 +555,10 @@ export class EtViewerTab extends ViewerElement implements Commandable,

private _handleBeforeSelectionChange(ev: CustomEvent): void {
if (ev.detail.originMouse) {
doLater( () => { this.copyToClipboard() } );
const generalConfig = this._configDatabase.getConfig("general");
if (generalConfig.autoCopySelectionToClipboard) {
this._copyToClipboardLater.trigger();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions extraterm/src/render_process/settings/GeneralSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class GeneralSettings extends SettingsBase<GeneralSettingsUi> {
if (ui.maxScrollbackFrames !== generalConfig.scrollbackMaxFrames) {
ui.maxScrollbackFrames = generalConfig.scrollbackMaxFrames;
}
if (ui.autoCopySelectionToClipboard !== generalConfig.autoCopySelectionToClipboard) {
ui.autoCopySelectionToClipboard = generalConfig.autoCopySelectionToClipboard;
}
}
}

Expand All @@ -48,6 +51,7 @@ export class GeneralSettings extends SettingsBase<GeneralSettingsUi> {
newGeneralConfig.showTips = ui.showTips;
newGeneralConfig.scrollbackMaxLines = ui.maxScrollbackLines;
newGeneralConfig.scrollbackMaxFrames = ui.maxScrollbackFrames;
newGeneralConfig.autoCopySelectionToClipboard = ui.autoCopySelectionToClipboard;

this._updateConfig(GENERAL_CONFIG, newGeneralConfig);
}
Expand Down
6 changes: 6 additions & 0 deletions extraterm/src/render_process/settings/GeneralSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const ID_SCROLLBACK_FRAMES = "ID_SCROLLBACK_FRAMES";
<label for="${ID_SCROLLBACK_FRAMES}">Max. Scrollback Frames:</label>
<span class="group"><input id="${ID_SCROLLBACK_FRAMES}" type="number" class="char-width-4"
v-model.number="maxScrollbackFrames" min="1" max="1000" debounce="500" /><span>frames</span></span>
<label></label>
<span><label><input type="checkbox" v-model="autoCopySelectionToClipboard">Automatically copy selection to clipboard</label></span>
</div>
</div>
`)
Expand All @@ -45,12 +49,14 @@ export class GeneralSettingsUi extends Vue {

maxScrollbackLines: number;
maxScrollbackFrames: number;
autoCopySelectionToClipboard: boolean;

constructor() {
super();
this.showTips = 'always';
this.showTipsOptions = [ { id: 'always', name: 'Everytime' }, { id: 'daily', name: 'Daily'}, { id: 'never', name: 'Never'} ];
this.maxScrollbackLines = 500000;
this.maxScrollbackFrames = 100;
this.autoCopySelectionToClipboard = true;
}
}

0 comments on commit f002365

Please sign in to comment.