Skip to content

Commit 5d3254e

Browse files
committed
added the option to add a ribbon icon
1 parent c0aaf17 commit 5d3254e

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ If you create a frame that you think other people would like, don't hesitate to
5050
## 🛣️ Roadmap
5151
- ~~Allow setting a custom icon for each pane~~
5252
- ~~Allow displaying custom frames in Markdown code blocks~~
53+
- ~~Add the ability to add a ribbon button for a frame that opens it in the main view~~
5354
- Allow creating links that open in a custom frame rather than the browser
5455
- Possibly allow executing custom JavaScript in iframes (though security implications still need to be explored)
5556
- Add a global setting that causes popups to be opened in a new Obsidian window rather than the default browser
5657
- Add more options to Markdown mode, like allowing for back and forward buttons
57-
- Add the ability to add a ribbon button for a frame that opens it in the main view
5858

5959
## ⚠️ Known Issues
6060
There are a few known issues with Custom Frames. If you encounter any of these, please **don't** report it on the issue tracker.

src/main.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Plugin, Platform } from "obsidian";
22
import { CustomFrame } from "./frame";
3-
import { CustomFramesSettings, defaultSettings } from "./settings";
3+
import { CustomFramesSettings, defaultSettings, getIcon } from "./settings";
44
import { CustomFramesSettingTab } from "./settings-tab";
55
import { CustomFrameView } from "./view";
66

@@ -28,6 +28,9 @@ export default class CustomFramesPlugin extends Plugin {
2828
name: `Open ${frame.displayName}`,
2929
callback: () => this.openLeaf(name),
3030
});
31+
32+
if (frame.addRibbonIcon)
33+
this.addRibbonIcon(getIcon(frame), `Open ${frame.displayName}`, () => this.openLeaf(name));
3134
} catch {
3235
console.error(`Couldn't register frame ${name}, is there already one with the same name?`);
3336
}

src/settings-tab.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ export class CustomFramesSettingTab extends PluginSettingTab {
9191
await this.plugin.saveSettings();
9292
});
9393
});
94+
new Setting(content)
95+
.setName("Add Ribbon Icon")
96+
.setDesc("Whether a button to open this frame should be added to the ribbon.")
97+
.addToggle(t => {
98+
t.setValue(frame.addRibbonIcon);
99+
t.onChange(async v => {
100+
frame.addRibbonIcon = v;
101+
await this.plugin.saveSettings();
102+
});
103+
});
94104
new Setting(content)
95105
.setName("Page Zoom")
96106
.setDesc("The zoom that this frame's page should be displayed with, as a percentage.")
@@ -147,9 +157,10 @@ export class CustomFramesSettingTab extends PluginSettingTab {
147157
url: "",
148158
displayName: "New Frame",
149159
icon: "",
160+
hideOnMobile: true,
161+
addRibbonIcon: false,
150162
zoomLevel: 1,
151-
customCss: "",
152-
hideOnMobile: true
163+
customCss: ""
153164
});
154165
}
155166
else {

src/settings.ts

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const presets: Record<string, CustomFrameSettings> = {
88
displayName: "Obsidian Forum",
99
icon: "edit",
1010
hideOnMobile: true,
11+
addRibbonIcon: true,
1112
zoomLevel: 1,
1213
customCss: ""
1314
},
@@ -16,6 +17,7 @@ export const presets: Record<string, CustomFrameSettings> = {
1617
displayName: "Google Calendar",
1718
icon: "calendar",
1819
hideOnMobile: true,
20+
addRibbonIcon: true,
1921
zoomLevel: 1,
2022
customCss: `/* hide right-side menu, and some buttons */
2123
div.d6McF,
@@ -33,6 +35,7 @@ div.dwlvNd {
3335
displayName: "Google Keep",
3436
icon: "files",
3537
hideOnMobile: true,
38+
addRibbonIcon: false,
3639
zoomLevel: 1,
3740
customCss: `/* hide the menu bar and the "Keep" text */
3841
html > body > div:nth-child(2) > div:nth-child(2) > div:first-child,
@@ -45,6 +48,7 @@ html > body > div:first-child > header:first-child > div > div:first-child > div
4548
displayName: "Todoist",
4649
icon: "list-checks",
4750
hideOnMobile: true,
51+
addRibbonIcon: false,
4852
zoomLevel: 1,
4953
customCss: `/* hide the help, home, search, and productivity overview buttons, create extra space, and prevent toast pop-up from acting weird */
5054
[aria-label="Go to Home view"], #quick_find, [aria-label="Productivity"], [aria-label="Help & Feedback"] {
@@ -69,6 +73,7 @@ html > body > div:first-child > header:first-child > div > div:first-child > div
6973
displayName: "Notion",
7074
icon: "box",
7175
hideOnMobile: true,
76+
addRibbonIcon: true,
7277
zoomLevel: 1,
7378
customCss: ""
7479
},
@@ -77,6 +82,7 @@ html > body > div:first-child > header:first-child > div > div:first-child > div
7782
displayName: "Twitter",
7883
icon: "twitter",
7984
hideOnMobile: true,
85+
addRibbonIcon: false,
8086
zoomLevel: 1,
8187
customCss: ""
8288
}
@@ -92,6 +98,11 @@ export interface CustomFrameSettings {
9298
displayName: string;
9399
icon: string;
94100
hideOnMobile: boolean;
101+
addRibbonIcon: boolean;
95102
zoomLevel: number;
96103
customCss: string;
97104
}
105+
106+
export function getIcon(settings: CustomFrameSettings) {
107+
return settings.icon ? `lucide-${settings.icon}` : "documents";
108+
}

src/view.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ItemView, WorkspaceLeaf, Platform, Menu } from "obsidian";
1+
import { ItemView, WorkspaceLeaf, Menu } from "obsidian";
22
import { CustomFrame } from "./frame";
3-
import { CustomFrameSettings, CustomFramesSettings } from "./settings";
3+
import { CustomFrameSettings, CustomFramesSettings, getIcon } from "./settings";
44

55
export class CustomFrameView extends ItemView {
66

@@ -72,7 +72,7 @@ export class CustomFrameView extends ItemView {
7272
}
7373

7474
getIcon(): string {
75-
return this.data.icon ? `lucide-${this.data.icon}` : "documents";
75+
return getIcon(this.data);
7676
}
7777
}
7878

0 commit comments

Comments
 (0)