forked from Shinonome/dots-hyprland
sideleft: remember last used page
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||||
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
||||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
const { Box, Button, EventBox, Label, Overlay, Stack } = Widget;
|
const { Box, Button, EventBox, Label, Overlay, Stack } = Widget;
|
||||||
@@ -7,12 +8,13 @@ import { setupCursorHover } from '../.widgetutils/cursorhover.js';
|
|||||||
import { DoubleRevealer } from '../.widgethacks/advancedrevealers.js';
|
import { DoubleRevealer } from '../.widgethacks/advancedrevealers.js';
|
||||||
|
|
||||||
export const TabContainer = ({
|
export const TabContainer = ({
|
||||||
icons, names, children,
|
icons, names, children, initIndex = 0,
|
||||||
className = '', setup = () => { },
|
className = '', setup = () => { },
|
||||||
|
onChange = () => { },
|
||||||
extraTabStripWidgets = [],
|
extraTabStripWidgets = [],
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const shownIndex = Variable(0);
|
const shownIndex = Variable(initIndex);
|
||||||
let previousShownIndex = 0;
|
let previousShownIndex = 0;
|
||||||
const count = Math.min(icons.length, names.length, children.length);
|
const count = Math.min(icons.length, names.length, children.length);
|
||||||
const tabs = Box({
|
const tabs = Box({
|
||||||
@@ -72,6 +74,8 @@ export const TabContainer = ({
|
|||||||
})
|
})
|
||||||
})]
|
})]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
shownIndex.setValue(initIndex)
|
||||||
const contentStack = Stack({
|
const contentStack = Stack({
|
||||||
transition: 'slide_left_right',
|
transition: 'slide_left_right',
|
||||||
children: children.reduce((acc, currentValue, index) => {
|
children: children.reduce((acc, currentValue, index) => {
|
||||||
@@ -82,6 +86,7 @@ export const TabContainer = ({
|
|||||||
self.shown = `${shownIndex.value}`;
|
self.shown = `${shownIndex.value}`;
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const mainBox = Box({
|
const mainBox = Box({
|
||||||
attribute: {
|
attribute: {
|
||||||
children: children,
|
children: children,
|
||||||
@@ -94,9 +99,11 @@ export const TabContainer = ({
|
|||||||
self.pack_start(tabSection, false, false, 0);
|
self.pack_start(tabSection, false, false, 0);
|
||||||
self.pack_end(contentStack, true, true, 0);
|
self.pack_end(contentStack, true, true, 0);
|
||||||
setup(self);
|
setup(self);
|
||||||
|
self.hook(shownIndex, (self) => onChange(self, shownIndex.value));
|
||||||
},
|
},
|
||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
|
|
||||||
mainBox.nextTab = () => shownIndex.value = Math.min(shownIndex.value + 1, count - 1);
|
mainBox.nextTab = () => shownIndex.value = Math.min(shownIndex.value + 1, count - 1);
|
||||||
mainBox.prevTab = () => shownIndex.value = Math.max(shownIndex.value - 1, 0);
|
mainBox.prevTab = () => shownIndex.value = Math.max(shownIndex.value - 1, 0);
|
||||||
mainBox.cycleTab = () => shownIndex.value = (shownIndex.value + 1) % count;
|
mainBox.cycleTab = () => shownIndex.value = (shownIndex.value + 1) % count;
|
||||||
@@ -107,11 +114,12 @@ export const TabContainer = ({
|
|||||||
|
|
||||||
export const IconTabContainer = ({
|
export const IconTabContainer = ({
|
||||||
iconWidgets, names, children, className = '',
|
iconWidgets, names, children, className = '',
|
||||||
|
initIndex = 0,
|
||||||
setup = () => { }, onChange = () => { },
|
setup = () => { }, onChange = () => { },
|
||||||
tabsHpack = 'center', tabSwitcherClassName = '',
|
tabsHpack = 'center', tabSwitcherClassName = '',
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const shownIndex = Variable(0);
|
const shownIndex = Variable(initIndex);
|
||||||
let previousShownIndex = 0;
|
let previousShownIndex = 0;
|
||||||
const count = Math.min(iconWidgets.length, names.length, children.length);
|
const count = Math.min(iconWidgets.length, names.length, children.length);
|
||||||
const tabs = Box({
|
const tabs = Box({
|
||||||
|
|||||||
@@ -123,13 +123,15 @@
|
|||||||
"apis",
|
"apis",
|
||||||
"tools"
|
"tools"
|
||||||
],
|
],
|
||||||
|
"defaultPage": "apis",
|
||||||
"apis": {
|
"apis": {
|
||||||
"order": [
|
"order": [
|
||||||
"gemini",
|
"gemini",
|
||||||
"gpt",
|
"gpt",
|
||||||
"waifu",
|
"waifu",
|
||||||
"booru"
|
"booru"
|
||||||
]
|
],
|
||||||
|
"defaultPage": "gemini"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"quickToggles": {
|
"quickToggles": {
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ const TextView = Widget.subclass(Gtk.TextView, "AgsTextView");
|
|||||||
|
|
||||||
import { widgetContent } from './sideleft.js';
|
import { widgetContent } from './sideleft.js';
|
||||||
import { IconTabContainer } from '../.commonwidgets/tabcontainer.js';
|
import { IconTabContainer } from '../.commonwidgets/tabcontainer.js';
|
||||||
|
import { updateNestedProperty } from '../.miscutils/objects.js';
|
||||||
|
|
||||||
const EXPAND_INPUT_THRESHOLD = 30;
|
const EXPAND_INPUT_THRESHOLD = 30;
|
||||||
|
const AGS_CONFIG_FILE = `${App.configDir}/user_options.jsonc`;
|
||||||
|
|
||||||
export const chatEntry = TextView({
|
export const chatEntry = TextView({
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
@@ -69,40 +71,44 @@ export const chatEntry = TextView({
|
|||||||
|
|
||||||
const APILIST = {
|
const APILIST = {
|
||||||
'gemini': {
|
'gemini': {
|
||||||
name: 'Assistant (Gemini Pro)',
|
"name": 'Assistant (Gemini Pro)',
|
||||||
sendCommand: geminiSendMessage,
|
"sendCommand": geminiSendMessage,
|
||||||
contentWidget: GeminiView(chatEntry),
|
"contentWidget": GeminiView(chatEntry),
|
||||||
commandBar: geminiCommands,
|
"commandBar": geminiCommands,
|
||||||
tabIcon: geminiTabIcon,
|
"tabIcon": geminiTabIcon,
|
||||||
placeholderText: getString('Message Gemini...'),
|
"placeholderText": getString('Message Gemini...'),
|
||||||
},
|
},
|
||||||
'gpt': {
|
'gpt': {
|
||||||
name: 'Assistant (GPTs)',
|
"name": 'Assistant (GPTs)',
|
||||||
sendCommand: chatGPTSendMessage,
|
"sendCommand": chatGPTSendMessage,
|
||||||
contentWidget: ChatGPTView(chatEntry),
|
"contentWidget": ChatGPTView(chatEntry),
|
||||||
commandBar: chatGPTCommands,
|
"commandBar": chatGPTCommands,
|
||||||
tabIcon: chatGPTTabIcon,
|
"tabIcon": chatGPTTabIcon,
|
||||||
placeholderText: getString('Message the model...'),
|
"placeholderText": getString('Message the model...'),
|
||||||
},
|
},
|
||||||
'waifu': {
|
'waifu': {
|
||||||
name: 'Waifus',
|
"name": 'Waifus',
|
||||||
sendCommand: waifuSendMessage,
|
"sendCommand": waifuSendMessage,
|
||||||
contentWidget: WaifuView(chatEntry),
|
"contentWidget": WaifuView(chatEntry),
|
||||||
commandBar: waifuCommands,
|
"commandBar": waifuCommands,
|
||||||
tabIcon: waifuTabIcon,
|
"tabIcon": waifuTabIcon,
|
||||||
placeholderText: getString('Enter tags'),
|
"placeholderText": getString('Enter tags'),
|
||||||
},
|
},
|
||||||
'booru': {
|
'booru': {
|
||||||
name: 'Booru',
|
"name": 'Booru',
|
||||||
sendCommand: booruSendMessage,
|
"sendCommand": booruSendMessage,
|
||||||
contentWidget: BooruView(chatEntry),
|
"contentWidget": BooruView(chatEntry),
|
||||||
commandBar: booruCommands,
|
"commandBar": booruCommands,
|
||||||
tabIcon: booruTabIcon,
|
"tabIcon": booruTabIcon,
|
||||||
placeholderText: getString('Enter tags and/or page number'),
|
"placeholderText": getString('Enter tags and/or page number'),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const APIS = userOptions.sidebar.pages.apis.order.map((apiName) => APILIST[apiName]);
|
const APIS = userOptions.sidebar.pages.apis.order.map((apiName) => {
|
||||||
let currentApiId = 0;
|
const obj = { ...APILIST[apiName] };
|
||||||
|
obj["id"] = apiName;
|
||||||
|
return obj;
|
||||||
|
});
|
||||||
|
let currentApiId = APIS.findIndex(obj => obj.id === userOptions.sidebar.pages.apis.defaultPage);
|
||||||
|
|
||||||
function apiSendMessage(textView) {
|
function apiSendMessage(textView) {
|
||||||
// Get text
|
// Get text
|
||||||
@@ -198,11 +204,21 @@ export const apiContentStack = IconTabContainer({
|
|||||||
iconWidgets: APIS.map((api) => api.tabIcon),
|
iconWidgets: APIS.map((api) => api.tabIcon),
|
||||||
names: APIS.map((api) => api.name),
|
names: APIS.map((api) => api.name),
|
||||||
children: APIS.map((api) => api.contentWidget),
|
children: APIS.map((api) => api.contentWidget),
|
||||||
|
initIndex: currentApiId,
|
||||||
onChange: (self, id) => {
|
onChange: (self, id) => {
|
||||||
apiCommandStack.shown = APIS[id].name;
|
apiCommandStack.shown = APIS[id].name;
|
||||||
chatPlaceholder.label = APIS[id].placeholderText;
|
chatPlaceholder.label = APIS[id].placeholderText;
|
||||||
currentApiId = id;
|
currentApiId = id;
|
||||||
|
const pageName = APIS[id].id;
|
||||||
|
const option = 'sidebar.pages.apis.defaultPage';
|
||||||
|
updateNestedProperty(userOptions, option, pageName);
|
||||||
|
execAsync(['bash', '-c', `${App.configDir}/scripts/ags/agsconfigurator.py \
|
||||||
|
--key ${option} \
|
||||||
|
--value ${pageName} \
|
||||||
|
--file ${AGS_CONFIG_FILE}`
|
||||||
|
]).catch(print);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function switchToTab(id) {
|
function switchToTab(id) {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import apiWidgets from './apiwidgets.js';
|
|||||||
import { chatEntry } from './apiwidgets.js';
|
import { chatEntry } from './apiwidgets.js';
|
||||||
import { TabContainer } from '../.commonwidgets/tabcontainer.js';
|
import { TabContainer } from '../.commonwidgets/tabcontainer.js';
|
||||||
import { checkKeybind } from '../.widgetutils/keybind.js';
|
import { checkKeybind } from '../.widgetutils/keybind.js';
|
||||||
|
import { updateNestedProperty } from '../.miscutils/objects.js';
|
||||||
|
|
||||||
|
const AGS_CONFIG_FILE = `${App.configDir}/user_options.jsonc`;
|
||||||
|
|
||||||
const SIDEBARTABS = {
|
const SIDEBARTABS = {
|
||||||
'apis': {
|
'apis': {
|
||||||
@@ -85,10 +88,17 @@ export const widgetContent = TabContainer({
|
|||||||
names: CONTENTS.map((item) => item.friendlyName),
|
names: CONTENTS.map((item) => item.friendlyName),
|
||||||
children: CONTENTS.map((item) => item.content),
|
children: CONTENTS.map((item) => item.content),
|
||||||
className: 'sidebar-left spacing-v-10',
|
className: 'sidebar-left spacing-v-10',
|
||||||
// setup: (self) => self.hook(App, (self, currentName, visible) => {
|
initIndex: CONTENTS.findIndex(obj => obj.name === userOptions.sidebar.pages.defaultPage),
|
||||||
// if (currentName === 'sideleft')
|
onChange: (self, index) => {
|
||||||
// self.toggleClassName('sidebar-pinned', pinButton.attribute.enabled && visible);
|
const pageName = CONTENTS[index].name;
|
||||||
// }),
|
const option = 'sidebar.pages.defaultPage';
|
||||||
|
updateNestedProperty(userOptions, option, pageName);
|
||||||
|
execAsync(['bash', '-c', `${App.configDir}/scripts/ags/agsconfigurator.py \
|
||||||
|
--key ${option} \
|
||||||
|
--value ${pageName} \
|
||||||
|
--file ${AGS_CONFIG_FILE}`
|
||||||
|
]).catch(print);
|
||||||
|
},
|
||||||
extraTabStripWidgets: [
|
extraTabStripWidgets: [
|
||||||
// pinButton,
|
// pinButton,
|
||||||
expandButton,
|
expandButton,
|
||||||
|
|||||||
Reference in New Issue
Block a user