Skip to content

Commit 4da1c3e

Browse files
committed
works!
1 parent e6d4107 commit 4da1c3e

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

TODO

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
the keyboard focus is somewhere else, and left-click on rowview
66
buttons or on workspace background does not grab the focus
77

8-
- could right-click on a region label pop up the rowview menu?
9-
10-
difficult with the structure we have now
11-
12-
have a custom menu and reimplement actions there
13-
148
- put region snap back?
159

1610
- maxpos, then create mark from coordinate should be two clicks

src/gtk/imagewindow.ui

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,25 @@
117117
<section>
118118
<item>
119119
<attribute name='label' translatable='yes'>Duplicate</attribute>
120+
<attribute name="action">win.region-duplicate</attribute>
120121
</item>
121122
<item>
122123
<attribute name='label' translatable='yes'>Reset</attribute>
124+
<attribute name="action">win.region-reset</attribute>
123125
</item>
124126
</section>
125127

126128
<section>
127129
<item>
128130
<attribute name='label' translatable='yes'>Save as ...</attribute>
131+
<attribute name="action">win.region-saveas</attribute>
129132
</item>
130133
</section>
131134

132135
<section>
133136
<item>
134137
<attribute name='label' translatable='yes'>Delete</attribute>
138+
<attribute name="action">win.region-delete</attribute>
135139
</item>
136140
</section>
137141
</menu>
@@ -273,6 +277,12 @@
273277
</object>
274278
</child>
275279

280+
<child>
281+
<object class="GtkPopoverMenu" id="region_menu">
282+
<property name="menu-model">imagewindow-region-menu</property>
283+
</object>
284+
</child>
285+
276286
</object>
277287
</child>
278288

@@ -289,11 +299,5 @@
289299
</object>
290300
</child>
291301

292-
<child>
293-
<object class="GtkPopoverMenu" id="region_menu">
294-
<property name="menu-model">imagewindow-region-menu</property>
295-
</object>
296-
</child>
297-
298302
</template>
299303
</interface>

src/imagewindow.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,45 @@ imagewindow_properties(GSimpleAction *action,
12161216
g_simple_action_set_state(action, state);
12171217
}
12181218

1219+
static void
1220+
imagewindow_region_action(GSimpleAction *action,
1221+
GVariant *state, gpointer user_data)
1222+
{
1223+
Imagewindow *win = IMAGEWINDOW(user_data);
1224+
1225+
if (win->action_view &&
1226+
IS_REGIONVIEW(win->action_view)) {
1227+
const char *name = g_action_get_name(G_ACTION(action));
1228+
Regionview *regionview = REGIONVIEW(win->action_view);
1229+
Row *row = HEAPMODEL(regionview->classmodel)->row;
1230+
Workspace *ws = row->ws;
1231+
1232+
if (g_str_equal(name, "region-duplicate")) {
1233+
row_select(row);
1234+
if (!workspace_selected_duplicate(ws))
1235+
workspace_set_show_error(row->ws, TRUE);
1236+
workspace_deselect_all(ws);
1237+
1238+
symbol_recalculate_all();
1239+
}
1240+
else if (g_str_equal(name, "region-reset")) {
1241+
(void) icontainer_map_all(ICONTAINER(row),
1242+
(icontainer_map_fn) model_clear_edited, NULL);
1243+
1244+
symbol_recalculate_all();
1245+
}
1246+
else if (g_str_equal(name, "region-saveas")) {
1247+
Model *graphic = row->child_rhs->graphic;
1248+
1249+
classmodel_graphic_save(CLASSMODEL(graphic), GTK_WINDOW(win));
1250+
}
1251+
else if (g_str_equal(name, "region-delete"))
1252+
IDESTROY(row->sym);
1253+
1254+
win->action_view = NULL;
1255+
}
1256+
}
1257+
12191258
static GActionEntry imagewindow_entries[] = {
12201259
{ "copy", imagewindow_copy_action },
12211260
{ "paste", imagewindow_paste_action },
@@ -1250,6 +1289,12 @@ static GActionEntry imagewindow_entries[] = {
12501289
imagewindow_background },
12511290

12521291
{ "reset", imagewindow_reset },
1292+
1293+
{ "region-duplicate", imagewindow_region_action },
1294+
{ "region-reset", imagewindow_region_action },
1295+
{ "region-saveas", imagewindow_region_action },
1296+
{ "region-delete", imagewindow_region_action },
1297+
12531298
};
12541299

12551300
static void
@@ -1367,8 +1412,10 @@ imagewindow_pressed(GtkGestureClick *gesture,
13671412
menu = win->region_menu;
13681413
win->action_view = VIEW(regionview);
13691414
}
1370-
else
1415+
else {
13711416
menu = win->right_click_menu;
1417+
win->action_view = NULL;
1418+
}
13721419

13731420
gtk_popover_set_pointing_to(GTK_POPOVER(menu),
13741421
&(const GdkRectangle){ x, y, 1, 1 });

0 commit comments

Comments
 (0)