Skip to content

Commit

Permalink
Merge pull request #22 from Osterie/dev
Browse files Browse the repository at this point in the history
Possible to create new hotkeys instead of just edit existing ones. Heavy refactoring
  • Loading branch information
Osterie authored Mar 16, 2024
2 parents 4560a3b + 0ea6e24 commit 254e987
Show file tree
Hide file tree
Showing 30 changed files with 754 additions and 530 deletions.
2 changes: 1 addition & 1 deletion config/meta.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[General]
activeUserProfile=Main
activeUserProfile=test
2 changes: 1 addition & 1 deletion src/Main/Lib/Actions/KeysPressedGui.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Class KeysPressedGui{
this.GuiShowKeysPressed.Opt("-Caption +AlwaysOnTop +Owner +LastFound")
this.GuiShowKeysPressed.BackColor := "EEAA99"
this.GuiShowKeysPressed.SetFont("s40 w70 q4", "Cascadia Code")
this.showKeysPressedControl := this.GuiShowKeysPressed.AddText(, "")
this.showKeysPressedControl := this.GuiShowKeysPressed.Add("Text")
}

; The reason for the asterisk is because the Hotkey function is used to create hotkeys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Class WebNavigator{
}

OpenUrl(url){
Run("chrome.exe -incognito " url)
Run("chrome.exe " url)
}

; Translates highligted text or the text in the clipboard
Expand Down
4 changes: 1 addition & 3 deletions src/Main/Lib/UserInterface/ExtraKeyboardsApp.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ SendMode "Event"
Class ExtraKeyboardsApp{

UserInterface := ""
MainScript := ""

__New(activeObjectsRegistry, keyboardLayersInfoRegister, mainScript, keyNames){
this.MainScript := mainScript
this.Model := ExtraKeyboardsAppGuiModel(activeObjectsRegistry, keyboardLayersInfoRegister, keyNames)
this.UserInterface := ExtraKeyboardsAppGuiView()
this.Controller := ExtraKeyboardsAppGuiController(this.Model, this.UserInterface, keyboardLayersInfoRegister, mainScript)
this.Controller := ExtraKeyboardsAppGuiController(this.Model, this.UserInterface, mainScript)
}

Start(){
Expand Down
100 changes: 72 additions & 28 deletions src/Main/Lib/UserInterface/ExtraKeyboardsAppGuiController.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
#Include <Util\JsonParsing\JsonFormatter\JsonFormatter>
#Include <Util\MetaInfo\MetaInfoStorage\FoldersAndFiles\FilePaths\FilePaths>
#Include "Main\Functionality\ActionSettings\SettingsEditor.ahk"
#Include "Main\Functionality\Keyboard\KeyboardEditing\HotKeyConfigurationPopup.ahk"
#Include "Main\Functionality\KeyboardEditing\HotKeyConfigurationView.ahk"
#Include "Main\Functionality\KeyboardEditing\HotKeyConfigurationController.ahk"
#Include "Main\Functionality\KeyboardEditing\HotKeyConfigurationModel.ahk"

Class ExtraKeyboardsAppGuiController{

MainScript := ""
keyboardLayersInfoRegister := ""

__New(model, view, keyboardLayersInfoRegister, MainScript){
__New(model, view, MainScript){
this.view := view
this.model := model

this.MainScript := MainScript
this.keyboardLayersInfoRegister := keyboardLayersInfoRegister

}

HandleProfileChangedEvent(*){
Expand All @@ -25,7 +24,7 @@ Class ExtraKeyboardsAppGuiController{
this.view.Destroy()
}

HandleKeyboardLayerSelected(listViewControl, treeViewElement, treeViewElementSelectedItemID){
ShowHotkeysForLayer(listViewControl, treeViewElement, treeViewElementSelectedItemID){
currentLayer := treeViewElement.GetText(treeViewElementSelectedItemID)

this.model.SetCurrentLayer(currentLayer)
Expand All @@ -34,40 +33,85 @@ Class ExtraKeyboardsAppGuiController{
listViewControl.SetNewListViewItems(hotkeysForLayer)
}

; TODO make sure user cant create multiple popups
HandleKeyComboActionDoubleClickedEvent(listView, indexOfKeyToEdit){

layerInformation := this.GetCurrentLayerInfo()
; TODO make sure user cant create multiple popups?
EditHotkey(listView, indexOfKeyToEdit){

if (Type(layerInformation) == "HotkeysRegistry"){
hotkeyBuild := listView.GetText(indexOfKeyToEdit, 1)
hotkeyAction := listView.GetText(indexOfKeyToEdit, 2)
this.CreatePopupForHotkeys(hotkeyBuild, hotkeyAction)
if (indexOfKeyToEdit = 0){
emptyHotkeyInformation := HotkeyInfo()
this.CreatePopupForHotkeys(emptyHotkeyInformation)
}
else if (Type(layerInformation) == "KeyboardOverlayInfo"){
; TODO implement
; popupForConfiguringHotkey.CreatePopupForKeyboardOverlayInfo()
else{

layerInformation := this.GetCurrentLayerInfo()

if (Type(layerInformation) == "HotkeysRegistry"){
hotkeyBuild := listView.GetText(indexOfKeyToEdit, 1)
hotkeyInformation := this.model.GetHotkeyInfoForCurrentLayer(hotkeyBuild)
; hotkeyAction := listView.GetText(indexOfKeyToEdit, 2)
this.CreatePopupForHotkeys(hotkeyInformation)
}
else if (Type(layerInformation) == "KeyboardOverlayInfo"){
; TODO implement
; popupForConfiguringHotkey.CreatePopupForKeyboardOverlayInfo()
}
}
}

; TODO move to view
CreatePopupForHotkeys(hotkeyBuild, hotkeyAction){
popupForConfiguringHotkey := HotKeyConfigurationPopup(this.GetActiveObjectsRegistry(), this.GetKeyNames())
popupForConfiguringHotkey.CreatePopupForHotkeyRegistry(hotkeyBuild, hotkeyAction)
saveButtonEvent := ObjBindMethod(this, "HotKeyConfigurationPopupSaveEvent", popupForConfiguringHotkey)
popupForConfiguringHotkey.addSaveButtonClickedEvent(saveButtonEvent)
CreatePopupForHotkeys(hotkeyInformation){
popupForConfiguringHotkeyModel := HotKeyConfigurationModel(this.GetActiveObjectsRegistry(), this.GetKeyNames(), hotkeyInformation)
popupForConfiguringHotkey := HotKeyConfigurationView()
popupForConfiguringHotkeyController := HotKeyConfigurationController(popupForConfiguringHotkeyModel, popupForConfiguringHotkey)
popupForConfiguringHotkey.CreateMain(popupForConfiguringHotkeyController, this.GetHwnd())


popupForConfiguringHotkeyController.subscribeToSaveEvent(ObjBindMethod(this, "changeHotkeys"))
popupForConfiguringHotkeyController.subscribeToDeleteEvent(ObjBindMethod(this, "deleteHotkey"))

; TODO add delete button event.
}

GetHwnd(){
return this.view.GetHwnd()
}

changeHotkeys(hotkeyInformation, originalHotkeyKey){
newHotkeyKey := hotkeyInformation.getHotkeyName()


HotKeyConfigurationPopupSaveEvent(popupForConfiguringHotkey, *){
originalHotkey := popupForConfiguringHotkey.getOriginalHotkey()
newHotkey := popupForConfiguringHotkey.getHotkey()
newAction := popupForConfiguringHotkey.getAction()
this.model.ChangeHotkey(originalHotkey, newHotkey, newAction)
; If it does not exist, add it
; TODO this is bad, how the heck does EKAPGC know the default values is NONE?
if (originalHotkeyKey = ""){
try{
hotkeyInformation.changeHotkey(newHotkeyKey)
this.model.AddHotkey(hotkeyInformation)
}
catch Error as e{
msgbox("Could not add hotkey. " . e.Message)
}
}
else{
try{
this.model.ChangeHotkey(originalHotkeyKey, newHotkeyKey, hotkeyInformation)
msgbox("Changed hotkey")
}
catch Error as e{
msgbox("Could not modify hotkey. " . e.Message)
}
}

this.MainScript.RunLogicalStartup()
}

deleteHotkey(hotkeyKey){
try{
this.model.DeleteHotkey(hotkeyKey)
msgbox("Deleted hotkey")
}
catch Error as e{
msgbox("Could not delete hotkey. " . e.Message)
}
this.MainScript.RunLogicalStartup()
popupForConfiguringHotkey.Destroy()
}

HandleFunctionFromTreeViewSelected(listViewControl, treeViewElement, treeViewElementSelectedItemID){
Expand Down
45 changes: 24 additions & 21 deletions src/Main/Lib/UserInterface/ExtraKeyboardsAppGuiModel.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#Include <Util\MetaInfo\MetaInfoStorage\FoldersAndFiles\IniFileReader>
#Include <Util\MetaInfo\MetaInfoStorage\FoldersAndFiles\FilePaths\FilePaths>
#Include <Util\MetaInfo\MetaInfoReading\KeyboadLayersInfoClassObjectReader>
#Include <Util\MetaInfo\MetaInfoWriting\ToJsonFileWriter>

Class ExtraKeyboardsAppGuiModel{

Expand All @@ -22,25 +23,23 @@ Class ExtraKeyboardsAppGuiModel{
}

ChangeHotkey(originalHotkey, newHotkey, newAction){

this.keyboardLayersInfoRegister.ChangeHotkey(this.GetCurrentLayer(), originalHotkey, newHotkey)
this.keyboardLayersInfoRegister.ChangeAction(this.GetCurrentLayer(), newHotkey, newAction)

if (newAction != ""){
this.keyboardLayersInfoRegister.ChangeAction(this.GetCurrentLayer(), originalHotkey, newAction)
}
else{
msgbox("new action was blank, action unchanged...")
}
ToJsonFileWriter.WriteKeyboardLayersInfoRegisterToJsonFile(this.keyboardLayersInfoRegister, this.GetPathToCurrentProfile() . "\Keyboards.json")
}

AddHotkey(newAction){

this.keyboardLayersInfoRegister.AddHotkey(this.GetCurrentLayer(), newAction)

ToJsonFileWriter.WriteKeyboardLayersInfoRegisterToJsonFile(this.keyboardLayersInfoRegister, this.GetPathToCurrentProfile() . "\Keyboards.json")
}

; TODO create a method for this.
toJsonReader := KeyboadLayersInfoClassObjectReader()
toJsonReader.ReadObjectToJson(this.keyboardLayersInfoRegister)
jsonObject := toJsonReader.getJsonObject()
DeleteHotkey(hotkeyKey){
this.keyboardLayersInfoRegister.DeleteHotkey(this.GetCurrentLayer(), hotkeyKey)

formatterForJson := JsonFormatter()
jsonString := formatterForJson.FormatJsonObject(jsonObject)
FileRecycle(this.GetPathToCurrentProfile() . "\Keyboards.json")
FileAppend(jsonString, this.GetPathToCurrentProfile() . "\Keyboards.json", "UTF-8")
ToJsonFileWriter.WriteKeyboardLayersInfoRegisterToJsonFile(this.keyboardLayersInfoRegister, this.GetPathToCurrentProfile() . "\Keyboards.json")
}

GetFunctionNames(){
Expand All @@ -64,12 +63,6 @@ Class ExtraKeyboardsAppGuiModel{
return currentSettingsSettingValuePair
}

GetFriendlyHotkeysForLayer(layerIdentifier){
itemsToShowForListView := this.keyboardLayersInfoRegister.GetRegistryByLayerIdentifier(layerIdentifier)
hotkeysForLayer := itemsToShowForListView.getFriendlyHotkeyActionPairValues()

return hotkeysForLayer
}

GetFriendlyHotkeysForCurrentLayer(){
itemsToShowForListView := this.keyboardLayersInfoRegister.GetRegistryByLayerIdentifier(this.currentLayer)
Expand Down Expand Up @@ -119,4 +112,14 @@ Class ExtraKeyboardsAppGuiModel{
return FilePaths.GetPathToCurrentProfile()
}

GetHotkeyInfoForCurrentLayer(hotkeyKey){
return this.keyboardLayersInfoRegister.GetHotkeyInfoForLayer(this.GetCurrentLayer(), hotkeyKey)
}

; GetFriendlyHotkeysForLayer(layerIdentifier){
; itemsToShowForListView := this.keyboardLayersInfoRegister.GetRegistryByLayerIdentifier(layerIdentifier)
; hotkeysForLayer := itemsToShowForListView.getFriendlyHotkeyActionPairValues()

; return hotkeysForLayer
; }
}
59 changes: 19 additions & 40 deletions src/Main/Lib/UserInterface/ExtraKeyboardsAppGuiView.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,39 @@
#Include <UserInterface\Main\ProfileEditing\ProfileRegionController>
#Include <UserInterface\Main\util\TreeViewMaker>
#Include <UserInterface\Main\util\ListViewMaker>
#Include <UserInterface\Main\Functionality\Keyboard\KeyboardEditing\HotKeyConfigurationPopup>
#Include <UserInterface\Main\util\GuiColorsChanger>

Class ExtraKeyboardsAppGuiView{
#Include <Util\MetaInfo\MetaInfoStorage\KeyboardLayouts\KeyboardsInfo\Hotkeys\entity\HotKeyInfo>

; Used to create the gui
ExtraKeyboardsAppGui := ""

#Include <UserInterface\Main\Util\DomainSpecificGui>


; TODO everything should inherit from a base gui class which fixes the colors and such of all the guis.
Class ExtraKeyboardsAppGuiView extends DomainSpecificGui{

__New(){
; Empty
super.__New("+Resize +MinSize920x480", "Extra Keyboards App")
}


CreateMain(controller){
this.controller := controller

this.ExtraKeyboardsAppGui := Gui("+Resize +MinSize920x480", "Extra Keyboards App")
this.ExtraKeyboardsAppGui.BackColor := "051336"
this.ExtraKeyboardsAppGui.SetFont("c6688cc Bold")
this.controller := controller

this.CreateProfileEditor()
this.CreateTabs()
this.setColors()

; Create gui in the top left corner of the screen
this.ExtraKeyboardsAppGui.Show("x0 y0")
this.Show("x0 y0")
}

CreateProfileEditor(){
profileModel := ProfileRegionModel(this.ExtraKeyboardsAppGui)
profileModel := ProfileRegionModel(this)
profileView := ProfileRegionView()
profileController := ProfileRegionController(profileModel, profileView, ObjBindMethod(this.controller, "HandleProfileChangedEvent"))
profileController.CreateView()
}

CreateTabs(){
Tab := this.ExtraKeyboardsAppGui.AddTab3("yp+40 xm", ["Keyboards","Change Functions Settings","Documentation"])
Tab := this.AddTab3("yp+40 xm", ["Keyboards","Change Functions Settings","Documentation"])
Tab.UseTab(1)
this.CreateKeyboardsTab()

Expand All @@ -56,44 +52,27 @@ Class ExtraKeyboardsAppGuiView{

CreateKeyboardsTab(){
keyboardLayoutChanger := TreeViewMaker()
keyboardLayoutChanger.createElementsForGui(this.ExtraKeyboardsAppGui, this.controller.GetKeyboardLayerIdentifiers())
keyboardLayoutChanger.createElementsForGui(this, this.controller.GetKeyboardLayerIdentifiers())

listViewControl := ListViewMaker()
listViewControl.CreateListView(this.ExtraKeyboardsAppGui, ["KeyCombo","Action"])
listViewControl.CreateListView(this, ["KeyCombo","Action"])

keyboardLayoutChanger.AddEventAction("ItemSelect", ObjBindMethod(this.controller, "HandleKeyboardLayerSelected", listViewControl))
listViewControl.AddEventAction("DoubleClick", ObjBindMethod(this.controller, "HandleKeyComboActionDoubleClickedEvent"))
keyboardLayoutChanger.AddEventAction("ItemSelect", ObjBindMethod(this.controller, "ShowHotkeysForLayer", listViewControl))
listViewControl.AddEventAction("DoubleClick", ObjBindMethod(this.controller, "EditHotkey"))
}

CreateFunctionSettingsTab(){

functionsNamesTreeView := TreeViewMaker()
functionsNamesTreeView.createElementsForGui(this.ExtraKeyboardsAppGui, this.controller.GetFunctionNames())
functionsNamesTreeView.createElementsForGui(this, this.controller.GetFunctionNames())

settingsValuesListView := ListViewMaker()
settingsValuesListView.CreateListView(this.ExtraKeyboardsAppGui, ["Setting","Value"])
settingsValuesListView.CreateListView(this, ["Setting","Value"])

functionsNamesTreeView.AddEventAction("ItemSelect", ObjBindMethod(this.controller, "HandleFunctionFromTreeViewSelected", settingsValuesListView))
settingsValuesListView.AddEventAction("DoubleClick", ObjBindMethod(this.controller, "HandleSettingClicked", functionsNamesTreeView))
}


CreateDocumentationTab(){
this.ExtraKeyboardsAppGui.Add("Edit", "vMyEdit r20") ; r20 means 20 rows tall.
}

setColors(){
controlColor := "060621"
textColor := "6688FF"
GuiColorsChanger.setControlsColor(this.ExtraKeyboardsAppGui, controlColor)
GuiColorsChanger.setControlsTextColor(this.ExtraKeyboardsAppGui, textColor)

; Top bar or whatever it is called
GuiColorsChanger.DwmSetCaptionColor(this.ExtraKeyboardsAppGui, 0x300f45) ; color is in RGB format
GuiColorsChanger.DwmSetTextColor(this.ExtraKeyboardsAppGui, 0x27eaf1)
}

Destroy(){
this.ExtraKeyboardsAppGui.Destroy()
this.Add("Edit", "vMyEdit r20") ; r20 means 20 rows tall.
}
}
Loading

0 comments on commit 254e987

Please sign in to comment.