Skip to content

Commit

Permalink
Drag and drop to reorder layers, double click to edit, created class …
Browse files Browse the repository at this point in the history
…to handle layers
  • Loading branch information
Alecaddd committed Mar 1, 2018
1 parent daa9299 commit af673ad
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 41 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ executable(
'src/Layouts/RightSideBar.vala',
'src/Layouts/StatusBar.vala',
'src/Layouts/Partials/LayersPanel.vala',
'src/Layouts/Partials/Layer.vala',
'src/Partials/HeaderBarButton.vala',
'src/Partials/MenuButton.vala',
'src/Widgets/SettingsDialog.vala',
Expand Down
75 changes: 75 additions & 0 deletions src/Layouts/Partials/Layer.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2018 Alecaddd (http://alecaddd.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Alessandro "Alecaddd" Castellani <[email protected]>
*/
public class Akira.Layouts.Partials.Layer : Granite.Widgets.SourceList.ExpandableItem, Granite.Widgets.SourceListDragSource, Granite.Widgets.SourceListDragDest {
public weak Akira.Window window { get; construct; }
// public Akira.Shape shape { get; construct; }

public Granite.Widgets.SourceList layers;

public Layer (Akira.Window main_window, string layer_name, string? icon_name) {
Object (window: main_window);
name = layer_name;

if (icon_name != null) {
try {
icon = new Gdk.Pixbuf.from_resource (icon_name);
} catch (Error e) {
warning (e.message);
}
}
}

construct {
selectable = true;
editable = true;

edited.connect (rename);
expand_all ();
}

protected void rename (string new_name) {
warning (new_name);
}

public void prepare_selection_data (Gtk.SelectionData selection_data) {

}

public bool draggable () {
return true;
}

private bool data_drop_possible (Gdk.DragContext context, Gtk.SelectionData data) {
var targets = window.main_window.right_sidebar.layers_panel.layers.root.children;
foreach (var target in targets) {
if (target == this) {
return true;
}
}
return false;
}

private Gdk.DragAction data_received (Gdk.DragContext context, Gtk.SelectionData data) {
var received = data.get_text ();
warning (received);
return Gdk.DragAction.COPY;
}
}
53 changes: 12 additions & 41 deletions src/Layouts/Partials/LayersPanel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,66 +55,37 @@ public class Akira.Layouts.Partials.LayersPanel : Gtk.Grid {
private Granite.Widgets.SourceList build_layers () {
layers = new Granite.Widgets.SourceList ();

var artboard = new Granite.Widgets.SourceList.ExpandableItem ("Artboard 1");
artboard.editable = true;
artboard.expand_all ();
var artboard = new Akira.Layouts.Partials.Layer (window, "Artboard 1", null);

var rectangle_item = new Granite.Widgets.SourceList.Item ("Rectangle");
rectangle_item.editable = true;
// rectangle_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/rectangle.svg");

var circle_item = new Granite.Widgets.SourceList.Item ("Circle");
circle_item.editable = true;
// circle_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/circle.svg");

var triangle_item = new Granite.Widgets.SourceList.Item ("Triangle");
triangle_item.editable = true;
// triangle_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/triangle.svg");
var rectangle_item = new Akira.Layouts.Partials.Layer (window, "Rectangle", "/com/github/alecaddd/akira/tools/rectangle.svg");
var circle_item = new Akira.Layouts.Partials.Layer (window, "Circle", "/com/github/alecaddd/akira/tools/circle.svg");
var triangle_item = new Akira.Layouts.Partials.Layer (window, "Triangle", "/com/github/alecaddd/akira/tools/triangle.svg");

artboard.add (rectangle_item);
artboard.add (circle_item);
artboard.add (triangle_item);

var artboard2 = new Granite.Widgets.SourceList.ExpandableItem ("Artboard 2");
artboard2.editable = true;
artboard2.expand_all ();
var artboard2 = new Akira.Layouts.Partials.Layer (window, "Artboard 2", null);

var text_item = new Granite.Widgets.SourceList.Item ("Text");
text_item.editable = true;
// text_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/text.svg");
var text_item = new Akira.Layouts.Partials.Layer (window, "Text", "/com/github/alecaddd/akira/tools/text.svg");

artboard2.add (text_item);

var group_rectangle_item = new Granite.Widgets.SourceList.Item ("Rectangle");
group_rectangle_item.editable = true;
// group_rectangle_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/rectangle.svg");

var group_circle_item = new Granite.Widgets.SourceList.Item ("Circle");
group_circle_item.editable = true;
// group_circle_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/circle.svg");
var group_rectangle_item = new Akira.Layouts.Partials.Layer (window, "Rectangle", "/com/github/alecaddd/akira/tools/rectangle.svg");
var group_circle_item = new Akira.Layouts.Partials.Layer (window, "Circle", "/com/github/alecaddd/akira/tools/circle.svg");

var compound_item = new Granite.Widgets.SourceList.ExpandableItem ("Compound Object");
// compound_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/bool-union.svg");
compound_item.editable = true;
compound_item.expand_all ();
var compound_item = new Akira.Layouts.Partials.Layer (window, "Compound Object", "/com/github/alecaddd/akira/tools/bool-union.svg");
compound_item.add (group_rectangle_item);
compound_item.add (group_circle_item);

var group_item = new Granite.Widgets.SourceList.ExpandableItem ("Group");
// group_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/group.svg");
group_item.editable = true;
group_item.expand_all ();
var group_item = new Akira.Layouts.Partials.Layer (window, "Group", "/com/github/alecaddd/akira/tools/group.svg");
group_item.add (compound_item);

artboard2.add (group_item);

var artboard3 = new Granite.Widgets.SourceList.ExpandableItem ("Artboard 3");
artboard3.editable = true;
artboard3.expand_all ();
var artboard3 = new Akira.Layouts.Partials.Layer (window, "Artboard 3", null);

var vector_item = new Granite.Widgets.SourceList.Item ("Vector Path");
vector_item.editable = true;
// vector_item.icon = new Gdk.Pixbuf.from_resource ("/com/github/alecaddd/akira/tools/pen.svg");
var vector_item = new Akira.Layouts.Partials.Layer (window, "Vector Path", "/com/github/alecaddd/akira/tools/pen.svg");

artboard3.add (vector_item);

Expand Down

0 comments on commit af673ad

Please sign in to comment.