「テーマのトグル」の版間の差分
ナビゲーションに移動
検索に移動
編集の要約なし |
編集の要約なし |
||
| 3行目: | 3行目: | ||
== 動作環境 == | == 動作環境 == | ||
Mery Ver 3.7 | * Mery Ver 3.8.0 以降 | ||
* Windows 7 以降 | |||
== 使用方法 == | == 使用方法 == | ||
| 25行目: | 26行目: | ||
== 変更履歴 == | == 変更履歴 == | ||
* 2026-01-11 | |||
** QuickJS で実行するようにした | |||
* 2025-12-26 | * 2025-12-26 | ||
** パフォーマンスの改善 | ** パフォーマンスの改善 | ||
| 46行目: | 49行目: | ||
<syntaxhighlight lang="javascript" copy> | <syntaxhighlight lang="javascript" copy> | ||
#fonticon = "\uE790", #4d82b8, #dddddd | #fonticon = "\uE790", #4d82b8, #dddddd | ||
#language = "quickjs" | |||
#title = "テーマのトグル" | #title = "テーマのトグル" | ||
const currentTheme = editor.ReadSettingString("Themes", "ThemeName", ""); | |||
let newTheme; | |||
switch (currentTheme) { | switch (currentTheme) { | ||
| 62行目: | 66行目: | ||
} | } | ||
const getItems = () => { | |||
let iniFullName = editor.FullName.replace(/\.exe$/i, ".ini"); | |||
if (!shell.FileExists(iniFullName)) { | if (!shell.FileExists(iniFullName)) { | ||
iniFullName = shell.GetEnv("APPDATA") + "\\Mery" + iniFullName.slice(iniFullName.lastIndexOf("\\")); | iniFullName = shell.GetEnv("APPDATA") + "\\Mery" + iniFullName.slice(iniFullName.lastIndexOf("\\")); | ||
} | } | ||
const iniText = shell.Exec(`cmd.exe /c type "${iniFullName}"`).stdOut; | |||
const iniLines = iniText.split("\r\n"); | |||
const sectionStart = iniLines.indexOf(`[Theme\\${newTheme}]`); | |||
if (sectionStart === -1) { | if (sectionStart === -1) { | ||
return; | return; | ||
} | } | ||
const sectionEnd = iniLines.indexOf("", sectionStart); | |||
return iniLines.slice(sectionStart + 1, sectionEnd).map(item => item.split("=")); | |||
}; | }; | ||
const items = getItems(); | |||
if (items) { | if (items) { | ||
const statusText = Status; | |||
editor.ExecuteMacro( | editor.ExecuteMacro( | ||
"Status = 'テーマ切り替え中...しばらくお待ちください';" + | "Status = 'テーマ切り替え中...しばらくお待ちください';" + | ||
| 92行目: | 93行目: | ||
editor.WriteSettingString("Themes", "ThemeName", newTheme); | editor.WriteSettingString("Themes", "ThemeName", newTheme); | ||
for ( | for (const [ident, value] of items) { | ||
editor.WriteSettingString("Display", | editor.WriteSettingString("Display", ident, value); | ||
} | } | ||
| 100行目: | 101行目: | ||
ShowTip("", meShowTipHide); | ShowTip("", meShowTipHide); | ||
} else { | } else { | ||
Alert(newTheme | Alert(`${newTheme} という名前でテーマを保存してください`); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
2026年1月11日 (日) 13:20時点における版
概要
テーマをキーボードショートカットなどでトグルできるようになるマクロです。フォーラムでucky様が作成されたものですが、フォーラムだけだと埋没してしまい検索に苦労したので、こちらにも記載させていただきました。
動作環境
- Mery Ver 3.8.0 以降
- Windows 7 以降
使用方法
あらかじめ [オプション] ダイアログの [表示] カテゴリの [テーマ] で切り替え用1・切り替え用2・切り替え用3というテーマ名で切り替えたいテーマを「名前を付けて保存」してからマクロを実行してください。
切り替えるテーマの数や保存する名前を変更したい場合は switch 文を編集してください。下記は FavoriteTheme1 と FavoriteTheme2 の二つのテーマを切り替える例です。
switch (currentTheme) {
case "FavoriteTheme1":
newTheme = "FavoriteTheme2";
break;
default:
newTheme = "FavoriteTheme1";
}
最初から入っているテーマを使用したい場合でも「名前を付けて保存」で別途保存してください。
テーマの仕様変更で追加された項目を反映させたい場合はテーマを保存しなおす必要があります。
変更履歴
- 2026-01-11
- QuickJS で実行するようにした
- 2025-12-26
- パフォーマンスの改善
- 2025-12-19
- テーマ切り替え中にステータスバーとツールチップにメッセージを表示するようにした
- 2025-12-12
- テーマの項目を INI ファイルから取得するようにした(pizz さんが作成された「テーマの自動変更」マクロのアイデアを参考にさせていただきました)
- ディレクティブ(
#fonticonと#title)を追加
- 2025-05-03
- Mery 3.7.13 時点の仕様に合わせて項目を追加
- 2024-12-29
- Mery 3.7.9 時点の仕様に合わせて項目を追加
- 2024-04-09
- メニュー等から変更した INI ファイルに書き込まれる前の設定が破棄されるのを修正
- 2024-03-03
- Mery 3.7.0 時点の仕様に合わせて項目を追加
- 2021-06-26
- 新規作成
ソースコード
#fonticon = "\uE790", #4d82b8, #dddddd
#language = "quickjs"
#title = "テーマのトグル"
const currentTheme = editor.ReadSettingString("Themes", "ThemeName", "");
let newTheme;
switch (currentTheme) {
case "切り替え用1":
newTheme = "切り替え用2";
break;
case "切り替え用2":
newTheme = "切り替え用3";
break;
default:
newTheme = "切り替え用1";
}
const getItems = () => {
let iniFullName = editor.FullName.replace(/\.exe$/i, ".ini");
if (!shell.FileExists(iniFullName)) {
iniFullName = shell.GetEnv("APPDATA") + "\\Mery" + iniFullName.slice(iniFullName.lastIndexOf("\\"));
}
const iniText = shell.Exec(`cmd.exe /c type "${iniFullName}"`).stdOut;
const iniLines = iniText.split("\r\n");
const sectionStart = iniLines.indexOf(`[Theme\\${newTheme}]`);
if (sectionStart === -1) {
return;
}
const sectionEnd = iniLines.indexOf("", sectionStart);
return iniLines.slice(sectionStart + 1, sectionEnd).map(item => item.split("="));
};
const items = getItems();
if (items) {
const statusText = Status;
editor.ExecuteMacro(
"Status = 'テーマ切り替え中...しばらくお待ちください';" +
"ShowTip('テーマ切り替え中...しばらくお待ちください', meShowTipPosMouse);",
meRunText | meMacroAsync
);
editor.WriteSettings();
editor.WriteSettingString("Themes", "ThemeName", newTheme);
for (const [ident, value] of items) {
editor.WriteSettingString("Display", ident, value);
}
editor.ReadSettings();
Status = statusText;
ShowTip("", meShowTipHide);
} else {
Alert(`${newTheme} という名前でテーマを保存してください`);
}
スポンサーリンク