[DE] Add recent-fonts

This commit is contained in:
ShimaginAndrey 2021-08-02 11:37:52 +03:00
parent cbf8194dae
commit c27d5bf9d9
2 changed files with 37 additions and 2 deletions

View file

@ -1,10 +1,13 @@
import {action, observable, computed, makeObservable} from 'mobx'; import {action, observable, computed, makeObservable} from 'mobx';
import { LocalStorage } from '../../../../common/mobile/utils/LocalStorage';
export class storeTextSettings { export class storeTextSettings {
constructor() { constructor() {
makeObservable(this, { makeObservable(this, {
fontsArray: observable, fontsArray: observable,
fontName: observable, fontName: observable,
arrayRecentFonts:observable,
fontSize: observable, fontSize: observable,
isBold: observable, isBold: observable,
isItalic: observable, isItalic: observable,
@ -39,11 +42,13 @@ export class storeTextSettings {
changeCustomTextColors: action, changeCustomTextColors: action,
resetLineSpacing: action, resetLineSpacing: action,
resetBackgroundColor: action, resetBackgroundColor: action,
changeFontFamily: action changeFontFamily: action,
addFontToRecent:action
}); });
} }
fontsArray = []; fontsArray = [];
arrayRecentFonts = [];
fontName = ''; fontName = '';
fontSize = undefined; fontSize = undefined;
isBold = false; isBold = false;
@ -80,6 +85,9 @@ export class storeTextSettings {
}); });
this.fontsArray = array; this.fontsArray = array;
this.arrayRecentFonts = LocalStorage.getItem('dde-settings-recent-fonts');
this.arrayRecentFonts = this.arrayRecentFonts ? this.arrayRecentFonts.split(';') : [];
} }
resetFontName (font) { resetFontName (font) {
let name = (typeof font.get_Name) === "function" ? font.get_Name() : font.asc_getName(); let name = (typeof font.get_Name) === "function" ? font.get_Name() : font.asc_getName();
@ -173,6 +181,20 @@ export class storeTextSettings {
this.fontName = name; this.fontName = name;
} }
addFontToRecent (font) {
this.arrayRecentFonts.forEach(item => {
if (item === font) this.arrayRecentFonts.splice(this.arrayRecentFonts.indexOf(item),1);
})
this.arrayRecentFonts.unshift(font);
if (this.arrayRecentFonts.length > 5) this.arrayRecentFonts.splice(4,1);
let arr = [];
this.arrayRecentFonts.forEach(item => arr.push(item));
arr = arr.join(';');
LocalStorage.setItem('dde-settings-recent-fonts', arr);
}
resetLineSpacing (vc) { resetLineSpacing (vc) {
let line = (vc.get_Line() === null || vc.get_LineRule() === null || vc.get_LineRule() != 1) ? -1 : vc.get_Line(); let line = (vc.get_Line() === null || vc.get_LineRule() === null || vc.get_LineRule() != 1) ? -1 : vc.get_Line();
this.lineSpacing = line; this.lineSpacing = line;

View file

@ -14,6 +14,7 @@ const PageFonts = props => {
const displaySize = typeof size === 'undefined' ? t('Edit.textAuto') : size + ' ' + t('Edit.textPt'); const displaySize = typeof size === 'undefined' ? t('Edit.textAuto') : size + ' ' + t('Edit.textPt');
const curFontName = storeTextSettings.fontName; const curFontName = storeTextSettings.fontName;
const fonts = storeTextSettings.fontsArray; const fonts = storeTextSettings.fontsArray;
const arrayFonts = storeTextSettings.arrayRecentFonts;
const [vlFonts, setVlFonts] = useState({ const [vlFonts, setVlFonts] = useState({
vlData: { vlData: {
items: [], items: [],
@ -56,6 +57,17 @@ const PageFonts = props => {
</div> </div>
</ListItem> </ListItem>
</List> </List>
<List>
{arrayFonts.map((item,index) => (
<ListItem
key={index}
link="#"
title={item}
style={{fontFamily: `${item}`}}
onClick={() => {storeTextSettings.changeFontFamily(item); props.changeFontFamily(item);}}
/>
))}
</List>
<BlockTitle>{t('Edit.textFonts')}</BlockTitle> <BlockTitle>{t('Edit.textFonts')}</BlockTitle>
<List virtualList virtualListParams={{ <List virtualList virtualListParams={{
items: fonts, items: fonts,
@ -69,7 +81,8 @@ const PageFonts = props => {
checked={curFontName === item.name} checked={curFontName === item.name}
title={item.name} title={item.name}
style={{fontFamily: `${item.name}`}} style={{fontFamily: `${item.name}`}}
onClick={() => {storeTextSettings.changeFontFamily(item.name); props.changeFontFamily(item.name)}} onClick={() => {storeTextSettings.changeFontFamily(item.name); props.changeFontFamily(item.name);
storeTextSettings.addFontToRecent(item.name)}}
></ListItem> ></ListItem>
))} ))}
</ul> </ul>