-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes for code review. Also reorganized some files and fixed some s…
…mall problems I found.
- Loading branch information
1 parent
cdae7c7
commit ce6286b
Showing
17 changed files
with
301 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { TabInfo } from '@shared/data/WebviewTypes'; | ||
|
||
const ErrorTab = ({ errorMessage }: { errorMessage: string }) => { | ||
return ( | ||
<> | ||
<div> | ||
Content could not be loaded. Please make sure you have the correct | ||
extension loaded. | ||
</div> | ||
<div>Message: {errorMessage}</div> | ||
</> | ||
); | ||
}; | ||
|
||
const createErrorTab = (errorMessage: string): TabInfo => { | ||
return { | ||
type: 'error', | ||
title: 'Error', | ||
content: <ErrorTab errorMessage={errorMessage} />, | ||
minWidth: 150, | ||
minHeight: 150, | ||
}; | ||
}; | ||
|
||
export default createErrorTab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import 'rc-dock/dist/rc-dock.css'; | ||
import './ParanextDockLayout.css'; | ||
import { newGuid } from '@shared/util/Util'; | ||
import { SavedTabInfo, TabCreator, TabInfo } from '@shared/data/WebviewTypes'; | ||
import DockLayout, { TabBase, TabData, TabGroup } from 'rc-dock'; | ||
import testLayout from '@renderer/testing/testLayout'; | ||
import createHelloPanel from '@renderer/testing/HelloPanel'; | ||
import createButtonsPanel from '@renderer/testing/TestButtonsPanel'; | ||
import createTabPanel from '@renderer/testing/TestPanel'; | ||
import createErrorTab from './ErrorTab'; | ||
import ParanextPanel from './ParanextPanel'; | ||
import ParanextTabTitle from './ParanextTabTitle'; | ||
|
||
// NOTE: 'card' is a built-in style. We can likely remove it when we | ||
// create a full theme for Paranext. | ||
const TAB_GROUPS = 'card paranext'; | ||
|
||
// TODO: Build this mapping from extensions so extensions can create their own panels | ||
const tabTypeCreationMap = new Map<string, TabCreator>([ | ||
['hello', createHelloPanel], | ||
['buttons', createButtonsPanel], | ||
['tab', createTabPanel], | ||
]); | ||
|
||
/** | ||
* Creates tab data from the specified saved tab information by calling back to the | ||
* extension that registered the creation of the tab type | ||
*/ | ||
const loadTab = (savedTabInfo: TabBase): TabData => { | ||
let { id } = savedTabInfo; | ||
if (!id) id = newGuid(); | ||
|
||
const tabInfo = savedTabInfo as SavedTabInfo; | ||
let newTabData: TabInfo | undefined; | ||
let error = ''; | ||
|
||
if (!tabInfo.type) { | ||
error = `No handler for the tab type '${tabInfo.type}'`; | ||
} else { | ||
const tabCreator = tabTypeCreationMap.get(tabInfo.type); | ||
if (!tabCreator) { | ||
error = `No handler for the tab type '${tabInfo.type}'`; | ||
} else { | ||
// Call the creation method to let the extension method create the tab | ||
newTabData = tabCreator(tabInfo); | ||
} | ||
} | ||
|
||
// If the tab couldn't be created, replace it with an error tab | ||
if (!newTabData) newTabData = createErrorTab(error); | ||
|
||
// Translate the data from the extension to be in the form needed by rc-dock | ||
return { | ||
id, | ||
title: <ParanextTabTitle text={newTabData.title} />, | ||
content: <ParanextPanel>{newTabData.content}</ParanextPanel>, | ||
minWidth: newTabData.minWidth, | ||
minHeight: newTabData.minHeight, | ||
group: TAB_GROUPS, | ||
closable: true, | ||
}; | ||
}; | ||
|
||
const groups: { | ||
[key: string]: TabGroup; | ||
} = { | ||
[TAB_GROUPS]: { | ||
maximizable: false, // Don't allow groups of tabs to be maximized | ||
floatable: true, // Allow tabs to be floated | ||
newWindow: true, // Allow floating windows to show in a native window | ||
animated: false, // Don't animate tab transitions | ||
panelExtra: undefined, // Get rid of buttons on tab group panel (we only want buttons on each tab) | ||
}, | ||
}; | ||
|
||
const ParanextDockLayout = () => { | ||
return ( | ||
<DockLayout | ||
groups={groups} | ||
defaultLayout={testLayout} | ||
dropMode="edge" | ||
loadTab={loadTab} | ||
style={{ position: 'absolute', left: 3, top: 3, right: 3, bottom: 3 }} | ||
/> | ||
); | ||
}; | ||
|
||
export default ParanextDockLayout; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.