mirror of
https://github.com/devonthesofa/obsidian-note-status.git
synced 2026-07-22 12:30:24 +00:00
feat: add config; add logic
This commit is contained in:
parent
45af700bc2
commit
bcf05a708f
6 changed files with 66 additions and 2 deletions
|
|
@ -144,6 +144,31 @@ export const UISettings: React.FC<Props> = ({ settings, onChange }) => {
|
|||
onChange={handleChange("statusBarShowNoStatusText")}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem
|
||||
name="Show template names in status bar"
|
||||
description="Control how template names are displayed alongside status names"
|
||||
>
|
||||
<Select
|
||||
options={[
|
||||
{
|
||||
value: "never",
|
||||
display: "Never show template names",
|
||||
},
|
||||
{
|
||||
value: "auto",
|
||||
display: "Show only when status names conflict",
|
||||
},
|
||||
{
|
||||
value: "always",
|
||||
display: "Always show template names",
|
||||
},
|
||||
]}
|
||||
defaultValue={settings.statusBarShowTemplateName || "auto"}
|
||||
onChange={(value) =>
|
||||
onChange("statusBarShowTemplateName", value)
|
||||
}
|
||||
/>
|
||||
</SettingItem>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { GroupLabel } from "../atoms/GroupLabel";
|
|||
import { CollapsibleCounter } from "../atoms/CollapsibleCounter";
|
||||
import { StatusDisplay } from "../atoms/StatusDisplay";
|
||||
import { useStatusBarContext } from "./StatusBarContext";
|
||||
import settingsService from "@/core/settingsService";
|
||||
|
||||
export interface StatusBarGroupProps {
|
||||
statuses: NoteStatus[];
|
||||
|
|
@ -22,6 +23,11 @@ export const StatusBarGroup: FC<StatusBarGroupProps> = ({
|
|||
? statuses
|
||||
: statuses.slice(0, maxVisible);
|
||||
const hiddenCount = Math.max(0, statuses.length - maxVisible);
|
||||
|
||||
const statusNames = statuses.map((s) => s.name);
|
||||
const hasConflicts = statusNames.some(
|
||||
(name, index) => statusNames.indexOf(name) !== index,
|
||||
);
|
||||
const { onStatusClick } = useStatusBarContext();
|
||||
|
||||
return (
|
||||
|
|
@ -42,6 +48,11 @@ export const StatusBarGroup: FC<StatusBarGroupProps> = ({
|
|||
<StatusDisplay
|
||||
status={status}
|
||||
variant="badge"
|
||||
templateNameMode={
|
||||
settingsService.settings
|
||||
.statusBarShowTemplateName
|
||||
}
|
||||
hasNameConflicts={hasConflicts}
|
||||
onClick={() => {
|
||||
onStatusClick(status);
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -9,16 +9,39 @@ interface StatusDisplayProps {
|
|||
status: NoteStatus;
|
||||
variant: StatusDisplayVariant;
|
||||
removable?: boolean;
|
||||
hasNameConflicts?: boolean;
|
||||
templateNameMode?: "always" | "never" | "auto";
|
||||
onRemove?: () => void;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
export const StatusDisplay: FC<StatusDisplayProps> = memo(
|
||||
({ status, variant, removable = false, onRemove, onClick }) => {
|
||||
({
|
||||
status,
|
||||
variant,
|
||||
removable = false,
|
||||
hasNameConflicts = false,
|
||||
templateNameMode = "auto",
|
||||
onRemove,
|
||||
onClick,
|
||||
}) => {
|
||||
const [isRemoving, setIsRemoving] = useState(false);
|
||||
|
||||
const getDisplayName = () => {
|
||||
return status.templateId
|
||||
const shouldShowTemplate = (() => {
|
||||
switch (templateNameMode) {
|
||||
case "always":
|
||||
return true;
|
||||
case "never":
|
||||
return false;
|
||||
case "auto":
|
||||
return hasNameConflicts && status.templateId;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
return shouldShowTemplate && status.templateId
|
||||
? `${status.name} (${status.templateId})`
|
||||
: status.name;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export const DEFAULT_PLUGIN_SETTINGS: PluginSettings = {
|
|||
enabledTemplates: DEFAULT_ENABLED_TEMPLATES,
|
||||
useCustomStatusesOnly: false,
|
||||
useMultipleStatuses: true,
|
||||
statusBarShowTemplateName: "auto", // Default to show template names only when needed
|
||||
tagPrefix: "obsidian-note-status",
|
||||
strictStatuses: false, // Default to show all statuses from frontmatter
|
||||
quickStatusCommands: ["active", "completed"], // Add default quick commands
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ export class StatusBarIntegration {
|
|||
if (key === "showStatusBar") {
|
||||
this.render(); // INFO: Force a render to set disabled or enabled
|
||||
}
|
||||
if (key === "statusBarShowTemplateName") {
|
||||
this.render(); // INFO: Force a render to set disabled or enabled
|
||||
}
|
||||
if (key === "enabledTemplates" || key === "templates") {
|
||||
this.handleActiveFileChange().catch(console.error); // INFO: Force a re-read of the statuses and render
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ export type PluginSettings = {
|
|||
autoHideStatusBar: boolean;
|
||||
templates: StatusTemplate[];
|
||||
customStatuses: NoteStatus[];
|
||||
statusBarShowTemplateName: "always" | "never" | "auto"; // How to show template names in status bar
|
||||
showStatusIconsInExplorer: boolean;
|
||||
hideUnknownStatusInExplorer: boolean;
|
||||
enabledTemplates: string[]; // IDs of enabled templates
|
||||
|
|
|
|||
Loading…
Reference in a new issue