Refactoring
This commit is contained in:
@ -13,7 +13,6 @@
|
||||
import InputDialog from './lib/InputDialog.svelte';
|
||||
import { createCsoundDerivedStores, type LogEntry } from './lib/csound';
|
||||
import { type CsoundProject } from './lib/project-system';
|
||||
import { uiState } from './lib/stores/uiState.svelte';
|
||||
import { DEFAULT_CSOUND_TEMPLATE } from './lib/config/templates';
|
||||
import { createAppContext, setAppContext } from './lib/contexts/app-context';
|
||||
import {
|
||||
@ -32,12 +31,11 @@
|
||||
const appContext = createAppContext();
|
||||
setAppContext(appContext);
|
||||
|
||||
const { csound, projectManager, editorSettings, projectEditor } = appContext;
|
||||
const { csound, projectManager, editorSettings, projectEditor, uiState } = appContext;
|
||||
const csoundDerived = createCsoundDerivedStores(csound);
|
||||
|
||||
let analyserNode = $state<AnalyserNode | null>(null);
|
||||
let interpreterLogs = $state<LogEntry[]>([]);
|
||||
let fileBrowserRef: FileBrowser;
|
||||
|
||||
onMount(async () => {
|
||||
await projectManager.init();
|
||||
@ -79,12 +77,11 @@
|
||||
}
|
||||
|
||||
function handleNewFile() {
|
||||
const needsConfirm = projectEditor.requestSwitch(
|
||||
() => projectEditor.createNew(DEFAULT_CSOUND_TEMPLATE),
|
||||
handleSwitchConfirm
|
||||
const result = projectEditor.requestSwitch(
|
||||
() => projectEditor.createNew(DEFAULT_CSOUND_TEMPLATE)
|
||||
);
|
||||
|
||||
if (needsConfirm) {
|
||||
if (result === 'confirm-unsaved') {
|
||||
uiState.showUnsavedChangesDialog();
|
||||
}
|
||||
}
|
||||
@ -92,12 +89,11 @@
|
||||
function handleFileSelect(project: CsoundProject | null) {
|
||||
if (!project) return;
|
||||
|
||||
const needsConfirm = projectEditor.requestSwitch(
|
||||
() => projectEditor.loadProject(project),
|
||||
handleSwitchConfirm
|
||||
const result = projectEditor.requestSwitch(
|
||||
() => projectEditor.loadProject(project)
|
||||
);
|
||||
|
||||
if (needsConfirm) {
|
||||
if (result === 'confirm-unsaved') {
|
||||
uiState.showUnsavedChangesDialog();
|
||||
}
|
||||
}
|
||||
@ -116,42 +112,34 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const success = await projectEditor.save();
|
||||
if (success) {
|
||||
fileBrowserRef?.refresh();
|
||||
}
|
||||
await projectEditor.save();
|
||||
}
|
||||
|
||||
async function handleSaveAs(title: string) {
|
||||
const success = await projectEditor.saveAs(title);
|
||||
if (success) {
|
||||
fileBrowserRef?.refresh();
|
||||
uiState.hideSaveAsDialog();
|
||||
}
|
||||
}
|
||||
|
||||
async function handleMetadataUpdate(projectId: string, updates: { title?: string; author?: string }) {
|
||||
const success = await projectEditor.updateMetadata(updates);
|
||||
if (success) {
|
||||
fileBrowserRef?.refresh();
|
||||
await projectEditor.updateMetadata(updates);
|
||||
}
|
||||
|
||||
async function handleSwitchSave() {
|
||||
const result = await projectEditor.confirmSaveAndSwitch();
|
||||
|
||||
if (result === 'show-save-as') {
|
||||
uiState.hideUnsavedChangesDialog();
|
||||
uiState.showSaveAsDialog();
|
||||
} else {
|
||||
uiState.hideUnsavedChangesDialog();
|
||||
}
|
||||
}
|
||||
|
||||
function handleSwitchConfirm(action: 'save' | 'discard') {
|
||||
if (action === 'save') {
|
||||
if (projectEditor.isNewUnsavedBuffer) {
|
||||
uiState.hideUnsavedChangesDialog();
|
||||
uiState.showSaveAsDialog();
|
||||
} else {
|
||||
projectEditor.handleSaveAndSwitch().then(() => {
|
||||
fileBrowserRef?.refresh();
|
||||
uiState.hideUnsavedChangesDialog();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
projectEditor.handleDiscardAndSwitch();
|
||||
uiState.hideUnsavedChangesDialog();
|
||||
}
|
||||
function handleSwitchDiscard() {
|
||||
projectEditor.confirmDiscardAndSwitch();
|
||||
uiState.hideUnsavedChangesDialog();
|
||||
}
|
||||
|
||||
async function handleShare() {
|
||||
@ -170,11 +158,15 @@
|
||||
|
||||
$effect(() => {
|
||||
if (uiState.scopePopupVisible || uiState.spectrogramPopupVisible) {
|
||||
const interval = setInterval(() => {
|
||||
analyserNode = csound.getAnalyserNode();
|
||||
}, 100);
|
||||
analyserNode = csound.getAnalyserNode();
|
||||
|
||||
return () => clearInterval(interval);
|
||||
const unsubscribe = csound.onAnalyserNodeCreated((node) => {
|
||||
analyserNode = node;
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
} else {
|
||||
analyserNode = null;
|
||||
}
|
||||
});
|
||||
|
||||
@ -198,7 +190,6 @@
|
||||
|
||||
{#snippet filesTabContent()}
|
||||
<FileBrowser
|
||||
bind:this={fileBrowserRef}
|
||||
{projectManager}
|
||||
onFileSelect={handleFileSelect}
|
||||
onNewFile={handleNewFile}
|
||||
@ -400,8 +391,8 @@
|
||||
message="You have unsaved changes. What would you like to do?"
|
||||
confirmLabel="Save"
|
||||
cancelLabel="Discard"
|
||||
onConfirm={() => handleSwitchConfirm('save')}
|
||||
onCancel={() => handleSwitchConfirm('discard')}
|
||||
onConfirm={handleSwitchSave}
|
||||
onCancel={handleSwitchDiscard}
|
||||
/>
|
||||
|
||||
<InputDialog
|
||||
|
||||
Reference in New Issue
Block a user