// 新目录 private void button_newDir_Click(object sender, System.EventArgs e) { // 当前所在路径 string strDirPath = ""; TreeNode parent = null; int nPrefixNumber = 1; // 当前已选择的node if (treeView1.SelectedNode == null) { strDirPath = ""; } else { // project下不能创建子节点,但是可以创建兄弟? if (treeView1.SelectedNode.ImageIndex == 0) parent = treeView1.SelectedNode; else parent = treeView1.SelectedNode.Parent; strDirPath = parent != null ? parent.FullPath : ""; } string strTempName = GetTempDirName(treeView1, parent, "new dir", ref nPrefixNumber); DirNameDlg namedlg = new DirNameDlg(); GuiUtil.AutoSetDefaultFont(namedlg); namedlg.textBox_dirName.Text = strTempName; namedlg.StartPosition = FormStartPosition.CenterScreen; namedlg.ShowDialog(this); if (namedlg.DialogResult == DialogResult.OK) { string strDirNamePath = (strDirPath != "" ? strDirPath + "/" : "") + namedlg.textBox_dirName.Text; XmlNode dirNode = scriptManager.NewDirNode(strDirNamePath); if (dirNode != null) { scriptManager.Save(); // 兑现显示? scriptManager.FillOneLevel(treeView1, parent, dirNode.ParentNode); TreeViewUtil.SelectTreeNode(treeView1, scriptManager.GetNodePathName(dirNode), '/'); /* if (parent != null) parent.Expand(); */ } } }
private void button_changeProjectLocation_Click(object sender, System.EventArgs e) { DirNameDlg dlg = new DirNameDlg(); GuiUtil.AutoSetDefaultFont(dlg); DirectoryInfo di = new DirectoryInfo(textBox_projectLocate.Text); dlg.textBox_dirName.Text = di.Name; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) { return; } // 改名 string strNewLocation = di.Parent.FullName + "\\" + dlg.textBox_dirName.Text; if (di.Exists == true) { try { Directory.Move(textBox_projectLocate.Text, strNewLocation); } catch (IOException ex) { MessageBox.Show(this, ex.Message); return; } catch (Exception ex) { MessageBox.Show(this, ExceptionUtil.GetAutoText(ex)); return; } } // 方案名 + 路径 ResultProjectNamePath = textBox_projectPathOfName.Text; if (ResultProjectNamePath != "") { ResultProjectNamePath += "/"; } ResultProjectNamePath += textBox_projectName.Text; string strError; Debug.Assert(scriptManager != null, "调用本对话框以前,scriptManager指针应初始化..."); if (m_bNew == false) { int nRet = scriptManager.ChangeProjectData( ResultProjectNamePath, null, strNewLocation, out strError); if (nRet == -1) { MessageBox.Show(this, strError); return; } scriptManager.Save(); } textBox_projectLocate.Text = strNewLocation; // 重新装载文件名? LoadFileInfo(); }
// 修改方案 private void button_modify_Click(object sender, System.EventArgs e) { int nRet; // 当前已选择的node if (treeView1.SelectedNode == null) { MessageBox.Show(this, "尚未选择方案或者目录"); return; } TreeNode node = treeView1.SelectedNode; if (node.ImageIndex == 0) { // 修改目录名 DirNameDlg namedlg = new DirNameDlg(); GuiUtil.AutoSetDefaultFont(namedlg); namedlg.textBox_dirName.Text = node.Text; namedlg.StartPosition = FormStartPosition.CenterScreen; namedlg.ShowDialog(this); if (namedlg.DialogResult == DialogResult.OK) { // return: // 0 not found // 1 found and changed nRet = scriptManager.RenameDir(node.FullPath, namedlg.textBox_dirName.Text); if (nRet == 1) { node.Text = namedlg.textBox_dirName.Text; // 兑现视觉 scriptManager.Save(); } } return; } string strProjectNamePath = node.FullPath; string strLocate = ""; // 获得方案参数 // strProjectNamePath 方案名,或者路径 // return: // -1 error // 0 not found project // 1 found nRet = scriptManager.GetProjectData( strProjectNamePath, out strLocate); if (nRet != 1) { MessageBox.Show(this, "方案 " + strProjectNamePath + " 在ScriptManager中没有找到"); return; } OneProjectDialog dlg = new OneProjectDialog(); GuiUtil.AutoSetDefaultFont(dlg); dlg.HostName = this.HostName; dlg.scriptManager = scriptManager; dlg.Initial(strProjectNamePath, strLocate); dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult == DialogResult.OK) { if (dlg.ResultProjectNamePath != strProjectNamePath) { /* // 修改显示的Project名字 string strPath; string strName; ScriptManager.SplitProjectPathName(dlg.ResultProjectNamePath, out strPath, out strName); string strError; nRet = scriptManager.ChangeProjectData(strProjectNamePath, strName, null, out strError); if (nRet == -1) { MessageBox.Show(this, strError); } else { // 兑现显示? } */ // XML DOM已经在ScriptDlg中修改,这里只是兑现显示 string strPath; string strName; ScriptManager.SplitProjectPathName(dlg.ResultProjectNamePath, out strPath, out strName); node.Text = strName; } scriptManager.Save(); } }
private void button_changeProjectLocation_Click(object sender, System.EventArgs e) { DirNameDlg dlg = new DirNameDlg(); GuiUtil.AutoSetDefaultFont(dlg); DirectoryInfo di = new DirectoryInfo(textBox_projectLocate.Text); dlg.textBox_dirName.Text = di.Name; dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(this); if (dlg.DialogResult != DialogResult.OK) return; // 改名 string strNewLocation = di.Parent.FullName + "\\" + dlg.textBox_dirName.Text; if (di.Exists == true) { try { Directory.Move(textBox_projectLocate.Text, strNewLocation); } catch (IOException ex) { MessageBox.Show(this, ex.Message); return; } catch (Exception ex) { MessageBox.Show(this, ExceptionUtil.GetAutoText(ex)); return; } } // 方案名 + 路径 ResultProjectNamePath = textBox_projectPathOfName.Text; if (ResultProjectNamePath != "") ResultProjectNamePath += "/"; ResultProjectNamePath += textBox_projectName.Text; string strError; Debug.Assert(scriptManager != null, "调用本对话框以前,scriptManager指针应初始化..."); if (m_bNew == false) { int nRet = scriptManager.ChangeProjectData( ResultProjectNamePath, null, strNewLocation, out strError); if (nRet == -1) { MessageBox.Show(this, strError); return; } scriptManager.Save(); } textBox_projectLocate.Text = strNewLocation; // 重新装载文件名? LoadFileInfo(); }