Skip to content

Commit c3e4b65

Browse files
committed
Expand list function
1 parent cadecb5 commit c3e4b65

File tree

5 files changed

+116
-45
lines changed

5 files changed

+116
-45
lines changed

src/Application.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public class Jorts.Application : Gtk.Application {
100100
set_accels_for_action ("win.action_toggle_mono", {"<Control>m"});
101101
set_accels_for_action ("win.action_focus_title", {"<Control>L"});
102102
set_accels_for_action ("win.action_show_emoji", {"<Control>period"});
103+
set_accels_for_action ("win.action_toggle_list", {"<Shift>F12"});
103104
set_accels_for_action ("win.action_show_menu", {"<Control>G", "<Control>O"});
104105

105106
set_accels_for_action ("win.action_theme_1", {"<Alt>1"});

src/Views/PreferencesView.vala

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,6 @@
3333
valign = Gtk.Align.START
3434
};
3535

36-
/*************************************************/
37-
/* scribbly Toggle */
38-
/*************************************************/
39-
40-
debug ("Built UI. Lets do connects and binds");
41-
42-
var scribbly_box = new Jorts.SettingsSwitch (
43-
_("Make unfocused notes unreadable"),
44-
_("If enabled, unfocused sticky notes become unreadable to protect their content from peeking eyes (Ctrl+H)"),
45-
"scribbly-mode-active");
46-
47-
settingsbox.append (scribbly_box);
48-
49-
50-
/*************************************************/
51-
/* hidebar Toggle */
52-
/*************************************************/
53-
54-
var hidebar_box = new Jorts.SettingsSwitch (
55-
_("Hide buttons"),
56-
_("If enabled, hides the bottom bar in sticky notes. Keyboard shortcuts will still function (Ctrl+T)"),
57-
"hide-bar");
58-
59-
settingsbox.append (hidebar_box);
60-
6136

6237
/***************************************/
6338
/* lists */
@@ -69,12 +44,13 @@
6944
halign = Gtk.Align.END,
7045
hexpand = false,
7146
valign = Gtk.Align.CENTER,
72-
width_request = 15
47+
max_width_chars = 5
7348
};
7449

7550
var list_label = new Granite.HeaderLabel (_("List item symbol")) {
7651
mnemonic_widget = list_entry,
77-
secondary_text = _("Symbol by which to begin each list item")
52+
secondary_text = _("Prefix by which to begin each item in a list"),
53+
hexpand = true
7854
};
7955

8056
lists_box.append (list_label);
@@ -89,6 +65,31 @@
8965
settingsbox.append (lists_box);
9066

9167

68+
/*************************************************/
69+
/* scribbly Toggle */
70+
/*************************************************/
71+
72+
debug ("Built UI. Lets do connects and binds");
73+
74+
var scribbly_box = new Jorts.SettingsSwitch (
75+
_("Make unfocused notes unreadable"),
76+
_("If enabled, unfocused sticky notes become unreadable to protect their content from peeking eyes (Ctrl+H)"),
77+
"scribbly-mode-active");
78+
79+
settingsbox.append (scribbly_box);
80+
81+
82+
/*************************************************/
83+
/* hidebar Toggle */
84+
/*************************************************/
85+
86+
var hidebar_box = new Jorts.SettingsSwitch (
87+
_("Hide buttons"),
88+
_("If enabled, hides the bottom bar in sticky notes. Keyboard shortcuts will still function (Ctrl+T)"),
89+
"hide-bar");
90+
91+
settingsbox.append (hidebar_box);
92+
9293

9394
/****************************************************/
9495
/* Autostart Request */
@@ -142,10 +143,10 @@
142143
var actionbar = new Gtk.CenterBox () {
143144
margin_start = 5,
144145
margin_end = 5,
145-
valign = Gtk.Align.END
146+
valign = Gtk.Align.END,
147+
hexpand = true,
148+
vexpand = false
146149
};
147-
actionbar.set_hexpand (true);
148-
actionbar.set_vexpand (false);
149150

150151
// Monies?
151152
var support_button = new Gtk.LinkButton.with_label (
@@ -162,13 +163,17 @@
162163
_("Close preferences")
163164
)
164165
};
165-
actionbar.end_widget = close_button;
166166

167-
var reset = new Gtk.Button.from_icon_name ("system-reboot") {
168-
tooltip_markup = _("Reset all settings to defaults")
167+
var reset = new Gtk.Button.from_icon_name ("system-reboot-symbolic") {
168+
tooltip_markup = _("Reset all settings to defaults"),
169+
valign = Gtk.Align.CENTER
169170
};
170171
reset.clicked.connect (on_reset);
171172

173+
var end_box = new Gtk.Box (HORIZONTAL, 5);
174+
end_box.append (reset);
175+
end_box.append (close_button);
176+
actionbar.end_widget = end_box;
172177

173178
append (settingsbox);
174179
append (actionbar);
@@ -177,13 +182,14 @@
177182
private void on_reset () {
178183
debug ("Resetting settings…");
179184

180-
string[] keys = {"scribbly-mode-active", "hide-bar"};
185+
string[] keys = {"scribbly-mode-active", "hide-bar", "list-item-start"};
181186
foreach (var key in keys) {
182187
Application.gsettings.reset (key);
183188
}
184189

185190
#if !WINDOWS
186191
Jorts.Utils.autostart_remove ();
192+
toast.send_notification ();
187193
#endif
188194
}
189195
}

src/Widgets/ActionBar.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
width_request = 32,
5151
height_request = 32,
5252
tooltip_markup = Granite.markup_accel_tooltip (
53-
{"<Control>w"},
53+
{"<Shift>F12"},
5454
_("Toggle list")
5555
)
5656
};
5757
list_button.add_css_class ("themedbutton");
58-
list_button.action_name = StickyNoteWindow.ACTION_PREFIX + StickyNoteWindow.ACTION_LIST;
58+
list_button.action_name = StickyNoteWindow.ACTION_PREFIX + StickyNoteWindow.ACTION_TOGGLE_LIST;
5959

6060

6161
emojichooser_popover = new Gtk.EmojiChooser ();

src/Widgets/TextView.vala

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,89 @@ public class Jorts.TextView : Granite.HyperTextView {
4444
});
4545
}
4646

47-
public void list () {
47+
public void toggle_list () {
4848
Gtk.TextIter start, end;
4949
buffer.get_selection_bounds (out start, out end);
5050

5151
var first_line = (uint8)start.get_line ();
5252
var last_line = (uint8)end.get_line ();
5353
debug ("got " + first_line.to_string () + " to " + last_line.to_string ());
5454

55-
Gtk.TextIter startline;
5655
var list_item_start = Application.gsettings.get_string ("list-item-start");
56+
var selected_is_list = this.is_list (first_line, last_line, list_item_start);
5757

5858
buffer.begin_user_action ();
59-
for (uint8 i = first_line; i <= last_line; i++) {
59+
if (selected_is_list)
60+
{
61+
this.remove_list (first_line, last_line, list_item_start);
6062

61-
debug ("doing line " + i.to_string ());
62-
buffer.get_iter_at_line_index (out startline, i, 0);
63-
buffer.insert (ref startline, list_item_start, -1);
63+
} else {
64+
this.set_list (first_line, last_line, list_item_start);
6465
}
6566
buffer.end_user_action ();
67+
}
68+
69+
/**
70+
* Add the list prefix only to lines who hasnt it already
71+
*/
72+
private bool has_prefix (uint8 line_number, string list_item_start) {
73+
Gtk.TextIter start, end;
74+
buffer.get_iter_at_line_offset (out start, line_number, 0);
75+
76+
end = start.copy ();
77+
end.forward_to_line_end ();
78+
79+
var text_in_line = buffer.get_slice (start, end, false);
80+
81+
return text_in_line.has_prefix (list_item_start);
82+
}
83+
84+
/**
85+
* Checks whether Line x to Line y are all bulleted.
86+
*/
87+
private bool is_list (uint8 first_line, uint8 last_line, string list_item_start) {
88+
89+
for (uint8 line_number = first_line; line_number <= last_line; line_number++) {
90+
debug ("doing line " + line_number.to_string ());
91+
92+
if (!this.has_prefix (line_number, list_item_start)) {
93+
return false;
94+
}
95+
}
6696

97+
return true;
6798
}
99+
100+
/**
101+
* Add the list prefix only to lines who hasnt it already
102+
*/
103+
private void set_list (uint8 first_line, uint8 last_line, string list_item_start) {
104+
Gtk.TextIter line_start;
105+
for (uint8 line_number = first_line; line_number <= last_line; line_number++) {
106+
107+
debug ("doing line " + line_number.to_string ());
108+
if (!this.has_prefix (line_number, list_item_start)) {
109+
buffer.get_iter_at_line_offset (out line_start, line_number, 0);
110+
buffer.insert (ref line_start, list_item_start, -1);
111+
}
112+
}
113+
}
114+
115+
/**
116+
* Remove list prefix from line x to line y. Presuppose it is there
117+
*/
118+
private void remove_list (uint8 first_line, uint8 last_line, string list_item_start) {
119+
Gtk.TextIter line_start, prefix_end;
120+
var remove_range = list_item_start.length;
121+
122+
for (uint8 line_number = first_line; line_number <= last_line; line_number++) {
123+
124+
debug ("doing line " + line_number.to_string ());
125+
buffer.get_iter_at_line_offset (out line_start, line_number, 0);
126+
buffer.get_iter_at_line_offset (out prefix_end, line_number, remove_range);
127+
buffer.delete (ref line_start, ref prefix_end);
128+
}
129+
}
130+
131+
68132
}

src/Windows/StickyNoteWindow.vala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class Jorts.StickyNoteWindow : Gtk.Window {
4141
public const string ACTION_ZOOM_IN = "action_zoom_in";
4242
public const string ACTION_TOGGLE_MONO = "action_toggle_mono";
4343
public const string ACTION_DELETE = "action_delete";
44-
public const string ACTION_LIST = "action_list";
44+
public const string ACTION_TOGGLE_LIST = "action_toggle_list";
4545

4646
public const string ACTION_THEME_1 = "action_theme_1";
4747
public const string ACTION_THEME_2 = "action_theme_2";
@@ -64,7 +64,7 @@ public class Jorts.StickyNoteWindow : Gtk.Window {
6464
{ ACTION_ZOOM_OUT, action_zoom_out},
6565
{ ACTION_ZOOM_DEFAULT, action_zoom_default},
6666
{ ACTION_TOGGLE_MONO, action_toggle_mono},
67-
{ ACTION_LIST, action_list},
67+
{ ACTION_TOGGLE_LIST, action_toggle_list},
6868
{ ACTION_ZOOM_IN, action_zoom_in},
6969
{ ACTION_THEME_1, action_theme_1},
7070
{ ACTION_THEME_2, action_theme_2},
@@ -244,7 +244,7 @@ public class Jorts.StickyNoteWindow : Gtk.Window {
244244
private void action_show_menu () {view.menu_button.activate ();}
245245
private void action_delete () {((Jorts.Application)this.application).manager.delete_note (this);}
246246
private void action_toggle_mono () {popover.monospace = !popover.monospace;}
247-
private void action_list () {view.textview.list ();}
247+
private void action_toggle_list () {view.textview.toggle_list ();}
248248

249249
private void action_zoom_out () {zoomcontroller.zoom_out ();}
250250
private void action_zoom_default () {zoomcontroller.zoom_default ();}

0 commit comments

Comments
 (0)