Skip to content

Commit f974c8c

Browse files
committed
Replace deprecated Gtk widgets and dialogs with modern alternatives
- Switch from GtkComboBoxText to GtkDropDown in preferences UI - Replace Gtk.MessageDialog with Gtk.AlertDialog for alerts - Remove deprecated dialog wrappers in DialogUtils - Update sidebar file removal to use Gtk.AlertDialog - Remove debug print statements and unused Gtk.Box children - Refactor preferences logic for new dropdowns - Simplify async error handling in WebView update
1 parent e9db66e commit f974c8c

File tree

9 files changed

+64
-145
lines changed

9 files changed

+64
-145
lines changed

data/ui/prefs_window.ui

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
<object class="HeSettingsRow">
1616
<property name="title">Font Type</property>
1717
<child>
18-
<object class="GtkComboBoxText" id="font_type">
19-
<items>
20-
<item translatable="yes">Quilt Mono</item>
21-
<item translatable="yes">Quilt Zwei</item>
22-
<item translatable="yes">Quilt Vier</item>
23-
</items>
18+
<object class="GtkDropDown" id="font_type">
2419
</object>
2520
</child>
2621
</object>
@@ -139,12 +134,7 @@
139134
<object class="HeSettingsRow">
140135
<property name="title">Preview Font Type</property>
141136
<child>
142-
<object class="GtkComboBoxText" id="preview_font_type">
143-
<items>
144-
<item translatable="yes">Serif</item>
145-
<item translatable="yes">Sans-serif</item>
146-
<item translatable="yes">Monospace</item>
147-
</items>
137+
<object class="GtkDropDown" id="preview_font_type">
148138
</object>
149139
</child>
150140
</object>

data/ui/sidebar.ui

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,13 @@
145145
</object>
146146
<template class="QuilterWidgetsSideBar" parent="HeBin">
147147
<property name="vexpand">1</property>
148-
<property name="hexpand">0</property>
149-
<property name="width-request">270</property>
150148
<child>
151149
<object class="GtkBox" id="navbox">
152150
<child>
153151
<object class="GtkBox">
154152
<property name="orientation">vertical</property>
155153
<child>
156154
<object class="HeAppBar">
157-
<property name="width-request">113</property>
158155
</object>
159156
</child>
160157
<child>
@@ -167,6 +164,7 @@
167164
<child>
168165
<object class="HeSideBar" id="flap">
169166
<property name="has-margins">0</property>
167+
<property name="width-request">280</property>
170168
<property name="show-left-title-buttons">0</property>
171169
<property name="vexpand">1</property>
172170
<property name="hexpand">1</property>

src/Application.vala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,9 @@ namespace Quilter {
169169
// Notify the user that something happened.
170170
if (msg.length > 0) {
171171
var parent_win = get_last_win () as Gtk.Window;
172-
var dialog = new Gtk.MessageDialog (parent_win,
173-
Gtk.DialogFlags.MODAL,
174-
Gtk.MessageType.WARNING,
175-
Gtk.ButtonsType.CLOSE,
176-
msg);
177-
dialog.show ();
178-
dialog.close ();
172+
var alert = new Gtk.AlertDialog (msg);
173+
alert.set_modal (true);
174+
alert.show (parent_win);
179175
}
180176
}
181177

src/MainWindow.vala

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ namespace Quilter {
244244

245245
private void setup_signals () {
246246
Quilter.Application.gsettings.changed.connect (on_settings_changed);
247-
appbar.open.connect (() => { print ("DEBUG: open clicked\n"); on_open (); });
248-
appbar.save.connect (() => { print ("DEBUG: save clicked\n"); on_save (); });
249-
appbar.save_as.connect (() => { print ("DEBUG: save_as clicked\n"); on_save_as (); });
250-
appbar.create_new.connect (() => { print ("DEBUG: new clicked\n"); on_create_new (); });
247+
appbar.open.connect (on_open);
248+
appbar.save.connect (on_save);
249+
appbar.save_as.connect (on_save_as);
250+
appbar.create_new.connect (on_create_new);
251251
appbar.preview_toggled.connect (on_preview_toggled);
252252
toggle_sidebar.connect (on_toggle_sidebar);
253253
focus_overlay_button.clicked.connect (() => {
@@ -521,7 +521,6 @@ namespace Quilter {
521521
}
522522

523523
private void on_create_new () {
524-
print ("DEBUG: on_create_new()\n");
525524
create_new_document ();
526525
file_manager.save_open_files (this);
527526
}
@@ -543,26 +542,19 @@ namespace Quilter {
543542
}
544543

545544
private void on_open () {
546-
print ("DEBUG: on_open()\n");
547545
on_open_async.begin ((obj, res) => {
548-
try {
549-
on_open_async.end (res);
550-
} catch (Error e) {
551-
warning ("Error in open operation: %s", e.message);
552-
}
546+
on_open_async.end (res);
553547
});
554548
}
555549

556550
private async void on_open_async () {
557-
print ("DEBUG: on_open_async() start\n");
558551
if (is_opening)return;
559552
is_opening = true;
560553

561554
try {
562555
var result = yield file_manager.open (this);
563-
556+
564557
if (result == null) {
565-
print ("DEBUG: open canceled or null result\n");
566558
is_opening = false;
567559
return;
568560
}
@@ -593,7 +585,6 @@ namespace Quilter {
593585
}
594586

595587
private void on_save () {
596-
print ("DEBUG: on_save()\n");
597588
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
598589
if (row == null) {
599590
// Fallback to current-file if no row is selected
@@ -614,7 +605,6 @@ namespace Quilter {
614605
try {
615606
// If this is a temp/unsaved file, route to Save As
616607
if (file_manager.is_temp_file (row.path)) {
617-
print ("DEBUG: on_save() -> temp file, delegating to Save As\n");
618608
on_save_as ();
619609
return;
620610
}
@@ -632,18 +622,12 @@ namespace Quilter {
632622
}
633623

634624
private void on_save_as () {
635-
print ("DEBUG: on_save_as()\n");
636625
on_save_as_async.begin ((obj, res) => {
637-
try {
638-
on_save_as_async.end (res);
639-
} catch (Error e) {
640-
warning ("Error in save as operation: %s", e.message);
641-
}
626+
on_save_as_async.end (res);
642627
});
643628
}
644629

645630
private async void on_save_as_async () {
646-
print ("DEBUG: on_save_as_async() start\n");
647631
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
648632
if (row == null) {
649633
// Fallback to current-file if no row is selected
@@ -665,7 +649,6 @@ namespace Quilter {
665649
string new_path = yield file_manager.save_as (edit_view_content.text, this);
666650

667651
if (new_path != "") {
668-
print ("DEBUG: save_as -> new path: %s\n", new_path);
669652
edit_view_content.modified = false;
670653
update_samenu_title (new_path);
671654
row.path = new_path;

src/Services/DialogUtils.vala

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,57 +47,5 @@ namespace Quilter.Services.DialogUtils {
4747
return response;
4848
}
4949

50-
public class Dialog : He.Bin {
51-
public MainWindow win { get; construct; }
52-
public Gtk.MessageDialog dialog;
53-
54-
public Dialog (MainWindow win) {
55-
Object (win: win);
56-
57-
dialog = new Gtk.MessageDialog (
58-
win,
59-
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
60-
Gtk.MessageType.QUESTION,
61-
Gtk.ButtonsType.NONE,
62-
_("Save Open File?")
63-
);
64-
65-
dialog.secondary_text = _("There are unsaved changes to the file, any changes will be lost if not saved.");
66-
67-
dialog.add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
68-
dialog.add_button (_("Close Without Saving"), Gtk.ResponseType.REJECT);
69-
dialog.add_button (_("Save"), Gtk.ResponseType.ACCEPT);
70-
71-
dialog.set_default_response (Gtk.ResponseType.ACCEPT);
72-
73-
this.child = dialog;
74-
}
75-
}
76-
77-
public class Dialog2 : He.Bin {
78-
public MainWindow win { get; construct; }
79-
public Gtk.MessageDialog dialog;
80-
81-
public Dialog2 (MainWindow win) {
82-
Object (win: win);
83-
84-
dialog = new Gtk.MessageDialog (
85-
win,
86-
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
87-
Gtk.MessageType.QUESTION,
88-
Gtk.ButtonsType.NONE,
89-
_("Remove File From Sidebar?")
90-
);
91-
92-
dialog.secondary_text = _("By removing this file from the Sidebar, any changes will be lost if not saved.");
93-
94-
dialog.add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
95-
dialog.add_button (_("Remove Without Saving"), Gtk.ResponseType.REJECT);
96-
dialog.add_button (_("Save"), Gtk.ResponseType.ACCEPT);
97-
98-
dialog.set_default_response (Gtk.ResponseType.ACCEPT);
99-
100-
this.child = dialog;
101-
}
102-
}
50+
// Note: Deprecated MessageDialog wrappers were removed.
10351
}

src/Widgets/Preferences.vala

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Quilter {
2020
[GtkTemplate (ui = "/io/github/lainsce/Quilter/prefs_window.ui")]
2121
public class Widgets.Preferences : He.SettingsWindow {
2222
[GtkChild]
23-
unowned Gtk.ComboBoxText font_type;
23+
unowned Gtk.DropDown font_type;
2424
[GtkChild]
2525
unowned Gtk.Switch autosave;
2626
[GtkChild]
@@ -34,7 +34,7 @@ namespace Quilter {
3434
[GtkChild]
3535
public unowned Gtk.CheckButton scope_sentence;
3636
[GtkChild]
37-
unowned Gtk.ComboBoxText preview_font_type;
37+
unowned Gtk.DropDown preview_font_type;
3838
[GtkChild]
3939
unowned Gtk.Switch center;
4040
[GtkChild]
@@ -53,14 +53,26 @@ namespace Quilter {
5353
}
5454

5555
private void preferences_connect () {
56-
font_type.active = Quilter.Application.gsettings.get_enum ("edit-font");
57-
font_type.changed.connect (() => {
58-
Quilter.Application.gsettings.set_enum ("edit-font", font_type.active);
56+
// Editor font type dropdown
57+
var edit_list = new Gtk.StringList (null);
58+
edit_list.append ("Quilt Mono");
59+
edit_list.append ("Quilt Zwei");
60+
edit_list.append ("Quilt Vier");
61+
font_type.set_model (edit_list);
62+
font_type.selected = (uint) Quilter.Application.gsettings.get_enum ("edit-font");
63+
font_type.notify["selected"].connect (() => {
64+
Quilter.Application.gsettings.set_enum ("edit-font", (int) font_type.selected);
5965
});
6066

61-
preview_font_type.active = Quilter.Application.gsettings.get_enum ("preview-font");
62-
preview_font_type.changed.connect (() => {
63-
Quilter.Application.gsettings.set_enum ("preview-font", preview_font_type.active);
67+
// Preview font type dropdown
68+
var prev_list = new Gtk.StringList (null);
69+
prev_list.append ("Serif");
70+
prev_list.append ("Sans-serif");
71+
prev_list.append ("Monospace");
72+
preview_font_type.set_model (prev_list);
73+
preview_font_type.selected = (uint) Quilter.Application.gsettings.get_enum ("preview-font");
74+
preview_font_type.notify["selected"].connect (() => {
75+
Quilter.Application.gsettings.set_enum ("preview-font", (int) preview_font_type.selected);
6476
});
6577

6678
scope_paragraph.toggled.connect (() => {

src/Widgets/SearchBar.vala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ namespace Quilter {
3939

4040
[GtkChild]
4141
public unowned Gtk.Revealer searchbar;
42-
[GtkChild]
43-
private unowned Gtk.Box box1;
44-
[GtkChild]
45-
private unowned Gtk.Box box2;
4642

4743
public GtkSource.SearchContext search_context = null;
4844
public weak MainWindow window { get; construct; }

src/Widgets/SideBar.vala

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -329,37 +329,39 @@ namespace Quilter.Widgets {
329329
}
330330

331331
private void remove_file (SideBarBox box) {
332-
var dialog = new Gtk.MessageDialog (win,
333-
Gtk.DialogFlags.MODAL,
334-
Gtk.MessageType.QUESTION,
335-
Gtk.ButtonsType.YES_NO,
336-
_("Remove this file from the sidebar?"));
337-
dialog.secondary_text = _("This will not delete the file from your computer.");
338-
339-
dialog.response.connect ((response) => {
340-
if (response == Gtk.ResponseType.YES) {
341-
column.remove (box);
342-
343-
// Select next available row
344-
var next_row = column.get_selected_row ();
345-
if (next_row == null) {
346-
next_row = column.get_row_at_index (0);
347-
}
332+
var alert = new Gtk.AlertDialog (_("Remove this file from the sidebar?"));
333+
alert.set_detail (_("This will not delete the file from your computer."));
334+
alert.set_modal (true);
335+
alert.set_buttons ({ _("Cancel"), _("Remove") });
336+
alert.set_cancel_button (0);
337+
alert.set_default_button (1);
338+
339+
alert.choose.begin (win, null, (obj, res) => {
340+
try {
341+
int idx = alert.choose.end (res);
342+
if (idx == 1) {
343+
column.remove (box);
344+
345+
// Select next available row
346+
var next_row = column.get_selected_row ();
347+
if (next_row == null) {
348+
next_row = column.get_row_at_index (0);
349+
}
348350

349-
if (next_row != null) {
350-
column.select_row (next_row);
351-
} else {
352-
win.edit_view_content.buffer.text = "";
353-
win.edit_view_content.modified = false;
354-
store.clear ();
355-
}
351+
if (next_row != null) {
352+
column.select_row (next_row);
353+
} else {
354+
win.edit_view_content.buffer.text = "";
355+
win.edit_view_content.modified = false;
356+
store.clear ();
357+
}
356358

357-
Services.FileManager.get_instance ().save_open_files (win);
359+
Services.FileManager.get_instance ().save_open_files (win);
360+
}
361+
} catch (Error e) {
362+
warning ("Alert error: %s", e.message);
358363
}
359-
dialog.destroy ();
360364
});
361-
362-
dialog.show ();
363365
}
364366

365367
// Legacy compatibility methods

src/Widgets/WebView.vala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,7 @@ namespace Quilter {
209209
}
210210

211211
public async void update_html_view_async () {
212-
try {
213-
warning ("Starting update_html_view_async\n");
214-
update_html_view ();
215-
warning ("Finished update_html_view_async\n");
216-
} catch (Error e) {
217-
warning ("Error in update_html_view_async: %s\n", e.message);
218-
}
212+
update_html_view ();
219213
yield;
220214
}
221215

0 commit comments

Comments
 (0)