Skip to content

Commit

Permalink
Checkpointing.
Browse files Browse the repository at this point in the history
  • Loading branch information
phase1geo committed Nov 8, 2024
1 parent 511e4a0 commit 8fb81c4
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 26 deletions.
132 changes: 132 additions & 0 deletions src/ImageMenu.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2024 (https://github.com/phase1geo/Minder)
*
* 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: Trevor Williams <[email protected]>
*/

using Gtk;

public class ImageMenu : Box {

private MenuButton _mb;
private Box _box;
private int _size = 0;
private int _selected = -1;
private int _current = 0;

public int selected {
get {
return( _selected );
}
set {
if( _selected != value ) {
_selected = value;
var picture = (Picture)Utils.get_child_at_index( _box, _selected );
_mb.child = new Picture.for_paintable( picture.paintable );
}
}
}

public signal void changed( int index );

//-------------------------------------------------------------
// Default constructor
public ImageMenu() {

_box = new Box( Orientation.VERTICAL, 5 ) {
margin_start = 5,
margin_end = 5
};

var popover = new Popover() {
child = _box
};

_mb = new MenuButton() {
valign = Align.CENTER,
popover = popover
};

_mb.activate.connect(() => {
var picture = (Picture)Utils.get_child_at_index( _box, 0 );
_current = 0;
picture.add_css_class( Granite.STYLE_CLASS_VIEW );
});

var key = new EventControllerKey();
_mb.add_controller( key );
key.key_pressed.connect((keyval, keycode, state) => {
var index = _current;
switch( keyval ) {
case Gdk.Key.Down : index = ((_current == (_size - 1)) ? _current : (_current + 1)); break;
case Gdk.Key.Up : index = ((_current == 0) ? _current : (_current - 1)); break;
case Gdk.Key.Return :
case Gdk.Key.space :
selected = _current;
changed( _current );
_mb.popover.popdown();
break;
case Gdk.Key.Escape :
_mb.popover.popdown();
break;
}
var before = (Picture)Utils.get_child_at_index( _box, _current );
before.remove_css_class( Granite.STYLE_CLASS_VIEW );
if( index != _current ) {
var after = (Picture)Utils.get_child_at_index( _box, index );
after.add_css_class( Granite.STYLE_CLASS_VIEW );
}
return( false );
});


append( _mb );

}

//-------------------------------------------------------------
// Add a button to this model
public void add_image( Gdk.Paintable image ) {

stdout.printf( "Adding image menu item %d\n", _size );

var entry = new Picture.for_paintable( image );
var index = _size++;

var click = new GestureClick();
entry.add_controller( click );
click.pressed.connect((n_press, x, y) => {
selected = index;
_mb.popover.popdown();
changed( index );
});

var motion = new EventControllerMotion();
entry.add_controller( motion );
motion.enter.connect(() => {
entry.add_css_class( Granite.STYLE_CLASS_VIEW );
});
motion.leave.connect(() => {
entry.remove_css_class( Granite.STYLE_CLASS_VIEW );
});

_box.append( entry );

}

}
2 changes: 1 addition & 1 deletion src/ModeButtons.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ModeButtons : Box {
set {
if( _selected != value ) {
_selected = value;
var button = (CheckButton)Utils.get_child_at_index( this, value );
var button = (ToggleButton)Utils.get_child_at_index( this, value );
button.active = true;
}
}
Expand Down
36 changes: 11 additions & 25 deletions src/StyleInspector.vala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class StyleInspector : Box {
private ModeButtons _link_types;
private Scale _link_width;
private Switch _link_arrow;
private Picture _link_dash;
private ImageMenu _link_dash;
private ModeButtons _node_borders;
private Scale _node_borderwidth;
private Switch _node_fill;
Expand Down Expand Up @@ -370,38 +370,24 @@ public class StyleInspector : Box {

var dashes = styles.get_link_dashes();

_link_dash = new Picture.for_paintable( dashes.index( 0 ).make_icon() );
_link_dash = new ImageMenu() {
halign = Align.END
};

_link_dash.changed.connect((index) => {
_da.undo_buffer.add_item( new UndoStyleLinkDash( _affects, dashes.index( index ), _da ) );
});

var menu = new GLib.Menu();
/* TODO - Need to figure out how to display the paintables
for( int i=0; i<dashes.length; i++ ) {
var dash = dashes.index( i );
var img = new Image.from_paintable( dash.make_icon() );
var mi = new Gtk.MenuItem( );
mi.activate.connect(() => {
_da.undo_buffer.add_item( new UndoStyleLinkDash( _affects, dash, _da ) );
_link_dash.paintable = img.paintable;
});
mi.add( img );
menu.add( mi );
_link_dash.add_image( dashes.index( i ).make_icon() );
}
*/

var popover = new Popover();

var mb = new MenuButton() {
halign = Align.END,
valign = Align.CENTER,
child = _link_dash,
popover = popover
};

var box = new Box( Orientation.HORIZONTAL, 0 ) {
halign = Align.FILL,
homogeneous = true
};
box.append( lbl );
box.append( mb );
box.append( _link_dash );

return( box );

Expand Down Expand Up @@ -1440,7 +1426,7 @@ public class StyleInspector : Box {
var link_dashes = styles.get_link_dashes();
for( int i=0; i<link_dashes.length; i++ ) {
if( link_dashes.index( i ).name == style.link_dash.name ) {
_link_dash.paintable = link_dashes.index( i ).make_icon();
_link_dash.selected = i;
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sources += files(
'HtmlToMarkdown.vala',
'ImageEditor.vala',
'ImageManager.vala',
'ImageMenu.vala',
'Layout.vala',
'Layouts.vala',
'LinkDash.vala',
Expand Down

0 comments on commit 8fb81c4

Please sign in to comment.