1 using System;
  2 using System.Collections;
  3 using System.Windows;
  4 
  5 namespace FileExplorer
  6 {
  7     public abstract class Node
  8     {
  9         public nothrow Node(const string& name_) : 
 10             name(name_)parent(null)treeViewNode(null)listViewItem(null)
 11         {
 12         }
 13         public virtual default ~Node();
 14         public inline nothrow const string& Name() const
 15         {
 16             return name;
 17         }
 18         public inline nothrow Node* Parent() const
 19         {
 20             return parent;
 21         }
 22         public nothrow void SetParent(Node* parent_)
 23         {
 24             parent = parent_;
 25         }
 26         public virtual nothrow bool IsRootDirectory() const
 27         {
 28             return false;
 29         }
 30         public virtual nothrow MainWindow* GetMainWindow() const
 31         {
 32             if (parent != null)
 33             {
 34                 return parent->GetMainWindow();
 35             }
 36             else
 37             {
 38                 return null;
 39             }
 40         }
 41         public inline nothrow TreeViewNode* GetTreeViewNode() const
 42         {
 43             return treeViewNode;
 44         }
 45         public nothrow void SetTreeViewNode(TreeViewNode* treeViewNode_)
 46         {
 47             treeViewNode = treeViewNode_;
 48             treeViewNode->SetData(this);
 49             TreeView* treeView = treeViewNode->GetTreeView();
 50             if (treeView != null)
 51             {
 52                 ImageList* imageList = treeView->GetImageList();
 53                 if (imageList != null)
 54                 {
 55                     int imageIndex = imageList->GetImageIndex(ImageName());
 56                     if (imageIndex != -1)
 57                     {
 58                         treeViewNode->SetImageIndex(imageIndex);
 59                     }
 60                 }
 61             }
 62         }
 63         public virtual nothrow TreeViewNode* ToTreeViewNode(bool createChildrenImageList* imageList)
 64         {
 65             return null;
 66         }
 67         public abstract nothrow string ImageName() const;
 68         public virtual nothrow string ExpandedImageName() const
 69         {
 70             return ImageName();
 71         }
 72         public virtual Control* CreateView(ImageList* imageList)
 73         {
 74             return null;
 75         }
 76         public virtual nothrow string DirectoryPath()
 77         {
 78             return string();
 79         }
 80         public virtual nothrow bool CanOpen() const
 81         {
 82             return true;
 83         }
 84         public void AddMenuItems(ContextMenu* contextMenubool treeView)
 85         {
 86             if (CanOpen())
 87             {
 88                 ClickAction* action = null;
 89                 UniquePtr<MenuItem> openMenuItem(new MenuItem("Open"));
 90                 if (treeView)
 91                 {
 92                     action = new OpenAndExpandAction(this);
 93                 }
 94                 else
 95                 {
 96                     action = new OpenAction(this);
 97                 }
 98                 contextMenu->AddMenuItemAction(openMenuItem.Release()action);
 99             }
100         }
101         public virtual nothrow void SetData(ListViewItem* itemImageList* imageList)
102         {
103             listViewItem = item;
104             item->SetData(this);
105             item->SetColumnValue(0Name());
106             string imageName = ImageName();
107             if (!imageName.IsEmpty())
108             {
109                 item->SetImageIndex(imageList->GetImageIndex(imageName));
110             }
111         }
112         public void Open()
113         {
114             Explore();
115             ViewContent();
116             SetCurrentPathNode();
117         }
118         public void OpenAndExpand()
119         {
120             Open();
121             TreeViewNode* treeViewNode = GetTreeViewNode();
122             if (treeViewNode != null && !treeViewNode->Children().IsEmpty())
123             {
124                 treeViewNode->Expand();
125             }
126         }
127         public void ExecuteDefaultAction()
128         {
129             if (CanOpen())
130             {
131                 Open();
132             }
133         }
134         private void Explore()
135         {
136             MainWindow* mainWindow = GetMainWindow();
137             if (mainWindow != null)
138             {
139                 DirectoryTreeView* directoryTreeView = mainWindow->GetDirectoryTreeView();
140                 if (directoryTreeView != null)
141                 {
142                     directoryTreeView->Open(this);
143                 }
144             }
145         }
146         private void ViewContent()
147         {
148             MainWindow* mainWindow = GetMainWindow();
149             if (mainWindow != null)
150             {
151                 ContentView* contentView = mainWindow->GetContentView();
152                 if (contentView != null)
153                 {
154                     contentView->ViewContent(this);
155                 }
156             }
157         }
158         public void SetCurrentPathNode()
159         {
160             MainWindow* mainWindow = GetMainWindow();
161             if (mainWindow != null)
162             {
163                 PathBar* pathBar = mainWindow->GetPathBar();
164                 if (pathBar != null)
165                 {
166                     pathBar->SetCurrentNode(this);
167                 }
168             }
169         }
170         private string name;
171         private Node* parent;
172         private TreeViewNode* treeViewNode;
173         private ListViewItem* listViewItem;
174     }
175 }
176