From eddec93589992887e286a3534ec1c5efe2ff6cca Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 13 Apr 2008 03:57:47 -0700 Subject: [PATCH] controllers: implement search by path Signed-off-by: David Aguilar --- ugit/controllers/__init__.py | 3 +++ ugit/controllers/search.py | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ugit/controllers/__init__.py b/ugit/controllers/__init__.py index 1da52426..3ac52e11 100644 --- a/ugit/controllers/__init__.py +++ b/ugit/controllers/__init__.py @@ -100,6 +100,7 @@ class Controller(QObserver): # Edit Menu menu_options = self.options, + # Seaarch Menu menu_search_revision = self.gen_search(search.REVISION_ID), @@ -107,6 +108,8 @@ class Controller(QObserver): self.gen_search(search.REVISION_RANGE), menu_search_message = self.gen_search(search.MESSAGE), + menu_search_path = + self.gen_search(search.PATH, True), menu_search_date_range = self.gen_search(search.DATE_RANGE), menu_search_diff = diff --git a/ugit/controllers/search.py b/ugit/controllers/search.py index 3799a172..8c1d3772 100644 --- a/ugit/controllers/search.py +++ b/ugit/controllers/search.py @@ -48,6 +48,12 @@ class RevisionRangeSearch(SearchEngine): input, args = self.get_common_args() return self.parse(self.model.rev_list(input, **args)) +class PathSearch(SearchEngine): + def get_results(self): + input, args = self.get_common_args() + paths = ['--'] + input.split(':') + return self.parse(self.model.rev_list(all=True,*paths,**args)) + class MessageSearch(SearchEngine): def get_results(self): input, args = self.get_common_args() @@ -77,6 +83,7 @@ class DateRangeSearch(SearchEngine): # Note: names correspond to radio button names for convenience REVISION_ID = 'radio_revision' REVISION_RANGE = 'radio_range' +PATH = 'radio_path' MESSAGE = 'radio_message' DIFF = 'radio_diff' DATE_RANGE = 'radio_daterange' @@ -85,6 +92,7 @@ DATE_RANGE = 'radio_daterange' SEARCH_ENGINES = { REVISION_ID: RevisionSearch, REVISION_RANGE: RevisionRangeSearch, + PATH: PathSearch, MESSAGE: MessageSearch, DIFF: DiffSearch, DATE_RANGE: DateRangeSearch, @@ -108,11 +116,13 @@ class SearchController(QObserver): self.add_callbacks( # Standard buttons button_search = self.search_callback, + button_browse = self.browse_callback, commit_list = self.display_callback, # Radio buttons trigger a search radio_revision = self.search_callback, radio_range = self.search_callback, radio_message = self.search_callback, + radio_path = self.search_callback, radio_diff = self.search_callback, radio_daterange = self.search_callback, ) @@ -157,6 +167,23 @@ class SearchController(QObserver): self.view.commit_list.clear() self.view.commit_text.setText('') + def browse_callback(self): + paths = QtGui.QFileDialog.getOpenFileNames( + self.view, + self.tr("Choose Path(s)")) + if not paths: + return + filepaths = [] + lenprefix = len(os.getcwd()) + 1 + for path in map(lambda x: unicode(x), paths): + if not path.startswith(os.getcwd()): + continue + filepaths.append(path[lenprefix:]) + input = ':'.join(filepaths) + self.model.set_input('') + self.set_mode(PATH) + self.model.set_input(input) + def display_results(self): commit_list = map(lambda x: x[1], self.results) self.model.set_commit_list(commit_list) -- 2.11.4.GIT