「テーマのトグル」の版間の差分
ナビゲーションに移動
検索に移動
編集の要約なし |
|||
| (同じ利用者による、間の3版が非表示) | |||
| 3行目: | 3行目: | ||
== 動作環境 == | == 動作環境 == | ||
Mery Ver 3.7 | * Mery Ver 3.8.0 以降 | ||
* Windows 7 以降 | |||
== 使用方法 == | == 使用方法 == | ||
あらかじめ [オプション] ダイアログの [表示] カテゴリの [テーマ] | あらかじめ [オプション] ダイアログの [表示] カテゴリの [テーマ] で切り替え用1・切り替え用2・切り替え用3というテーマ名で切り替えたいテーマを「名前を付けて保存」または「インポート」してからマクロを実行してください。 | ||
切り替えるテーマの数や使用するテーマを変更したい場合は switch 文を編集してください。下記は FavoriteTheme1 と FavoriteTheme2 の二つのテーマを切り替える例です。 | |||
<syntaxhighlight lang="javascript" copy> | <syntaxhighlight lang="javascript" copy> | ||
| 25行目: | 26行目: | ||
== 変更履歴 == | == 変更履歴 == | ||
* 2026-03-27 | |||
** テーマ切り替え中にステータスバーにメッセージを表示しないようにした | |||
* 2026-01-11 | |||
** QuickJS で実行するようにした | |||
* 2025-12-26 | |||
** パフォーマンスの改善 | |||
* 2025-12-19 | |||
** テーマ切り替え中にステータスバーとツールチップにメッセージを表示するようにした | |||
* 2025-12-12 | * 2025-12-12 | ||
** テーマの項目を INI ファイルから取得するようにした(pizz さんが作成された「[[テーマの自動変更]]」マクロのアイデアを参考にさせていただきました) | ** テーマの項目を INI ファイルから取得するようにした(pizz さんが作成された「[[テーマの自動変更]]」マクロのアイデアを参考にさせていただきました) | ||
| 42行目: | 51行目: | ||
<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) { | ||
| 58行目: | 68行目: | ||
} | } | ||
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) { | ||
ShowTip("テーマ切り替え中...しばらくお待ちください", meShowTipPosMouse); | |||
editor.WriteSettings(); | editor.WriteSettings(); | ||
editor.WriteSettingString("Themes", "ThemeName", newTheme); | editor.WriteSettingString("Themes", "ThemeName", newTheme); | ||
for (const [ident, value] of items) { | |||
editor.WriteSettingString("Display", ident, value); | |||
editor.WriteSettingString("Display", | |||
} | } | ||
editor.ReadSettings(); | editor.ReadSettings(); | ||
ShowTip("", meShowTipHide); | ShowTip("", meShowTipHide); | ||
} else { | } else { | ||
Alert(newTheme | Alert(`${newTheme} という名前でテーマを保存してください`); | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
2026年3月27日 (金) 20:59時点における最新版
概要[編集]
テーマをキーボードショートカットなどでトグルできるようになるマクロです。フォーラムで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-03-27
- テーマ切り替え中にステータスバーにメッセージを表示しないようにした
- 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) {
ShowTip("テーマ切り替え中...しばらくお待ちください", meShowTipPosMouse);
editor.WriteSettings();
editor.WriteSettingString("Themes", "ThemeName", newTheme);
for (const [ident, value] of items) {
editor.WriteSettingString("Display", ident, value);
}
editor.ReadSettings();
ShowTip("", meShowTipHide);
} else {
Alert(`${newTheme} という名前でテーマを保存してください`);
}
スポンサーリンク