2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
10 goog
.provide('armadillo.File');
12 goog
.require('armadillo.Actor');
13 goog
.require('goog.Disposable');
14 goog
.require('goog.dom');
17 * A file in a directory listing.
18 * @param {string} File name.
21 armadillo
.File
= function(name
) {
22 goog
.Disposable
.call(this);
24 this.isDirectory_
= app
.isDirectory(name
);
26 goog
.inherits(armadillo
.File
, goog
.Disposable
);
32 goog
.Disposable
.prototype.disposeInternal
= function() {
33 armadillo
.File
.superClass_
.disposeInternal
.call(this);
35 goog
.events
.unlistenByKey(this.clickListener_
);
36 goog
.events
.unlistenByKey(this.mouseOverListener_
);
37 goog
.events
.unlistenByKey(this.mouseOutListener_
);
39 goog
.events
.unlistenByKey(this.buttonListener_
);
43 * Constructs the Elements that make up the UI.
44 * @returns {Element} An element ready for insertion into DOM.
46 armadillo
.File
.prototype.draw
= function() {
47 // Create the element if it does not exist. If it does, remove all children.
49 this.element_
= goog
.dom
.createElement('li');
50 this.element_
.representedObject
= this;
51 this.clickListener_
= goog
.events
.listen(this.element_
,
52 goog
.events
.EventType
.CLICK
, this.clickHandler_
, false, this);
53 if (!this.isSpecial_()) {
54 this.mouseOverListener_
= goog
.events
.listen(this.element_
,
55 goog
.events
.EventType
.MOUSEOVER
, this.hoverHandler_
, false, this);
56 this.mouseOutListener_
= goog
.events
.listen(this.element_
,
57 goog
.events
.EventType
.MOUSEOUT
, this.hoverHandler_
, false, this);
60 goog
.dom
.removeChildren(this.element_
);
62 // Set the name of the entry.
63 goog
.dom
.setTextContent(this.element_
, this.name_
);
65 // Create the edit button.
66 if (!this.isSpecial_()) {
67 this.button_
= goog
.dom
.createElement('button');
68 goog
.dom
.setTextContent(this.button_
, 'Edit');
69 goog
.dom
.appendChild(this.element_
, this.button_
);
70 this.button_
.style
.display
= 'none';
71 this.buttonListener_
= goog
.events
.listen(this.button_
,
72 goog
.events
.EventType
.CLICK
, this.buttonClickHandler_
, false, this);
79 * Click handler for the list element.
82 armadillo
.File
.prototype.clickHandler_
= function(e
) {
83 if (armadillo
.Actor
.isModal()) {
86 if (this.isDirectory_
) {
87 app
.navigate(this.name_
);
92 * Hover event handler for the list element. This can handle both mouseover
93 * and mouseout events.
96 armadillo
.File
.prototype.hoverHandler_
= function(e
) {
97 if (armadillo
.Actor
.isModal())
99 var display
= (e
.type
== goog
.events
.EventType
.MOUSEOVER
);
100 this.button_
.style
.display
= (display
? '' : 'none');
104 * Click handler for the button element.
107 armadillo
.File
.prototype.buttonClickHandler_
= function(e
) {
108 if (armadillo
.Actor
.isModal())
111 var actor
= new armadillo
.Actor();
112 actor
.show(e
.clientX
, e
.clientY
);
116 * Returns TRUE if this File is not a real file, but a special kind.
119 armadillo
.File
.prototype.isSpecial_
= function() {
120 return this.name_
== '../';