| 1 |
/* |
| 2 |
* Copyright (c) 2017-2019 José Amuedo (https://github.com/spheras) |
| 3 |
* |
| 4 |
* This program is free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
/** |
| 19 |
* @class |
| 20 |
* Folder Window that is shown above the desktop to manage files and folders |
| 21 |
*/ |
| 22 |
public class DesktopFolder.FolderWindow : Gtk.ApplicationWindow { |
| 23 |
protected FolderManager manager = null; |
| 24 |
protected Gtk.Fixed container = null; |
| 25 |
protected Gtk.ScrolledWindow scroll = null; |
| 26 |
protected Gtk.Menu context_menu = null; |
| 27 |
protected bool flag_moving = false; |
| 28 |
private Gtk.Button trash_button = null; |
| 29 |
private DesktopFolder.EditableLabel label = null; |
| 30 |
protected Gtk.Button properties_button = null; |
| 31 |
protected Gdk.Point ? press_point = null; |
| 32 |
|
| 33 |
public const string HEAD_TAGS_COLORS[3] = { null, "#ffffff", "#000000" }; |
| 34 |
public const string HEAD_TAGS_COLORS_CLASS[3] = { "df_headless", "df_light", "df_dark" }; |
| 35 |
|
| 36 |
public const string BODY_TAGS_COLORS[10] = { null, "#ffe16b", "#ffa154", "#795548", "#9bdb4d", "#64baff", "#ad65d6", "#ed5353", "#d4d4d4", "#000000" }; |
| 37 |
public const string BODY_TAGS_COLORS_CLASS[10] = { "df_transparent", "df_yellow", "df_orange", "df_brown", "df_green", "df_blue", "df_purple", "df_red", "df_gray", "df_black" }; |
| 38 |
protected string last_custom_color = "#FF0000"; |
| 39 |
private Gtk.CssProvider custom_color_provider = new Gtk.CssProvider (); |
| 40 |
/** timeout id for configure event */ |
| 41 |
private uint configure_event_timeout = 0; |
| 42 |
private const int MAX_ITEMS_TO_PROCESS_DINAMICALLY = 50; |
| 43 |
|
| 44 |
|
| 45 |
/** flag to know if the window was painted /packed already */ |
| 46 |
private bool flag_realized = false; |
| 47 |
/** flag to create fade_out effect for the grid */ |
| 48 |
private double grid_fade = 0; |
| 49 |
|
| 50 |
/** flag to know whether any item or header is benig editing */ |
| 51 |
private bool flag_is_editing = false; |
| 52 |
|
| 53 |
/** spinner widget to show background process indicator */ |
| 54 |
private Gtk.Spinner spinner; |
| 55 |
|
| 56 |
// this is the link image loaded |
| 57 |
static Gdk.Pixbuf LINK_PIXBUF = null; |
| 58 |
static construct { |
| 59 |
try { |
| 60 |
int scale = DesktopFolder.ICON_SIZE / 3; |
| 61 |
FolderWindow.LINK_PIXBUF = new Gdk.Pixbuf.from_resource ("/com/github/spheras/desktopfolder/link.svg"); |
| 62 |
FolderWindow.LINK_PIXBUF = FolderWindow.LINK_PIXBUF.scale_simple (scale, scale, Gdk.InterpType.BILINEAR); |
| 63 |
} catch (Error e) { |
| 64 |
stderr.printf ("Error: %s\n", e.message); |
| 65 |
Util.show_error_dialog ("Error", e.message); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
construct { |
| 70 |
set_keep_below (true); |
| 71 |
this.hide_titlebar_when_maximized = false; |
| 72 |
set_type_hint (Gdk.WindowTypeHint.DESKTOP); |
| 73 |
|
| 74 |
set_skip_taskbar_hint (true); |
| 75 |
this.set_property ("skip-taskbar-hint", true); |
| 76 |
this.set_property ("skip-pager-hint", true); |
| 77 |
this.set_property ("skip_taskbar_hint", true); |
| 78 |
this.set_property ("skip_pager_hint", true); |
| 79 |
this.set_accept_focus (true); |
| 80 |
this.skip_pager_hint = true; |
| 81 |
this.skip_taskbar_hint = true; |
| 82 |
|
| 83 |
stick (); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @constructor |
| 88 |
* @param FolderManager manager the manager of this window |
| 89 |
*/ |
| 90 |
public FolderWindow (FolderManager manager) { |
| 91 |
Object ( |
| 92 |
application: manager.get_application (), |
| 93 |
icon_name: "com.github.spheras.desktopfolder", |
| 94 |
resizable: true, |
| 95 |
accept_focus: true, |
| 96 |
skip_taskbar_hint: true, |
| 97 |
skip_pager_hint: true, |
| 98 |
decorated: true, |
| 99 |
title: (manager.get_folder_name ()), |
| 100 |
type_hint: Gdk.WindowTypeHint.DESKTOP, |
| 101 |
deletable: false, |
| 102 |
default_width: 300, |
| 103 |
default_height: 300, |
| 104 |
height_request: 50, |
| 105 |
width_request: 50 |
| 106 |
); |
| 107 |
this.manager = manager; |
| 108 |
|
| 109 |
DesktopManager desktop_manager = manager.get_application ().get_fake_desktop (); |
| 110 |
if (desktop_manager != null) { |
| 111 |
this.set_transient_for (desktop_manager.get_view ()); |
| 112 |
} |
| 113 |
|
| 114 |
this.name = manager.get_application ().get_next_id (); |
| 115 |
this.get_style_context ().add_class ("df_fadeout"); |
| 116 |
|
| 117 |
this.trash_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic"); |
| 118 |
this.trash_button.has_tooltip = true; |
| 119 |
this.trash_button.tooltip_text = DesktopFolder.Lang.DESKTOPFOLDER_DELETE_TOOLTIP; |
| 120 |
this.trash_button.get_image ().get_style_context ().add_class ("df_titlebar_button"); |
| 121 |
this.trash_button.get_image ().get_style_context ().add_class ("df_titlebar_button_hidden"); |
| 122 |
this.trash_button.enter_notify_event.connect (() => { |
| 123 |
this.trash_button.get_image ().get_style_context ().add_class ("df_titlebar_button_hover"); |
| 124 |
return true; |
| 125 |
}); |
| 126 |
this.trash_button.leave_notify_event.connect (() => { |
| 127 |
this.trash_button.get_image ().get_style_context ().remove_class ("df_titlebar_button_hover"); |
| 128 |
return true; |
| 129 |
}); |
| 130 |
|
| 131 |
this.properties_button = new Gtk.Button.from_icon_name ("open-menu-symbolic"); |
| 132 |
this.properties_button.has_tooltip = true; |
| 133 |
this.properties_button.tooltip_text = DesktopFolder.Lang.DESKTOPFOLDER_PROPERTIES_TOOLTIP; |
| 134 |
this.properties_button.get_image ().get_style_context ().add_class ("df_titlebar_button"); |
| 135 |
this.properties_button.get_image ().get_style_context ().add_class ("df_titlebar_button_hidden"); |
| 136 |
this.properties_button.enter_notify_event.connect (() => { |
| 137 |
this.properties_button.get_image ().get_style_context ().add_class ("df_titlebar_button_hover"); |
| 138 |
return true; |
| 139 |
}); |
| 140 |
this.properties_button.leave_notify_event.connect (() => { |
| 141 |
this.properties_button.get_image ().get_style_context ().remove_class ("df_titlebar_button_hover"); |
| 142 |
return true; |
| 143 |
}); |
| 144 |
|
| 145 |
create_headerbar (); |
| 146 |
|
| 147 |
// To avoid showing in the taskbar |
| 148 |
this.set_skip_taskbar_hint (true); |
| 149 |
skip_pager_hint = true; |
| 150 |
skip_taskbar_hint = true; |
| 151 |
this.set_property ("skip-taskbar-hint", true); |
| 152 |
|
| 153 |
this.container = new Gtk.Fixed (); |
| 154 |
// if (!(this is DesktopWindow)) { |
| 155 |
// only panels are scrollable |
| 156 |
this.scroll = new Gtk.ScrolledWindow (null, null); |
| 157 |
this.scroll.add (this.container); |
| 158 |
add (this.scroll); |
| 159 |
// } else { |
| 160 |
// add (this.container); |
| 161 |
// } |
| 162 |
|
| 163 |
// important to load settings 2 times, now and after realized event |
| 164 |
this.reload_settings (); |
| 165 |
this.realize.connect (() => { |
| 166 |
if (!this.flag_realized) { |
| 167 |
this.flag_realized = true; |
| 168 |
// we need to reload settings to ensure that it get the real sizes and positiions |
| 169 |
this.reload_settings (); |
| 170 |
} |
| 171 |
}); |
| 172 |
|
| 173 |
this.configure_event.connect (this.on_configure); |
| 174 |
this.button_press_event.connect (this.on_press); |
| 175 |
this.button_release_event.connect (this.on_release); |
| 176 |
this.motion_notify_event.connect (this.on_motion); |
| 177 |
// this.key_release_event.connect (this.on_key); |
| 178 |
this.key_press_event.connect (this.on_key); |
| 179 |
this.draw.connect (this.draw_background); |
| 180 |
this.enter_notify_event.connect (this.on_enter_notify); |
| 181 |
this.leave_notify_event.connect (this.on_leave_notify); |
| 182 |
|
| 183 |
// Warning! we need to connect with the press_event, instead of release or clicked to avoid problems |
| 184 |
trash_button.button_release_event.connect ((event) => { |
| 185 |
this.manager.trash (); |
| 186 |
return true; |
| 187 |
}); |
| 188 |
properties_button.button_press_event.connect ((event) => { |
| 189 |
this.show_properties_dialog (); |
| 190 |
return true; |
| 191 |
}); |
| 192 |
|
| 193 |
// TODO: Does the GTK window have any active signal or css :active state? |
| 194 |
Wnck.Screen screen = Wnck.Screen.get_default (); |
| 195 |
screen.active_window_changed.connect (on_active_change); |
| 196 |
|
| 197 |
|
| 198 |
// TODO this.dnd_behaviour=new DragnDrop.DndBehaviour(this,false, true); |
| 199 |
|
| 200 |
FolderSettings settings = this.manager.get_settings (); |
| 201 |
if (settings.recently_created) { |
| 202 |
GLib.Timeout.add (50, () => { |
| 203 |
this.label.start_editing (); |
| 204 |
settings.recently_created = false; |
| 205 |
settings.save (); |
| 206 |
return false; |
| 207 |
}); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* @name show_loading |
| 213 |
* @description show the loading spinner |
| 214 |
*/ |
| 215 |
public void show_loading () { |
| 216 |
if (this.spinner != null) { |
| 217 |
debug ("setting LOADING VISIBLE: %s", this.manager.get_folder_name ()); |
| 218 |
this.spinner.set_visible (true); |
| 219 |
this.spinner.set_opacity (1); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* @name hide_loading |
| 225 |
* @description hide the loading spinner |
| 226 |
*/ |
| 227 |
public void hide_loading () { |
| 228 |
if (this.spinner != null) { |
| 229 |
debug ("setting LOADING NO VISIBLE: %s", this.manager.get_folder_name ()); |
| 230 |
this.spinner.set_visible (false); |
| 231 |
this.spinner.set_opacity (0); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* @name show_properties_dialog |
| 237 |
* @description show the properties dialog |
| 238 |
*/ |
| 239 |
protected void show_properties_dialog () { |
| 240 |
var dialog = new DesktopFolder.Dialogs.PanelProperties (this); |
| 241 |
dialog.set_transient_for (this); |
| 242 |
dialog.show_all (); |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* @name create_headerbar |
| 247 |
* @description create the header bar |
| 248 |
*/ |
| 249 |
protected virtual void create_headerbar () { |
| 250 |
// debug("Create headerbar for %s",this.manager.get_folder_name ()); |
| 251 |
|
| 252 |
var header = new Gtk.HeaderBar (); |
| 253 |
header.button_press_event.connect (() => { |
| 254 |
// to avoid moving the window if it is forbidden |
| 255 |
return !this.manager.can_move (); |
| 256 |
}); |
| 257 |
header.height_request = DesktopFolder.HEADERBAR_HEIGHT; |
| 258 |
header.set_decoration_layout (""); |
| 259 |
this.label = new DesktopFolder.EditableLabel (manager.get_folder_name ()); |
| 260 |
this.label.set_margin (10); |
| 261 |
this.label.show_popup.connect (this.on_press); |
| 262 |
this.label.get_style_context ().add_class ("title"); |
| 263 |
// header.set_custom_title (label); |
| 264 |
header.pack_start (trash_button); |
| 265 |
header.set_custom_title (label); |
| 266 |
header.pack_end (properties_button); |
| 267 |
|
| 268 |
this.set_titlebar (header); |
| 269 |
|
| 270 |
this.spinner = new Gtk.Spinner (); |
| 271 |
this.spinner.active = true; |
| 272 |
header.pack_start (this.spinner); |
| 273 |
this.spinner.set_visible (false); |
| 274 |
this.spinner.set_opacity (0); |
| 275 |
|
| 276 |
|
| 277 |
label.changed.connect ((new_name) => { |
| 278 |
if (this.manager.rename (new_name)) { |
| 279 |
label.text = new_name; |
| 280 |
} |
| 281 |
}); |
| 282 |
|
| 283 |
label.on_start_editing.connect (() => { |
| 284 |
this.on_start_editing (); |
| 285 |
}); |
| 286 |
label.on_stop_editing.connect (() => { |
| 287 |
this.on_end_editing (); |
| 288 |
}); |
| 289 |
|
| 290 |
} |
| 291 |
|
| 292 |
/** |
| 293 |
* @name fade_in |
| 294 |
* @description fade the view in. does not call show |
| 295 |
*/ |
| 296 |
public void fade_in () { |
| 297 |
this.get_style_context ().remove_class ("df_fadeout"); |
| 298 |
this.get_style_context ().add_class ("df_fadein"); |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* @name fade_out |
| 303 |
* @description fade the view out. does not call hide |
| 304 |
*/ |
| 305 |
public void fade_out () { |
| 306 |
this.get_style_context ().remove_class ("df_fadein"); |
| 307 |
this.get_style_context ().add_class ("df_fadeout"); |
| 308 |
} |
| 309 |
|
| 310 |
/** |
| 311 |
* @name move_to |
| 312 |
* @description move the window to other position |
| 313 |
*/ |
| 314 |
protected virtual void move_to (int x, int y) { |
| 315 |
// debug ("MOVE_TO: %d,%d", x, y); |
| 316 |
this.move (x, y); |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 320 |
* @name resize_to |
| 321 |
* @description resize the window to other position |
| 322 |
*/ |
| 323 |
public virtual void resize_to (int width, int height) { |
| 324 |
// strange hack to avoid problems when resizing after the window has a header |
| 325 |
// (i.e. after new screen resolution change event) |
| 326 |
Gtk.Allocation title_allocation; |
| 327 |
this.get_titlebar ().get_allocation (out title_allocation); |
| 328 |
int height_pad = title_allocation.height; |
| 329 |
if (height_pad < 2) { |
| 330 |
height_pad = 0; // hack! |
| 331 |
} |
| 332 |
|
| 333 |
debug ("RESIZE_TO: %d,%d", width, height); |
| 334 |
this.set_default_size (width, height - height_pad); |
| 335 |
this.resize (width, height - height_pad); |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* @name reload_settings |
| 340 |
* @description reload the window style in general |
| 341 |
*/ |
| 342 |
public virtual void reload_settings () { |
| 343 |
FolderSettings settings = this.manager.get_settings (); |
| 344 |
if (settings.w > 0) { |
| 345 |
// applying existing position and size configuration |
| 346 |
this.resize_to (settings.w, settings.h); |
| 347 |
this.move_to (settings.x, settings.y); |
| 348 |
// debug ("Moving '%s' to (%d,%d), Resizing to (%d,%d)", this.manager.get_folder_name (), settings.x, settings.y, settings.w, settings.h); |
| 349 |
} |
| 350 |
List <unowned string> classes = this.get_style_context ().list_classes (); |
| 351 |
foreach (string class in classes) { |
| 352 |
if (class.has_prefix ("df_")) { |
| 353 |
this.get_style_context ().remove_class (class); |
| 354 |
} |
| 355 |
} |
| 356 |
// we set a class to this window to manage the css |
| 357 |
this.get_style_context ().add_class ("df_folder"); |
| 358 |
|
| 359 |
this.get_style_context ().add_class ("df_fadingwindow"); |
| 360 |
if (this.manager.get_application ().get_desktop_visibility ()) { |
| 361 |
this.get_style_context ().add_class ("df_fadein"); |
| 362 |
// setting opacity to stop the folder window flashing at startup |
| 363 |
this.opacity = 1; |
| 364 |
} else { |
| 365 |
this.get_style_context ().add_class ("df_fadeout"); |
| 366 |
// ditto |
| 367 |
this.opacity = 0; |
| 368 |
} |
| 369 |
|
| 370 |
// applying existing colors configuration |
| 371 |
if (settings.bgcolor.has_prefix ("rgb")) { |
| 372 |
string custom = settings.bgcolor; |
| 373 |
this.set_custom_color (custom); |
| 374 |
} else { |
| 375 |
Gdk.RGBA rgba = Gdk.RGBA (); |
| 376 |
rgba.parse (this.get_color_for_class (settings.bgcolor)); |
| 377 |
rgba.alpha = 0.35; |
| 378 |
this.last_custom_color = rgba.to_string (); |
| 379 |
this.get_style_context ().add_class (settings.bgcolor); |
| 380 |
} |
| 381 |
this.get_style_context ().add_class (settings.fgcolor); |
| 382 |
|
| 383 |
if (settings.textshadow) { |
| 384 |
this.get_style_context ().add_class ("df_shadow"); |
| 385 |
} |
| 386 |
if (settings.textbold) { |
| 387 |
this.get_style_context ().add_class ("df_bold"); |
| 388 |
} |
| 389 |
|
| 390 |
this.set_title (manager.get_folder_name ()); |
| 391 |
|
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* @name set_custom_color |
| 396 |
* @description utility function to set a custom color for the window |
| 397 |
* @param {string} custom the custom color to set (rgba(....)) |
| 398 |
* @return {string} the real custom color applied |
| 399 |
*/ |
| 400 |
private string set_custom_color (string custom) { |
| 401 |
for (int i = 0; i < BODY_TAGS_COLORS_CLASS.length; i++) { |
| 402 |
string scolor = BODY_TAGS_COLORS_CLASS[i]; |
| 403 |
this.get_style_context ().remove_class (scolor); |
| 404 |
} |
| 405 |
|
| 406 |
Gdk.RGBA rgba = Gdk.RGBA (); |
| 407 |
rgba.parse (custom); |
| 408 |
string mycustom = custom; |
| 409 |
if (rgba.alpha == 1) { |
| 410 |
// this solves a bug wen setting an opaque color to gtk and vice |
| 411 |
rgba.alpha = 0.999; |
| 412 |
mycustom = rgba.to_string (); |
| 413 |
} |
| 414 |
|
| 415 |
Gtk.StyleContext.remove_provider_for_screen (Gdk.Screen.get_default (), this.custom_color_provider); |
| 416 |
try { |
| 417 |
string css = |
| 418 |
"#" + this.name + """.df_folder.window-frame, #""" + this.name + """.df_folder.window-frame:backdrop { |
| 419 |
border-color: """ + mycustom + """; |
| 420 |
} |
| 421 |
#""" + this.name + """.df_folder.background, #""" + this.name + """.df_folder.background:backdrop { |
| 422 |
background-color: """ + mycustom + """; |
| 423 |
} |
| 424 |
#""" + this.name + """.df_folder .titlebar, #""" + this.name + """.df_folder .titlebar:backdrop{ |
| 425 |
background-color: """ + mycustom + """; |
| 426 |
border-color: """ + mycustom + """; |
| 427 |
}"""; |
| 428 |
// debug("applying css:\n %s",css); |
| 429 |
this.custom_color_provider.load_from_data (css); |
| 430 |
} catch (Error e) { |
| 431 |
stderr.printf ("Error: %s\n", e.message); |
| 432 |
DesktopFolder.Util.show_error_dialog ("Error", e.message); |
| 433 |
} |
| 434 |
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), this.custom_color_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER); |
| 435 |
this.last_custom_color = mycustom; |
| 436 |
|
| 437 |
return mycustom; |
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* @name get_color_for_class |
| 442 |
* @description return the correct color for a certain class |
| 443 |
* @param {string} class the class to obtain (@see BODY_TAGS_COLORS_CLASS) |
| 444 |
* @return {string} the color for the class passed |
| 445 |
*/ |
| 446 |
private string get_color_for_class (string class) { |
| 447 |
if (class == "df_transparent") { |
| 448 |
return "rgba(0,0,0,0)"; |
| 449 |
} else { |
| 450 |
for (int i = 0; i < BODY_TAGS_COLORS_CLASS.length; i++) { |
| 451 |
if (BODY_TAGS_COLORS_CLASS[i] == class) { |
| 452 |
return BODY_TAGS_COLORS[i]; |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
return "rgba(0,0,0)"; |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
* @name on_active_change |
| 461 |
* @description the screen actived window has change signal |
| 462 |
* @param {Wnck.Window} the previous actived window |
| 463 |
*/ |
| 464 |
private void on_active_change (Wnck.Window ? previous) { |
| 465 |
string sclass = "df_active"; |
| 466 |
Gtk.StyleContext style = this.get_style_context (); |
| 467 |
// debug("%s is active? %s",this.manager.get_folder_name(), this.is_active ? "true" : "false"); |
| 468 |
if (this.is_active) { |
| 469 |
this.manager.on_active (); |
| 470 |
if (!style.has_class (sclass)) { |
| 471 |
style.add_class ("df_active"); |
| 472 |
// we need to force a queue_draw |
| 473 |
this.queue_draw (); |
| 474 |
} |
| 475 |
} else { |
| 476 |
if (style.has_class (sclass)) { |
| 477 |
style.remove_class ("df_active"); |
| 478 |
this.type_hint = Gdk.WindowTypeHint.DESKTOP; |
| 479 |
// we need to force a queue_draw |
| 480 |
this.queue_draw (); |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
/** |
| 486 |
* @name refresh |
| 487 |
* @description refresh the window |
| 488 |
*/ |
| 489 |
public virtual void refresh () { |
| 490 |
if (this.manager.get_application ().get_desktop_visibility ()) { |
| 491 |
this.show_all (); |
| 492 |
this.manager.quick_show_items (); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
/** |
| 497 |
* @name on_configure |
| 498 |
* @description the configure event is produced when the window change its dimensions or location settings |
| 499 |
*/ |
| 500 |
private bool on_configure (Gdk.EventConfigure event) { |
| 501 |
// it seems: |
| 502 |
// - the window.height is this.allocation.height + decoration.margin.height * 2 + header.height |
| 503 |
// - the window.width is the allocation.width + decoration.margin.width * 2 |
| 504 |
if (!this.flag_realized) { |
| 505 |
// we discard all the pre realized configure events |
| 506 |
return false; |
| 507 |
} |
| 508 |
|
| 509 |
// debug ("---------------------------------------------------------"); |
| 510 |
// debug ("event configure: type:%d,se:%d,w:%d,h:%d,x:%d,y:%d", event.type, event.send_event, event.width, event.height, event.x, event.y); |
| 511 |
if (event.type == Gdk.EventType.CONFIGURE) { |
| 512 |
// This is to avoid minimization when Show Desktop shortcut is used |
| 513 |
// TODO: Is there a way to make a desktop window resizable and movable? |
| 514 |
this.type_hint = Gdk.WindowTypeHint.DESKTOP; // Going to try DIALOG at some point |
| 515 |
|
| 516 |
if (this.manager.get_settings ().items.length > MAX_ITEMS_TO_PROCESS_DINAMICALLY) { |
| 517 |
// waiting 400ms of inactivity to save the new position |
| 518 |
if (this.configure_event_timeout > 0) { |
| 519 |
Source.remove (this.configure_event_timeout); |
| 520 |
this.configure_event_timeout = 0; |
| 521 |
} |
| 522 |
this.configure_event_timeout = Timeout.add (400, () => { |
| 523 |
this.configure_event_timeout = 0; |
| 524 |
this.save_current_position_and_size (event); |
| 525 |
return false; |
| 526 |
}); |
| 527 |
} else { |
| 528 |
// saving position inmediatelly, we can afford it |
| 529 |
this.save_current_position_and_size (event); |
| 530 |
} |
| 531 |
|
| 532 |
} |
| 533 |
return false; |
| 534 |
} |
| 535 |
|
| 536 |
/** |
| 537 |
* @name save_position_and_size |
| 538 |
* @description save the current position and size of the window |
| 539 |
*/ |
| 540 |
public void save_current_position_and_size (Gdk.EventConfigure event) { |
| 541 |
// we are saving here the last position and size |
| 542 |
// we avoid doing it at on_configure because it launches a lot of events |
| 543 |
|
| 544 |
int x = event.x + DesktopFolder.WINDOW_DECORATION_MARGIN; |
| 545 |
int y = event.y + DesktopFolder.WINDOW_DECORATION_MARGIN; |
| 546 |
int w = event.width - (DesktopFolder.WINDOW_DECORATION_MARGIN * 2); |
| 547 |
int h = event.height - (DesktopFolder.WINDOW_DECORATION_MARGIN * 2); |
| 548 |
// debug ("%s - set_new_shape: %i,%i,%i,%i", this.get_manager().get_folder_name(), x, y, w, h); |
| 549 |
this.manager.set_new_shape (x, y, w, h); |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* @name on_enter_notify |
| 554 |
* @description On mouse entering the window |
| 555 |
*/ |
| 556 |
protected virtual bool on_enter_notify (Gdk.EventCrossing event) { |
| 557 |
// debug("FOLDERWINDOW '%s' ENTER notify",this.manager.get_folder_name()); |
| 558 |
trash_button.get_image ().get_style_context ().remove_class ("df_titlebar_button_hidden"); |
| 559 |
properties_button.get_image ().get_style_context ().remove_class ("df_titlebar_button_hidden"); |
| 560 |
return false; |
| 561 |
} |
| 562 |
|
| 563 |
/** |
| 564 |
* @name on_enter_leave |
| 565 |
* @description On mouse leaving the window |
| 566 |
*/ |
| 567 |
protected virtual bool on_leave_notify (Gdk.EventCrossing event) { |
| 568 |
if (event.detail == Gdk.NotifyType.ANCESTOR || event.detail == Gdk.NotifyType.VIRTUAL || event.detail == Gdk.NotifyType.INFERIOR) { |
| 569 |
return false; |
| 570 |
} |
| 571 |
// debug("FOLDERWINDOW '%s' LEAVE notify",this.manager.get_folder_name()); |
| 572 |
trash_button.get_image ().get_style_context ().add_class ("df_titlebar_button_hidden"); |
| 573 |
properties_button.get_image ().get_style_context ().add_class ("df_titlebar_button_hidden"); |
| 574 |
return false; |
| 575 |
} |
| 576 |
|
| 577 |
/** |
| 578 |
* @name on_release |
| 579 |
* @description release event captured. |
| 580 |
* @return bool @see widget on_release signal |
| 581 |
*/ |
| 582 |
private bool on_release (Gdk.EventButton event) { |
| 583 |
if (this.press_point != null) { |
| 584 |
// removing old press point |
| 585 |
this.press_point = null; |
| 586 |
this.current_point = null; |
| 587 |
this.queue_draw (); |
| 588 |
} |
| 589 |
// This is to avoid minimization when Show Desktop shortcut is used |
| 590 |
// TODO: Is there a way to make a desktop window resizable and movable? |
| 591 |
this.type_hint = Gdk.WindowTypeHint.DESKTOP; |
| 592 |
return false; |
| 593 |
} |
| 594 |
|
| 595 |
/** |
| 596 |
* @name on_press |
| 597 |
* @description press event captured. The Window should show the popup on right button |
| 598 |
* @return bool @see widget on_press signal |
| 599 |
*/ |
| 600 |
protected virtual bool on_press (Gdk.EventButton event) { |
| 601 |
// debug("on_press folderwindow: %d, %d",(int)event.x,(int)event.y); |
| 602 |
// Needed to exit focus from title when editting |
| 603 |
this.activate_focus (); |
| 604 |
|
| 605 |
// this code is to allow the drag'ndrop of files inside the folder window |
| 606 |
var mods = event.state & Gtk.accelerator_get_default_mod_mask (); |
| 607 |
bool control_pressed = ((mods & Gdk.ModifierType.CONTROL_MASK) != 0); |
| 608 |
bool can_drag = this.manager.get_arrangement ().can_drag (); |
| 609 |
if (!can_drag) { |
| 610 |
Gee.List <ItemView> selecteds = this.manager.get_selected_items (); |
| 611 |
for (int i = 0; i < selecteds.size && !control_pressed; i++) { |
| 612 |
ItemView selected = selecteds.@get (i); |
| 613 |
control_pressed = selected.is_dragdrop_started (); |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == Gdk.BUTTON_PRIMARY && control_pressed) { |
| 618 |
return false; |
| 619 |
} |
| 620 |
|
| 621 |
if (!control_pressed) { |
| 622 |
this.unselect_all (); |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
// This is to allow moving and resizing the panel |
| 627 |
// TODO: Is there a way to make a desktop window resizable and movable? |
| 628 |
this.type_hint = Gdk.WindowTypeHint.NORMAL; // Going to try DIALOG at some point to make below obsolete |
| 629 |
|
| 630 |
// debug("press:%i,%i,%i",(int)event.button,(int)event.x,(int)event.y); |
| 631 |
if (event.type == Gdk.EventType.BUTTON_PRESS && |
| 632 |
(event.button == Gdk.BUTTON_SECONDARY)) { |
| 633 |
this.show_popup (event); |
| 634 |
return true; |
| 635 |
// Remove below later if hiding behind Wingpanel is properly fixed (required for drag boxes) |
| 636 |
} else if (event.type == Gdk.EventType.BUTTON_PRESS && |
| 637 |
(event.button == Gdk.BUTTON_MIDDLE || |
| 638 |
(event.button == Gdk.BUTTON_PRIMARY && event.y < 31))) { |
| 639 |
this.unselect_all (); |
| 640 |
|
| 641 |
if (this.manager.can_move ()) { |
| 642 |
// int width = this.get_allocated_width (); |
| 643 |
// int height = this.get_allocated_height (); |
| 644 |
// debug("x:%d,y:%d,width:%d,height:%d",(int)event.x,(int) event.y,width,height); |
| 645 |
// some tricks to allow resizing from border |
| 646 |
if (event.x > 11 && event.y > 11) { |
| 647 |
// the corner need some extra space |
| 648 |
if (!(event.x < 31 && event.y < 31)) { |
| 649 |
this.begin_move_drag ((int) event.button, (int) event.x_root, (int) event.y_root, event.time); |
| 650 |
} |
| 651 |
} |
| 652 |
} else { |
| 653 |
return true; |
| 654 |
} |
| 655 |
} else if (event.x > 11 && |
| 656 |
event.type == Gdk.EventType.BUTTON_PRESS && |
| 657 |
event.button == Gdk.BUTTON_PRIMARY) { |
| 658 |
this.press_point = Gdk.Point (); |
| 659 |
this.press_point.x = (int) event.x; |
| 660 |
this.press_point.y = (int) event.y; |
| 661 |
} |
| 662 |
|
| 663 |
return false; |
| 664 |
} |
| 665 |
|
| 666 |
/** |
| 667 |
* @name show_popup |
| 668 |
* @description build and show the popup menu |
| 669 |
* @param event EventButton the origin event, needed to position the menu |
| 670 |
*/ |
| 671 |
protected virtual void show_popup (Gdk.EventButton event) { |
| 672 |
// debug("evento:%f,%f",event.x,event.y); |
| 673 |
// if(this.menu==null) { // we need the event coordinates for the menu, we need to recreate?! |
| 674 |
|
| 675 |
// Forcing desktop mode to avoid minimization in certain extreme cases without on_press signal! |
| 676 |
// TODO: Is there a way to make a desktop window resizable and movable? |
| 677 |
|
| 678 |
this.type_hint = Gdk.WindowTypeHint.DESKTOP; |
| 679 |
this.context_menu = new Gtk.Menu (); |
| 680 |
Clipboard.ClipboardManager cm = Clipboard.ClipboardManager.get_for_display (); |
| 681 |
|
| 682 |
// Creating items (please try and keep these in the same order as appended to the menu) |
| 683 |
var new_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_SUBMENU); |
| 684 |
|
| 685 |
var new_submenu = new Gtk.Menu (); |
| 686 |
var newfolder_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_FOLDER); |
| 687 |
var emptyfile_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_EMPTY_FILE); |
| 688 |
var newlink_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_FILE_LINK); |
| 689 |
var newlinkdir_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_FOLDER_LINK); |
| 690 |
var newpanel_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_DESKTOP_FOLDER); |
| 691 |
var newlinkpanel_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_LINK_PANEL); |
| 692 |
var newnote_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_NOTE); |
| 693 |
var newphoto_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_NEW_PHOTO); |
| 694 |
var openterminal_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_OPENTERMINAL); |
| 695 |
|
| 696 |
// sortby submenu ----------- |
| 697 |
var sortby_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY); |
| 698 |
var sortby_submenu = new Gtk.Menu (); |
| 699 |
var sortby_name_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY_NAME); |
| 700 |
var sortby_size_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY_SIZE); |
| 701 |
var sortby_type_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_BY_TYPE); |
| 702 |
var sortby_reverse_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_REVERSE); |
| 703 |
var sortby_vertical_item = new Gtk.CheckMenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_VERTICAL); |
| 704 |
var organize_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_SORT_ORGANIZE); |
| 705 |
// ---------------------------- |
| 706 |
|
| 707 |
var trash_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_REMOVE_DESKTOP_FOLDER); |
| 708 |
var rename_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_RENAME_DESKTOP_FOLDER); |
| 709 |
var textcolor_item = new MenuItemColor (HEAD_TAGS_COLORS, null); |
| 710 |
var backgroundcolor_item = new MenuItemColor (BODY_TAGS_COLORS, this.last_custom_color); |
| 711 |
|
| 712 |
// Events (please try and keep these in the same order as appended to the menu) |
| 713 |
newfolder_item.activate.connect (() => { this.new_folder ((int) event.x, (int) event.y); }); |
| 714 |
emptyfile_item.activate.connect (() => { this.new_text_file ((int) event.x, (int) event.y); }); |
| 715 |
newlink_item.activate.connect (() => { this.new_link ((int) event.x, (int) event.y, false); }); |
| 716 |
newlinkdir_item.activate.connect (() => { this.new_link ((int) event.x, (int) event.y, true); }); |
| 717 |
newpanel_item.activate.connect (() => { this.new_desktop_folder ((int) event.x, (int) event.y); }); |
| 718 |
newlinkpanel_item.activate.connect (() => { this.new_link_panel ((int) event.x, (int) event.y); }); |
| 719 |
newnote_item.activate.connect (() => { this.new_note ((int) event.x, (int) event.y); }); |
| 720 |
newphoto_item.activate.connect (() => { this.new_photo ((int) event.x, (int) event.y); }); |
| 721 |
openterminal_item.activate.connect (this.open_terminal); |
| 722 |
|
| 723 |
// sortby submenu --------- |
| 724 |
sortby_name_item.set_active (this.manager.get_settings ().sort_by_type == FolderSort.SORT_BY_NAME); |
| 725 |
sortby_size_item.set_active (this.manager.get_settings ().sort_by_type == FolderSort.SORT_BY_SIZE); |
| 726 |
sortby_type_item.set_active (this.manager.get_settings ().sort_by_type == FolderSort.SORT_BY_TYPE); |
| 727 |
sortby_reverse_item.set_active (this.manager.get_settings ().sort_reverse == true); |
| 728 |
sortby_vertical_item.set_active (this.manager.is_vertical_arragement ()); |
| 729 |
|
| 730 |
sortby_name_item.toggled.connect ((item) => { |
| 731 |
this.on_sort_by (FolderSort.SORT_BY_NAME); |
| 732 |
}); |
| 733 |
sortby_size_item.toggled.connect ((item) => { |
| 734 |
this.on_sort_by (FolderSort.SORT_BY_SIZE); |
| 735 |
}); |
| 736 |
sortby_type_item.toggled.connect ((item) => { |
| 737 |
this.on_sort_by (FolderSort.SORT_BY_TYPE); |
| 738 |
}); |
| 739 |
sortby_reverse_item.toggled.connect ((item) => { |
| 740 |
this.manager.get_settings ().sort_reverse = !this.manager.get_settings ().sort_reverse; |
| 741 |
this.manager.get_settings ().save (); |
| 742 |
this.manager.organize_panel_items (); |
| 743 |
}); |
| 744 |
sortby_vertical_item.toggled.connect ((item) => { |
| 745 |
if (this.manager.is_vertical_arragement ()) { |
| 746 |
this.manager.get_settings ().arrangement_orientation = FolderSettings.ARRANGEMENT_ORIENTATION_HORIZONTAL; |
| 747 |
} else { |
| 748 |
this.manager.get_settings ().arrangement_orientation = FolderSettings.ARRANGEMENT_ORIENTATION_VERTICAL; |
| 749 |
} |
| 750 |
this.manager.get_settings ().save (); |
| 751 |
this.manager.organize_panel_items (); |
| 752 |
}); |
| 753 |
organize_item.activate.connect (this.manager.organize_panel_items); |
| 754 |
// ------------------------ |
| 755 |
|
| 756 |
trash_item.activate.connect (this.manager.trash); |
| 757 |
rename_item.activate.connect (this.label.start_editing); |
| 758 |
((MenuItemColor) textcolor_item).color_changed.connect (change_head_color); |
| 759 |
((MenuItemColor) backgroundcolor_item).color_changed.connect (change_body_color); |
| 760 |
((MenuItemColor) backgroundcolor_item).custom_changed.connect (change_body_color_custom); |
| 761 |
|
| 762 |
// Appending (in order) |
| 763 |
if (cm.can_paste) { |
| 764 |
var paste_item = new Gtk.MenuItem.with_label (DesktopFolder.Lang.DESKTOPFOLDER_MENU_PASTE); |
| 765 |
paste_item.activate.connect (this.manager.paste); |
| 766 |
context_menu.append (paste_item); |
| 767 |
context_menu.append (new MenuItemSeparator ()); |
| 768 |
} |
| 769 |
context_menu.append (new_item); |
| 770 |
new_item.set_submenu (new_submenu); |
| 771 |
|
| 772 |
new_submenu.append (newfolder_item); |
| 773 |
new_submenu.append (emptyfile_item); |
| 774 |
new_submenu.append (new MenuItemSeparator ()); |
| 775 |
new_submenu.append (newlink_item); |
| 776 |
new_submenu.append (newlinkdir_item); |
| 777 |
if (!this.manager.get_application ().get_desktoppanel_enabled ()) { |
| 778 |
new_submenu.append (new MenuItemSeparator ()); |
| 779 |
new_submenu.append (newpanel_item); |
| 780 |
new_submenu.append (newlinkpanel_item); |
| 781 |
new_submenu.append (newnote_item); |
| 782 |
new_submenu.append (newphoto_item); |
| 783 |
} |
| 784 |
|
| 785 |
// sortby submenu --------- |
| 786 |
context_menu.append (new MenuItemSeparator ()); |
| 787 |
context_menu.append (sortby_item); |
| 788 |
sortby_item.set_submenu (sortby_submenu); |
| 789 |
sortby_submenu.append (sortby_name_item); |
| 790 |
sortby_submenu.append (sortby_size_item); |
| 791 |
sortby_submenu.append (sortby_type_item); |
| 792 |
sortby_submenu.append (new MenuItemSeparator ()); |
| 793 |
sortby_submenu.append (sortby_reverse_item); |
| 794 |
sortby_submenu.append (sortby_vertical_item); |
| 795 |
if (this.manager.get_arrangement ().can_organize ()) { |
| 796 |
context_menu.append (organize_item); |
| 797 |
} |
| 798 |
context_menu.append (new MenuItemSeparator ()); |
| 799 |
context_menu.append (openterminal_item); |
| 800 |
// ------------------------- |
| 801 |
|
| 802 |
// context_menu.append (new MenuItemSeparator ()); |
| 803 |
// context_menu.append (aligntogrid_item); |
| 804 |
context_menu.append (new MenuItemSeparator ()); |
| 805 |
context_menu.append (trash_item); |
| 806 |
// context_menu.append (new MenuItemSeparator ()); |
| 807 |
context_menu.append (rename_item); |
| 808 |
// context_menu.append (new MenuItemSeparator ()); |
| 809 |
// context_menu.append (lockitems_item); |
| 810 |
// context_menu.append (textshadow_item); |
| 811 |
// context_menu.append (textbold_item); |
| 812 |
context_menu.append (textcolor_item); |
| 813 |
context_menu.append (backgroundcolor_item); |
| 814 |
|
| 815 |
|
| 816 |
context_menu.show_all (); |
| 817 |
|
| 818 |
context_menu.popup_at_pointer (null); |
| 819 |
} |
| 820 |
|
| 821 |
/** |
| 822 |
* @name on_toggle_bold |
| 823 |
* @description the bold toggle event. the text bold property must change |
| 824 |
*/ |
| 825 |
public void on_toggle_bold () { |
| 826 |
Gtk.StyleContext style = this.get_style_context (); |
| 827 |
string bold_class = "df_bold"; |
| 828 |
if (this.manager.get_settings ().textbold) { |
| 829 |
style.remove_class (bold_class); |
| 830 |
this.manager.get_settings ().textbold = false; |
| 831 |
} else { |
| 832 |
style.add_class (bold_class); |
| 833 |
this.manager.get_settings ().textbold = true; |
| 834 |
} |
| 835 |
this.manager.get_settings ().save (); |
| 836 |
// List <weak Gtk.Widget> children = this.container.get_children (); |
| 837 |
// foreach (Gtk.Widget elem in children) { |
| 838 |
// (elem as ItemView).force_adjust_label (); |
| 839 |
// } |
| 840 |
} |
| 841 |
|
| 842 |
/** |
| 843 |
* @name on_sort_by |
| 844 |
* @description the sort by of the panel has changed |
| 845 |
* @param int type the new sort by type @see FolderArrangetment sort by types consts |
| 846 |
*/ |
| 847 |
public void on_sort_by (int type) { |
| 848 |
if (this.manager.get_settings ().sort_by_type != type) { |
| 849 |
this.manager.get_settings ().sort_by_type = type; |
| 850 |
this.manager.get_settings ().save (); |
| 851 |
this.manager.organize_panel_items (); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
/** |
| 856 |
* @name on_toggle_shadow |
| 857 |
* @description the toggle shadow event. The shadow property must change |
| 858 |
*/ |
| 859 |
public void on_toggle_shadow () { |
| 860 |
Gtk.StyleContext style = this.get_style_context (); |
| 861 |
string shadow_class = "df_shadow"; |
| 862 |
if (this.manager.get_settings ().textshadow) { |
| 863 |
style.remove_class (shadow_class); |
| 864 |
this.manager.get_settings ().textshadow = false; |
| 865 |
} else { |
| 866 |
style.add_class (shadow_class); |
| 867 |
this.manager.get_settings ().textshadow = true; |
| 868 |
} |
| 869 |
this.manager.get_settings ().save (); |
| 870 |
// List <weak Gtk.Widget> children = this.container.get_children (); |
| 871 |
// foreach (Gtk.Widget elem in children) { |
| 872 |
// (elem as ItemView).force_adjust_label (); |
| 873 |
// } |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* @name on_toggle_lockitems |
| 878 |
* @description the toggle lock items event. The lock items property must change |
| 879 |
*/ |
| 880 |
public void on_toggle_lockitems () { |
| 881 |
this.manager.get_settings ().lockitems = !this.manager.get_settings ().lockitems; |
| 882 |
this.manager.get_settings ().save (); |
| 883 |
} |
| 884 |
|
| 885 |
/** |
| 886 |
* @name on_toggle_lockpanel |
| 887 |
* @description the toggle lock panel event. The lock panel property must change |
| 888 |
*/ |
| 889 |
public void on_toggle_lockpanel () { |
| 890 |
this.manager.get_settings ().lockpanel = !this.manager.get_settings ().lockpanel; |
| 891 |
this.manager.get_settings ().save (); |
| 892 |
} |
| 893 |
|
| 894 |
/** |
| 895 |
* @name change_head_color |
| 896 |
* @description change event captured from the popup for a new color to the head window |
| 897 |
* @param {int} ncolor the new color for the head window |
| 898 |
*/ |
| 899 |
protected void change_head_color (int ncolor) { |
| 900 |
string color = HEAD_TAGS_COLORS_CLASS[ncolor]; |
| 901 |
for (int i = 0; i < HEAD_TAGS_COLORS_CLASS.length; i++) { |
| 902 |
string scolor = HEAD_TAGS_COLORS_CLASS[i]; |
| 903 |
this.get_style_context ().remove_class (scolor); |
| 904 |
} |
| 905 |
this.get_style_context ().add_class (color); |
| 906 |
this.manager.save_head_color (color); |
| 907 |
// debug("color:%d,%s",ncolor,color); |
| 908 |
} |
| 909 |
|
| 910 |
/** |
| 911 |
* @name move_item |
| 912 |
* @description move an item inside this window to a certain position |
| 913 |
* @param {ItemView} item the item to be moved |
| 914 |
* @param {int} x the x position |
| 915 |
* @param {int} y the y position |
| 916 |
*/ |
| 917 |
public void move_item (ItemView item, int x, int y) { |
| 918 |
// debug("moved to:%d,%d",x,y); |
| 919 |
this.container.move (item, x, y); |
| 920 |
} |
| 921 |
|
| 922 |
/** |
| 923 |
* @name change_body_color |
| 924 |
* @description change event captured from the popup for a new color to the body window |
| 925 |
* @param {int} ncolor the new color for the body window |
| 926 |
*/ |
| 927 |
public void change_body_color (int ncolor) { |
| 928 |
string color = BODY_TAGS_COLORS_CLASS[ncolor]; |
| 929 |
for (int i = 0; i < BODY_TAGS_COLORS_CLASS.length; i++) { |
| 930 |
string scolor = BODY_TAGS_COLORS_CLASS[i]; |
| 931 |
this.get_style_context ().remove_class (scolor); |
| 932 |
} |
| 933 |
if (this.custom_color_provider != null) { |
| 934 |
Gtk.StyleContext.remove_provider_for_screen (Gdk.Screen.get_default (), this.custom_color_provider); |
| 935 |
} |
| 936 |
|
| 937 |
if (ncolor > 0) { |
| 938 |
Gdk.RGBA rgba = Gdk.RGBA (); |
| 939 |
rgba.parse (BODY_TAGS_COLORS[ncolor]); |
| 940 |
rgba.alpha = 0.35; |
| 941 |
this.last_custom_color = rgba.to_string (); |
| 942 |
} else { |
| 943 |
this.last_custom_color = "rgba(0,0,0,0)"; |
| 944 |
} |
| 945 |
|
| 946 |
this.get_style_context ().add_class (color); |
| 947 |
this.manager.save_body_color (color); |
| 948 |
// debug("color:%d,%s",ncolor,color); |
| 949 |
} |
| 950 |
|
| 951 |
/** |
| 952 |
* @name change_body_color_custom |
| 953 |
* @description change event captured from the popup for a new color to the body window |
| 954 |
* @param custom string the new custom color |
| 955 |
*/ |
| 956 |
public void change_body_color_custom (string custom) { |
| 957 |
string mycustom = this.set_custom_color (custom); |
| 958 |
this.manager.save_body_color (mycustom); |
| 959 |
} |
| 960 |
|
| 961 |
/** |
| 962 |
* @name clear_all |
| 963 |
* @description clear all the items inside this folder window |
| 964 |
*/ |
| 965 |
public void clear_all () { |
| 966 |
// debug("clearing all items"); |
| 967 |
var children = this.container.get_children (); |
| 968 |
foreach (Gtk.Widget element in children) |
| 969 |
this.container.remove (element); |
| 970 |
} |
| 971 |
|
| 972 |
/** |
| 973 |
* @name add_item |
| 974 |
* @description add an item icon to the container |
| 975 |
* @param ItemView item the item to be added |
| 976 |
* @param int x the x position where it should be placed |
| 977 |
* @param int y the y position where it should be placed |
| 978 |
*/ |
| 979 |
public void add_item (ItemView item, int x, int y) { |
| 980 |
// debug("initial position:%d,%d",x,y); |
| 981 |
// x = ItemView.RoundToNearestMultiple (x, this.get_sensitivity ()); TODO |
| 982 |
// y = ItemView.RoundToNearestMultiple (y, this.get_sensitivity ()); TODO |
| 983 |
int margin = 0; // ItemView.PADDING_X; |
| 984 |
this.container.put (item, x + margin, y); |
| 985 |
} |
| 986 |
|
| 987 |
/** |
| 988 |
* @name remove_item |
| 989 |
* @description remove an item from the view |
| 990 |
* @param ItemView item the item to be removed |
| 991 |
*/ |
| 992 |
public void remove_item (ItemView item) { |
| 993 |
this.container.remove (item); |
| 994 |
} |
| 995 |
|
| 996 |
/** |
| 997 |
* @name raise |
| 998 |
* @description bring to front the item |
| 999 |
* @param {ItemView} |
| 1000 |
*/ |
| 1001 |
public void raise (ItemView item, int x, int y) { |
| 1002 |
this.container.remove (item); |
| 1003 |
add_item (item, x, y); |
| 1004 |
} |
| 1005 |
|
| 1006 |
/** |
| 1007 |
* @name on_start_editing |
| 1008 |
* @description a label is being edited |
| 1009 |
*/ |
| 1010 |
public void on_start_editing () { |
| 1011 |
this.flag_is_editing = true; |
| 1012 |
} |
| 1013 |
|
| 1014 |
/** |
| 1015 |
* @name on_end_editing |
| 1016 |
* @description a label has finished the edition |
| 1017 |
*/ |
| 1018 |
public void on_end_editing () { |
| 1019 |
this.flag_is_editing = false; |
| 1020 |
} |
| 1021 |
|
| 1022 |
/** |
| 1023 |
* @name on_key |
| 1024 |
* @description the key event captured for the window |
| 1025 |
* @param EventKey event the event produced |
| 1026 |
* @return bool @see the on_key signal |
| 1027 |
*/ |
| 1028 |
private bool on_key (Gdk.EventKey event) { |
| 1029 |
// debug("FolderWindow on_key, event: %s",event.type == Gdk.EventType.KEY_RELEASE?"KEY_RELEASE":event.type == Gdk.EventType.KEY_PRESS?"KEY_PRESS":"OTRO"); |
| 1030 |
// If the uses is editing something on an entry |
| 1031 |
|
| 1032 |
if (flag_is_editing) { |
| 1033 |
// debug ("User is editing!"); |
| 1034 |
return false; |
| 1035 |
} |
| 1036 |
|
| 1037 |
int key = (int) event.keyval; |
| 1038 |
|
| 1039 |
debug ("event key %d", key); |
| 1040 |
const int DELETE_KEY = 65535; |
| 1041 |
const int F2_KEY = 65471; |
| 1042 |
const int ENTER_KEY = 65293; |
| 1043 |
const int ARROW_LEFT_KEY = 65361; |
| 1044 |
const int ARROW_UP_KEY = 65362; |
| 1045 |
const int ARROW_RIGHT_KEY = 65363; |
| 1046 |
const int ARROW_DOWN_KEY = 65364; |
| 1047 |
|
| 1048 |
var mods = event.state & Gtk.accelerator_get_default_mod_mask (); |
| 1049 |
bool control_pressed = ((mods & Gdk.ModifierType.CONTROL_MASK) != 0); |
| 1050 |
bool shift_pressed = ((mods & Gdk.ModifierType.SHIFT_MASK) != 0); |
| 1051 |
|
| 1052 |
// lets get the first selected item |
| 1053 |
ItemView[] selecteds = this.manager.get_selected_items ().to_array (); |
| 1054 |
ItemView selected = null; |
| 1055 |
for (int i = 0; i < selecteds.length; i++) { |
| 1056 |
ItemView isel = selecteds[i]; |
| 1057 |
if (isel != null) { |
| 1058 |
selected = isel; |
| 1059 |
} |
| 1060 |
} |
| 1061 |
|
| 1062 |
if (control_pressed && selected != null && (key == 'c' || key == 'C')) { |
| 1063 |
if (selected != null) { |
| 1064 |
selected.copy (); |
| 1065 |
} |
| 1066 |
return true; |
| 1067 |
} |
| 1068 |
|
| 1069 |
if (control_pressed && selected != null && (key == 'x' || key == 'X')) { |
| 1070 |
if (selected != null) { |
| 1071 |
selected.cut (); |
| 1072 |
} |
| 1073 |
return true; |
| 1074 |
} |
| 1075 |
|
| 1076 |
if (control_pressed && (key == 'v' || key == 'V')) { |
| 1077 |
this.manager.paste (); |
| 1078 |
} |
| 1079 |
|
| 1080 |
if (key == DELETE_KEY) { |
| 1081 |
if (selected == null) { |
| 1082 |
// I feel this is too drastic |
| 1083 |
// this.manager.trash (); |
| 1084 |
} else { |
| 1085 |
|
| 1086 |
for (int i = 0; i < selecteds.length; i++) { |
| 1087 |
ItemView isel = selecteds[i]; |
| 1088 |
if (isel != null) { |
| 1089 |
if (shift_pressed) { |
| 1090 |
isel.delete_dialog (); |
| 1091 |
} else { |
| 1092 |
isel.trash (); |
| 1093 |
} |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
} |
| 1099 |
return true; |
| 1100 |
} |
| 1101 |
|
| 1102 |
if (key == F2_KEY) { |
| 1103 |
flag_is_editing = true; |
| 1104 |
if (selected != null) { |
| 1105 |
selected.start_editing (); |
| 1106 |
return true; |
| 1107 |
} else { |
| 1108 |
this.label.start_editing (); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
if (selected != null && key == ENTER_KEY) { |
| 1113 |
selected.execute (); |
| 1114 |
return true; |
| 1115 |
} |
| 1116 |
|
| 1117 |
if (key == ARROW_LEFT_KEY) { |
| 1118 |
// left arrow pressed |
| 1119 |
move_selected_to ((a, b) => { |
| 1120 |
return (b.y >= a.y && b.y <= (a.y + a.height)) || (a.y >= b.y && a.y <= (b.y + b.height)); |
| 1121 |
}, (a, b) => { |
| 1122 |
return a.x < b.x; |
| 1123 |
}); |
| 1124 |
} |
| 1125 |
if (key == ARROW_UP_KEY) { |
| 1126 |
// up arrow pressed |
| 1127 |
move_selected_to ((a, b) => { |
| 1128 |
return (b.x >= a.x && b.x <= (a.x + a.width)) || (a.x >= b.x && a.x <= (b.x + b.width)); |
| 1129 |
}, (a, b) => { |
| 1130 |
return a.y < b.y; |
| 1131 |
}); |
| 1132 |
} |
| 1133 |
if (key == ARROW_RIGHT_KEY) { |
| 1134 |
// right arrow pressed |
| 1135 |
move_selected_to ((a, b) => { |
| 1136 |
return (b.y >= a.y && b.y <= (a.y + a.height)) || (a.y >= b.y && a.y <= (b.y + b.height)); |
| 1137 |
}, (a, b) => { |
| 1138 |
return a.x > b.x; |
| 1139 |
}); |
| 1140 |
} |
| 1141 |
if (key == ARROW_DOWN_KEY) { |
| 1142 |
// down arrow pressed |
| 1143 |
move_selected_to ((a, b) => { |
| 1144 |
return (b.x >= a.x && b.x <= (a.x + a.width)) || (a.x >= b.x && a.x <= (b.x + b.width)); |
| 1145 |
}, (a, b) => { |
| 1146 |
return a.y > b.y; |
| 1147 |
}); |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
return false; |
| 1152 |
} |
| 1153 |
|
| 1154 |
/** |
| 1155 |
* @name CompareAllocations |
| 1156 |
* @description Comparator of GtkAllocation objects to order the selection with the keyboard |
| 1157 |
* @return {bool} if the a element is greater than the b element |
| 1158 |
*/ |
| 1159 |
private delegate bool CompareAllocations (Gtk.Allocation a, Gtk.Allocation b); |
| 1160 |
|
| 1161 |
/** |
| 1162 |
* @name move_selected_to |
| 1163 |
* @description select the next item following a direction |
| 1164 |
* @param {CompareAllocations} same_axis a function to check that the next item is on the same axis than the previous one |
| 1165 |
* @param {CompareAllocations} is_selectable a function to check that the next item is in the correct direction |
| 1166 |
*/ |
| 1167 |
private void move_selected_to (CompareAllocations same_axis, CompareAllocations is_selectable) { |
| 1168 |
Gee.List <ItemView> selecteds = this.manager.get_selected_items (); |
| 1169 |
ItemView actual_item = null; |
| 1170 |
if (selecteds.size > 0) { |
| 1171 |
actual_item = selecteds.@get (0); |
| 1172 |
} |
| 1173 |
if (actual_item == null) { |
| 1174 |
actual_item = (ItemView) this.container.get_children ().nth_data (0); |
| 1175 |
if (actual_item == null) { |
| 1176 |
debug ("There are not widgets on the folder."); |
| 1177 |
return; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
Gtk.Allocation actual_allocation; |
| 1181 |
actual_item.get_allocation (out actual_allocation); |
| 1182 |
ItemView next_item = null; |
| 1183 |
Gtk.Allocation next_allocation = actual_allocation; |
| 1184 |
|
| 1185 |
List <weak Gtk.Widget> children = this.container.get_children (); |
| 1186 |
foreach (Gtk.Widget elem in children) { |
| 1187 |
Gtk.Allocation elem_allocation; |
| 1188 |
elem.get_allocation (out elem_allocation); |
| 1189 |
if (same_axis (elem_allocation, actual_allocation) && is_selectable (elem_allocation, actual_allocation)) { |
| 1190 |
if (next_item == null) { |
| 1191 |
// If this is the first element is selectable found |
| 1192 |
next_allocation = elem_allocation; |
| 1193 |
next_item = (ItemView) elem; |
| 1194 |
} else if (!is_selectable (elem_allocation, next_allocation)) { |
| 1195 |
// If it is nearer from the last found |
| 1196 |
next_allocation = elem_allocation; |
| 1197 |
next_item = (ItemView) elem; |
| 1198 |
} |
| 1199 |
} |
| 1200 |
} |
| 1201 |
if (next_item != null) { |
| 1202 |
next_item.select_only (); |
| 1203 |
} else { |
| 1204 |
debug ("There are no elements on this direction"); |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
/** |
| 1209 |
* @name new_desktop_folder |
| 1210 |
* @description create a new desktop folder |
| 1211 |
*/ |
| 1212 |
protected void new_desktop_folder (int x, int y) { |
| 1213 |
DesktopFolder.Util.create_new_desktop_folder (this, x, y); |
| 1214 |
} |
| 1215 |
|
| 1216 |
/** |
| 1217 |
* @name new_link_panel |
| 1218 |
* @description create a new link panel |
| 1219 |
*/ |
| 1220 |
protected void new_link_panel (int x, int y) { |
| 1221 |
DesktopFolder.Util.create_new_link_panel (this, x, y); |
| 1222 |
} |
| 1223 |
|
| 1224 |
/* |
| 1225 |
* @name new_note |
| 1226 |
* @description create a new note |
| 1227 |
*/ |
| 1228 |
protected void new_note (int x, int y) { |
| 1229 |
DesktopFolder.Util.create_new_note (this, x, y); |
| 1230 |
} |
| 1231 |
|
| 1232 |
/** |
| 1233 |
* @name new_photo |
| 1234 |
* @description create a new photo |
| 1235 |
*/ |
| 1236 |
protected void new_photo (int x, int y) { |
| 1237 |
DesktopFolder.Util.create_new_photo (this, x, y); |
| 1238 |
} |
| 1239 |
|
| 1240 |
/** |
| 1241 |
* @name open_terminal |
| 1242 |
* @description Open terminal here |
| 1243 |
*/ |
| 1244 |
protected void open_terminal () { |
| 1245 |
string path = this.manager.get_absolute_path (); |
| 1246 |
this.manager.open_terminal_here (path); |
| 1247 |
} |
| 1248 |
|
| 1249 |
/** |
| 1250 |
* @name new_folder |
| 1251 |
* @description show a dialog to create a new folder |
| 1252 |
* @param int x the x position where the new folder icon should be generated |
| 1253 |
* @param int y the y position where the new folder icon should be generated |
| 1254 |
*/ |
| 1255 |
protected void new_folder (int x, int y) { |
| 1256 |
string new_name = this.manager.create_new_folder (x, y); |
| 1257 |
|
| 1258 |
GLib.Timeout.add (50, () => { |
| 1259 |
var item = this.manager.get_item_by_filename (new_name); |
| 1260 |
if (item != null) { |
| 1261 |
ItemView itemview = item.get_view (); |
| 1262 |
itemview.start_editing (); |
| 1263 |
} |
| 1264 |
|
| 1265 |
return false; |
| 1266 |
}); |
| 1267 |
} |
| 1268 |
|
| 1269 |
/** |
| 1270 |
* @name new_text_file |
| 1271 |
* @description create a new text file item inside this folder |
| 1272 |
* @param int x the x position where the new item should be placed |
| 1273 |
* @param int y the y position where the new item should be placed |
| 1274 |
*/ |
| 1275 |
protected void new_text_file (int x, int y) { |
| 1276 |
string new_name = this.manager.create_new_text_file (x, y); |
| 1277 |
|
| 1278 |
GLib.Timeout.add (500, () => { |
| 1279 |
// sync algorithm thread need time to react |
| 1280 |
var item = this.manager.get_item_by_filename (new_name); |
| 1281 |
if (item != null) { |
| 1282 |
ItemView itemview = item.get_view (); |
| 1283 |
itemview.start_editing (); |
| 1284 |
} |
| 1285 |
|
| 1286 |
return false; |
| 1287 |
}); |
| 1288 |
} |
| 1289 |
|
| 1290 |
/** |
| 1291 |
* @name new_link |
| 1292 |
* @description create a new link item inside this folder |
| 1293 |
* @param int x the x position where the new item should be placed |
| 1294 |
* @param int y the y position where the new item should be placed |
| 1295 |
* @param bool folder to indicate if we want to select a folder or a file |
| 1296 |
*/ |
| 1297 |
protected void new_link (int x, int y, bool folder) { |
| 1298 |
Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog ( |
| 1299 |
DesktopFolder.Lang.DESKTOPFOLDER_LINK_MESSAGE, this, Gtk.FileChooserAction.OPEN, |
| 1300 |
DesktopFolder.Lang.DIALOG_CANCEL, |
| 1301 |
Gtk.ResponseType.CANCEL, |
| 1302 |
DesktopFolder.Lang.DIALOG_SELECT, |
| 1303 |
Gtk.ResponseType.ACCEPT); |
| 1304 |
|
| 1305 |
if (folder) { |
| 1306 |
chooser.set_action (Gtk.FileChooserAction.SELECT_FOLDER); |
| 1307 |
} |
| 1308 |
// Process response: |
| 1309 |
if (chooser.run () == Gtk.ResponseType.ACCEPT) { |
| 1310 |
var filename = chooser.get_filename (); |
| 1311 |
debug ("file:%s", filename); |
| 1312 |
this.manager.create_new_link (filename, x, y); |
| 1313 |
} |
| 1314 |
chooser.close (); |
| 1315 |
} |
| 1316 |
|
| 1317 |
/** |
| 1318 |
* @name unselect_all |
| 1319 |
* @description unselect all the items inside this folder |
| 1320 |
*/ |
| 1321 |
public void unselect_all () { |
| 1322 |
var children = this.container.get_children (); |
| 1323 |
foreach (Gtk.Widget element in children) { |
| 1324 |
((ItemView) element).unselect (); |
| 1325 |
} |
| 1326 |
} |
| 1327 |
|
| 1328 |
/** |
| 1329 |
* @name on_item_moving |
| 1330 |
* @description event capture of an item moving or stop moving |
| 1331 |
* @param {bool} moving if the item started moving or stopped moving |
| 1332 |
*/ |
| 1333 |
public void on_item_moving (bool moving) { |
| 1334 |
this.grid_fade = 0; |
| 1335 |
if (!moving) { |
| 1336 |
// trying to perform a fadeout effect (OMG, just learning) |
| 1337 |
double step = 0.002f; // fade steps |
| 1338 |
int duration = 300; // desired milliseconds |
| 1339 |
double last = step * (duration - 1); |
| 1340 |
for (int i = 0; i < duration; i++) { |
| 1341 |
GLib.Timeout.add (i, () => { |
| 1342 |
this.grid_fade = this.grid_fade + step; |
| 1343 |
if (this.grid_fade == last) { |
| 1344 |
this.grid_fade = 0; |
| 1345 |
this.flag_moving = false; |
| 1346 |
} |
| 1347 |
this.queue_draw (); |
| 1348 |
return false; |
| 1349 |
}); |
| 1350 |
} |
| 1351 |
|
| 1352 |
} else { |
| 1353 |
this.flag_moving = moving; |
| 1354 |
} |
| 1355 |
} |
| 1356 |
|
| 1357 |
/** |
| 1358 |
* @name get_manager |
| 1359 |
* @description return the FolderManager |
| 1360 |
* @return {FolderManager} |
| 1361 |
*/ |
| 1362 |
public FolderManager get_manager () { |
| 1363 |
return this.manager; |
| 1364 |
} |
| 1365 |
|
| 1366 |
private Gdk.Point ? current_point = null; |
| 1367 |
|
| 1368 |
/** |
| 1369 |
* @name on_motion |
| 1370 |
* @description the on_motion event captured |
| 1371 |
* @param EventMotion event @see the on_motion signal |
| 1372 |
* @return bool @see the on_motion signal |
| 1373 |
*/ |
| 1374 |
private bool on_motion (Gdk.EventMotion event) { |
| 1375 |
if (this.press_point != null) { |
| 1376 |
this.current_point = Gdk.Point (); |
| 1377 |
this.current_point.x = (int) event.x; |
| 1378 |
this.current_point.y = (int) event.y; |
| 1379 |
this.queue_draw (); |
| 1380 |
|
| 1381 |
this.manager.select_items (this.get_selected_rectangle ()); |
| 1382 |
} |
| 1383 |
|
| 1384 |
return true; |
| 1385 |
} |
| 1386 |
|
| 1387 |
/** |
| 1388 |
* @name get_selected_rectangle |
| 1389 |
* @description create the rectangle which is being drawed by the selection |
| 1390 |
* @return {Gdk.Rectangle} the rectangle selected |
| 1391 |
*/ |
| 1392 |
private Gdk.Rectangle ? get_selected_rectangle () { |
| 1393 |
if (this.press_point != null) { |
| 1394 |
Gdk.Rectangle sel_rectangle = Gdk.Rectangle (); |
| 1395 |
Gdk.Point point_a = this.press_point; |
| 1396 |
Gdk.Point point_b = this.current_point; |
| 1397 |
int sel_width = point_b.x - point_a.x; |
| 1398 |
int sel_height = point_b.y - point_a.y; |
| 1399 |
|
| 1400 |
sel_rectangle.x = point_a.x; |
| 1401 |
sel_rectangle.y = point_a.y; |
| 1402 |
sel_rectangle.width = sel_width; |
| 1403 |
sel_rectangle.height = sel_height; |
| 1404 |
|
| 1405 |
if (sel_rectangle.width < 0) { |
| 1406 |
sel_rectangle.x = sel_rectangle.x + sel_rectangle.width; |
| 1407 |
sel_rectangle.width = -sel_rectangle.width; |
| 1408 |
} |
| 1409 |
if (sel_rectangle.height < 0) { |
| 1410 |
sel_rectangle.y = sel_rectangle.y + sel_rectangle.height; |
| 1411 |
sel_rectangle.height = -sel_rectangle.height; |
| 1412 |
} |
| 1413 |
|
| 1414 |
// debug("rectangle: %d,%d,%d,%d",sel_rectangle.x,sel_rectangle.y,sel_rectangle.width,sel_rectangle.height); |
| 1415 |
|
| 1416 |
return sel_rectangle; |
| 1417 |
} |
| 1418 |
return null; |
| 1419 |
} |
| 1420 |
|
| 1421 |
/** |
| 1422 |
* @name draw_backgorund |
| 1423 |
* @description draw the folder window background intercepting the draw signal |
| 1424 |
* @param {Cairo.Context} cr the cairo context |
| 1425 |
* @bool @see draw signal |
| 1426 |
*/ |
| 1427 |
private bool draw_background (Cairo.Context cr) { |
| 1428 |
// util code to draw the whole window background (which contains also the decoration and you can size it) |
| 1429 |
// cr.rectangle(0,0,10000,10000); |
| 1430 |
// cr.set_source_rgba (1, 1, 1, 0.2); |
| 1431 |
// cr.fill(); |
| 1432 |
|
| 1433 |
// we must show the grid if it is enabled and an item being moved |
| 1434 |
|
| 1435 |
if (this.press_point != null && this.current_point != null) { |
| 1436 |
Gdk.Point point_a = this.press_point; |
| 1437 |
Gdk.Point point_b = this.current_point; |
| 1438 |
int sel_width = point_b.x - point_a.x; |
| 1439 |
int sel_height = point_b.y - point_a.y; |
| 1440 |
// debug("rectangle: %d,%d - %d,%d",point_a.x,point_a.y,sel_width,sel_height); |
| 1441 |
cr.rectangle (point_a.x, point_a.y, sel_width, sel_height); |
| 1442 |
// cr.set_source_rgba (0, 0.5, 1, 0.1); |
| 1443 |
cr.set_source_rgba (0.2, 0.6, 1, 0.8); |
| 1444 |
cr.stroke (); |
| 1445 |
|
| 1446 |
cr.rectangle (point_a.x, point_a.y, sel_width, sel_height); |
| 1447 |
cr.set_source_rgba (0.2, 0.6, 1, 0.2); |
| 1448 |
cr.fill (); |
| 1449 |
} |
| 1450 |
|
| 1451 |
if (flag_moving == true && this.manager.get_settings ().arrangement_type == FolderArrangement.ARRANGEMENT_TYPE_GRID) { |
| 1452 |
|
| 1453 |
int container_width = this.container.get_allocated_width (); |
| 1454 |
int container_height = this.container.get_allocated_height (); |
| 1455 |
int window_width = this.get_allocated_width (); |
| 1456 |
int window_height = this.get_allocated_height (); |
| 1457 |
// debug("drawing (%d,%d) (%d,%d)",container_width,container_height,window_width,window_height); |
| 1458 |
int width = (container_width > window_width ? container_width : window_width); |
| 1459 |
int height = (container_height > window_height ? container_height : window_height); |
| 1460 |
|
| 1461 |
cr.set_operator (Cairo.Operator.CLEAR); |
| 1462 |
cr.paint (); |
| 1463 |
cr.set_operator (Cairo.Operator.OVER); |
| 1464 |
|
| 1465 |
double vscroll = this.scroll.get_vadjustment ().value; |
| 1466 |
double hscroll = this.scroll.get_hadjustment ().value; |
| 1467 |
// debug("scroll: %f %f",hscroll,vscroll); |
| 1468 |
|
| 1469 |
// TODO hate magic numbers!! |
| 1470 |
cr.rectangle (0, 40, window_width - 14, window_height - 54); |
| 1471 |
cr.clip (); |
| 1472 |
|
| 1473 |
|
| 1474 |
Gtk.Allocation title_allocation; |
| 1475 |
this.get_titlebar ().get_allocation (out title_allocation); |
| 1476 |
// debug("panel: width:%d height:%d",width,height); |
| 1477 |
// debug("header: x:%d y:%d width:%d height:%d",title_allocation.x,title_allocation.y,title_allocation.width,title_allocation.height); |
| 1478 |
|
| 1479 |
int left_padding = FolderArrangement.DEFAULT_EXTERNAL_MARGIN; |
| 1480 |
int top_padding = FolderArrangement.DEFAULT_EXTERNAL_MARGIN; |
| 1481 |
int header = title_allocation.height + top_padding; |
| 1482 |
int margin = this.manager.get_settings ().arrangement_padding; |
| 1483 |
int sensitivity = this.get_manager ().get_arrangement ().get_sensitivity (); |
| 1484 |
|
| 1485 |
// TODO Multiselection!!!!!!!!!!!! |
| 1486 |
int selected_cell_x = 0; |
| 1487 |
int selected_cell_y = 0; |
| 1488 |
|
| 1489 |
if (this.manager.are_items_selected ()) { |
| 1490 |
ItemView selected_item = this.manager.get_selected_items ().@get (0); |
| 1491 |
Gtk.Allocation allocation; |
| 1492 |
selected_item.get_allocation (out allocation); |
| 1493 |
selected_cell_x = (allocation.x + DesktopFolder.ICON_DEFAULT_WIDTH / 2) / (sensitivity + margin); |
| 1494 |
selected_cell_y = (allocation.y + DesktopFolder.ICON_DEFAULT_WIDTH / 2) / (sensitivity + margin); |
| 1495 |
// debug ("selected: %d, %d", selected_i, selected_j); |
| 1496 |
} |
| 1497 |
|
| 1498 |
|
| 1499 |
for (int i = left_padding + DesktopFolder.ItemView.PADDING_X, cell_x = 0; i <= width - left_padding; i += sensitivity + margin, cell_x++) { |
| 1500 |
// debug("-i: %d",i); |
| 1501 |
for (int j = header, cell_y = 0; j <= height - top_padding; j += sensitivity + margin, cell_y++) { |
| 1502 |
// debug("|j: %d",j); |
| 1503 |
cr.rectangle (i - hscroll, j - vscroll, sensitivity, sensitivity); |
| 1504 |
|
| 1505 |
int distance_x = cell_x - selected_cell_x; |
| 1506 |
int distance_y = cell_y - selected_cell_y; |
| 1507 |
if (distance_x < 0) { |
| 1508 |
distance_x = -distance_x; |
| 1509 |
} |
| 1510 |
if (distance_y < 0) { |
| 1511 |
distance_y = -distance_y; |
| 1512 |
} |
| 1513 |
float distance = distance_x; |
| 1514 |
if (distance_y > distance) { |
| 1515 |
distance = distance_y; |
| 1516 |
} |
| 1517 |
distance = (distance) / 20; |
| 1518 |
float alpha = 0.3f; |
| 1519 |
alpha = alpha - distance; |
| 1520 |
|
| 1521 |
if (distance == 0) { |
| 1522 |
alpha = 0f; |
| 1523 |
} else if (cell_x == selected_cell_x || cell_y == selected_cell_y) { |
| 1524 |
alpha = 0.4f - distance + 0.1f; |
| 1525 |
if (alpha < 0.02) { |
| 1526 |
alpha = 0.02f; |
| 1527 |
} |
| 1528 |
} |
| 1529 |
|
| 1530 |
cr.set_source_rgba (1, 1, 1, alpha - this.grid_fade); |
| 1531 |
cr.fill (); |
| 1532 |
|
| 1533 |
cr.rectangle (i - hscroll, j - vscroll, sensitivity, sensitivity); |
| 1534 |
cr.set_line_width (1); |
| 1535 |
// debug("cell (%d,%d) - (%d,%d)",cell_x,cell_y,init_item_cell.x, init_item_cell.y); |
| 1536 |
cr.set_source_rgba (1, 1, 1, alpha + 0.1 - this.grid_fade); |
| 1537 |
if (distance == 0) { |
| 1538 |
cr.set_dash (null, 0); |
| 1539 |
} else { |
| 1540 |
cr.set_dash ({ 1 }, 0); |
| 1541 |
} |
| 1542 |
cr.stroke (); |
| 1543 |
|
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
// drawing the initial cell a bit different |
| 1548 |
if (((FolderArrangementGrid) this.manager.get_arrangement ()).is_dragging ()) { |
| 1549 |
Gdk.Point init_item_cell = ((FolderArrangementGrid) this.manager.get_arrangement ()).get_init_item_cell (); |
| 1550 |
var init_cell_i_start = left_padding + DesktopFolder.ItemView.PADDING_X + (sensitivity + margin) * init_item_cell.x; |
| 1551 |
var init_cell_j_start = header + (sensitivity + margin) * init_item_cell.y; |
| 1552 |
Gdk.Rectangle init_cell_rect = Gdk.Rectangle (); |
| 1553 |
init_cell_rect.x = (int) (init_cell_i_start - hscroll); |
| 1554 |
init_cell_rect.y = (int) (init_cell_j_start - vscroll); |
| 1555 |
init_cell_rect.width = sensitivity; |
| 1556 |
init_cell_rect.height = sensitivity; |
| 1557 |
// first, filling the cell |
| 1558 |
Util.cairo_rounded_rectangle (cr, init_cell_rect.x, init_cell_rect.y, init_cell_rect.width, init_cell_rect.height, 5); |
| 1559 |
cr.set_source_rgba (1, 1, 1, 0.1f - this.grid_fade); |
| 1560 |
cr.fill (); |
| 1561 |
|
| 1562 |
// second, stroking the cell |
| 1563 |
Util.cairo_rounded_rectangle (cr, init_cell_rect.x, init_cell_rect.y, init_cell_rect.width, init_cell_rect.height, 5); |
| 1564 |
cr.set_source_rgba (1, 1, 1, 0.4f - this.grid_fade); |
| 1565 |
// cr.set_dash ({10, 5, 10, 5, 10, 5, 20, 5}, 0); |
| 1566 |
cr.set_dash (null, 0); |
| 1567 |
cr.set_line_width (3); |
| 1568 |
cr.stroke (); |
| 1569 |
|
| 1570 |
} |
| 1571 |
|
| 1572 |
cr.reset_clip (); |
| 1573 |
} |
| 1574 |
|
| 1575 |
base.draw (cr); |
| 1576 |
|
| 1577 |
// we must show the link icon for link panels |
| 1578 |
if (this.manager.is_link ()) { |
| 1579 |
try { |
| 1580 |
int width = this.get_allocated_width (); |
| 1581 |
int height = this.get_allocated_height (); |
| 1582 |
|
| 1583 |
int scale = DesktopFolder.ICON_SIZE / 3; |
| 1584 |
var links = Gdk.cairo_surface_create_from_pixbuf (FolderWindow.LINK_PIXBUF, 1, null); |
| 1585 |
cr.set_source_surface (links, width - scale - 20, height - scale - 20); |
| 1586 |
cr.paint_with_alpha (0.8); |
| 1587 |
} catch (Error e) { |
| 1588 |
stderr.printf ("Error: %s\n", e.message); |
| 1589 |
Util.show_error_dialog ("Error", e.message); |
| 1590 |
} |
| 1591 |
} |
| 1592 |
|
| 1593 |
return true; |
| 1594 |
} |
| 1595 |
|
| 1596 |
} |