Skip to content

Commit

Permalink
Allow move Projects main view to new window in tab header. (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
Acylation authored Sep 5, 2023
1 parent e424cc2 commit 49ee8a2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/stores/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ i18next.init({
title: "Create project in folder",
},
},
tabHeader: {
newWindow: {
title: "Move to new window",
},
},
},
modals: {
project: {
Expand Down
26 changes: 26 additions & 0 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import {
Plugin,
ItemView,
WorkspaceLeaf,
Menu,
type ViewStateResult,
} from "obsidian";
import { get } from "svelte/store";

import App from "src/ui/app/App.svelte";
import { i18n } from "./lib/stores/i18n";
import { customViews } from "src/lib/stores/customViews";
import { view } from "src/lib/stores/obsidian";
import { BoardView } from "src/ui/views/Board";
Expand Down Expand Up @@ -51,6 +54,29 @@ export class ProjectsView extends ItemView {
return "layout";
}

onPaneMenu(menu: Menu, source: "more-options" | "tab-header" | string) {
if (source == "tab-header") {
super.onPaneMenu(menu, source);
menu.addItem((item) => {
item
.setTitle(get(i18n).t("menus.tabHeader.newWindow.title"))
.setIcon("maximize")
.onClick(() => {
const existingLeaves =
this.app.workspace.getLeavesOfType(VIEW_TYPE_PROJECTS);
if (existingLeaves[0]) {
this.app.workspace.moveLeafToPopout(existingLeaves[0]);
}
})
.setSection("open");
});
return;
}

// In other cases, keep the original behavior
super.onPaneMenu(menu, source);
}

async onload() {
view.set(this);
}
Expand Down

0 comments on commit 49ee8a2

Please sign in to comment.