| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef APP_TREE_NODE_MODEL_H_ | 5 #ifndef APP_TREE_NODE_MODEL_H_ |
| 6 #define APP_TREE_NODE_MODEL_H_ | 6 #define APP_TREE_NODE_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 int IndexOfChild(const NodeType* node) const { | 150 int IndexOfChild(const NodeType* node) const { |
| 151 DCHECK(node); | 151 DCHECK(node); |
| 152 typename std::vector<NodeType*>::const_iterator i = | 152 typename std::vector<NodeType*>::const_iterator i = |
| 153 std::find(children_->begin(), children_->end(), node); | 153 std::find(children_->begin(), children_->end(), node); |
| 154 if (i != children_->end()) | 154 if (i != children_->end()) |
| 155 return static_cast<int>(i - children_->begin()); | 155 return static_cast<int>(i - children_->begin()); |
| 156 return -1; | 156 return -1; |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Sets the title of the node. | 159 // Sets the title of the node. |
| 160 // TODO(munjal): Remove wstring overload once all code is moved to string16. | |
| 161 #if !defined(WCHAR_T_IS_UTF16) | |
| 162 void SetTitle(const std::wstring& string) { | |
| 163 title_ = WideToUTF16(string); | |
| 164 } | |
| 165 #endif | |
| 166 void SetTitle(const string16& string) { | 160 void SetTitle(const string16& string) { |
| 167 title_ = string; | 161 title_ = string; |
| 168 } | 162 } |
| 169 | 163 |
| 170 // TODO(munjal): Remove wstring version and rename GetTitleAsString16 to | 164 // TODO(munjal): Remove wstring version and rename GetTitleAsString16 to |
| 171 // GetTitle once all code is moved to string16. | 165 // GetTitle once all code is moved to string16. |
| 172 // Returns the title of the node. | 166 // Returns the title of the node. |
| 173 virtual std::wstring GetTitle() const { | 167 virtual std::wstring GetTitle() const { |
| 174 return UTF16ToWide(title_); | 168 return UTF16ToWide(title_); |
| 175 } | 169 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 268 } |
| 275 | 269 |
| 276 NodeType* AsNode(TreeModelNode* model_node) { | 270 NodeType* AsNode(TreeModelNode* model_node) { |
| 277 return static_cast<NodeType*>(model_node); | 271 return static_cast<NodeType*>(model_node); |
| 278 } | 272 } |
| 279 | 273 |
| 280 // Sets the title of the specified node. | 274 // Sets the title of the specified node. |
| 281 virtual void SetTitle(TreeModelNode* node, | 275 virtual void SetTitle(TreeModelNode* node, |
| 282 const std::wstring& title) { | 276 const std::wstring& title) { |
| 283 DCHECK(node); | 277 DCHECK(node); |
| 284 AsNode(node)->SetTitle(title); | 278 AsNode(node)->SetTitle(WideToUTF16Hack(title)); |
| 285 NotifyObserverTreeNodeChanged(node); | 279 NotifyObserverTreeNodeChanged(node); |
| 286 } | 280 } |
| 287 | 281 |
| 288 void Add(NodeType* parent, int index, NodeType* child) { | 282 void Add(NodeType* parent, int index, NodeType* child) { |
| 289 DCHECK(parent && child); | 283 DCHECK(parent && child); |
| 290 parent->Add(index, child); | 284 parent->Add(index, child); |
| 291 NotifyObserverTreeNodesAdded(parent, index, 1); | 285 NotifyObserverTreeNodesAdded(parent, index, 1); |
| 292 } | 286 } |
| 293 | 287 |
| 294 NodeType* Remove(NodeType* parent, int index) { | 288 NodeType* Remove(NodeType* parent, int index) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 322 private: | 316 private: |
| 323 // The observers. | 317 // The observers. |
| 324 ObserverList<TreeModelObserver> observer_list_; | 318 ObserverList<TreeModelObserver> observer_list_; |
| 325 // The root. | 319 // The root. |
| 326 scoped_ptr<NodeType> root_; | 320 scoped_ptr<NodeType> root_; |
| 327 | 321 |
| 328 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); | 322 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); |
| 329 }; | 323 }; |
| 330 | 324 |
| 331 #endif // APP_TREE_NODE_MODEL_H_ | 325 #endif // APP_TREE_NODE_MODEL_H_ |
| OLD | NEW |