Skip to content

Commit

Permalink
[UI] prevent error while editing without selecting a valid item
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Nov 4, 2020
1 parent 5f3c36c commit 8eb35c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NaiveSharp/ConstText/Msg.cs
Expand Up @@ -7,5 +7,7 @@ public static class Msg
public const string TIP_TITLE = "Naive# Tip";

public const string ASK_CHANGES_NEED_APP_RESTART = "Reopening Naive# is required to apply changes.\nDo you want to reopen Naive# immediately?";

public const string CHOOSE_NULL_ITEM = "Please choose a valid item through left list control!";
}
}
21 changes: 21 additions & 0 deletions NaiveSharp/View/MainWindow.cs
Expand Up @@ -220,26 +220,47 @@ private void txtName_TextChanged(object sender, EventArgs e)
}
}
*/
if (CheckIsSelectNodeNull())
return;

tvwNodeList.SelectedNode.Name = tvwNodeList.SelectedNode.Text = txtName.Text;
Config.Name = txtName.Text;
SyncToTag();
}

private bool CheckIsSelectNodeNull()
{
if (tvwNodeList.SelectedNode is null)
{
MessageBox.Show(Msg.CHOOSE_NULL_ITEM, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return true;
}
return false;
}

private void txtUsername_TextChanged(object sender, EventArgs e)
{
if (CheckIsSelectNodeNull())
return;

Config.Username = txtUsername.Text;
SyncToTag();
}

private void txtPassword_TextChanged(object sender, EventArgs e)
{
if (CheckIsSelectNodeNull())
return;

Config.Password = txtPassword.Text;
SyncToTag();
}

private void txtHost_TextChanged(object sender, EventArgs e)
{
if (CheckIsSelectNodeNull())
return;

Config.Host = txtHost.Text;
SyncToTag();
}
Expand Down

0 comments on commit 8eb35c8

Please sign in to comment.