Skip to content

Commit

Permalink
offer three titlebar for selection
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottzheng committed May 2, 2019
1 parent 65a9101 commit a8c83fb
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 87 deletions.
3 changes: 2 additions & 1 deletion dist_locales/en.json
Expand Up @@ -43,5 +43,6 @@
"ok": "OK",
"restoreDefault": "Restore default settings",
"enableNotify": "Enable Notify",
"smartTranslate": "Smart Translate"
"smartTranslate": "Smart Translate",
"titleBar": "titleBar"
}
3 changes: 2 additions & 1 deletion dist_locales/zh-cn.json
Expand Up @@ -43,5 +43,6 @@
"ok": "确定",
"restoreDefault": "恢复默认设置",
"enableNotify": "启用通知",
"smartTranslate": "智能互译"
"smartTranslate": "智能互译",
"titleBar": "标题栏"
}
3 changes: 2 additions & 1 deletion dist_locales/zh-tw.json
Expand Up @@ -44,5 +44,6 @@
"resetDefault": "恢復預設設定",
"restoreDefault": "恢復預設設定",
"enableNotify": "啟用通知",
"smartTranslate": "Smart Translate"
"smartTranslate": "Smart Translate",
"titleBar": "titleBar"
}
56 changes: 11 additions & 45 deletions src/components/StatusBar.vue
@@ -1,61 +1,27 @@
<template>
<div
class="statusBar"
:style="styleNow"
v-on:dblclick="minify"
v-on:contextmenu="switchListen"
v-on:mousedown="startDrag"
></div>
<div>
<StatusBarV3 v-if="type === 2"></StatusBarV3>
<StatusBarV2 v-else-if="type === 1"></StatusBarV2>
<StatusBarV1 v-else-if="type === 0"></StatusBarV1>
</div>
</template>

<script>
import WindowController from "./WindowController";
import { MessageType, WinOpt } from "../tools/enums";
import { ipcRenderer as ipc } from "electron";
import { WindowWrapper } from "../tools/windows";
import StatusBarV3 from "./StatusBarV3";
import { RuleName } from "../tools/rule";
import StatusBarV2 from "./StatusBarV2";
import StatusBarV1 from "./StatusBarV1";
export default {
mixins: [WindowController],
components: { StatusBarV3, StatusBarV2, StatusBarV1 },
data: function() {
return {
colorNow: "white"
type: this.$controller.get(RuleName.titleBar)
};
},
computed: {
styleNow() {
return `background: ${this.colorNow}; `;
}
},
methods: {
switchColor(color) {
this.colorNow = color;
},
switchListen() {
this.$controller.action.callback("listenClipboard");
}
},
mounted: function() {
ipc.on(MessageType.WindowOpt.toString(), (event, arg) => {
switch (arg.type) {
case WinOpt.ChangeColor:
this.switchColor(arg.args);
break;
case WinOpt.EndDrag:
this.endDrag();
break;
}
});
this.$controller.setCurrentColor();
}
};
</script>

<style scoped>
.statusBar {
width: 100%;
height: 15px;
}
.dragButton {
-webkit-app-region: drag;
}
</style>
50 changes: 50 additions & 0 deletions src/components/StatusBarV1.vue
@@ -0,0 +1,50 @@
<template>
<div
class="statusBar"
:style="styleNow"
v-on:dblclick="minify"
v-on:mousedown="bindDrag"
v-on:contextmenu="switchListen"
></div>
</template>

<script>
import WindowController from "./WindowController";
import { MessageType, WinOpt } from "../tools/enums";
import { ipcRenderer as ipc } from "electron";
export default {
name: "StatusBarV1",
mixins: [WindowController],
data: function() {
return {
colorNow: "white"
};
},
computed: {
styleNow() {
return `height: 15px;background: ${this.colorNow};`;
}
},
methods: {
switchColor(color) {
this.colorNow = color;
},
switchListen() {
this.$controller.action.callback("listenClipboard");
}
},
mounted: function() {
ipc.on(MessageType.WindowOpt.toString(), (event, arg) => {
switch (arg.type) {
case WinOpt.ChangeColor:
this.switchColor(arg.args);
break;
}
});
this.$controller.setCurrentColor();
}
};
</script>

<style scoped></style>
61 changes: 61 additions & 0 deletions src/components/StatusBarV2.vue
@@ -0,0 +1,61 @@
<template>
<div
class="statusBar"
:style="styleNow"
v-on:dblclick="minify"
v-on:contextmenu="switchListen"
>
<i class="el-icon-rank dragButton"></i>
<i class="el-icon-rank dragButton" style="float:left;"></i>
<i class="el-icon-rank dragButton" style="float:right;"></i>
</div>
</template>

<script>
import WindowController from "./WindowController";
import { MessageType, WinOpt } from "../tools/enums";
import { ipcRenderer as ipc } from "electron";
export default {
name: "StatusBarV2",
mixins: [WindowController],
data: function() {
return {
colorNow: "white"
};
},
computed: {
styleNow() {
return `background: ${this.colorNow}; `;
}
},
methods: {
switchColor(color) {
this.colorNow = color;
},
switchListen() {
this.$controller.action.callback("listenClipboard");
}
},
mounted: function() {
ipc.on(MessageType.WindowOpt.toString(), (event, arg) => {
switch (arg.type) {
case WinOpt.ChangeColor:
this.switchColor(arg.args);
break;
}
});
this.$controller.setCurrentColor();
}
};
</script>

<style scoped>
.statusBar {
width: 100%;
height: 20px;
}
.dragButton {
-webkit-app-region: drag;
}
</style>
62 changes: 62 additions & 0 deletions src/components/StatusBarV3.vue
@@ -0,0 +1,62 @@
<template>
<div
class="statusBar"
:style="styleNow"
v-on:dblclick="minify"
v-on:contextmenu="switchListen"
v-on:mousedown="startDrag"
></div>
</template>

<script>
import WindowController from "./WindowController";
import { MessageType, WinOpt } from "../tools/enums";
import { ipcRenderer as ipc } from "electron";
import { WindowWrapper } from "../tools/windows";
export default {
name: "StatusBarV3",
mixins: [WindowController],
data: function() {
return {
colorNow: "white"
};
},
computed: {
styleNow() {
return `background: ${this.colorNow}; `;
}
},
methods: {
switchColor(color) {
this.colorNow = color;
},
switchListen() {
this.$controller.action.callback("listenClipboard");
}
},
mounted: function() {
ipc.on(MessageType.WindowOpt.toString(), (event, arg) => {
switch (arg.type) {
case WinOpt.ChangeColor:
this.switchColor(arg.args);
break;
case WinOpt.EndDrag:
this.endDrag();
break;
}
});
this.$controller.setCurrentColor();
}
};
</script>

<style scoped>
.statusBar {
width: 100%;
height: 15px;
}
.dragButton {
-webkit-app-region: drag;
}
</style>
9 changes: 9 additions & 0 deletions src/components/WindowController.vue
Expand Up @@ -30,6 +30,15 @@ export default {
minify(event) {
this.windowOpt(WinOpt.Minify);
},
bindDrag(event) {
if (event.button === 0) {
this.windowOpt(WinOpt.Drag, {
status: true,
x: event.screenX,
y: event.screenY
});
}
},
startDrag(event) {
if (event.button === 0) {
requestAnimationFrame(this.dragging);
Expand Down
5 changes: 4 additions & 1 deletion src/core/controller.ts
Expand Up @@ -16,6 +16,7 @@ import { handleActions } from "./actionCallback";
import { checkNotice } from "../tools/checker";
import { checkForUpdates } from "../tools/update";
import { log } from "../tools/logger";
import { ExecException } from "child_process";

const clipboard = require("electron-clipboard-extended");

Expand Down Expand Up @@ -335,6 +336,9 @@ class Controller {
case RuleName.listenClipboard:
this.setWatch(value);
break;
case RuleName.titleBar:
value = parseInt(value);
break;
case RuleName.stayTop:
if (this.win.window) {
this.win.window.focus();
Expand Down Expand Up @@ -418,7 +422,6 @@ class Controller {

setByKeyValue(ruleKey: string, value: any, save = true, refresh = true) {
let ruleValue = reverseRuleName[ruleKey];

this.setByRuleName(ruleValue, value, save, refresh);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/action.ts
Expand Up @@ -9,7 +9,7 @@ import { RuleName } from "./rule";
import { ConfigParser, getEnumValue as r } from "./configParser";
//r can be used to transform a enum to string
import { envConfig } from "./envConfig";
import { HideDirection } from "./enums";
import { HideDirection, TitlebarType } from "./enums";
import { TranslatorType } from "./translation/translators";
import { defaultShortcuts } from "./shortcuts";
import { Controller } from "../core/controller";
Expand Down Expand Up @@ -212,6 +212,7 @@ class ActionManager {

items.push(enumAction(RuleName.hideDirect, HideDirection));
items.push(enumAction(RuleName.translatorType, TranslatorType));
items.push(enumAction(RuleName.titleBar, TitlebarType));
items.push(normalAction("copySource"));
items.push(normalAction("copyResult"));
items.push(normalAction("clear"));
Expand Down Expand Up @@ -267,7 +268,6 @@ class ActionManager {
languageGenerator(RuleName.targetLanguage)
)
);

const localeGenerator = () => {
const id = r(RuleName.localeSetting);
return (<Controller>(<any>global).controller).locales
Expand Down
8 changes: 7 additions & 1 deletion src/tools/configuration.ts
@@ -1,6 +1,6 @@
import { ConfigParser } from "./configParser";
import { BoolRule, EnumRule, GroupRule, ModeRule, RuleName } from "./rule";
import { FrameMode, HideDirection } from "./enums";
import { FrameMode, HideDirection, TitlebarType } from "./enums";
import { TranslatorType } from "./translation/translators";
import { RouteName } from "./action";

Expand Down Expand Up @@ -79,6 +79,11 @@ function initConfig(
new EnumRule(HideDirection.Up, "HideDirection", HideDirection)
);

config.addRule(
RuleName.titleBar,
new EnumRule(TitlebarType.Enhance, "titlebar Type", TitlebarType)
);

config.addRule(
RuleName.focus,
new ModeRule(
Expand Down Expand Up @@ -191,6 +196,7 @@ function initConfig(
[
"translatorType",
"hideDirect",
"titleBar",
"copySource",
"copyResult",
"clear",
Expand Down

0 comments on commit a8c83fb

Please sign in to comment.