Skip to content

Commit

Permalink
siteeditor: Fix some issue with changing column focus
Browse files Browse the repository at this point in the history
Gtk a shit sometimes, most of the time.
  • Loading branch information
ahodesuka committed Nov 25, 2017
1 parent 1a57dd8 commit 345d30e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/siteeditor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ SiteEditor::~SiteEditor()
m_SiteCheckThread.join();
}

bool SiteEditor::on_key_release_event(GdkEventKey *e)
{
if (e->keyval == GDK_Return || e->keyval == GDK_ISO_Enter
|| e->keyval == GDK_KP_Enter || e->keyval == GDK_Tab)
{
Gtk::TreeIter iter = get_selection()->get_selected();
Gtk::TreePath p(iter);

if (iter->get_value(m_Columns.url).empty())
set_cursor(p, *m_UrlColumn, true);
else if (iter->get_value(m_Columns.name).empty())
set_cursor(p, *m_NameColumn, true);
}

return false;
}

void SiteEditor::on_cursor_changed()
{
Gtk::TreeView::on_cursor_changed();
Expand Down Expand Up @@ -142,12 +159,15 @@ void SiteEditor::delete_site()
{
Gtk::TreeIter o = get_selection()->get_selected();

m_Sites.erase(std::remove(m_Sites.begin(), m_Sites.end(), o->get_value(m_Columns.site)), m_Sites.end());
m_SignalEdited();
if (o)
{
m_Sites.erase(std::remove(m_Sites.begin(), m_Sites.end(), o->get_value(m_Columns.site)), m_Sites.end());
m_SignalEdited();

Gtk::TreeIter n = m_Model->erase(o);
get_selection()->select(n ? n : --n);
on_cursor_changed();
Gtk::TreeIter n = m_Model->erase(o);
get_selection()->select(n ? n : --n);
on_cursor_changed();
}
}

void SiteEditor::on_name_edited(const std::string &p, const std::string &text)
Expand All @@ -162,10 +182,7 @@ void SiteEditor::on_name_edited(const std::string &p, const std::string &text)

iter->set_value(m_Columns.name, name);

// start editing url column if it's blank
if (iter->get_value(m_Columns.url).empty())
set_cursor(path, *m_UrlColumn, true);
else
if (!iter->get_value(m_Columns.url).empty())
add_edit_site(iter);
}

Expand Down
2 changes: 2 additions & 0 deletions src/siteeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace AhoViewer

sigc::signal<void> signal_edited() const { return m_SignalEdited; }
protected:
virtual bool on_key_release_event(GdkEventKey *e) override;

void on_cursor_changed() override;
private:
class CellRendererIcon : public Gtk::CellRenderer/*{{{*/
Expand Down

0 comments on commit 345d30e

Please sign in to comment.