Sunday, February 23, 2014

Patch for PCManFM to remember view mode

There is a bug in PCManFM that causes it not to remember the view mode (the view mode is icons, compact, thumbnails, or detailed list). This patch fixes it.
 commit 7c137a883350025a9724be1d8c2d8bd0307b1305  
 Author: sashoalm <sashoalm@aspire>  
 Date:  Sun Feb 23 20:59:58 2014 +0200  
   Remember view mode.  
 diff --git a/src/main-win.c b/src/main-win.c  
 index 6a65035..3947de3 100644  
 --- a/src/main-win.c  
 +++ b/src/main-win.c  
 @@ -1266,6 +1266,9 @@ static void on_fullscreen(GtkToggleAction* act, FmMainWin* win)  
      gtk_window_unfullscreen(GTK_WINDOW(win));  
  }  
 +  
 +extern char* profile;  
 +  
  static void on_change_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)  
  {  
    int mode = gtk_radio_action_get_current_value(cur);  
 @@ -1277,8 +1280,11 @@ static void on_change_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin*  
                       win->current_page->sort_type,  
                       win->current_page->sort_by, mode,  
                       win->current_page->show_hidden, NULL);  
 -  else  
 +  else {  
      win->current_page->view_mode = mode;  
 +    app_config->view_mode = mode;  
 +    fm_app_config_save_profile(app_config, profile);  
 +  }  
  }  
  static void on_sort_by(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)  
 diff --git a/src/pcmanfm.c b/src/pcmanfm.c  
 index 2fe3482..7ea63c2 100644  
 --- a/src/pcmanfm.c  
 +++ b/src/pcmanfm.c  
 @@ -52,7 +52,7 @@ static guint save_config_idle = 0;  
  static char** files_to_open = NULL;  
  static int n_files_to_open = 0;  
 -static char* profile = NULL;  
 +char* profile = NULL;  
  static gboolean no_desktop = FALSE;  
  static gboolean show_desktop = FALSE;  
  static gboolean desktop_off = FALSE;  

Saturday, February 22, 2014

Patch to start quick filter instead of quick search when typing in Krusader

Krusader has both quick search and quick filter, but quick filter needs to be started explicitly with Ctrl+I. With this patch, when you start typing, quick filter is started instead of quick search.

 commit a4aaddc554d9c98b6c7a84fe9a2f2b2b79c4582f  
 Author: sashoalm <sashoalm@aspire>  
 Date:  Fri Feb 14 22:49:05 2014 +0200  
   Start quick filter instead of quick search.  
 diff --git a/krusader/Panel/krview.cpp b/krusader/Panel/krview.cpp  
 index d9ff07d..0c738eb 100644  
 --- a/krusader/Panel/krview.cpp  
 +++ b/krusader/Panel/krview.cpp  
 @@ -213,10 +213,14 @@ void KrViewOperator::quickFilterChanged(const QString &text)  
    _quickFilter->setMatch(_view->_count || !_view->_files->numVfiles());  
  }  
 -void KrViewOperator::startQuickFilter()  
 +void KrViewOperator::startQuickFilter(QEvent *e)  
  {  
    _quickFilter->show();  
    _quickFilter->lineEdit()->setFocus();  
 +  if (e) {  
 +    QLineEdit *p = _quickFilter->lineEdit();  
 +    p->event(e);  
 +  }  
  }  
  void KrViewOperator::stopQuickFilter(bool refreshView)  
 @@ -964,26 +968,8 @@ bool KrView::handleKeyEventInt(QKeyEvent *e)  
        //if ( _config->readBoolEntry( "Do Quicksearch", _DoQuicksearch ) ) {  
        // are we using krusader's classic quicksearch, or wincmd style?  
      {  
 -      KConfigGroup grpSv(_config, "Look&Feel");  
 -      if (!grpSv.readEntry("New Style Quicksearch", _NewStyleQuicksearch))  
 -        return false;  
 -      else {  
 -        // first, show the quicksearch if its hidden  
 -        if (op()->quickSearch()->isHidden()) {  
 -          op()->quickSearch()->show();  
 -          // HACK: if the pressed key requires a scroll down, the selected  
 -          // item is "below" the quick search window, as the icon view will  
 -          // realize its new size after the key processing. The following line  
 -          // will resize the icon view immediately.  
 -          // ACTIVE_PANEL->gui->layout->activate();  
 -          // UPDATE: it seems like this isn't needed anymore, in case I'm wrong  
 -          // do something like op()->emitQuickSearchStartet()  
 -          // -----------------------------  
 -        }  
 -        // now, send the key to the quicksearch  
 -        op()->quickSearch()->myKeyPressEvent(e);  
 -        return true;  
 -      }  
 +      op()->startQuickFilter(e);  
 +      return true;  
      } else {  
        if (!op()->quickSearch()->isHidden()) {  
          op()->quickSearch()->hide();  
 diff --git a/krusader/Panel/krview.h b/krusader/Panel/krview.h  
 index 2f3c8a8..7db5fba 100644  
 --- a/krusader/Panel/krview.h  
 +++ b/krusader/Panel/krview.h  
 @@ -205,7 +205,7 @@ public slots:  
    void stopQuickSearch(QKeyEvent*);  
    void handleQuickSearchEvent(QKeyEvent*);  
 -  void startQuickFilter();  
 +  void startQuickFilter(QEvent *e = 0);  
    void stopQuickFilter(bool refreshView = true);  
  signals:  

Patch to enable PCManFM quick search to match mid-string (instead of strictly at the beginning)

PCManFM lets you select a file or directory by typing the first letters of its name.

Unfortunately, it does not let you search the file by typing a sub-string that appears in the middle of the file name. For example, typing "down" will select "Downloads", but typing "loads" will not, even though "loads" appears in the string.

Luckily, there is a way to change that, but it requires patching the source code of libfm, which is used by PCManFM. So, if you have Debian, download the source code and build dependencies:
 apt-get source libfm  
 sudo apt-get build-dep libfm  
After that, apply this patch:
 commit 437943e1ba9a43cd1809a1957d221a44fb22e02f  
 Author: sashoalm <sashoalm@aspire>  
 Date:  Sun Feb 23 12:45:09 2014 +0200  
   Enable mid-string search in PCManFM.  
 diff --git a/src/gtk/exo/exo-icon-view.c b/src/gtk/exo/exo-icon-view.c  
 index 8cf6279..1131580 100644  
 --- a/src/gtk/exo/exo-icon-view.c  
 +++ b/src/gtk/exo/exo-icon-view.c  
 @@ -453,7 +453,7 @@ static void   exo_icon_view_search_preedit_changed  (GtkIMContext  *im_cont  
  #endif  
  static gboolean exo_icon_view_search_start       (ExoIconView  *icon_view,  
                              gboolean    keybinding);  
 -static gboolean exo_icon_view_search_equal_func     (GtkTreeModel  *model,  
 +gboolean exo_icon_view_search_equal_func     (GtkTreeModel  *model,  
                              gint      column,  
                              const gchar  *key,  
                              GtkTreeIter  *iter,  
 @@ -8871,7 +8871,7 @@ exo_icon_view_search_start (ExoIconView *icon_view,  
 -static gboolean  
 +gboolean  
  exo_icon_view_search_equal_func (GtkTreeModel *model,  
                  gint     column,  
                  const gchar *key,  
 @@ -8918,7 +8918,7 @@ exo_icon_view_search_equal_func (GtkTreeModel *model,  
     case_normalized_key = g_utf8_casefold (normalized_key, -1);  
     /* compare the casefolded strings */  
 -   if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)  
 +   if (strstr (case_normalized_string, case_normalized_key) != 0)  
      retval = FALSE;  
    }  
 diff --git a/src/gtk/exo/exo-tree-view.c b/src/gtk/exo/exo-tree-view.c  
 index 207cc9c..36ac5a7 100644  
 --- a/src/gtk/exo/exo-tree-view.c  
 +++ b/src/gtk/exo/exo-tree-view.c  
 @@ -223,11 +223,18 @@ exo_tree_view_class_init (ExoTreeViewClass *klass)  
                             EXO_PARAM_READWRITE));  
  }  
 -  
 +gboolean  
 +exo_icon_view_search_equal_func (GtkTreeModel *model,  
 +                 gint     column,  
 +                 const gchar *key,  
 +                 GtkTreeIter *iter,  
 +                 gpointer   user_data);  
  static void  
  exo_tree_view_init (ExoTreeView *tree_view)  
  {  
 + gtk_tree_view_set_search_equal_func(&tree_view->__parent__, exo_icon_view_search_equal_func, 0, 0);  
 +   
   /* grab a pointer on the private data */  
   tree_view->priv = EXO_TREE_VIEW_GET_PRIVATE (tree_view);  
   tree_view->priv->single_click_timeout_id = -1;  

After that compile and install libfm:
 ./configure  
 make  
 sudo make install  
This will install it in /usr/local/lib, and our modified libfm will be loaded by PCManFM instead of the stock that comes with Ubuntu, and is in /usr/lib.