diff --git a/usr/lib/sticky/manager.py b/usr/lib/sticky/manager.py index c28e789..9fe061c 100644 --- a/usr/lib/sticky/manager.py +++ b/usr/lib/sticky/manager.py @@ -18,12 +18,16 @@ def __init__(self, item, settings): self.item = item self.settings = settings + self.hidden_icon = None self.set_has_window(False) self.style_manager = XApp.StyleManager(widget=self) self.title_bar = Gtk.Box(name='title-bar', visible=True) - self.title_bar.pack_start(Gtk.Label(label=item.title, name='title', visible=True, margin_top=5, margin_bottom=5, ellipsize=Pango.EllipsizeMode.END), False, False, 0) + self.title_bar.pack_start(Gtk.Label(label=item.title, name='title', visible=True, margin_top=5, margin_bottom=5, ellipsize=Pango.EllipsizeMode.END), True, True, 0) + if item.hidden: + self.hidden_icon = Gtk.Image(icon_name='xsi-view-conceal-symbolic', icon_size=Gtk.IconSize.MENU, visible=True, margin_end=2) + self.title_bar.pack_end(self.hidden_icon, False, False, 0) self.title_bar.set_parent(self) self.buffer = NoteBuffer() @@ -36,7 +40,10 @@ def __init__(self, item, settings): self.settings.connect('changed::font', self.set_font) self.set_font() - self.set_tooltip_text(item.title) + if item.hidden: + self.set_tooltip_text(_("%s (hidden - click the icon to show)") % item.title) + else: + self.set_tooltip_text(item.title) self.initialized = True @@ -218,6 +225,7 @@ def __init__(self, info, group_name): self.info = info self.group_name = group_name self.text = info['text'] + self.hidden = info.get('hidden', False) if not 'title'in info or info['title'] in [None, '']: self.title = _("Untitled") else: @@ -338,7 +346,7 @@ def create_group_entry(item): def on_list_clicked(self, list, event): for note in self.app.notes: - note.present_with_time(Gtk.get_current_event_time()) + note.restore(Gtk.get_current_event_time()) def on_list_changed(self, a, group_name): if group_name == self.get_current_group(): @@ -402,11 +410,37 @@ def open_search(self, *args): self.search_bar.set_search_mode(True) def on_note_activated(self, *args): - activated = self.note_view.get_selected_children()[0].item - activated_group = activated.group_name - self.select_group(activated_group) + self.show_note(self.note_view.get_selected_children()[0].item) + + def show_note(self, item): + self.select_group(item.group_name) + + self.app.focus_note(item.info) + + def is_over_hidden_icon(self, wrapper, entry, event): + icon = entry.hidden_icon + allocation = icon.get_allocation() + (x, y) = icon.translate_coordinates(wrapper, 0, 0) + padding = 4 + + return (x - padding <= event.x < x + allocation.width + padding and + y - padding <= event.y < y + allocation.height + padding) + + def on_preview_motion(self, wrapper, event, entry): + cursor = None + if self.is_over_hidden_icon(wrapper, entry, event): + cursor = Gdk.Cursor.new_from_name(wrapper.get_display(), 'pointer') - self.app.focus_note(activated.info) + wrapper.get_window().set_cursor(cursor) + + def on_preview_released(self, wrapper, event, entry): + if event.button != 1 or not self.is_over_hidden_icon(wrapper, entry, event): + return Gdk.EVENT_PROPAGATE + + wrapper.get_window().set_cursor(None) + GLib.idle_add(self.show_note, entry.item) + + return Gdk.EVENT_STOP def on_selected_notes_changed(self, *args): sensitive = len(self.note_view.get_selected_children()) != 0 @@ -430,11 +464,19 @@ def create_note_entry(self, item): context = wrapper.get_style_context() context.add_class(item.info['color']) context.add_class('note-preview') + if item.hidden: + context.add_class('hidden-note') outer_box.pack_start(wrapper, False, False, 0) entry = NoteEntry(item, self.app.settings) wrapper.pack_start(entry, False, False, 0) + if item.hidden: + dnd_wrapper.add_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK) + dnd_wrapper.connect('motion-notify-event', self.on_preview_motion, entry) + dnd_wrapper.connect('leave-notify-event', lambda w, e: w.get_window().set_cursor(None)) + dnd_wrapper.connect('button-release-event', self.on_preview_released, entry) + widget.show_all() return widget @@ -535,6 +577,7 @@ def duplicate_note(self, *args): note_info = selected.copy() note_info['x'] += 50 note_info['y'] += 50 + note_info['hidden'] = False group = self.get_current_group() notes = self.file_handler.get_note_list(group) notes.append(note_info) diff --git a/usr/lib/sticky/sticky.py b/usr/lib/sticky/sticky.py index a409e0f..75fd68c 100755 --- a/usr/lib/sticky/sticky.py +++ b/usr/lib/sticky/sticky.py @@ -132,6 +132,7 @@ def __init__(self, app, parent, info={}): title = info.get('title', '') self.cached_text = info.get('text', '') self.color = info.get('color', self.app.settings.get_string('default-color')) + self.hidden = info.get('hidden', False) super(Note, self).__init__( skip_taskbar_hint=True, @@ -199,6 +200,13 @@ def __init__(self, app, parent, info={}): close_button.set_tooltip_text(_("Delete Note")) self.title_bar.pack_end(close_button, False, False, 0) + hide_icon = Gtk.Image.new_from_icon_name('sticky-hide', Gtk.IconSize.BUTTON) + hide_button = Gtk.Button(image=hide_icon, relief=Gtk.ReliefStyle.NONE, name='window-button', valign=Gtk.Align.CENTER) + hide_button.connect('clicked', self.hide_note) + hide_button.connect('button-press-event', self.on_title_click) + hide_button.set_tooltip_text(_("Hide Note")) + self.title_bar.pack_end(hide_button, False, False, 0) + add_icon = Gtk.Image.new_from_icon_name('sticky-add', Gtk.IconSize.BUTTON) add_button = Gtk.Button(image=add_icon, relief=Gtk.ReliefStyle.NONE, name='window-button', valign=Gtk.Align.CENTER) add_button.connect('clicked', self.app.new_note, self) @@ -249,7 +257,11 @@ def __init__(self, app, parent, info={}): self.move(self.x, self.y) - self.show_all() + if self.hidden: + self.title_bar.show_all() + scroll.show_all() + else: + self.show_all() def test(self, *args): self.buffer.test() @@ -366,6 +378,9 @@ def on_title_click(self, w, event): return Gdk.EVENT_PROPAGATE def restore(self, time=0): + if self.hidden: + return + if time == 0: time = Gtk.get_current_event_time() @@ -373,6 +388,16 @@ def restore(self, time=0): self.present_with_time(time) self.move(self.x, self.y) + def hide_note(self, *args): + self.hidden = True + self.hide() + self.emit('update') + + def show_note(self, time=0): + self.hidden = False + self.restore(time) + self.emit('update') + def queue_update(self, b=None, invalidate_cache=False): self.invalid_cache = invalidate_cache @@ -399,7 +424,8 @@ def get_info(self): 'width': self.width, 'color': self.color, 'title': self.title.get_text(), - 'text': self.cached_text + 'text': self.cached_text, + 'hidden': self.hidden } return info @@ -423,6 +449,10 @@ def add_context_menu_items(self, popup, is_title=False): edit_title.connect('activate', self.set_title) popup.append(edit_title) + hide_item = Gtk.MenuItem(label=_("Hide Note"), visible=True) + hide_item.connect('activate', self.hide_note) + popup.append(hide_item) + duplicate_item = Gtk.MenuItem(label=_("Duplicate Note"), visible=True) duplicate_item.connect('activate', self.duplicate) popup.append(duplicate_item) @@ -1130,13 +1160,18 @@ def duplicate_note(self, new_note): new_note_info = new_note.get_info() new_note_info['x'] += 50 new_note_info['y'] += 50 + new_note_info['hidden'] = False self.add_note(new_note_info) def focus_note(self, note_info): + note_info = dict(note_info, hidden=note_info.get('hidden', False)) for note in self.notes: if note.get_info() == note_info: - note.present_with_time(0) + if note.hidden: + note.show_note() + else: + note.present_with_time(0) def on_lists_changed(self, *args): if not self.note_group in self.file_handler.get_note_group_names(): diff --git a/usr/share/icons/hicolor/scalable/status/sticky-hide.svg b/usr/share/icons/hicolor/scalable/status/sticky-hide.svg new file mode 100644 index 0000000..939d2e8 --- /dev/null +++ b/usr/share/icons/hicolor/scalable/status/sticky-hide.svg @@ -0,0 +1,8 @@ + + + + + + diff --git a/usr/share/sticky/sticky.css b/usr/share/sticky/sticky.css index 13489ac..d788b4c 100644 --- a/usr/share/sticky/sticky.css +++ b/usr/share/sticky/sticky.css @@ -65,6 +65,14 @@ padding: 0 5px; } +.note-preview.hidden-note { + opacity: 0.45; +} + +.note-preview.hidden-note #title { + font-style: italic; +} + #sticky-note decoration { box-shadow: 0 3px 9px 1px transparent, 0 2px 6px 2px rgba(0, 0, 0, 0.5); }