📄 albumspane.cs
字号:
#region AdjustButtons
/// <summary>
/// adjusts the position and the visibility of the up&down buttons
/// </summary>
private void AdjustButtons() {
if (SelAlbum != null) {
try {
// show and position the buttons
bUp.Top = tvAlbums.SelectedNode.Bounds.Top + bUp.Height;
if (bUp.Top < paneTitle.Height)
bUp.Top = paneTitle.Height + 1;
bUp.Left = tvAlbums.Width - bUp.Width * 2 - 4;
bDown.Top = bUp.Top + bUp.Height;
bDown.Left = bUp.Left;
bUp.Show();
bDown.Show();
}
catch {
bUp.Hide();
bDown.Hide();
}
} else {
bUp.Hide();
bDown.Hide();
}
}
#endregion
#region MoveNode
/// <summary>
/// moves the currently selected node (and the albums associated with it) up one pos
/// </summary>
private void MoveUp() {
if (SelAlbum != null) {
TreeNodeCollection parentNodes;
TreeNode parent = null;
bool isExpanded = tvAlbums.SelectedNode.IsExpanded;
if (tvAlbums.SelectedNode.Parent != null) {
parentNodes = tvAlbums.SelectedNode.Parent.Nodes;
parent = tvAlbums.SelectedNode.Parent;
} else
parentNodes = tvAlbums.Nodes;
if (parentNodes.Count > 1 && tvAlbums.SelectedNode.Index != 0) {
TreeNode newNode = (TreeNode) tvAlbums.SelectedNode.Clone();
parentNodes.Insert(tvAlbums.SelectedNode.Index - 1, newNode);
parentNodes.Remove(tvAlbums.SelectedNode);
tvAlbums.SelectedNode = newNode;
// apply expanded state
if (isExpanded == true)
newNode.Expand();
else
newNode.Collapse();
// save the changes to file
if (parent != null)
ParseNode(parent);
else
ParseNode(parentNodes);
}
}
}
/// <summary>
/// moves the currently selected node (and the albums associated with it) down one pos
/// </summary>
private void MoveDown() {
if (SelAlbum != null) {
TreeNodeCollection parentNodes;
TreeNode parent = null;
bool isExpanded = tvAlbums.SelectedNode.IsExpanded;
if (tvAlbums.SelectedNode.Parent != null) {
parentNodes = tvAlbums.SelectedNode.Parent.Nodes;
parent = tvAlbums.SelectedNode.Parent;
} else
parentNodes = tvAlbums.Nodes;
if (parentNodes.Count > 1 && tvAlbums.SelectedNode.Index < parentNodes.Count - 1) {
TreeNode newNode = (TreeNode) tvAlbums.SelectedNode.Clone();
parentNodes.Insert(tvAlbums.SelectedNode.Index + 2, newNode);
parentNodes.Remove(tvAlbums.SelectedNode);
tvAlbums.SelectedNode = newNode;
// apply expanded state
if (isExpanded == true)
newNode.Expand();
else
newNode.Collapse();
// save the changes to file
if (parent != null)
ParseNode(parent);
else
ParseNode(parentNodes);
}
}
}
#endregion
#region helper methods
/// <summary>
/// loads the component's strings from the language file
/// </summary>
public void LoadStrings() {
// local language strings
string LsPaneText;
string LsAddAlbum;
string LsAddPhotos;
string LsFiles;
string LsFolder;
string LsRen;
string LsDel;
string lsProp;
string lsExpAll;
string lsColAll;
string lsUp;
string lsDown;
const string ALBUMSPANE = "AlbumsPane"; // the master node which we're looking for in the lang file
// default language strings
const string LCPANETEXT = "Albums";
const string LCADDALBUM = "Add Album...";
const string LCADDPHOTOS = "Add Photos";
const string LCFILES = "From File...";
const string LCFOLDER = "From Folder...";
const string LCREN = "Rename";
const string LCDEL = "Delete";
const string LCWARNING = "Warning";
const string LCCONFIRMDEL = "This will delete the album, all its subalbums, and all photos within the album and its subalbums, proceed?";
const string LCPROP = "Properties";
const string LCPHOTOS = "Photos";
const string LCEXPALL = "Expand all";
const string LCCOLALL = "Collapse all";
const string LCUP = "Move up";
const string LCDOWN = "Move down";
try {
// read the strings from file
TXmlReader reader = XmlHandler.OpenLangFile();
LsPaneText = reader.GetString(ALBUMSPANE, "PaneText", LCPANETEXT);
LsAddAlbum = reader.GetString(ALBUMSPANE, "AddAlbum", LCADDALBUM);
LsAddPhotos = reader.GetString(ALBUMSPANE, "AddPhotos", LCADDPHOTOS);
LsFiles = reader.GetString(ALBUMSPANE, "File", LCFILES);
LsFolder = reader.GetString(ALBUMSPANE, "Folder", LCFOLDER);
LsRen = reader.GetString(ALBUMSPANE, "Rename", LCREN);
LsDel = reader.GetString(ALBUMSPANE, "Delete", LCDEL);
LsWarning = reader.GetString(ALBUMSPANE, "Warning", LCWARNING);
LsConfirmDel = reader.GetString(ALBUMSPANE, "ConfirmDel", LCCONFIRMDEL);
lsProp = reader.GetString(ALBUMSPANE, "Properties", LCPROP);
LsPhotos = reader.GetString(ALBUMSPANE, "Photos", LCPHOTOS);
lsExpAll = reader.GetString(ALBUMSPANE, "ExpandAll", LCEXPALL);
lsColAll = reader.GetString(ALBUMSPANE, "CollapseAll", LCCOLALL);
lsUp = reader.GetString(ALBUMSPANE, "MoveUp", LCUP);
lsDown = reader.GetString(ALBUMSPANE, "MoveDown", LCDOWN);
reader.Close();
}
catch {
// if the language file cannot be found use the default values
//MessageBox.Show(e.Message + " (" + e.FileName + ")\nThus the default (English) values will be used", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
LsPaneText = LCPANETEXT;
LsAddAlbum = LCADDALBUM;
LsAddPhotos = LCADDPHOTOS;
LsFiles = LCFILES;
LsFolder = LCFOLDER;
LsRen = LCREN;
LsDel = LCDEL;
LsWarning = LCWARNING;
LsConfirmDel = LCCONFIRMDEL;
lsProp = LCPROP;
LsPhotos = LCPHOTOS;
lsExpAll = LCEXPALL;
lsColAll = LCCOLALL;
lsUp = LCUP;
lsDown = LCDOWN;
}
// assign the string to their controls
paneTitle.Text = LsPaneText;
miAddAlbum.Text = LsAddAlbum;
miAddPhotos.Text = LsAddPhotos;
miFiles.Text = LsFiles;
miFolder.Text = LsFolder;
miRen.Text = LsRen;
miDel.Text = LsDel;
miProp.Text = lsProp;
miExpAll.Text = lsExpAll;
miColAll.Text = lsColAll;
miUp.Text = lsUp;
miDown.Text = lsDown;
}
/// <summary>
/// adds each album in RAlbum to tvAlbums
/// </summary>
private void ParseRootAlbum() {
// prevent tvAlbums from redrawing itself
tvAlbums.BeginUpdate();
tvAlbums.Nodes.Clear();
TreeNode node;
foreach (Album a in RAlbum.Albums) {
node = new TreeNode(a.AlbumName);
node.Tag = a;
ParseSubAlbums(a, node);
tvAlbums.Nodes.Add(node);
}
// redraw tvAlbums
tvAlbums.EndUpdate();
}
/// <summary>
/// parses an album's subalbums and adds them to the specified treeNode
/// </summary>
private void ParseSubAlbums(Album album, TreeNode tn) {
TreeNode node;
foreach (Album a in album.SubAlbums) {
node = new TreeNode(a.AlbumName);
node.Tag = a;
tn.Nodes.Add(node);
ParseSubAlbums(a, node);
}
}
/// <summary>
/// Removes the filename from a given path and returns only the directories
/// </summary>
private static string GetDirectoryFromFilePath(string path) {
int i = 0;
for (i = path.Length - 1; i > 0; i--) {
if (path[i] == '\\')
break;
}
if (i != 0)
return path.Substring(0, i);
else
return Directory.GetCurrentDirectory();
}
private void FireOpenAlbum() {
try {
Album a = (Album) tvAlbums.SelectedNode.Tag;
OpenAlbum(a);
}
catch { }
}
/// <summary>
/// used to specify whether the quick album info shall be shown or not
/// </summary>
public void UpdateToolTipState(bool active) {
timerToolTip.Enabled = active;
ttAlbInfo.Active = active;
}
#endregion
#region Vom Komponenten-Designer generierter Code
/// <summary>
/// Erforderliche Methode f黵 die Designerunterst黷zung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor ge鋘dert werden.
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AlbumsPane));
this.tvAlbums = new System.Windows.Forms.TreeView();
this.contMenu = new System.Windows.Forms.ContextMenu();
this.miAddAlbum = new System.Windows.Forms.MenuItem();
this.miAddPhotos = new System.Windows.Forms.MenuItem();
this.miFiles = new System.Windows.Forms.MenuItem();
this.miFolder = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.miUp = new System.Windows.Forms.MenuItem();
this.miDown = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.miExpAll = new System.Windows.Forms.MenuItem();
this.miColAll = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.miDel = new System.Windows.Forms.MenuItem();
this.miRen = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.miProp = new System.Windows.Forms.MenuItem();
this.chAlbumN = new System.Windows.Forms.ColumnHeader();
this.chPhotos = new System.Windows.Forms.ColumnHeader();
this.paneTitle = new VirtualPhotoOrganizer.Controls.PaneTitle();
this.ttAlbInfo = new System.Windows.Forms.ToolTip(this.components);
this.timerToolTip = new System.Windows.Forms.Timer(this.components);
this.bUp = new System.Windows.Forms.Button();
this.ilButtons = new System.Windows.Forms.ImageList(this.components);
this.bDown = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// tvAlbums
//
this.tvAlbums.AllowDrop = true;
this.tvAlbums.ContextMenu = this.contMenu;
this.tvAlbums.Cursor = System.Windows.Forms.Cursors.Default;
this.tvAlbums.HideSelection = false;
this.tvAlbums.HotTracking = true;
this.tvAlbums.ImageIndex = -1;
this.tvAlbums.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.tvAlbums.LabelEdit = true;
this.tvAlbums.Location = new System.Drawing.Point(0, 20);
this.tvAlbums.Name = "tvAlbums";
this.tvAlbums.SelectedImageIndex = -1;
this.tvAlbums.Size = new System.Drawing.Size(208, 332);
this.tvAlbums.TabIndex = 0;
this.tvAlbums.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tvAlbums_KeyDown);
this.tvAlbums.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tvAlbums_MouseDown);
this.tvAlbums.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.tvAlbums_AfterExpand);
this.tvAlbums.AfterCollapse += new System.Windows.Forms.TreeViewEventHandler(this.tvAlbums_AfterCollapse);
this.tvAlbums.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tvAlbums_MouseUp);
this.tvAlbums.DragOver += new System.Windows.Forms.DragEventHandler(this.tvAlbums_DragOver);
this.tvAlbums.DoubleClick += new System.EventHandler(this.tvAlbums_DoubleClick);
this.tvAlbums.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvAlbums_AfterSelect);
this.tvAlbums.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.tvAlbums_AfterLabelEdit);
this.tvAlbums.DragEnter += new System.Windows.Forms.DragEventHandler(this.tvAlbums_DragEnter);
this.tvAlbums.MouseMove += new System.Windows.Forms.MouseEventHandler(this.tvAlbums_MouseMove);
this.tvAlbums.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.tvAlbums_ItemDrag);
this.tvAlbums.BeforeLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.tvAlbums_BeforeLabelEdit);
this.tvAlbums.DragDrop += new System.Windows.Forms.DragEventHandler(this.tvAlbums_DragDrop);
//
// contMenu
//
this.contMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miAddAlbum,
this.miAddPhotos,
this.menuItem5,
this.miUp,
this.miDown,
this.menuItem6,
this.miExpAll,
this.miColAll,
this.menuItem4,
this.miDel,
this.miRen,
this.menuItem1,
this.miProp});
this.contMenu.Popup += new System.EventHandler(this.contMenu_Popup);
//
// miAddAlbum
//
this.miAddAlbum.Index = 0;
this.miAddAlbum.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.miAddAlbum.Text = "添加相册";
this.miAddAlbum.Click += new System.EventHandler(this.miAddAlbum_Click);
//
// miAddPhotos
//
this.miAddPhotos.Index = 1;
this.miAddPhotos.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miFiles,
this.miFolder});
this.miAddPhotos.Text = "添加图片";
//
// miFiles
//
this.miFiles.Index = 0;
this.miFiles.Text = "从文件";
this.miFiles.Click += new System.EventHandler(this.miFiles_Click);
//
// miFolder
//
this.miFolder.Index = 1;
this.miFolder.Text = "从目录";
this.miFolder.Click += new System.EventHandler(this.miFolder_Click);
//
// menuItem5
//
this.menuItem5.Index = 2;
this.menuItem5.Text = "-";
//
// miUp
//
this.miUp.Index = 3;
this.miUp.Shortcut = System.Windows.Forms.Shortcut.CtrlU;
this.miUp.Text = "上移";
this.miUp.Click += new System.EventHandler(this.miUp_Click);
//
// miDown
//
this.miDown.Index = 4;
this.miDown.Shortcut = System.Windows.Forms.Shortcut.CtrlD;
this.miDown.Text = "下移";
this.miDown.Click += new System.EventHandler(this.miDown_Click);
//
// menuItem6
//
this.menuItem6.Index = 5;
this.menuItem6.Text = "-";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -