Skip to content

Commit

Permalink
Merge pull request #31 from Osterie/dev
Browse files Browse the repository at this point in the history
Fixes and features
  • Loading branch information
Osterie authored Mar 31, 2024
2 parents 310286a + f67cb9c commit d48e887
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 96 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
13 changes: 9 additions & 4 deletions src/Main/Lib/UserInterface/ExtraKeyboardsAppGuiController.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Class ExtraKeyboardsAppGuiController{
this.view.Destroy()
}

DoLayerSelected(currentLayer){
this.ShowHotkeysForLayer(currentLayer)
this.View.UpdateConfigurationButtons()
}

ShowHotkeysForLayer(currentLayer){

this.model.SetCurrentLayer(currentLayer)
Expand All @@ -37,18 +42,18 @@ Class ExtraKeyboardsAppGuiController{

; TODO make sure user cant create multiple popups?
; TODO change name for this...
EditHotkey(listView, indexOfKeyToEdit){
DoAddOrEditHotkey(hotkeyBuild := ""){

layerInformation := this.GetCurrentLayerInfo()

if (Type(layerInformation) == "HotkeysRegistry"){
hotkeyInformation := HotkeyInfo()

if (indexOfKeyToEdit = 0){
; this.CreatePopupForHotkeys(hotkeyInformation)
; TODO find a better way than this...
if (hotkeyBuild = "KeyCombo" || hotkeyBuild = ""){

}
else{
hotkeyBuild := listView.GetText(indexOfKeyToEdit, 1)
hotkeyInformation := this.model.GetHotkeyInfoForCurrentLayer(hotkeyBuild)
}
this.CreatePopupForHotkeys(hotkeyInformation)
Expand Down
55 changes: 52 additions & 3 deletions src/Main/Lib/UserInterface/ExtraKeyboardsAppGuiView.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Class ExtraKeyboardsAppGuiView extends DomainSpecificGui{
}

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

Expand All @@ -60,8 +60,57 @@ Class ExtraKeyboardsAppGuiView extends DomainSpecificGui{
this.hotkeysListView := ListViewMaker()
this.hotkeysListView.CreateListView(this, "r20 w600 x+10 -multi" , ["KeyCombo","Action"])

keyboardLayoutChanger.AddEventAction("ItemSelect", (*) => this.controller.ShowHotkeysForLayer(keyboardLayoutChanger.GetSelectionText()))
this.hotkeysListView.AddEventAction("DoubleClick", ObjBindMethod(this.controller, "EditHotkey"))

this.ButtonForAddingInfo := this.Add("Button", "", "Add")
this.ButtonForAddingInfo.OnEvent("Click", (*) => this.controller.DoAddOrEditHotkey())

this.ButtonForAddingInfo.Opt("Hidden1")

this.ButtonForEditingInfo := this.Add("Button", "Yp", "Edit")
this.ButtonForEditingInfo.Opt("Hidden1")

this.ButtonForDeletingInfo := this.Add("Button", "Yp", "Delete")
this.ButtonForDeletingInfo.Opt("Hidden1")


this.hotkeysListView.AddEventAction("ItemSelect", (listView, rowSelected, ColumnSelected) => this.ChangeConfigurationButtonsStatus(rowSelected))
keyboardLayoutChanger.AddEventAction("ItemSelect", (*) => this.controller.DoLayerSelected(keyboardLayoutChanger.GetSelectionText()))
this.hotkeysListView.AddEventAction("DoubleClick", (listView, rowClicked) => this.controller.DoAddOrEditHotkey(listView.GetText(rowClicked, 1)))

}

UpdateConfigurationButtons(){
this.DisableConfigurationButtons()

if (this.controller.GetCurrentLayer() == ""){
this.ButtonForAddingInfo.Opt("Hidden1")
this.ButtonForEditingInfo.Opt("Hidden1")
this.ButtonForDeletingInfo.Opt("Hidden1")
}
else {
this.ButtonForAddingInfo.Opt("Hidden0")
this.ButtonForEditingInfo.Opt("Hidden0")
this.ButtonForDeletingInfo.Opt("Hidden0")
}
}

ChangeConfigurationButtonsStatus(rowFocused){
if (rowFocused = 0){
this.DisableConfigurationButtons()
}
else{
this.EnableConfigurationButtons()
}
}

EnableConfigurationButtons(){
this.ButtonForEditingInfo.Enabled := true
this.ButtonForDeletingInfo.Enabled := true
}

DisableConfigurationButtons(){
this.ButtonForEditingInfo.Enabled := false
this.ButtonForDeletingInfo.Enabled := false
}

UpdateHotkeys(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ class HotKeyConfigurationView extends DomainSpecificGui{
}

createChangeButtons(){
buttonToChangeOriginalHotkey := this.AddButton("Default w100 xm", "Change Hotkey")
buttonToChangeOriginalHotkey := this.Add("Button", "Default w100 xm", "Change Hotkey")
buttonToChangeOriginalHotkey.onEvent("Click", (*) => this.controller.changeHotkey("Hotkey"))

buttonToChangeOriginalAction := this.AddButton("Default w100", "Change Action")
buttonToChangeOriginalAction := this.Add("Button", "Default w100", "Change Action")
buttonToChangeOriginalAction.onEvent("Click", (*) => this.controller.changeHotkey("Action"))
}

createFinalizationButtons(){
saveButton := this.AddButton("Default w100", "Save+Done")
saveButton := this.Add("Button", "Default w100", "Save+Done")
saveButton.onEvent("Click", (*) => this.controller.NotifyListenersSave())
cancelButton := this.AddButton("Default w100", "Cancel+Done")
cancelButton := this.Add("Button", "Default w100", "Cancel+Done")
cancelButton.onEvent("Click", (*) => this.Destroy())
deleteButton := this.AddButton("Default w100", "Delete+Done")
deleteButton := this.Add("Button", "Default w100", "Delete+Done")
deleteButton.onEvent("Click", (*) => this.controller.NotifyListenersDelete())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
class ProfileRegionController{

view := ""

editView := ""


addprofileView := ""

; Used to manage the preset user profiles, the user is only allowed to add a preset profile as a new profile
PresetProfilesManager := ""
; Used to manage the existing user profiles, the user is allowed to edit, delete, and add new profiles
ExistingProfilesManager := ""


__New(view){
this.view := view
Expand Down Expand Up @@ -124,64 +120,78 @@ class ProfileRegionController{
}

doAddProfile(profileToAdd, profileName){
; Guard condition
if (this.ExistingProfilesManager.hasFolder(profileName)){
msgbox("Failed to add profile. A profile with the given name already exists")
return
}
else{
try{
profilePath := this.PresetProfilesManager.getFolderPathByName(profileToAdd)
this.ExistingProfilesManager.CopyFolderToNewLocation(profilePath, FilePaths.GetPathToProfiles() . "/" . profileName, profileName)
this.view.UpdateProfilesDropDownMenu()
this.addprofileView.Destroy()
msgbox("Successfully added profile " . profileName)
}
catch{
msgbox("Failed to add profile, perhaps a profile with the given name already exists")
}
try{
profilePath := this.PresetProfilesManager.getFolderPathByName(profileToAdd)
this.ExistingProfilesManager.CopyFolderToNewLocation(profilePath, FilePaths.GetPathToProfiles() . "/" . profileName, profileName)
this.view.UpdateProfilesDropDownMenu()
this.addprofileView.Destroy()
msgbox("Successfully added profile " . profileName)
}
catch{
msgbox("Failed to add profile, perhaps a profile with the given name already exists")
}
}

; TODO this methods is way too long..
doImportProfile(){

; TODO check if the profile already exists
; TODO check if the profile has a keyboards.json and ClassObjects.ini file.
selectedFilePath := FileSelect("D", , "Choose a location to save profile",)
; Guard condition
if selectedFilePath = ""{
; Canceled
return
}
else{
try{
filesFoundWhichShouldBeFound := 0
amountOfFilesToFind := 2
Loop Files (selectedFilePath . "\*"){
subFolderName := A_LoopFileName
if (subFolderName = "keyboards.json" || subFolderName = "ClassObjects.ini"){
filesFoundWhichShouldBeFound++
}
amountOfFilesToFind -= 1
if (amountOfFilesToFind = 0){
break
}
}
if (filesFoundWhichShouldBeFound := 2){
parts := StrSplit(selectedFilePath, "\")
folderName := parts[parts.length]
if (this.ExistingProfilesManager.CopyFolderToNewLocation(selectedFilePath, FilePaths.GetPathToProfiles() . "/" . folderName, folderName)){
msgbox("Successfully imported profile " . folderName)
this.view.UpdateProfilesDropDownMenu()
}
else{
msgbox("Failed to import profile, perhaps a profile with the given name already exists")
}
}
else{
msgbox("The folder you selected is not a valid profile.")
}
if (!this.profileIsValid(selectedFilePath)){
msgbox("The folder you selected is not a valid profile.")
return
}
try{
folderName := this.getEndOfPath(selectedFilePath)
if (this.ExistingProfilesManager.CopyFolderToNewLocation(selectedFilePath, FilePaths.GetPathToProfiles() . "/" . folderName, folderName)){
msgbox("Successfully imported profile " . folderName)
this.view.UpdateProfilesDropDownMenu()
}
catch Error as e{
MsgBox("Failed to import rofile")
else{
msgbox("Failed to import profile, perhaps a profile with the given name already exists")
}
}
catch Error as e{
MsgBox("Failed to import profile")
}
}

; TODO create a helper class for this
getEndOfPath(path){
parts := StrSplit(path, "\")
return parts[parts.length]
}

; TODO create a helper class for this
profileIsValid(profilePath){
validProfile := false
filesToBeFound := 2
amountOfFilesToLookFor := 2
Loop Files (profilePath . "\*"){
subFolderName := A_LoopFileName
if (subFolderName = "Keyboards.json" || subFolderName = "ClassObjects.ini"){
filesToBeFound--
}
amountOfFilesToLookFor -= 1
if (amountOfFilesToLookFor = -1){
break
}
}
if (filesToBeFound = 0 && amountOfFilesToLookFor != -1){
validProfile := true
}
else{
validProfile := false
}
return validProfile
}

doExportProfile(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ProfileRegionView{

guiHwnd := ""

editProfilesButton := ""

CreateView(guiObject, controller){

this.controller := controller
Expand All @@ -24,20 +26,18 @@ class ProfileRegionView{

this.profilesDropDownMenu.OnEvent("Change", (*) => this.NotifyListenersProfileChanged(this.profilesDropDownMenu.Text))


editProfilesButton := guiObject.Add("Button", "Default w80 ym+1", "Edit profiles")
addProfileButton := guiObject.Add("Button", "Default w80 ym+1", "Add profile")
importProfileButton := guiObject.Add("Button", "Default w80 ym+1", "Import profile")
exportProfileButton := guiObject.Add("Button", "Default w80 ym+1", "Export profile")
this.editProfilesButton := guiObject.Add("Button", "Default w80 ym+1", "&Edit profiles")
addProfileButton := guiObject.Add("Button", "Default w80 ym+1", "&Add profile")
importProfileButton := guiObject.Add("Button", "Default w80 ym+1", "&Import profile")
exportProfileButton := guiObject.Add("Button", "Default w80 ym+1", "E&xport profile")


editProfilesButton.OnEvent("Click", (*) => ObjBindMethod(controller, "doOpenEditProfileView")())
this.editProfilesButton.OnEvent("Click", (*) => ObjBindMethod(controller, "doOpenEditProfileView")())
addProfileButton.OnEvent("Click", (*) => ObjBindMethod(controller, "doOpenAddProfileDialog")())
importProfileButton.OnEvent("Click", (*) => ObjBindMethod(controller, "doImportProfile")())
exportProfileButton.OnEvent("Click", (*) => ObjBindMethod(controller, "doExportProfile")())

this.guiHwnd := guiObject.GetHwnd()

guiObject.Show()
}

Expand Down Expand Up @@ -78,9 +78,16 @@ class ProfileRegionView{
profilesDropDownMenu := guiObject.Add("DropDownList", "ym+1 Choose" . profileIndex, profiles)
}

; profilesDropDownMenu.OnEvent("Focus", (*) => this.unFocusDropDownMenu(profilesDropDownMenu))

return profilesDropDownMenu
}

unFocusDropDownMenu(dropDownMenu){
; This avoid focusing the dropdown, which is really irritating
this.editProfilesButton.Focus()
}

GetHwnd(){
return this.guiHwnd
}
Expand Down
Loading

0 comments on commit d48e887

Please sign in to comment.