aboutsummaryrefslogtreecommitdiff
path: root/src/background/operators/impls/CommandOperatorFactoryChain.ts
blob: 680a38489f8436756c9da0cbe83b05bbc28ab1c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { inject, injectable } from "tsyringe";
import Operator from "../Operator";
import OperatorFactoryChain from "../OperatorFactoryChain";
import ShowCommandOperator from "./ShowCommandOperator";
import ShowOpenCommandOperator from "./ShowOpenCommandOperator";
import ShowTabOpenCommandOperator from "./ShowTabOpenCommandOperator";
import ShowWinOpenCommandOperator from "./ShowWinOpenCommandOperator";
import ShowBufferCommandOperator from "./ShowBufferCommandOperator";
import ShowAddBookmarkOperator from "./ShowAddBookmarkOperator";
import TabPresenter from "../../presenters/TabPresenter";
import ConsoleClient from "../../infrastructures/ConsoleClient";
import * as operations from "../../../shared/operations";
import StartFindOperator from "./StartFindOperator";

@injectable()
export default class CommandOperatorFactoryChain
  implements OperatorFactoryChain {
  constructor(
    @inject("TabPresenter")
    private readonly tabPresenter: TabPresenter,
    @inject("ConsoleClient")
    private readonly consoleClient: ConsoleClient
  ) {}

  create(op: operations.Operation): Operator | null {
    switch (op.type) {
      case operations.COMMAND_SHOW:
        return new ShowCommandOperator(this.tabPresenter, this.consoleClient);
      case operations.COMMAND_SHOW_OPEN:
        return new ShowOpenCommandOperator(
          this.tabPresenter,
          this.consoleClient,
          op.alter
        );
      case operations.COMMAND_SHOW_TABOPEN:
        return new ShowTabOpenCommandOperator(
          this.tabPresenter,
          this.consoleClient,
          op.alter
        );
      case operations.COMMAND_SHOW_WINOPEN:
        return new ShowWinOpenCommandOperator(
          this.tabPresenter,
          this.consoleClient,
          op.alter
        );
      case operations.COMMAND_SHOW_BUFFER:
        return new ShowBufferCommandOperator(
          this.tabPresenter,
          this.consoleClient
        );
      case operations.COMMAND_SHOW_ADDBOOKMARK:
        return new ShowAddBookmarkOperator(
          this.tabPresenter,
          this.consoleClient,
          op.alter
        );
      case operations.FIND_START:
        return new StartFindOperator(this.tabPresenter, this.consoleClient);
    }
    return null;
  }
}