Skip to content

Commit

Permalink
Merge pull request #30 from Osterie/dev
Browse files Browse the repository at this point in the history
Import and Export buttons work.
  • Loading branch information
Osterie authored Mar 29, 2024
2 parents c533b06 + 6c859a9 commit 310286a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EditorView extends DomainSpecificGui{
CreateDeleteProfileInputBox(){
profileToDelete := this.profilesToEditDropDownMenu.Text
inputPrompt := InputBox("Are you sure you want to delete the profile named '" . profileToDelete . "'? Deleted profiles cannot be resuscitated. Type yes to confirm", "Delete profile",, profileToDelete)
this.controller.HandleDeleteProfile(profileToDelete, inputPrompt)
this.controller.doDeleteProfile(profileToDelete, inputPrompt)
}

UpdateProfilesDropDownMenu(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ProfileRegionController{
}
}

HandleDeleteProfile(profileToDelete, inputPrompt){
DoDeleteProfile(profileToDelete, inputPrompt){
inputPromptResult := inputPrompt.Result


Expand All @@ -119,18 +119,18 @@ class ProfileRegionController{
doOpenAddProfileDialog(){
this.addprofileView := AddProfileDialog(this.GetHwnd())
this.addprofileView.CreateView(this.GetPresetProfiles())
this.addProfileView.SubscribeToProfileAddedEvent(ObjBindMethod(this, "HandleAddProfileConfirmedEvent"))
this.addProfileView.SubscribeToProfileAddedEvent(ObjBindMethod(this, "doAddProfile"))
this.addprofileView.Show()
}

HandleAddProfileConfirmedEvent(profileToAdd, profileName){
doAddProfile(profileToAdd, profileName){
if (this.ExistingProfilesManager.hasFolder(profileName)){
msgbox("Failed to add profile. A profile with the given name already exists")
}
else{
try{
profilePath := this.PresetProfilesManager.getFolderPathByName(profileToAdd)
this.ExistingProfilesManager.CopyFolderToNewLocation(profilePath, FilePaths.GetPathToProfiles() . "/" . profileName, profileName, profileName)
this.ExistingProfilesManager.CopyFolderToNewLocation(profilePath, FilePaths.GetPathToProfiles() . "/" . profileName, profileName)
this.view.UpdateProfilesDropDownMenu()
this.addprofileView.Destroy()
msgbox("Successfully added profile " . profileName)
Expand All @@ -141,6 +141,67 @@ class ProfileRegionController{
}
}

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",)
if selectedFilePath = ""{
; Canceled
}
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.")
}
}
catch Error as e{
MsgBox("Failed to import rofile")
}
}
}

doExportProfile(){
selectedFilePath := FileSelect("DS", , "Choose a location to save profile",)
if selectedFilePath = ""{
; Canceled
}
else{

try{
profileName := FilePaths.GetCurrentProfile()
profilePath := this.ExistingProfilesManager.getFolderPathByName(profileName)
DirCopy(profilePath, selectedFilePath . "/" . profileName)
}
catch Error as e{
MsgBox("Failed to export profile, perhaps because a folder of that name already exists in " . selectedFilePath)
}
}
}

UpdateProfileDropDownMenu(){
this.view.Delete()
this.view.Add(this.ExistingProfilesManager.getFolderNames())
Expand All @@ -150,164 +211,4 @@ class ProfileRegionController{
GetHwnd(){
return this.view.GetHwnd()
}
}



; ; 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 := ""
; ; A constant which is the path to the preset profiles

; ; TODO dont need these
; PATH_TO_EMPTY_PROFILE := ""
; PATH_TO_PRESET_PROFILES := ""
; PATH_TO_EXISTING_PROFILES := ""
; PATH_TO_META_FILE := ""
; currentProfile := ""
; ; Gui part
; profilesDropDownMenu := ""

; profiles := ""

; guiObject := ""


; __New(guiObject){

; this.guiObject := guiObject
; this.PATH_TO_META_FILE := FilePaths.GetPathToMetaFile()
; this.PATH_TO_EXISTING_PROFILES := FilePaths.GetPathToProfiles()
; this.PATH_TO_EMPTY_PROFILE := FilePaths.GetPathToEmptyProfile()
; this.PATH_TO_PRESET_PROFILES := FilePaths.GetPathToPresetProfiles()


; this.ExistingProfilesManager := FolderManager()
; this.PresetProfilesManager := FolderManager()

; this.PresetProfilesManager.addSubFoldersToRegistryFromFolder(this.PATH_TO_PRESET_PROFILES)
; this.PresetProfilesManager.addFolderToRegistry("EmptyProfile", this.PATH_TO_EMPTY_PROFILE)
; this.ExistingProfilesManager.addSubFoldersToRegistryFromFolder(this.PATH_TO_EXISTING_PROFILES)

; this.currentProfile := iniRead(this.PATH_TO_META_FILE, "General", "activeUserProfile")

; this.profiles := this.ExistingProfilesManager.getFolderNames()


; }

; updateProfiles(){
; this.profiles := this.ExistingProfilesManager.getFolderNames()
; }

; getGuiObject(){
; return this.guiObject
; }

; getProfiles(){
; return this.profiles
; }


; getCurrentProfileIndex(){
; currentProfileIndex := -1
; Loop this.profiles.Length{
; if (this.profiles[A_Index] = FilePaths.GetCurrentProfile()){
; currentProfileIndex := A_Index
; }
; }
; return currentProfileIndex
; }

; renameProfile(profileName, newProfileName){
; renamedSuccesfully := false

; if (this.ExistingProfilesManager.RenameFolder(profileName, newProfileName)){
; this.updateProfiles()
; if (profileName = this.currentProfile){
; this.setCurrentProfile(newProfileName)
; }

; renamedSuccesfully := true
; }
; else{
; msgbox("failed to change profile name, perhaps name already exists or illegal characters were used.")
; renamedSuccesfully := false
; }
; return renamedSuccesfully
; }

; DeleteProfile(profileToDelete){

; deletedProfile := false

; if (this.ExistingProfilesManager.DeleteFolder(profileToDelete)){
; ; Deleted profile succesfully
; this.updateProfiles()
; if (this.profiles.Length != 0){
; if (profileToDelete = this.currentProfile){
; this.setCurrentProfile(this.profiles[1])
; }
; }

; deletedProfile := true

; }
; else{
; deletedProfile := false
; }
; return deletedProfile
; }

; AddProfile(profile, profileName){
; profileAdded := false
; if (this.hasProfile(profileName)){
; profileAdded := false
; }
; else{
; try{
; presetProfileName := profileName
; profilePath := this.PresetProfilesManager.getFolderPathByName(profile)
; this.ExistingProfilesManager.CopyFolderToNewLocation(profilePath, this.PATH_TO_EXISTING_PROFILES . "\" . profileName, profileName, profileName)
; profileAdded := true
; this.updateProfiles()
; }
; catch{
; profileAdded := false
; }
; }
; return profileAdded
; }

; getCurrentProfile(){
; return this.currentProfile
; }


; hasProfile(profileName){
; hasProfile := false
; Loop this.profiles.Length{
; if (this.profiles[A_Index] = profileName){
; hasProfile := true
; }
; }
; return hasProfile
; }

; UpdateProfileDropDownMenu(guiObject){
; guiObject.Delete()
; guiObject.Add(this.ExistingProfilesManager.getFolderNames())
; guiObject.Choose(this.currentProfile)
; }



; ; ProfileChangedFromDropDownMenuEvent(profilesDropDownMenu){
; ; iniWrite(profilesDropDownMenu.Text, this.PATH_TO_META_FILE, "General", "activeUserProfile")
; ; }




; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ProfileRegionView{

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

this.guiHwnd := guiObject.GetHwnd()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FilePaths{
static KEY_NAMES := "../../resources/keyNames.txt"

static PATH_TO_PRESET_PROFILES := "../../config/PresetProfiles"
static PATH_TO_PROFILES := "../../config/UserProfiles/"
static PATH_TO_PROFILES := "../../config/UserProfiles"

static PATH_TO_EMPTY_PROFILE := "../../config/PresetProfiles/EmptyProfile"
static PATH_TO_EMPTY_KEYBOARD_PROFILE := "../../config/PresetProfiles/EmptyProfile/Keyboards.json"
Expand Down Expand Up @@ -45,10 +45,10 @@ class FilePaths{
this.CURRENT_PROFILE := this.DEFAULT_PROFILE
}
finally{
if (FileExist(this.PATH_TO_PROFILES . this.CURRENT_PROFILE)){
if (FileExist(this.PATH_TO_PROFILES . "/" . this.CURRENT_PROFILE)){
; do nothing
}
else if (!FileExist(this.PATH_TO_PROFILES . this.CURRENT_PROFILE)){
else if (!FileExist(this.PATH_TO_PROFILES . "/" . this.CURRENT_PROFILE)){
this.CURRENT_PROFILE := this.DEFAULT_PROFILE
}
else{
Expand All @@ -60,7 +60,7 @@ class FilePaths{
}

static GetPathToCurrentProfile(){
PATH_TO_CURRENT_PROFILE := this.getPathToProfiles() . this.GetCurrentProfile()
PATH_TO_CURRENT_PROFILE := this.getPathToProfiles() . "/" . this.GetCurrentProfile()
if (!FileExist(PATH_TO_CURRENT_PROFILE)){
PATH_TO_CURRENT_PROFILE := this.GetPathToEmptyProfile()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class FolderManager{
; Todo implement
; }

CopyFolderToNewLocation(fromFolderPath, toFolderPath, oldFolderName, newFolderName){
CopyFolderToNewLocation(fromFolderPath, toFolderPath, newFolderName){

copiedFolder := false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Class FolderRegistry{
addSubFoldersFromFolder(folderPath){
Loop Files folderPath . "\*", "D"{
subFolderName := A_LoopFileName
this.addFolder(subFolderName, folderPath . "\" . subFolderName)
this.addFolder(subFolderName, folderPath . "/" . subFolderName)
}
}

Expand Down

0 comments on commit 310286a

Please sign in to comment.